Exemple #1
0
        void CreateNULLListPlayer(int n, string name)
        {
            InfoPlayer info = new InfoPlayer();

            info.Score = 0;
            info.Name  = name;
            listPlayer.Add(info);
        }
Exemple #2
0
        //Updateo la posicion del player
        static void BroadcastPositionUpdateEvent(uint playerId, ref InfoPlayer infoPlayer)
        {
            var protocol = new Protocol();
            var buffer   = protocol.Serialize((byte)PacketId.PositionAndRotationUpdateEvent, playerId,
                                              infoPlayer.position.x, infoPlayer.position.y, infoPlayer.position.z,
                                              infoPlayer.rotation.x, infoPlayer.rotation.y, infoPlayer.rotation.z,
                                              infoPlayer.rotationPivotWeapon.x, infoPlayer.rotationPivotWeapon.y, infoPlayer.rotationPivotWeapon.z);
            var packet = default(Packet);

            packet.Create(buffer);
            _server.Broadcast(0, ref packet);
        }
Exemple #3
0
        static void HandlePacket(ref Event netEvent)
        {
            InfoPlayer transform = new InfoPlayer();

            transform.position.x = 0;
            transform.position.y = 0;
            transform.position.z = 0;

            transform.rotation.x = 0;
            transform.rotation.y = 0;
            transform.rotation.z = 0;

            transform.rotationPivotWeapon.x = 0;
            transform.rotationPivotWeapon.y = 0;
            transform.rotationPivotWeapon.z = 0;

            var readBuffer = new byte[1024];
            var readStream = new MemoryStream(readBuffer);
            var reader     = new BinaryReader(readStream);

            readStream.Position = 0;
            netEvent.Packet.CopyTo(readBuffer);
            var packetId = (PacketId)reader.ReadByte();

            if (packetId != PacketId.PositionAndRotationUpdateRequest)
            {
                Console.WriteLine($"HandlePacket received: {packetId}");
            }

            if (packetId == PacketId.LoginRequest)
            {
                var playerId = netEvent.Peer.ID;
                SendLoginResponse(ref netEvent, playerId);
                BroadcastLoginEvent(playerId);
                foreach (var p in _players)
                {
                    SendLoginEvent(ref netEvent, p.Key);
                }
                _players.Add(playerId, transform);
            }
            else if (packetId == PacketId.PositionAndRotationUpdateRequest)
            {
                var playerId = reader.ReadUInt32();

                InfoPlayer infoPlayer;

                infoPlayer.position.x = reader.ReadSingle();
                infoPlayer.position.y = reader.ReadSingle();
                infoPlayer.position.z = reader.ReadSingle();

                infoPlayer.rotation.x = reader.ReadSingle();
                infoPlayer.rotation.y = reader.ReadSingle();
                infoPlayer.rotation.z = reader.ReadSingle();

                infoPlayer.rotationPivotWeapon.x = reader.ReadSingle();
                infoPlayer.rotationPivotWeapon.y = reader.ReadSingle();
                infoPlayer.rotationPivotWeapon.z = reader.ReadSingle();

                //Console.WriteLine($"ID: {playerId}, Pos: {x}, {y}");
                BroadcastPositionUpdateEvent(playerId, ref infoPlayer);
            }
            else if (packetId == PacketId.SpawnBulletEvent)
            {
                var playerId = reader.ReadUInt32();
                SendSpawnBulletEvent(playerId);
            }
            else if (packetId == PacketId.CheckColisionBullet)
            {
                var playerId = reader.ReadUInt32();

                float rangeToleration = 10f;
                float positionBulletX = reader.ReadSingle();
                float positionBulletY = reader.ReadSingle();
                float positionBulletZ = reader.ReadSingle();

                float positionPlayerX = _players[playerId].position.x;
                float positionPlayerY = _players[playerId].position.y;
                float positionPlayerZ = _players[playerId].position.z;

                bool enableX = false;
                bool enableY = false;
                bool enableZ = false;
                //      3.5                 5f;               5                   3.5                 5f;              5
                if (positionPlayerX + rangeToleration >= positionBulletX && positionPlayerX - rangeToleration <= positionBulletX)
                {
                    enableX = true;
                }

                if (positionPlayerY + rangeToleration >= positionBulletY && positionPlayerY - rangeToleration <= positionBulletY)
                {
                    enableY = true;
                }

                if (positionPlayerZ + rangeToleration >= positionBulletZ && positionPlayerZ - rangeToleration <= positionBulletZ)
                {
                    enableZ = true;
                }

                if (enableX && enableY && enableZ)
                {
                    SendStateCollisionEventTrue(playerId);
                }
                else
                {
                    SendStateCollisionEventFalse(playerId);
                }
            }
        }