def __init__(self, rosters, host):
        self.probed = False
        self._closed = False
        self.rosters = rosters
        self._session = None

        self.rosters.set_resources(self.get_resources())

        self._fixedjid = UCache.UCache.formalize_jid(unicode(self.authJID))
        self._userid = self._fixedjid.partition('@')[0].encode("gbk")

        if (not self.rosters.allow_login(self.authJID.bare)):
            Log.warn("user %s login denied" % self._userid)
#            self.unbind_res()
            self.stream_error('policy-violation', 'Login denied. Too many logins?')
            return
        Log.info("%s: session start" % unicode(self.authJID))

        if self.authJID.resource[:-8] != "Resource" and len(self.authJID.resource) > 8:
            try:
                routes = self.routes(self.authJID.bare)
                for route in routes:
                    jid = route[0]
                    if jid.resource[:-8] == self.authJID.resource[:-8]:
                        if jid.resource != self.authJID.resource:
                            # old resource!
                            Log.info("old jid: %s %r" % (jid.full, route[1]))
                            route[1].stream_error('conflict', 'A new client with the same resource connected')
                    else:
                        Log.info("another me: %s %r" % (jid.full, route[1]))
            except NoRoute:
                pass
            Log.debug("%s: checked for old sessions" % self.authJID.full)

        # Login the user
        self._user = UserManager.UserManager.LoadUser(self._userid)
        if (self._user == None):
            raise Exception("How can that be!")
        self._peer_addr = self.getpeername()
        self._session = Session(self._user, self._peer_addr[0])
        self._session.RecordLogin()
        # insert into global session list!
        self._userinfo = self._session.Register()
        self._loginid = self._session.utmpent
        self._hostname = host
        self.bind(xmpp.ReceivedCloseStream, self.recv_close)
        self.bind(xmpp.StreamClosed, self.stream_closed)
        self.bind(xmpp.SentCloseStream, self.sent_close)

        self.rosters.register_conn(self)

        msgbox = MsgBox.MsgBox(self._userid)
        if self.rosters.get_xmpp_read(self._user.GetUID()) is None:
            self.rosters.set_xmpp_read(self._user.GetUID(), msgbox.GetMsgCount(all = False) - msgbox.GetUnreadCount())
        self.check_msg()
dataset/ETHPy150Open HenryHu/pybbs/xmppserver.py/XMPPServer.__init__/original