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);
        }
示例#2
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 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());
        }
示例#5
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());
                }

            }
        }
示例#7
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);
        }