How to create a client authoritive player for a multiplayer game

0

Hello guys,

i want to create a basic multiplayer game using gamelift, but i have some troubles creating something like a "player" which anyone connected to a gamelift session can control.

I'm not sure how i can achieve this. First i thought i can just add a "Netbinding-Component" to my player prefab, but this doesnt work.

Then i reversed engineered a bit the multiplayer sample and now i know how they implemented the player using client-authoritive data and rpc calls.

But implementing something like this would take me a huge amount of time. Isn't there an easier way to create something like an "player" which gets replicated across the network for each connection?

Do i really have to write my own C++ Server?

Beside that i have some questions regarding the multiplayer-sample:

1.) I couldn't figure it out how the game-server terminates game-sessions. When i tried this, you can create a session using the lobby but is there really no way to delete a session?

2.) Created player-sessions get not disconnected aswell, that means with every new Connection from a Client to a game-session the amount of active player-sessions increased by one, but never decreased even when i terminated the client program.

Thanks in advance :)

asked 7 years ago351 views
5 Answers
0
Accepted Answer

Hi @REDACTEDUSER

You are on the right path! Adding a netbinding component is needed to "bind" an entity to the network so its data gets replicated. I posted a simple example of a networked player controller a little while ago: https://forums.awsgametech.com/t/networked-player-controller-example/2277/1

The sample has lua code that needs to be updated to work with 1.9, but if this is something that you think would be useful for your game I'd be happy to update it for you.

It is client-authoritative and each player that joins the server has their own character they control.

Regarding your questions

0.) Do you have to write your own C++ Server?

Lumberyard comes with a dedicated server out of the box, so you don't need to write any C++ code if you just want to use Lua. That said, most multiplayer games do add/modify the C++ code for their dedicated server to optimize performance and to facilitate better security. If you are making a simple game where those are not issues (for example a prototype) then you don't need to write any C++ server code.

1.) I couldn't figure it out how the game-server terminates game-sessions. When i tried this, you can create a session using the lobby but is there really no way to delete a session?

There are C++ commands to terminate GameLift game sessions from the server, however in the multiplayer sample the dedicated server waits to receive a terminate message from GameLift before shutting down. So this means the client initiates the session creation, but GameLift handles the session termination in the sample. If you want your server to terminate the GameLift session you could call AWS::GameLift::Server::TerminateGameSession() (http://docs.aws.amazon.com/gamelift/latest/developerguide/integration-server-sdk-cpp-ref-actions.html#integration-server-sdk-cpp-ref-terminategamesession)

2.) Created player-sessions get not disconnected aswell, that means with every new Connection from a Client to a game-session the amount of active player-sessions increased by one, but never decreased even when i terminated the client program.

This sounds like the players are disconnecting incorrectly and the server has disconnect detection turned off? When a player disconnects the server is supposed to call Aws::GameLift::Server::RemovePlayerSession (line 247 of GameLiftServerSession.cpp in OnReplicaDeactivate).

answered 7 years ago
0

Hey @REDACTEDUSER

answered 7 years ago
0

thanks :) i just need an easy way to instantiate a player for each connection to the gameserver

answered 7 years ago
0

Thanks, i'll try your character controller in the weekend.

One last question regarding "0.) Do you have to write your own C++ Server?"

Yea i know that lumberyard comes with a dedicated server out of the box and do the replication stuff etc. automatically, but say i am doing a prototype for my game, how does the server knows how to behave for this specific game? E.g. for a racing game the server has to manage obviously some sort of Leaderboard or handle when the race has been finished and transition all players to a new race. Is the only way to do this using C++?

Edit:

What i try to achieve is to spawn the controllable chicken from the samples project for each player, so each player can walk around. I tried this by just adding the netbinding-component to it, but the result of this is weird. The Chicken itself gets replicated from each client, but a cient is not able to move it (the server itself is able to move around but this chicken gets not replicated). Can you explain me why?

answered 7 years ago
0

Hi @REDACTEDUSER

If you want players to be able to control a character, either the client needs to spawn the character in which case the client owns it - or the server needs to spawn the character and only allow one client to control it. The first method is client-authoritative and is what the sample I posted does. Take a look at that setup to make sure you aren't spawning a slice that has a controller on it. You just want to spawn a single player controller for each client and spawn the pawn dynamically. It sounds like maybe you are dynamically spawning multiple player controllers.

For the server-side logic you can start out with an entity that has a Lua script that only runs on the server. I typically expose the gEnv->pNetwork->IsDedicated() and gEnv->pNetwork->IsClient() to Lua so I can prototype quickly. However, this is not secure for a real game. The best way to secure your server logic is to only include that code on the dedicated server. You can implement that logic in Lua and load it (the compiled lua) on the server if you want, or just write it in C++.

answered 7 years ago

This post is closed: Adding new answers, comments, and votes is disabled.