Exemplo n.º 1
0
        Packet CreateAndTestJoinPacket(Server server)
        {
            var joinData = new byte[1024];

            var jsonDataObject = new JoinHandlerJson();
            var jsonData       = JsonConvert.SerializeObject(jsonDataObject);

            var packet = new Packet(server, 1024, joinData, server.BindEp);

            packet.AddHeaderToData(17, true, Commands.Join);
            packet.Writer.Write(jsonData);
            packet.PacketSize = (int)packet.Stream.Position;

            Assert.That(packet.Id, Is.EqualTo(17));
            Assert.That(packet.IsReliable, Is.EqualTo(true));
            Assert.That(packet.Command, Is.EqualTo(Commands.Join));
            Assert.That(packet.RemoteEp, Is.EqualTo(server.BindEp));
            var payloadOffset = packet.PayloadOffset;

            packet.ParseHeaderFromData();

            Assert.That(packet.Id, Is.EqualTo(17));
            Assert.That(packet.IsReliable, Is.EqualTo(true));
            Assert.That(packet.Command, Is.EqualTo(Commands.Join));
            Assert.That(packet.RemoteEp, Is.EqualTo(server.BindEp));
            Assert.That(packet.PayloadOffset, Is.EqualTo(payloadOffset));

            var packetHandler = packet.PacketHandler as JoinHandler;

            Assert.That(packetHandler, Is.Not.EqualTo(null));
            Assert.That(server.HasClient(packetHandler.Client), Is.EqualTo(true));

            return(packet);
        }
Exemplo n.º 2
0
        Packet CreateAndTestMovedPacket(Server server)
        {
            server.AddClient(new Client(server.BindEp));

            var UpdateData = new byte[1024];

            var packetId = Utilities.Utilities.GetPacketId();
            var packet   = new Packet(server, 1024, UpdateData, server.BindEp);

            packet.AddHeaderToData(packetId, false, Commands.Move);
            packet.Writer.Write((byte)128);
            packet.Writer.Write(102.5f);
            packet.Writer.Write(0f);
            packet.Writer.Write(25.25f);
            packet.Writer.Write(654f);
            packet.Writer.Write(177.7f);
            packet.Writer.Write(321f);
            packet.Writer.Write(6f);
            packet.PacketSize = (int)packet.Stream.Position;

            Assert.That(packet.Id, Is.EqualTo(packetId));
            Assert.That(packet.IsReliable, Is.EqualTo(false));
            Assert.That(packet.Command, Is.EqualTo(Commands.Move));
            Assert.That(packet.RemoteEp, Is.EqualTo(server.BindEp));
            var payloadOffset = packet.PayloadOffset;

            packet.ParseHeaderFromData();

            Assert.That(packet.Id, Is.EqualTo(packetId));
            Assert.That(packet.IsReliable, Is.EqualTo(false));
            Assert.That(packet.Command, Is.EqualTo(Commands.Move));
            Assert.That(packet.RemoteEp, Is.EqualTo(server.BindEp));
            Assert.That(packet.PayloadOffset, Is.EqualTo(payloadOffset));

            var packetHandler = packet.PacketHandler as MovedHandler;

            Assert.That(packetHandler, Is.Not.EqualTo(null));

            Assert.That(packetHandler.MoveType, Is.EqualTo((byte)128));
            Assert.That(packetHandler.X, Is.EqualTo(102.5f));
            Assert.That(packetHandler.Y, Is.EqualTo(0f));
            Assert.That(packetHandler.Z, Is.EqualTo(25.25f));
            Assert.That(packetHandler.Rx, Is.EqualTo(654f));
            Assert.That(packetHandler.Ry, Is.EqualTo(177.7f));
            Assert.That(packetHandler.Rz, Is.EqualTo(321f));
            Assert.That(packetHandler.Rw, Is.EqualTo(6f));

            return(packet);
        }
Exemplo n.º 3
0
        public void PacketAddHeaderToDataTest()
        {
            var data = new byte[1024];

            var server = new Server(new IPEndPoint(0, 0));

            uint id       = 0;
            var  reliable = true;
            var  command  = Commands.Join;
            var  packet   = new Packet(server, 1024, data, server.BindEp);

            packet.AddHeaderToData(id, reliable, command);

            Assert.That(packet.Id, Is.EqualTo(id));
            Assert.That(packet.IsReliable, Is.EqualTo(reliable));
            Assert.That(packet.Command, Is.EqualTo(command));
            Assert.That(packet.RemoteEp, Is.EqualTo(server.BindEp));
        }