def update_room(self): try: if len(self.clients) <= 0: return if self.paused: return; map(lambda i: i.update(self), self.items) self.gamemode.update(self) if self.intermission_end_time is not None: if time.time() > self.intermission_end_time: with self.broadcastbuffer(1, True) as cds: swh.put_mapreload(cds) self.intermission_end_time = None elif self.match_end_time is not None and self.gamemode.timed: if time.time() > self.match_end_time: with self.broadcastbuffer(1, True) as cds: swh.put_timeup(cds, 0) self.match_end_time = None self.intermission_end_time = time.time() + INTERMISSIONLEN except: traceback.print_exc()
def paused(self, value): if self.paused == value: return with self.broadcastbuffer(1, True) as cds: if value: self.pause_start = time.time() else: extend = (time.time() - self.pause_start) map(lambda i: i.extend(extend), self.items) self.match_end_time += extend self.pause_start = None swh.put_pausegame(cds, self.paused) if not value: swh.put_timeup(cds, self.timeleft)
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()
def timeleft(self, value): self.match_end_time = time.time() + value with self.broadcastbuffer(1, True) as cds: swh.put_timeup(cds, self.timeleft)