using ExitGames.Logging;
using Photon.SocketServer;
using PhotonHostRuntimeInterfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OHAGameServer
{
class UnityClient : ClientPeer
{
private readonly ILogger Log = LogManager.GetCurrentClassLogger();
public UnityClient(InitRequest initRequest) : base(initRequest)
{
Log.Info("Player Client ip: " + this.RemoteIP);
}
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
switch (operationRequest.OperationCode)
{
case 1:
if (operationRequest.Parameters.ContainsKey(1))
{
Log.Info("recv:" + operationRequest.Parameters[1]);
OperationResponse response = new OperationResponse(operationRequest.OperationCode);
response.Parameters = new Dictionary<byte, object> { { 1, "response message" } };
SendOperationResponse(response, sendParameters);
}
break;
case 2:
if (operationRequest.Parameters.ContainsKey(1))
{
Log.Info("recv:" + operationRequest.Parameters[1]);
EventData eventData = new EventData(1);
eventData.Parameters = new Dictionary<byte, object> { { 1, "response for event" } };
SendEvent(eventData, sendParameters);
}
break;
default:
Log.Info("Unknown OperationRequest received!:" + operationRequest.OperationCode);
break;
}
}
protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
{
Log.Info("Disconnected!");
}
}
}