Skip to main content

Server authoritative gameplay guide

As mentioned in the requirements, Server authoritative approach is mandatory for games using Elympics SDK. The main concept is that the games MUST be played on the server, with the client influencing it only by sending inputs.

Please use these resources to learn more about Server Authoritative Principles:

Running in the Editor

In order to make your development easier, Elympics offers Half Remote mode, using the included ParallelSync package. This allows you to open two (or more) different Unity Editor instances and test the Server - Client behaviours.

important

Half Remote only works for the Gameplay scene but that is enough for the first phase of the development, since the lobby (menu) scene can be delayed until it is completed. We heavily recommend starting with gameplay scene Server authoritative approach & input syncing.

Gameplay integration

Input syncing

Player's actions (input) should not affect the game world immediately but go through gathering input phase, sending it to the server and only then applying its effects. Please check out this page for more information

Elympics also supports RPC calls for single time inputs.
Please check out this page for more information

note

It's recommend to run the server Half Remote instance at 640 x 480 resolution as this is the resolution it will run online. It is important to know when mapping and sending the mouse position as an input.

Game logic synchronization

To ensure both Server & Client are always the same, it is important to synchronize the state of gameplay and run its logic in the ElympicsUpdate.

Randomization

The provide randomization, synchronizing the random seed between your Server & Client is crucial for ensuring both scenes are always the same. You can find more information on this page and in the youtube video

Player handling

In your server you will should handle player connections / disconnections. For example for starting game when player client is connected.
Elympics provides an interface to track this easily, please inherit from IServerHandlerGuid (works only for the server instance). There is also a default implementation for it which handles closing the game if any player disconnects.

Finishing a match

Additionally, the server must handle ending the game as it's the only instance that is allowed to submit score to our leaderboards.
To do this you can copy this code snippet:

private void EndGame()
{
// retrieve the final score of your user, this value should be the same in Client & Server
var score = ScoreManager.score;

if (Elympics.IsServer)
{
Elympics.EndGame(new ResultMatchPlayerDatas(new List<ResultMatchPlayerData> { new ResultMatchPlayerData { MatchmakerData = new float[1] { score } } }));
}

// logic to display end game visually here
. . .
}
note

Elympics.EndGame() do not work in Half Remote.

Using it with a deployed server automatically closes it and submits the score to our backend. The scores will NOT be saved to our backend if the server is not deployed.

Testing with the online server

For that, you need to upload the server build.
After that, run the game from the lobby scene or with Debug Online Player mode (using the gameplay scene) instead of Half Remote.

More learning resources

Whole gameplay creation process

You can also learn from a more general video tutorial, participate in the online course, or check out a template project

Useful development tips

If you want more insight into the topic of integrating gameplay with Elympics SDK visit general development tips article .

Continue to Lobby scene

Once you are finished with that, it's time to implement the menu scene.