Session Object Data#
The Session Object describes a realtime interaction between a group of one or more players.
To grab the Session, a developer requires the SessionService.
SessionService#
The session service is a utility class used to communicate with the server to create and maintain Session objects. A reference to the SessionService can be pulled from the ServiceFactory
CoreSDK.ServiceFactory.GetService<SessionService>();
In Chess, the Session object is pulled from the server once the a match is found on a ticket using the SessionUid property of the ticket.
Session session = await sessionService.FindById(ticket.SessionUid.ToString());
In Chess, the Session object’s Data is the primary way of communicating data between players. It’s persistent data that can be pulled from any user in a session. It can be pulled directly from the session object with the Data property
1// Get A reference to the Sessions data
2AXRObject data = _session.Data;
There are several ways to make changes to the Session object’s data. In the case of Chess, the SetProperty method is used.
The first parameter is the label of the variable being stored. The second parameter is the value of the variable being stored.
1data.SetProperty("board", map.ToObject());
2// Set the Sessions data to the changed data object
3_session.Data = data;
Once the session data has been updated locally it must be updated on the server for those changes to be distributed.
1_session = await _serviceFactory.GetService<SessionService>().Update(_session.Uid.ToString(), _session);
Those changes can only be distributed if the local user is the Session Host. If a non-host wishes to update the Session object’s data they must be set as the host.
This can be done by setting the Session’s HostUid property as the host.
The Session object’s data can be used in a variety of ways for game development. In Chess, its used to distribute board state and for the chat system.