]> code.delx.au - pymsnt/blobdiff - src/tlib/msn/msnw.py
Use vCard fullname if nickname isn't around.
[pymsnt] / src / tlib / msn / msnw.py
index 6330444ba559ea2d2afc08b6bd47e1b860f0cef5..6b58f50ed0097698ccb2621451218dc5bce07e87 100644 (file)
@@ -7,7 +7,7 @@ from twisted.internet.defer import Deferred
 from twisted.internet.protocol import ClientFactory
 
 # System imports
-import math, base64, binascii, math
+import math, base64, binascii
 
 # Local imports
 from debug import LogEvent, INFO, WARN, ERROR
@@ -50,7 +50,9 @@ class MSNConnection:
 
        def _getNotificationReferral(self):
                def timeout():
-                       if not d.called: d.errback()
+                       if not d.called:
+                               d.errback()
+                               self.logOut() # Clean up everything
                self.timeout = reactor.callLater(30, timeout)
                dispatchFactory = msn.DispatchFactory()
                dispatchFactory.userHandle = self.username
@@ -219,7 +221,7 @@ class MSNConnection:
        
        def logOut(self):
                """ Shuts down the whole connection. Don't try to call any
-               other methods after this one. """
+               other methods after this one. Except maybe connect() """
                if self.notificationClient:
                        self.notificationClient.logOut()
                for c in self.connectors:
@@ -227,6 +229,9 @@ class MSNConnection:
                if self.notificationFactory:
                        self.notificationFactory.msncon = None
                self.connectors = []
+               for sbs in self.switchboardSessions.values():
+                       if hasattr(sbs, "transport") and sbs.transport:
+                               sbs.transport.loseConnection()
                self.switchboardSessions = {}
                LogEvent(INFO, self.ident)
                
@@ -620,7 +625,7 @@ class OneSwitchboardSession(SwitchboardSessionBase):
                self.timeout = None
                for message, noerror in self.messageBuffer:
                        if not noerror:
-                               self.failedMessage(self.remoteUser, message)
+                               self.failedMessage(message)
 
        def _ready(self):
                LogEvent(INFO, self.ident)
@@ -687,7 +692,8 @@ class OneSwitchboardSession(SwitchboardSessionBase):
        def userLeft(self, userHandle):
                def wait():
                        if userHandle == self.remoteUser:
-                               del self.msncon.switchboardSessions[self.remoteUser]
+                               if self.msncon and self.msncon.switchboardSessions.has_key(self.remoteUser):
+                                       del self.msncon.switchboardSessions[self.remoteUser]
                reactor.callLater(0, wait) # Make sure this is handled after everything else
 
        def gotMessage(self, message):