Exemplo n.º 1
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.º 2
0
        public void DestroyItem()
        {
            using (var client = new Client("Test"))
            {
                SpawnItem(client);
                client.SendOperation(Operations.DestroyItem("MyItem", byte.MaxValue));
                Func <EventData, bool> checkAction =
                    e => (string)e.Parameters[(byte)ParameterCode.ItemId] == "MyItem" && (byte)e.Parameters[(byte)ParameterCode.ItemType] == byte.MaxValue;
                client.BeginReceiveEvent(EventCode.ItemDestroyed, checkAction);

                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");
                client.EndReceiveEvent(Settings.WaitTime, out data);
            }
        }
Exemplo n.º 3
0
        private static void EndReceiveEvent(Client client, EventCode eventCode)
        {
            EventData data;

            Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTimeMultiOp, out data), "Event " + eventCode + " not received");
            Assert.AreEqual(eventCode, (EventCode)data.Code);
            Console.WriteLine("EndReceiveEvent " + client.Username + " " + eventCode + " " + Interlocked.Increment(ref counterEndReceiveEvent));
        }
Exemplo n.º 4
0
        /// <summary>
        /// The end receive event.
        /// </summary>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <param name="eventCode">
        /// The event EventCode.
        /// </param>
        /// <returns>
        /// the received event
        /// </returns>
        private static EventData EndReceiveEvent(Client client, EventCode eventCode)
        {
            EventData data;

            Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
            Assert.AreEqual(eventCode, (EventCode)data.Code);
            return(data);
        }
Exemplo n.º 5
0
        /// <summary>
        /// The exit world.
        /// </summary>
        /// <param name="client">
        /// The client.
        /// </param>
        private static void ExitWorld(Client client)
        {
            EventData data;

            client.SendOperation(Operations.ExitWorld());
            client.BeginReceiveEvent(EventCode.WorldExited, d => true);
            Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
            Assert.AreEqual(data.Code, (byte)EventCode.WorldExited);
        }
Exemplo n.º 6
0
        public void SubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);
                client.SendOperation(Operations.SubscribeItem(client.Username, (byte)ItemType.Avatar, null));
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d.Parameters[(byte)ParameterCode.ItemId] == client.Username);
                EventData data;
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemSubscribed);

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

                Func <EventData, bool> checkAction =
                    d =>
                    (string)d.Parameters[(byte)ParameterCode.ItemId] == client.Username && (byte)d.Parameters[(byte)ParameterCode.ItemType] == (byte)ItemType.Avatar;
                client.BeginReceiveEvent(EventCode.ItemMoved, checkAction);
                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");
            }
        }
Exemplo n.º 7
0
        public void RaiseGenericEvent()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

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

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

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

                // subscribe own avatar
                client.SendOperation(Operations.SubscribeItem(client.Username, (byte)ItemType.Avatar, null));
                client.SendOperation(Operations.RaiseGenericEvent(null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemSubscriber));
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction);
                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 - target avatar subscriber");
            }
        }
Exemplo n.º 8
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.º 9
0
 /// <summary>
 /// The end receive event.
 /// </summary>
 /// <param name="client">
 /// The client.
 /// </param>
 /// <param name="eventCode">
 /// The event EventCode.
 /// </param>
 /// <returns>
 /// the received event
 /// </returns>
 private static EventData EndReceiveEvent(Client client, EventCode eventCode)
 {
     EventData data;
     Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
     Assert.AreEqual(eventCode, (EventCode)data.Code);
     return data;
 }
Exemplo n.º 10
0
 /// <summary>
 /// The exit world.
 /// </summary>
 /// <param name="client">
 /// The client.
 /// </param>
 private static void ExitWorld(Client client)
 {
     EventData data;
     client.SendOperation(Operations.ExitWorld());
     client.BeginReceiveEvent(EventCode.WorldExited, d => true);
     Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received");
     Assert.AreEqual(data.Code, (byte)EventCode.WorldExited);
 }
Exemplo n.º 11
0
        public void UnsubscribeItem()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);
                client.SendOperation(Operations.SubscribeItem(client.Username, (byte)ItemType.Avatar, null));
                client.BeginReceiveEvent(EventCode.ItemSubscribed, d => (string)d.Parameters[(byte)ParameterCode.ItemId] == client.Username);
                EventData data;
                client.EndReceiveEvent(Settings.WaitTime, out data);
                Assert.AreEqual(data.Code, (byte)EventCode.ItemSubscribed);

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

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

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

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

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

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

                // subscribe own avatar
                client.SendOperation(Operations.SubscribeItem(client.Username, (byte)ItemType.Avatar, null));
                client.SendOperation(Operations.RaiseGenericEvent(null, null, byte.MaxValue, null, Reliability.Reliable, EventReceiver.ItemSubscriber));
                client.BeginReceiveEvent(EventCode.ItemGeneric, checkAction);
                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 - target avatar subscriber");
            }
        }
Exemplo n.º 13
0
        public void EnterWorld()
        {
            using (var client = new Client("Test"))
            {
                EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

                client.SendOperation(Operations.EnterWorld("TestWorld", client.Username, null, new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }));
                ReceiveOperationResponse(client, ReturnCode.InvalidOperation);

                using (var client2 = new Client("Test"))
                {
                    EnterWorld(client2, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null);

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

                    Assert.IsFalse(client.Peer.Connected);
                    //// client.SendOperation(Operations.Move(null, null, new[] { 2f, 2f }));
                    //// ReceiveOperationResponse(client, ReturnCode.InvalidOperation);
                }
            }
        }
Exemplo n.º 14
0
        public void DestroyItem()
        {
            using (var client = new Client("Test"))
            {
                SpawnItem(client);
                client.SendOperation(Operations.DestroyItem("MyItem", byte.MaxValue));
                Func<EventData, bool> checkAction =
                    e => (string)e.Parameters[(byte)ParameterCode.ItemId] == "MyItem" && (byte)e.Parameters[(byte)ParameterCode.ItemType] == byte.MaxValue;
                client.BeginReceiveEvent(EventCode.ItemDestroyed, checkAction);

                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");
                client.EndReceiveEvent(Settings.WaitTime, out data);
            }
        }
Exemplo n.º 15
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
            }
        }