/// <summary> /// The enter world. /// </summary> /// <param name="client"> /// The client. /// </param> /// <param name="worldName"> /// The world name. /// </param> /// <param name="position"> /// The position. /// </param> /// <param name="viewDistanceEnter"> /// The view Distance Enter. /// </param> /// <param name="viewDistanceExit"> /// The view Distance Exit. /// </param> /// <param name="properties"> /// The properties. /// </param> private static void EnterWorld( Client client, string worldName, float[] position, float[] viewDistanceEnter, float[] viewDistanceExit, Hashtable properties) { client.SendOperation(Operations.EnterWorld(worldName, client.Username, properties, position, viewDistanceEnter, viewDistanceExit)); ReceiveOperationResponse(client, ReturnCode.Ok); }
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 } }
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 }
/// <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); }
/// <summary> /// The spawn item. /// </summary> /// <param name="client"> /// The client. /// </param> private static void SpawnItem(Client client) { EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null); client.SendOperation(Operations.SpawnItem("MyItem", byte.MaxValue, new[] { 1f, 1f }, null, true)); OperationResponse data = ReceiveOperationResponse(client); Assert.AreEqual("MyItem", data.Parameters[(byte)ParameterCode.ItemId]); Assert.AreEqual(byte.MaxValue, data.Parameters[(byte)ParameterCode.ItemType]); if (data.ReturnCode != (int)ReturnCode.Ok) { // move item to view area client.SendOperation(Operations.Move("MyItem", byte.MaxValue, new[] { 1f, 1f })); ReceiveOperationResponse(client, ReturnCode.Ok); } }
private static void MoveAction(Client client, int number) { if (number < 5) { Vector pos = client.Position; client.SendOperation(Operations.Move(null, pos)); client.Peer.RequestFiber.Schedule(() => MoveAction(client, number + 1), 100); } }
/// <summary> /// The exit world begin. /// </summary> /// <param name="client"> /// The client. /// </param> private static void ExitWorldBegin(Client client) { ThreadPoolEnqueue( client, () => { client.SendOperation(Operations.ExitWorld()); BeginReceiveEvent(client, EventCode.WorldExited); }); }
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); } }
public void SetViewDistance() { using (var client = new Client("Test")) { EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null); client.SendOperation(Operations.SetViewDistance(new[] { 2f, 2f }, new[] { 3f, 3f })); NotReceiveOperationResponse(client); } }
/// <summary> /// The move action. /// </summary> /// <param name="client"> /// The client. /// </param> /// <param name="number"> /// The number. /// </param> private static void MoveAction(Client client, int number) { float[] pos = client.Position; client.SendOperation(Operations.Move(null, null, pos)); number++; if (number < 6) { client.Peer.RequestFiber.Schedule(() => MoveAction(client, number), 100); } }
public void ExitWorld() { using (var client = new Client("Test")) { client.SendOperation(Operations.ExitWorld()); ReceiveOperationResponse(client, ReturnCode.InvalidOperation); EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null); ExitWorld(client); } }
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 }
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 } }
private static void ExitWorldBegin(Client client) { ThreadPoolEnqueue( client, () => { client.SendOperation(Operations.ExitWorld()); Console.WriteLine("ExitWorldBegin " + client.Username + " " + Interlocked.Increment(ref counterExitWorldBegin)); BeginReceiveEvent(client, EventCode.WorldExited); }); }
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); } }
public void SetProperties() { using (var client = new Client("Test")) { EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null); client.SendOperation(Operations.SetProperties(null, null, new Hashtable { { "Key", "Value" } }, null)); NotReceiveOperationResponse(client); } }
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 } }
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"); } }
public void DetachCamera() { using (var client = new Client("Test")) { EnterWorld(client, "TestWorld", new[] { 1f, 1f }, new[] { 1f, 1f }, new[] { 2f, 2f }, null); client.SendOperation(Operations.DetachCamera()); client.BeginReceiveResponse(); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok); } }
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"); } }
private static void EnterWorldBegin(Client client, World world, Vector position) { var viewDistanceEnter = new Vector(1f, 1f); var viewDistanceExit = new Vector(2f, 2f); client.Position = position; ThreadPoolEnqueue( client, () => { client.SendOperation(Operations.EnterWorld(world.Name, client.Username, null, position, viewDistanceEnter, viewDistanceExit)); client.BeginReceiveResponse(); }); }
public void AttachCamera() { using (var client = new Client("Test")) { SpawnItem(client); client.SendOperation(Operations.AttachCamera("MyItem", byte.MaxValue)); client.BeginReceiveResponse(); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Event not received"); Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok); Func <OperationResponse, bool> checkAction = e => (string)e.Parameters[(byte)ParameterCode.ItemId] == "MyItem" && (byte)e.Parameters[(byte)ParameterCode.ItemType] == byte.MaxValue; Assert.IsTrue(checkAction(data), "check action failed"); } }
public void AttachCamera() { using (var client = new Client("Test")) { SpawnItem(client); client.SendOperation(Operations.AttachCamera("MyItem", byte.MaxValue)); client.BeginReceiveResponse(); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Event not received"); Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok); Func<OperationResponse, bool> checkAction = e => (string)e.Parameters[(byte)ParameterCode.ItemId] == "MyItem" && (byte)e.Parameters[(byte)ParameterCode.ItemType] == byte.MaxValue; Assert.IsTrue(checkAction(data), "check action failed"); } }
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); } }
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); } } }
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"); } }
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"); } }
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 } }
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 } }
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); } } }
/// <summary> /// The enter world. /// </summary> /// <param name="client"> /// The client. /// </param> /// <param name="world"> /// The world. /// </param> /// <param name="position"> /// The position. /// </param> private static void EnterWorldBegin(Client client, MmoWorld world, float[] position) { var viewDistanceEnter = new[] { 1f, 1f }; var viewDistanceExit = new[] { 2f, 2f }; client.Position = position; ThreadPoolEnqueue( client, () => { client.SendOperation(Operations.EnterWorld(world.Name, client.Username, null, position, viewDistanceEnter, viewDistanceExit)); client.BeginReceiveResponse(); }); }
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); } }