Ejemplo n.º 1
0
    async def read_match(self) -> Match:
        """Read an osu! match from the internal buffer."""
        m = Match()

        # ignore match id (i16) and inprogress (i8).
        self._buf = self._buf[3:]

        m.type = MatchTypes(await self.read_i8())
        m.mods = Mods(await self.read_i32())

        m.name = await self.read_string()
        m.passwd = await self.read_string()

        # TODO: don't do this, do it like everyone else..

        # ignore the map's name, we're going
        # to get all it's info from the md5.
        await self.read_string()

        map_id = await self.read_i32()
        map_md5 = await self.read_string()

        m.bmap = await Beatmap.from_md5(map_md5)
        if not m.bmap and map_id != (1 << 32) - 1:
            # if they pick an unsubmitted map,
            # just give them vivid [insane] lol.
            vivid_md5 = '1cf5b2c2edfafd055536d2cefcb89c0e'
            m.bmap = await Beatmap.from_md5(vivid_md5)

        for slot in m.slots:
            slot.status = await self.read_i8()

        for slot in m.slots:
            slot.team = Teams(await self.read_i8())

        for slot in m.slots:
            if slot.status & SlotStatus.has_player:
                # we don't need this, ignore it.
                self._buf = self._buf[4:]

        host_id = await self.read_i32()
        m.host = await glob.players.get_by_id(host_id)

        m.mode = GameMode(await self.read_i8())
        m.match_scoring = MatchScoringTypes(await self.read_i8())
        m.team_type = MatchTeamTypes(await self.read_i8())
        m.freemods = await self.read_i8() == 1

        # if we're in freemods mode,
        # read individual slot mods.
        if m.freemods:
            for slot in m.slots:
                slot.mods = Mods(await self.read_i32())

        # read the seed (used for mania)
        m.seed = await self.read_i32()

        return m
Ejemplo n.º 2
0
def read_match(data: bytearray) -> Tuple[Match, int]:
    """ Read an osu! match from `data`. """
    m = Match()

    # Ignore match id (i32) & inprogress (i8).
    offset = 3

    # Read type & match mods.
    m.type, m.mods = struct.unpack('<bI', data[offset:offset + 5])
    offset += 5

    # Read match name & password.
    m.name, offs = read_string(data[offset:])
    offset += offs
    m.passwd, offs = read_string(data[offset:])
    offset += offs

    # Ignore map's name.
    offset += 1
    if data[offset - 1] == 0x0b:
        offset += sum(read_uleb128(data[offset:]))

    # Ignore map's id.
    offset += 4

    # Read map's md5 (only thing needed to get map).
    map_md5, offs = read_string(data[offset:])
    offset += offs

    # Get beatmap object for map selected.
    m.bmap = Beatmap.from_md5(map_md5)

    # Read slot statuses.
    for s in m.slots:
        s.status = data[offset]
        offset += 1

    # Read slot teams.
    for s in m.slots:
        s.team = data[offset]
        offset += 1

    for s in m.slots:
        if s.status & SlotStatus.has_player:
            # Dont think we need this?
            offset += 4

    # Read match host.
    m.host = glob.players.get_by_id(
        int.from_bytes(data[offset:offset + 4], 'little'))
    offset += 4

    # Read match mode, match scoring,
    # team type, and freemods.
    m.game_mode = data[offset]
    offset += 1
    m.match_scoring = data[offset]
    offset += 1
    m.team_type = data[offset]
    offset += 1
    m.freemods = data[offset]
    offset += 1

    # If we're in freemods mode,
    # read individual slot mods.
    if m.freemods:
        for s in m.slots:
            s.mods = int.from_bytes(data[offset:offset + 4], 'little')
            offset += 4

    # Read the seed from multi.
    # XXX: Used for mania random mod.
    m.seed = int.from_bytes(data[offset:offset + 4], 'little')
    return m, offset + 4
Ejemplo n.º 3
0
async def read_match(data: bytearray) -> Tuple[Match, int]:
    """ Read an osu! match from `data`. """
    m = Match()

    # Ignore match id (i32) & inprogress (i8).
    offset = 3

    # Read type & match mods.
    m.type, m.mods = struct.unpack('<bI', data[offset:offset + 5])
    offset += 5

    # Read match name & password.
    m.name, offs = await read_string(data[offset:])
    offset += offs
    m.passwd, offs = await read_string(data[offset:])
    offset += offs

    # Ignore map's name.
    offset += 1
    if data[offset - 1] == 0x0b:
        offset += sum(await read_uleb128(data[offset:]))

    # Read beatmap information (id & md5).
    map_id = int.from_bytes(data[offset:offset + 4], 'little')
    offset += 4

    map_md5, offs = await read_string(data[offset:])
    offset += offs

    # Get beatmap object for map selected.
    m.bmap = await Beatmap.from_md5(map_md5)
    if not m.bmap and map_id != (1 << 32) - 1:
        # If they pick an unsubmitted map,
        # just give them Vivid [Insane] lol.
        vivid_md5 = '1cf5b2c2edfafd055536d2cefcb89c0e'
        m.bmap = await Beatmap.from_md5(vivid_md5)

    # Read slot statuses.
    for s in m.slots:
        s.status = data[offset]
        offset += 1

    # Read slot teams.
    for s in m.slots:
        s.team = data[offset]
        offset += 1

    for s in m.slots:
        if s.status & SlotStatus.has_player:
            # Dont think we need this?
            offset += 4

    # Read match host.
    user_id = int.from_bytes(data[offset:offset + 4], 'little')
    m.host = await glob.players.get_by_id(user_id)
    offset += 4

    # Read match mode, match scoring,
    # team type, and freemods.
    m.game_mode = data[offset]
    offset += 1
    m.match_scoring = data[offset]
    offset += 1
    m.team_type = data[offset]
    offset += 1
    m.freemods = data[offset]
    offset += 1

    # If we're in freemods mode,
    # read individual slot mods.
    if m.freemods:
        for s in m.slots:
            s.mods = int.from_bytes(data[offset:offset + 4], 'little')
            offset += 4

    # Read the seed from multi.
    # XXX: Used for mania random mod.
    m.seed = int.from_bytes(data[offset:offset + 4], 'little')
    return m, offset + 4