def matchInvite(p: Player, pr: PacketReader) -> None: if not p.match: printlog(f"{p} tried to invite someone to a match but isn't in one!") pr.ignore(4) return userID = pr.read(osuTypes.i32)[0] if not (t := glob.players.get_by_id(userID)): printlog(f'{t} tried to invite a user who is not online! ({userID})') return
async def logout(p: Player, pr: PacketReader) -> None: pr.ignore(4) # osu client sends \x00\x00\x00\x00 every time lol if (time.time() - p.login_time) < 2: # osu! has a weird tendency to log out immediately when # it logs in, then reconnects? not sure why..? return await p.logout() await plog(f'{p} logged out.', Ansi.LIGHT_YELLOW)
async def matchInvite(p: Player, pr: PacketReader) -> None: if not p.match: await plog(f"{p} tried to invite someone to a match but isn't in one!") pr.ignore(4) return user_id, = await pr.read(osuTypes.i32) if not (t := await glob.players.get_by_id(user_id)): await plog(f'{t} tried to invite a user who is not online! ({user_id})' ) return
def startSpectating(p: Player, pr: PacketReader) -> None: target_id = pr.read(osuTypes.i32)[0] if not (host := glob.players.get_by_id(target_id)): printlog(f'{p} tried to spectate nonexistant id {target_id}.', Ansi.YELLOW) return
def matchJoin(p: Player, pr: PacketReader) -> None: m_id, passwd = pr.read(osuTypes.i32, osuTypes.string) if m_id not in range(64): return if not (m := glob.matches.get_by_id(m_id)): printlog(f'{p} tried to join a non-existant mp lobby?') return
def statsRequest(p: Player, pr: PacketReader) -> None: if len(pr.data) < 6: return userIDs = pr.read(osuTypes.i32_list) is_online = lambda o: o in glob.players.ids and o != p.id for online in filter(is_online, userIDs): target = glob.players.get_by_id(online) p.enqueue(packets.userStats(target))
def sendPrivateMessage(p: Player, pr: PacketReader) -> None: if p.silenced: printlog(f'{p} tried to send a dm while silenced.', Ansi.YELLOW) return client, msg, target, client_id = pr.read(osuTypes.message) if not (t := glob.players.get_by_name(target)): printlog(f'{p} tried to write to non-existant user {target}.', Ansi.YELLOW) return
def readStatus(p: Player, pr: PacketReader) -> None: data = pr.read( osuTypes.u8, # actionType osuTypes.string, # infotext osuTypes.string, # beatmap md5 osuTypes.u32, # mods osuTypes.u8, # gamemode osuTypes.i32 # beatmapid ) p.status.update(*data) p.rx = p.status.mods & Mods.RELAX > 0 glob.players.enqueue(packets.userStats(p))
def channelJoin(p: Player, pr: PacketReader) -> None: chan_name = pr.read(osuTypes.string)[0] c = glob.channels.get(chan_name) if not c or not p.join_channel(c): printlog(f'{p} failed to join {chan_name}.', Ansi.YELLOW) return # Enqueue new channelinfo (playercount) to all players. glob.players.enqueue(packets.channelInfo(*c.basic_info)) # Enqueue channelJoin to our player. p.enqueue(packets.channelJoin(c.name))
def sendMessage(p: Player, pr: PacketReader) -> None: if p.silenced: printlog(f'{p} tried to send a message while silenced.', Ansi.YELLOW) return # client_id only proto >= 14 client, msg, target, client_id = pr.read(osuTypes.message) # no nice wrapper to do it in reverse :P if target == '#spectator': target = f'#spec_{p.spectating.id if p.spectating else p.id}' elif target == '#multiplayer': target = f'#multi_{p.match.id if p.match is not None else 0}' if not (t := glob.channels.get(target)): printlog(f'{p} tried to write to non-existant {target}.', Ansi.YELLOW) return
def receiveUpdates(p: Player, pr: PacketReader) -> None: if (f := pr.read(osuTypes.i32)[0]) not in range(3): printlog(f'{p} tried to set his presence filter to {f}?') return
async def setAwayMessage(p: Player, pr: PacketReader) -> None: pr.ignore(3) # why does first string send \x0b\x00? p.away_msg, = await pr.read(osuTypes.string) pr.ignore(4)
async def spectateFrames(p: Player, pr: PacketReader) -> None: data = await packets.spectateFrames(pr.data[:pr.length]) pr.ignore_packet() for t in p.spectators: t.enqueue(data)
def toggleBlockingDMs(p: Player, pr: PacketReader) -> None: p.pm_private = pr.read(osuTypes.i32)[0] == 1
def userPresenceRequest(p: Player, pr: PacketReader) -> None: for pid in pr.read(osuTypes.i32_list): if t := glob.players.get_by_id(pid): p.enqueue(packets.userPresence(t))
def matchCreate(p: Player, pr: PacketReader) -> None: m = pr.read(osuTypes.match)[0] m.host = p p.join_match(m, m.passwd) printlog(f'{p} created a new multiplayer match.')
def channelPart(p: Player, pr: PacketReader) -> None: if not (chan := pr.read(osuTypes.string)[0]): return
def friendRemove(p: Player, pr: PacketReader) -> None: userID = pr.read(osuTypes.i32)[0] if not (t := glob.players.get_by_id(userID)): printlog(f'{t} tried to remove a user who is not online! ({userID})') return