예제 #1
0
파일: game.py 프로젝트: ospalh/kajongg-fork
 def assignVoices(self):
     """now we have all remote user voices"""
     assert self.belongsToHumanPlayer()
     available = Voice.availableVoices()[:]
     # available is without transferred human voices
     for player in self.players:
         if player.voice and player.voice.oggFiles():
             # remote human player sent her voice, or we are human and have a voice
             if Debug.sound and player != self.myself:
                 logDebug('%s got voice from opponent: %s' % (player.name, player.voice))
         else:
             player.voice = Voice.locate(player.name)
             if player.voice:
                 if Debug.sound:
                     logDebug('%s has own local voice %s' % (player.name, player.voice))
         if player.voice:
             for voice in Voice.availableVoices():
                 if voice in available and voice.md5sum == player.voice.md5sum:
                     # if the local voice is also predefined,
                     # make sure we do not use both
                     available.remove(voice)
     # for the other players use predefined voices in preferred language. Only if
     # we do not have enough predefined voices, look again in locally defined voices
     predefined = [x for x in available if x.language() != 'local']
     predefined.extend(available)
     for player in self.players:
         if player.voice is None and predefined:
             player.voice = predefined.pop(0)
             if Debug.sound:
                 logDebug('%s gets one of the still available voices %s' % (player.name, player.voice))
예제 #2
0
 def __init__(self,
              names,
              ruleset,
              gameid=None,
              wantedGame=None,
              client=None,
              playOpen=False,
              autoPlay=False):
     """a new game instance, comes from database if gameid is set"""
     self.__activePlayer = None
     self.prevActivePlayer = None
     self.defaultNameBrush = None
     Game.__init__(self,
                   names,
                   ruleset,
                   gameid,
                   wantedGame=wantedGame,
                   client=client)
     self.playOpen = playOpen
     self.autoPlay = autoPlay
     myself = self.myself
     if self.belongsToHumanPlayer() and myself:
         myself.voice = Voice.locate(myself.name)
         if myself.voice:
             if Debug.sound:
                 logDebug('myself %s gets voice %s' %
                          (myself.name, myself.voice))
         else:
             if Debug.sound:
                 logDebug('myself %s gets no voice' % (myself.name))
예제 #3
0
 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)
예제 #4
0
 def clientAction(self, dummyClient, move):
     """server sent us voice sounds about somebody else"""
     move.player.voice = Voice(move.md5sum, move.source)
     if Debug.sound:
         logDebug(
             '%s gets voice data %s from server, language=%s' %
             (move.player, move.player.voice, move.player.voice.language()))
예제 #5
0
 def assignVoices(self):
     """now we have all remote user voices"""
     assert self.belongsToHumanPlayer()
     available = Voice.availableVoices()[:]
     # available is without transferred human voices
     for player in self.players:
         if player.voice and player.voice.oggFiles():
             # remote human player sent her voice, or we are human
             # and have a voice
             if Debug.sound and player != self.myself:
                 logDebug('%s got voice from opponent: %s' %
                          (player.name, player.voice))
         else:
             player.voice = Voice.locate(player.name)
             if player.voice:
                 if Debug.sound:
                     logDebug('%s has own local voice %s' %
                              (player.name, player.voice))
         if player.voice:
             for voice in Voice.availableVoices():
                 if (voice in available
                         and voice.md5sum == player.voice.md5sum):
                     # if the local voice is also predefined,
                     # make sure we do not use both
                     available.remove(voice)
     # for the other players use predefined voices in preferred language.
     # Only if we do not have enough predefined voices, look again in
     # locally defined voices
     predefined = [x for x in available if x.language() != 'local']
     predefined.extend(available)
     for player in self.players:
         if player.voice is None and predefined:
             player.voice = predefined.pop(0)
             if Debug.sound:
                 logDebug('%s gets one of the still available voices %s' %
                          (player.name, player.voice))
예제 #6
0
 def __loggedIn(self, connection):
     """callback after the server answered our login request"""
     self.connection = connection
     self.ruleset = connection.ruleset
     self.name = connection.username
     self.tableList.show()
     voiceId = None
     if Preferences.uploadVoice:
         voice = Voice.locate(self.name)
         if voice:
             voiceId = voice.md5sum
         if Debug.sound and voiceId:
             logDebug('%s sends own voice %s to server' % (self.name, voiceId))
     maxGameId = Query('select max(id) from game').records[0][0]
     maxGameId = int(maxGameId) if maxGameId else 0
     self.callServer('setClientProperties',
         Internal.dbIdent,
         voiceId, maxGameId, Internal.version).addCallbacks(self.__initTableList, self.__versionError)
예제 #7
0
파일: game.py 프로젝트: ospalh/kajongg-fork
 def __init__(self, names, ruleset, gameid=None, wantedGame=None, shouldSave=True, \
         client=None, playOpen=False, autoPlay=False):
     """a new game instance, comes from database if gameid is set"""
     self.__activePlayer = None
     self.prevActivePlayer = None
     self.defaultNameBrush = None
     PlayingGame.__init__(self, names, ruleset, gameid,
         wantedGame=wantedGame, shouldSave=shouldSave, client=client)
     self.playOpen = playOpen
     self.autoPlay = autoPlay
     myself = self.myself
     if self.belongsToHumanPlayer() and myself:
         myself.voice = Voice.locate(myself.name)
         if myself.voice:
             if Debug.sound:
                 logDebug('RemoteGame: myself %s gets voice %s' % (myself.name, myself.voice))
         else:
             if Debug.sound:
                 logDebug('myself %s gets no voice'% (myself.name))
예제 #8
0
파일: humanclient.py 프로젝트: KDE/kajongg
 def __loggedIn(self, connection):
     """callback after the server answered our login request"""
     self.connection = connection
     self.ruleset = connection.ruleset
     self.name = connection.username
     self.tableList.show()
     voiceId = None
     if Internal.Preferences.uploadVoice:
         voice = Voice.locate(self.name)
         if voice:
             voiceId = voice.md5sum
         if Debug.sound and voiceId:
             logDebug(
                 u'%s sends own voice %s to server' %
                 (self.name, voiceId))
     maxGameId = Query('select max(id) from game').records[0][0]
     maxGameId = int(maxGameId) if maxGameId else 0
     self.callServer('setClientProperties',
                     Internal.db.identifier,
                     voiceId, maxGameId,
                     Internal.defaultPort).addCallbacks(self.__initTableList, self.__versionError)
예제 #9
0
 def clientAction(self, dummyClient, move):
     """the server gave us a voice id about another player"""
     if Internal.Preferences.useSounds and Options.gui:
         move.player.voice = Voice.locate(move.source)
         if not move.player.voice:
             return Message.ClientWantsVoiceData, move.source
예제 #10
0
파일: message.py 프로젝트: KDE/kajongg
 def clientAction(self, dummyClient, move):
     """the server gave us a voice id about another player"""
     if Internal.Preferences.useSounds and Options.gui:
         move.player.voice = Voice.locate(move.source)
         if not move.player.voice:
             return Message.ClientWantsVoiceData, move.source
예제 #11
0
 def clientAction(self, dummyClient, move):
     """the server gave us a voice id about another player"""
     if Sound.enabled:
         move.player.voice = Voice.locate(move.source)
         if not move.player.voice:
             return Message.ClientWantsVoiceData, move.source