Tips

Projects Client & Server

  • The Client contains all the Unity scripts

  • The Server is our MasterServer.sln which is separated into MasterServer and MasterServerModels

    • MasterServer contains all the server code

    • MasterServerModels are the models and serialization/de-serialization we share between the Client and the Server

Server Address

The asset is made so that it works with Darkrift server when it's run locally. When you switch to remote server you will have to change the IP address accordingly.

To do so, open the MultiplayerServer scene there is game object called Networking which holds a component called Client, change the values accordingly

Requests between Server & Client

The Networking game object holds a NetworkingManager component which we use for all the requests we receive and send.

Receiving requests

We use OnMessageReceived to receive every request from the server. To make things more readable we use Tags enumerator from the MasterServerModels library which is shared between server and client, this way we know what request we are receiving so we can serialize it accordingly.

Sending requests

Sending TCP/UDP requests to the server is as easy as that, just create a new message with the Tags enum so when we receive it in the server side we know what we are working with and attach a data to it, the data is a serializable class that we hold inside the MasterServerModels library which we share between the server and the client. Currently we only need TCP requests that's why every message we send is of type SendMode.Reliable

Serializing & De-serializing requests

It's as simple as creating a single class like shown in the image.

Keep in mind we try to avoid large amount of data because these are TCP requests, so it's better if it's contained into smaller and smarter ways. For example lets check our NError class. Instead of sending the full error message we just have int value which we just send the type of the error, when we receive it in the Client side, we check what type the error is and show the correct dialog/error message or whatever it should be.

Working with enumerators is easy and clean way to reduce packet size

More

For further instructions check the comments in the server code for how things work or if it's easier for u to read there is a locally generated Documentation you can find in the main directory.

If you have any questions don't be scared to contact us on fakeitdev@gmail.com

Last updated