comparison orpg/networking/mplay_server.py @ 224:29cf1a17ca16 alpha

Traipse Alpha 'OpenRPG' {100503-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) Finalizing!!! 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 Update to how display names are acquired Update to Server, added some 'Pious' technology 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 Fix to Server GUI's broadcast, room, player messaging
author sirebral
date Mon, 03 May 2010 01:44:38 -0500
parents d5ff505a2a16
children 24769389a7ba
comparison
equal deleted inserted replaced
223:d5ff505a2a16 224:29cf1a17ca16
888 print "'togglelobbysound' - Will turn on or off the Auto sending of a sound to all players who join the loby" 888 print "'togglelobbysound' - Will turn on or off the Auto sending of a sound to all players who join the loby"
889 print "'lobbysound' - Lets you specify which sound file to send to players joining the lobby" 889 print "'lobbysound' - Lets you specify which sound file to send to players joining the lobby"
890 print "'help' or '?' or 'h' - for this help message" 890 print "'help' or '?' or 'h' - for this help message"
891 print 891 print
892 892
893 def broadcast(self,msg): 893 def broadcast(self, msg):
894 self.send_to_all("0","<msg to='all' from='0' group_id='1'><font color='#FF0000'>" + msg + "</font></msg>") 894 broadcast = '<chat type="1" version="1.0"><font color="#FF0000">' +msg+ '</font></chat>'
895 chat = Element('chat')
896 chat.set('type', '1')
897 chat.set('version', '1.0')
898 chat.text = broadcast
899 msg = self.buildMsg('all', '0', '1', tostring(chat))
900 self.send_to_all('0', msg)
895 901
896 def console_log(self): 902 def console_log(self):
897 if self.log_to_console == 1: 903 if self.log_to_console == 1:
898 print "console logging now off" 904 print "console logging now off"
899 self.log_to_console = 0 905 self.log_to_console = 0
1116 (remote_host,remote_port) = newsock.getpeername() 1122 (remote_host,remote_port) = newsock.getpeername()
1117 bad_xml_string = "Your client sent an illegal message to the server and will be disconnected. " 1123 bad_xml_string = "Your client sent an illegal message to the server and will be disconnected. "
1118 bad_xml_string += "Please report this bug to the development team at:<br /> " 1124 bad_xml_string += "Please report this bug to the development team at:<br /> "
1119 bad_xml_string += "<a href='http://www.assembla.com/spaces/traipse_dev/tickets/'>Traipse-Dev " 1125 bad_xml_string += "<a href='http://www.assembla.com/spaces/traipse_dev/tickets/'>Traipse-Dev "
1120 bad_xml_string += "(http://www.assembla.com/spaces/traipse_dev/tickets/)</a><br />" 1126 bad_xml_string += "(http://www.assembla.com/spaces/traipse_dev/tickets/)</a><br />"
1121 self.sendMsg( newsock, "<msg to='" +props['id']+ "' from='" +props['id']+ "' group_id='0' />" +bad_xml_string, 1127 msg = self.buildMsg(props['id'], props['id'], '0', bad_xml_string)
1122 new_stub.useCompression, new_stub.compressionType) 1128 self.sendMsg( newsock, msg, new_stub.useCompression, new_stub.compressionType)
1123 1129
1124 time.sleep(2) 1130 time.sleep(2)
1125 newsock.close() 1131 newsock.close()
1126 print "Error in parse found from " + str(remote_host) + ". Disconnected." 1132 print "Error in parse found from " + str(remote_host) + ". Disconnected."
1127 print " Offending data(" + str(len(data)) + "bytes)=" + data 1133 print " Offending data(" + str(len(data)) + "bytes)=" + data
1222 self.sendMsg( newsock, "<msg to='" + props['id'] + "' from='" + props['id'] + "' group_id='0' />" + err_string, new_stub.useCompression, new_stub.compressionType ) 1228 self.sendMsg( newsock, "<msg to='" + props['id'] + "' from='" + props['id'] + "' group_id='0' />" + err_string, new_stub.useCompression, new_stub.compressionType )
1223 time.sleep(2) 1229 time.sleep(2)
1224 newsock.close() 1230 newsock.close()
1225 1231
1226 # Display the lobby message 1232 # Display the lobby message
1227 print 'lobby message'
1228 self.SendLobbyMessage(newsock, props['id']) 1233 self.SendLobbyMessage(newsock, props['id'])
1229 1234
1230 def checkClientVersion(self, clientversion): 1235 def checkClientVersion(self, clientversion):
1231 minv = self.minClientVersion.split('.') 1236 minv = self.minClientVersion.split('.')
1232 cver = clientversion.split('.') 1237 cver = clientversion.split('.')
1867 xml_dom, data = ServerPlugins.preParseIncoming(xml_dom, data) 1872 xml_dom, data = ServerPlugins.preParseIncoming(xml_dom, data)
1868 ########################################################### 1873 ###########################################################
1869 to_id = xml_dom.get("to") 1874 to_id = xml_dom.get("to")
1870 from_id = xml_dom.get("from") 1875 from_id = xml_dom.get("from")
1871 group_id = xml_dom.get("group_id") 1876 group_id = xml_dom.get("group_id")
1872
1873 ## Backwards compatibility with older clients 1877 ## Backwards compatibility with older clients
1874 end = data.find(">") 1878 end = data.find(">")
1875 head = data[:end+1]
1876 msg = data[end+1:] 1879 msg = data[end+1:]
1877 if msg[-6:] == '</msg>': msg = msg[:-6] 1880 if msg[-6:] == '</msg>': msg = msg[:-6]
1878 if head[end-1:] == '/>': head = head[:end-2]+'>' 1881 data = msg
1879 data = head+msg+'</msg>'
1880 1882
1881 if from_id == "0" or len(from_id) == 0: 1883 if from_id == "0" or len(from_id) == 0:
1882 print "WARNING!! Message received with an invalid from_id. Message dropped." 1884 print "WARNING!! Message received with an invalid from_id. Message dropped."
1883 return None 1885 return None
1884 1886
1898 if group_id == '0': 1900 if group_id == '0':
1899 #attempt to change lobby map. Illegal operation. 1901 #attempt to change lobby map. Illegal operation.
1900 self.players[from_id].self_message('The lobby map may not be altered.') 1902 self.players[from_id].self_message('The lobby map may not be altered.')
1901 elif to_id.lower() == 'all': 1903 elif to_id.lower() == 'all':
1902 #valid map for all players that is not the lobby. 1904 #valid map for all players that is not the lobby.
1903 self.send_to_group(from_id,group_id,data) 1905 msg = self.buildMsg('all', from_id, group_id, data)
1904 self.groups[group_id].game_map.init_from_xml(data) 1906 self.send_to_group(from_id,group_id,msg)
1907 self.groups[group_id].game_map.init_from_xml(msg)
1905 else: 1908 else:
1906 #attempting to send map to specific individuals which is not supported. 1909 #attempting to send map to specific individuals which is not supported.
1907 self.players[from_id].self_message('Invalid map message. Message not sent to others.') 1910 self.players[from_id].self_message('Invalid map message. Message not sent to others.')
1908 1911
1909 elif msg[:6] == '<boot ': 1912 elif msg[:6] == '<boot ':
1913 msg = self.buildMsg('all', from_id, group_id, data)
1910 self.handle_boot(from_id,to_id,group_id,msg) 1914 self.handle_boot(from_id,to_id,group_id,msg)
1911 1915
1912 else: 1916 else:
1913 if to_id == 'all': 1917 if to_id == 'all':
1914 if self.groups[group_id].moderated and not self.groups[group_id].voice.has_key(from_id): 1918 if self.groups[group_id].moderated and not self.groups[group_id].voice.has_key(from_id):
1915 self.players[from_id].self_message('This room is moderated - message not sent to others') 1919 self.players[from_id].self_message('This room is moderated - message not sent to others')
1916 else: self.send_to_group(from_id,group_id,data) 1920 else:
1917 else: self.players[to_id].outbox.put(data) 1921 msg = self.buildMsg('all', from_id, group_id, data)
1922 self.send_to_group(from_id,group_id,msg)
1923 else:
1924 msg = self.buildMsg('all', from_id, group_id, data)
1925 self.players[to_id].outbox.put(msg)
1918 self.check_group_members(group_id) 1926 self.check_group_members(group_id)
1919 return 1927 return
1920 1928
1921 def sound_msg_handler(self, xml_dom, data): 1929 def sound_msg_handler(self, xml_dom, data):
1922 from_id = xml_dom.get("from") 1930 from_id = xml_dom.get("from")
2117 self.ban_list[ip]['ip'] = ip 2125 self.ban_list[ip]['ip'] = ip
2118 self.ban_list[ip]['name'] = self.players[id].name 2126 self.ban_list[ip]['name'] = self.players[id].name
2119 self.saveBanList() 2127 self.saveBanList()
2120 2128
2121 # Send a message to everyone in the victim's room, letting them know someone has been booted 2129 # Send a message to everyone in the victim's room, letting them know someone has been booted
2122 ban_msg = "<msg to='all' from='0' group_id='%s'/><font color='#FF0000'>Banning '(%s) %s' from server... %s</font>" % ( group_id, id, self.players[id].name, str(message)) 2130 msg = 'Banning ('+id+') '+self.players[id].name+' from server... </font>'
2131 msg = self.buildMsg('all', '0', group_id, msg)
2123 self.log_msg("ban_msg:" + ban_msg) 2132 self.log_msg("ban_msg:" + ban_msg)
2124 if (silent == 0): self.send_to_group("0", group_id, ban_msg) 2133 if (silent == 0): self.send_to_group("0", group_id, ban_msg)
2125 time.sleep( .1 ) 2134 time.sleep( .1 )
2126 2135
2127 self.log_msg("baning player " + str(id) + " from server.") 2136 self.log_msg("baning player " + str(id) + " from server.")
2280 self.admin_kick(k,"Removing dead client", self.silent_auto_kick) 2289 self.admin_kick(k,"Removing dead client", self.silent_auto_kick)
2281 except Exception, e: 2290 except Exception, e:
2282 self.log_msg("Exception: check_group_members(): " + str(e)) 2291 self.log_msg("Exception: check_group_members(): " + str(e))
2283 self.log_msg( ('exception', str(e)) ) 2292 self.log_msg( ('exception', str(e)) )
2284 2293
2294 def buildMsg(self, toId, fromId, roomId, data):
2295 msg = '<msg to="' +toId+ '" from="' +fromId+ '" group_id="' +roomId+ '">'
2296 msg += data+ '</msg>'
2297 return msg
2285 2298
2286 def remote_admin_handler(self,xml_dom,data): 2299 def remote_admin_handler(self,xml_dom,data):
2287 """ 2300 """
2288 # handle incoming remove server admin messages 2301 # handle incoming remove server admin messages
2289 # (allows basic administration of server from a remote client) 2302 # (allows basic administration of server from a remote client)
2328 2341
2329 #message now deemed 'authentic' 2342 #message now deemed 'authentic'
2330 #determine action to take based on command (cmd) 2343 #determine action to take based on command (cmd)
2331 if cmd == "list": 2344 if cmd == "list":
2332 #return player list to this user. 2345 #return player list to this user.
2333 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'>" + self.player_list_remote() 2346 msg = self.buildMsg(pid, '0', gid, self.player_list_remote())
2334 self.players[pid].outbox.put(msg) 2347 self.players[pid].outbox.put(msg)
2335 elif cmd == "banip": 2348 elif cmd == "banip":
2336 ip = xml_dom.get("bip") 2349 ip = xml_dom.get("bip")
2337 name = xml_dom.get("bname") 2350 name = xml_dom.get("bname")
2338 msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'> Banned: " + str(ip) 2351 msg = self.buildMsg(pid, '0', gid, str(ip))
2339 self.admin_banip(ip, name) 2352 self.admin_banip(ip, name)
2340 elif cmd == "ban": 2353 elif cmd == "ban":
2341 id = xml_dom.get("bid") 2354 id = xml_dom.get("bid")
2342 msg = "<msg to='" + id + "' from='0' group_id='" + gid + "'> Banned!" 2355 msg = self.buildMsg(id, '0', gid, 'Banned!')
2343 self.players[pid].outbox.put(msg) 2356 self.players[pid].outbox.put(msg)
2344 self.admin_ban(id, "") 2357 self.admin_ban(id, "")
2345 ### Alpha ### and untested 2358 ### Alpha ### and untested
2346 elif cmd == "boot": 2359 elif cmd == "boot":
2347 id = xml_dom.get("bid") 2360 id = xml_dom.get("bid")
2348 msg = "<msg to='" + id + "' from='0' group_id='" + gid + "'> Booted!" 2361 msg = self.buildMsg(id, '0', gid, 'Booted!!')
2349 self.players[pid].outbox.put(msg) 2362 self.players[pid].outbox.put(msg)
2350 self.admin_kick(id, "") 2363 self.admin_kick(id, "")
2351 ############# 2364 #############
2352 elif cmd == "unban": 2365 elif cmd == "unban":
2353 ip = xml_dom.get("ip") 2366 ip = xml_dom.get("ip")
2354 self.admin_unban(ip) 2367 self.admin_unban(ip)
2355 msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'> Unbaned: " + str(ip) 2368 msg = self.buildMsg(pid, '0', gid, str(ip))
2356 self.players[pid].outbox.put(msg) 2369 self.players[pid].outbox.put(msg)
2357 elif cmd == "banlist": 2370 elif cmd == "banlist":
2358 msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" + self.admin_banlist() 2371 msg = self.buildMsg(pid, '0', gid, self.admin_banlist())
2359 self.players[pid].outbox.put(msg) 2372 self.players[pid].outbox.put(msg)
2360 elif cmd == "killgroup": 2373 elif cmd == "killgroup":
2361 ugid = xml_dom.get("gid") 2374 ugid = xml_dom.get("gid")
2362 if ugid == "0": 2375 if ugid == "0":
2363 m = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" 2376 m + "Cannot Remove Lobby! Remote administrator request denied!"
2364 m += "Cannot Remove Lobby! Remote administrator request denied!" 2377 msg = self.buildMsg(pid, '0', gid, m)
2365 self.players[pid].outbox.put(m) 2378 self.players[pid].outbox.put(msg)
2366 else: 2379 else:
2367 result = self.prune_room(ugid) 2380 result = self.prune_room(ugid)
2368 msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" + str(result) 2381 msg = self.buildMsg(pid, '0', gid, str(result))
2369 self.players[pid].outbox.put(msg) 2382 self.players[pid].outbox.put(msg)
2370 2383
2371 elif cmd == "message": 2384 elif cmd == "message":
2372 tuid = xml_dom.get("to_id") 2385 tuid = xml_dom.get("to_id")
2373 msg = xml_dom.get("msg") 2386 msg = xml_dom.get("msg")
2374 pmsg = "<msg to='" + tuid + "' from='0' group_id='" + self.players[tuid].group_id + "' >" + msg 2387 pmsg = self.buildMsg(tuid, '0', self.players[tuid].group_id, msg)
2375 try: self.players[tuid].outbox.put(pmsg) 2388 try: self.players[tuid].outbox.put(pmsg)
2376 except: 2389 except:
2377 msg = "<msg to='" + pid + "' from='0' group_id='" + gid + ">Unknown Player ID: No message sent." 2390 msg = "Unknown Player ID: No message sent."
2391 msg = self.buildMsg(pid, '0', gid, msg)
2378 self.players[pid].outbox.put(msg) 2392 self.players[pid].outbox.put(msg)
2379 elif cmd == "broadcast": 2393 elif cmd == "broadcast":
2380 bmsg = xml_dom.get("msg") 2394 bmsg = xml_dom.get("msg")
2381 self.broadcast(bmsg) 2395 self.send_to_all('0', bmsg)
2382 elif cmd == "killserver" and self.allowRemoteKill: 2396 elif cmd == "killserver" and self.allowRemoteKill:
2383 #dangerous command..once server stopped it must be restarted manually 2397 #dangerous command..once server stopped it must be restarted manually
2384 self.kill_server() 2398 self.kill_server()
2385 elif cmd == "uptime": 2399 elif cmd == "uptime":
2386 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'>" + self.uptime(1) 2400 msg = self.uptime(1)
2401 msg = self.buildMsg(pid, '0', gid, msg)
2387 self.players[pid].outbox.put(msg) 2402 self.players[pid].outbox.put(msg)
2388 elif cmd == "help": 2403 elif cmd == "help":
2389 msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" 2404 msg = self.AdminHelpMessage()
2390 msg += self.AdminHelpMessage() 2405 msg = self.buildMsg(pid, '0', gid, msg)
2391 self.players[pid].outbox.put( msg) 2406 self.players[pid].outbox.put( msg)
2392 elif cmd == "roompasswords": 2407 elif cmd == "roompasswords":
2393 # Toggle if room passwords are allowed on this server 2408 # Toggle if room passwords are allowed on this server
2394 msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" 2409 msg = self.RoomPasswords()
2395 msg += self.RoomPasswords() 2410 msg = self.buildMsg(pid, '0', gid, msg)
2396 self.players[pid].outbox.put( msg) 2411 self.players[pid].outbox.put( msg)
2397 elif cmd == "createroom": 2412 elif cmd == "createroom":
2398 rm_name = xml_dom.get("name") 2413 rm_name = xml_dom.get("name")
2399 rm_pass = xml_dom.get("pass") 2414 rm_pass = xml_dom.get("pass")
2400 rm_boot = xml_dom.get("boot") 2415 rm_boot = xml_dom.get("boot")
2401 result = self.create_temporary_persistant_room(rm_name, rm_boot, rm_pass) 2416 result = self.create_temporary_persistant_room(rm_name, rm_boot, rm_pass)
2402 msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" + result 2417 msg = self.buildMsg(pid, '0', gid, result)
2403 self.players[pid].outbox.put(msg) 2418 self.players[pid].outbox.put(msg)
2404 elif cmd == "nameroom": 2419 elif cmd == "nameroom":
2405 rm_id = xml_dom.get("rmid") 2420 rm_id = xml_dom.get("rmid")
2406 rm_name = xml_dom.get("name") 2421 rm_name = xml_dom.get("name")
2407 result = self.change_group_name(rm_id,rm_name,pid) 2422 result = self.change_group_name(rm_id,rm_name,pid)
2408 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'/>" + result 2423 msg = self.buildMsg(pid, '0', gid, result)
2409 self.players[pid].outbox.put(msg) 2424 self.players[pid].outbox.put(msg)
2410 elif cmd == "passwd": 2425 elif cmd == "passwd":
2411 tgid = xml_dom.get("gid") 2426 tgid = xml_dom.get("gid")
2412 npwd = xml_dom.get("pass") 2427 npwd = xml_dom.get("pass")
2413 if tgid == "0": 2428 if tgid == "0":
2414 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'>" 2429 msg = "Server password may not be changed remotely!"
2415 msg += "Server password may not be changed remotely!" 2430 msg = self.buildMsg(pid, '0', gid, msg)
2416 self.players[pid].outbox.put(msg) 2431 self.players[pid].outbox.put(msg)
2417 else: 2432 else:
2418 try: 2433 try:
2419 self.groups[tgid].boot_pwd = npwd 2434 self.groups[tgid].boot_pwd = npwd
2420 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'>Password changed for room " + tgid 2435 msg = "Password changed for room " + tgid
2436 msg = self.buildMsg(pid, '0', gid, msg)
2421 self.players[pid].outbox.put(msg) 2437 self.players[pid].outbox.put(msg)
2422 except: pass 2438 except: pass
2423 elif cmd == "savemaps": 2439 elif cmd == "savemaps":
2424 for g in self.groups.itervalues(): g.save_map() 2440 for g in self.groups.itervalues(): g.save_map()
2425 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'>Persistent room maps saved" 2441 msg = "Persistent room maps saved"
2442 msg = self.buildMsg(pid, '0', gid, msg)
2426 self.players[pid].outbox.put(msg) 2443 self.players[pid].outbox.put(msg)
2427 else: 2444 else:
2428 msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'><i>[Unknown Remote Administration Command]</i>" 2445 msg = "<i>[Unknown Remote Administration Command]</i>"
2446 msg = self.buildMsg(pid, '0', gid, msg)
2429 self.players[pid].outbox.put(msg) 2447 self.players[pid].outbox.put(msg)
2430 except Exception, e: 2448 except Exception, e:
2431 self.log_msg("Exception: Remote Admin Handler Error: " + str(e)) 2449 self.log_msg("Exception: Remote Admin Handler Error: " + str(e))
2432 traceback.print_exc() 2450 traceback.print_exc()
2433 self.log_msg( ('exception', str(e)) ) 2451 self.log_msg( ('exception', str(e)) )
2600 pl += "players: " + str(len(self.players)) + "</i></b></font></td></tr></table>" 2618 pl += "players: " + str(len(self.players)) + "</i></b></font></td></tr></table>"
2601 except Exception, e: self.log_msg(str(e)); self.log_msg( ('exception', str(e)) ) 2619 except Exception, e: self.log_msg(str(e)); self.log_msg( ('exception', str(e)) )
2602 self.p_lock.release() 2620 self.p_lock.release()
2603 return pl 2621 return pl
2604 2622
2605 server = mplay_server() 2623 server = mplay_server()