def shutdown_loser(self): loser = Player.fetch(uid=self.loser_uid) url = loser.endpoint + "/shutdown" try: notify(url) except Exception: pass
def create_player(request): log.debug("hello there") player_data = request.params log.debug("player_data = {}".format(player_data)) player = Player.fetch(name=player_data['name']) if not player: player = Player(data=player_data) player.save() else: log.debug("Player {} already registered".format(player.name)) ch = Championship.fetch() rt_dict = player.to_dict() rt_dict['championship_uuid'] = ch.uuid return json.dumps(rt_dict)
def notify_player(self, player_uid, opponent_uid, mode): player = Player.fetch(uid=player_uid) opponent = Player.fetch(uid=opponent_uid) data = { "championship_uuid": self.championship_uuid, "championship_name": self.championship_name, "game_uuid": self.game_uuid, "game_name": self.game_name, "mode": mode, "opponent": opponent.name, "stage": self.stage, "round_no": self.round_no, "defense_strength": player.defense_strength, } url = player.endpoint + "/game_info" notify(url, data=data)
def add_player_to_championship(request): championship_uuid = request.matchdict.get('championship_uuid') championship = Championship.fetch(uuid=championship_uuid) if len(championship.players) >= 8: return json.dumps({'status': 404}) player_name = request.params.get('player_name') player = Player.fetch(name=player_name) log.debug("Champ ID: {}".format(championship.uid)) try: championship.add_player(player) championship.save() except Exception: pass if len(championship.players) == 8: log.info("All players have registered. Starting Championship .. ") ChampionshipGreenlet(championship).start() return json.dumps({'status': 'ok'})
def list_all_players(request): return json.dumps([p.to_dict() for p in Player.list()])