Esempio n. 1
0
        public void OnMessageReceived(IntPtr data, int size, long messageNum, long recvTime, int channel)
        {
            var packet = _networkMessagePackager.Unpack(data, size);

            if (packet.GetType() == typeof(TileTypePacket))
            {
                var tileTypePacket = (TileTypePacket)packet;
                var x        = tileTypePacket.X;
                var y        = tileTypePacket.Y;
                var tileType = tileTypePacket.TileType;

                _tiles[x, y].TileType = tileType;
            }
            else if (packet.GetType() == typeof(NewPlayerPacket))
            {
                var newPlayerPacket = (NewPlayerPacket)packet;
                PlayersToAdd.Add(newPlayerPacket);
            }
            else if (packet.GetType() == typeof(MapSendCompletePacket))
            {
                ReceivedMap = true;
            }

            _tilesReceived++;
        }
        public void UnPackEnumPropertyCorrectly()
        {
            var networkMessagePackager = new NetworkMessagePackager();

            var testPacket = new EnumPacket()
            {
                TestEnum = TestEnum.Test
            };

            networkMessagePackager.AddDefinition <EnumPacket>();

            var value  = networkMessagePackager.Package(testPacket);
            var result = (EnumPacket)networkMessagePackager.Unpack(value);

            result.TestEnum.ShouldBe(testPacket.TestEnum);
        }
        public void UnPackCorrectly()
        {
            var networkMessagePackager = new NetworkMessagePackager();

            var testPacket = new TestPacket()
            {
                Number = 3,
                Name   = "Test"
            };

            networkMessagePackager.AddDefinition <TestPacket>();

            var value  = networkMessagePackager.Package(testPacket);
            var result = (TestPacket)networkMessagePackager.Unpack(value);

            result.Name.ShouldBe(testPacket.Name);
            result.Number.ShouldBe(testPacket.Number);
        }