예제 #1
0
        public void TestHasComponentSerialization()
        {
            // Arrange
            HasComponents unitUnderTest = this.CreateHasComponents();

            // Act
            byte[] data = ProtoUtil.Serialize(unitUnderTest);

            Assert.IsNotNull(data, "Serialization failed");

            HasComponents deserialized = ProtoUtil.Deserialize <HasComponents>(data);

            // Assert
            Assert.IsNotNull(deserialized, "Deserialization failed");

            Assert.IsTrue(unitUnderTest.HasComponent <DropWhenCompletelyHarvested>());
            Assert.IsNotNull(unitUnderTest.GetExactComponent <DropWhenCompletelyHarvested>());
            Assert.IsNotNull(unitUnderTest.GetComponent <DropWhenCompletelyHarvested>());
            Assert.IsNotNull(unitUnderTest.GetComponent <ComponentHarvestable>());

            Assert.IsTrue(deserialized.HasComponent <DropWhenCompletelyHarvested>());
            Assert.IsNotNull(deserialized.GetExactComponent <DropWhenCompletelyHarvested>());
            Assert.IsNotNull(deserialized.GetComponent <DropWhenCompletelyHarvested>());
            Assert.IsNotNull(deserialized.GetComponent <ComponentHarvestable>());
            Assert.IsNotNull(deserialized.GetExactComponent <ComponentSelectable>(), "Components didn't serialize properly");
            Assert.IsNotNull(deserialized.GetExactComponent <ComponentRenderer>(), "Components didn't serialize properly");
        }
예제 #2
0
        private void TileTest()
        {
            string data = Convert.ToBase64String(ProtoUtil.Serialize <Dirt>(new Dirt(3, 2)));
            Dirt   dirt = ProtoUtil.Deserialize <Dirt>(data);

            Assert.AreEqual(dirt.Location, new Point2D(3, 2));
            Assert.IsNotNull(dirt.ID);
        }
예제 #3
0
        private void WorldTest()
        {
            this.Setup();
            World.Initialize(1, 1, new GrassAndDirt(0));
            WorldTransferMessage input = new WorldTransferMessage(World.Dimensions);

            byte[] data = ProtoUtil.Serialize(input);
            Assert.IsNotNull(data, "Failed to serialize");

            WorldTransferMessage result = (WorldTransferMessage)ProtoUtil.Deserialize(data);
        }
예제 #4
0
        async Task <byte[]> HandleUserLoginReq(byte[] msg)
        {
            var req = ProtoUtil.Deserialize <UserLoginReq>(msg);

            //todo

            var res = new UserLoginRes
            {
                Res    = 0,
                UserId = Guid.NewGuid().ToByteArray()
            };

            return(ProtoUtil.Serialize(res));
        }
예제 #5
0
        void OnRequestReceived(NetWork.Session session, BinaryRequestInfo requestInfo)
        {
            Console.WriteLine("OnRequestReceived success.");

            ByteBuffer buffer = new ByteBuffer(requestInfo.Body);

            if (buffer == null)
            {
                Console.WriteLine("----------Error data");
                return;
            }

            try
            {
                //int length = buffer.ReadShort ();
                int            length    = 0;
                C2S_Proto_Type protoType = (C2S_Proto_Type)buffer.ReadShort();
                Console.WriteLine("Receive proto size : {0}, name : {1}", length, protoType);
                switch (protoType)
                {
                case C2S_Proto_Type.Proto_Stuff_Login:
                {
                    Stuff_Login login = ProtoUtil.Deserialize <Stuff_Login>(buffer);

                    if (CheckAuthentication(login))
                    {
                        Player player = new Player(login.PlayerId);
                        player.SetSession(session);
                        player.OnPlayerLogin();
                    }
                }
                break;

                case C2S_Proto_Type.Proto_Stuff_Account:
                {
                    Stuff_Account account = ProtoUtil.Deserialize <Stuff_Account>(buffer);
                    Console.WriteLine(account.UserName + account.PassWord);
                }
                break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Deserialize exception : {0}", ex.Message);
            }
        }
예제 #6
0
        /// <summary>
        /// Loads a chunk from disk.
        /// </summary>
        /// <param name="chunkX">The x position of the chunk within the dimension.</param>
        /// <param name="chunkY">The y position of the chunk within the dimension.</param>
        /// <param name="dimensionID">The ID of the dimension that the chunk belongs to.</param>
        /// <returns></returns>
        public Chunk LoadChunk(Point chunkLocation, Guid dimensionID)
        {
            bool dimensionExists = this.DimensionPaths.TryGetValue(dimensionID, out string path);

            if (!dimensionExists)
            {
                throw new Exception("Dimension save folder does not exist!");
            }

            using (StreamReader sr = new StreamReader(path + chunkLocation.ToString() + ".chunk"))
            {
                Task <string> serialized = sr.ReadToEndAsync();
                return(ProtoUtil.Deserialize <Chunk>(serialized.Result));
            }
        }
예제 #7
0
        public void TestJobSerialization()
        {
            this.Setup();
            MineJob job = new MineJob(new MagicalLifeAPI.DataTypes.Point2D(3, 6));

            HumanFactory humanFactory = new HumanFactory();
            Human        human        = humanFactory.GenerateHuman(new MagicalLifeAPI.DataTypes.Point2D(1, 3), 0, Guid.NewGuid());

            JobAssignedMessage message = new JobAssignedMessage(human, job);

            byte[] data = ProtoUtil.Serialize(message);
            Assert.IsNotNull(data);

            JobAssignedMessage result = (JobAssignedMessage)ProtoUtil.Deserialize(data);
        }
예제 #8
0
        private void Client_DataReceived(object sender, Message e)
        {
            BaseMessage msg = (BaseMessage)ProtoUtil.Deserialize(e.Data);

            ClientProcessor.Process(msg);
        }