BackendServices/functions/requestgamesession.py [47:92]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                    pipe.watch(b'-lock'+game_server_key)

                    # get the current reservation and max players for this game server.
                    # Server will use "current-players" for actually connected players
                    current_reservations = pipe.hget(game_server_key, b'reserved-player-slots')
                    max_players = pipe.hget(game_server_key, b'max-players')
                    print("current reservations: " + str(current_reservations))
                    print("max players: " + str(max_players))

                    if current_reservations == None:
                        current_reservations = 0

                    # Check if this server is full already
                    if int(current_reservations) >= int(max_players):
                        print("Server full, cannot join")
                        continue

                    next_value = int(current_reservations) + 1

                    # now we can put the pipeline back into buffered mode with MULTI and try to update
                    pipe.multi()
                    pipe.hset(game_server_key, b'reserved-player-slots', next_value)
                    pipe.hset(game_server_key, b'last-reservation-time', time.time())
                    # Update lock
                    pipe.set(b'-lock'+game_server_key, "")
                    pipe.expire(b'-lock'+game_server_key, timedelta(seconds=3))
                    # and finally, execute the pipeline (the set command)
                    pipe.execute()

                    # If we reached here, there was no WatchError
                    print("Successfully taken the spot, return IP and port to client")

                    publicIP = redis_client.hget(game_server_key, b'publicIP')
                    port = redis_client.hget(game_server_key, b'port')

                    print("Got server: " + str(publicIP) + ":" + str(port))

                    return {
                        "statusCode": 200,
                        "body": json.dumps({ 'publicIP': publicIP.decode('UTF-8'), 'port': port.decode('UTF-8') })
                    }
                except WatchError:
                    # another client must have changed the game server data in between
                    # the time we started WATCHing it and the pipeline's execution.
                    # We will retry a placement
                    print("Failed to reserve slot, retrying")
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



BackendServices/functions/requestgamesession.py [133:178]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                pipe.watch(b'-lock'+game_server_key)

                # get the current reservation and max players for this game server.
                # Server will use "current-players" for actually connected players
                current_reservations = pipe.hget(game_server_key, b'reserved-player-slots')
                max_players = pipe.hget(game_server_key, b'max-players')
                print("current reservations: " + str(current_reservations))
                print("max players: " + str(max_players))

                if current_reservations == None:
                    current_reservations = 0

                # Check if this was preserved full already
                if int(current_reservations) >= int(max_players):
                    print("Server full, cannot join")
                    continue

                next_value = int(current_reservations) + 1

                # now we can put the pipeline back into buffered mode with MULTI and try to update
                pipe.multi()
                pipe.hset(game_server_key, b'reserved-player-slots', next_value)
                pipe.hset(game_server_key, b'last-reservation-time', time.time())
                # Update lock
                pipe.set(b'-lock'+game_server_key, "")
                pipe.expire(b'-lock'+game_server_key, timedelta(seconds=3))
                # and finally, execute the pipeline (the set command)
                pipe.execute()

                # If we reached here, there was no WatchError
                print("Successfully taken the spot, return IP and port to client")

                publicIP = redis_client.hget(game_server_key, b'publicIP')
                port = redis_client.hget(game_server_key, b'port')

                print("Got server: " + str(publicIP) + ":" + str(port))

                return {
                    "statusCode": 200,
                    "body": json.dumps({ 'publicIP': publicIP.decode('UTF-8'), 'port': port.decode('UTF-8') })
                }
        except WatchError:
            # another client must have changed 'OUR-SEQUENCE-KEY' between
            # the time we started WATCHing it and the pipeline's execution.
            # our best bet is to just retry.
            print("Failed to reserve slot, retrying")
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



