diff --git a/src/cn/citycraft/CTZLoginServer/CTZLoginServer.java b/src/cn/citycraft/CTZLoginServer/CTZLoginServer.java index b50dc21..dc0e86c 100644 --- a/src/cn/citycraft/CTZLoginServer/CTZLoginServer.java +++ b/src/cn/citycraft/CTZLoginServer/CTZLoginServer.java @@ -52,13 +52,16 @@ public class CTZLoginServer extends JavaPlugin { loginserver = this .getServer() .getScheduler() - .runTaskAsynchronously(this, - new CTZLoginServerSocket(this, Config.getInstance().getInt("server.port"))); + .runTaskAsynchronously( + this, + new CTZLoginServerSocket(this, Config.getInstance().getInt("config.port", + 25580))); getLogger().info("CTZL登录服务器已开启!"); } @Override public void onLoad() { Config.load(this, "1.0"); + CTZServers.Init(Config.getInstance().getConfigurationSection("areas")); } } diff --git a/src/cn/citycraft/CTZLoginServer/CTZServers.java b/src/cn/citycraft/CTZLoginServer/CTZServers.java new file mode 100644 index 0000000..2e0d750 --- /dev/null +++ b/src/cn/citycraft/CTZLoginServer/CTZServers.java @@ -0,0 +1,156 @@ +/** + * + */ +package cn.citycraft.CTZLoginServer; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.bukkit.configuration.ConfigurationSection; + +import com.google.gson.Gson; + +/** + * @author 蒋天蓓 + * 2015年8月8日下午2:50:02 + * TODO + */ +public class CTZServers { + + CTZServers stz = new CTZServers(); + + static CTZServer sl = new CTZServer(); + + public static void Init(ConfigurationSection cs) { + Set arealist = cs.getKeys(false); + for (String a : arealist) { + Area area = new Area(); + area.setName(cs.getString(a + ".name")); + Set serverlist = cs.getConfigurationSection(a + ".servers").getKeys(false); + for (String s : serverlist) { + Server server = new Server(); + server.name = cs.getString(a + ".servers." + s + ".name"); + server.address = cs.getString(a + ".servers." + s + ".address"); + server.port = cs.getInt(a + ".servers." + s + ".port"); + server.version = cs.getString(a + ".servers." + s + ".version"); + server.info = cs.getString(a + ".servers." + s + ".info"); + server.url = cs.getString(a + ".servers." + s + ".url"); + area.servers.add(server); + } + sl.areas.add(area); + } + } + + public static String getJson() { + Gson gson = new Gson(); + return gson.toJson(sl); + } +} + +class CTZServer { + List areas = new ArrayList(); + + public List getAreas() { + return areas; + } + + public void setAreas(List aareas) { + areas = aareas; + } +} + +class Area { + String name; + List servers = new ArrayList(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getServers() { + return servers; + } + + public void setServers(List servers) { + this.servers = servers; + } + + @Override + public String toString() { + return String.format("\"name\":\"{0}\",\"servers\":\"{1}\"", name, servers.toString()); + } + +} + +class Server { + + public String name; + + public String address; + + public int port; + + public String info; + + public String version; + + public String url; + + @Override + public String toString() { + return String.format("{0}:{1}", address, port); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java b/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java index 9c4a56e..535aa19 100644 --- a/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java +++ b/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java @@ -12,6 +12,7 @@ import org.bukkit.Bukkit; import cn.citycraft.CTZLoginServer.CTZLoginQueue; import cn.citycraft.CTZLoginServer.CTZLoginServer; +import cn.citycraft.CTZLoginServer.CTZServers; import cn.citycraft.CTZLoginServer.Socket.Response.HttpStates; import fr.xephi.authme.api.API; @@ -148,6 +149,12 @@ public class CTZLoginServerSocket implements Runnable { else res.setHtml("false"); break; + case "serverlist": + res.setState(HttpStates.OK); + // {"areas":[{"name":"纯净大区","servers":[{"name":"光板小镇","address":"CityCraft.cn","port":25565,"version":"1.8","url":"http://CityCraft.cn:88/gbxz.zip","info":"纯净 有爱"}]}]} + res.setHeader("Content-Type", "text/html;charset=utf-8"); + res.setHtml(CTZServers.getJson()); + break; default: res.setState(HttpStates.Bad_Request); } diff --git a/src/config.yml b/src/config.yml index 6cbd0ab..ab49197 100644 --- a/src/config.yml +++ b/src/config.yml @@ -7,8 +7,29 @@ pluginname: '&6[&bCTZL&6]&r' #是否提示 tipplayer: true #服务器配置 -server: +config: #服务器监听端口 port: 25580 #断线重连超时 - timeout: 10 \ No newline at end of file + timeout: 10 +areas: + 1: + name: '纯净大区' + servers: + 1: + name: "光板小镇" + address: "CityCraft.cn" + port: 25565 + info: "纯净服务器" + version: "1.8-Forge" + url: "CityCraft.cn" + 2: + name: '模组大区' + servers: + 1: + name: "光板小镇" + address: "CityCraft.cn" + port: 25565 + info: "MOD服务器: 豆腐 家具 " + version: "1.7.10-Forge" + url: "CityCraft.cn"