Welcome back to part 2 of the server 2 server material.
In Part 1 we covered making a NodeResolverBase which we called Master server. Now we need a way to communicate with the MasterServer so we are going to create a new class called IncomingSubServerPeer. So create that class and implement the members, but we will have a slightly different constructor. We will also create a link to the MasterServer and our Log to be able to add logs any time we feel the need.
class IncomingSubServerPeer : ServerPeerBase
{
private MasterServer _server;
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();
public IncomingSubServerPeer(InitRequest request, MasterServer server) : base(request.Protocol, request.PhotonPeer)
{
_server = server;
if(Log.IsDebugEnabled)
{
Log.DebugFormat("SubServer connected from {0}:{1} - connection id: {2}", RemoteIP, RemotePort, ConnectionId);
}
}
#region Overrides of PeerBase
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
throw new NotImplementedException();
}
protected override void OnDisconnect()
{
throw new NotImplementedException();
}
#endregion
#region Overrides of ServerPeerBase
protected override void OnEvent(IEventData eventData, SendParameters sendParameters)
{
throw new NotImplementedException();
}
protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
{
throw new NotImplementedException();
}
#endregion
}
With that in place, the next thing we are going to go ahead and do is write out to the log when we have received an OperationRequest.
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
if(Log.IsDebugEnabled)
{
Log.DebugFormat("Received operation request from {0} - op code {1}", ConnectionId, operationRequest.OperationCode);
}
}
We will also put in a log statement for when the server disconnects.
protected override void OnDisconnect()
{
if(Log.IsDebugEnabled)
{
Log.DebugFormat("Connection from Sub Server {0} terminated", ConnectionId);
}
}
With that we have everything for this file done. The last thing we need to look at doing is creating this peer when a server connects. Fortunately we already have that in place in the MasterServer.CreatePeer()
protected override PeerBase CreatePeer(InitRequest initRequest)
{
if(IsSubServerPeer(initRequest))
{
if(Log.IsDebugEnabled)
{
Log.DebugFormat("Received init request from sub server");
}
return new IncomingSubServerPeer(initRequest, this);
}
return null;
}
And thats everything. In Part 3 we will be adding in the code and classes necessary to register a sub server by processing the registersubserver operation request.