diff orpg/networking/mplay_client.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_client.py	Fri Sep 25 20:47:16 2009 -0500
+++ b/orpg/networking/mplay_client.py	Tue Nov 10 14:11:28 2009 -0600
@@ -31,20 +31,21 @@
 
 ### Alpha ### 
 ##import orpg.minidom ## Deprecated. xml.parseXml calls minidom.parseString so it was superfluous and wasteful.
-import socket
-import Queue
-import thread
-import traceback
+import socket, Queue, thread, traceback, errno, os, time
+
 from threading import Event, Lock
 from xml.sax.saxutils import escape
 from struct import pack, unpack, calcsize
 from string import *
 from orpg.orpg_version import CLIENT_STRING, PROTOCOL_VERSION, VERSION
-import errno
-import os
-import time
+
 from orpg.orpgCore import component
 from orpg.orpg_xml import xml
+from orpg.tools.orpg_log import debug
+
+from xml.etree.ElementTree import ElementTree, Element, iselement
+from xml.etree.ElementTree import fromstring, tostring
+from xml.parsers.expat import ExpatError
 
 try:
     import bz2
@@ -56,8 +57,7 @@
     cmpZLIB = True
 except: cmpZLIB = False
 
-
-# This should be configurable
+# Default, is configurable
 OPENRPG_PORT = 9557
 
 # We should be sending a length for each packet
@@ -92,7 +92,7 @@
     return escape(data,{"\"":""})
 
 class mplay_event:
-    def __init__(self,id,data=None):
+    def __init__(self, id, data=None):
         self.id = id
         self.data = data
 
@@ -105,7 +105,6 @@
 BOOT_MSG = "YoU ArE ThE WeAkEsT LiNk. GoOdByE."
 
 class client_base:
-
     # Player role definitions
     def __init__(self):
         self.outbox = Queue.Queue(0)
@@ -147,7 +146,7 @@
 
         # Loop as long as we have a connection
         while( self.get_status() == MPLAY_CONNECTED ):
-            try: readMsg = self.outbox.get( block=1 )
+            try: readMsg = self.outbox.get(block=1)
             except Exception, text:
                 self.log_msg( ("outbox.get() got an exception:  ", text) )
 
@@ -166,7 +165,6 @@
 
     def recvThread( self, arg ):
         "Receiving thread.  This thread reads from the socket and writes to the data queue."
-
         # Wait to be told it's okay to start running
         self.startedEvent.wait()
 
@@ -189,14 +187,13 @@
         if bytes == 0:
             self.log_msg( "Remote has disconnected!" )
             self.set_status( MPLAY_DISCONNECTING )
-        self.outbox.put( "" )    # Make sure the other thread is woken up!
+        self.outbox.put("")    # Make sure the other thread is woken up!
         self.sendThreadExitEvent.set()
         self.log_msg( "recvThread has terminated..." )
 
     def sendMsg( self, sock, msg ):
         """Very simple function that will properly encode and send a message to te
         remote on the specified socket."""
-
         if self.useCompression and self.compressionType != None:
             mpacket = self.compressionType.compress(msg)
             lpacket = pack('!i', len(mpacket))
@@ -208,16 +205,10 @@
                 offset += sent
             sentm = offset
         else:
-            # Calculate our message length
-            length = len(msg)
-
-            # Encode the message length into network byte order
-            lp = pack('!i', length)
-
+            length = len(msg) # Calculate our message length
+            lp = pack('!i', length) # Encode the message length into network byte order
             try:
-                # Send the encoded length
-                sentl = sock.send( lp )
-
+                sentl = sock.send( lp ) # Send the encoded length
                 # Now, send the message the the length was describing
                 sentm = sock.send( msg )
                 if self.isServer(): self.log_msg(("data_sent", sentl+sentm))
@@ -248,27 +239,18 @@
             data = ""
         return data
 
-    def recvMsg( self, sock ):
-        """This method now expects to receive a message having a 4-byte prefix length.  It will ONLY read
-        completed messages.  In the event that the remote's connection is terminated, it will throw an
-        exception which should allow for the caller to more gracefully handle this exception event.
+    def recvMsg(self, sock):
+        """This method now expects to receive a message having a 4-byte prefix length.  It will ONLY read completed messages.  In the event that the remote's connection is terminated, it will throw an exception which should allow for the caller to more gracefully handle this exception event.
 
-        Because we use strictly reading ONLY based on the length that is told to use, we no longer have to
-        worry about partially adjusting for fragmented buffers starting somewhere within a buffer that we've
-        read.  Rather, it will get ONLY a whole message and nothing more.  Everything else will remain buffered
-        with the OS until we attempt to read the next complete message."""
-
+        Because we use strictly reading ONLY based on the length that is told to use, we no longer have to worry about partially adjusting for fragmented buffers starting somewhere within a buffer that we've read.  Rather, it will get ONLY a whole message and nothing more.  Everything else will remain buffered with the OS until we attempt to read the next complete message."""
         msgData = ""
         try:
             lenData = self.recvData( sock, MPLAY_LENSIZE )
-            # Now, convert to a usable form
-            (length,) = unpack('!i', lenData)
-            # Read exactly the remaining amount of data
-            msgData = self.recvData( sock, length )
+            (length,) = unpack('!i', lenData) # Now, convert to a usable form
+            msgData = self.recvData( sock, length ) # Read exactly the remaining amount of data
             if self.isServer():
                 self.log_msg(("data_recv", length+4))
-                # Make the peer IP address available for reference later
-                if self.remote_ip is None:
+                if self.remote_ip is None: # Make the peer IP address available for reference later
                     self.remote_ip = self.sock.getpeername()
         except IOError, e: self.log_msg( e )
         except Exception, e: self.log_msg( e )
@@ -279,15 +261,16 @@
         self.status = MPLAY_CONNECTED
         self.sock.setblocking(1)
         # Confirm that our threads have started
-        thread.start_new_thread( self.sendThread,(0,) )
-        thread.start_new_thread( self.recvThread,(0,) )
+        thread.start_new_thread( self.sendThread,(0,))
+        thread.start_new_thread( self.recvThread,(0,))
         self.startedEvent.set()
 
     def disconnect(self):
+        debug()
         self.set_status(MPLAY_DISCONNECTING)
         self.log_msg("client stub " + self.ip +" disconnecting...")
         self.log_msg("closing sockets...")
-        try: self.sock.shutdown( 2 )
+        try: self.sock.shutdown(2)
         except Exception, e:
             print "Caught exception:  " + str(e)
             print
@@ -304,10 +287,8 @@
         self.role = role
 
     def use_roles(self):
-        if self.useroles:
-            return 1
-        else:
-            return 0
+        if self.useroles: return 1
+        else: return 0
     def update_self_from_player(self, player):
         try: (self.name, self.ip, self.id, 
                 self.text_status, self.version, 
@@ -318,26 +299,30 @@
      The IP field should really be deprecated as too many systems are NAT'd and/or behind firewalls for a
      client provided IP address to have much value.  As such, we now label it as deprecated.
     """
-    def toxml(self,action):
-        xml_data = '<player name="' + myescape(self.name) + '"'
-        xml_data += ' action="' + action + '" id="' + self.id + '"'
-        xml_data += ' group_id="' + self.group_id + '" ip="' + self.ip + '"'
-        xml_data += ' status="' + self.text_status + '"'
-        xml_data += ' version="' + self.version + '"'
-        xml_data += ' protocol_version="' + self.protocol_version + '"'
-        xml_data += ' client_string="' + self.client_string + '"'
-        xml_data += ' useCompression="' + str(self.useCompression) + '"'
+    def toxml(self, action):
+        el = Element('player')
+        el.set('name', self.name)
+        el.set('action', action)
+        el.set('role', self.role)
+        el.set('id', self.id)
+        el.set('group_id', self.group_id)
+        el.set('ip', self.ip)
+        el.set('status', self.text_status)
+        el.set('version', self.version)
+        el.set('protocol_version', self.protocol_version)
+        el.set('client_string', self.client_string)
+        el.set('useCompression', str(self.useCompression))
+        cmpType = 'None'
         if cmpBZ2 and (self.compressionType == 'Undefined' or self.compressionType == bz2):
-            xml_data += ' cmpType="bz2"'
+            cmpType = 'bz2'
         elif cmpZLIB and (self.compressionType == 'Undefined' or self.compressionType == zlib):
-            xml_data += ' cmpType="zlib"'
-        else: xml_data += ' cmpType="None"'
-        xml_data += ' />'
-        return xml_data
+            cmpType = 'zlib'
+        el.set('cmpType', cmpType)
+        return tostring(el)
 
     def log_msg(self,msg):
-        if self.log_console:
-            self.log_console(msg)
+        debug(msg, log=False)
+        if self.log_console: self.log_console(msg)
 
     def get_status(self):
         self.statLock.acquire()
@@ -346,17 +331,7 @@
         return status
 
     def my_role(self):
-        #Leaving this for testing.
         return self.role
-        """
-        if self.role == "GM":
-            return self.ROLE_GM
-        elif self.role == "Player":
-            return self.ROLE_PLAYER
-        elif self.role == "Lurker":
-            return self.ROLE_LURKER
-        return -1
-        """
 
     def set_status(self,status):
         self.statLock.acquire()
@@ -542,25 +517,28 @@
                 return (0,id,name)
         self.ignore_name.append(self.players[id][0])
         self.ignore_id.append(self.players[id][2])
-        return (1,self.players[id][2],self.players[id][0])
+        return (1, self.players[id][2], self.players[id][0])
 
     def boot_player(self,id,boot_pwd = ""):
-        #self.send(BOOT_MSG,id)
-        msg = '<boot boot_pwd="' + boot_pwd + '"/>'
-        self.send(msg,id)
+        el = Element('boot')
+        el.set('boot_pwd', boot_pwd)
+        self.send(tostring(el), id)
 
 #---------------------------------------------------------
 # [START] Snowdog Password/Room Name altering code 12/02
 #---------------------------------------------------------
 
-    def set_room_pass(self,npwd,pwd=""):
-        recycle_bin = "<alter key=\"pwd\" "
-        recycle_bin += "val=\"" +npwd+ "\" bpw=\"" + pwd + "\" "
-        recycle_bin += "plr=\"" + self.id +"\" gid=\"" + self.group_id + "\" />"
-        self.outbox.put(recycle_bin); del recycle_bin #makes line easier to read. --TaS
+    def set_room_pass(self, npwd, pwd=""):
+        el = Element('alter')
+        el.set('key', 'pwd')
+        el.set('val', npwd)
+        el.set('bpw', pwd)
+        el.set('plr', self.id)
+        el.set('gid', self.group_id)
+        self.outbox.put(tostring(el))
         self.update()
 
-    def set_room_name(self,name,pwd=""):
+    def set_room_name(self, name, pwd=""):
         loc = name.find("&")
         oldloc=0
         while loc > -1:
@@ -588,10 +566,13 @@
                 e = name[loc+1:]
                 name = b + "&#39;" + e
                 oldloc = loc+1
-        recycle_bin = "<alter key=\"name\" "
-        recycle_bin += "val=\"" + name + "\" bpw=\"" + pwd + "\" "
-        recycle_bin += "plr=\"" + self.id +"\" gid=\"" + self.group_id + "\" />"
-        self.outbox.put(recycle_bin); del recycle_bin #makes line easier to read. --TaS
+        el = Element('alter')
+        el.set('key', 'pwd')
+        #el.set('val', npwd)
+        el.set('bpw', str(pwd))
+        el.set('plr', self.id)
+        el.set('gid', self.group_id)
+        self.outbox.put(tostring(el))
         self.update()
 
 #---------------------------------------------------------
@@ -599,19 +580,39 @@
 #---------------------------------------------------------
 
     def display_roles(self):
-        self.outbox.put("<role action=\"display\" player=\"" + self.id +"\" group_id=\""+self.group_id + "\" />")
+        el = Element('role')
+        el.set('action', 'display')
+        el.set('player', self.id)
+        el.set('group_id', self.group_id)
+        self.outbox.put(tostring(el))
 
     def get_role(self):
-        self.outbox.put("<role action=\"get\" player=\"" + self.id +"\" group_id=\""+self.group_id + "\" />")
+        el = Element('role')
+        el.set('action', 'get')
+        el.set('player', self.id)
+        el.set('group_id', self.group_id)
+        self.outbox.put(tostring(el))
 
-    def set_role(self,player,role,pwd=""):
-        recycle_bin = "<role action=\"set\" player=\"" + player + "\" "
-        recycle_bin += "role=\"" +role+ "\" boot_pwd=\"" + pwd + "\" group_id=\"" + self.group_id + "\" />"
-        self.outbox.put(recycle_bin); del recycle_bin #makes line easer to read. --TaS
+    def set_role(self, player, role, pwd=""):
+        el = Element('role')
+        el.set('action', 'set')
+        el.set('player', player)
+        el.set('role', role)
+        el.set('boot_pwd', pwd)
+        el.set('group_id', self.group_id)
+        self.outbox.put(tostring(el))
         self.update()
 
-    def send(self,msg,player="all"):
+    def send(self, msg, player="all"):
         if self.status == MPLAY_CONNECTED and player != self.id:
+            ### Pre Alpha ###
+            #el = Element('msg')
+            #el.set('to', player)
+            #el.set('from', self.id)
+            #el.set('group_id', self.group_id)
+            #el.append(fromstring(msg))
+            #self.outbox.put(tostring(el))
+            ### Current chat is not ready for Element Tree ###
             self.outbox.put("<msg to='"+player+"' from='"+self.id+"' group_id='"+self.group_id+"' />"+msg)
         self.check_my_status()
 
@@ -620,19 +621,26 @@
             self.outbox.put(snd_xml)
         self.check_my_status()
 
-    def send_create_group(self,name,pwd,boot_pwd,minversion):
-        recycle_bin = "<create_group from=\""+self.id+"\" "
-        recycle_bin += "pwd=\""+pwd+"\" name=\""+ name+"\" boot_pwd=\""+boot_pwd+"\" "
-        recycle_bin += "min_version=\"" + minversion +"\" />"
-        self.outbox.put(recycle_bin); del recycle_bin #makes line easier to read. --TaS
+    def send_create_group(self, name, pwd, boot_pwd, min_version):
+        el = Element('create_group')
+        el.set('from', self.id)
+        el.set('pwd', pwd)
+        el.set('name', name)
+        el.set('boot_pwd', boot_pwd)
+        el.set('min_version', min_version)
+        self.outbox.put(tostring(el))
 
-    def send_join_group(self,group_id,pwd):
+    def send_join_group(self, group_id, pwd):
         if (group_id != 0): self.update_role("Lurker")
-        self.outbox.put("<join_group from=\""+self.id+"\" pwd=\""+pwd+"\" group_id=\""+str(group_id)+"\" />")
+        el = Element('join_group')
+        el.set('from', self.id)
+        el.set('pwd', pwd)
+        el.set('group_id', str(group_id))
+
+        self.outbox.put(tostring(el))
 
     def poll(self, evt=None):
-        try:
-            msg = self.inbox.get_nowait()
+        try: msg = self.inbox.get_nowait()
         except:
             if self.get_status() != MPLAY_CONNECTED:
                 self.check_my_status()
@@ -663,29 +671,32 @@
         self.add_msg_handler('password', self.on_password, True)
         self.add_msg_handler('sound', self.on_sound, True)
 
-    def pretranslate(self,data):
+    def pretranslate(self, data):
         # Pre-qualify our data.  If we don't have atleast 5-bytes, then there is
         # no way we even have a valid message!
         if len(data) < 5: return
-        end = data.find(">")
-        head = data[:end+1]
-        msg = data[end+1:]
-        xml_dom = self.xml.parseXml(head)
-        xml_dom = xml_dom._get_documentElement()
-        tag_name = xml_dom._get_tagName()
-        id = xml_dom.getAttribute("from")
-        if id == '': id = xml_dom.getAttribute("id")
-        if self.msg_handlers.has_key(tag_name): self.msg_handlers[tag_name](id, data, xml_dom)
-        else:
-            #Unknown messages recived ignoring
-            #using pass insted or printing an error message
-            #because plugins should now be able to send and proccess messages
-            #if someone is using a plugin to send messages and this user does not
-            #have the plugin they would be getting errors
-            pass
-        if xml_dom: xml_dom.unlink()
+        try: el = fromstring(data)
+        except ExpatError:
+            end = data.find(">")
+            head = data[:end+1]
+            msg = data[end+1:]
+            ### Alpha ###
+            if head[end:] != '/':
+                if head[end:] != '>': head = head[:end] + '/>' 
+            ### This if statement should help close invalid messages.  Since it needs fixing, use the try except message for now.
+            try: el = fromstring(head)
+            except: el = fromstring(head[:end] +'/>')
 
-    def on_sound(self, id, data, xml_dom):
+            try:
+                el1 = fromstring(msg)
+                el.append(el1)
+            except ExpatError:
+                el.text = msg
+                #logger.general("Bad Message: \n" + data)
+        id = el.get('from') or el.get('id')
+        if el.tag in self.msg_handlers: self.msg_handlers[el.tag](id, data, el)
+
+    def on_sound(self, id, data, etreeEl):
         (ignore_id,ignore_name) = self.get_ignore_list()
         for m in ignore_id:
             if m == id:
@@ -693,96 +704,79 @@
                 print "ignoring sound from player:"
                 return
         chat = self.get_chat()
-        snd = xml_dom.getAttribute("url")
-        loop_sound = xml_dom.getAttribute("loop")
-        chat.sound_player.play(snd, "remote", loop_sound)
+        chat.sound_player.play(etreeEl.get('url'), 'remote', etreeEl.get('loop'))
 
-    def on_msg(self, id, data, xml_dom):
+    def on_msg(self, id, data, etreeEl):
         end = data.find(">")
         head = data[:end+1]
         msg = data[end+1:]
-        if id == "0":
-            self.on_receive(msg,None)      #  None get's interpreted in on_receive as the sys admin.
-                                           #  Doing it this way makes it harder to impersonate the admin
-        else:
-            if self.is_valid_id(id): self.on_receive(msg,self.players[id])
-        if xml_dom: xml_dom.unlink()
+        if msg[-6:] == '</msg>': msg = msg[:-6]
+        if id == "0": self.on_receive(msg, None)
+        #  None get's interpreted in on_receive as the sys admin.
+        #  Doing it this way makes it harder to impersonate the admin
+        elif self.is_valid_id(id): self.on_receive(msg, self.players[id])
 
-    def on_ping(self, id, msg, xml_dom):
+    def on_ping(self, id, msg, etreeEl):
         #a REAL ping time implementation by Snowdog 8/03
         # recieves special server <ping time="###" /> command
         # where ### is a returning time from the clients ping command
         #get current time, pull old time from object and compare them
         # the difference is the latency between server and client * 2
         ct = time.clock()
-        ot = xml_dom.getAttribute("time")
+        ot = etreeEl.get("time")
         latency = float(float(ct) - float(ot))
-        latency = int( latency * 10000.0 )
-        latency = float( latency) / 10.0
+        latency = int(latency * 10000.0)
+        latency = float(latency) / 10.0
         ping_msg = "Ping Results: " + str(latency) + " ms (parsed message, round trip)"
-        self.on_receive(ping_msg,None)
-        if xml_dom: xml_dom.unlink()
+        self.on_receive(ping_msg, None)
 
-    def on_group(self, id, msg, xml_dom):
-        name = xml_dom.getAttribute("name")
-        players = xml_dom.getAttribute("players")
-        act = xml_dom.getAttribute("action")
-        pwd = xml_dom.getAttribute("pwd")
-        group_data = (id, name, pwd, players)
-
-        if act == 'new':
+    def on_group(self, id, msg, etreeEl):
+        act = etreeEl.get("action")
+        group_data = (id, etreeEl.get("name"), etreeEl.get("pwd"), etreeEl.get("players"))
+        if act == ('new' or 'update'):
             self.groups[id] = group_data
-            self.on_group_event(mplay_event(GROUP_NEW, group_data))
+            if act == 'update': self.on_group_event(mplay_event(GROUP_UPDATE, group_data))
+            elif act == 'new': self.on_group_event(mplay_event(GROUP_NEW, group_data))
         elif act == 'del':
             del self.groups[id]
             self.on_group_event(mplay_event(GROUP_DEL, group_data))
-        elif act == 'update':
-            self.groups[id] = group_data
-            self.on_group_event(mplay_event(GROUP_UPDATE, group_data))
-        if xml_dom: xml_dom.unlink()
 
-    def on_role(self, id, msg, xml_dom):
-        act = xml_dom.getAttribute("action")
-        role = xml_dom.getAttribute("role")
+    def on_role(self, id, msg, etreeEl):
+        act = etreeEl.get("action")
         if (act == "set") or (act == "update"):
             try:
                 (a,b,c,d,e,f,g,h) = self.players[id]
                 if id == self.id:
-                    self.players[id] = (a,b,c,d,e,f,g,role)
-                    self.update_role(role)
-                else: self.players[id] = (a,b,c,d,e,f,g,role)
-                self.on_player_event(mplay_event(PLAYER_UPDATE,self.players[id]))
+                    self.players[id] = (a,b,c,d,e,f,g,etreeEl.get("role"))
+                    self.update_role(etreeEl.get("role"))
+                else: self.players[id] = (a,b,c,d,e,f,g,etreeEl.get("role"))
+                self.on_player_event(mplay_event(PLAYER_UPDATE, self.players[id]))
             except: pass
-        if xml_dom: xml_dom.unlink()
 
-    def on_player(self, id, msg, xml_dom):
-        act = xml_dom.getAttribute("action")
-        ip = xml_dom.getAttribute("ip")
-        name = xml_dom.getAttribute("name")
-        status = xml_dom.getAttribute("status")
-        version = xml_dom.getAttribute("version")
-        protocol_version = xml_dom.getAttribute("protocol_version")
-        client_string = xml_dom.getAttribute("client_string")
-        try: player = (name, ip, id, status, 
-                        version, protocol_version, 
-                        client_string, self.players[id][7])
+    def on_player(self, id, msg, etreeEl):
+        act = etreeEl.get("action")
+        try: player = (etreeEl.get("name"), etreeEl.get("ip"), id, etreeEl.get("status"), 
+                        etreeEl.get("version"), etreeEl.get("protocol_version"), 
+                        etreeEl.get("client_string"), self.players[id][7])
         except Exception, e:
-            player = (name, ip, id, status, 
-                        version, protocol_version, 
-                        client_string, "Player")
+            player = (etreeEl.get("name"), etreeEl.get("ip"), id, etreeEl.get("status"), 
+                        etreeEl.get("version"), etreeEl.get("protocol_version"), 
+                        etreeEl.get("client_string"), "Player")
+            print e
         if act == "new":
             self.players[id] = player
             self.on_player_event(mplay_event(PLAYER_NEW, self.players[id]))
         elif act == "group":
-            self.group_id = xml_dom.getAttribute("group_id")
+            self.group_id = etreeEl.get('group_id')
             self.clear_players()
             self.on_mplay_event(mplay_event(MPLAY_GROUP_CHANGE, self.groups[self.group_id]))
-            self.players[self.id] = self.get_my_info() #(self.name,self.ip,self.id,self.text_status)
+            self.players[self.id] = self.get_my_info() 
+            #(self.name,self.ip,self.id,self.text_status)
             self.on_player_event(mplay_event(PLAYER_NEW, self.players[self.id]))
         elif act == "failed":
             self.on_mplay_event(mplay_event(MPLAY_GROUP_CHANGE_F))
         elif act == "del":
-            self.on_player_event(mplay_event(PLAYER_DEL,self.players[id]))
+            self.on_player_event(mplay_event(PLAYER_DEL, self.players[id]))
             if self.players.has_key(id): del self.players[id]
             if id == self.id: self.do_disconnect()
         #  the next two cases handle the events that are used to let you know when others are typing
@@ -792,20 +786,13 @@
                 self.update_self_from_player(player)
             else: self.players[id] = player
             dont_send = 0
-            for m in self.ignore_id:
+            for m in self.ignore_id: 
                 if m == id: dont_send=1
-            if dont_send != 1: self.on_player_event(mplay_event(PLAYER_UPDATE,self.players[id]))
-        if xml_dom: xml_dom.unlink()
+            if dont_send != 1: self.on_player_event(mplay_event(PLAYER_UPDATE, self.players[id]))
 
-    def on_password(self, id, msg, xml_dom):
-        signal = type = id = data = None
-        id = xml_dom.getAttribute("id")
-        type = xml_dom.getAttribute("type")
-        signal = xml_dom.getAttribute("signal")
-        data = xml_dom.getAttribute("data")
-        self.on_password_signal( signal,type,id,data )
-        if xml_dom:
-            xml_dom.unlink()
+    def on_password(self, id, msg, etreeEl):
+        self.on_password_signal(etreeEl.get("signal"), etreeEl.get("type"), 
+                                etreeEl.get("id"), etreeEl.get("data"))
 
     def check_my_status(self):
         status = self.get_status()
@@ -817,7 +804,6 @@
         if self.is_connected():
             self.log_msg( "Client is already connected to a server?!?  Need to disconnect first." )
             return 0
-        xml_dom = None
         self.inbox = Queue.Queue(0)
         self.outbox = Queue.Queue(0)
         addressport_ar = addressport.split(":")
@@ -832,29 +818,29 @@
         try:
             self.sock.connect((address,port))
             # send client into with id=0
-            self.sendMsg( self.sock, self.toxml("new") )
-            data = self.recvMsg( self.sock )
+            outgoing = self.toxml('new')
+            if iselement(outgoing): outgoing = tostring(outgoing)
+            self.sendMsg(self.sock, outgoing)
+            data = self.recvMsg(self.sock)
             # get new id and group_id
-            xml_dom = self.xml.parseXml(data)
-            xml_dom = xml_dom._get_documentElement()
-            self.id = xml_dom.getAttribute("id")
-            self.group_id = xml_dom.getAttribute("group_id")
-            if xml_dom.hasAttribute('useCompression') and xml_dom.getAttribute('useCompression') == 'True':
+            el = fromstring(data)
+            self.id = el.get('id')
+            self.group_id = el.get('group_id')
+            if el.get('useCompression') == 'True':
                 self.useCompression = True
-                if xml_dom.hasAttribute('cmpType'):
-                    if cmpBZ2 and xml_dom.getAttribute('cmpType') == 'bz2':
-                        self.compressionType = bz2
-                    elif cmpZLIB and xml_dom.getAttribute('cmpType') == 'zlib':
-                        self.compressionType = zlib
-                    else: self.compressionType = None
-                else: self.compressionType = bz2
+                if cmpBZ2 and el.get('cmpType') == 'bz2':
+                    self.compressionType = bz2
+                elif cmpZLIB and el.get('cmpType') == 'zlib':
+                    self.compressionType = zlib
+                else: self.compressionType = None
             #send confirmation
-            self.sendMsg( self.sock, self.toxml("new") )
+            outgoing = self.toxml('new')
+            if iselement(outgoing): outgoing = tostring(outgoing)
+            self.sendMsg(self.sock, outgoing)
         except Exception, e:
+            print e
             self.log_msg(e)
-            if xml_dom: xml_dom.unlink()
             return 0
-
         # Start things rollings along
         self.initialize_threads()
         self.on_mplay_event(mplay_event(MPLAY_CONNECTED))
@@ -862,12 +848,13 @@
                                 self.text_status, self.version, 
                                 self.protocol_version, self.client_string, self.role)
         self.on_player_event(mplay_event(PLAYER_NEW,self.players[self.id]))
-        if xml_dom: xml_dom.unlink()
         return 1
 
     def start_disconnect(self):
         self.on_mplay_event(mplay_event(MPLAY_DISCONNECTING))
-        self.outbox.put( self.toxml("del") )
+        outgoing = self.toxml('del')
+        if iselement(outgoing): outgoing = tostring(outgoing)
+        self.outbox.put(outgoing)
         ## Client Side Disconect Forced -- Snowdog 10-09-2003
         #pause to allow GUI events time to sync.
         time.sleep(1)