]> code.delx.au - pymsnt/blobdiff - src/tlib/msn/msn.py
Made avatars more reliable.
[pymsnt] / src / tlib / msn / msn.py
index bcc9aaa04773475e77b0d9a94b65c23d6719f33e..1ad7cfd9cd04ae06eff61f61a0be7817a3fe9792 100644 (file)
@@ -99,7 +99,7 @@ import msnp11chl
 # Twisted imports
 from twisted.internet import reactor, task
 from twisted.internet.defer import Deferred
-from twisted.internet.protocol import ClientFactory
+from twisted.internet.protocol import ReconnectingClientFactory, ClientFactory
 try:
     from twisted.internet.ssl import ClientContextFactory
 except ImportError:
@@ -154,7 +154,7 @@ STATUS_LUNCH   = 'LUN'
 
 PINGSPEED = 50.0
 
-DEBUGALL = True
+DEBUGALL = False
 LINEDEBUG = False
 MESSAGEDEBUG = False
 MSNP2PDEBUG = False
@@ -973,6 +973,7 @@ class NotificationClient(MSNEventBase):
         MSNEventBase.connectionMade(self)
         self._setState('CONNECTED')
         self.sendLine("VER %s %s" % (self._nextTransactionID(), MSN_PROTOCOL_VERSION))
+        self.factory.resetDelay()
 
     def connectionLost(self, reason):
         self._setState('DISCONNECTED')
@@ -1386,6 +1387,7 @@ class NotificationClient(MSNEventBase):
 
     def handle_OUT(self, params):
         checkParamLen(len(params), 1, 'OUT')
+        self.factory.stopTrying()
         if params[0] == "OTH": self.multipleLogin()
         elif params[0] == "SSD": self.serverGoingDown()
         else: raise MSNProtocolError, "Invalid Parameters received for OUT" # debug
@@ -1991,10 +1993,11 @@ class NotificationClient(MSNEventBase):
         if self.pingCheckTask:
             self.pingCheckTask.stop()
             self.pingCheckTask = None
+        self.factory.stopTrying()
         self.sendLine("OUT")
         self.transport.loseConnection()
 
-class NotificationFactory(ClientFactory):
+class NotificationFactory(ReconnectingClientFactory):
     """
     Factory for the NotificationClient protocol.
     This is basically responsible for keeping
@@ -2017,6 +2020,8 @@ class NotificationFactory(ClientFactory):
                           (the whole URL is required)
     @ivar status: The status of the client -- this is generally kept
                   up to date by the default command handlers
+    @ivar maxRetries: The number of times the factory will reconnect
+                      if the connection dies because of a network error.
     """
 
     contacts = None
@@ -2026,6 +2031,7 @@ class NotificationFactory(ClientFactory):
     passportServer = 'https://nexus.passport.com/rdr/pprdr.asp'
     status = 'FLN'
     protocol = NotificationClient
+    maxRetries = 5
 
 
 class SwitchboardClient(MSNEventBase):
@@ -2367,6 +2373,7 @@ class SwitchboardClient(MSNEventBase):
         def bufferClosed(data):
             d.callback((data,))
         buffer = StringBuffer(bufferClosed)
+        buffer.error = lambda: None
         slpLink = SLPLink_AvatarReceive(remoteUser=msnContact.userHandle, switchboard=self, consumer=buffer, context=msnContact.msnobj.text)
         self.slpLinks[slpLink.sessionID] = slpLink
         return d
@@ -3013,10 +3020,12 @@ class SLPLink_AvatarReceive(SLPLink_Receive):
                 "AppID"    : 1,\
                 "Context"  : context}
         self.sendSLPMessage("INVITE", "application/x-msnmsgr-sessionreqbody", data)
+        self.handlePacket = self.wait_dataprep
 
     def handleSLPMessage(self, slpMessage):
         if slpMessage.status == "200":
-            self.handlePacket = self.wait_dataprep
+            pass
+            #self.handlePacket = self.wait_dataprep # Moved upwards
         else:
             if MSNP2PDEBUG: log.msg("SLPLink is over due to error or BYE")
             self.killLink()