コード例 #1
0
        public void CanSerializeAndDeserializeAMessageWithManyItems()
        {
            var item1 = new Item() { Type = ItemType.Player, Data = new PlayerState() };
            var item2 = new Item() { Type = ItemType.PlayerSettings, Data = new NetworkPlayerSettings() };
            var item3 = new Item() { Type = ItemType.ChatLog, Data = new List<Frenetic.ChatMessage>() { new Frenetic.ChatMessage() { ClientName = "1", Message = "hello" } } };
            var msg = new Message() { Items = new List<Item>() { item1, item3, item1, item2 } };
            buffer.Write(msg);

            Console.WriteLine("Serializing Message with 2 x PlayerState, 1 x ChatMessage and PlayerSettings took " + buffer.Data.Length + " bytes");
            var output = buffer.ReadMessage();

            Assert.AreEqual(4, output.Items.Count);
        }
コード例 #2
0
        public void ServerCanSendMessageToAllExceptOneClient()
        {
            Message msg = new Message() { Items = { new Item() { Type = ItemType.SuccessfulJoin, Data = 666 } } };
            NetBuffer tmpBuffer = new NetBuffer();

            stubNetServer.Stub(x => x.CreateBuffer()).Return(tmpBuffer);

            serverMessageSender.SendToAllExcept(msg, NetChannel.Unreliable, stubNetConnection);

            stubNetServer.AssertWasCalled(x => x.SendToAll(Arg<NetBuffer>.Is.Equal(tmpBuffer),
                                                        Arg<NetChannel>.Is.Equal(NetChannel.Unreliable), Arg<INetConnection>.Is.Equal(stubNetConnection)));
            Assert.AreEqual(666, tmpBuffer.ReadMessage().Items[0].Data);
        }
コード例 #3
0
        public void ServerCanSendMessagesToAllClients()
        {
            Message msg = new Message() { Items = { new Item() { Type = ItemType.DisconnectingClient, Data = 999 } } };
            NetBuffer tmpBuffer = new NetBuffer();

            stubNetServer.Stub(x => x.CreateBuffer()).Return(tmpBuffer);

            serverMessageSender.SendToAll(msg, NetChannel.Unreliable);

            stubNetServer.AssertWasCalled(x => x.SendToAll(Arg<NetBuffer>.Is.Equal(tmpBuffer),
                                                        Arg<NetChannel>.Is.Equal(NetChannel.Unreliable)));
            Assert.AreEqual(999, tmpBuffer.ReadMessage().Items[0].Data);
        }
コード例 #4
0
        public void HandlesAllItemsOnTheMessage()
        {
            var msg = new Message() { Items = { new Item() { Type = ItemType.SuccessfulJoin, Data = 143 }, new Item() { Type = ItemType.NewClient, Data = 3 }, new Item() { Type = ItemType.Player, Data = new Frenetic.Player.PlayerState() } } };
            NetBuffer buffer = new NetBuffer();
            buffer.Write(msg);
            stubNetClient.Stub(me => me.CreateBuffer()).Return(buffer);
            stubNetClient.Stub(me => me.ReadMessage(Arg<NetBuffer>.Is.Equal(buffer), out Arg<NetMessageType>.Out(NetMessageType.Data).Dummy)).Return(true);
            clientNetworkSession.ClientJoined += delegate { };

            var unprocessedMsg = clientNetworkSession.ReadNextMessage();

            Assert.AreEqual(1, unprocessedMsg.Items.Count);
            Assert.AreEqual(ItemType.Player, unprocessedMsg.Items[0].Type);
        }
コード例 #5
0
        public void ServerCanSendMessageToAllExceptOneClient()
        {
            serverNetworkSession.ActiveConnections.Add(100, stubNetConnection);
            Message msg = new Message() { Items = { new Item() { Data = new byte[] { 1, 2, 3, 4 } } } };

            serverNetworkSession.SendToAllExcept(msg, NetChannel.Unreliable, 100);

            stubMessageSender.AssertWasCalled(me => me.SendToAllExcept(msg, NetChannel.Unreliable, stubNetConnection));
        }
コード例 #6
0
        public void ServerCanSendMessagesToAllClients()
        {
            Message msg = new Message() { Items = { new Item() { Data = new byte[] { 1, 2, 3, 4 } } } };

            serverNetworkSession.SendToAll(msg, NetChannel.Unreliable);

            stubMessageSender.AssertWasCalled(me => me.SendToAll(Arg<Message>.Is.Equal(msg), Arg<NetChannel>.Is.Equal(NetChannel.Unreliable)));
        }
コード例 #7
0
        public void SendIsForwardedCorrectly()
        {
            Message msg = new Message();

            serverNetworkSession.Send(msg, NetChannel.UnreliableInOrder11);

            stubMessageSender.AssertWasCalled(me => me.SendToAll(msg, NetChannel.UnreliableInOrder11));
        }
コード例 #8
0
        public void ClientProcessesAndSendsToServer()
        {
            NetBuffer tmpBuffer = new NetBuffer();
            Message msg = new Message() { Items = { new Item() { Type = ItemType.NewClient, Data = 10 } } };
            stubNetClient.Stub(x => x.CreateBuffer()).Return(tmpBuffer);
            stubNetClient.Stub(x => x.Status).Return(NetConnectionStatus.Connected);

            clientNetworkSession.Send(msg, NetChannel.ReliableUnordered);

            stubNetClient.AssertWasCalled(x => x.CreateBuffer());
            stubNetClient.AssertWasCalled(x => x.SendMessage(tmpBuffer, NetChannel.ReliableUnordered));
            Assert.AreEqual(10, tmpBuffer.ReadMessage().Items[0].Data);
        }