public static NetworkResponse Parse(MemoryStream dataStream) { ResponseZoneList response = new ResponseZoneList(); response.status = DataReader.ReadShort(dataStream); Dictionary<int, Player> players = new Dictionary<int, Player>(); List<Zone> zones = new List<Zone>(); if (response.status == 0) { short size = DataReader.ReadShort(dataStream); for (int i = 0; i < size; i++) { int player_id = DataReader.ReadInt(dataStream); Player player = new Player(player_id); player.name = DataReader.ReadString(dataStream); string[] rgb = DataReader.ReadString(dataStream).Split(','); player.color = new Color32(byte.Parse(rgb[0]), byte.Parse(rgb[1]), byte.Parse(rgb[2]), 255); players.Add(player_id, player); } response.players = players; response.height = DataReader.ReadShort(dataStream); response.width = DataReader.ReadShort(dataStream); string zone_str = DataReader.ReadString(dataStream); foreach (string item in zone_str.Split(';')) { if (item == "") { continue; } string[] temp = item.Split(','); Zone zone = new Zone(int.Parse(temp[0])); zone.row = short.Parse(temp[1]); zone.column = short.Parse(temp[2]); zone.terrain_type = short.Parse(temp[3]); zone.v_capacity = int.Parse(temp[4]); zone.player_id = int.Parse(temp[5]); zones.Add(zone); } response.zones = zones; } return response; }
public static NetworkResponse Parse(MemoryStream dataStream) { ResponseEcosystem response = new ResponseEcosystem(); response.status = DataReader.ReadShort(dataStream); List<Zone> zones = new List<Zone>(); if (response.status == 0) { int eco_id = DataReader.ReadInt(dataStream); Ecosystem ecosystem = new Ecosystem(eco_id); ecosystem.type = DataReader.ReadShort(dataStream); ecosystem.score = DataReader.ReadInt(dataStream); int player_id = DataReader.ReadInt(dataStream); Player player = new Player(player_id); player.name = DataReader.ReadString(dataStream); string[] rgb = DataReader.ReadString(dataStream).Split(','); player.color = new Color32(byte.Parse(rgb[0]), byte.Parse(rgb[1]), byte.Parse(rgb[2]), 255); ecosystem.player = player; string zone_str = DataReader.ReadString(dataStream); foreach (string item in zone_str.Split(';')) { if (item == "") { continue; } string[] temp = item.Split(','); Zone zone = new Zone(int.Parse(temp[0])); zone.row = short.Parse(temp[1]); zone.column = short.Parse(temp[2]); zone.terrain_type = short.Parse(temp[3]); zone.v_capacity = int.Parse(temp[4]); zones.Add(zone); } ecosystem.zones = zones; response.ecosystem = ecosystem; } return response; }
public static NetworkResponse Parse(MemoryStream dataStream) { ResponsePlayers response = new ResponsePlayers(); Dictionary<int, Player> playerList = new Dictionary<int, Player>(); int size = DataReader.ReadShort(dataStream); for (int i = 0; i < size; i++) { int player_id = DataReader.ReadInt(dataStream); Player player = new Player(player_id); player.name = DataReader.ReadString(dataStream); string[] rgb = DataReader.ReadString(dataStream).Split(','); player.color = new Color32(byte.Parse(rgb[0]), byte.Parse(rgb[1]), byte.Parse(rgb[2]), 255); playerList.Add(player.GetID(), player); } response.playerList = playerList; return response; }
public static NetworkResponse Parse(MemoryStream dataStream) { ResponsePlayerSelect response = new ResponsePlayerSelect(); response.status = DataReader.ReadShort(dataStream); if (response.status == 0) { int player_id = DataReader.ReadInt(dataStream); Player player = new Player(player_id); player.name = DataReader.ReadString(dataStream); player.level = DataReader.ReadShort(dataStream); player.xp = DataReader.ReadInt(dataStream); player.credits = DataReader.ReadInt(dataStream); string[] rgb = DataReader.ReadString(dataStream).Split(','); player.color = new Color32(byte.Parse(rgb[0]), byte.Parse(rgb[1]), byte.Parse(rgb[2]), 255); player.last_played = DataReader.ReadString(dataStream); response.player = player; } return response; }