Mercurial > traipse_dev
comparison orpg/networking/mplay_server.py @ 222:bb7b9648792c beta
Traipse Beta 'OpenRPG' {100502-00}
Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for
developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to
the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user.
Update Summary (Patch-2)
New Features:
New Namespace method with two new syntaxes
New Namespace Internal is context sensitive, always!
New Namespace External is 'as narrow as you make it'
New Namespace FutureCheck helps ensure you don't receive an incorrect node
New PluginDB access for URL2Link plugin
New to Forms, they now show their content in Design Mode
New to Update Manager, checks Repo for updates on software start
New to Mini Lin node, change title in design mode
New to Game Tree, never lose a node, appends a number to the end of corrupted trees
New to Server GUI, Traipse Suite's Debug Console
New Namespace plugin, Allows Traipse users to use the Standard syntax !@ :: @!
Updates:
Update to White Board layer, uses a pencil image for color button
Update to Grid Layer, uses a grid image for color button
Update to Chat Window, size of drop down menus
Update to default lobby message
Update to template Text node
Update to 4e PC Sheet node
Fixes:
Fix to Server GUI startup errors
Fix to Server GUI Rooms tab updating
Fix to Chat and Settings if non existant die roller is picked
Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated
Fix to Alias Lib's Export to Tree, Open, Save features
Fix to alias node, now works properly
Fix to Splitter node, minor GUI cleanup
Fix to Backgrounds not loading through remote loader
Fix to Node name errors
Fix to rolling dice in chat Whispers
Fix to Splitters Sizing issues
Fix to URL2Link plugin, modified regex compilation should remove memory leak
Fix to mapy.py, a roll back due to zoomed grid issues
Fix to whiteboard_handler, Circles work by you clicking the center of the circle
Fix to Servers parse_incoming_dom which was outdated and did not respect XML
Fix to a broken link in the server welcome message
Fix to InterParse and logger requiring traceback
Fix to Update Manager Status Bar
Fix to failed image and erroneous pop up
Fix to Mini Lib node that was preventing use
Fix to plugins that parce dice but did not call InterParse
Fix to nodes for name changing by double click
Fix to Game Tree, node ordering on drag and drop corrected
Fix to Game Tree, corrupted error message was not showing
Fix to Update Manager, checks for internet connection
Fix to Update Manager, Auto Update corrections
author | sirebral |
---|---|
date | Sun, 02 May 2010 16:30:28 -0500 |
parents | 13054be69834 |
children | b29454610f36 |
comparison
equal
deleted
inserted
replaced
217:c719a07cd28d | 222:bb7b9648792c |
---|---|
323 self.ban_list[playerIP]['name'] = playerName | 323 self.ban_list[playerIP]['name'] = playerName |
324 self.log_msg(str(playerName) + " " + str(playerIP) + " is banned.") | 324 self.log_msg(str(playerName) + " " + str(playerIP) + " is banned.") |
325 self.saveBanList() | 325 self.saveBanList() |
326 except Exception, e: | 326 except Exception, e: |
327 self.log_msg("Exception in initBanList() " + str(e)) | 327 self.log_msg("Exception in initBanList() " + str(e)) |
328 self.log_msg( ('exception', str(e)) ) | |
328 | 329 |
329 # This method writes out the server's ban list added by Darren | 330 # This method writes out the server's ban list added by Darren |
330 def saveBanList( self ): | 331 def saveBanList( self ): |
331 self.log_msg("Saving Ban List File...") | 332 self.log_msg("Saving Ban List File...") |
332 | 333 |
341 file = open(self.userPath + self.banFile ,"w") | 342 file = open(self.userPath + self.banFile ,"w") |
342 file.write(tostring(etreeEl)) | 343 file.write(tostring(etreeEl)) |
343 file.close() | 344 file.close() |
344 except Exception, e: | 345 except Exception, e: |
345 self.log_msg("Exception in saveBanList() " + str(e)) | 346 self.log_msg("Exception in saveBanList() " + str(e)) |
347 self.log_msg( ('exception', str(e)) ) | |
346 | 348 |
347 # This method reads in the server's configuration file and reconfigs the server | 349 # This method reads in the server's configuration file and reconfigs the server |
348 # as needed, over-riding any default values as requested. | 350 # as needed, over-riding any default values as requested. |
349 | 351 |
350 def initServerConfig(self): | 352 def initServerConfig(self): |
524 self.makePersistentRooms() | 526 self.makePersistentRooms() |
525 self.log_msg("Server Configuration File: Processing Completed.") | 527 self.log_msg("Server Configuration File: Processing Completed.") |
526 except Exception, e: | 528 except Exception, e: |
527 traceback.print_exc() | 529 traceback.print_exc() |
528 self.log_msg("Exception in initServerConfig() " + str(e)) | 530 self.log_msg("Exception in initServerConfig() " + str(e)) |
531 self.log_msg( ('exception', str(e)) ) | |
529 | 532 |
530 def makePersistentRooms(self): | 533 def makePersistentRooms(self): |
531 'Creates rooms on the server as defined in the server config file.' | 534 'Creates rooms on the server as defined in the server config file.' |
532 for element in self.configDom.findall('room'): | 535 for element in self.configDom.findall('room'): |
533 roomName = element.get('name') | 536 roomName = element.get('name') |
569 if id not in self.groups: return 0 #invalid room, can't be persistant | 572 if id not in self.groups: return 0 #invalid room, can't be persistant |
570 pr = (self.groups[id]).persistant | 573 pr = (self.groups[id]).persistant |
571 return pr | 574 return pr |
572 except: | 575 except: |
573 self.log_msg("Exception occured in isPersistentRoom(self,id)") | 576 self.log_msg("Exception occured in isPersistentRoom(self,id)") |
577 self.log_msg( ('exception', str(e)) ) | |
574 return 0 | 578 return 0 |
575 | 579 |
576 #----------------------------------------------------- | 580 #----------------------------------------------------- |
577 # Toggle Meta Logging -- Added by Snowdog 4/03 | 581 # Toggle Meta Logging -- Added by Snowdog 4/03 |
578 #----------------------------------------------------- | 582 #----------------------------------------------------- |
773 length = len( msg ) # Calculate our message length | 777 length = len( msg ) # Calculate our message length |
774 lp = pack('!i', length) # Encode the message length into network byte order | 778 lp = pack('!i', length) # Encode the message length into network byte order |
775 try: | 779 try: |
776 sentl = sock.send( lp ) # Send the encoded length | 780 sentl = sock.send( lp ) # Send the encoded length |
777 sentm = sock.send( msg ) # Now, send the message the the length was describing | 781 sentm = sock.send( msg ) # Now, send the message the the length was describing |
778 except socket.error, e: self.log_msg( e ) | 782 except socket.error, e: self.log_msg( ('exception', str(e)) ); self.log_msg( e ) |
779 except Exception, e: self.log_msg( e ) | 783 except Exception, e: self.log_msg( e ); self.log_msg( ('exception', str(e)) ) |
780 | 784 |
781 | 785 |
782 def recvData( self, sock, readSize ): | 786 def recvData( self, sock, readSize ): |
783 """Simple socket receive method. This method will only return when the exact | 787 """Simple socket receive method. This method will only return when the exact |
784 byte count has been read from the connection, if remote terminates our | 788 byte count has been read from the connection, if remote terminates our |
816 (length,) = unpack('!i', lenData) # Now, convert to a usable form | 820 (length,) = unpack('!i', lenData) # Now, convert to a usable form |
817 msgData = self.recvData( sock, length ) # Read exactly the remaining amount of data | 821 msgData = self.recvData( sock, length ) # Read exactly the remaining amount of data |
818 try: | 822 try: |
819 if useCompression and cmpType != None: msgData = cmpType.decompress(msgData) | 823 if useCompression and cmpType != None: msgData = cmpType.decompress(msgData) |
820 except: traceback.print_exc() | 824 except: traceback.print_exc() |
821 except Exception, e: self.log_msg( "Exception: recvMsg(): " + str(e) ) | 825 except Exception, e: self.log_msg( "Exception: recvMsg(): " + str(e) ); self.log_msg( ('exception', str(e)) ) |
822 return msgData | 826 return msgData |
823 | 827 |
824 def kill_server(self): | 828 def kill_server(self): |
825 self.alive = 0 | 829 self.alive = 0 |
826 self.log_msg("Server stopping...") | 830 self.log_msg("Server stopping...") |
908 if self.isPersistentRoom( k ): pr = " S" #using S for static (P for persistant conflicts with password) | 912 if self.isPersistentRoom( k ): pr = " S" #using S for static (P for persistant conflicts with password) |
909 print "Group: " + k + pr + pw + ' Name: ' + self.groups[k].name | 913 print "Group: " + k + pr + pw + ' Name: ' + self.groups[k].name |
910 print | 914 print |
911 except Exception, e: | 915 except Exception, e: |
912 self.log_msg(str(e)) | 916 self.log_msg(str(e)) |
917 self.log_msg( ('exception', str(e)) ) | |
913 self.p_lock.release() | 918 self.p_lock.release() |
914 | 919 |
915 """ | 920 """ |
916 #---------------------------------------------------------------- | 921 #---------------------------------------------------------------- |
917 # Monitor Function -- Added by snowdog 2/05 | 922 # Monitor Function -- Added by snowdog 2/05 |
994 print " Moderated: %s" % self.groups[k].moderated | 999 print " Moderated: %s" % self.groups[k].moderated |
995 print " Map: %s" % self.groups[k].game_map.get_all_xml() | 1000 print " Map: %s" % self.groups[k].game_map.get_all_xml() |
996 print | 1001 print |
997 except Exception, e: | 1002 except Exception, e: |
998 self.log_msg(str(e)) | 1003 self.log_msg(str(e)) |
1004 self.log_msg( ('exception', str(e)) ) | |
999 self.p_lock.release() | 1005 self.p_lock.release() |
1000 | 1006 |
1001 """ | 1007 """ |
1002 #---------------------------------------------------------------- | 1008 #---------------------------------------------------------------- |
1003 # Player List -- Added by snowdog 4/03 | 1009 # Player List -- Added by snowdog 4/03 |
1026 if len(ids) > 0: print "" | 1032 if len(ids) > 0: print "" |
1027 print "--------------------------------------" | 1033 print "--------------------------------------" |
1028 print "\nStatistics: groups: " + str(len(self.groups)) + " players: " + str(len(self.players)) | 1034 print "\nStatistics: groups: " + str(len(self.groups)) + " players: " + str(len(self.players)) |
1029 except Exception, e: | 1035 except Exception, e: |
1030 self.log_msg(str(e)) | 1036 self.log_msg(str(e)) |
1037 self.log_msg( ('exception', str(e)) ) | |
1031 self.p_lock.release() | 1038 self.p_lock.release() |
1032 | 1039 |
1033 | 1040 |
1034 def player_dump(self): | 1041 def player_dump(self): |
1035 self.p_lock.acquire() | 1042 self.p_lock.acquire() |
1043 else: | 1050 else: |
1044 self.groups[k].remove_player(id) | 1051 self.groups[k].remove_player(id) |
1045 print "Bad Player Ref (#" + id + ") in group" | 1052 print "Bad Player Ref (#" + id + ") in group" |
1046 except Exception, e: | 1053 except Exception, e: |
1047 self.log_msg(str(e)) | 1054 self.log_msg(str(e)) |
1055 self.log_msg( ('exception', str(e)) ) | |
1048 self.p_lock.release() | 1056 self.p_lock.release() |
1049 | 1057 |
1050 def update_request(self,newsock, xml_dom): | 1058 def update_request(self,newsock, xml_dom): |
1051 # handle reconnects | 1059 # handle reconnects |
1052 self.log_msg( "update_request() has been called." ) | 1060 self.log_msg( "update_request() has been called." ) |
1108 (remote_host,remote_port) = newsock.getpeername() | 1116 (remote_host,remote_port) = newsock.getpeername() |
1109 bad_xml_string = "Your client sent an illegal message to the server and will be disconnected. " | 1117 bad_xml_string = "Your client sent an illegal message to the server and will be disconnected. " |
1110 bad_xml_string += "Please report this bug to the development team at:<br /> " | 1118 bad_xml_string += "Please report this bug to the development team at:<br /> " |
1111 bad_xml_string += "<a href='http://www.assembla.com/spaces/traipse_dev/tickets/'>Traipse-Dev " | 1119 bad_xml_string += "<a href='http://www.assembla.com/spaces/traipse_dev/tickets/'>Traipse-Dev " |
1112 bad_xml_string += "(http://www.assembla.com/spaces/traipse_dev/tickets/)</a><br />" | 1120 bad_xml_string += "(http://www.assembla.com/spaces/traipse_dev/tickets/)</a><br />" |
1113 self.sendMsg( newsock, "<msg to='" + props['id'] + "' from='" + props['id'] + "' group_id='0' />" + bad_xml_string, | 1121 self.sendMsg( newsock, "<msg to='" +props['id']+ "' from='" +props['id']+ "' group_id='0' />" +bad_xml_string, |
1114 new_stub.useCompression, new_stub.compressionType) | 1122 new_stub.useCompression, new_stub.compressionType) |
1115 | 1123 |
1116 time.sleep(2) | 1124 time.sleep(2) |
1117 newsock.close() | 1125 newsock.close() |
1118 print "Error in parse found from " + str(remote_host) + ". Disconnected." | 1126 print "Error in parse found from " + str(remote_host) + ". Disconnected." |
1119 print " Offending data(" + str(len(data)) + "bytes)=" + data | 1127 print " Offending data(" + str(len(data)) + "bytes)=" + data |
1120 print "Exception=" + str(e) | 1128 print "Exception=" + str(e) |
1129 self.log_msg( ('exception', str(e)) ) | |
1121 #if xml_dom: xml_dom.unlink() | 1130 #if xml_dom: xml_dom.unlink() |
1122 return | 1131 return |
1123 | 1132 |
1124 #start threads and store player | 1133 #start threads and store player |
1125 allowed = 1 | 1134 allowed = 1 |
1275 self.listen_sock.bind(('', self.server_port)) | 1284 self.listen_sock.bind(('', self.server_port)) |
1276 self.listen_sock.listen(5) | 1285 self.listen_sock.listen(5) |
1277 | 1286 |
1278 except Exception, e: | 1287 except Exception, e: |
1279 self.log_msg(("Error binding request socket!", e)) | 1288 self.log_msg(("Error binding request socket!", e)) |
1289 self.log_msg( ('exception', str(e)) ) | |
1280 self.alive = 0 | 1290 self.alive = 0 |
1281 | 1291 |
1282 while self.alive: | 1292 while self.alive: |
1283 # Block on the socket waiting for a new connection | 1293 # Block on the socket waiting for a new connection |
1284 try: | 1294 try: |
1291 # our face! :O After words, this thread is dead ready for another connection | 1301 # our face! :O After words, this thread is dead ready for another connection |
1292 # accept to come in. | 1302 # accept to come in. |
1293 """ | 1303 """ |
1294 thread.start_new_thread(self.acceptedNewConnectionThread, ( newsock, addr )) | 1304 thread.start_new_thread(self.acceptedNewConnectionThread, ( newsock, addr )) |
1295 | 1305 |
1296 except: | 1306 except Exception, e: |
1297 print "The following exception caught accepting new connection:" | 1307 print "The following exception caught accepting new connection:" |
1298 traceback.print_exc() | 1308 traceback.print_exc() |
1309 self.log_msg( ('exception', str(e)) ) | |
1299 | 1310 |
1300 # At this point, we're done and cleaning up. | 1311 # At this point, we're done and cleaning up. |
1301 self.log_msg("server socket listening thread exiting...") | 1312 self.log_msg("server socket listening thread exiting...") |
1302 self.listen_event.set() | 1313 self.listen_event.set() |
1303 | 1314 |
1314 if data=="" or data == None: | 1325 if data=="" or data == None: |
1315 self.log_msg("Connection from " + str(addr) + " failed. Closing connection.") | 1326 self.log_msg("Connection from " + str(addr) + " failed. Closing connection.") |
1316 try: newsock.close() | 1327 try: newsock.close() |
1317 except Exception, e: | 1328 except Exception, e: |
1318 self.log_msg( str(e) ) | 1329 self.log_msg( str(e) ) |
1330 self.log_msg( ('exception', str(e)) ) | |
1319 print str(e) | 1331 print str(e) |
1320 return #returning causes connection thread instance to terminate | 1332 return #returning causes connection thread instance to terminate |
1321 if data == "<system/>": | 1333 if data == "<system/>": |
1322 try: newsock.close() | 1334 try: newsock.close() |
1323 except: pass | 1335 except: pass |
1335 try: | 1347 try: |
1336 xml_dom = XML(data) | 1348 xml_dom = XML(data) |
1337 | 1349 |
1338 except: | 1350 except: |
1339 try: newsock.close() | 1351 try: newsock.close() |
1340 except: pass | 1352 except Exception, e: pass |
1341 self.log_msg( "Error in parse found from " + str(addr) + ". Disconnected.") | 1353 self.log_msg( "Error in parse found from " + str(addr) + ". Disconnected.") |
1342 self.log_msg(" Offending data(" + str(len(data)) + "bytes)=" + data) | 1354 self.log_msg(" Offending data(" + str(len(data)) + "bytes)=" + data) |
1343 self.log_msg( "Exception:") | 1355 self.log_msg( "Exception:") |
1356 self.log_msg( ('exception', str(e)) ) | |
1344 traceback.print_exc() | 1357 traceback.print_exc() |
1345 return #returning causes connection thread instance to terminate | 1358 return #returning causes connection thread instance to terminate |
1346 | 1359 |
1347 # Determine the correct action and execute it | 1360 # Determine the correct action and execute it |
1348 try: | 1361 try: |
1356 | 1369 |
1357 except Exception, e: | 1370 except Exception, e: |
1358 print "The following message: " + str(data) | 1371 print "The following message: " + str(data) |
1359 print "from " + str(addr) + " created the following exception: " | 1372 print "from " + str(addr) + " created the following exception: " |
1360 traceback.print_exc() | 1373 traceback.print_exc() |
1374 self.log_msg( ('exception', str(e)) ) | |
1361 return #returning causes connection thread instance to terminate | 1375 return #returning causes connection thread instance to terminate |
1362 | 1376 |
1363 """ | 1377 """ |
1364 #======================================================== | 1378 #======================================================== |
1365 # | 1379 # |
1390 #so data in passed objects doesn't change (python passes by reference) | 1404 #so data in passed objects doesn't change (python passes by reference) |
1391 del data | 1405 del data |
1392 data = None | 1406 data = None |
1393 except Exception, e: | 1407 except Exception, e: |
1394 self.log_msg(str(e)) | 1408 self.log_msg(str(e)) |
1409 self.log_msg( ('exception', str(e)) ) | |
1395 self.log_msg("message handler thread exiting...") | 1410 self.log_msg("message handler thread exiting...") |
1396 self.incoming_event.set() | 1411 self.incoming_event.set() |
1397 | 1412 |
1398 def parse_incoming_dom(self, data): | 1413 def parse_incoming_dom(self, data): |
1399 end = data.find(">") | 1414 end = data.find(">") |
1408 self.message_action(xml_dom, data) | 1423 self.message_action(xml_dom, data) |
1409 except Exception, e: | 1424 except Exception, e: |
1410 print "Error in parse of inbound message. Ignoring message." | 1425 print "Error in parse of inbound message. Ignoring message." |
1411 print " Offending data(" + str(len(data)) + "bytes)=" + data | 1426 print " Offending data(" + str(len(data)) + "bytes)=" + data |
1412 print "Exception=" + str(e) | 1427 print "Exception=" + str(e) |
1428 self.log_msg( ('exception', str(e)) ) | |
1413 | 1429 |
1414 def message_action(self, xml_dom, data): | 1430 def message_action(self, xml_dom, data): |
1415 tag_name = xml_dom.tag | 1431 tag_name = xml_dom.tag |
1416 if self.svrcmds.has_key(tag_name): self.svrcmds[tag_name]['function'](xml_dom, data) | 1432 if self.svrcmds.has_key(tag_name): self.svrcmds[tag_name]['function'](xml_dom, data) |
1417 else: raise Exception, "Not a valid header!" | 1433 else: |
1434 raise Exception, "Not a valid header!" | |
1435 self.log_msg( ('exception', 'Not a valid header!') ) | |
1418 #Message Action thread expires and closes here. | 1436 #Message Action thread expires and closes here. |
1419 return | 1437 return |
1420 | 1438 |
1421 def do_alter(self, xml_dom, data): | 1439 def do_alter(self, xml_dom, data): |
1422 target = xml_dom.get("key") or 'None' | 1440 target = xml_dom.get("key") or 'None' |
1516 if self.groups[group_id].voice.has_key(i.strip()): del self.groups[group_id].voice[i.strip()] | 1534 if self.groups[group_id].voice.has_key(i.strip()): del self.groups[group_id].voice[i.strip()] |
1517 else: | 1535 else: |
1518 print "Bad input: " + data | 1536 print "Bad input: " + data |
1519 except Exception,e: | 1537 except Exception,e: |
1520 self.log_msg(str(e)) | 1538 self.log_msg(str(e)) |
1539 self.log_msg( ('exception', str(e)) ) | |
1521 | 1540 |
1522 def join_group(self, xml_dom, data): | 1541 def join_group(self, xml_dom, data): |
1523 try: | 1542 try: |
1524 from_id = xml_dom.get("from") | 1543 from_id = xml_dom.get("from") |
1525 pwd = xml_dom.get("pwd") | 1544 pwd = xml_dom.get("pwd") |
1549 | 1568 |
1550 #move the player into their new group. | 1569 #move the player into their new group. |
1551 self.move_player(from_id, group_id) | 1570 self.move_player(from_id, group_id) |
1552 except Exception, e: | 1571 except Exception, e: |
1553 self.log_msg(str(e)) | 1572 self.log_msg(str(e)) |
1573 self.log_msg( ('exception', str(e)) ) | |
1554 | 1574 |
1555 """ | 1575 """ |
1556 # move_player function -- added by Snowdog 4/03 | 1576 # move_player function -- added by Snowdog 4/03 |
1557 # | 1577 # |
1558 # Split join_group function in half. separating the player validation checks | 1578 # Split join_group function in half. separating the player validation checks |
1566 try: | 1586 try: |
1567 if group_id == "0": self.players[from_id].role = "GM" | 1587 if group_id == "0": self.players[from_id].role = "GM" |
1568 else: self.players[from_id].role = "Lurker" | 1588 else: self.players[from_id].role = "Lurker" |
1569 except Exception, e: | 1589 except Exception, e: |
1570 print "exception in move_player() " | 1590 print "exception in move_player() " |
1591 self.log_msg( ('exception', str(e)) ) | |
1571 traceback.print_exc() | 1592 traceback.print_exc() |
1572 | 1593 |
1573 old_group_id = self.players[from_id].change_group(group_id, self.groups) | 1594 old_group_id = self.players[from_id].change_group(group_id, self.groups) |
1574 self.send_to_group(from_id, old_group_id, self.players[from_id].toxml('del')) | 1595 self.send_to_group(from_id, old_group_id, self.players[from_id].toxml('del')) |
1575 self.send_to_group(from_id, group_id, self.players[from_id].toxml('new')) | 1596 self.send_to_group(from_id, group_id, self.players[from_id].toxml('new')) |
1594 urllib.urlcleanup() | 1615 urllib.urlcleanup() |
1595 | 1616 |
1596 except Exception, e: | 1617 except Exception, e: |
1597 roomMsg = "" | 1618 roomMsg = "" |
1598 self.log_msg(str(e)) | 1619 self.log_msg(str(e)) |
1620 self.log_msg( ('exception', str(e)) ) | |
1599 | 1621 |
1600 # Spit that darn message out now! | 1622 # Spit that darn message out now! |
1601 self.players[from_id].outbox.put("<msg to='" + from_id + "' from='0' group_id='" + group_id + "' />" + roomMsg) | 1623 self.players[from_id].outbox.put("<msg to='" + from_id + "' from='0' group_id='" + group_id + "' />" + roomMsg) |
1602 if self.sendLobbySound and group_id == '0': | 1624 if self.sendLobbySound and group_id == '0': |
1603 self.players[from_id].outbox.put('<sound url="' + self.lobbySound + '" group_id="0" from="0" loop="True" />') | 1625 self.players[from_id].outbox.put('<sound url="' + self.lobbySound + '" group_id="0" from="0" loop="True" />') |
1611 self.log_msg(("update_group", (self.groups[old_group_id].name, old_group_id, len(self.groups[old_group_id].players) ))) | 1633 self.log_msg(("update_group", (self.groups[old_group_id].name, old_group_id, len(self.groups[old_group_id].players) ))) |
1612 self.log_msg(("update_group", (self.groups[group_id].name, group_id, len(self.groups[group_id].players) ))) | 1634 self.log_msg(("update_group", (self.groups[group_id].name, group_id, len(self.groups[group_id].players) ))) |
1613 self.handle_role("set", from_id, self.players[from_id].role, self.groups[group_id].boot_pwd, group_id) | 1635 self.handle_role("set", from_id, self.players[from_id].role, self.groups[group_id].boot_pwd, group_id) |
1614 except Exception, e: | 1636 except Exception, e: |
1615 self.log_msg(str(e)) | 1637 self.log_msg(str(e)) |
1638 self.log_msg( ('exception', str(e)) ) | |
1616 thread.start_new_thread(self.registerRooms,(0,)) | 1639 thread.start_new_thread(self.registerRooms,(0,)) |
1617 | 1640 |
1618 def return_room_roles(self, from_id, group_id): | 1641 def return_room_roles(self, from_id, group_id): |
1619 for m in self.players.keys(): | 1642 for m in self.players.keys(): |
1620 if self.players[m].group_id == group_id: | 1643 if self.players[m].group_id == group_id: |
1769 del self.groups[group_id] | 1792 del self.groups[group_id] |
1770 self.log_msg(("delete_group", (group_id, from_id))) | 1793 self.log_msg(("delete_group", (group_id, from_id))) |
1771 else: self.send_to_all("0",self.groups[group_id].toxml('update')) | 1794 else: self.send_to_all("0",self.groups[group_id].toxml('update')) |
1772 #The register Rooms thread | 1795 #The register Rooms thread |
1773 thread.start_new_thread(self.registerRooms,(0,)) | 1796 thread.start_new_thread(self.registerRooms,(0,)) |
1774 except Exception, e: self.log_msg(str(e)) | 1797 except Exception, e: self.log_msg( ('exception', str(e)) ) |
1775 | 1798 |
1776 def del_player(self, id, group_id): | 1799 def del_player(self, id, group_id): |
1777 try: | 1800 try: |
1778 dmsg = "Client Disconnect: (" + str(id) + ") " + str(self.players[id].name) | 1801 dmsg = "Client Disconnect: (" + str(id) + ") " + str(self.players[id].name) |
1779 self.players[id].disconnect() | 1802 self.players[id].disconnect() |
1787 # Note: Upon server shutdown, the server is first unregistered, so | 1810 # Note: Upon server shutdown, the server is first unregistered, so |
1788 # this code won't be repeated for each player being deleted. | 1811 # this code won't be repeated for each player being deleted. |
1789 """ | 1812 """ |
1790 if self.be_registered: | 1813 if self.be_registered: |
1791 self.register() | 1814 self.register() |
1792 except Exception, e: self.log_msg(str(e)) | 1815 except Exception, e: self.log_msg( ('exception', str(e)) ) |
1793 self.log_msg("Explicit garbage collection shows %s undeletable items." % str(gc.collect())) | 1816 self.log_msg("Explicit garbage collection shows %s undeletable items." % str(gc.collect())) |
1794 | 1817 |
1795 def incoming_player_handler(self, xml_dom, data): | 1818 def incoming_player_handler(self, xml_dom, data): |
1796 id = xml_dom.get("id") | 1819 id = xml_dom.get("id") |
1797 act = xml_dom.get("action") | 1820 act = xml_dom.get("action") |
1802 self.send_to_group(id,group_id,data) | 1825 self.send_to_group(id,group_id,data) |
1803 if act=="new": | 1826 if act=="new": |
1804 try: | 1827 try: |
1805 self.send_player_list(id,group_id) | 1828 self.send_player_list(id,group_id) |
1806 self.send_group_list(id) | 1829 self.send_group_list(id) |
1807 except Exception, e: traceback.print_exc() | 1830 except Exception, e: self.log_msg( ('exception', str(e)) ); traceback.print_exc() |
1808 elif act=="del": | 1831 elif act=="del": |
1809 self.del_player(id,group_id) | 1832 self.del_player(id,group_id) |
1810 self.check_group(id, group_id) | 1833 self.check_group(id, group_id) |
1811 elif act=="update": | 1834 elif act=="update": |
1812 self.players[id].take_dom(xml_dom) | 1835 self.players[id].take_dom(xml_dom) |
1844 xml_dom, data = ServerPlugins.preParseIncoming(xml_dom, data) | 1867 xml_dom, data = ServerPlugins.preParseIncoming(xml_dom, data) |
1845 ########################################################### | 1868 ########################################################### |
1846 to_id = xml_dom.get("to") | 1869 to_id = xml_dom.get("to") |
1847 from_id = xml_dom.get("from") | 1870 from_id = xml_dom.get("from") |
1848 group_id = xml_dom.get("group_id") | 1871 group_id = xml_dom.get("group_id") |
1872 ## Backwards compatibility with older clients | |
1849 end = data.find(">") | 1873 end = data.find(">") |
1850 msg = data[end+1:] | 1874 msg = data[end+1:] |
1875 if msg[-6:] == '</msg>': msg = msg[:-6] | |
1876 data = msg | |
1851 | 1877 |
1852 if from_id == "0" or len(from_id) == 0: | 1878 if from_id == "0" or len(from_id) == 0: |
1853 print "WARNING!! Message received with an invalid from_id. Message dropped." | 1879 print "WARNING!! Message received with an invalid from_id. Message dropped." |
1854 return None | 1880 return None |
1855 | 1881 |
1870 #attempt to change lobby map. Illegal operation. | 1896 #attempt to change lobby map. Illegal operation. |
1871 self.players[from_id].self_message('The lobby map may not be altered.') | 1897 self.players[from_id].self_message('The lobby map may not be altered.') |
1872 elif to_id.lower() == 'all': | 1898 elif to_id.lower() == 'all': |
1873 #valid map for all players that is not the lobby. | 1899 #valid map for all players that is not the lobby. |
1874 self.send_to_group(from_id,group_id,data) | 1900 self.send_to_group(from_id,group_id,data) |
1875 self.groups[group_id].game_map.init_from_xml(msg) | 1901 self.groups[group_id].game_map.init_from_xml(data) |
1876 else: | 1902 else: |
1877 #attempting to send map to specific individuals which is not supported. | 1903 #attempting to send map to specific individuals which is not supported. |
1878 self.players[from_id].self_message('Invalid map message. Message not sent to others.') | 1904 self.players[from_id].self_message('Invalid map message. Message not sent to others.') |
1879 | 1905 |
1880 elif msg[:6] == '<boot ': | 1906 elif msg[:6] == '<boot ': |
1941 print e | 1967 print e |
1942 print "Error executing the role change" | 1968 print "Error executing the role change" |
1943 print "due to the following exception:" | 1969 print "due to the following exception:" |
1944 traceback.print_exc() | 1970 traceback.print_exc() |
1945 print "Ignoring boot message" | 1971 print "Ignoring boot message" |
1972 self.log_msg( ('exception', str(e)) ) | |
1946 | 1973 |
1947 def handle_boot(self,from_id,to_id,group_id,msg): | 1974 def handle_boot(self,from_id,to_id,group_id,msg): |
1948 xml_dom = None | 1975 xml_dom = None |
1949 try: | 1976 try: |
1950 given_boot_pwd = None | 1977 given_boot_pwd = None |
1951 try: | 1978 try: |
1952 xml_dom = XML(msg) | 1979 xml_dom = XML(msg) |
1953 given_boot_pwd = xml_dom.get("boot_pwd") | 1980 given_boot_pwd = xml_dom.get("boot_pwd") |
1954 | 1981 |
1955 except: | 1982 except Exception, e: |
1956 print "Error in parse of boot message, Ignoring." | 1983 print "Error in parse of boot message, Ignoring." |
1957 print "Exception: " | 1984 print "Exception: " |
1958 traceback.print_exc() | 1985 traceback.print_exc() |
1986 self.log_msg( ('exception', str(e)) ) | |
1959 | 1987 |
1960 try: | 1988 try: |
1961 actual_boot_pwd = self.groups[group_id].boot_pwd | 1989 actual_boot_pwd = self.groups[group_id].boot_pwd |
1962 server_admin_pwd = self.groups["0"].boot_pwd | 1990 server_admin_pwd = self.groups["0"].boot_pwd |
1963 self.log_msg("Actual boot pwd = " + actual_boot_pwd) | 1991 self.log_msg("Actual boot pwd = " + actual_boot_pwd) |
2006 print "boot passwords did not match" | 2034 print "boot passwords did not match" |
2007 | 2035 |
2008 except Exception, e: | 2036 except Exception, e: |
2009 traceback.print_exc() | 2037 traceback.print_exc() |
2010 self.log_msg('Exception in handle_boot() ' + str(e)) | 2038 self.log_msg('Exception in handle_boot() ' + str(e)) |
2039 self.log_msg( ('exception', str(e)) ) | |
2011 | 2040 |
2012 finally: | 2041 finally: |
2013 try: | 2042 try: |
2014 if xml_dom: xml_dom.unlink() | 2043 if xml_dom: xml_dom.unlink() |
2015 except Exception, e: | 2044 except Exception, e: |
2016 traceback.print_exc() | 2045 traceback.print_exc() |
2017 self.log_msg('Exception in xml_dom.unlink() ' + str(e)) | 2046 self.log_msg('Exception in xml_dom.unlink() ' + str(e)) |
2047 self.log_msg( ('exception', str(e)) ) | |
2018 | 2048 |
2019 """ | 2049 """ |
2020 # admin_kick function -- by Snowdog 4/03 | 2050 # admin_kick function -- by Snowdog 4/03 |
2021 # 9/17/05 updated to allow stealth boots (no client chat announce) -SD | 2051 # 9/17/05 updated to allow stealth boots (no client chat announce) -SD |
2022 """ | 2052 """ |
2043 self.check_group(id, group_id) | 2073 self.check_group(id, group_id) |
2044 | 2074 |
2045 except Exception, e: | 2075 except Exception, e: |
2046 traceback.print_exc() | 2076 traceback.print_exc() |
2047 self.log_msg('Exception in admin_kick() ' + str(e)) | 2077 self.log_msg('Exception in admin_kick() ' + str(e)) |
2078 self.log_msg( ('exception', str(e)) ) | |
2048 | 2079 |
2049 ### Alpha ### Addition added to assist in Un Banning users. | 2080 ### Alpha ### Addition added to assist in Un Banning users. |
2050 def admin_build_banlist(self): | 2081 def admin_build_banlist(self): |
2051 validate.config_file("ban_list.xml", "default_ban_list.xml" ) | 2082 validate.config_file("ban_list.xml", "default_ban_list.xml" ) |
2052 configDom = parse(dir_struct["user"] + 'ban_list.xml') | 2083 configDom = parse(dir_struct["user"] + 'ban_list.xml') |
2069 self.saveBanList() | 2100 self.saveBanList() |
2070 | 2101 |
2071 except Exception, e: | 2102 except Exception, e: |
2072 traceback.print_exc() | 2103 traceback.print_exc() |
2073 self.log_msg('Exception in admin_banip() ' + str(e)) | 2104 self.log_msg('Exception in admin_banip() ' + str(e)) |
2105 self.log_msg( ('exception', str(e)) ) | |
2074 | 2106 |
2075 def admin_ban(self, id, message="", silent = 0): | 2107 def admin_ban(self, id, message="", silent = 0): |
2076 "Ban a player from a server from the console" | 2108 "Ban a player from a server from the console" |
2077 try: | 2109 try: |
2078 id = str(id) | 2110 id = str(id) |
2100 self.check_group(id, group_id) | 2132 self.check_group(id, group_id) |
2101 | 2133 |
2102 except Exception, e: | 2134 except Exception, e: |
2103 traceback.print_exc() | 2135 traceback.print_exc() |
2104 self.log_msg('Exception in admin_ban() ' + str(e)) | 2136 self.log_msg('Exception in admin_ban() ' + str(e)) |
2137 self.log_msg( ('exception', str(e)) ) | |
2105 | 2138 |
2106 def admin_unban(self, ip): | 2139 def admin_unban(self, ip): |
2107 self.admin_build_banlist() | 2140 self.admin_build_banlist() |
2108 try: | 2141 try: |
2109 if self.ban_list.has_key(ip): del self.ban_list[ip] | 2142 if self.ban_list.has_key(ip): del self.ban_list[ip] |
2110 self.saveBanList() | 2143 self.saveBanList() |
2111 | 2144 |
2112 except Exception, e: | 2145 except Exception, e: |
2113 traceback.print_exc() | 2146 traceback.print_exc() |
2114 self.log_msg('Exception in admin_unban() ' + str(e)) | 2147 self.log_msg('Exception in admin_unban() ' + str(e)) |
2148 self.log_msg( ('exception', str(e)) ) | |
2115 | 2149 |
2116 def admin_banlist(self): | 2150 def admin_banlist(self): |
2117 msg = [] | 2151 msg = [] |
2118 msg.append('<table border="1"><tr><td><b>Name</b></td><td><b>IP</b></td></tr>') | 2152 msg.append('<table border="1"><tr><td><b>Name</b></td><td><b>IP</b></td></tr>') |
2119 for ip in self.ban_list.keys(): | 2153 for ip in self.ban_list.keys(): |
2161 for k in keys: | 2195 for k in keys: |
2162 if k != from_id: self.players[k].outbox.put(data) | 2196 if k != from_id: self.players[k].outbox.put(data) |
2163 except Exception, e: | 2197 except Exception, e: |
2164 traceback.print_exc() | 2198 traceback.print_exc() |
2165 self.log_msg("Exception: send_to_all(): " + str(e)) | 2199 self.log_msg("Exception: send_to_all(): " + str(e)) |
2200 self.log_msg( ('exception', str(e)) ) | |
2166 | 2201 |
2167 def send_to_group(self, from_id, group_id, data): | 2202 def send_to_group(self, from_id, group_id, data): |
2168 #data = ("<msg to='all' from='0' group_id='"+str(group_id)+"' /><font color='#FF0000'>" + data + "</font>") | 2203 #data = ("<msg to='all' from='0' group_id='"+str(group_id)+"' /><font color='#FF0000'>" + data + "</font>") |
2169 data = ServerPlugins.postParseIncoming(data) #Function breaks here. | 2204 data = ServerPlugins.postParseIncoming(data) #Function breaks here. |
2170 try: | 2205 try: |
2174 for k in keys: | 2209 for k in keys: |
2175 if k != from_id: self.players[k].outbox.put(data) | 2210 if k != from_id: self.players[k].outbox.put(data) |
2176 except Exception, e: | 2211 except Exception, e: |
2177 traceback.print_exc() | 2212 traceback.print_exc() |
2178 self.log_msg("Exception: send_to_group(): " + str(e)) | 2213 self.log_msg("Exception: send_to_group(): " + str(e)) |
2214 self.log_msg( ('exception', str(e)) ) | |
2179 | 2215 |
2180 def send_player_list(self,to_id,group_id): | 2216 def send_player_list(self,to_id,group_id): |
2181 try: | 2217 try: |
2182 keys = self.groups[group_id].get_player_ids() | 2218 keys = self.groups[group_id].get_player_ids() |
2183 for k in keys: | 2219 for k in keys: |
2185 data = self.players[k].toxml('new') | 2221 data = self.players[k].toxml('new') |
2186 self.players[to_id].outbox.put(data) | 2222 self.players[to_id].outbox.put(data) |
2187 except Exception, e: | 2223 except Exception, e: |
2188 traceback.print_exc() | 2224 traceback.print_exc() |
2189 self.log_msg("Exception: send_player_list(): " + str(e)) | 2225 self.log_msg("Exception: send_player_list(): " + str(e)) |
2226 self.log_msg( ('exception', str(e)) ) | |
2190 | 2227 |
2191 def send_group_list(self, to_id, action="new"): | 2228 def send_group_list(self, to_id, action="new"): |
2192 try: | 2229 try: |
2193 for key in self.groups: | 2230 for key in self.groups: |
2194 xml = self.groups[key].toxml(action) | 2231 xml = self.groups[key].toxml(action) |
2195 self.players[to_id].outbox.put(xml) | 2232 self.players[to_id].outbox.put(xml) |
2196 except Exception, e: | 2233 except Exception, e: |
2197 self.log_msg("Exception: send_group_list(): (client #"+to_id+") : " + str(e)) | 2234 self.log_msg("Exception: send_group_list(): (client #"+to_id+") : " + str(e)) |
2198 traceback.print_exc() | 2235 traceback.print_exc() |
2236 self.log_msg( ('exception', str(e)) ) | |
2199 | 2237 |
2200 """ | 2238 """ |
2201 # KICK_ALL_CLIENTS() | 2239 # KICK_ALL_CLIENTS() |
2202 # | 2240 # |
2203 # Convience method for booting all clients off the server at once. | 2241 # Convience method for booting all clients off the server at once. |
2211 pl = self.groups[k].get_player_ids() | 2249 pl = self.groups[k].get_player_ids() |
2212 for p in pl: self.admin_kick(p,"Purged from server") | 2250 for p in pl: self.admin_kick(p,"Purged from server") |
2213 except Exception, e: | 2251 except Exception, e: |
2214 traceback.print_exc() | 2252 traceback.print_exc() |
2215 self.log_msg("Exception: kick_all_clients(): " + str(e)) | 2253 self.log_msg("Exception: kick_all_clients(): " + str(e)) |
2254 self.log_msg( ('exception', str(e)) ) | |
2216 | 2255 |
2217 """ | 2256 """ |
2218 # This really has little value as it will only catch people that are hung | 2257 # This really has little value as it will only catch people that are hung |
2219 # on a disconnect which didn't complete. Other idle connections which are | 2258 # on a disconnect which didn't complete. Other idle connections which are |
2220 # really dead go undeterred. | 2259 # really dead go undeterred. |
2236 if self.players[k].check_time_out(): | 2275 if self.players[k].check_time_out(): |
2237 self.log_msg("Player #" + k + " Lost connection!") | 2276 self.log_msg("Player #" + k + " Lost connection!") |
2238 self.admin_kick(k,"Removing dead client", self.silent_auto_kick) | 2277 self.admin_kick(k,"Removing dead client", self.silent_auto_kick) |
2239 except Exception, e: | 2278 except Exception, e: |
2240 self.log_msg("Exception: check_group_members(): " + str(e)) | 2279 self.log_msg("Exception: check_group_members(): " + str(e)) |
2280 self.log_msg( ('exception', str(e)) ) | |
2241 | 2281 |
2242 | 2282 |
2243 def remote_admin_handler(self,xml_dom,data): | 2283 def remote_admin_handler(self,xml_dom,data): |
2244 """ | 2284 """ |
2245 # handle incoming remove server admin messages | 2285 # handle incoming remove server admin messages |
2385 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'><i>[Unknown Remote Administration Command]</i>" | 2425 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'><i>[Unknown Remote Administration Command]</i>" |
2386 self.players[pid].outbox.put(msg) | 2426 self.players[pid].outbox.put(msg) |
2387 except Exception, e: | 2427 except Exception, e: |
2388 self.log_msg("Exception: Remote Admin Handler Error: " + str(e)) | 2428 self.log_msg("Exception: Remote Admin Handler Error: " + str(e)) |
2389 traceback.print_exc() | 2429 traceback.print_exc() |
2430 self.log_msg( ('exception', str(e)) ) | |
2390 | 2431 |
2391 def toggleRemoteKill(self): | 2432 def toggleRemoteKill(self): |
2392 if self.allowRemoteKill: self.allowRemoteKill = False | 2433 if self.allowRemoteKill: self.allowRemoteKill = False |
2393 else: self.allowRemoteKill = True | 2434 else: self.allowRemoteKill = True |
2394 return self.allowRemoteKill | 2435 return self.allowRemoteKill |
2552 pl +="<tr><td colspan='4' bgcolor=" + COLOR3 + " >Bad Player Ref (#" + id + ") in group" | 2593 pl +="<tr><td colspan='4' bgcolor=" + COLOR3 + " >Bad Player Ref (#" + id + ") in group" |
2553 pl+="</td></tr>" | 2594 pl+="</td></tr>" |
2554 pl += "<tr><td colspan='4' bgcolor=" + COLOR1 + ">" | 2595 pl += "<tr><td colspan='4' bgcolor=" + COLOR1 + ">" |
2555 pl += "<font color=" + COLOR4 + "><b><i>Statistics: groups: " + str(len(self.groups)) + " " | 2596 pl += "<font color=" + COLOR4 + "><b><i>Statistics: groups: " + str(len(self.groups)) + " " |
2556 pl += "players: " + str(len(self.players)) + "</i></b></font></td></tr></table>" | 2597 pl += "players: " + str(len(self.players)) + "</i></b></font></td></tr></table>" |
2557 except Exception, e: self.log_msg(str(e)) | 2598 except Exception, e: self.log_msg(str(e)); self.log_msg( ('exception', str(e)) ) |
2558 self.p_lock.release() | 2599 self.p_lock.release() |
2559 return pl | 2600 return pl |
2560 | 2601 |
2561 server = mplay_server() | 2602 server = mplay_server() |