Exemplo n.º 1
0
    def initial_values(self):
        """ Get the initial Player values for registration

        Returns
        -------
        dict
            Initial values
        """
        return {
            'username': None,
            'password': None,
            'balance': 0,
            'token': None,
            'demo_balance': game_conf['initial_demo_bal'],
            'level_id': None,
            'exp': 0,
            'wagered': 0,
            'won': 0,
            'lost': 0,
            'status': 'alive',
            'chat_messages_count': 0,
            'bets_count': 0,
            'bets_won_count': 0,
            'country_id': Countries.iso2_from_ip(request.remote_addr),
            'registered_date': now(),
            'settings': None,
            'room_id': None,
            'last_checkup': None,
            'is_online': True
        }
Exemplo n.º 2
0
def checkup():
    """
    status 1 -> round in progress, return time left until end
    status 2 -> player is not logged in
    status 3 -> No round running in players room
    """
    rnd = Rounds.current_by_room_id(g.player.room_id)
    if rnd is None:
        return json.dumps({'status': 3})
    left = int(game_conf['rounds_interval']) - secs_passed(rnd.start_date)

    Players.update_by_id({'last_checkup': now()}, g.player.id)
    return json.dumps({'status': 1, 'left': int(left)})
Exemplo n.º 3
0
    def join_some_room(self):
        """ Quit any room first, if inside one.
        Join the room with the most players playing currently
        """
        self.quit_any_room()

        pid = g.player.id
        room_id = Rooms.id_by_max_players()
        self.update_by_id({'room_id': room_id, 'last_checkup': now()}, pid)

        Rooms.add_player(room_id, pid)

        return room_id
Exemplo n.º 4
0
    def _log(self, pid, action, ip=None):
        """ Abstract function to be called by 'log_login' or 'log_logout' below

        Parameters
        ----------
        action : str
            Must be 'logout' or 'login'
        """
        self.insert({
            'player_id': pid,
            'action': action,
            'ip': ip,
            'date': now()
        })
Exemplo n.º 5
0
    def initial_values(self):
        """ Get the initial Round values

        Returns
        -------
        dict
            Initial values
        """
        return {
            'room_id': None,
            'player_id_list': [],
            'outcome': None,
            'start_date': now(),
            'end_date': None
        }
Exemplo n.º 6
0
    def log_entry(self, room_id, pid):
        """ Log in db, that player has joined some room

        Parameters
        ----------
        room_id : int
            Id of the room player has joined
        pid : int
            Id of the player joining the room
        """
        self.insert({
            'room_id': room_id,
            'player_id': pid,
            'entry_date': now(),
            'leave_date': None
        })
Exemplo n.º 7
0
    def log_leave(self, room_id, pid):
        """ Log in db, that player has left the room he joined previously

        Parameters
        ----------
        room_id : int
            Id of the room the player has left
        pid : int
            Id of the player that has left the room
        """
        last_entry_id = self.find(['id'],
                                  'room_id=%(rid)s AND player_id=%(pid)s', {
                                      'rid': room_id,
                                      'pid': pid
                                  },
                                  order_by='entry_date DESC').id

        self.update_by_id({'leave_date': now()}, last_entry_id)
Exemplo n.º 8
0
 def end_round(self, round_id):
     """ Generate random number as outcome and end the round """
     self.update_by_id({
         'outcome': randint(0, 36),
         'end_date': now()
     }, round_id)