def perspective_setClientProperties( self, dbIdent, voiceId, maxGameId, clientVersion=None): """perspective_* methods are to be called remotely""" self.dbIdent = dbIdent self.voiceId = voiceId self.maxGameId = maxGameId clientVersion = nativeString(clientVersion) serverVersion = Internal.defaultPort if clientVersion != serverVersion: # we assume that versions x.y.* are compatible if clientVersion is None: # client passed no version info return fail(srvError(pb.Error, m18nE( 'Your client has a version older than 4.9.0 but you need %1 for this server'), serverVersion)) else: commonDigits = len([x for x in zip( clientVersion.split(b'.'), serverVersion.split(b'.')) if x[0] == x[1]]) if commonDigits < 2: return fail(srvError(pb.Error, m18nE( 'Your client has version %1 but you need %2 for this server'), clientVersion or '<4.9.0', '.'.join(serverVersion.split('.')[:2]) + '.*')) if Debug.table: logDebug(u'client has dbIdent={} voiceId={} maxGameId={} clientVersion {}'.format( self.dbIdent, self.voiceId, self.maxGameId, clientVersion)) self.server.sendTables(self)
def chat(self): """chat. Only generate ChatWindow after the message has successfully been sent to the server. Because the server might have gone away.""" def initChat(_): """now that we were able to send the message to the server instantiate the chat window""" table.chatWindow = ChatWindow(table=table) table.chatWindow.receiveLine(msg) table = self.selectedTable() if not table.chatWindow: line = m18nE('opens a chat window') msg = ChatMessage( table.tableid, table.client.name, line, isStatusMessage=True) table.client.sendChat( msg).addCallback( initChat).addErrback( self.client.tableError) elif table.chatWindow.isVisible(): table.chatWindow.hide() else: table.chatWindow.show()
def __failed(self, result, request): """a user did not or not correctly answer""" if request in self.requests: self.removeRequest(request) if result.type in [pb.PBConnectionLost]: msg = m18nE('The game server lost connection to player %1') self.table.abort(msg, request.user.name) else: msg = m18nE('Error for player %1: %2\n%3') try: traceBack = result.getTraceback() except BaseException: # may happen with twisted 12.3.0 traceBack = u'twisted cannot give us a traceback' self.table.abort( msg, request.user.name, result.getErrorMessage(), traceBack)
def showConcealedMelds(self, concealedMelds, ignoreDiscard=None): """the server tells how the winner shows and melds his concealed tiles. In case of error, return message and arguments""" for meld in concealedMelds: for tile in meld: if tile == ignoreDiscard: ignoreDiscard = None else: if tile not in self._concealedTiles: msg = m18nE( '%1 claiming MahJongg: She does not really have tile %2') return msg, self.name, tile self._concealedTiles.remove(tile) if meld.isConcealed and not meld.isKong: self._concealedMelds.append(meld) else: self._exposedMelds.append(meld) if self._concealedTiles: msg = m18nE( '%1 claiming MahJongg: She did not pass all concealed tiles to the server') return msg, self.name self._hand = None
def tell(self, about, receivers, command, **kwargs): """send info about player 'about' to users 'receivers'""" def encodeKwargs(): """those values are classes like Meld, Tile etc. Convert to str(python2) or bytes(python3""" for keyword in ('tile', 'tiles', 'meld', 'melds'): if keyword in kwargs: kwargs[keyword] = str(kwargs[keyword]).encode() encodeKwargs() if about.__class__.__name__ == 'User': about = self.playerForUser(about) if not isinstance(receivers, list): receivers = list([receivers]) assert receivers, 'DeferredBlock.tell(%s) has no receiver' % command self.__enrichMessage(self.table.game, about, command, kwargs) aboutName = about.name if about else None if self.table.running and len(receivers) in [1, 4]: # messages are either identical for all 4 players # or identical for 3 players and different for 1 player. And # we want to capture each message exactly once. self.table.game.appendMove(about, command, kwargs) localDeferreds = [] for rec in self.__convertReceivers(receivers): isClient = rec.__class__.__name__.endswith('Client') if Debug.traffic and not isClient: message = u'-> {receiver:<15} about {about} {command}{kwargs}'.format( receiver=rec.name[:15], about=about, command=command, kwargs=Move.prettyKwargs(kwargs)) logDebug(message) if isClient: defer = Deferred() defer.addCallback(rec.remote_move, command, **kwargs) else: defer = self.table.server.callRemote( rec, 'move', aboutName, command.name, **kwargs) if defer: defer.command = command.name defer.notifying = 'notifying' in kwargs self.__addRequest(defer, rec, about) else: msg = m18nE('The game server lost connection to player %1') self.table.abort(msg, rec.name) if isClient: localDeferreds.append(defer) for defer in localDeferreds: defer.callback(aboutName) # callback needs an argument !
def __init__(self, name=None): ClassicalChinese.__init__( self, name or m18nE('Classical Chinese BMJA'))
def __init__(self, name=None): PredefinedRuleset.__init__( self, name or m18nE('Classical Chinese standard'))