예제 #1
0
 void Sync(NeutronReader streamReader)
 {
     using (streamReader)
     {
         newPosition        = streamReader.ReadVector3();
         newRotation        = streamReader.ReadQuaternion();
         newVelocity        = streamReader.ReadVector3();
         newAngularVelocity = streamReader.ReadVector3();
     }
 }
 public static void ServerMovementValidation(NeutronReader paramsReader, Player mSocket)
 {
     if (!ServerCheatDetection.enabled)
     {
         ServerCheatDetection.enabled = true;
     }
     if (ServerCheatDetection.enabled)
     {
         Vector3    newPosition = paramsReader.ReadVector3();
         Quaternion newRotation = paramsReader.ReadQuaternion();
         //Vector3 newVelocity = paramsReader.ReadVector3();
         //Vector3 newAngularVelocity = paramsReader.ReadVector3();
         //===========================================================\\
         PlayerState statePlayer = mSocket.GetStateObject();
         if (statePlayer != null)
         {
             statePlayer.lastPosition = newPosition;
             statePlayer.lastRotation = newRotation;
             statePlayer.mFrequency++;
         }
     }
 }
예제 #3
0
    void ProcessClientData(TcpClient mSocket, byte[] bufferCopy, int length, IPEndPoint endPoint)
    {
        try
        {
            using (NeutronReader mReader = new NeutronReader(bufferCopy))
            {
                Packet mCommand = mReader.ReadPacket <Packet>();
                if (GetPlayer(mSocket, out Player Sender))
                {
                    switch (mCommand)
                    {
                    case Packet.Connected:
                        HandleConfirmation(Sender, mCommand);
                        break;

                    case Packet.Nickname:
                        HandleNickname(Sender, mReader.ReadString());
                        break;

                    case Packet.SendChat:
                        HandleSendChat(Sender, mCommand, mReader.ReadPacket <Broadcast>(), mReader.ReadString());
                        break;

                    case Packet.InstantiatePlayer:
                        HandleInstantiatePlayer(Sender, mCommand, mReader.ReadPacket <Broadcast>(), mReader.ReadVector3(), mReader.ReadQuaternion(), mReader.ReadString());
                        break;

                    case Packet.SendInput:
                        HandleSendInput(Sender, mCommand, mReader.ReadBytes(length));
                        break;

                    case Packet.RPC:
                        HandleRPC(Sender, mCommand, mReader.ReadPacket <Broadcast>(), mReader.ReadInt32(), mReader.ReadPacket <SendTo>(), mReader.ReadPacket <ValidationPacket>(), mReader.ReadBoolean(), mReader.ReadBytes(length), endPoint);
                        break;

                    case Packet.OnCustomPacket:
                        HandleOnCustomPacket(Sender, mCommand, mReader.ReadPacket <Packet>(), mReader.ReadBytes(length));
                        break;

                    case Packet.Database:
                        Packet dbPacket = mReader.ReadPacket <Packet>();
                        switch (dbPacket)
                        {
                        case Packet.Login:
                            if (!isLoggedin(mSocket))
                            {
                                string username  = mReader.ReadString();
                                string passsword = mReader.ReadString();
                                Enqueue(() => StartCoroutine(Login(Sender, username, passsword)), ref monoBehaviourActions);
                            }
                            else
                            {
                                SendErrorMessage(Sender, mCommand, "You are already logged in.");
                            }
                            break;
                        }
                        break;

                    case Packet.GetChannels:
                        HandleGetChannels(Sender, mCommand);
                        break;

                    case Packet.JoinChannel:
                        HandleJoinChannel(Sender, mCommand, mReader.ReadInt32());
                        break;

                    case Packet.GetChached:
                        HandleGetCached(Sender, mReader.ReadPacket <CachedPacket>());
                        break;

                    case Packet.CreateRoom:
                        HandleCreateRoom(Sender, mCommand, mReader.ReadString(), mReader.ReadInt32(), mReader.ReadString(), mReader.ReadBoolean(), mReader.ReadBoolean(), mReader.ReadBytes(length));
                        break;

                    case Packet.GetRooms:
                        HandleGetRooms(Sender, mCommand);
                        break;

                    case Packet.JoinRoom:
                        HandleJoinRoom(Sender, mCommand, mReader.ReadInt32());
                        break;

                    case Packet.DestroyPlayer:
                        HandleDestroyPlayer(Sender, mCommand);
                        break;

                    case Packet.SendMousePosition:
                        HandleNavMeshAgent(Sender, mCommand, mReader.ReadVector3());
                        break;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LoggerError($"Failed to Response Client {ex.Message}");
        }
    }