def change_map_mode(self, map_name, mode_num): if not mode_num in gamemodes.keys(): return self.gamemode = gamemodes[mode_num]() self.hasitems = False self.items = [] self.map_name = map_name self.mode_num = mode_num with self.broadcastbuffer(1, True) as cds: swh.put_mapchange(cds, self.map_name, self.mode_num, self.hasitems) for client in self.clients.values(): client.send_spawn_state(self.gamemode) if self.gamemode.timed: self.timeleft = self.gamemode.timeout
def add_client(self, client): try: existing_clients = self.clients.values() self.clients[client.cn] = client self.gamemode.on_client_connected(self, client) # Connect up all the client signals client.connect_all_instance_signals(self, "on_client_") # Tell the client about the status of the room with client.sendbuffer(1, True) as cds: swh.put_welcome(cds, self.hasmap) if self.map_name != None: swh.put_mapchange(cds, self.map_name, self.mode_num, self.hasitems) if self.gamemode.timed and self.match_end_time is not None: swh.put_timeup(cds, self.timeleft) if self.gamemode.hasitems and self.hasitems: swh.put_itemlist(cds, self.items) swh.put_resume(cds, existing_clients) swh.put_initclients(cds, existing_clients) # Tell the other clients about the newcomer with self.broadcastbuffer(1, True, [client]) as cds: swh.put_resume(cds, [client]) swh.put_initclients(cds, [client]) if len(existing_clients) > 0: client.send_spawn_state(self.gamemode) except: traceback.print_exc()