[Unreal] How to remove a PlayerSession when Player leaves a GameSession?

For some reason when players leave a GameSession they are not removed when I call the function RemovePlayerSession run on Server reliable. Why?


The PlayerSessionID is the same used when calling AcceptPlayerSession.

#GameLift

Just to clarify your question, are you currently calling RemovePlayerSession in a server rpc initiated by the client? Sorry if I’m misunderstanding.

I don’t know if this is a RPC (Remote Procedure Call), as you can see above I call a function run on the Server. I also tried to run this function on the GameMode or GameInstance.

It does seem like it’s a remote procedure call as I took a closer look just now. My next question would be then, when the client has this WB_InGameMenu widget displayed on its screen, is the client connected to the server on GameLift yet?

1 Like

Yes, his PlayerSession is confirmed in the backend - and it appears as if he is connected, until he logs out, while the Server keeps maintaining the PlayerSession.

Next question would be, do you get an error message? Or the “Player Session Removed” message?

I have added a print node and this is what it says
LogBlueprintUserMessages: [WB_InGameMenu_C_0] Player Session Removed Error:
No error message, since it is probably not copied to the client, nevertheless an error.

So the Node is accessed but the server calls error, perhaps because the player already left?

I try to call a previous node which removes the PlayerPawn after the RemoveSession - will report back, perhaps in about 12 hrs.

I would suggest remote connecting into the instance hosting your server and checking the logs there if possible. Here’s a link with more info on that if you need it.

1 Like

Thank you will check it out.

Hi @Lektrolical

For some reason when players leave a GameSession they are not removed when I call the function RemovePlayerSession run on Server reliable. Why?

Could you please help me understand what is not working? I.e. did you call DescribePlayerSessions with the playerId (or visited the console) and saw that the player Id status is not “COMPLETED”? (See doc on all the possible player status: PlayerSession - GameLift Service)

The canonical flow is:

  1. Player disconnects from the server process, triggering an event. This depends on how your server is implemented, e.g. if you are using Websocket servers, there will be an onClose event.
  2. In the event handling, you should call RemovePlayerSession, e.g. this is a simplified version of how a websocket server would implement it. (I free typed this so there might be syntactical errors)
    // This event gets called when player first initiates a websocket connection with the websocket server
    websocketServer.on('connect', (websocketConnection, request) => {
       logger.info(`Player connected from IP: ${request.connection.remoteAddress}!`);
    
       // Stores the player session id for this websocket connection
       val playerSessionId;
    
       websocketConnection.on('message', async (message) => {
            if (message.type === 'login') {
               // Client connections are expected to pass in the playerSessionId when they first connect, see:
               // https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-sdk-server-api.html#gamelift-sdk-server-validateplayer
               playerSessionId = message.attributes.playerSessionId;
    
               // This sets your player session from RESERVED to ACTIVE
               let outcome = await GameLiftServerSDK.AcceptPlayerSession(playerSessionId);
               if (!outcome.Success) {
                   // Log error
               } else {
                   // Log success
                   // You can now call GameLiftServerSDK.DescribePlayerSessions(...) if needed to retrieve the player data
               }
            }
            // Handle other message types, like player movements, chat, etc.
       });
    
       // This gets called when the websocket connection is terminated, e.g. player disconnects, game client crashes, network timeout, etc.
       websocketConnection.on('close', async () => {
          // This sets your player session from ACTIVE to COMPLETE
          let outcome = await GameLiftServerSDK.RemovePlayerSession(playerSessionId);
          if (!outcome.Success) {
             // Log error
          } else {
             // Log success
          }
       });
    });
    
  3. You should be able to call DescribePlayerSessions, either from the GameLiftServerSDK or the AWS SDK/CLI and see that the player session is now in COMPLETE status

See doc on the flow: Amazon GameLift–Game Server/Client Interactions - Amazon GameLift

Is it possible to download the AWS CLI Fleet Log after I have terminated a fleet?
Can you tell me the command to download a fleet log?

I am using an Unreal Plugin which uses the AWS SDK, why should I call DescribePlayerSessions when knowing the PlayerSessionID?

Here are the server commands

server-aws

After the player has logged into the server I see in the backend that the PlayerSession is set to Accepted, this remains after the player has left the GameSession.

I don’t believe you can look at the server logs once the fleet is terminated since you will no longer be able to remotely connect into the fleet’s instances anymore. I would suggest spinning up another fleet with one instance with one server process running, remote connect to the instance, then recreate the situation with the client, and finally look at the server logs while being remote connected in a separate rdp/ssh window.

As for why you would call DescribePlayerSessions through the aws cli like @JamesM_Aws suggested, you can use that call after recreating the situation to see the state of a player session immediately after a client leaves the server but while the game session is still active. This is another, and probably a better way to determine whether or not the player session was indeed terminated. Here’s a reference to that in case you need it.

1 Like

Do you perhaps know the command for downloading the log? I look at this page but have no idea what a log group name is get-log-events — AWS CLI 1.20.29 Command Reference

I just want the command to get the GameSession log from a Fleet.

Okay found it.

aws gamelift get-game-session-log --game-session-id arn:aws:gamelift:xx-xxxxxx-1::gamesession/fleet-xxxxx/gsess-xxxx --save-as gamelift_log.txt

When I try to download the log with this command:

aws gamelift get-game-session-log --game-session-id arn:aws:gamelift:eu-central-1::gamesession/fleet-95a27d37-2f31-4bcf-877d-74f0aa2ea5d8/gsess-ab96ff98-ac23-40c6-9db8-6b2f01effa28 --save-as gamelift_log.txt

I get this error:

An error occurred (NotFoundException) when calling the GetGameSessionLogUrl operation: No log found for game session arn:aws:gamelift:xx-central-1::gamesession/fleet-xxxx-xxx-4bcf-877d-74f0aa2ea5d8/gsess-ab96ff98-ac23-40c6-9db8-6b2f01effa28 in fleet fleet-95a27d37-2f31-4bcf-877d-74f0aa2ea5d8

I can see the Fleet and active GameSession in the backend, and an active PlayerSession.
The game log does not show an error for the DescribeGameSessions node, but again throws an error on RemovePlayerSession.

Okay so I was able to download a log after terminating the Fleet. However, the log is not in *:txt format,I don’t know how to open it.

Next: Going to upload a Server build in debug mode.

but again throws an error on RemovePlayerSession.

Could you post the error message here? Akshay hopefully helped you understood why the file is not opening in this post: How to open a AWS GameLift Log? - #2 by _Akshay

Hi, this is the error

Game Server Logs
Error: Missing file/directory C:\game\xxxxxx\Binaries\Win64\logfile.txt

The GameSession is still ongoing, because when a player leaves, the PlayerSession remains active. If I shutdown the fleet, the error is the same.

Hi @Lektrolical

  1. Could you confirm "Missing file/directory..." was the error message you saw after calling RemovePlayerSession? I’m asking this because I don’t recall RemovePlayerSession invoke logging logics, so it’s possible that the error message came from a separate thread.
  2. Did you by any chance store the output of RemovePlayerSession? Does the Success attribute equal false?
  3. Do you recognize C:\game\xxxxxx\Binaries\Win64\logfile.txt as something you specified? E.g. in logPaths attribute that you passed to ProcessReady? If so, could you change the path to something valid and if you are unblocked? Alternatively, you may also pass an empty array for logPaths in ProcessReady, or add a dummy text file in C:\game\xxxxxx\Binaries\Win64\logfile.txt

There is no error message from the RemovePlayerSession node.

I do not recognize that I have specified this path.
I have already shipped a logfile.zip/txt - the error remains the same.

Could you send me a sample GameSessionId where RemoveGameSession was called but player session remained ACTIVE? I can have the GameLift team take a look in the backend.

GameSessionId can be retrieved by DescribeGameSession or CreateGameSession, and looks something like this: arn:aws:gamelift:<region>::gamesession/<fleet_id>/<game_session_name>

1 Like