Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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");
        }
Beispiel #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);
        }
Beispiel #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);
     }
 }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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));
        }
Beispiel #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);
        }
Beispiel #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);
                }
            }
        }
Beispiel #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);
 }
Beispiel #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));
 }
Beispiel #16
0
 public void Send <T>(T message)
     where T : BaseMessage
 {
     this.Client.Write(Convert.FromBase64String(ProtoUtil.Serialize <T>(message)));
 }
Beispiel #17
0
 public void Send <T>(T data, Guid player)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     this.PlayerToSocket[player].Send(buffer);
 }
Beispiel #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);
 }
Beispiel #20
0
 public void Send <T>(T message)
     where T : BaseMessage
 {
     this.Client.Write(ProtoUtil.Serialize <T>(message));
 }
Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #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)));
 }