コード例 #1
0
 public static byte[] SerializeHost(GameHosting host)
 {
     using (var ms = new MemoryStream())
         using (var w = new BinaryWriter(ms))
         {
             w.Write((byte)InteractionMessage.PingAnswer);
             w.Write(host.HostId);
             w.Write(host.PlayerCount);
             w.Write(host.MaxPlayers);
             w.Write((byte)host.State);
             w.Write(host.GameTitle);
             return(ms.GetBuffer());
         }
 }
コード例 #2
0
        public static GameHosting FromBytes(IPEndPoint address, byte[] data, int index)
        {
            var ms = new MemoryStream(data, index, data.Length - index);
            var r  = new BinaryReader(ms);
            var gh = new GameHosting();

            gh.Address     = address;
            gh.HostId      = r.ReadInt64();
            gh.PlayerCount = r.ReadInt32();
            gh.MaxPlayers  = r.ReadByte();
            gh.State       = (GameState)r.ReadByte();
            gh.GameTitle   = r.ReadString();
            r.Close();
            ms.Close();
            return(gh);
        }