Exemplo n.º 1
0
        private static void EnterWorld(
            Client client, string worldName, Vector position, Vector viewDistanceEnter, Vector viewDistanceExit, Hashtable properties)

        {
            client.ResetEvent();
            client.SendOperation(Operations.EnterWorld(worldName, client.Username, properties, position, viewDistanceEnter, viewDistanceExit));
            ReceiveOperationResponse(client, ReturnCode.Ok); // blocking
        }
Exemplo n.º 2
0
        public void SubscribeUnsubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                var myItemId = "MyItem";

                // spawn item out of interest area
                client.ResetEvent();
                client.SendOperation(Operations.SpawnItem(myItemId, ItemType.Bot, new Vector(3f, 3f, 0f), null, true));
                OperationResponse spawnData = ReceiveOperationResponse(client); // blocking
                Assert.AreEqual(spawnData.ReturnCode, (int)ReturnCode.Ok, "SpawnItem op error:" + spawnData.ReturnCode + " " + spawnData.DebugMessage);

                Console.WriteLine("Subscribing...");
                client.ResetEvent();
                client.SendOperation(Operations.SubscribeItem(myItemId, null));
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d.Parameters[(byte)ParameterCode.ItemId] == myItemId);
                EventData data;
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); // blocking

                Console.WriteLine("Unsubscribing...");

                client.ResetEvent();
                client.SendOperation(Operations.Move(myItemId, new Vector(3f, 3.3f, 0f)));
                Func <EventData, bool> checkMoveAction = d => (string)d.Parameters[(byte)ParameterCode.ItemId] == myItemId;
                client.BeginReceiveEvent(EventCode.ItemMoved, checkMoveAction);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");// blocking

                Assert.AreEqual(data.Code, (byte)EventCode.ItemMoved);
                Assert.IsTrue(checkMoveAction(data), "check action failed");

                // unsubscribe test
                client.ResetEvent();
                client.SendOperation(Operations.UnsubscribeItem(myItemId));
                client.BeginReceiveEvent(EventCode.ItemUnsubscribed, d => (string)d.Parameters[(byte)ParameterCode.ItemId] == myItemId);
                client.EndReceiveEvent(Settings.WaitTime, out data); // blocking
                Assert.AreEqual(data.Code, (byte)EventCode.ItemUnsubscribed);

                // check if unsubscription worked
                client.ResetEvent();
                client.SendOperation(Operations.Move(null, new Vector(1f, 2f, 0f)));
                client.BeginReceiveEvent(EventCode.ItemMoved, checkMoveAction);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received"); // blocking
            }
        }
Exemplo n.º 3
0
        public void CreateWorld()
        {
            using (var client = new Client("Test"))
            {
                client.ResetEvent();
                client.SendOperation(Operations.CreateWorld("CreateWorld", new BoundingBox(new Vector(0f, 0f, 0f), new Vector(10f, 10f, 0f)), new Vector(1f, 1f, 0f)));
                client.BeginReceiveResponse();
                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); // blocking
                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok);

                // "Test" defined in setup
                client.ResetEvent();
                client.SendOperation(Operations.CreateWorld("TestWorld", new BoundingBox(new Vector(0f, 0f, 0f), new Vector(10f, 10f, 0f)), new Vector(1f, 1f, 0f)));
                client.BeginReceiveResponse();
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); // blocking
                Assert.AreEqual(data.ReturnCode, (byte)ReturnCode.WorldAlreadyExists);
            }
        }
Exemplo n.º 4
0
        private static void ExitWorld(Client client)
        {
            EventData data;

            client.ResetEvent();
            client.SendOperation(Operations.ExitWorld());
            client.BeginReceiveEvent(EventCode.WorldExited, d => true);                               // blocking
            Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); // blocking
            Assert.AreEqual(data.Code, (byte)EventCode.WorldExited);
        }
Exemplo n.º 5
0
        public void CreateWorld()
        {
            using (var client = new Client("Test"))
            {
                client.ResetEvent();
                client.SendOperation(Operations.CreateWorld("CreateWorld", new BoundingBox(new Vector(0f, 0f, 0f), new Vector(10f, 10f, 0f)), new Vector(1f, 1f, 0f)));
                client.BeginReceiveResponse();
                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); // blocking
                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok);

                // "Test" defined in setup
                client.ResetEvent();
                client.SendOperation(Operations.CreateWorld("TestWorld", new BoundingBox(new Vector(0f, 0f, 0f), new Vector(10f, 10f, 0f)), new Vector(1f, 1f, 0f)));
                client.BeginReceiveResponse();
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); // blocking
                Assert.AreEqual(data.ReturnCode, (byte)ReturnCode.WorldAlreadyExists);
            }
        }
Exemplo n.º 6
0
        public void SetViewDistance()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                client.ResetEvent();
                client.SendOperation(Operations.SetViewDistance(new Vector(2f, 2f, 0f), new Vector(3f, 3f, 0f)));
                NotReceiveOperationResponse(client); // blocking
            }
        }
Exemplo n.º 7
0
        private static void SpawnItem(Client client)
        {
            EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

            client.ResetEvent();
            client.SendOperation(Operations.SpawnItem("MyItem", ItemType.Bot, new Vector(1f, 1f, 0f), null, true));
            OperationResponse data = ReceiveOperationResponse(client); // blocking

            Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok, "SpawnItem op error:" + data.ReturnCode + " " + data.DebugMessage);

            // move item to view area
            client.ResetEvent();
            client.SendOperation(Operations.Move("MyItem", new Vector(1f, 1f, 0f)));
            NotReceiveOperationResponse(client); // blocking

            // test not existing item move
            client.ResetEvent();
            client.SendOperation(Operations.Move("NotExistsing", new Vector(1f, 1f, 0f)));
            ReceiveOperationResponse(client, ReturnCode.ItemNotFound); // blocking
        }
Exemplo n.º 8
0
        public void ExitWorld()
        {
            using (var client = new Client("Test"))
            {
                client.ResetEvent();
                client.SendOperation(Operations.ExitWorld());
                ReceiveOperationResponse(client, ReturnCode.InvalidOperation); // blocking

                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);
                ExitWorld(client);
            }
        }
Exemplo n.º 9
0
        public void SetProperties()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                client.ResetEvent();
                client.SendOperation(Operations.SetProperties(null, new Hashtable {
                    { "Key", "Value" }
                }, null));
                NotReceiveOperationResponse(client);// blocking
            }
        }
Exemplo n.º 10
0
        public void EnterWorld()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                client.ResetEvent();
                client.SendOperation(Operations.EnterWorld("TestWorld", client.Username, null, new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f)));
                ReceiveOperationResponse(client, ReturnCode.InvalidOperation); // blocking

                using (var client2 = new Client("Test"))
                {
                    EnterWorld(client2, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                    EventData @event;
                    client.ResetEvent();
                    client.BeginReceiveEvent(EventCode.WorldExited, d => true);
                    Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out @event), "Event not received"); // blocking
                    Assert.AreEqual((byte)EventCode.WorldExited, @event.Code);

                    Assert.IsFalse(client.Peer.Connected);
                }
            }
        }
Exemplo n.º 11
0
        public void DetachCamera()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                client.ResetEvent();
                client.SendOperation(Operations.DetachCamera());
                client.BeginReceiveResponse();

                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); // blocking
                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok);
            }
        }
Exemplo n.º 12
0
        private static List <Client> SetupClients(World world)
        {
            Stopwatch t = Stopwatch.StartNew();

            var clients = new List <Client>();

            for (int xx = 0; xx < world.TileX; xx++)
            {
                for (int yy = 0; yy < world.TileY; yy++)
                {
                    for (var i = 0; i < 2; i++)
                    {
                        // 2 clients in single tile offset by x?
                        int    x      = (int)(world.Area.Min.X + world.TileDimensions.X * xx + world.TileDimensions.X * (i + 1) / 3);
                        int    y      = (int)(world.Area.Min.Y + world.TileDimensions.Y * yy + world.TileDimensions.Y / 2);
                        string name   = string.Format("MyUsername{0}/{1}", x, y);
                        var    client = new Client(name);

                        client.ResetEvent();
                        EnterWorldBegin(client, world, new Vector(x / 100f, y / 100f));
                        // ...

                        clients.Add(client);
                        clientCount++;
                        Console.WriteLine(string.Format("Client {0} added, total: {1}", name, clientCount));
                    }
                }
            }

            // ...
            clients.ForEach(EnterWorldEnd); // blocking

            clients.ForEach(ResetEvent);
            clients.ForEach(c => BeginReceiveEvent(c, EventCode.ItemSubscribed, d => true));
            clients.ForEach(c => EndReceiveEvent(c, EventCode.ItemSubscribed));// blocking

            PrintStats(t);

            Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at start");
            log.Info("enter completed");

            Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");

            return(clients);
        }
Exemplo n.º 13
0
        public void AttachCamera()
        {
            using (var client = new Client("Test"))
            {
                SpawnItem(client);

                client.ResetEvent();
                client.SendOperation(Operations.AttachCamera("MyItem"));
                client.BeginReceiveResponse();
                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Event not received"); // blocking

                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok);
                Func<OperationResponse, bool> checkAction =
                    e => (string)e.Parameters[(byte)ParameterCode.ItemId] == "MyItem";
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
Exemplo n.º 14
0
        public void DestroyItem()
        {
            using (var client = new Client("Test"))
            {
                SpawnItem(client);

                client.ResetEvent();
                client.SendOperation(Operations.DestroyItem("MyItem"));
                Func <EventData, bool> checkAction =
                    e => (string)e.Parameters[(byte)ParameterCode.ItemId] == "MyItem";
                client.BeginReceiveEvent(EventCode.ItemDestroyed, checkAction);
                EventData data;
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); // blocking

                Assert.AreEqual(data.Code, (byte)EventCode.ItemDestroyed);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
Exemplo n.º 15
0
        public void AttachCamera()
        {
            using (var client = new Client("Test"))
            {
                SpawnItem(client);

                client.ResetEvent();
                client.SendOperation(Operations.AttachCamera("MyItem"));
                client.BeginReceiveResponse();
                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Event not received"); // blocking

                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok);
                Func <OperationResponse, bool> checkAction =
                    e => (string)e.Parameters[(byte)ParameterCode.ItemId] == "MyItem";
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
Exemplo n.º 16
0
        public void DetachCamera()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                client.ResetEvent();
                client.SendOperation(Operations.DetachCamera());
                client.BeginReceiveResponse();

                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); // blocking
                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok);
            }
        }
Exemplo n.º 17
0
        public void ExitWorld()
        {
            using (var client = new Client("Test"))
            {
                client.ResetEvent();
                client.SendOperation(Operations.ExitWorld());
                ReceiveOperationResponse(client, ReturnCode.InvalidOperation); // blocking

                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);
                ExitWorld(client);
            }
        }
Exemplo n.º 18
0
        public void SetViewDistance()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector( 1f, 1f, 0f), new Vector( 1f, 1f, 0f), new Vector( 2f, 2f, 0f), null);

                client.ResetEvent();
                client.SendOperation(Operations.SetViewDistance(new Vector(2f, 2f, 0f), new Vector( 3f, 3f, 0f)));
                NotReceiveOperationResponse(client); // blocking
            }
        }
Exemplo n.º 19
0
        public void SetProperties()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                client.ResetEvent();
                client.SendOperation(Operations.SetProperties(null, new Hashtable { { "Key", "Value" } }, null));
                NotReceiveOperationResponse(client);// blocking
            }
        }
Exemplo n.º 20
0
 private static void EnterWorld(
     Client client, string worldName, Vector position, Vector viewDistanceEnter, Vector viewDistanceExit, Hashtable properties)
 {
     client.ResetEvent();
     client.SendOperation(Operations.EnterWorld(worldName, client.Username, properties, position, viewDistanceEnter, viewDistanceExit));
     ReceiveOperationResponse(client, ReturnCode.Ok); // blocking
 }
Exemplo n.º 21
0
        public void SubscribeUnsubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                var myItemId = "MyItem";

                // spawn item out of interest area
                client.ResetEvent();
                client.SendOperation(Operations.SpawnItem(myItemId, ItemType.Bot, new Vector(3f, 3f, 0f), null, true));
                OperationResponse spawnData = ReceiveOperationResponse(client); // blocking
                Assert.AreEqual(spawnData.ReturnCode, (int)ReturnCode.Ok, "SpawnItem op error:" + spawnData.ReturnCode + " " + spawnData.DebugMessage);

                Console.WriteLine("Subscribing...");
                client.ResetEvent();
                client.SendOperation(Operations.SubscribeItem(myItemId, null));
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d.Parameters[(byte)ParameterCode.ItemId] == myItemId);
                EventData data;
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); // blocking

                Console.WriteLine("Unsubscribing...");

                client.ResetEvent();
                client.SendOperation(Operations.Move(myItemId, new Vector(3f, 3.3f, 0f)));
                Func<EventData, bool> checkMoveAction = d => (string)d.Parameters[(byte)ParameterCode.ItemId] == myItemId;
                client.BeginReceiveEvent(EventCode.ItemMoved, checkMoveAction);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");// blocking

                Assert.AreEqual(data.Code, (byte)EventCode.ItemMoved);
                Assert.IsTrue(checkMoveAction(data), "check action failed");

                // unsubscribe test
                client.ResetEvent();
                client.SendOperation(Operations.UnsubscribeItem(myItemId));
                client.BeginReceiveEvent(EventCode.ItemUnsubscribed, d => (string)d.Parameters[(byte)ParameterCode.ItemId] == myItemId);
                client.EndReceiveEvent(Settings.WaitTime, out data); // blocking
                Assert.AreEqual(data.Code, (byte)EventCode.ItemUnsubscribed);

                // check if unsubscription worked
                client.ResetEvent();
                client.SendOperation(Operations.Move(null, new Vector(1f, 2f, 0f)));
                client.BeginReceiveEvent(EventCode.ItemMoved, checkMoveAction);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received"); // blocking
            }
        }
Exemplo n.º 22
0
 private static void ExitWorld(Client client)
 {
     EventData data;
     client.ResetEvent();
     client.SendOperation(Operations.ExitWorld());
     client.BeginReceiveEvent(EventCode.WorldExited, d => true);// blocking
     Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); // blocking
     Assert.AreEqual(data.Code, (byte)EventCode.WorldExited);
 }
Exemplo n.º 23
0
        private static void SpawnItem(Client client)
        {
            EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

            client.ResetEvent();
            client.SendOperation(Operations.SpawnItem("MyItem", ItemType.Bot, new Vector(1f, 1f, 0f), null, true));
            OperationResponse data = ReceiveOperationResponse(client); // blocking

            Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok, "SpawnItem op error:" + data.ReturnCode + " " + data.DebugMessage);

            // move item to view area
            client.ResetEvent();
            client.SendOperation(Operations.Move("MyItem", new Vector(1f, 1f, 0f)));
            NotReceiveOperationResponse(client); // blocking

            // test not existing item move
            client.ResetEvent();
            client.SendOperation(Operations.Move("NotExistsing", new Vector(1f, 1f, 0f)));
            ReceiveOperationResponse(client, ReturnCode.ItemNotFound); // blocking
        }
Exemplo n.º 24
0
        public void DestroyItem()
        {
            using (var client = new Client("Test"))
            {
                SpawnItem(client);

                client.ResetEvent();
                client.SendOperation(Operations.DestroyItem("MyItem"));
                Func<EventData, bool> checkAction =
                    e => (string)e.Parameters[(byte)ParameterCode.ItemId] == "MyItem";
                client.BeginReceiveEvent(EventCode.ItemDestroyed, checkAction);
                EventData data;
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); // blocking

                Assert.AreEqual(data.Code, (byte)EventCode.ItemDestroyed);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
Exemplo n.º 25
0
 private static void ResetEvent(Client client)
 {
     client.ResetEvent();
 }
Exemplo n.º 26
0
        public void EnterWorld()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                client.ResetEvent();
                client.SendOperation(Operations.EnterWorld("TestWorld", client.Username, null, new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f)));
                ReceiveOperationResponse(client, ReturnCode.InvalidOperation); // blocking

                using (var client2 = new Client("Test"))
                {
                    EnterWorld(client2, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                    EventData @event;
                    client.ResetEvent();
                    client.BeginReceiveEvent(EventCode.WorldExited, d => true);
                    Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out @event), "Event not received"); // blocking
                    Assert.AreEqual((byte)EventCode.WorldExited, @event.Code);

                    Assert.IsFalse(client.Peer.Connected);
                }
            }
        }