예제 #1
0
        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");
            }
        }
예제 #2
0
파일: HeavyLoad.cs 프로젝트: geosohal/Mmo
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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");
            }
        }
예제 #6
0
        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");
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
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");
            }
        }
예제 #10
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), 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");
            }
        }
예제 #11
0
        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");
            }
        }
예제 #12
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");
            }
        }
예제 #13
0
        /////// <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");
            }
        }
예제 #14
0
        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");
            }
        }
예제 #15
0
        /////// <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");
            }
        }
예제 #16
0
        /// <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);
        }
예제 #17
0
        /// <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);
        }
예제 #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);
            }
        }
예제 #19
0
        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");
            }
        }
예제 #20
0
        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);
            }
        }
예제 #21
0
 /// <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));
 }
예제 #22
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");
            }
        }
예제 #23
0
        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");
            }
        }
예제 #24
0
파일: HeavyLoad.cs 프로젝트: geosohal/Mmo
        private static void EnterWorldEnd(Client client)
        {
            OperationResponse data;

            Assert.IsTrue(client.EndReceiveResponse(Settings.WaitTimeMultiOp, out data));
        }
예제 #25
0
        /// <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);
        }