ServerConnection

The core of the plugin is the ServerConnection component. This component handles all aspects of connection and communication with the PlayReal Scalable Server

You can only use the ServerConnection component or you can build your game upon the game architecture proposed in the sample.

Access to the documentation of Scalable Server: http://ssdoc.asmodee.net

_images/ServerConnection_diagramme.JPG

Integration

Create an object in the hierarchy containing the PlayReal Manager script. This is the script that hosts the unique instance of ServerConnection.

We wish that this component is unique throughout the lifetime of the game. It is then necessary to ensure that the object containing the PlayReal Manager script is never destroyed during the scene change

  1. Create the object which we call Manager
_images/Hierarchy_create_manager.png

Renaming the object to Manager

_images/Hierarchy_rename_manager.png
  1. Add PlayReal Manager component to the Manager object
_images/Inspector_add_network_manager.png
  1. Select the setting by clicking the circle to the right of the parameter Network Parameters
_images/Inspector_set_network_parameter.png

In the Assets tab, select the desired parameter

_images/Selector_select_network_parameter.png
  1. Add the component Singleton in the Manager object
_images/Inspector_add_singleton.png

Singleton component visible under the PlayReal Manager :

_images/Inspector_singleton.png

Use

Communication with the Scalable Server is done asynchronously. A request is sent to the server and the component waits for a response. When it receives the response, it raises an event.

Connection and authentication of a user :

  1. Subscribe to the events ConnectedToServerEvent.AsyncConnectedEvent
NetworkManager.Instance.ServerConnection.ConnectedToServerEvent += ServerConnection_ConnectedToServerEvent;
NetworkManager.Instance.ServerConnection.AsyncConnectedEvent += ServerConnection_AsyncConnectedEvent;
  1. Creation of methods called when events are fired
private void ServerConnection_ConnectedToServerEvent()
{
    NetworkManager.Instance.ServerConnection.AuthenticateUser("login", "password");
}

private void ServerConnection_AsyncConnectedEvent(AsyncConnectedRequest asyncConnectedRequest)
{
    Debug.Log(string.Format("User {0} is authenticated", asyncConnectedRequest.player.name));
}
  1. Deleting events
private void Dispose()
{
    NetworkManager.Instance.ServerConnection.ConnectedToServerEvent -= ServerConnection_ConnectedToServerEvent;
    NetworkManager.Instance.ServerConnection.AsyncConnectedEvent -= ServerConnection_AsyncConnectedEvent;
}