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) {