1
0
mirror of https://e.coding.net/circlecloud/CTZLoginServer.git synced 2024-12-11 05:18:48 +00:00

add ServerInfo Class Client can getServerJson from Server...

This commit is contained in:
j502647092 2015-08-08 17:35:55 +08:00
parent 3ffccd7b7b
commit a1068c62b2
4 changed files with 191 additions and 4 deletions

View File

@ -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"));
}
}

View File

@ -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<String> arealist = cs.getKeys(false);
for (String a : arealist) {
Area area = new Area();
area.setName(cs.getString(a + ".name"));
Set<String> 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<Area> areas = new ArrayList<Area>();
public List<Area> getAreas() {
return areas;
}
public void setAreas(List<Area> aareas) {
areas = aareas;
}
}
class Area {
String name;
List<Server> servers = new ArrayList<Server>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Server> getServers() {
return servers;
}
public void setServers(List<Server> 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;
}
}

View File

@ -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);
}

View File

@ -7,8 +7,29 @@ pluginname: '&6[&bCTZL&6]&r'
#是否提示
tipplayer: true
#服务器配置
server:
config:
#服务器监听端口
port: 25580
#断线重连超时
timeout: 10
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"