Синтаксис:
Используется csharp
class PhotonServer : ApplicationBase
{
#region Overload of AplicationBase
protected override PeerBase CreatePeer(InitRequest initRequest)
{
return new UnityClient(initRequest.Protocol, initRequest.PhotonPeer);
}
protected override void Setup()
{
var file = new FileInfo(Path.Combine(BinaryPath, "log4net.config"));
if (file.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
XmlConfigurator.ConfigureAndWatch(file);
}
}
protected override void TearDown()
{
}
#endregion
}
{
#region Overload of AplicationBase
protected override PeerBase CreatePeer(InitRequest initRequest)
{
return new UnityClient(initRequest.Protocol, initRequest.PhotonPeer);
}
protected override void Setup()
{
var file = new FileInfo(Path.Combine(BinaryPath, "log4net.config"));
if (file.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
XmlConfigurator.ConfigureAndWatch(file);
}
}
protected override void TearDown()
{
}
#endregion
}
И класс UnityClient унаследованный от PeerBase (представлено часть кода)
Синтаксис:
Используется csharp
public class UnityClient : PeerBase
{
private readonly ILogger log = LogManager.GetCurrentClassLogger();
public UnityClient(IRpcProtocol protocol, IPhotonPeer peer)
: base(protocol, peer)
{
log.Debug("Connected from " + peer.GetRemoteIP());
}
protected override void OnDisconnect()
{
log.Debug("Client disconnected");
}
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
switch(operationRequest.OperationCode)
{
case 1:
if (operationRequest.Parameters.ContainsKey(1))
{
log.Debug("Recived 123 " + operationRequest.Parameters[1]);
OperationResponse response = new OperationResponse(operationRequest.OperationCode);
response.Parameters = new Dictionary<byte, object> { { 1, "Response recived" } };
SendOperationResponse(response, sendParameters);
Flush();
}
break;
case 2:
if (operationRequest.Parameters.ContainsKey(1))
{
private readonly ILogger log = LogManager.GetCurrentClassLogger();
public UnityClient(IRpcProtocol protocol, IPhotonPeer peer)
: base(protocol, peer)
{
log.Debug("Connected from " + peer.GetRemoteIP());
}
protected override void OnDisconnect()
{
log.Debug("Client disconnected");
}
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
switch(operationRequest.OperationCode)
{
case 1:
if (operationRequest.Parameters.ContainsKey(1))
{
log.Debug("Recived 123 " + operationRequest.Parameters[1]);
OperationResponse response = new OperationResponse(operationRequest.OperationCode);
response.Parameters = new Dictionary<byte, object> { { 1, "Response recived" } };
SendOperationResponse(response, sendParameters);
Flush();
}
break;
case 2:
if (operationRequest.Parameters.ContainsKey(1))
Тоесть я отлавливаю OnOperationRequest и через switch(operationRequest.OperationCode) узнаю что пришло и что делать дальше
Но сразу возникает Вопрос а если ответов от клиента нужно учитывать сотни, то нужно делать сто case или это как то можно по другому реализовать? Покажите или расскажите как это правильно делается? Какие есть способы еще?