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"); } }
private static void CreateWorld(World world, Client client) { Operations.CreateWorld(client, world.Name, world.Area, world.TileDimensions); client.BeginReceiveResponse(0); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTimeMultiOp, out data), "Response not received"); Assert.IsTrue(data.ReturnCode == (int)ReturnCode.Ok || data.ReturnCode == (int)ReturnCode.WorldAlreadyExists); }
private static void CreateWorld(string world, Client client) { Operations.CreateWorld(client, world, new BoundingBox(new Vector(0f, 0f), new Vector(10f, 10f)), new Vector(1f, 1f)); client.BeginReceiveResponse(0); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); Assert.IsTrue(data.ReturnCode == (int)ReturnCode.Ok || data.ReturnCode == (int)ReturnCode.WorldAlreadyExists); }
private static void EnterWorld( Client client, string worldName, Vector position, Vector viewDistanceEnter, Vector viewDistanceExit, Hashtable properties) { Operations.EnterWorld(client, worldName, client.Username, properties, position, viewDistanceEnter, viewDistanceExit); client.BeginReceiveResponse(0); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Event not received"); Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok); }
public void Move() { using (var client = new Client("Test")) { Assert.IsTrue(client.Connect()); CreateWorld("TestWorld", client); EnterWorld(client, "TestWorld", new Vector(1f, 1f), new Vector(1f, 1f), new Vector(2f, 2f), null); Operations.Move(client, null, new Vector(1f, 2f)); client.BeginReceiveResponse(0); OperationResponse data; Assert.IsFalse(client.EndReceiveResponse(Settings.WaitTime, out data), "Response received"); } }
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 DetachCamera() { using (var client = new Client("Test")) { Assert.IsTrue(client.Connect()); CreateWorld("TestWorld", client); EnterWorld(client, "TestWorld", new Vector(1f, 1f), new Vector(1f, 1f), new Vector(2f, 2f), 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); } }
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); } }
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"); } }
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), new Vector(10f, 10f)), new Vector(1f, 1f)); 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"); } }
public void AttachCamera() { using (var client = new Client("Test")) { Assert.IsTrue(client.Connect()); CreateWorld("TestWorld", client); EnterWorld(client, "TestWorld", new Vector(1f, 1f), new Vector(1f, 1f), new Vector(2f, 2f), 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 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"); } }
/////// <summary> /////// The receive operation response. /////// </summary> /////// <param name="client"> /////// The client. /////// </param> /////// <param name="operationCode"> /////// The operation code. /////// </param> /////// <returns> /////// the received response event /////// </returns> ////private static Hashtable ReceiveOperationResponse(Client client, OperationCode operationCode) ////{ //// Func<Hashtable, bool> checkAction = d => (byte)d.OperationCode == (byte)operationCode; //// client.BeginReceiveEvent(EventCode.OperationSuccess, checkAction, 10); //// Hashtable data; //// Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); //// var eventCode = (EventCode)(byte)data.Code; //// Assert.IsTrue(eventCode == EventCode.OperationSuccess || eventCode == EventCode.OperationError); //// Assert.AreEqual((OperationCode)(byte)data.OperationCode, operationCode); //// return data; ////} /////// <summary> /////// The receive operation success. /////// </summary> /////// <param name="client"> /////// The client. /////// </param> /////// <param name="operationCode"> /////// The operation code. /////// </param> ////private static void ReceiveOperationSuccess(Client client, OperationCode operationCode) ////{ //// Hashtable data = ReceiveOperationResponse(client, operationCode); //// Assert.AreEqual((EventCode)(byte)data.Code, EventCode.OperationSuccess); ////} /// <summary> /// The spawn item. /// </summary> /// <param name = "client"> /// The client. /// </param> private static void SpawnItem(Client client) { Operations.SpawnItem(client, "MyItem", byte.MaxValue, new[] { 1f, 1f }, 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[] { 1f, 1f }); } else { Assert.IsTrue(checkAction(data), "check action failed"); } }
private static void SpawnItem(Client client, ReturnCode result = ReturnCode.Ok) { Operations.SpawnItem(client, "MyItem", byte.MaxValue, new Vector(1f, 1f), null, true); Func <OperationResponse, bool> checkAction = e => (string)e[(byte)ParameterCode.ItemId] == "MyItem"; client.BeginReceiveResponse(0); OperationResponse data; // may exist if other client is online? Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); Assert.AreEqual(result, (ReturnCode)data.ReturnCode); if (data.ReturnCode != (int)ReturnCode.Ok) { Assert.AreEqual(ReturnCode.ItemAlreadyExists, (ReturnCode)data.ReturnCode); Operations.Move(client, "MyItem", new Vector(1f, 1f)); } else { Assert.IsTrue(checkAction(data), "check action failed"); } }
/////// <summary> /////// The receive operation response. /////// </summary> /////// <param name="client"> /////// The client. /////// </param> /////// <param name="operationCode"> /////// The operation code. /////// </param> /////// <returns> /////// the received response event /////// </returns> ////private static Hashtable ReceiveOperationResponse(Client client, OperationCode operationCode) ////{ //// Func<Hashtable, bool> checkAction = d => (byte)d.OperationCode == (byte)operationCode; //// client.BeginReceiveEvent(EventCode.OperationSuccess, checkAction, 10); //// Hashtable data; //// Assert.IsTrue(client.EndReceiveEvent(Settings.WaitTime, out data), "Event not received"); //// var eventCode = (EventCode)(byte)data.Code; //// Assert.IsTrue(eventCode == EventCode.OperationSuccess || eventCode == EventCode.OperationError); //// Assert.AreEqual((OperationCode)(byte)data.OperationCode, operationCode); //// return data; ////} /////// <summary> /////// The receive operation success. /////// </summary> /////// <param name="client"> /////// The client. /////// </param> /////// <param name="operationCode"> /////// The operation code. /////// </param> ////private static void ReceiveOperationSuccess(Client client, OperationCode operationCode) ////{ //// Hashtable data = ReceiveOperationResponse(client, operationCode); //// Assert.AreEqual((EventCode)(byte)data.Code, EventCode.OperationSuccess); ////} /// <summary> /// The spawn item. /// </summary> /// <param name = "client"> /// The client. /// </param> private static void SpawnItem(Client client) { Operations.SpawnItem(client, "MyItem", byte.MaxValue, new[] { 1f, 1f }, 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[] { 1f, 1f }); } else { Assert.IsTrue(checkAction(data), "check action failed"); } }
/// <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) { Operations.EnterWorld(client, worldName, client.Username, properties, position, viewDistanceEnter, viewDistanceExit); client.BeginReceiveResponse(0); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Event not received"); Assert.AreEqual(data.ReturnCode, (int)ReturnCode.Ok); }
/// <summary> /// The create world. /// </summary> /// <param name = "world"> /// The world. /// </param> /// <param name = "client"> /// The client. /// </param> private static void CreateWorld(string world, Client client) { Operations.CreateWorld(client, world, new[] { 0f, 0f }, new[] { 10f, 10f }, new[] { 1f, 1f }); client.BeginReceiveResponse(0); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); Assert.IsTrue(data.ReturnCode == (int)ReturnCode.Ok || data.ReturnCode == (int)ReturnCode.WorldAlreadyExists); }
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); } }
/// <summary> /// The enter world end. /// </summary> /// <param name = "client"> /// The client. /// </param> private static void EnterWorldEnd(Client client) { OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data)); }
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"); } }
private static void SpawnItem(Client client, ReturnCode result = ReturnCode.Ok) { Operations.SpawnItem(client, "MyItem", byte.MaxValue, new Vector(1f, 1f, 0f), null, true); Func<OperationResponse, bool> checkAction = e => (string)e[(byte)ParameterCode.ItemId] == "MyItem"; client.BeginReceiveResponse(0); OperationResponse data; // may exist if other client is online? Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); Assert.AreEqual(result, (ReturnCode)data.ReturnCode); if (data.ReturnCode != (int)ReturnCode.Ok) { Assert.AreEqual(ReturnCode.ItemAlreadyExists, (ReturnCode)data.ReturnCode); Operations.Move(client, "MyItem", new Vector(1f, 1f, 0f)); } else { Assert.IsTrue(checkAction(data), "check action failed"); } }
private static void EnterWorldEnd(Client client) { OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTimeMultiOp, out data)); }
/// <summary> /// The create world. /// </summary> /// <param name = "world"> /// The world. /// </param> /// <param name = "client"> /// The client. /// </param> private static void CreateWorld(MmoWorld world, Client client) { Operations.CreateWorld(client, world.Name, world.Area.Min.ToFloatArray(2), world.Area.Max.ToFloatArray(2), world.TileDimensions.ToFloatArray(2)); client.BeginReceiveResponse(0); OperationResponse data; Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTime, out data), "Response not received"); Assert.IsTrue(data.ReturnCode == (int)ReturnCode.Ok || data.ReturnCode == (int)ReturnCode.WorldAlreadyExists); }