Example #1
0
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
Example #2
0
def ut2_get_info(sock):
    ms1 = fragmon.get_millis()
    sock.send(SERVER_INFO)
    sinf = sock.recv(65535)
    ms2 = fragmon.get_millis()
    ping = ms2 - ms1

    header = sinf[0]
    query_type = sinf[4]
    assert ord(query_type) == 0, 'invalid info reply'
   
    info = UT2Info(teamAname = 'Red', teamBname = 'Blue', teamAcolor=0xffb1b1, teamBcolor=0xa6acff)

    #start past headder and other fluff
    pos = 10            
    info.game_port,     pos = query.parse_num(sinf, pos, bytes=4) #get game port
    #move past more fluff 
    pos += 4 
    info.hostname,      pos = ut_parse_str(sinf, pos)
    info.map,           pos = ut_parse_str(sinf, pos)
    info.type,          pos = ut_parse_str(sinf, pos)
    info.curplayers,    pos = query.parse_num(sinf, pos, bytes=4)
    info.maxplayers,    pos = query.parse_num(sinf, pos, bytes=4)

    info.ping = ping
    gt = info.type.lower()

    if gt.find('ctf') >= 0 or gt.find('team') or gt.find('onslaught') >= 0:
        info.mode = "team"
    else:
        info.mode = "1v1"

    return ping, info
Example #3
0
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
Example #4
0
def css_check_multi_packet(buf):
    req_id = pcur = ptot = None
    if buf[0] == "\xfe":
        req_id = query.parse_num(buf, 4, bytes=4)[0]
        pnum = ord(buf[8])
        pcur = pnum >> 4
        ptot = pnum & 0x0F
        buf = buf[9:]
    return req_id, pcur, ptot, buf
Example #5
0
File: q4.py Project: cdrttn/fragmon
def get_player(start, buf):
    id = ord(buf[start])
    start += 1
    ping, start = query.parse_num(buf, start, bytes=2)
    rate, start = query.parse_num(buf, start, bytes=2)
    
    #ping, rate = struct.unpack('hh', buf[start+1:start+5])

    #start += 5 
    #f**k this shit
    strs = []
    for i in xrange(STRCOUNT):
        pos = buf[start:].find('\x00')    
        #print 'pos ->', pos
        assert pos >= 0
        s = buf[start:start+pos]
        #print 's ->', s
        start += pos + 1
        strs.append(s)  

    return start, id, ping, rate, strs 
Example #6
0
def css_get_rules(sock, chal=None):
    if chal == None:
        chal = css_get_challenge(sock)

    ms1 = fragmon.get_millis()
    sock.send(GET_RULES + chal)
    sinfo = css_recv_multi_packet(sock)
    ms2 = fragmon.get_millis()
    ping = ms2 - ms1

    header = sinfo[4]
    assert header == "E", "bad header for get rules"

    pos = 5
    rules_count, pos = query.parse_num(sinfo, pos, bytes=2)
    rules = []
    while pos < len(sinfo):
        key, pos = query.parse_str(sinfo, pos)
        value, pos = query.parse_str(sinfo, pos)
        rules.append(Rule(key, value))

    return ping, rules, chal
Example #7
0
def css_get_info_source(buf, pos):
    info = HL2Overview(teamAname="Terrorists", teamBname="Counter Terrorists")

    info.hostname, pos = query.parse_str(buf, pos)
    info.map, pos = query.parse_str(buf, pos)
    info.game_dir, pos = query.parse_str(buf, pos)
    info.type, pos = query.parse_str(buf, pos)
    info.appid, pos = query.parse_num(buf, pos, bytes=2)
    info.curplayers, pos = query.parse_num(buf, pos, bytes=1)
    info.maxplayers, pos = query.parse_num(buf, pos, bytes=1)
    info.numbots, pos = query.parse_num(buf, pos, bytes=1)
    info.dedicated, pos = buf[pos], pos + 1
    info.os, pos = buf[pos], pos + 1
    info.password, pos = query.parse_num(buf, pos, bytes=1)
    info.secure, pos = query.parse_num(buf, pos, bytes=1)
    info.version, pos = query.parse_str(buf, pos)

    return info
Example #8
0
def css_get_info_hl1(buf, pos):
    info = HL1Overview(teamAname="Terrorists", teamBname="Counter Terrorists")

    info.game_ip, pos = query.parse_str(buf, pos)
    info.hostname, pos = query.parse_str(buf, pos)
    info.map, pos = query.parse_str(buf, pos)
    info.game_dir, pos = query.parse_str(buf, pos)
    info.type, pos = query.parse_str(buf, pos)
    info.curplayers, pos = query.parse_num(buf, pos, bytes=1)
    info.maxplayers, pos = query.parse_num(buf, pos, bytes=1)
    version, pos = query.parse_num(buf, pos, bytes=1)
    info.dedicated, pos = buf[pos], pos + 1
    info.os, pos = buf[pos], pos + 1
    info.password, pos = query.parse_num(buf, pos, bytes=1)
    info.is_mod, pos = query.parse_num(buf, pos, bytes=1)
    info.mod_urlinfo, pos = query.parse_str(buf, pos)
    info.mod_urldl, pos = query.parse_str(buf, pos)
    fluff, pos = query.parse_str(buf, pos)
    info.mod_vers, pos = query.parse_num(buf, pos, bytes=4)
    info.mod_size, pos = query.parse_num(buf, pos, bytes=4)
    info.mod_svonly, pos = query.parse_num(buf, pos, bytes=1)
    info.mod_cldll, pos = query.parse_num(buf, pos, bytes=1)
    info.secure, pos = query.parse_num(buf, pos, bytes=1)
    info.numbots, pos = query.parse_num(buf, pos, bytes=1)

    info.version = str(version)

    return info