Exemplo n.º 1
0
 public void Send <T>(T data, Guid player)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     MasterLog.DebugWriteLine("Sending " + buffer.Length + " bytes");
     this.PlayerToSocket[player].Send(buffer);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Broadcasts the message to a specific client.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="client"></param>
 public void Send <T>(T data, Socket client)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     MasterLog.DebugWriteLine("Sending " + buffer.Length + " bytes");
     client.Send(buffer);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Broadcasts the message to all connected clients.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 public void Broadcast <T>(T data)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     MasterLog.DebugWriteLine("Sending " + buffer.Length + " bytes");
     this.Server.Broadcast(buffer);
 }
Exemplo n.º 4
0
 public void Send <T>(T message)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(message);
     MasterLog.DebugWriteLine("Sending " + buffer.Length + " bytes");
     this.Client.Write(buffer);
 }
Exemplo n.º 5
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");
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public override void Receive <T>(T data, string filePath, Guid dimensionID)
 {
     this.ValidateData(data);
     byte[] worldData = ProtoUtil.Serialize(data);
     using (FileStream fs = new FileStream(filePath, FileMode.Create))
     {
         fs.Write(worldData, 0, worldData.Length);
     }
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public bool SendPb(ProtoBuf.IExtensible proto)
        {
            ByteBuffer buff = new ByteBuffer();

            byte[] contents = ProtoUtil.Serialize(proto);

            buff.WriteShort((ushort)(contents.Length + 2));
            buff.WriteShort((ushort)ProtoUtil.GetProtoType(proto));
            buff.WriteBytes(contents);

            this.SendBytes(buff.ToBytes());
            return(true);
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Saves a chunk to disk.
        /// </summary>
        /// <param name="chunk">The chunk to save.</param>
        /// <param name="dimensionID">The ID of the dimension the chunk belongs to.</param>
        public void SaveChunk(Chunk chunk, Guid dimensionID)
        {
            bool dimensionExists = this.DimensionPaths.TryGetValue(dimensionID, out string path);

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

            using (FileStream fs = File.Create(path + chunk.ChunkLocation.ToString() + ".chunk"))
            {
                string serialized = Convert.ToBase64String(ProtoUtil.Serialize <Chunk>(chunk));

                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteAsync(serialized);
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Broadcasts the message to a specific client.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="client"></param>
 public void Send <T>(T data, Socket client)
     where T : BaseMessage
 {
     client.Send(ProtoUtil.Serialize <T>(data));
 }
 private void Send(BaseMessage msg)
 {
     byte[] data = ProtoUtil.Serialize(msg);
     this.Client.Send(data);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Broadcasts the message to all connected clients.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 public void Broadcast <T>(T data)
     where T : BaseMessage
 {
     this.Server.Broadcast(ProtoUtil.Serialize <T>(data));
 }
Exemplo n.º 16
0
 public void Send <T>(T message)
     where T : BaseMessage
 {
     this.Client.Write(Convert.FromBase64String(ProtoUtil.Serialize <T>(message)));
 }
Exemplo n.º 17
0
 public void Send <T>(T data, Guid player)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     this.PlayerToSocket[player].Send(buffer);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Broadcasts the message to all connected clients.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 public void Broadcast <T>(T data)
     where T : BaseMessage
 {
     this.Server.Broadcast(Convert.FromBase64String(ProtoUtil.Serialize <T>(data)));
 }
 public void Send <T>(T message)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(message);
     this.Client.Write(buffer);
 }
Exemplo n.º 20
0
 public void Send <T>(T message)
     where T : BaseMessage
 {
     this.Client.Write(ProtoUtil.Serialize <T>(message));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Broadcasts the message to all connected clients.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 public void Broadcast <T>(T data)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     this.Server.Broadcast(buffer);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Broadcasts the message to a specific client.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="client"></param>
 public void Send <T>(T data, Socket client)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     client.Send(buffer);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Broadcasts the message to a specific client.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="client"></param>
 public void Send <T>(T data, Socket client)
     where T : BaseMessage
 {
     client.Send(Convert.FromBase64String(ProtoUtil.Serialize <T>(data)));
 }