def game_play_card(self, game_id, card): """ Play one card in given game, by given player. """ game = self._get_game(game_id) player = self.authenticated_player game.play_card(player, rpc.rpc_decode(Card, card)) return True
def player_register(self, player): """ Register a new player to the server. Return the player id. """ player = rpc.rpc_decode(RPCProxyPlayer, player) return self._register_player(player)
def rpc_decode(cls, rpcobj): """ Decode an rpc object into an Event instance. """ instance = None for subcls in cls.__subclasses__(): if getattr(subcls, 'type') == rpcobj['type']: return rpc.rpc_decode(subcls, rpcobj) return cls.rpc_decode_simple(rpcobj)
def rpc_decode(cls, rpcobj): elist = cls() for event in rpcobj: elist.append(rpc.rpc_decode(Event, event)) return elist
def get_state(self, player_id): state = self.server.game.get_state(self.akey, self.game_id) state['game_state'] = rpc.rpc_decode(GameState, state['game_state']) state['hand'] = rpc.rpc_decode(CardSet, state['hand']) return state
def get_events(self, player_id): return rpc.rpc_decode(EventList, self.server.get_events(self.akey))
def rpc_decode(cls, rpcobj): cset = cls() for card in rpcobj: cset.append(rpc.rpc_decode(Card, card)) return cset
def rpc_decode(cls, rpcobj): card = Card(rpc.rpc_decode(Suit, rpcobj["suit"]), rpcobj["value"]) if rpcobj.has_key("played_by"): card.played_by = rpcobj["played_by"] return card