playerCode, client in self.clients.iteritems(): client.resetPlay() self.currentWorld = self.currentWorld for playerCode, client in self.clients.iteritems(): client.startPlay() else: pass def addClient(self, newClient): self.clients[newClient.playerCode] = newClient self.informAllOthers(newClient, TransformiceClientHandler.sendNewPlayer, [newClient.getPlayerData()]) newClient.room = self newClient.startPlay() #self.stateRecorder.sendToClient(newClient) def updatesqlserver(self): for playerCode, client in self.clients.iteritems(): if client.username.startswith("*"): pass else: dbcur.execute('UPDATE users SET rounds = ? WHERE name = ?', [client.roundCount, client.username]) dbcur.execute('UPDATE users SET saves = ? WHERE name = ?', [client.micesaves, client.username]) dbcur.execute('UPDATE users SET shamcheese = ? WHERE name = ?', [client.shamancheese, client.username]) dbcur.execute('UPDATE users SET first = ? WHERE name = ?', [client.firstcount, client.username]) dbcur.execute('UPDATE users SET cheese = ? WHERE name = ?', [client.cheesecount, client.username]) dbcur.execute('UPDATE users SET shopcheese = ? WHERE name = ?', [client.shopcheese, client.username]) dbcur.execute('UPDATE users SET shop = ? WHERE name = ?', [client.shopitems, client.username]) dbcur.execute('UPDATE users SET look = ? WHERE name = ?', [client.look, client.username]) dbcur.execute('UPDATE users SET lastroom = ? WHERE name = ?', [client.room, client.username]) def removeClient(self, removeClient): if self.clients.has_key(removeClient.playerCode): for playerCode, client in self.clients.iteritems(): if playerCode == removeClient.playerCode: if client.username.startswith("*"): pass else: dbcur.execute('UPDATE users SET rounds = ? WHERE name = ?', [client.roundCount, client.username]) dbcur.execute('UPDATE users SET lastroom = ? WHERE name = ?', ["Offline", client.username]) dbcur.execute('UPDATE users SET saves = ? WHERE name = ?', [client.micesaves, client.username]) dbcur.execute('UPDATE users SET shamcheese = ? WHERE name = ?', [client.shamancheese, client.username]) dbcur.execute('UPDATE users SET first = ? WHERE name = ?', [client.firstcount, client.username]) dbcur.execute('UPDATE users SET cheese = ? WHERE name = ?', [client.cheesecount, client.username]) dbcur.execute('UPDATE users SET shopcheese = ? WHERE name = ?', [client.shopcheese, client.username]) dbcur.execute('UPDATE users SET shop = ? WHERE name = ?', [client.shopitems, client.username]) dbcur.execute('UPDATE users SET look = ? WHERE name = ?', [client.look, client.username]) del self.clients[removeClient.playerCode] if self.getPlayerCount() == 0: self.server.closeRoom(self) return self.informAll(TransformiceClientHandler.sendPlayerDisconnect, [removeClient.playerCode]) if self.currentSyncroniserCode == removeClient.playerCode: newSyncroniser = random.choice(self.clients.values()) newSyncroniser.isSyncroniser = True self.currentSyncroniserCode = newSyncroniser.playerCode self.informAll(TransformiceClientHandler.sendSynchroniser, [newSyncroniser.playerCode]) self.checkShouldChangeWorld() def changeSyncroniserRandom(self): newSyncroniser = random.choice(self.clients.values()) newSyncroniser.isSyncroniser = True self.currentSyncroniserCode = newSyncroniser.playerCode self.informAll(TransformiceClientHandler.sendSynchroniser, [newSyncroniser.playerCode]) def getPlayerName(self, code): for room in self.server.rooms.itervalues(): for playerCode, client in room.clients.iteritems(): if client.playerCode == code: return client.username def getPlayerCode(self, name): for room in self.server.rooms.itervalues(): for playerCode, client in room.clients.iteritems(): if client.username == name: return client.playerCode def changeSyncroniserSpecific(self, username): for room in self.server.rooms.itervalues(): for playerCode, client in room.clients.iteritems(): if client.username == username: newSyncroniser = client break newSyncroniser.isSyncroniser = True self.currentSyncroniserCode = newSyncroniser.playerCode self.informAll(TransformiceClientHandler.sendSynchroniser, [newSyncroniser.playerCode]) def playMusic(self, path): self.informAll(TransformiceClientHandler.sendPlayMusic, [path]) def changeScore(self, playerCode, score): for playerCode, client in self.clients.iteritems(): if client.playerCode == playerCode: client.score = score def startSnowStorm(self): self.sendAllOthersAndSelf(self, "\x05" + "\x17", ["0"]) self.isSnowing=True self.endSnowStormTimer = threading.Timer(300, self.endSnowStorm) self.endSnowStormTimer.start() def endSnowStorm(self): self.sendAllOthersAndSelf(self, "\x05" + "\x17", []) self.isSnowing=False self.snowStormStartTimer = threading.Timer(random.randrange(900, 1500), self.startSnowStorm) self.snowStormStartTimer.start() def informAll(self, clientFunction, args): for playerCode, client in self.clients.iteritems(): lol = "%r"%(clientFunction) if "TransformiceClientHandler.sendPlayMusic" in lol: if client.musicOff: pass else: clientFunction(client, *args) else: clientFunction(client, *args) def informAllOthers(self, senderClient, clientFunction, args): for playerCode, client in self.clients.iteritems(): if playerCode != senderClient.playerCode: clientFunction(client, *args) def sendAll(self, eventTokens, data = None): for playerCode, client in self.clients.iteritems(): client.sendData(eventTokens, data) def sendAllOthers(self, senderClient, eventTokens, data): for playerCode, client in self.clients.iteritems(): if client.playerCode != senderClient.playerCode: client.sendData(eventTokens, data) def sendAllOthersAndSelf(self, senderClient, eventTokens, data): for playerCode, client in self.clients.iteritems(): client.sendData(eventTokens, data) def sendWholeServer(self, senderClient, eventTokens,