X-Git-Url: https://code.delx.au/pymsnt/blobdiff_plain/62534e74df1796f4b708209da91112af00dee5be..ab3667805a3bb1f43d9a3dcbfe74d3d15b0ea0fa:/src/main.py diff --git a/src/main.py b/src/main.py index 4de6f42..eb90dd4 100644 --- a/src/main.py +++ b/src/main.py @@ -7,7 +7,7 @@ sys.setdefaultencoding("utf-8") sys.stdout = codecs.lookup('utf-8')[-1](sys.stdout) # Find the best reactor -selectWarning = "Unable to install any good reactors (kqueue, epoll, poll).\nWe fell back to using select. You may have scalability problems.\nThis reactor will not support more than 1024 connections +at a time." +selectWarning = "Unable to install any good reactors (kqueue, epoll, poll).\nWe fell back to using select. You may have scalability problems.\nThis reactor will not support more than 1024 connections at a time." try: from twisted.internet import epollreactor as bestreactor except: @@ -25,7 +25,7 @@ except: from twisted.internet import default as bestreactor print selectWarning except: - print "Unable to find a reactor.\nExiting..." + print "Unable to find a reactor. Please make sure you have Twisted properly installed.\nExiting..." sys.exit(1) bestreactor.install() @@ -96,6 +96,7 @@ from tlib.xmlw import Element, jid, component from debug import LogEvent, INFO, WARN, ERROR import debug +import svninfo import utils import xdb import avatar @@ -114,11 +115,15 @@ import housekeep class PyTransport(component.Service): def __init__(self): LogEvent(INFO) + try: + LogEvent(INFO, msg="SVN r" + str(svninfo.getSVNVersion())) + except: + pass # Discovery, as well as some builtin features self.discovery = disco.ServerDiscovery(self) - self.discovery.addIdentity("gateway", legacy.id, legacy.name, config.jid) - self.discovery.addIdentity("conference", "text", legacy.name + " Chatrooms", config.jid) + self.discovery.addIdentity("gateway", legacy.id, config.discoName, config.jid) + self.discovery.addIdentity("conference", "text", config.discoName + " Chatrooms", config.jid) self.discovery.addFeature(disco.XCONFERENCE, None, config.jid) # So that clients know you can create groupchat rooms on the server self.discovery.addFeature("jabber:iq:conference", None, config.jid) # We don't actually support this, but Psi has a bug where it looks for this instead of the above self.discovery.addIdentity("client", "pc", "MSN Messenger", "USER") @@ -242,10 +247,11 @@ class PyTransport(component.Service): mtype = el.getAttribute("type") s = self.sessions.get(froj.userhost(), None) if mtype == "error" and s: + LogEvent(INFO, s.jabberID, "Removing session because of message type=error") s.removeMe() elif s: s.onMessage(el) - else: + elif mtype != "error": to = el.getAttribute("to") ulang = utils.getLang(el) body = None @@ -254,6 +260,7 @@ class PyTransport(component.Service): body = child.__str__() LogEvent(INFO, "", "Sending error response to a message outside of session.") jabw.sendErrorMessage(self, fro, to, "auth", "not-authorized", lang.get(ulang).notLoggedIn, body) + jabw.sendPresence(self, fro, to, ptype="unavailable") def onPresence(self, el): fro = el.getAttribute("from") @@ -265,8 +272,12 @@ class PyTransport(component.Service): LogEvent(WARN, "", "Failed stringprep.") return + ptype = el.getAttribute("type") s = self.sessions.get(froj.userhost()) - if s: + if ptype == "error" and s: + LogEvent(INFO, s.jabberID, "Removing session because of message type=error") + s.removeMe() + elif s: s.onPresence(el) else: ulang = utils.getLang(el) @@ -288,25 +299,24 @@ class PyTransport(component.Service): elif el.getAttribute("type") != "error": LogEvent(INFO, "", "Sending unavailable presence to non-logged in user.") - pres = Element((None, "presence")) - pres.attributes["from"] = to - pres.attributes["to"] = fro - pres.attributes["type"] = "unavailable" - self.send(pres) + jabw.sendPresence(self, fro, to, ptype="unavailable") return elif ptype and (ptype.startswith("subscribe") or ptype.startswith("unsubscribe")): # They haven't logged in, and are trying to change subscription to a user + # No, lets not log them in. Lets send an error :) + jabw.sendPresence(self, fro, to, ptype="error") + # Lets log them in and then do it - LogEvent(INFO, "", "Attempting to create a session to do subscription stuff.") - s = session.makeSession(self, froj.userhost(), ulang) - if s: - self.sessions[froj.userhost()] = s - LogEvent(INFO, "", "New session created.") - # Tell the session there's a new resource - s.handleResourcePresence(froj.userhost(), froj.resource, toj.userhost(), toj.resource, 0, None, None, None) - # Send this subscription - s.onPresence(el) + #LogEvent(INFO, "", "Attempting to create a session to do subscription stuff.") + #s = session.makeSession(self, froj.userhost(), ulang) + #if s: + # self.sessions[froj.userhost()] = s + # LogEvent(INFO, "", "New session created.") + # # Tell the session there's a new resource + # s.handleResourcePresence(froj.userhost(), froj.resource, toj.userhost(), toj.resource, 0, None, None, None) + # # Send this subscription + # s.onPresence(el) class App: