def collectVoiceData(self, requests): """collect voices of other players""" if not self.running: return block = DeferredBlock(self) voiceDataRequests = [] for request in requests: if request.answer == Message.ClientWantsVoiceData: # another human player requests sounds for voiceId voiceId = request.args[0] voiceFor = [ x for x in self.game.players if isinstance(self.remotes[x], User) and self.remotes[x].voiceId == voiceId ][0] voiceFor.voice = Voice(voiceId) if Debug.sound: logDebug('client %s wants voice data %s for %s' % (request.user.name, request.args[0], voiceFor)) voiceDataRequests.append((request.user, voiceFor)) if not voiceFor.voice.oggFiles(): # the server does not have it, ask the client with that # voice block.tell(voiceFor, voiceFor, Message.ServerWantsVoiceData) block.callback(self.sendVoiceData, voiceDataRequests)
def sendVoiceIds(self): """tell each player what voice ids the others have. By now the client has a Game instance!""" humanPlayers = [ x for x in self.game.players if isinstance(self.remotes[x], User) ] if len(humanPlayers) < 2 or not any(self.remotes[x].voiceId for x in humanPlayers): # no need to pass around voice data self.assignVoices() return block = DeferredBlock(self) for player in humanPlayers: remote = self.remotes[player] if remote.voiceId: # send it to other human players: others = [x for x in humanPlayers if x != player] if Debug.sound: logDebug( 'telling other human players that %s has voiceId %s' % (player.name, remote.voiceId)) block.tell(player, others, Message.VoiceId, source=remote.voiceId) block.callback(self.collectVoiceData)
def assignVoices(self, dummyResults=None): """now all human players have all voice data needed""" humanPlayers = [ x for x in self.game.players if isinstance(self.remotes[x], User) ] block = DeferredBlock(self) block.tell(None, humanPlayers, Message.AssignVoices) block.callback(self.startHand)
def divided(self, dummyResults=None): """the wall is now divided for all clients""" if not self.running: return block = DeferredBlock(self) for clientPlayer in self.game.players: for player in self.game.players: if player == clientPlayer or self.game.playOpen: tiles = player.concealedTiles else: tiles = TileList(Tile.unknown * 13) block.tell(player, clientPlayer, Message.SetConcealedTiles, tiles=TileList(chain(tiles, player.bonusTiles))) block.callback(self.dealt)
def sendVoiceData(self, requests, voiceDataRequests): """sends voice sounds to other human players""" self.processAnswers(requests) block = DeferredBlock(self) for voiceDataRequester, voiceFor in voiceDataRequests: # this player requested sounds for voiceFor voice = voiceFor.voice content = voice.archiveContent if content: if Debug.sound: logDebug('server got voice data %s for %s from client' % (voiceFor.voice, voiceFor.name)) block.tell(voiceFor, voiceDataRequester, Message.VoiceData, md5sum=voice.md5sum, source=content) elif Debug.sound: logDebug('server got empty voice data %s for %s from client' % ( voice, voiceFor.name)) block.callback(self.assignVoices)
def sendVoiceIds(self): """tell each player what voice ids the others have. By now the client has a Game instance!""" humanPlayers = [x for x in self.game.players if isinstance(x.remote, User)] if len(humanPlayers) < 2 or not any(x.remote.voiceId for x in humanPlayers): # no need to pass around voice data self.assignVoices() return block = DeferredBlock(self) for player in humanPlayers: if player.remote.voiceId: # send it to other human players: others = [x for x in humanPlayers if x != player] if Debug.sound: logDebug('telling other human players that %s has voiceId %s' % ( player.name, player.remote.voiceId)) block.tell(player, others, Message.VoiceId, source=player.remote.voiceId) block.callback(self.collectVoiceData)
def leaveTable(self, user, tableid, message=None, *args): """user leaves table. If no human user is left on a new table, remove it""" if tableid in self.tables: table = self.tables[tableid] if user in table.users: if len(table.users) == 1 and not table.suspendedAt: # silent: do not tell the user who left the table that he # did self.removeTable(table, 'silent', message, *args) else: table.delUser(user) if self.srvUsers: block = DeferredBlock(table) block.tell(None, self.srvUsers, Message.TableChanged, source=table.asSimpleList()) block.callback(False) return True
def collectVoiceData(self, requests): """collect voices of other players""" if not self.game: return block = DeferredBlock(self) voiceDataRequests = [] for request in requests: if request.answer == Message.ClientWantsVoiceData: # another human player requests sounds for voiceId voiceId = request.args[0] voiceFor = [x for x in self.game.players if isinstance(x.remote, User) \ and x.remote.voiceId == voiceId][0] voiceFor.voice = Voice(voiceId) if Debug.sound: logDebug('client %s wants voice data %s for %s' % (request.player.name, request.args[0], voiceFor)) voiceDataRequests.append((request.player, voiceFor)) if not voiceFor.voice.oggFiles(): # the server does not have it, ask the client with that voice block.tell(voiceFor, voiceFor, Message.ServerWantsVoiceData) block.callback(self.sendVoiceData, voiceDataRequests)
def sendVoiceData(self, requests, voiceDataRequests): """sends voice sounds to other human players""" self.processAnswers(requests) block = DeferredBlock(self) for voiceDataRequester, voiceFor in voiceDataRequests: # this player requested sounds for voiceFor voice = voiceFor.voice content = voice.archiveContent if content: if Debug.sound: logDebug('server got voice data %s for %s from client' % (voiceFor.voice, voiceFor.name)) block.tell(voiceFor, voiceDataRequester, Message.VoiceData, md5sum=voice.md5sum, source=content) elif Debug.sound: logDebug('server got empty voice data %s for %s from client' % (voice, voiceFor.name)) block.callback(self.assignVoices)
def joinTable(self, user, tableid): """user joins table""" table = self._lookupTable(tableid) table.addUser(user) block = DeferredBlock(table) block.tell(None, self.srvUsers, Message.TableChanged, source=table.asSimpleList()) if len(table.users) == table.maxSeats(): if Debug.table: logDebug('Table %s: All seats taken, starting' % table) def startTable(dummy): """now all players know about our join""" table.readyForGameStart(table.owner) block.callback(startTable) else: block.callback(False) return True
def assignVoices(self, dummyResults=None): """now all human players have all voice data needed""" humanPlayers = [x for x in self.game.players if isinstance(x.remote, User)] block = DeferredBlock(self) block.tell(None, humanPlayers, Message.AssignVoices) block.callback(self.startHand)