Exemple #1
0
 public PlayerConnectedCmd(byte[] bytes, int offset = 0) :
     base(CommandType.PlayerConnected)
 {
     pID  = Serialization.DecodeInt(bytes, offset);
     pCol = Serialization.DecodeVec3(bytes, offset + 4);
     pPos = Serialization.DecodeVec3(bytes, offset + 4 + Vector3.SizeInBytes);
 }
Exemple #2
0
        public static ClientUpdate Decode(byte[] bytes, int offset = 0)
        {
            int ID = Serialization.DecodeInt(bytes, offset);

            offset += 4;
            int pID = Serialization.DecodeInt(bytes, offset);

            offset += 4;
            PressedKeys keys = (PressedKeys)bytes[offset];

            offset += 1;
            bool left = Serialization.DecodeBool(bytes, offset);

            offset += 1;
            bool right = Serialization.DecodeBool(bytes, offset);

            offset += 1;
            float mAngle = Serialization.DecodeFloat(bytes, offset);

            offset += 4;
            double dt = Serialization.DecodeDouble(bytes, offset);

            offset += 8;
            return(new ClientUpdate(ID, pID, keys, mAngle, left, right, dt));
        }
Exemple #3
0
 public PlayerDeathCmd(byte[] bytes, int offset = 0) :
     base(CommandType.PlayerDeath)
 {
     killedID = Serialization.DecodeInt(bytes, offset);
     offset  += 4;
     killerID = Serialization.DecodeInt(bytes, offset);
     offset  += 4;
     rPos     = Serialization.DecodeVec3(bytes, offset);
     offset  += 4;
 }
Exemple #4
0
 public PlayerFireCmd(byte[] bytes, int offset = 0) :
     base(CommandType.PlayerFire)
 {
     pID     = Serialization.DecodeInt(bytes, offset);
     offset += 4;
     sDir    = Serialization.DecodeVec2(bytes, offset);
     offset += Vector2.SizeInBytes;
     sPos    = Serialization.DecodeVec2(bytes, offset);
     offset += Vector2.SizeInBytes;
 }
Exemple #5
0
        /// <summary>
        /// Receives message using TCP socket.
        /// </summary>
        /// <param name="from">Connected socket to the server</param>
        /// <returns>Task representing the received message.</returns>
        public static async Task <byte[]> TCPReceiveMessageAsync(Socket from)
        {
            var msgLen = Serialization.DecodeInt(await TCPReceiveNBytesAsync(from, 4), 0);

            if (msgLen > 0)
            {
                return(await TCPReceiveNBytesAsync(from, msgLen));
            }
            else
            {
                return(new byte[0]);
            }
        }
Exemple #6
0
        public static ConnectingStaticData Decode(byte[] bytes, int startIndex)
        {
            int pID       = Serialization.DecodeInt(bytes, startIndex);
            int arenaSize = (int)Math.Sqrt(bytes.Length - 4 - startIndex);
            var arena     = new Engine.Arena(arenaSize);

            for (int y = 0; y < arena.Size; y++)
            {
                for (int x = 0; x < arena.Size; x++)
                {
                    arena[x, y] = (Engine.Arena.CellType)bytes[4 + startIndex + x + y * arena.Size];
                }
            }
            return(new ConnectingStaticData(pID, arena));
        }
Exemple #7
0
        public static ConnectingDynamicData Decode(byte[] bytes, int startIndex)
        {
            int offset     = startIndex;
            var numPlayers = Serialization.DecodeInt(bytes, offset);

            offset += 4;
            var numPickups = Serialization.DecodeInt(bytes, offset);

            offset += 4;
            var players = new Dictionary <int, Engine.Player>(numPlayers);

            for (int i = 0; i < numPlayers; ++i)
            {
                var pID = Serialization.DecodeInt(bytes, offset);
                offset += 4;
                var pos = Serialization.DecodeVec3(bytes, offset);
                offset += OpenTK.Vector3.SizeInBytes;
                var col = Serialization.DecodeVec3(bytes, offset);
                offset += OpenTK.Vector3.SizeInBytes;
                var killCount = Serialization.DecodeInt(bytes, offset);
                offset += 4;
                var deathCount = Serialization.DecodeInt(bytes, offset);
                offset += 4;
                players.Add(pID, new Engine.Player(pID, pos, col, killCount, deathCount));
            }
            var pickups = new Dictionary <int, Engine.ShieldPickup>(numPickups);

            for (int i = 0; i < numPickups; ++i)
            {
                var pID = Serialization.DecodeInt(bytes, offset);
                offset += 4;
                var pos = Serialization.DecodeVec3(bytes, offset);
                offset += OpenTK.Vector3.SizeInBytes;
                var state = Serialization.DecodeBool(bytes, offset);
                offset += 1;
                pickups.Add(pID, new Engine.ShieldPickup(pos, state));
            }
            return(new ConnectingDynamicData(players, pickups));
        }
Exemple #8
0
        public PlayersStateCmd(byte[] bytes, int offset = 0) :
            base(CommandType.PlayersStates)
        {
            int numPlayers = (bytes.Length - headerSize) / bytesPerPlayer;

            playerStates = new List <PlayersStateCommand.PlayerState>();

            while (numPlayers-- > 0)
            {
                var ID = Serialization.DecodeInt(bytes, offset);
                offset += 4;
                var pos = Serialization.DecodeVec3(bytes, offset);
                offset += Vector3.SizeInBytes;
                var tankAngle = Serialization.DecodeFloat(bytes, offset);
                offset += 4;
                var towerAngle = Serialization.DecodeFloat(bytes, offset);
                offset += 4;
                var fireCooldown = Serialization.DecodeDouble(bytes, offset);
                offset += 8;
                var currShields = bytes[offset++];
                var currHealth  = bytes[offset++];
                playerStates.Add(new PlayersStateCommand.PlayerState(ID, pos, tankAngle, towerAngle, fireCooldown, currHealth, currShields));
            }
        }
Exemple #9
0
 public PlayerDisconnectedCmd(byte[] bytes, int offset = 0) :
     base(CommandType.PlayerDisconnected)
 {
     pID = Serialization.DecodeInt(bytes, offset);
 }
Exemple #10
0
 public UseShieldPickupCmd(byte[] bytes, int offset = 0) :
     base(CommandType.ShieldDespawn)
 {
     pID     = Serialization.DecodeInt(bytes, offset);
     offset += 4;
 }