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

0

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

REMOVEDUPLOAD The PlayerSessionID is the same used when calling AcceptPlayerSession.

#GameLift

asked 3 years ago1281 views
21 Answers
0

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

answered 3 years ago
0

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.

answered 3 years ago
0

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?

answered 3 years ago
0

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.

answered 3 years ago
0

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

answered 3 years ago
0

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.

answered 3 years ago
0

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.

answered 3 years ago
0

Thank you will check it out.

answered 3 years ago
0

Hi @REDACTEDUSER

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: https://docs.aws.amazon.com/gamelift/latest/apireference/API_PlayerSession.html#gamelift-Type-PlayerSession-Status)

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: https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-sdk-server-api-interaction-vsd.html

answered 3 years ago
0

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?

answered 3 years ago
0

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

REMOVEDUPLOAD

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.

answered 3 years ago
0

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 @REDACTEDUSER

answered 3 years ago
0

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 https://docs.aws.amazon.com/cli/latest/reference/logs/get-log-events.html

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:******

answered 3 years ago
0

When I try to download the log with this command:

aws gamelift get-game-session-log --game-session-id arn:******

I get this error:

An error occurred (NotFoundException) when calling the GetGameSessionLogUrl operation: No log found for game session arn:******

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.

answered 3 years ago
0

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: https://forums.awsgametech.com/t/how-to-open-a-aws-gamelift-log/11161/2

answered 3 years ago
0

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.

answered 3 years ago
0

Hi @REDACTEDUSER

  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
answered 3 years ago
0

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.

answered 3 years ago
0

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:******

answered 3 years ago
0

Thank you for the suggestion, but for some reason player sessions are now activated and completed on logout!

I am not exactly sure what change was responsible but if someone wants a particular screenshot of my Unreal blueprint setup let me know.

Thank you James and Chris for your outstanding support!

Next I need to figure out how to shutdown GameSessions :)

answered 3 years ago
0

Nice, glad it worked.

When a game session is completed, you should call GameLiftServerSDK::ProcessEnding and promptly exit the process.

In Unity, this is Application.Quit(), but I'm not sure what the equivalence is in UE. This might be helpful: https://forums.awsgametech.com/t/server-process-force-terminated-event-when-manually-scaling-down-fleet-******

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions