]> code.delx.au - pymsnt/blobdiff - src/legacy/msn/msnw.py
The <host/> config option now sets the bind address for outgoing connections
[pymsnt] / src / legacy / msn / msnw.py
index da41fc56e7f5d3f3c4eeda66932ea40fe4b0eeb7..1e361542a492e76fcacabac1905090514a5656d7 100644 (file)
@@ -25,6 +25,7 @@ class MSNConnection:
        MAXMESSAGESIZE     = 1400
        SWITCHBOARDTIMEOUT = 30.0*60.0
        GETALLAVATARS      = False
+       BINDADDRESS        = "0.0.0.0"
 
        def __init__(self, username, password, ident):
                """ Connects to the MSN servers.
@@ -62,7 +63,7 @@ class MSNConnection:
                d = Deferred()
                dispatchFactory.d = d
                d.addCallbacks(self._gotNotificationReferral, self.connectionFailed)
-               self.connectors.append(reactor.connectTCP("messenger.hotmail.com", 1863, dispatchFactory))
+               self.connectors.append(reactor.connectTCP("messenger.hotmail.com", 1863, dispatchFactory, bindAddress=(MSNConnection.BINDADDRESS, 0)))
                LogEvent(INFO, self.ident)
        
        def _gotNotificationReferral(self, (host, port)):
@@ -74,7 +75,7 @@ class MSNConnection:
                self.notificationFactory.password = self.password
                self.notificationFactory.msncon = self
                self.notificationFactory.protocol = NotificationClient
-               self.connectors.append(reactor.connectTCP(host, port, self.notificationFactory))
+               self.connectors.append(reactor.connectTCP(host, port, self.notificationFactory, bindAddress=(MSNConnection.BINDADDRESS, 0)))
                LogEvent(INFO, self.ident)
        
        def _sendSavedEvents(self):
@@ -169,16 +170,16 @@ class MSNConnection:
                sb = self.switchboardSessions.get(userHandle)
                if sb: return sb.sendTypingNotification()
        
-       def changeAvatar(self, imageData):
+       def changeAvatar(self, imageDataFunc):
                """
                Changes the user's avatar.
-               @param imageData: the new PNG avatar image data.
+               @param imageDataFunc: a function which returns the new PNG avatar image data.
                """
                if self.notificationClient:
                        LogEvent(INFO, self.ident)
-                       self.notificationClient.changeAvatar(imageData, push=True)
+                       self.notificationClient.changeAvatar(imageDataFunc, push=True)
                # Save the avatar for reuse on disconnection
-               self.savedEvents.avatarImageData = imageData
+               self.savedEvents.avatarImageDataFunc = imageDataFunc
        
        def changeStatus(self, statusCode, screenName, personal):
                """
@@ -342,13 +343,13 @@ class SavedEvents:
                self.screenName = ""
                self.statusCode = ""
                self.personal = ""
-               self.avatarImageData = ""
+               self.avatarImageDataFunc = None
                self.addContacts = []
                self.remContacts = []
        
        def send(self, msncon):
-               if self.avatarImageData:
-                       msncon.notificationClient.changeAvatar(self.avatarImageData, push=False)
+               if self.avatarImageDataFunc:
+                       msncon.notificationClient.changeAvatar(self.avatarImageDataFunc, push=False)
                if self.screenName or self.statusCode or self.personal:
                        msncon.changeStatus(self.statusCode, self.screenName, self.personal)
                for listType, userHandle in self.addContacts:
@@ -502,7 +503,7 @@ class SwitchboardSessionBase(msn.SwitchboardClient):
                        self.reply = 0
                        factory = ClientFactory()
                        factory.buildProtocol = lambda addr: self
-                       reactor.connectTCP(host, port, factory)
+                       self.msncon.connectors.append(reactor.connectTCP(host, port, factory, bindAddress=(MSNConnection.BINDADDRESS, 0)))
                def sbRequestFailed(ignored=None):
                        LogEvent(INFO, self.ident)
                        del self.msncon.switchboardSessions[self.remoteUser]
@@ -517,7 +518,7 @@ class SwitchboardSessionBase(msn.SwitchboardClient):
                self.reply = 1
                factory = ClientFactory()
                factory.buildProtocol = lambda addr: self
-               reactor.connectTCP(host, port, factory)
+               self.msncon.connectors.append(reactor.connectTCP(host, port, factory, bindAddress=(MSNConnection.BINDADDRESS, 0)))
        
        def flushBuffer(self):
                for message, noerror in self.messageBuffer[:]:
@@ -709,7 +710,7 @@ class OneSwitchboardSession(SwitchboardSessionBase):
        
        def userJoined(self, userHandle, screenName=''):
                LogEvent(INFO, self.ident)
-               if not self.reply:
+               if not self.reply and not self.ready:
                        self._ready()
                if userHandle != self.remoteUser:
                        # Another user has joined, so we now have three participants.