public WorldInfo[] GetAllWorlds() { _db.Open(); List<WorldInfo> worlds = new List<WorldInfo>(); DbDataReader reader = _db.ExcecuteReader(DbNames.GETALLWORLDS_STOREDPROC, System.Data.CommandType.StoredProcedure, null); int ordinalId = reader.GetOrdinal(DbNames.WORLDINFO_ID); int ordinalName = reader.GetOrdinal(DbNames.WORLDINFO_NAME); int ordinalDesc = reader.GetOrdinal(DbNames.WORLDINFO_DESC); int ordinalIP = reader.GetOrdinal(DbNames.WORLDINFO_IP); int ordinalPort = reader.GetOrdinal(DbNames.WORLDINFO_PORT); while (reader.Read()) { WorldInfo world = new WorldInfo { WorldId = reader.GetInt32(ordinalId), WorldName = reader.GetString(ordinalName), WorldDesc = reader.GetString(ordinalDesc), IPAddress = reader.GetString(ordinalIP), Port = reader.GetInt32(ordinalPort) }; worlds.Add(world); } reader.Close(); _db.Close(); return worlds.ToArray(); }
/// <summary> /// Send list of worlds to client /// </summary> /// <returns></returns> public static byte[] SendWorldList(WorldInfo[] worldInfos) { Packet p = new Packet(100); p.WriteByte(worldInfos.Length); for (int i = 0; i < worldInfos.Length; i++) { p.WriteByte(worldInfos[i].WorldId); p.WriteString(worldInfos[i].WorldName); p.WriteString(worldInfos[i].WorldDesc); } return p.GetWrittenBuffer(PacketIds.SendWorldList); }