Пример #1
0
    def put(self):
        """Update player position."""
        uid = self.get_argument('uid')
        x = self.get_argument('x')
        y = self.get_argument('y')
        now = get_datetimenow_with_server_timezone()

        # Update player with new coordinates
        with rdb_connection() as conn:
            rdb.table('players').get(uid).update(
                {'y': y, 'x': x, 'touched': now}
            ).run(conn)
Пример #2
0
    def post(self):
        """Log new player to receive uid."""
        name = self.get_argument('name')
        now = get_datetimenow_with_server_timezone()

        with rdb_connection() as conn:
            output = rdb.table('players').insert(
                {'name': name, 'y': 3, 'x': 3, 'touched': now}
            ).run(conn)

        if output.get('generated_keys'):
            uid = output['generated_keys'][0]

        self.write({'uid': uid})
Пример #3
0
    def get(self):
        """Get list of currently active players on the map.

        Before selecting active players, we make sure to delete guys that
        were inactive for more then 30 seconds.

        """
        now = get_datetimenow_with_server_timezone()

        with rdb_connection() as conn:
            # Removing old players
            rdb.table('players').filter(
                lambda player: player['touched'] < (now - timedelta(seconds=30))
            ).delete().run(conn)
            # Selecting active players
            players = rdb.table('players').without('touched').run(conn)

        self.write({'players': list(players)})