Beispiel #1
0
        public override void ReadFromBitStream(ReadOnlyBitStream bitStream)
        {
            bool isBigEndian = bitStream.IsBigEndian();

            bitStream.SetBigEndian(false);

            ClientTimeUnix = bitStream.ReadInt64();
            ServerTimeUnix = bitStream.ReadInt64();

            bitStream.SetBigEndian(isBigEndian);
        }
 public void FromBitStream(ReadOnlyBitStream packetStream)
 {
     CharacterId = packetStream.ReadInt64();
 }
        public override void Run()
        {
            while (!terminationRequested || !incomingPacketQueue.IsEmpty)
            {
                IncomingDatagramPacket packet;

                if (incomingPacketQueue.TryDequeue(out packet))
                {
                    ReadOnlyBitStream packetStream = new ReadOnlyBitStream(packet.Data);

                    byte rakNetPacketId = packetStream.ReadByte();

                    switch (rakNetPacketId)
                    {
                    case 17:     // ID_NEW_INCOMING_CONNECTION
                    {
                        Server.Instance.Scheduler.RunTask(() => Server.Instance.EventManager.Publish(new ClientConnectEvent(packet.SourceAddress, packet.SourcePort, packet.DestinationAddress, packet.DestinationPort)));
                        break;
                    }

                    case 19:     // ID_DISCONNECTION_NOTIFICATION
                    case 20:     // ID_CONNECTION_LOST
                    {
                        Server.Instance.Scheduler.RunTask(() => Server.Instance.EventManager.Publish(new ClientDisconnectEvent(packet.SourceAddress, packet.SourcePort, packet.DestinationAddress, packet.DestinationPort)));
                        break;
                    }

                    case 83:     // ID_USER_PACKET_ENUM
                    {
                        try
                        {
                            RemoteConnectionType remoteConnectionType = (RemoteConnectionType)packetStream.ReadUInt16();
                            uint luPacketId = packetStream.ReadUInt32();

                            packetStream.SkipBytes(1);

                            IUnserializable gamePacket = null;

                            switch (remoteConnectionType)
                            {
                            case RemoteConnectionType.General:
                            {
                                GeneralPacketId generalPacketId = (GeneralPacketId)luPacketId;

                                switch (generalPacketId)
                                {
                                case GeneralPacketId.MSG_SERVER_VERSION_CONFIRM:
                                {
                                    gamePacket = new GeneralVersionConfirmPacket();
                                    break;
                                }

                                default:
                                {
                                    Server.Instance.Logger.Log("Received an unknown LU packet. generalPacketId=" + generalPacketId);
                                    break;
                                }
                                }

                                break;
                            }

                            case RemoteConnectionType.Auth:
                            {
                                AuthPacketId authPacketId = (AuthPacketId)luPacketId;

                                switch (authPacketId)
                                {
                                case AuthPacketId.MSG_AUTH_LOGIN_REQUEST:
                                {
                                    gamePacket = new AuthLoginRequestPacket();
                                    break;
                                }

                                default:
                                {
                                    Server.Instance.Logger.Log("Received an unknown LU packet. authPacketId=" + authPacketId);
                                    break;
                                }
                                }

                                break;
                            }

                            case RemoteConnectionType.World:
                            {
                                WorldPacketId worldPacketId = (WorldPacketId)luPacketId;

                                switch (worldPacketId)
                                {
                                case WorldPacketId.MSG_WORLD_CLIENT_VALIDATION:
                                {
                                    gamePacket = new WorldValidationPacket();
                                    break;
                                }

                                case WorldPacketId.MSG_WORLD_CLIENT_CHARACTER_LIST_REQUEST:
                                {
                                    gamePacket = new WorldCharacterListRequestPacket();
                                    break;
                                }

                                case WorldPacketId.MSG_WORLD_CLIENT_CHARACTER_CREATE_REQUEST:
                                {
                                    gamePacket = new WorldCharacterCreateRequestPacket();
                                    break;
                                }

                                case WorldPacketId.MSG_WORLD_CLIENT_CHARACTER_DELETE_REQUEST:
                                {
                                    gamePacket = new WorldCharacterDeleteRequestPacket();
                                    break;
                                }

                                case WorldPacketId.MSG_WORLD_CLIENT_CHARACTER_RENAME_REQUEST:
                                {
                                    gamePacket = new WorldCharacterRenameRequestPacket();
                                    break;
                                }

                                case WorldPacketId.MSG_WORLD_CLIENT_LOGIN_REQUEST:
                                {
                                    gamePacket = new WorldLoginRequestPacket();
                                    break;
                                }

                                case WorldPacketId.MSG_WORLD_CLIENT_LEVEL_LOAD_COMPLETE:
                                {
                                    gamePacket = new WorldLevelLoadCompletePacket();
                                    break;
                                }

                                case WorldPacketId.MSG_WORLD_CLIENT_POSITION_UPDATE:
                                {
                                    gamePacket = new WorldPositionUpdatePacket();
                                    break;
                                }

                                case WorldPacketId.MSG_WORLD_CLIENT_GAME_MSG:
                                {
                                    long   objectId      = packetStream.ReadInt64();
                                    ushort gameMessageId = packetStream.ReadUInt16();

                                    switch (gameMessageId)
                                    {
                                    case (ushort)GameMessageId.PlayerLoaded:
                                    {
                                        gamePacket = new PlayerLoadedGameMessage(objectId);
                                        break;
                                    }

                                    default:
                                    {
                                        Server.Instance.Logger.Log("Received an unknown LU packet. gameMessageId=" + gameMessageId);
                                        break;
                                    }
                                    }
                                    break;
                                }

                                default:
                                {
                                    Server.Instance.Logger.Log("Received an unknown LU packet. worldPacketId=" + worldPacketId);
                                    break;
                                }
                                }

                                break;
                            }

                            default:
                            {
                                Server.Instance.Logger.Log("Received an unknown LU packet. remoteConnectionType=" + remoteConnectionType);
                                break;
                            }
                            }

                            if (gamePacket != null)
                            {
                                gamePacket.FromBitStream(packetStream);

                                Server.Instance.Scheduler.RunTask(() => Server.Instance.EventManager.Publish(new GamePacketReceiveEvent(packet.SourceAddress, packet.SourcePort, packet.DestinationAddress, packet.DestinationPort, gamePacket)));
                            }
                        }
                        catch (Exception exc)
                        {
                            StackTrace stackTrace = new StackTrace(exc, true);
                            StackFrame stackFrame = stackTrace.GetFrame(0);

                            string fileName   = stackFrame.GetFileName();
                            int    fileLine   = stackFrame.GetFileLineNumber();
                            int    fileColumn = stackFrame.GetFileColumnNumber();

                            Server.Instance.Logger.Log("Received an invalid game packet. address=" + packet.SourceAddress + " port=" + packet.SourcePort + " exception=" + exc.Message + " stackTrace=" + fileName + ":" + fileLine + ":" + fileColumn);
                        }

                        break;
                    }

                    default:
                    {
                        Server.Instance.Logger.Log("Received an unknown RakNet packet. rakNetPacketId=" + rakNetPacketId);
                        break;
                    }
                    }
                }
                else
                {
                    Thread.Sleep(1);
                }
            }
        }
        public void FromBitStream(ReadOnlyBitStream packetStream)
        {
            float positionX = packetStream.ReadSingle();
            float positionY = packetStream.ReadSingle();
            float positionZ = packetStream.ReadSingle();

            Position = new JVector(positionX, positionY, positionZ);

            float rotationX = packetStream.ReadSingle();
            float rotationY = packetStream.ReadSingle();
            float rotationZ = packetStream.ReadSingle();
            float rotationW = packetStream.ReadSingle();

            Rotation = new JQuaternion(rotationX, rotationY, rotationZ, rotationW);

            IsSupported = packetStream.ReadBit();
            IsOnRail    = packetStream.ReadBit();

            bool flag = packetStream.ReadBit();

            if (flag)
            {
                float linearVelocityX = packetStream.ReadSingle();
                float linearVelocityY = packetStream.ReadSingle();
                float linearVelocityZ = packetStream.ReadSingle();

                LinearVelocity = new JVector(linearVelocityX, linearVelocityY, linearVelocityZ);
            }

            flag = packetStream.ReadBit();

            if (flag)
            {
                float angularVelocityX = packetStream.ReadSingle();
                float angularVelocityY = packetStream.ReadSingle();
                float angularVelocityZ = packetStream.ReadSingle();

                AngularVelocity = new JVector(angularVelocityX, angularVelocityY, angularVelocityZ);
            }

            flag = packetStream.ReadBit();

            if (flag)
            {
                LocalSpaceObjectId = packetStream.ReadInt64();

                float localPositionX = packetStream.ReadSingle();
                float localPositionY = packetStream.ReadSingle();
                float localPositionZ = packetStream.ReadSingle();

                LocalPosition = new JVector(localPositionX, localPositionY, localPositionZ);

                flag = packetStream.ReadBit();

                if (flag)
                {
                    float localLinearVelocityX = packetStream.ReadSingle();
                    float localLinearVelocityY = packetStream.ReadSingle();
                    float localLinearVelocityZ = packetStream.ReadSingle();

                    LocalLinearVelocity = new JVector(localLinearVelocityX, localLinearVelocityY, localLinearVelocityZ);
                }
            }
        }
 public void FromBitStream(ReadOnlyBitStream packetStream)
 {
     PlayerId = packetStream.ReadInt64();
 }
Beispiel #6
0
 public void FromBitStream(ReadOnlyBitStream packetStream)
 {
     CharacterId = packetStream.ReadInt64();
     NewName     = packetStream.ReadWideString(33);
 }