public void AttachCamera()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                Operations.SpawnItem(client, "MyItem", byte.MaxValue, new[] { 10f, 10f }, null, true);
                Func<OperationResponse, bool> checkAction =
                    e => (string)e[(byte)ParameterCode.ItemId] == "MyItem" && (byte)e[(byte)ParameterCode.ItemType] == byte.MaxValue;
                client.BeginReceiveResponse(0);

                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received");
                if (data.ReturnCode != (int)ReturnCode.Ok)
                {
                    Assert.AreEqual(ReturnCode.ItemAlreadyExists, (ReturnCode)data.ReturnCode);
                    Operations.Move(client, "MyItem", byte.MaxValue, new[] { 10f, 10f });
                }
                else
                {
                    Assert.IsTrue(checkAction(data), "check action failed");
                }

                Operations.AttachCamera(client, "MyItem", byte.MaxValue);
                client.BeginReceiveResponse(0);

                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received");
                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
 public void Connect()
 {
     using (var client = new Client("Test"))
     {
         Assert.IsTrue(client.Connect());
         Thread.Sleep(1000);
         Assert.IsTrue(client.Disconnect());
     }
 }
示例#3
0
        public void Run()
        {
            MmoWorldCache.Instance.Clear();
            MmoWorld world;
            MmoWorldCache.Instance.TryCreate(
                "HeavyLoad2", (new[] { 0f, 0f }).ToVector(), (new[] { 99f, 99f }).ToVector(), (new[] { 10f, 10f }).ToVector(), out world);

            using (var client = new Client(string.Empty))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld(world, client);
            }

            Stopwatch t = Stopwatch.StartNew();

            var clients = new List<Client>();
            try
            {
                SetupClients(world, clients, t);

                Client.ResetStats();
                log.Info("ItemPositionUpdate wait completed");
                Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");

                t = Stopwatch.StartNew();
                MoveClients(clients);
                PrintStats(t);
                MoveClients(clients);
                PrintStats(t);
                MoveClients(clients);
                PrintStats(t);
                MoveClients(clients);
                PrintStats(t);
                MoveClients(clients);
                PrintStats(t);
                Client.ResetStats();
                log.Info("move completed");
                Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");

                DisconnectClients(clients);
            }
            finally
            {
                clients.ForEach(c => c.Dispose());
            }
        }
示例#4
0
        public void CreateWorld()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("CreateWorld", client);

                // "Test" defined in setup
                Operations.CreateWorld(client, "CreateWorld", new BoundingBox(new Vector(0f, 0f, 0f), new Vector(10f, 10f, 0f)), new Vector(1f, 1f, 0f));

                Func<OperationResponse, bool> checkAction = d => d.OperationCode == (byte)OperationCode.CreateWorld;
                client.BeginReceiveResponse(10);

                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received");
                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.WorldAlreadyExists);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
示例#5
0
        public void AttachCamera()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                SpawnItem(client);

                Func<OperationResponse, bool> checkAction =
                    e => (string)e[(byte)ParameterCode.ItemId] == "MyItem";
                OperationResponse data;
                Operations.AttachCamera(client, "MyItem");
                client.BeginReceiveResponse(0);

                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received");
                Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
        public void UnsubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                Operations.SubscribeItem(client, client.Username, (byte)ItemType.Avatar, null);
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d[(byte)ParameterCode.ItemId] == client.Username, 0);
                EventData data;
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemSubscribed);

                Operations.UnsubscribeItem(client, client.Username, (byte)ItemType.Avatar);
                client.BeginReceiveEvent(EventCode.ItemUnsubscribed, d => (string)d[(byte)ParameterCode.ItemId] == client.Username, 0);
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemUnsubscribed);

                // check if subscription worked
                Operations.Move(client, null, null, new[] { 1f, 2f });

                Func<EventData, bool> checkAction = d => true;
                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction, 0);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received");
            }
        }
 public void SpawnItem()
 {
     using (var client = new Client("Test"))
     {
         Assert.IsTrue(client.Connect());
         CreateWorld("TestWorld", client);
         EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);
         SpawnItem(client);
     }
 }
        public void SetViewDistance()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                Operations.SetViewDistance(client, new[] { 2f, 2f }, new[] { 3f, 3f });

                client.BeginReceiveResponse(0);
                OperationResponse data;
                Assert.IsFalse(client.EndReceiveResponse(Settings.WaitTime, out data), "Response received");
            }
        }
        public void SetProperties()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                Operations.SetProperties(client, null, null, new Hashtable { { "Key", "Value" } }, null);

                client.BeginReceiveResponse(0);
                EventData data;
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Response received");
            }
        }
        public void RaiseGenericEvent()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                ////Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.WorldRegion);
                Func<EventData, bool> checkAction =
                    d =>
                    (string)d[(byte)ParameterCode.ItemId] == client.Username && (byte)d[(byte)ParameterCode.ItemType] == (byte)ItemType.Avatar &&
                    (byte)d[(byte)ParameterCode.CustomEventCode] == byte.MaxValue;

                ////client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                EventData data;

                ////Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar world region");
                ////Assert.AreEqual((byte)data.Code, (byte)EventCode.ItemGeneric);
                ////Assert.IsTrue(checkAction(data), "check action failed");
                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemOwner);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar owner");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemGeneric);
                Assert.IsTrue(checkAction(data), "check action failed");

                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemSubscriber);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received - avator should not be subscribed");

                // subscribe avatar
                Operations.SubscribeItem(client, client.Username, (byte)ItemType.Avatar, null);
                Operations.RaiseGenericEvent(client, null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemSubscriber);
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received - target avatar subscriber");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemGeneric);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
        public void ExitWorld()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                Operations.ExitWorld(client);

                client.BeginReceiveResponse(0);

                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received");
                Assert.AreEqual(data.ReturnCode, (byte)ReturnCode.InvalidOperation);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);
                ExitWorld(client);
            }
        }
示例#12
0
 public void EnterWorld()
 {
     using (var client = new Client("Test"))
     {
         Assert.IsTrue(client.Connect());
         CreateWorld("TestWorld", client);
         EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);
     }
 }
示例#13
0
        public void RunForTime()
        {
            WorldCache.Instance.Clear();
            World world;
            WorldCache.Instance.TryCreate(
                "HeavyLoad3", new BoundingBox(new Vector(0f, 0f), new Vector(100f, 100f)), new Vector(20f, 20f, 0f), out world);

            using (var client = new Client(string.Empty))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld(world, client);
            }

            Stopwatch t = Stopwatch.StartNew();

            var clients = new List<Client>();
            try
            {
                SetupClients(world, clients, t);

                Client.ResetStats();
                t = Stopwatch.StartNew();
                while (t.ElapsedMilliseconds < 10000)
                {
                    MoveClients(clients);
                    PrintStats(t);
                    Client.ResetStats();
                }

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

                DisconnectClients(clients);
            }
            finally
            {
                clients.ForEach(c => c.Dispose());
            }
        }
示例#14
0
        public void SubscribeUnsubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                var myItemId = "MyItem";

                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                SpawnItem(client);

                // subscribing...
                Operations.SubscribeItem(client, myItemId, null);
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d[(byte)ParameterCode.ItemId] == myItemId, 0);
                EventData data;
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemSubscribed);

                // check if subscription works
                Operations.Move(client, myItemId, new Vector(3f, 3.3f, 0f));

                Func<EventData, bool> checkAction =
                    d => (string)d[(byte)ParameterCode.ItemId] == myItemId;
                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction, 0);
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemMoved);
                Assert.IsTrue(checkAction(data), "check action failed");

                // unsubscribing...
                Operations.UnsubscribeItem(client, myItemId);
                client.BeginReceiveEvent(EventCode.ItemUnsubscribed, d => (string)d[(byte)ParameterCode.ItemId] == myItemId, 0);
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemUnsubscribed);

                // check if unsubscription works
                Operations.Move(client, null, new Vector(1f, 2f, 0f));

                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction, 0);
                Assert.IsFalse(client.EndReceiveEvent(Settings.WaitTime, out data), "Event received");
            }
        }
示例#15
0
 public void SpawnItem()
 {
     using (var client = new Client("Test"))
     {
         Assert.IsTrue(client.Connect());
         CreateWorld("TestWorld", client);
         EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);
         SpawnItem(client);
         // check error on existing
         SpawnItem(client, ReturnCode.ItemAlreadyExists);
     }
 }
示例#16
0
        public void Move()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);
                Operations.Move(client, null, new Vector(1f, 2f, 0f));

                client.BeginReceiveResponse(0);
                OperationResponse data;
                Assert.IsFalse(client.EndReceiveResponse(Settings.WaitTime, out data), "Response received");
            }
        }
        public void DestroyItem()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);
                SpawnItem(client);
                Operations.DestroyItem(client, "MyItem", byte.MaxValue);

                Func<EventData, bool> checkAction =
                    d => (string)d.Parameters[(byte)ParameterCode.ItemId] == "MyItem" && (byte)d[(byte)ParameterCode.ItemType] == byte.MaxValue;
                client.BeginReceiveEvent(EventCode.ItemDestroyed, checkAction, 10);
                EventData data;
                Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
                Assert.AreEqual(data.Code, (byte)EventCode.ItemDestroyed);
                Assert.IsTrue(checkAction(data), "check action failed");
            }
        }
示例#18
0
        public void DetachCamera()
        {
            using (var client = new Client("Test"))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld("TestWorld", client);
                EnterWorld(client, "TestWorld", new Vector(1f, 1f, 0f), new Vector(1f, 1f, 0f), new Vector(2f, 2f, 0f), null);

                Operations.DetachCamera(client);
                client.BeginReceiveResponse(0);

                OperationResponse data;
                Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received");
                Assert.AreEqual(data.ReturnCode, (byte)ReturnCode.Ok);
            }
        }