Skip to content

Instantly share code, notes, and snippets.

@TinkerWorX
Created May 3, 2012 17:30
Show Gist options
  • Save TinkerWorX/2587445 to your computer and use it in GitHub Desktop.
Save TinkerWorX/2587445 to your computer and use it in GitHub Desktop.
An example message from Legeria.Networking.
[NetworkMessageData(0x0005, NetworkMessageTransport.TCP)]
public class NetworkMessageRealmSector : INetworkMessage
{
public SectorPoint SectorPoint;
public Tile[,] Tiles;
public void Write(BinaryWriter writer)
{
if (this.Tiles == null) throw new Exception("this.Tiles must be initialized with Tile data.");
writer.Write(this.SectorPoint.PackedValue);
for (var x = 0; x < TileWorX.SECTOR_TILE_SIZE; x += 1)
{
for (var y = 0; y < TileWorX.SECTOR_TILE_SIZE; y += 1)
{
writer.Write(this.Tiles[x, y].BackType.Id);
writer.Write(this.Tiles[x, y].BaseType.Id);
}
}
}
public void Read(BinaryReader reader)
{
this.Tiles = new Tile[TileWorX.SECTOR_TILE_SIZE, TileWorX.SECTOR_TILE_SIZE];
this.SectorPoint = new SectorPoint(reader.ReadUInt16());
for (var x = 0; x < TileWorX.SECTOR_TILE_SIZE; x += 1)
{
for (var y = 0; y < TileWorX.SECTOR_TILE_SIZE; y += 1)
{
this.Tiles[x, y] = new Tile(
reader.ReadByte(), // BackType.Id
reader.ReadByte()); // BaseType.Id
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment