From 3a6f330500086fdbdbfef1fc2b418c4b97dd79a2 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Wed, 29 Jul 2015 20:39:48 +0800 Subject: [PATCH] fix some bug... --- .../Socket/CTZLoginServerSocket.java | 29 ++++++++++++------- .../CTZLoginServer/Socket/Request.java | 4 +-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java b/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java index be38df5..3af2d80 100644 --- a/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java +++ b/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java @@ -39,7 +39,7 @@ public class CTZLoginServerSocket implements Runnable { // 等待请求,此方法会一直阻塞,直到获得请求才往下走 while (true) { socket = s.accept(); - System.out.println("CTZL服务器收到请求 客户端IP: " + socket.getRemoteSocketAddress() + " 端口:" + System.out.println("CTZL服务器收到请求 客户端IP: " + socket.getInetAddress() + " 端口:" + socket.getPort()); new ClientThread(socket).start(); } @@ -81,36 +81,42 @@ public class CTZLoginServerSocket implements Runnable { String password = ""; if (req.isSuccess) { switch (req.getPrefix().substring(1)) { - case "isregister": - username = req.getQuerystring("username"); + case "isregistered": + username = req.Query("username"); if (username == null) { res.setState(HttpStates.Bad_Request); break; } + Bukkit.getConsoleSender().sendMessage( + "§6玩家: §a" + username + " §6请求注册检测!"); if (API.isRegistered(username)) res.setHtml("true"); else res.setHtml("false"); break; case "register": - username = req.getQuerystring("username"); - password = req.getQuerystring("password"); + username = req.Query("username"); + password = req.Query("password"); if (username == null || password == null) { res.setState(HttpStates.Bad_Request); break; } + Bukkit.getConsoleSender().sendMessage( + "§6玩家: §a" + username + " §6请求注册!"); if (API.registerPlayer(username, password)) res.setHtml("true"); else res.setHtml("false"); break; case "login": - username = req.getQuerystring("username"); - password = req.getQuerystring("password"); + username = req.Query("username"); + password = req.Query("password"); if (username == null || password == null) { res.setState(HttpStates.Bad_Request); break; } + Bukkit.getConsoleSender().sendMessage( + "§6玩家: §a" + username + " §6请求登录!"); if (API.checkPassword(username, password)) res.setHtml("true"); // TODO 处理玩家后续登录事件 @@ -118,19 +124,21 @@ public class CTZLoginServerSocket implements Runnable { res.setHtml("false"); break; case "islogin": - username = req.getQuerystring("username"); + username = req.Query("username"); if (username == null) { res.setState(HttpStates.Bad_Request); break; } + Bukkit.getConsoleSender().sendMessage( + "§6玩家: §a" + username + " §6请求登录检测!"); if (Bukkit.getPlayer(username) != null) res.setHtml("true"); else res.setHtml("false"); break; case "changepassword": - username = req.getQuerystring("username"); - password = req.getQuerystring("password"); + username = req.Query("username"); + password = req.Query("password"); if (username == null) { res.setState(HttpStates.Bad_Request); break; @@ -144,7 +152,6 @@ public class CTZLoginServerSocket implements Runnable { default: res.setState(HttpStates.Bad_Request); } - System.out.println(res.toString()); pw.write(res.toString()); pw.flush(); } diff --git a/src/cn/citycraft/CTZLoginServer/Socket/Request.java b/src/cn/citycraft/CTZLoginServer/Socket/Request.java index 2eb6ede..1cc84e8 100644 --- a/src/cn/citycraft/CTZLoginServer/Socket/Request.java +++ b/src/cn/citycraft/CTZLoginServer/Socket/Request.java @@ -42,7 +42,7 @@ public class Request { // 解析URL 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) { if (param.contains("=")) { String[] paraminfo = param.split("="); @@ -79,7 +79,7 @@ public class Request { /** * @return 查询数据 */ - public String getQuerystring(String key) { + public String Query(String key) { return querystring.get(key); }