示例#1
0
    def handleClientInRoom(self, uid, rid, flag, name):

        if flag == EV_LEAVE:
            msg = "<userleave id='%d' name='%s' rid='%d' />" % (uid, escape_string(name), rid)
        else:
            msg = "<userjoin id='%d' name='%s' rid='%d' />" % (uid, escape_string(name), rid)

        c = self.db.cursor()
        s = "select users_id from users_rooms where rooms_id = %d" % rid
        c.execute(s)
        rs = c.fetchall()

        if rs is None or len(rs) == 0:
            # there is no one in the room, we don't need to notify anybody
            return

        notifyList = []
        for r in rs:
            notifyList.append(r[0])
        print 'notifyList', notifyList

        for ids in self._map:
            if not isinstance(self._map[ids], PalabreClient):
                continue
            #print "ids=%d, uid=%d" % (self._map[ids].ids, uid)
            #print "notifyList: ", notifyList

            targetIds = self._map[ids].ids

            if targetIds != uid and targetIds in notifyList:
                # We don't need to notify ourselves
                print 'GOING:', ids
                self._map[ids].clientSendMessage(msg)
示例#2
0
    def checkPassword(self, nickName, password, sesId, ip):
        rc = True
        try:
            c = self.db.cursor()
            c.execute("select id from users where name = '%s' and upassword = '******'" %\
                (escape_string(nickName), escape_string(password)))
            rs = c.fetchone()
            if rs is None:
                rc = False
                ids = -1
            else:
                ids = rs[0]
                s = "insert into sessions (sesid, userid, ip) values ('%s', %d, '%s')" %\
                    (sesId, ids, ip)
                print "Executing: ", s
                c.execute(s)

                s = "insert into connect_history (sesid, userid, lastip) values ('%s', %d, '%s')" %\
                    (sesId, ids, ip)
                print "Executing: ", s
                c.execute(s)

                self.db.commit();
        except:
            raise
        return (rc, ids)