From b5935e9349f50a47b8dbd8da4699114b5f8ac5d4 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 16 Sep 2015 09:06:12 +0800 Subject: [PATCH] add new command... Signed-off-by: 502647092 --- .../java/cn/citycraft/CTZServer/CTZAuth.java | 3 +- .../CTZServer/commands/CommandRegister.java | 39 +++++++++++++++++++ .../CTZServer/commands/HandlerCommand.java | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/main/java/cn/citycraft/CTZServer/commands/CommandRegister.java diff --git a/src/main/java/cn/citycraft/CTZServer/CTZAuth.java b/src/main/java/cn/citycraft/CTZServer/CTZAuth.java index de213ce..7541b23 100644 --- a/src/main/java/cn/citycraft/CTZServer/CTZAuth.java +++ b/src/main/java/cn/citycraft/CTZServer/CTZAuth.java @@ -42,8 +42,7 @@ public class CTZAuth { if (isRegistered(username)) return false; else - sql.dbInsert(TableName, new KeyValue(UserField, username).add(PWDField, StringUtil.getMD5Code(password))); - return false; + return sql.dbInsert(TableName, new KeyValue(UserField, username).add(PWDField, StringUtil.getMD5Code(password))); } } diff --git a/src/main/java/cn/citycraft/CTZServer/commands/CommandRegister.java b/src/main/java/cn/citycraft/CTZServer/commands/CommandRegister.java new file mode 100644 index 0000000..f8c010f --- /dev/null +++ b/src/main/java/cn/citycraft/CTZServer/commands/CommandRegister.java @@ -0,0 +1,39 @@ +package cn.citycraft.CTZServer.commands; + +import cn.citycraft.CTZServer.CTZAuth; +import cn.citycraft.CTZServer.CTZServer; +import cn.citycraft.CTZServer.ServerThread; +import net.md_5.bungee.api.ChatColor; + +public class CommandRegister extends BaseCommand { + ServerThread serverThread; + + public CommandRegister(ServerThread serverThread) { + super("reg", "register"); + this.serverThread = serverThread; + } + + @Override + public void execute(String label, String[] args) { + if (CTZAuth.registerPlayer(args[0], args[1])) + CTZServer.print(ChatColor.GREEN + "账户 " + args[0] + " 注册成功!"); + else + CTZServer.warn(ChatColor.RED + "账户 " + args[0] + " 注册失败!"); + } + + @Override + public String getDescription() { + return ChatColor.GREEN + "注册新账户"; + } + + @Override + public int getMinimumArguments() { + return 2; + } + + @Override + public String getPossibleArguments() { + return "<账号> <密码>"; + } + +} diff --git a/src/main/java/cn/citycraft/CTZServer/commands/HandlerCommand.java b/src/main/java/cn/citycraft/CTZServer/commands/HandlerCommand.java index c82f6b9..3bf2813 100644 --- a/src/main/java/cn/citycraft/CTZServer/commands/HandlerCommand.java +++ b/src/main/java/cn/citycraft/CTZServer/commands/HandlerCommand.java @@ -24,6 +24,7 @@ public class HandlerCommand { this.serverThread = serverThread; registerCommand(new CommandStop(serverThread)); registerCommand(new CommandGc(serverThread)); + registerCommand(new CommandRegister(serverThread)); } public boolean execute(String cmd, String[] args) {