def getPlayer(self, id): if id in self.player.keys(): return self.player[id] self.cur.execute("select name,hw_x,hw_y,login from player where id=:id",(id,)) r = self.cur.fetchone() if not r: return None p = Player(id, r[0], r[3]) if r[1] and r[2]: p.hw = r[1],r[2] self.player[id] = p return p
def getPlayerByLogin(self, login): p = [p for _,p in self.player.iteritems() if p.login==login] if p: return p #look in db self.cur.execute("select id,name,hw_x,hw_y from player where login=:login",(login,)) r = self.cur.fetchone() #or should we add empty user to the list ? if not r: log.error('player (login: %s) not found'%(login,)) return None p = Player(r[0], r[1], login) if r[2] and r[3]: p.hw = to_pos(r[2],r[3]) self.player[p.id] = p return p