Exemple #1
0
        protected override bool OnHandleMessage(IMessage message, PhotonClientPeer peer)
        {
            Log.DebugFormat("Handling Client Chat Request");

            #region Purge & Replace (PeerId, UserId, CharacterId)
            message.Parameters.Remove((byte)ClientParameterCode.PeerId);
            message.Parameters.Add((byte)ClientParameterCode.PeerId, peer.PeerId.ToByteArray());
            message.Parameters.Remove((byte)ClientParameterCode.UserId);
            if (peer.ClientData <CharacterData>().UserId.HasValue)
            {
                message.Parameters.Add((byte)ClientParameterCode.UserId, peer.ClientData <CharacterData>().UserId);
            }
            if (peer.ClientData <CharacterData>().CharacterId.HasValue)
            {
                message.Parameters.Remove((byte)ClientParameterCode.CharacterId);
                message.Parameters.Add((byte)ClientParameterCode.CharacterId, peer.ClientData <CharacterData>().CharacterId);
            }
            #endregion

            var operationRequest = new OperationRequest(message.Code, message.Parameters);
            switch (message.Code)
            {
            case (byte)ClientOperationCode.Chat:
                if (Server.ConnectionCollection <PhotonConnectionCollection>() != null)
                {
                    Server.ConnectionCollection <PhotonConnectionCollection>().GetServerByType((int)ServerType.Chat).SendOperationRequest(operationRequest, new SendParameters());
                }
                break;

            default:
                Log.DebugFormat("Invalid Operation Code - Expecting Chat");
                break;
            }
            return(true);
        }
        public override bool OnHandleMessage(IMessage message, IServerPeer serverPeer)
        {
            Log.DebugFormat("Forwarding Response {0}-{1}", message.Code, message.SubCode);
            if (message.Parameters.ContainsKey(_serverConfiguration.PeerIdCode))
            {
                Log.DebugFormat("Looking for Peer Id {0}", new Guid((Byte[])message.Parameters[_serverConfiguration.PeerIdCode]));
                PhotonClientPeer peer = _connectionCollection.GetPeers <PhotonClientPeer>().FirstOrDefault(p => p.PeerId == new Guid((Byte[])message.Parameters[_serverConfiguration.PeerIdCode]));
                if (peer != null)
                {
                    Log.DebugFormat("Found Peer");

                    message.Parameters.Remove(_serverConfiguration.PeerIdCode);
                    _clientCodeRemover.RemoveCodes(message);

                    var response = message as Response;
                    if (response != null)
                    {
                        peer.SendOperationResponse(
                            new OperationResponse(response.Code, response.Parameters)
                        {
                            DebugMessage = response.DebugMessage,
                            ReturnCode   = response.ReturnCode
                        },
                            new SendParameters());
                    }
                    else
                    {
                        peer.SendOperationResponse(new OperationResponse(message.Code, message.Parameters), new SendParameters());
                    }
                }
            }
            return(true);
        }
        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            var clientPeer = new PhotonClientPeer(initRequest);

            clientPeer.Fiber.Enqueue(() => application.OnConnected(clientPeer));
            return(clientPeer);
        }
        protected override bool OnHandleMessage(IMessage message, PhotonClientPeer peer)
        {
            Log.DebugFormat("Here we are handling a message with code {0}", message.Code);
            message.Parameters.Remove((byte)ClientParameterCode.PeerId);
            message.Parameters.Add((byte)ClientParameterCode.PeerId, peer.PeerId.ToByteArray());
            message.Parameters.Remove((byte)ClientParameterCode.UserId);
            if (peer.ClientData <CharacterData>().UserId.HasValue)
            {
                message.Parameters.Add((byte)ClientParameterCode.UserId, peer.ClientData <CharacterData>().UserId);
            }

            if (peer.ClientData <CharacterData>().CharacterId.HasValue)
            {
                message.Parameters.Remove((byte)ClientParameterCode.CharacterId);
                message.Parameters.Add((byte)ClientParameterCode.CharacterId, peer.ClientData <CharacterData>().CharacterId);
            }
            var operationRequest = new OperationRequest(message.Code, message.Parameters);

            switch (message.Code)
            {
            case (byte)ClientOperationCode.Login:
                if (Server.ConnectionCollection <PhotonConnectionCollection>() != null)
                {
                    Server.ConnectionCollection <PhotonConnectionCollection>().GetServerByType((int)ServerType.Login)
                    .SendOperationRequest(operationRequest, new SendParameters());
                }
                break;

            default:
                Log.DebugFormat("invalid operation code expecting login");
                break;
            }

            return(true);
        }
 public PhotonPeerFactory(PhotonServerPeer.Factory serverPeerFactory, PhotonClientPeer.Factory clientPeerFactory, PhotonConnectionCollection subServerCollection, PhotonApplication application)
 {
     _serverPeerFactory = serverPeerFactory;
     _clientPeerFactory = clientPeerFactory;
     _subServerCollection = subServerCollection;
     _application = application;
 }
        public override void ClientDisconnect(PhotonClientPeer clientPeer)
        {
            var para = new Dictionary<byte, object>
            {
                {(byte) ClientParameterCode.PeerId, clientPeer.PeerId.ToByteArray()}
            };

            if (clientPeer.ClientData<CharacterData>().CharacterId.HasValue)
            {
                Log.DebugFormat("Sending disconnect for client {0}:{1}", clientPeer.PeerId,
                    clientPeer.ClientData<CharacterData>().CharacterId.Value);
                if (ChatServer != null)
                {
                    ChatServer.SendEvent(new EventData((byte)ServerEventCode.CharacterDeRegister, para),
                   new SendParameters());
                }
                if (clientPeer.CurrentServer != null)
                {
                    clientPeer.CurrentServer.SendEvent(
                    new EventData((byte)ServerEventCode.CharacterDeRegister, para), new SendParameters());
                }

            }

            Log.DebugFormat("xxx sending user loggedout sendevent");
            LoginServer.SendEvent(new EventData((byte) ServerEventCode.UserLoggedOut, para), new SendParameters());
        }
        public override void ClientDisconnect(PhotonClientPeer clientPeer)
        {
            var para = new Dictionary<byte, object>
            {
                {(byte) ClientParameterCode.PeerId, clientPeer.PeerId.ToByteArray()}
            };

            if (clientPeer.ClientData<CharacterData>().CharacterId.HasValue)
            {
                Log.DebugFormat("Sending disconnect for client {0}:{1}", clientPeer.PeerId,
                    clientPeer.ClientData<CharacterData>().CharacterId.Value);
                if (ChatServer != null)
                {
                    ChatServer.SendEvent(new EventData((byte)ServerEventCode.CharacterDeRegister, para),
                   new SendParameters());
                }
                if (clientPeer.CurrentServer != null)
                {
                    clientPeer.CurrentServer.SendEvent(
                    new EventData((byte)ServerEventCode.CharacterDeRegister, para), new SendParameters());
                }
                
            }

            Log.DebugFormat("xxx sending user loggedout sendevent");
            LoginServer.SendEvent(new EventData((byte) ServerEventCode.UserLoggedOut, para), new SendParameters());
        }
Exemple #8
0
    //---------------------------------------------------------------------
    public override void init()
    {
        EbLog.Note("EcApp.init() entity_rpcid=" + Entity.getEntityRpcId());

        defRpcMethod((byte)_eNodeType.Es, (ushort)_eMethodType.es2ecOnLogin, es2ecOnLogin);

        mPeer = new PhotonClientPeer(EntityMgr, 1, (RpcSessionListener)this);
        Entity.setSession((byte)_eNodeType.Es, mPeer.getRpcSession());

        mPeer.Connect("127.0.0.1:5880", "EsTest");
    }
Exemple #9
0
        public override bool OnHandleMessage(IMessage message, IServerPeer serverPeer)
        {
            Log.DebugFormat("Forwarding Event {0}-{1}", message.Code, message.SubCode);
            if (message.Parameters.ContainsKey(_serverConfiguration.PeerIdCode))
            {
                Log.DebugFormat("Looking for Peer Id {0}", new Guid((Byte[])message.Parameters[_serverConfiguration.PeerIdCode]));
                PhotonClientPeer peer = _connectionCollection.GetPeers <PhotonClientPeer>().FirstOrDefault(p => p.PeerId == new Guid((Byte[])message.Parameters[_serverConfiguration.PeerIdCode]));

                if (peer != null)
                {
                    message.Parameters.Remove(_serverConfiguration.PeerIdCode);
                    _clientCodeRemover.RemoveCodes(message);
                    peer.SendEvent(new EventData(message.Code, message.Parameters), new SendParameters());
                }
            }

            return(true);
        }
Exemple #10
0
        public override void ClientConnect(PhotonClientPeer clientPeer)
        {
            if (clientPeer.ClientData <CharacterData>().CharacterId.HasValue)
            {
                var para = new Dictionary <byte, object>
                {
                    { (byte)ClientParameterCode.CharacterId, clientPeer.ClientData <CharacterData>().CharacterId.Value },
                    { (byte)ClientParameterCode.PeerId, clientPeer.PeerId.ToByteArray() }
                };

                if (ChatServer != null)
                {
                    ChatServer.SendEvent(new EventData((byte)ServerEventCode.CharacterRegister, para), new SendParameters());
                }

                if (clientPeer.CurrentServer != null)
                {
                    clientPeer.CurrentServer.SendEvent(new EventData((byte)ServerEventCode.CharacterRegister, para), new SendParameters());
                }
            }
        }
        public override void ClientConnect(PhotonClientPeer clientPeer)
        {
            if (clientPeer.ClientData<CharacterData>().CharacterId.HasValue)
            {
                var para = new Dictionary<byte, object>
                {
                    {(byte) ClientParameterCode.CharacterId, clientPeer.ClientData<CharacterData>().CharacterId.Value},
                    {(byte) ClientParameterCode.PeerId, clientPeer.PeerId}
                };
                if (ChatServer != null)
                {
                    ChatServer.SendEvent(new EventData((byte)ServerEventCode.CharacterRegister, para),
                  new SendParameters());
                }
                if (clientPeer.CurrentServer != null)
                {
                    clientPeer.CurrentServer.SendEvent(
                  new EventData((byte)ServerEventCode.CharacterRegister, para), new SendParameters());
                }

            }
        }
Exemple #12
0
        protected override bool OnHandleMessage(IMessage message, PhotonClientPeer peer)
        {
            Log.DebugFormat("Handling Client Region Request");

            #region Security information purge and replace
            // Removes messages PeerId and puts real one, if peers instance has and UserId and CharId then removes and replaces them too.
            message.Parameters.Remove((byte)ClientParameterCode.PeerId);
            message.Parameters.Add((byte)ClientParameterCode.PeerId, peer.PeerId.ToByteArray());
            message.Parameters.Remove((byte)ClientParameterCode.UserId);
            if (peer.ClientData <CharacterData>().UserId.HasValue)
            {
                message.Parameters.Add((byte)ClientParameterCode.UserId, peer.ClientData <CharacterData>().UserId);
            }
            if (peer.ClientData <CharacterData>().CharacterId.HasValue)
            {
                message.Parameters.Remove((byte)ClientParameterCode.CharacterId);
                message.Parameters.Add((byte)ClientParameterCode.CharacterId, peer.ClientData <CharacterData>().CharacterId);
            }
            #endregion

            var operationRequest = new OperationRequest(message.Code, message.Parameters);
            switch (message.Code)
            {
            case (byte)ClientOperationCode.Region:
                if (Server.ConnectionCollection <PhotonConnectionCollection>() != null)
                {
                    peer.CurrentServer.SendOperationRequest(operationRequest, new SendParameters());
                }
                break;

            default:
                Log.DebugFormat("Invalid Operation Code - Expecting Region");
                break;
            }
            return(true);
        }
 public override void ClientDisconnect(PhotonClientPeer clientPeer)
 {
     Log.InfoFormat("Logged out {0}", clientPeer.PeerId);
 }
 public override void ClientDisconnect(PhotonClientPeer clientPeer)
 {
     throw new NotImplementedException();
 }
 public override void ClientDisconnect(PhotonClientPeer clientPeer)
 {
     //Log.InfoFormat("Logged out {0}", clientPeer.ClientData[((byte)ClientDataCode.UserId).GetType()]);
 }