async def join_channel(self, c: Channel) -> bool: """Attempt to add `self` to `c`.""" if self in c: # user already in the channel. if glob.config.debug: log(f'{self} was double-added to {c}.') return False if not self.priv & c.read: log(f'{self} tried to join {c} but lacks privs.') return False # lobby can only be interacted with while in mp lobby. if c._name == '#lobby' and not self.in_lobby: return False c.append(self) # Add to channels self.channels.append(c) # Add to player self.enqueue(packets.channelJoin(c.name)) # update channel usercounts for all clients that can see. # for instanced channels, enqueue update to only players # in the instance; for normal channels, enqueue to all. targets = c.players if c.instance else glob.players for p in targets: p.enqueue(packets.channelInfo(*c.basic_info)) if glob.config.debug: log(f'{self} joined {c}.') return True
async def handle(self, p: Player) -> None: c = glob.channels[self.name] if not c or not await p.join_channel(c): log(f'{p} failed to join {self.name}.', Ansi.YELLOW) return # enqueue channelJoin to our player. p.enqueue(packets.channelJoin(c.name))
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 join_channel(self, c: Channel) -> bool: if self in c: printlog(f'{self} tried to double join {c}.') return False if not self.priv & c.read: printlog(f'{self} tried to join {c} but lacks privs.') return False # Lobby can only be interacted with while in mp lobby. if c._name == '#lobby' and not self.in_lobby: return False c.append(self) # Add to channels self.channels.append(c) # Add to player self.enqueue(packets.channelJoin(c.name)) printlog(f'{self} joined {c}.') return True
) # tells osu! to load channels from config, i believe? data += packets.channelInfoEnd() # channels for c in glob.channels: if p.priv & c.read_priv != c.read_priv: continue # no priv to read # autojoinable channels if c.auto_join and await p.join_channel(c): # NOTE: p.join_channel enqueues channelJoin, but # if we don't send this back in this specific request, # the client will attempt to join the channel again. data += packets.channelJoin(c.name) data += packets.channelInfo(*c.basic_info) # fetch some of the player's # information from sql to be cached. await p.achievements_from_sql() await p.stats_from_sql_full() await p.friends_from_sql() if glob.config.server_build: # update their country data with # the IP from the login request. await p.fetch_geoloc(ip) # update our new player's stats, and broadcast them.
f'Current build: {glob.version}') + # tells osu! to load channels from config, i believe? packets.channelInfoEnd()) # channels for c in glob.channels: if not p.priv & c.read: continue # no priv to read # autojoinable channels if c.auto_join and await p.join_channel(c): # NOTE: p.join_channel enqueues channelJoin, but # if we don't send this back in this specific request, # the client will attempt to join the channel again. data.extend(packets.channelJoin(c.name)) data.extend(packets.channelInfo(*c.basic_info)) # fetch some of the player's # information from sql to be cached. await p.stats_from_sql_full() await p.friends_from_sql() if glob.config.server_build: # update their country data with # the IP from the login request. await p.fetch_geoloc(ip) # update our new player's stats, and broadcast them. user_data = (packets.userPresence(p) + packets.userStats(p))
if not (c := glob.channels.get(chan_name)): # Spec channel does not exist, create it and join. glob.channels.add( Channel(name=chan_name, topic=f"{self.name}'s spectator channel.'", read=Privileges.Normal, write=Privileges.Normal, auto_join=False, temp=True)) c = glob.channels.get(chan_name) if not p.join_channel(c): return printlog(f'{self} failed to join {c}?') p.enqueue(packets.channelJoin(c.name)) p_joined = packets.fellowSpectatorJoined(p.id) for s in self.spectators: s.enqueue(p_joined) p.enqueue(packets.fellowSpectatorJoined(s.id)) self.spectators.append(p) p.spectating = self self.enqueue(packets.spectatorJoined(p.id)) printlog(f'{p} is now spectating {self}.') def remove_spectator(self, p) -> None: self.spectators.remove(p) p.spectating = None