def css_get_players(sock, chal=None): if chal == None: chal = css_get_challenge(sock) ms1 = fragmon.get_millis() sock.send(GET_PLAYERS + chal) sinfo = css_recv_multi_packet(sock) ms2 = fragmon.get_millis() ping = ms2 - ms1 header = sinfo[4] assert header == "D", "bad header for get players" player_count = ord(sinfo[5]) pos = 6 players = [] while pos < len(sinfo): plr = Player() plr.id, pos = query.parse_num(sinfo, pos, bytes=1) plr.name, pos = query.parse_str(sinfo, pos) plr.score, pos = query.parse_num(sinfo, pos, bytes=4) pos += 4 # XXX: player time not included players.append(plr) return ping, players, chal
def ut2_get_players(sock): if isinstance(sock, str): ping = 0 sinf = sock else: ms1 = fragmon.get_millis() sock.send(PLAYER_INFO) sinf = sock.recv(65535) ms2 = fragmon.get_millis() ping = ms2 - ms1 header = sinf[0] query_type = sinf[4] assert ord(query_type) == 2, 'invalid server info reply' pos = 5 #print repr(sinf) #print repr(sinf[pos:]) players =[] while pos < len(sinf): plr = Player() plr.id, pos = query.parse_num(sinf, pos, bytes=4) plr.name, pos = ut_parse_str(sinf, pos) plr.ping, pos = query.parse_num(sinf, pos, bytes=4) plr.score, pos = query.parse_num(sinf, pos, bytes=4, signed=True) stats, pos = query.parse_num(sinf, pos, bytes=4) if (stats & 1L<<29): plr.team = "Red" plr.teamid = 0 elif (stats & 1L<<30): plr.team = "Blue" plr.teamid = 1
def q4_make_players(pbuf, pi): buflen = len(pbuf) start = 0 players = [] while start < buflen: #XXX: Format for q4 1.1 seems to have changed slightly. this hack makes it work try: start, pid, ping, rate, ss = get_player(start, pbuf) except IndexError: break plr = Player() plr.name = q4_strip_name(ss[-2]) plr.team = q4_strip_name(ss[-1]) plr.ping = ping plr.id = pid #XXX: I believe q4max uses player ids to match players to teams plr.score = pi.get_score(pid) plr.teamid = pi.get_team(pid) #print '%2d %3d %4d %s %s' % (pid, p, rate, ss[-2], ss[-1]) players.append(plr) return players
def __init__(self, colorname='', *args, **kwargs): Player.__init__(self, *args, **kwargs) self.colorname = colorname