Ejemplo n.º 1
0
        public void ReadPacketTwo_ReadsValuesProperly()
        {
            var packet = new PlayerPureSyncPacket();

            packet.Read(this.testPacketTwo);

            packet.SyncFlags.IsInWater.Should().Be(false);
            packet.SyncFlags.IsOnGround.Should().Be(true);
            packet.SyncFlags.HasJetpack.Should().Be(false);
            packet.SyncFlags.IsDucked.Should().Be(false);
            packet.SyncFlags.WearsGoggles.Should().Be(false);
            packet.SyncFlags.HasContact.Should().Be(false);
            packet.SyncFlags.IsChoking.Should().Be(false);
            packet.SyncFlags.AkimboTargetUp.Should().Be(false);
            packet.SyncFlags.IsOnFire.Should().Be(false);
            packet.SyncFlags.HasAWeapon.Should().Be(true);
            packet.SyncFlags.IsSyncingVelocity.Should().Be(false);
            packet.SyncFlags.IsStealthAiming.Should().Be(false);

            packet.Position.Should().NotBe(Vector3.Zero);
            packet.Velocity.Should().Be(Vector3.Zero);

            packet.Health.Should().Be(100);
            packet.Armor.Should().Be(0);

            //packet.CameraRotation.Should().Be(0);
            packet.CameraOrientation.BasePosition.Should().Be(packet.Position);
            //packet.CameraOrientation.CameraPosition.Should().Be(Vector3.Zero);
            //packet.CameraOrientation.CameraForward.Should().Be(Vector3.Zero);
        }
Ejemplo n.º 2
0
        protected override void HandlePacket(PacketQueueEntry queueEntry)
        {
            try
            {
                switch (queueEntry.PacketId)
                {
                case PacketId.PACKET_ID_CAMERA_SYNC:
                    CameraSyncPacket cameraPureSyncPacket = new CameraSyncPacket();
                    cameraPureSyncPacket.Read(queueEntry.Data);
                    HandleCameraSyncPacket(queueEntry.Client, cameraPureSyncPacket);
                    break;

                case PacketId.PACKET_ID_PLAYER_PURESYNC:
                    PlayerPureSyncPacket playerPureSyncPacket = new PlayerPureSyncPacket();
                    playerPureSyncPacket.Read(queueEntry.Data);
                    HandleClientPureSyncPacket(queueEntry.Client, playerPureSyncPacket);
                    break;
                }
            } catch (Exception e)
            {
                Debug.WriteLine("Handling packet failed");
                Debug.WriteLine(string.Join(", ", queueEntry.Data));
                Debug.WriteLine($"{e.Message}\n{e.StackTrace}");
            }
        }
Ejemplo n.º 3
0
        public async void HandlePackets()
        {
            while (true)
            {
                while (this.packetQueue.TryDequeue(out PacketQueueEntry queueEntry))
                {
                    try
                    {
                        Console.WriteLine(queueEntry.PacketId);
                        switch (queueEntry.PacketId)
                        {
                        case PacketId.PACKET_ID_CAMERA_SYNC:
                            CameraSyncPacket cameraPureSyncPacket = new CameraSyncPacket();
                            cameraPureSyncPacket.Read(queueEntry.Data);
                            HandleCameraSyncPacket(queueEntry.Client, cameraPureSyncPacket);
                            break;

                        case PacketId.PACKET_ID_PLAYER_PURESYNC:
                            PlayerPureSyncPacket playerPureSyncPacket = new PlayerPureSyncPacket();
                            playerPureSyncPacket.Read(queueEntry.Data);
                            HandlePlayerPureSyncPacket(queueEntry.Client, playerPureSyncPacket);
                            break;
                        }
                    } catch (Exception e)
                    {
                        Console.WriteLine("Handling packet failed");
                        Console.WriteLine(string.Join(", ", queueEntry.Data));
                        //Console.WriteLine($"{e.Message}\n{e.StackTrace}");
                    }
                }
                await Task.Delay(this.sleepInterval);
            }
        }
Ejemplo n.º 4
0
        private void TestPureSync(Client client)
        {
            var playerList = new PlayerListPacket(false);

            playerList.AddPlayer(
                playerId: 666,
                timeContext: 0,
                nickname: "Dummy-Player",
                bitsreamVersion: 343,
                buildNumber: 0,

                isDead: false,
                isInVehicle: false,
                hasJetpack: true,
                isNametagShowing: true,
                isNametagColorOverriden: true,
                isHeadless: false,
                isFrozen: false,

                nametagText: "Dummy-Player",
                color: Color.FromArgb(255, 255, 0, 255),
                moveAnimation: 0,

                model: 9,
                teamId: null,

                vehicleId: null,
                seat: null,

                position: new Vector3(5, 0, 3),
                rotation: 0,

                dimension: 0,
                fightingStyle: 0,
                alpha: 255,
                interior: 0,

                weapons: new byte[16]
                );
            client.SendPacket(playerList);

            var data     = new byte[] { 0, 0, 0, 0, 2, 46, 33, 240, 8, 159, 255, 240, 8, 4, 116, 11, 186, 246, 64, 0, 73, 144, 129, 19, 48, 0, 0 };
            var puresync = new PlayerPureSyncPacket();

            puresync.Read(data);

            puresync.PlayerId = 666;
            puresync.Latency  = 0;

            //_ = Task.Run(async () =>
            //{
            //    for (int i = 0; i < 1000; i++)
            //    {
            //        puresync.Position += new Vector3(0.25f, 0, 0);
            //        client.SendPacket(puresync);
            //        await Task.Delay(250);
            //    }
            //});
        }
Ejemplo n.º 5
0
        private void HandleClientPureSyncPacket(Client client, PlayerPureSyncPacket packet)
        {
            client.SendPacket(new ReturnSyncPacket(packet.Position));

            packet.PlayerId = client.Player.Id;
            packet.Latency  = 0;
            foreach (var remotePlayer in this.elementRepository.GetByType <Player>(ElementType.Player))
            {
                if (remotePlayer.Client != client)
                {
                    remotePlayer.Client.SendPacket(packet);
                }
            }

            var player = client.Player;

            player.Position     = packet.Position;
            player.Velocity     = packet.Velocity;
            player.Health       = packet.Health;
            player.Armor        = packet.Armor;
            player.AimOrigin    = packet.AimOrigin;
            player.AimDirection = packet.AimDirection;

            player.ContactElement = this.elementRepository.Get(packet.ContactElementId);

            player.CurrentWeapon = new PlayerWeapon()
            {
                WeaponType = packet.WeaponType,
                Slot       = packet.WeaponSlot,
                Ammo       = packet.TotalAmmo,
                AmmoInClip = packet.AmmoInClip
            };

            player.IsInWater         = packet.SyncFlags.IsInWater;
            player.IsOnGround        = packet.SyncFlags.IsOnGround;
            player.HasJetpack        = packet.SyncFlags.HasJetpack;
            player.IsDucked          = packet.SyncFlags.IsDucked;
            player.WearsGoggles      = packet.SyncFlags.WearsGoggles;
            player.HasContact        = packet.SyncFlags.HasContact;
            player.IsChoking         = packet.SyncFlags.IsChoking;
            player.AkimboTargetUp    = packet.SyncFlags.AkimboTargetUp;
            player.IsOnFire          = packet.SyncFlags.IsOnFire;
            player.IsSyncingVelocity = packet.SyncFlags.IsSyncingVelocity;
            player.IsStealthAiming   = packet.SyncFlags.IsStealthAiming;

            player.CameraPosition  = packet.CameraOrientation.CameraPosition;
            player.CameraDirection = packet.CameraOrientation.CameraForward;
            player.CameraRotation  = packet.CameraRotation;
        }
Ejemplo n.º 6
0
        public void ReadPacketThree_ReadsValuesProperly()
        {
            var packet = new PlayerPureSyncPacket();

            packet.Read(this.testPacketThree);

            packet.SyncFlags.IsInWater.Should().Be(false);
            packet.SyncFlags.IsOnGround.Should().Be(true);
            packet.SyncFlags.HasJetpack.Should().Be(false);
            packet.SyncFlags.IsDucked.Should().Be(false);
            packet.SyncFlags.WearsGoggles.Should().Be(false);
            packet.SyncFlags.HasContact.Should().Be(false);
            packet.SyncFlags.IsChoking.Should().Be(false);
            packet.SyncFlags.AkimboTargetUp.Should().Be(false);
            packet.SyncFlags.IsOnFire.Should().Be(false);
            packet.SyncFlags.HasAWeapon.Should().Be(true);
            packet.SyncFlags.IsSyncingVelocity.Should().Be(true);
            packet.SyncFlags.IsStealthAiming.Should().Be(false);
        }
Ejemplo n.º 7
0
        private void HandlePlayerPureSyncPacket(Client client, PlayerPureSyncPacket packet)
        {
            client.SendPacket(new ReturnSyncPacket(packet.Position));

            packet.PlayerId = client.Id;
            packet.Latency  = 0;
            foreach (var player in this.server.ElementRepository.GetByType <Client>(ElementType.Player))
            {
                if (player != client)
                {
                    player.SendPacket(packet);
                }
            }

            client.Position = packet.Position;

            //Console.WriteLine($"client {client.Id} pure sync: ");
            //Console.WriteLine($"\tFlags:");

            //Console.WriteLine($"\t\tIsInWater: {packet.SyncFlags.IsInWater}");
            //Console.WriteLine($"\t\tIsOnGround: {packet.SyncFlags.IsOnGround}");
            //Console.WriteLine($"\t\tHasJetpack: {packet.SyncFlags.HasJetpack}");
            //Console.WriteLine($"\t\tIsDucked: {packet.SyncFlags.IsDucked}");
            //Console.WriteLine($"\t\tWearsGoggles: {packet.SyncFlags.WearsGoggles}");
            //Console.WriteLine($"\t\tHasContact: {packet.SyncFlags.HasContact}");
            //Console.WriteLine($"\t\tIsChoking: {packet.SyncFlags.IsChoking}");
            //Console.WriteLine($"\t\tAkimboTargetUp: {packet.SyncFlags.AkimboTargetUp}");
            //Console.WriteLine($"\t\tIsOnFire: {packet.SyncFlags.IsOnFire}");
            //Console.WriteLine($"\t\tHasAWeapon: {packet.SyncFlags.HasAWeapon}");
            //Console.WriteLine($"\t\tIsSyncingVelocity: {packet.SyncFlags.IsSyncingVelocity}");
            //Console.WriteLine($"\t\tIsStealthAiming: {packet.SyncFlags.IsStealthAiming}");

            Console.WriteLine($"\tposition: {packet.Position}, rotation: {packet.Rotation}");
            //Console.WriteLine($"\tvelocity: {packet.Velocity}");
            //Console.WriteLine($"\thealth: {packet.Health}, armour: {packet.Armour}");
            //Console.WriteLine($"\tCamera rotation: {packet.CameraRotation}, position: {packet.CameraOrientation.CameraPosition}, forward: {packet.CameraOrientation.CameraForward}");
        }