mirror of
https://e.coding.net/circlecloud/CTZLoginServer.git
synced 2025-01-07 12:39:01 +00:00
fix some bug...
This commit is contained in:
parent
5bc4bd4bb2
commit
3a6f330500
@ -39,7 +39,7 @@ public class CTZLoginServerSocket implements Runnable {
|
|||||||
// 等待请求,此方法会一直阻塞,直到获得请求才往下走
|
// 等待请求,此方法会一直阻塞,直到获得请求才往下走
|
||||||
while (true) {
|
while (true) {
|
||||||
socket = s.accept();
|
socket = s.accept();
|
||||||
System.out.println("CTZL服务器收到请求 客户端IP: " + socket.getRemoteSocketAddress() + " 端口:"
|
System.out.println("CTZL服务器收到请求 客户端IP: " + socket.getInetAddress() + " 端口:"
|
||||||
+ socket.getPort());
|
+ socket.getPort());
|
||||||
new ClientThread(socket).start();
|
new ClientThread(socket).start();
|
||||||
}
|
}
|
||||||
@ -81,36 +81,42 @@ public class CTZLoginServerSocket implements Runnable {
|
|||||||
String password = "";
|
String password = "";
|
||||||
if (req.isSuccess) {
|
if (req.isSuccess) {
|
||||||
switch (req.getPrefix().substring(1)) {
|
switch (req.getPrefix().substring(1)) {
|
||||||
case "isregister":
|
case "isregistered":
|
||||||
username = req.getQuerystring("username");
|
username = req.Query("username");
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
res.setState(HttpStates.Bad_Request);
|
res.setState(HttpStates.Bad_Request);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Bukkit.getConsoleSender().sendMessage(
|
||||||
|
"§6玩家: §a" + username + " §6请求注册检测!");
|
||||||
if (API.isRegistered(username))
|
if (API.isRegistered(username))
|
||||||
res.setHtml("true");
|
res.setHtml("true");
|
||||||
else
|
else
|
||||||
res.setHtml("false");
|
res.setHtml("false");
|
||||||
break;
|
break;
|
||||||
case "register":
|
case "register":
|
||||||
username = req.getQuerystring("username");
|
username = req.Query("username");
|
||||||
password = req.getQuerystring("password");
|
password = req.Query("password");
|
||||||
if (username == null || password == null) {
|
if (username == null || password == null) {
|
||||||
res.setState(HttpStates.Bad_Request);
|
res.setState(HttpStates.Bad_Request);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Bukkit.getConsoleSender().sendMessage(
|
||||||
|
"§6玩家: §a" + username + " §6请求注册!");
|
||||||
if (API.registerPlayer(username, password))
|
if (API.registerPlayer(username, password))
|
||||||
res.setHtml("true");
|
res.setHtml("true");
|
||||||
else
|
else
|
||||||
res.setHtml("false");
|
res.setHtml("false");
|
||||||
break;
|
break;
|
||||||
case "login":
|
case "login":
|
||||||
username = req.getQuerystring("username");
|
username = req.Query("username");
|
||||||
password = req.getQuerystring("password");
|
password = req.Query("password");
|
||||||
if (username == null || password == null) {
|
if (username == null || password == null) {
|
||||||
res.setState(HttpStates.Bad_Request);
|
res.setState(HttpStates.Bad_Request);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Bukkit.getConsoleSender().sendMessage(
|
||||||
|
"§6玩家: §a" + username + " §6请求登录!");
|
||||||
if (API.checkPassword(username, password))
|
if (API.checkPassword(username, password))
|
||||||
res.setHtml("true");
|
res.setHtml("true");
|
||||||
// TODO 处理玩家后续登录事件
|
// TODO 处理玩家后续登录事件
|
||||||
@ -118,19 +124,21 @@ public class CTZLoginServerSocket implements Runnable {
|
|||||||
res.setHtml("false");
|
res.setHtml("false");
|
||||||
break;
|
break;
|
||||||
case "islogin":
|
case "islogin":
|
||||||
username = req.getQuerystring("username");
|
username = req.Query("username");
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
res.setState(HttpStates.Bad_Request);
|
res.setState(HttpStates.Bad_Request);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Bukkit.getConsoleSender().sendMessage(
|
||||||
|
"§6玩家: §a" + username + " §6请求登录检测!");
|
||||||
if (Bukkit.getPlayer(username) != null)
|
if (Bukkit.getPlayer(username) != null)
|
||||||
res.setHtml("true");
|
res.setHtml("true");
|
||||||
else
|
else
|
||||||
res.setHtml("false");
|
res.setHtml("false");
|
||||||
break;
|
break;
|
||||||
case "changepassword":
|
case "changepassword":
|
||||||
username = req.getQuerystring("username");
|
username = req.Query("username");
|
||||||
password = req.getQuerystring("password");
|
password = req.Query("password");
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
res.setState(HttpStates.Bad_Request);
|
res.setState(HttpStates.Bad_Request);
|
||||||
break;
|
break;
|
||||||
@ -144,7 +152,6 @@ public class CTZLoginServerSocket implements Runnable {
|
|||||||
default:
|
default:
|
||||||
res.setState(HttpStates.Bad_Request);
|
res.setState(HttpStates.Bad_Request);
|
||||||
}
|
}
|
||||||
System.out.println(res.toString());
|
|
||||||
pw.write(res.toString());
|
pw.write(res.toString());
|
||||||
pw.flush();
|
pw.flush();
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class Request {
|
|||||||
// 解析URL
|
// 解析URL
|
||||||
prefix = args[1].substring(0, lastc);
|
prefix = args[1].substring(0, lastc);
|
||||||
// 解析查询字符串
|
// 解析查询字符串
|
||||||
String[] params = args[1].substring(lastc).split("&");
|
String[] params = args[1].substring(lastc + 1).split("&");
|
||||||
for (String param : params) {
|
for (String param : params) {
|
||||||
if (param.contains("=")) {
|
if (param.contains("=")) {
|
||||||
String[] paraminfo = param.split("=");
|
String[] paraminfo = param.split("=");
|
||||||
@ -79,7 +79,7 @@ public class Request {
|
|||||||
/**
|
/**
|
||||||
* @return 查询数据
|
* @return 查询数据
|
||||||
*/
|
*/
|
||||||
public String getQuerystring(String key) {
|
public String Query(String key) {
|
||||||
return querystring.get(key);
|
return querystring.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user