Mercurial > traipse_dev
diff orpg/networking/mplay_server.py @ 135:dcf4fbe09b70 beta
Traipse Beta 'OpenRPG' {091010-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 (Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
**Pretty important update that can help remove thousands of dead children from your gametree.
**Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and
look for dead children!!
**New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author | sirebral |
---|---|
date | Tue, 10 Nov 2009 14:11:28 -0600 |
parents | 7ed4979cc1cf |
children | e842a5f1b775 |
line wrap: on
line diff
--- a/orpg/networking/mplay_server.py Fri Sep 25 20:47:16 2009 -0500 +++ b/orpg/networking/mplay_server.py Tue Nov 10 14:11:28 2009 -0600 @@ -31,6 +31,8 @@ # 04-15-2005 [Snowdog]: Added patch from Brandan Yares (xeriar). Reference: patch tracker id #1182076 +from __future__ import with_statement + __version__ = "$Id: mplay_server.py,v 1.155 2008/01/24 03:52:03 digitalxero Exp $" #!/usr/bin/env python @@ -43,14 +45,7 @@ <role action='set,get,display' player='' group_id='' boot_pwd='' role=''/> """ -import re -import gc -import cgi -import sys -import string -import time -import urllib -import traceback +import re, gc, cgi, sys, string, time, urllib, traceback from mplay_client import * from mplay_client import MPLAY_LENSIZE @@ -62,8 +57,11 @@ from struct import pack, unpack, calcsize from meta_server_lib import * -# Import the minidom XML module -from xml.dom import minidom +from xml.etree.ElementTree import ElementTree, Element, iselement +from xml.etree.ElementTree import fromstring, tostring, parse, XML + +from orpg.tools.orpg_log import logger, crash, debug +from orpg.tools.decorators import debugging # Snag the version number from orpg.orpg_version import VERSION, PROTOCOL_VERSION, CLIENT_STRING, SERVER_MIN_CLIENT_VERSION @@ -77,7 +75,8 @@ class game_group(object): - def __init__( self, id, name, pwd, desc="", boot_pwd="", minVersion="", mapFile=None, messageFile=None, persist =0 ): + def __init__(self, id, name, pwd, desc="", boot_pwd="", + minVersion="", mapFile=None, messageFile=None, persist=0): self.id = id self.name = name self.desc = desc @@ -92,19 +91,16 @@ self.voice = {} self.persistant = persist self.mapFile = None - + ### Needs to use Element Tree closer if mapFile != None: - self.mapFile = mapFile f = open( mapFile ) tree = f.read() f.close() - else: - f = open(dir_struct["template"] + "default_map.xml") + f = open(orpg.dirpath.dir_struct["template"] + "default_map.xml") tree = f.read() f.close() - - self.game_map.init_from_xml(tree) + self.game_map.init_from_xml(fromstring(tree)) def save_map(self): if self.mapFile is not None and self.persistant == 1 and self.mapFile.find("default_map.xml") == -1: @@ -116,8 +112,7 @@ self.players.append(id) def remove_player(self,id): - if self.voice.has_key(id): - del self.voice[id] + if self.voice.has_key(id): del self.voice[id] self.players.remove(id) def get_num_players(self): @@ -149,18 +144,18 @@ return 1 #depreciated - see send_group_list() - def toxml(self,act="new"): + def toxml(self, act="new"): # Please don't add the boot_pwd to the xml, as this will give it away to players watching their console - xml_data = "<group id=\"" + self.id - xml_data += "\" name=\"" + self.name - xml_data += "\" pwd=\"" + str(self.pwd!="") - xml_data += "\" players=\"" + str(self.get_num_players()) - xml_data += "\" action=\"" + act + "\" />" - return xml_data - + el = Element('group') + el.set('id', self.id) + el.set('name', self.name) + el.set('pwd', str(self.pwd!="")) + el.set('players', str(self.get_num_players())) + el.set('action', act) + return tostring(el) class client_stub(client_base): - def __init__(self,inbox,sock,props,log): + def __init__(self, inbox, sock, props, log): client_base.__init__(self) self.ip = props['ip'] self.role = props['role'] @@ -190,11 +185,16 @@ if diff > 1800: return 1 else: return 0 - def send(self,msg,player,group): + def send(self, msg, player, group): if self.get_status() == MPLAY_CONNECTED: + #el = Element('msg') + #el.set('to', player) + #el.set('from', '0') + #el.set('group_id', group) + #el.text(msg) self.outbox.put("<msg to='" + player + "' from='0' group_id='" + group + "' />" + msg) - def change_group(self,group_id,groups): + def change_group(self, group_id, groups): old_group_id = str(self.group_id) groups[group_id].add_player(self.id) groups[old_group_id].remove_player(self.id) @@ -205,11 +205,11 @@ return old_group_id def self_message(self,act): - self.send(act,self.id,self.group_id) + self.send(act, self.id, self.group_id) def take_dom(self,xml_dom): - self.name = xml_dom.getAttribute("name") - self.text_status = xml_dom.getAttribute("status") + self.name = xml_dom.get("name") + self.text_status = xml_dom.get("status") """ ###################################################################### @@ -225,6 +225,8 @@ class mplay_server: def __init__(self, log_console=None, name=None): + logger._set_log_level = 16 + logger._set_log_to_console(True) self.log_to_console = 1 self.log_console = log_console self.alive = 1 @@ -238,9 +240,9 @@ self.next_group_id = 100 self.metas = {} # This holds the registerThread objects for each meta self.be_registered = 0 # Status flag for whether we want to be registered. - self.serverName = name # Name of this server in the metas + self.serverName = name # Name of this server in the metas self.boot_pwd = "" - self.server_address = None # IP or Name of server to post to the meta. None means the meta will auto-detect it. + self.server_address = None # IP or Name of server to post to the meta. None means the meta will auto-detect it. self.defaultMessageFile = None self.userPath = dir_struct["user"] self.lobbyMapFile = "Lobby_map.xml" @@ -316,13 +318,13 @@ # try to use it. try: - self.banDom = minidom.parse(self.userPath + 'ban_list.xml') - self.banDom.normalize() - self.banDoc = self.banDom.documentElement + self.banDom = parse(self.userPath + 'ban_list.xml') + #self.banDom.normalize() + self.banDoc = self.banDom.getroot() - for element in self.banDom.getElementsByTagName('banned'): - playerName = element.getAttribute( 'name' ).replace("&", "&").replace("<", "<").replace('"', """).replace(">", ">") - playerIP = element.getAttribute('ip') + for element in self.banDom.findall('banned'): + playerName = element.get('name').replace("&", "&").replace("<", "<").replace('"', """).replace(">", ">") + playerIP = element.get('ip') self.ban_list[playerIP] = {} self.ban_list[playerIP]['ip'] = playerIP self.ban_list[playerIP]['name'] = playerName @@ -337,50 +339,49 @@ # try to use it. try: - data = [] - data.append("<server>\n") + etreeEl = Element('server') for ip in self.ban_list: - data.append(' <banned name="' + str(self.ban_list[ip]['name'].replace("&", "&").replace("<", "<").replace(""", '"').replace(">", ">")) + '" ip="' + str(self.ban_list[ip]['ip']) + '" />' + "\n") - data.append("</server>") + el = Element('banned') + el.set('name', str(self.ban_list[ip]['name'].replace("&", "&").replace("<", "<").replace(""", '"').replace(">", ">"))) + el.set('ip', str(self.ban_list[ip]['ip'])) + etreeEl.append(el) file = open(self.userPath + self.banFile ,"w") - file.write("".join(data)) + file.write(tostring(etreeEl)) file.close() except Exception, e: self.log_msg("Exception in saveBanList() " + str(e)) # This method reads in the server's configuration file and reconfigs the server # as needed, over-riding any default values as requested. + def initServerConfig(self): + debug(log=False) self.log_msg("Processing Server Configuration File... " + self.userPath) # make sure the server_ini.xml exists! validate.config_file( "server_ini.xml", "default_server_ini.xml" ) # try to use it. try: - self.configDom = minidom.parse(self.userPath + 'server_ini.xml') - self.configDom.normalize() - self.configDoc = self.configDom.documentElement - + self.configDom = parse(self.userPath + 'server_ini.xml') + #self.configDom.normalize() + self.configDoc = self.configDom.getroot() if hasattr(self, 'bootPassword'): self.boot_pwd = self.bootPassword - else: - if self.configDoc.hasAttribute("admin"): self.boot_pwd = self.configDoc.getAttribute("admin") - elif self.configDoc.hasAttribute("boot"): self.boot_pwd = self.configDoc.getAttribute("boot") - + if self.configDoc.get("admin"): self.boot_pwd = self.configDoc.get("admin") + elif self.configDoc.get("boot"): self.boot_pwd = self.configDoc.get("boot") if len(self.boot_pwd) < 1: self.boot_pwd = raw_input("Enter admin password: ") - - if not hasattr(self, 'reg') and self.configDoc.hasAttribute("register"): - self.reg = self.configDoc.getAttribute("register") + if not hasattr(self, 'reg') and self.configDoc.get("register"): + self.reg = self.configDoc.get("register") if not len(self.reg) > 0 or self.reg[0].upper() not in ("Y", "N"): opt = raw_input("Do you want to post your server to the OpenRPG Meta Server list? (y,n) ") if len(opt) and (opt[0].upper() == 'Y'): self.reg = 'Y' else: self.reg = 'N' LobbyName = 'Lobby' - if self.configDoc.hasAttribute("lobbyname"): LobbyName = self.configDoc.getAttribute("lobbyname") - map_node = service_node = self.configDoc.getElementsByTagName("map")[0] - msg_node = service_node = self.configDoc.getElementsByTagName("message")[0] - mapFile = map_node.getAttribute('file') - msgFile = msg_node.getAttribute('file') + if self.configDoc.get("lobbyname"): LobbyName = self.configDoc.get("lobbyname") + map_node = service_node = self.configDoc.findall("map")[0] + msg_node = service_node = self.configDoc.findall("message")[0] + mapFile = map_node.get('file') + msgFile = msg_node.get('file') if mapFile == '': mapFile = 'Lobby_map.xml' if msgFile == '': msgFile = 'LobbyMessage.html' # Update the lobby with the passwords if they've been specified @@ -392,15 +393,15 @@ } # set ip or dns name to send to meta server - service_node = self.configDoc.getElementsByTagName("service")[0] - address = service_node.getAttribute("address") + service_node = self.configDoc.findall("service")[0] + address = service_node.get("address") address = address.lower() if address == "" or address == "hostname/address" or address == "localhost": self.server_address = None else: self.server_address = address self.server_port = OPENRPG_PORT - if service_node.hasAttribute("port"): self.server_port = int(service_node.getAttribute("port")) - if self.configDoc.hasAttribute("name") and len(self.configDoc.getAttribute("name")) > 0 : - self.name = self.configDoc.getAttribute("name") + if service_node.get("port"): self.server_port = int(service_node.get("port")) + if self.configDoc.get("name") and len(self.configDoc.get("name")) > 0 : + self.name = self.configDoc.get("name") else: if self.reg[0].upper() == "Y": if self.name == None: self.name = raw_input("Server Name? ") @@ -414,8 +415,8 @@ """ try: - mver = self.configDoc.getElementsByTagName("version")[0] - self.minClientVersion = mver.getAttribute("min") + mver = self.configDoc.findall("version")[0] + self.minClientVersion = mver.get("min") except: self.minClientVersion = SERVER_MIN_CLIENT_VERSION #from orpg/orpg_version.py self.defaultMessageFile = "" # This try/except bit is to allow older versions of python to continue without a list error. @@ -431,13 +432,13 @@ """ try: - ak = self.configDoc.getElementsByTagName("autokick")[0] - if ak.hasAttribute("silent"): - if ((ak.getAttribute("silent")).lower() == "yes"): self.silent_auto_kick = 1 + ak = self.configDoc.findall("autokick")[0] + if ak.get("silent"): + if ((ak.get("silent")).lower() == "yes"): self.silent_auto_kick = 1 else: self.silent_auto_kick = 0 - if ak.hasAttribute("delay"): + if ak.get("delay"): try: - delay = int(ak.getAttribute("delay")) + delay = int(ak.get("delay")) self.zombie_time = delay except: #delay value cannot be converted into an int use defaut @@ -474,28 +475,28 @@ #pull information from config file DOM try: - roomdefaults = self.configDom.getElementsByTagName("room_defaults")[0] + roomdefaults = self.configDom.findall("room_defaults")[0] #rd.normalize() #roomdefaults = self.rd.documentElement try: - setting = roomdefaults.getElementsByTagName('passwords')[0] - rpw = setting.getAttribute('allow') + setting = roomdefaults.findall('passwords')[0] + rpw = setting.get('allow') if rpw == "no" or rpw == "0": roomdefault_pass = 0 self.log_msg("Room Defaults: Disallowing Passworded Rooms") else: self.log_msg("Room Defaults: Allowing Passworded Rooms") except: self.log_msg("Room Defaults: [Warning] Allowing Passworded Rooms") try: - setting = roomdefaults.getElementsByTagName('map')[0] - map = setting.getAttribute('file') + setting = roomdefaults.findall('map')[0] + map = setting.get('file') if map != "": roomdefault_map = self.userPath + map.replace("myfiles/", "") self.log_msg("Room Defaults: Using " + str(map) + " for room map") except: self.log_msg("Room Defaults: [Warning] Using Default Map") try: - setting = roomdefaults.getElementsByTagName('message')[0] - msg = setting.getAttribute('file') + setting = roomdefaults.findall('message')[0] + msg = setting.get('file') if msg != "": if msg[:4].lower() == 'http': roomdefault_msg = msg else: roomdefault_msg = self.userPath + msg.replace("myfiles/", "") @@ -520,16 +521,16 @@ ###Server Cheat message try: - cheat_node = self.configDoc.getElementsByTagName("cheat")[0] - self.cheat_msg = cheat_node.getAttribute("text") + cheat_node = self.configDoc.findall("cheat")[0] + self.cheat_msg = cheat_node.get("text") except: self.cheat_msg = "**FAKE ROLL**" self.log_msg("**WARNING** <cheat txt=\"\"> tag missing from server configuration file. Using empty string.") # should validate protocal - validate_protocol_node = self.configDom.getElementsByTagName("validate_protocol ") + validate_protocol_node = self.configDom.findall("validate_protocol") self.validate_protocol = 1 - if(validate_protocol_node): self.validate_protocol = (validate_protocol_node[0].getAttribute("value") == "True") + if(validate_protocol_node): self.validate_protocol = (validate_protocol_node[0].get("value") == "True") if(self.validate_protocol != 1): self.log_msg("Protocol Validation: OFF") self.makePersistentRooms() self.log_msg("Server Configuration File: Processing Completed.") @@ -539,28 +540,28 @@ def makePersistentRooms(self): 'Creates rooms on the server as defined in the server config file.' - for element in self.configDom.getElementsByTagName('room'): - roomName = element.getAttribute('name') - roomPassword = element.getAttribute('password') - bootPassword = element.getAttribute('boot') + for element in self.configDom.findall('room'): + roomName = element.get('name') + roomPassword = element.get('password') + bootPassword = element.get('boot') # Conditionally check for minVersion attribute - if element.hasAttribute('minVersion'): minVersion = element.getAttribute('minVersion') + if element.get('minVersion'): minVersion = element.get('minVersion') else: minVersion = "" # Extract the map filename attribute from the map node # we only care about the first map element found -- others are ignored - mapElement = element.getElementsByTagName('map')[0] - mapFile = self.userPath + mapElement.getAttribute('file').replace("myfiles/", "") - messageElement = element.getElementsByTagName('message')[0] - messageFile = messageElement.getAttribute('file') + mapElement = element.findall('map')[0] + mapFile = self.userPath + mapElement.get('file').replace("myfiles/", "") + messageElement = element.findall('message')[0] + messageFile = messageElement.get('file') if messageFile[:4] != 'http': messageFile = self.userPath + messageFile.replace("myfiles/", "") # Make sure we have a message to even mess with if(len(messageFile) == 0): messageFile = self.defaultMessageFile if(len(mapFile) == 0): mapFile = self.defaultMapFile moderated = 0 - if element.hasAttribute('moderated') and element.getAttribute('moderated').lower() == "true": moderated = 1 + if element.get('moderated') and element.get('moderated').lower() == "true": moderated = 1 #create the new persistant group self.new_group(roomName, roomPassword, @@ -620,7 +621,7 @@ elif self.log_network_messages == 2: return "Network Traffic Log: Logging (inbound/outbound files)" else: self.log_msg("Network Traffic Log: [Unknown]") - def register_callback(instance, xml_dom = None,source=None): + def register_callback(instance, xml_dom = None, source=None): if xml_dom: # if we get something if source == getMetaServerBaseURL(): # if the source of this DOM is the authoritative meta try: @@ -666,7 +667,7 @@ id, cookie = self.metas[meta].getIdAndCookie() data = urllib.urlencode( {"room_data[server_id]":id, "act":'registerrooms'}) - get_server_dom(data+'&'+rooms, self.metas[meta].path) + get_server_dom(data+'&'+rooms, self.metas[meta].path, string=True) def register(self,name_given=None): if name_given == None: name = self.name @@ -757,21 +758,21 @@ data = ServerPlugins.preParseOutgoing() for msg in data: try: - xml_dom = parseXml(msg) - xml_dom = xml_dom._get_documentElement() - if xml_dom.hasAttribute('from') and int(xml_dom.getAttribute('from')) > -1: - xml_dom.setAttribute('from', '-1') - xml_dom.setAttribute('to', 'all') + #xml_dom = parseXml(msg) + xml_dom = fromstring(msg).getroot() + if xml_dom.get('from') and int(xml_dom.get('from')) > -1: + xml_dom.set('from', '-1') + xml_dom.set('to', 'all') self.incoming_msg_handler(xml_dom, msg) - xml_dom.unlink() + #xml_dom.unlink() except: pass self.p_lock.release() time.sleep(0.250) def sendMsg( self, sock, msg, useCompression=False, cmpType=None): - """Very simple function that will properly encode and send a message to te + """Very simple function that will properly encode and send a message to the remote on the specified socket.""" - if useCompression and cmpType != None: + if not useCompression and cmpType != None: mpacket = cmpType.compress(msg) lpacket = pack('!i', len(mpacket)) sock.send(lpacket) @@ -859,6 +860,7 @@ self.log_msg("Server stopped!") def log_msg(self,msg): + debug(parents=True) if self.log_to_console: if self.log_console: self.log_console(msg) else: print str(msg) @@ -899,7 +901,7 @@ print def broadcast(self,msg): - self.send_to_all("0","<msg to='all' from='0' group_id='1'><font color='#FF0000'>" + msg + "</font>") + self.send_to_all("0","<msg to='all' from='0' group_id='1'><font color='#FF0000'>" + msg + "</font></msg>") def console_log(self): if self.log_to_console == 1: @@ -959,6 +961,10 @@ elif self.players[id].protocol_version.find(patern)>-1: self.print_player_info(self.players[id]) elif self.players[id].client_string.find(patern)>-1: self.print_player_info(self.players[id]) + def obtain_by_id(self, id, objects): + ### Alpha ### Basic way to obtain information for the Server GUI, currently reports the Client String only + return self.players[id].client_string + def print_player_info(self,player): print player.id, player.name, player.ip, player.group_id, player.role, player.version, player.protocol_version, player.client_string @@ -1055,13 +1061,13 @@ self.log_msg(str(e)) self.p_lock.release() - def update_request(self,newsock,xml_dom): + def update_request(self,newsock, xml_dom): # handle reconnects self.log_msg( "update_request() has been called." ) # get player id - id = xml_dom.getAttribute("id") - group_id = xml_dom.getAttribute("group_id") + id = xml_dom.get("id") + group_id = xml_dom.get("group_id") self.p_lock.acquire() if self.players.has_key(id): self.sendMsg(newsock, self.players[id].toxml("update"), @@ -1072,33 +1078,31 @@ need_new = 0 else: need_new = 1 self.p_lock.release() - if need_new: self.new_request(newsock,xml_dom) + if need_new: self.new_request(newsock, xml_dom) else: msg = self.groups[group_id].game_map.get_all_xml() self.send(msg,id,group_id) - def new_request(self,newsock,xml_dom,LOBBY_ID='0'): + def new_request(self,newsock, xml_dom, LOBBY_ID='0'): #build client stub props = {} # Don't trust what the client tells us...trust what they connected as! props['ip'] = socket.gethostbyname( newsock.getpeername()[0] ) - try: props['role'] = xml_dom.getAttribute("role") - except: props['role'] = "GM" - - props['name'] = xml_dom.getAttribute("name") + props['role'] = xml_dom.get("role") or 'GM' + props['name'] = xml_dom.get("name") props['group_id'] = LOBBY_ID props['id'] = str(self.next_player_id) - props['version'] = xml_dom.getAttribute("version") - props['protocol_version'] = xml_dom.getAttribute("protocol_version") - props['client_string'] = xml_dom.getAttribute("client_string") + props['version'] = xml_dom.get("version") + props['protocol_version'] = xml_dom.get("protocol_version") + props['client_string'] = xml_dom.get("client_string") self.next_player_id += 1 - new_stub = client_stub(self.incoming,newsock,props,self.log_console) - if xml_dom.hasAttribute('useCompression'): + new_stub = client_stub(self.incoming, newsock, props, self.log_console) + if xml_dom.get('useCompression'): new_stub.useCompression = True - if xml_dom.hasAttribute('cmpType'): - cmpType = xml_dom.getAttribute('cmpType') + if xml_dom.get('cmpType'): + cmpType = xml_dom.get('cmpType') if cmpBZ2 and cmpType == 'bz2': new_stub.compressionType = bz2 elif cmpZLIB and cmpType == 'zlib': new_stub.compressionType = zlib else: new_stub.compressionType = None @@ -1110,14 +1114,14 @@ self.sendMsg(newsock, new_stub.toxml("new"), False, None) # try to remove circular refs - if xml_dom: - xml_dom.unlink() + #if xml_dom: + # xml_dom.unlink() # send confirmation data = self.recvMsg(newsock, new_stub.useCompression, new_stub.compressionType) try: - xml_dom = parseXml(data) - xml_dom = xml_dom._get_documentElement() + xml_dom = XML(data) + #xml_dom = xml_dom._get_documentElement() except Exception, e: print e (remote_host,remote_port) = newsock.getpeername() @@ -1132,7 +1136,7 @@ print "Error in parse found from " + str(remote_host) + ". Disconnected." print " Offending data(" + str(len(data)) + "bytes)=" + data print "Exception=" + str(e) - if xml_dom: xml_dom.unlink() + #if xml_dom: xml_dom.unlink() return #start threads and store player @@ -1161,8 +1165,7 @@ time.sleep(1) self.log_msg("Connection terminating due to version incompatibility with client (ver: " + props['version'] + " protocol: " + props['protocol_version'] + ")" ) newsock.close() - if xml_dom: - xml_dom.unlink() + #if xml_dom: xml_dom.unlink() return None ip = props['ip'] @@ -1175,8 +1178,7 @@ # Give messages time to flow time.sleep(1) newsock.close() - if xml_dom: - xml_dom.unlink() + #if xml_dom: xml_dom.unlink() return None """ @@ -1194,7 +1196,7 @@ """ try: - if xml_dom.getAttribute("id") == props['id']: + if xml_dom.get("id") == props['id']: new_stub.initialize_threads() self.p_lock.acquire() self.players[props['id']] = new_stub @@ -1203,12 +1205,12 @@ self.send_player_list(props['id'],LOBBY_ID) self.p_lock.release() msg = self.groups[LOBBY_ID].game_map.get_all_xml() - self.send(msg,props['id'],LOBBY_ID) - self.send_to_group(props['id'],LOBBY_ID,self.players[props['id']].toxml('new')) - self.return_room_roles(props['id'],LOBBY_ID) + self.send(msg, props['id'], LOBBY_ID) + self.send_to_group(props['id'], LOBBY_ID, self.players[props['id']].toxml('new')) + self.return_room_roles(props['id'], LOBBY_ID) # Re-initialize the role for this player incase they came from a different server - self.handle_role("set",props['id'], "GM",self.groups[LOBBY_ID].boot_pwd, LOBBY_ID) + self.handle_role("set", props['id'], "GM", self.groups[LOBBY_ID].boot_pwd, LOBBY_ID) cmsg = "Client Connect: (" + str(props['id']) + ") " + str(props['name']) + " [" + str(props['ip']) + "]" self.log_msg(cmsg) cmsg = ("connect", props) ################################################# @@ -1223,7 +1225,7 @@ #something didn't go right. Notify client and drop the connection err_string = "<center>" - err_string += "<hr><b>The server has encountered an error while processing your connection request.</b><hr>" + err_string += "<hr><b>The server has encountered an error while processing your connection request.</b><hr>" err_string += "<br /><i>You are being disconnected from the server.</i><br />" err_string += "This error may represent a problem with the server. If you continue to get this message " err_string += "please contact the servers administrator to correct the issue.</center> " @@ -1233,8 +1235,7 @@ # Display the lobby message self.SendLobbyMessage(newsock,props['id']) - if xml_dom: - xml_dom.unlink() + #if xml_dom: xml_dom.unlink() def checkClientVersion(self, clientversion): minv = self.minClientVersion.split('.') @@ -1258,10 +1259,8 @@ lobbyMsg += "server, version '" + VERSION + "'" # See if we have a server name to report! - if len(self.serverName): - lobbyMsg += ", named '" + self.serverName + "'." - else: - lobbyMsg += "." + if len(self.serverName): lobbyMsg += ", named '" + self.serverName + "'." + else: lobbyMsg += "." # Add extra line spacing lobbyMsg += "\n\n" @@ -1343,8 +1342,7 @@ except: pass return #returning causes connection thread instance to terminate # Clear out the xml_dom in preparation for new stuff, if necessary - try: - if xml_dom: xml_dom.unlink() + """try: if xml_dom: xml_dom.unlink() except: self.log_msg( "The following exception caught unlinking xml_dom:") @@ -1352,10 +1350,10 @@ try: newsock.close() except: pass return #returning causes connection thread instance to terminate - # Parse the XML received from the connecting client + # Parse the XML received from the connecting client""" try: - xml_dom = parseXml(data) - xml_dom = xml_dom._get_documentElement() + xml_dom = XML(data) + #xml_dom = xml_dom._get_documentElement() except: try: newsock.close() @@ -1369,11 +1367,11 @@ # Determine the correct action and execute it try: # get action - action = xml_dom.getAttribute("action") + action = xml_dom.get("action") # Figure out what type of connection we have going on now - if action == "new": self.new_request(newsock,xml_dom) - elif action == "update": self.update_request(newsock,xml_dom) + if action == "new": self.new_request(newsock, xml_dom) + elif action == "update": self.update_request(newsock, xml_dom) else: self.log_msg("Unknown Join Request!") except Exception, e: @@ -1383,12 +1381,12 @@ return #returning causes connection thread instance to terminate # Again attempt to clean out DOM stuff - try: - if xml_dom: xml_dom.unlink() + """ + try: if xml_dom: xml_dom.unlink() except: print "The following exception caught unlinking xml_dom:" traceback.print_exc() - return #returning causes connection thread instance to terminate + return #returning causes connection thread instance to terminate""" """ #======================================================== @@ -1402,7 +1400,7 @@ # and player load capacity -- Snowdog 3/04 """ - def message_handler(self,arg): + def message_handler(self, arg): xml_dom = None self.log_msg( "message handler thread running..." ) while self.alive: @@ -1422,40 +1420,40 @@ data = None except Exception, e: self.log_msg(str(e)) - if xml_dom: xml_dom.unlink() - if xml_dom: xml_dom.unlink() + #if xml_dom: xml_dom.unlink() + #if xml_dom: xml_dom.unlink() self.log_msg("message handler thread exiting...") self.incoming_event.set() - def parse_incoming_dom(self,data): + def parse_incoming_dom(self, data): + #debug((data, tostring(data) if iselement(data) else 'None element')) Sometimes I catch an error. end = data.find(">") #locate end of first element of message head = data[:end+1] #self.log_msg(head) xml_dom = None try: - xml_dom = parseXml(head) - xml_dom = xml_dom._get_documentElement() - self.message_action(xml_dom,data) + xml_dom = XML(head) + #xml_dom = xml_dom._get_documentElement() + self.message_action(xml_dom, data) except Exception, e: print "Error in parse of inbound message. Ignoring message." print " Offending data(" + str(len(data)) + "bytes)=" + data print "Exception=" + str(e) - if xml_dom: xml_dom.unlink() - + def message_action(self, xml_dom, data): - tag_name = xml_dom._get_tagName() - if self.svrcmds.has_key(tag_name): self.svrcmds[tag_name]['function'](xml_dom,data) + tag_name = xml_dom.tag + if self.svrcmds.has_key(tag_name): self.svrcmds[tag_name]['function'](xml_dom, data) else: raise Exception, "Not a valid header!" #Message Action thread expires and closes here. return def do_alter(self, xml_dom, data): - target = xml_dom.getAttribute("key") - value = xml_dom.getAttribute("val") - player = xml_dom.getAttribute("plr") - group_id = xml_dom.getAttribute("gid") - boot_pwd = xml_dom.getAttribute("bpw") + target = xml_dom.get("key") or 'None' + value = xml_dom.get("val") or 'None' + player = xml_dom.get("plr") or 'None' + group_id = xml_dom.get("gid") or 'None' + boot_pwd = xml_dom.get("bpw") or 'None' actual_boot_pwd = self.groups[group_id].boot_pwd if self.allow_room_passwords == 0: @@ -1474,7 +1472,7 @@ elif target == "name": # Check for & in name. We want to allow this because of its common # use in d&d games - result = self.change_group_name(group_id,value,player) + result = self.change_group_name(group_id, value, player) msg ="<msg to='" + player + "' from='0' group_id='0' />" + result self.players[player].outbox.put(msg) else: @@ -1484,39 +1482,39 @@ def do_role(self, xml_dom, data): role = "" boot_pwd = "" - act = xml_dom.getAttribute("action") - player = xml_dom.getAttribute("player") - group_id = xml_dom.getAttribute("group_id") + act = xml_dom.get("action") + player = xml_dom.get("player") + group_id = xml_dom.get("group_id") if act == "set": - role = xml_dom.getAttribute("role") - boot_pwd = xml_dom.getAttribute("boot_pwd") - xml_dom.unlink() + role = xml_dom.get("role") + boot_pwd = xml_dom.get("boot_pwd") + #xml_dom.unlink() if group_id != "0": self.handle_role(act, player, role, boot_pwd, group_id) self.log_msg(("role", (player, role))) def do_ping(self, xml_dom, data): - player = xml_dom.getAttribute("player") - group_id = xml_dom.getAttribute("group_id") + player = xml_dom.get("player") + group_id = xml_dom.get("group_id") sent_time = "" msg = "" - try: sent_time = xml_dom.getAttribute("time") + try: sent_time = xml_dom.get("time") except: pass if sent_time != "": msg ="<ping time='" + str(sent_time) + "' />" #because a time was sent return a ping response else: msg ="<msg to='" + player + "' from='" + player + "' group_id='" + group_id + "'>" msg += "<font color='#FF0000'>PONG!?!</font>" self.players[player].outbox.put(msg) - xml_dom.unlink() + #xml_dom.unlink() def do_system(self, xml_dom, data): pass def moderate_group(self,xml_dom,data): try: - action = xml_dom.getAttribute("action") - from_id = xml_dom.getAttribute("from") - if xml_dom.hasAttribute("pwd"): pwd=xml_dom.getAttribute("pwd") + action = xml_dom.get("action") + from_id = xml_dom.get("from") + if xml_dom.get("pwd"): pwd=xml_dom.get("pwd") else: pwd="" group_id=self.players[from_id].group_id if action == "list": @@ -1542,10 +1540,10 @@ self.groups[group_id].moderated = 0 self.players[from_id].self_message("This channel is now unmoderated") if action == 'addvoice': - users = xml_dom.getAttribute("users").split(',') + users = xml_dom.get("users").split(',') for i in users: self.groups[group_id].voice[i.strip()]=1 if action == 'delvoice': - users = xml_dom.getAttribute("users").split(',') + users = xml_dom.get("users").split(',') for i in users: if self.groups[group_id].voice.has_key(i.strip()): del self.groups[group_id].voice[i.strip()] else: @@ -1553,11 +1551,11 @@ except Exception,e: self.log_msg(str(e)) - def join_group(self,xml_dom,data): + def join_group(self, xml_dom, data): try: - from_id = xml_dom.getAttribute("from") - pwd = xml_dom.getAttribute("pwd") - group_id = xml_dom.getAttribute("group_id") + from_id = xml_dom.get("from") + pwd = xml_dom.get("pwd") + group_id = xml_dom.get("group_id") ver = self.players[from_id].version allowed = 1 @@ -1567,9 +1565,8 @@ if not self.groups[group_id].check_pwd(pwd): allowed = 0 - #tell the clients password manager the password failed -- SD 8/03 - pm = "<password signal=\"fail\" type=\"room\" id=\"" + group_id + "\" data=\"\"/>" + pm = "<password signal='fail' type='room' id='" + group_id + "' data=''/>" self.players[from_id].outbox.put(pm) msg = 'failed - incorrect room password' @@ -1578,7 +1575,7 @@ #the following line makes sure that their role is reset to normal, #since it is briefly set to lurker when they even TRY to change #rooms - msg = "<role action=\"update\" id=\"" + from_id + "\" role=\"" + self.players[from_id].role + "\" />" + msg = "<role action='update' id='" + from_id + "' role='" + self.players[from_id].role + "' />" self.players[from_id].outbox.put(msg) return @@ -1599,17 +1596,15 @@ "move a player from one group to another" try: try: - if group_id == "0": - self.players[from_id].role = "GM" - else: - self.players[from_id].role = "Lurker" + if group_id == "0": self.players[from_id].role = "GM" + else: self.players[from_id].role = "Lurker" except Exception, e: print "exception in move_player() " traceback.print_exc() - old_group_id = self.players[from_id].change_group(group_id,self.groups) - self.send_to_group(from_id,old_group_id,self.players[from_id].toxml('del')) - self.send_to_group(from_id,group_id,self.players[from_id].toxml('new')) + old_group_id = self.players[from_id].change_group(group_id, self.groups) + self.send_to_group(from_id, old_group_id, self.players[from_id].toxml('del')) + self.send_to_group(from_id, group_id, self.players[from_id].toxml('new')) self.check_group(from_id, old_group_id) """ @@ -1650,10 +1645,11 @@ self.log_msg(str(e)) thread.start_new_thread(self.registerRooms,(0,)) - def return_room_roles(self,from_id,group_id): + def return_room_roles(self, from_id, group_id): for m in self.players.keys(): if self.players[m].group_id == group_id: - msg = "<role action=\"update\" id=\"" + self.players[m].id + "\" role=\"" + self.players[m].role + "\" />" + try: msg = "<role action='update' id='" + self.players[m].id + "' role='" + self.players[m].role + "' />" + except: exit() self.players[from_id].outbox.put(msg) """ @@ -1664,7 +1660,7 @@ # conditions written all over them. Ack! Ack! """ def new_group( self, name, pwd, boot, minVersion, mapFile, messageFile, persist = 0, moderated=0 ): - group_id = str( self.next_group_id ) + group_id = str(self.next_group_id) self.next_group_id += 1 self.groups[group_id] = game_group( group_id, name, pwd, "", boot, minVersion, mapFile, messageFile, persist ) self.groups[group_id].moderated = moderated @@ -1672,9 +1668,9 @@ if persist !=0: ins="Persistant " lmsg = "Creating " + ins + "Group... (" + str(group_id) + ") " + str(name) self.log_msg( lmsg ) - self.log_msg(("create_group", (str(name), int(group_id), 0) )) ##-99 works, could be better. + self.log_msg(("create_group", (str(name), int(group_id), pwd, 0) )) - def change_group_name(self,gid,name,pid): + def change_group_name(self, gid, name, pid): "Change the name of a group" # Check for & in name. We want to allow this because of its common # use in d&d games. @@ -1710,83 +1706,86 @@ self.groups[gid].name = str(name) lmessage = "Room name changed to from \"" + oldroomname + "\" to \"" + name + "\"" self.log_msg(lmessage + " by " + str(pid) ) + self.log_msg(("update_group", (str(name), group_id, False))) + self.send_to_all('0',self.groups[gid].toxml('update')) return lmessage except: return "An error occured during rename of room!" thread.start_new_thread(self.registerRooms,(0,)) - def create_group(self,xml_dom,data): - try: - from_id = xml_dom.getAttribute("from") - pwd = xml_dom.getAttribute("pwd") - name = xml_dom.getAttribute("name") - boot_pwd = xml_dom.getAttribute("boot_pwd") - minVersion = xml_dom.getAttribute("min_version") - #added var reassign -- akoman - messageFile = self.defaultMessageFile + def create_group(self, xml_dom, data): + #try: + from_id = xml_dom.get("from") + pwd = xml_dom.get("pwd") + name = xml_dom.get("name") + boot_pwd = xml_dom.get("boot_pwd") + minVersion = xml_dom.get("min_version") + #added var reassign -- akoman + messageFile = self.defaultMessageFile - # see if passwords are allowed on this server and null password if not - if self.allow_room_passwords != 1: pwd = "" + # see if passwords are allowed on this server and null password if not + if self.allow_room_passwords != 1: pwd = "" - # Check for & in name. We want to allow this because of its common - # use in d&d games. + # Check for & in name. We want to allow this because of its common + # use in d&d games. - loc = name.find("&") - oldloc = 0 - while loc > -1: - loc = name.find("&",oldloc) - if loc > -1: - b = name[:loc] - e = name[loc+1:] - name = b + "&" + e - oldloc = loc+1 - loc = name.find("'") - oldloc = 0 - while loc > -1: - loc = name.find("'",oldloc) - if loc > -1: - b = name[:loc] - e = name[loc+1:] - name = b + "'" + e - oldloc = loc+1 - loc = name.find('"') - oldloc = 0 - while loc > -1: - loc = name.find('"',oldloc) - if loc > -1: - b = name[:loc] - e = name[loc+1:] - name = b + """ + e - oldloc = loc+1 - group_id = str(self.next_group_id) - self.next_group_id += 1 - self.groups[group_id] = game_group(group_id,name,pwd,"",boot_pwd, minVersion, None, messageFile ) - self.groups[group_id].voice[from_id]=1 - self.players[from_id].outbox.put(self.groups[group_id].toxml('new')) - old_group_id = self.players[from_id].change_group(group_id,self.groups) - self.send_to_group(from_id,old_group_id,self.players[from_id].toxml('del')) - self.check_group(from_id, old_group_id) - self.send_to_all(from_id,self.groups[group_id].toxml('new')) - self.send_to_all('0',self.groups[group_id].toxml('update')) - self.handle_role("set",from_id,"GM",boot_pwd, group_id) - lmsg = "Creating Group... (" + str(group_id) + ") " + str(name) - self.log_msg( lmsg ) - jmsg = "moving to room " + str(group_id) + "." - self.log_msg( jmsg ) - self.log_msg(("create_group", (str(name), group_id, from_id))) - #even creators of the room should see the HTML --akoman - #edit: jan10/03 - was placed in the except statement. Silly me. - if self.defaultMessageFile != None: - if self.defaultMessageFile[:4] == 'http': - data = urllib.urlretrieve(self.defaultMessageFile) - open_msg = open(data[0]) - urllib.urlcleanup() - else: open_msg = open( self.defaultMessageFile, "r" ) - roomMsg = open_msg.read() - open_msg.close() - # Send the rooms message to the client no matter what - self.players[from_id].outbox.put( "<msg to='" + from_id + "' from='0' group_id='" + group_id + "' />" + roomMsg ) - except Exception, e: self.log_msg( "Exception: create_group(): " + str(e)) + loc = name.find("&") + oldloc = 0 + while loc > -1: + loc = name.find("&",oldloc) + if loc > -1: + b = name[:loc] + e = name[loc+1:] + name = b + "&" + e + oldloc = loc+1 + loc = name.find("'") + oldloc = 0 + while loc > -1: + loc = name.find("'",oldloc) + if loc > -1: + b = name[:loc] + e = name[loc+1:] + name = b + "'" + e + oldloc = loc+1 + loc = name.find('"') + oldloc = 0 + while loc > -1: + loc = name.find('"',oldloc) + if loc > -1: + b = name[:loc] + e = name[loc+1:] + name = b + """ + e + oldloc = loc+1 + group_id = str(self.next_group_id) + self.next_group_id += 1 + + self.groups[group_id] = game_group(group_id, name, pwd, "", boot_pwd, minVersion, None, messageFile) + self.groups[group_id].voice[from_id]=1 + self.players[from_id].outbox.put(self.groups[group_id].toxml('new')) + old_group_id = self.players[from_id].change_group(group_id, self.groups) + self.send_to_group(from_id, old_group_id, self.players[from_id].toxml('del')) + self.check_group(from_id, old_group_id) + self.send_to_all(from_id,self.groups[group_id].toxml('new')) + self.send_to_all('0',self.groups[group_id].toxml('update')) + self.handle_role("set",from_id,"GM", boot_pwd, group_id) + lmsg = "Creating Group... (" + str(group_id) + ") " + str(name) + self.log_msg( lmsg ) + jmsg = "moving to room " + str(group_id) + "." + self.log_msg( jmsg ) + self.log_msg(("create_group", (str(name), group_id, from_id, 'No' if pwd == '' else 'Yes'))) + #even creators of the room should see the HTML --akoman + #edit: jan10/03 - was placed in the except statement. Silly me. + if self.defaultMessageFile != None: + if self.defaultMessageFile[:4] == 'http': + data = urllib.urlretrieve(self.defaultMessageFile) + open_msg = open(data[0]) + urllib.urlcleanup() + else: open_msg = open( self.defaultMessageFile, "r" ) + roomMsg = open_msg.read() + open_msg.close() + # Send the rooms message to the client no matter what + self.players[from_id].outbox.put( "<msg to='" + from_id + "' from='0' group_id='" + group_id + "' />" + roomMsg ) + #except Exception, e: self.log_msg( "Exception: create_group(): " + str(e)) thread.start_new_thread(self.registerRooms,(0,)) def check_group(self, from_id, group_id): @@ -1800,13 +1799,11 @@ del self.groups[group_id] self.log_msg(("delete_group", (group_id, from_id))) else: self.send_to_all("0",self.groups[group_id].toxml('update')) - #The register Rooms thread thread.start_new_thread(self.registerRooms,(0,)) - except Exception, e: self.log_msg(str(e)) - def del_player(self,id,group_id): + def del_player(self, id, group_id): try: dmsg = "Client Disconnect: (" + str(id) + ") " + str(self.players[id].name) self.players[id].disconnect() @@ -1825,10 +1822,10 @@ except Exception, e: self.log_msg(str(e)) self.log_msg("Explicit garbage collection shows %s undeletable items." % str(gc.collect())) - def incoming_player_handler(self,xml_dom,data): - id = xml_dom.getAttribute("id") - act = xml_dom.getAttribute("action") - #group_id = xml_dom.getAttribute("group_id") + def incoming_player_handler(self, xml_dom, data): + id = xml_dom.get("id") + act = xml_dom.get("action") + #group_id = xml_dom.get("group_id") group_id = self.players[id].group_id ip = self.players[id].ip self.log_msg("Player with IP: " + str(ip) + " joined.") @@ -1840,21 +1837,20 @@ self.send_group_list(id) except Exception, e: traceback.print_exc() elif act=="del": - #print "del player" self.del_player(id,group_id) self.check_group(id, group_id) elif act=="update": self.players[id].take_dom(xml_dom) self.log_msg(("update", {"id": id, - "name": xml_dom.getAttribute("name"), - "status": xml_dom.getAttribute("status"), - "role": xml_dom.getAttribute("role"), + "name": xml_dom.get("name"), + "status": xml_dom.get("status"), + "role": xml_dom.get("role"), "ip": str(ip), - "group": xml_dom.getAttribute("group_id"), - "room": xml_dom.getAttribute("name"), - "boot": xml_dom.getAttribute("rm_boot"), - "version": xml_dom.getAttribute("version"), - "ping": xml_dom.getAttribute("time") \ + "group": xml_dom.get("group_id"), + "room": xml_dom.get("name"), + "boot": xml_dom.get("rm_boot"), + "version": xml_dom.get("version"), + "ping": xml_dom.get("time") \ })) def strip_cheat_roll(self, string): @@ -1877,9 +1873,10 @@ def incoming_msg_handler(self,xml_dom,data): xml_dom, data = ServerPlugins.preParseIncoming(xml_dom, data) - to_id = xml_dom.getAttribute("to") - from_id = xml_dom.getAttribute("from") - group_id = xml_dom.getAttribute("group_id") + ########################################################### + to_id = xml_dom.get("to") + from_id = xml_dom.get("from") + group_id = xml_dom.get("group_id") end = data.find(">") msg = data[end+1:] @@ -1924,14 +1921,14 @@ return def sound_msg_handler(self, xml_dom, data): - from_id = xml_dom.getAttribute("from") - group_id = xml_dom.getAttribute("group_id") + from_id = xml_dom.get("from") + group_id = xml_dom.get("group_id") if group_id != 0: self.send_to_group(from_id, group_id, data) def plugin_msg_handler(self,xml_dom,data): - to_id = xml_dom.getAttribute("to") - from_id = xml_dom.getAttribute("from") - group_id = xml_dom.getAttribute("group_id") + to_id = xml_dom.get("to") + from_id = xml_dom.get("from") + group_id = xml_dom.get("group_id") end = data.find(">") msg = data[end+1:] @@ -1983,9 +1980,9 @@ try: given_boot_pwd = None try: - xml_dom = parseXml(msg) - xml_dom = xml_dom._get_documentElement() - given_boot_pwd = xml_dom.getAttribute("boot_pwd") + xml_dom = XML(msg) + #xml_dom = xml_dom._get_documentElement() + given_boot_pwd = xml_dom.get("boot_pwd") except: print "Error in parse of boot message, Ignoring." @@ -2083,14 +2080,14 @@ ### Alpha ### Addition added to assist in Un Banning users. def admin_build_banlist(self): validate.config_file("ban_list.xml", "default_ban_list.xml" ) - configDom = minidom.parse(dir_struct["user"] + 'ban_list.xml') + configDom = parse(dir_struct["user"] + 'ban_list.xml') self.ban_list = {} - for element in configDom.getElementsByTagName('banned'): - player = element.getAttribute('name').replace("&", "&").replace("<", "<").replace('"', """).replace(">", ">") - ip = element.getAttribute('ip') + for element in configDom.findall('banned'): + player = element.get('name').replace("&", "&").replace("<", "<").replace('"', """).replace(">", ">") + ip = element.get('ip') self.ban_list[ip] = {} self.ban_list[ip]['ip'] = ip - self.ban_list[ip]['name'] = element.getAttribute('name') + self.ban_list[ip]['name'] = element.get('name') ################ def admin_banip(self, ip, name="", silent = 0): @@ -2190,7 +2187,6 @@ def send_to_all(self,from_id,data): try: - print data self.p_lock.acquire() keys = self.players.keys() self.p_lock.release() @@ -2226,8 +2222,10 @@ def send_group_list(self, to_id, action="new"): try: + print self.groups for key in self.groups: xml = self.groups[key].toxml(action) + print xml, key self.players[to_id].outbox.put(xml) except Exception, e: self.log_msg("Exception: send_group_list(): (client #"+to_id+") : " + str(e)) @@ -2284,10 +2282,10 @@ """ if not self.allowRemoteAdmin: return try: - pid = xml_dom.getAttribute("id") + pid = xml_dom.get("id") gid = "" - given_pwd = xml_dom.getAttribute("pwd") - cmd = xml_dom.getAttribute("cmd") + given_pwd = xml_dom.get("pwd") + cmd = xml_dom.get("cmd") server_admin_pwd = self.groups["0"].boot_pwd p_id = "" p_name= "" @@ -2326,17 +2324,24 @@ msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'>" + self.player_list_remote() self.players[pid].outbox.put(msg) elif cmd == "banip": - ip = xml_dom.getAttribute("bip") - name = xml_dom.getAttribute("bname") + ip = xml_dom.get("bip") + name = xml_dom.get("bname") msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'> Banned: " + str(ip) self.admin_banip(ip, name) elif cmd == "ban": - id = xml_dom.getAttribute("bid") + id = xml_dom.get("bid") msg = "<msg to='" + id + "' from='0' group_id='" + gid + "'> Banned!" self.players[pid].outbox.put(msg) self.admin_ban(id, "") + ### Alpha ### and untested + elif cmd == "boot": + id = xml_dom.get("bid") + msg = "<msg to='" + id + "' from='0' group_id='" + gid + "'> Booted!" + self.players[pid].outbox.put(msg) + self.admin_kick(id, "") + ############# elif cmd == "unban": - ip = xml_dom.getAttribute("ip") + ip = xml_dom.get("ip") self.admin_unban(ip) msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'> Unbaned: " + str(ip) self.players[pid].outbox.put(msg) @@ -2344,7 +2349,7 @@ msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" + self.admin_banlist() self.players[pid].outbox.put(msg) elif cmd == "killgroup": - ugid = xml_dom.getAttribute("gid") + ugid = xml_dom.get("gid") if ugid == "0": m = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" m += "Cannot Remove Lobby! Remote administrator request denied!" @@ -2355,15 +2360,15 @@ self.players[pid].outbox.put(msg) elif cmd == "message": - tuid = xml_dom.getAttribute("to_id") - msg = xml_dom.getAttribute("msg") + tuid = xml_dom.get("to_id") + msg = xml_dom.get("msg") pmsg = "<msg to='" + tuid + "' from='0' group_id='" + self.players[tuid].group_id + "' >" + msg try: self.players[tuid].outbox.put(pmsg) except: msg = "<msg to='" + pid + "' from='0' group_id='" + gid + ">Unknown Player ID: No message sent." self.players[pid].outbox.put(msg) elif cmd == "broadcast": - bmsg = xml_dom.getAttribute("msg") + bmsg = xml_dom.get("msg") self.broadcast(bmsg) elif cmd == "killserver" and self.allowRemoteKill: #dangerous command..once server stopped it must be restarted manually @@ -2381,21 +2386,21 @@ msg += self.RoomPasswords() self.players[pid].outbox.put( msg) elif cmd == "createroom": - rm_name = xml_dom.getAttribute("name") - rm_pass = xml_dom.getAttribute("pass") - rm_boot = xml_dom.getAttribute("boot") + rm_name = xml_dom.get("name") + rm_pass = xml_dom.get("pass") + rm_boot = xml_dom.get("boot") result = self.create_temporary_persistant_room(rm_name, rm_boot, rm_pass) msg = "<msg to='" + pid + "' from='0' group_id='" + gid + "'>" + result self.players[pid].outbox.put(msg) elif cmd == "nameroom": - rm_id = xml_dom.getAttribute("rmid") - rm_name = xml_dom.getAttribute("name") + rm_id = xml_dom.get("rmid") + rm_name = xml_dom.get("name") result = self.change_group_name(rm_id,rm_name,pid) msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'/>" + result self.players[pid].outbox.put(msg) elif cmd == "passwd": - tgid = xml_dom.getAttribute("gid") - npwd = xml_dom.getAttribute("pass") + tgid = xml_dom.get("gid") + npwd = xml_dom.get("pass") if tgid == "0": msg ="<msg to='" + pid + "' from='0' group_id='" + gid + "'>" msg += "Server password may not be changed remotely!" @@ -2533,30 +2538,32 @@ # in chat window on remote client """ def player_list_remote(self): - COLOR1 = "\"#004080\"" #header/footer background color - COLOR2 = "\"#DDDDDD\"" #group line background color - COLOR3 = "\"#FFFFFF\"" #player line background color - COLOR4 = "\"#FFFFFF\"" #header/footer text color - PCOLOR = "\"#000000\"" #Player text color - LCOLOR = "\"#404040\"" #Lurker text color - GCOLOR = "\"#FF0000\"" #GM text color - SIZE = "size=\"-1\"" #player info text size + """Does not work!!!""" # TaS. + COLOR1 = "'#004080'" #header/footer background color + COLOR2 = "'#DDDDDD'" #group line background color + COLOR3 = "'#FFFFFF'" #player line background color + COLOR4 = "'#FFFFFF'" #header/footer text color + PCOLOR = "'#000000'" #Player text color + LCOLOR = "'#404040'" #Lurker text color + GCOLOR = "'#FF0000'" #GM text color + SIZE = "size='-1'" #player info text size FG = PCOLOR "display a condensed list of players on the server" self.p_lock.acquire() - pl = "<br /><table border=\"0\" cellpadding=\"1\" cellspacing=\"2\">" - pl += "<tr><td colspan='4' bgcolor=" + COLOR1 + "><font color=" + COLOR4 + ">" - pl += "<b>GROUP & PLAYER LIST</b></font></td></tr>" + pl = "<br /><table border='0' cellpadding='1' cellspacing='2'>" + pl += "<tr><td colspan='4' bgcolor=" + COLOR1 + "><font color='" + COLOR4 + "'>" + pl += "<b>GROUP & '' PLAYER LIST</b></font></td></tr>" try: keys = self.groups.keys() keys.sort(id_compare) for k in keys: - groupstring = "<tr><td bgcolor=" + COLOR2 + " colspan='2'>" + debug((self.groups, self.groups[k], self.groups[k].name)) + groupstring = "<tr><td bgcolor='" + COLOR2 + "' colspan='2'>" groutstring += "<b>Group " + str(k) + ": " + self.groups[k].name + "</b>" - groupstring += "</td><td bgcolor=" + COLOR2 + " > <i>Password: \"" + self.groups[k].pwd + "\"</td>" - groupstring += "<td bgcolor=" + COLOR2 + " > Boot: \"" + self.groups[k].boot_pwd + "\"</i></td></tr>" - pl += groupstring + groupstring += "</td><td bgcolor=" + COLOR2 + " > <i>Password: " + self.groups[k].pwd + "</td>" + groupstring += "<td bgcolor=" + COLOR2 + " > Boot: " + self.groups[k].boot_pwd + "</i></td></tr>" + pl += groupstring; debug(groupstring) ids = self.groups[k].get_player_ids() ids.sort(id_compare) for id in ids: