Skip to content

Commit

Permalink
更新到v1.4版本:
Browse files Browse the repository at this point in the history
1.设置中增加是否打印错误日志(mysql)选项。
2.增加MySQL超时时间设置,连接超时后将断开连接重新连接。
3.配置文件增加是否验证正版帐号选项,开启后网页端无法注册有同名正版帐号的帐号(不区分大小写),命令行添加帐号时如果检测到有正版同名帐号,则提示是否直接使用正版UUID
  • Loading branch information
lintx committed Jan 23, 2020
1 parent 35c0a0e commit 0a607b0
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 150 deletions.
87 changes: 78 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,96 @@

<groupId>org.lintx.plugin</groupId>
<artifactId>WebAuth</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>org.lintx.plugins.webauth.maven.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>org.lintx.plugins.modules</pattern>
<shadedPattern>org.lintx.plugins.webauth.maven.modules</shadedPattern>
</relocation>
</relocations>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>org.bstats</include>
<include>org.lintx.plugins.modules</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5.bungee</groupId>
<artifactId>BungeeCord</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/BungeeCord.jar</systemPath>
</dependency>
<dependency>
<groupId>org.lintx.plugins.modules</groupId>
<artifactId>Configure</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/Configure-1.2.3-SNAPSHOT.jar</systemPath>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.lintx.plugins.modules</groupId>-->
<!-- <artifactId>Configure</artifactId>-->
<!-- <version>1.2.1-SNAPSHOT</version>-->
<!-- <version>1.0</version>-->
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/libs/Configure-1.2.3-SNAPSHOT.jar</systemPath>-->
<!-- </dependency>-->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bungeecord</artifactId>
<version>1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.lintx.plugins.modules</groupId>
<artifactId>Configure</artifactId>
<version>1.2.3-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
18 changes: 17 additions & 1 deletion src/main/java/org/lintx/plugin/webauth/Commands.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.lintx.plugin.webauth;

import com.google.common.base.Charsets;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
import org.lintx.plugin.webauth.httpserver.Caches;
import org.lintx.plugin.webauth.httpserver.Messages;
import org.lintx.plugin.webauth.models.PlayerModel;
import org.lintx.plugin.webauth.utils.MojangApi;
import org.lintx.plugin.webauth.utils.Utils;

import java.io.*;
Expand Down Expand Up @@ -48,8 +50,22 @@ public void execute(CommandSender sender, String[] args) {
sender.sendMessage(new TextComponent(Message.playerNameLong));
return;
}

String password = args[3];
PlayerModel model = new PlayerModel(username,password);
if (Config.getInstance().isCheckPlayerNameFromMojang()){
MojangApi.MojangAccount account = MojangApi.getMojangAccount(username);
if (!account.checkName(username)){
if (args.length == 4 || (!args[4].equalsIgnoreCase("confirm") && !args[4].equalsIgnoreCase("ignore"))){
sender.sendMessage(new TextComponent(Message.addMojangPlayer.replaceAll("\\{name\\}",username).replaceAll("\\{uuid\\}",account.id)));
return;
}
if (args[4].equalsIgnoreCase("confirm")){
model.setUuid(account.getUUID());
}
}
}

if (auth.getModel().insertPlayer(model)){
model = auth.getModel().getPlayerWithPlayerName(username);
sender.sendMessage(new TextComponent(Message.addPlayerSuccess));
Expand Down
107 changes: 31 additions & 76 deletions src/main/java/org/lintx/plugin/webauth/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.lintx.plugin.webauth;

import lombok.Getter;
import org.lintx.plugin.webauth.config.DatabaseConfig;
import org.lintx.plugins.modules.configure.Configure;
import org.lintx.plugins.modules.configure.YamlConfig;
Expand All @@ -24,111 +25,65 @@ public void load(WebAuth plugin){
}

@YamlConfig
@Getter
private String notRegister = "你还没有注册,请打开网页\n{url}\n注册后登录游戏";

@YamlConfig
@Getter
private String tokenIsValid = "登录凭证无效,请检查您的凭证\n如忘记凭证请打开网页\n{url}\n重置凭证";

@YamlConfig
@Getter
private String tokenIsExpired = "登录凭证已过期,请打开网页\n{url}\n重置凭证";

@YamlConfig
@Getter
private String nameIsValid = "玩家名中含有不允许的字符,请打开网页\n{url}\n修改玩家名或联系管理员";

@YamlConfig
private String tokenManageUrl = "";

@YamlConfig
@Getter
private DatabaseConfig databaseConfig = new DatabaseConfig();

@YamlConfig
@Getter
private int webPort = 0;

@YamlConfig
@Getter
private boolean openRegister = true;

@YamlConfig
@Getter
private boolean openChangePlayername = false;

@YamlConfig
@Getter
private String playerNameRegexp = "^[a-zA-Z0-9\\u4e00-\\u9fa5]+$";

public String getNameIsValid() {
return nameIsValid;
}
@YamlConfig
@Getter
private boolean checkPlayerNameFromMojang = false;

public void setNameIsValid(String nameIsValid) {
this.nameIsValid = nameIsValid;
}
@YamlConfig
@Getter
private String httpProxyType = "http/socks";

public String getPlayerNameRegexp() {
return playerNameRegexp;
}
@YamlConfig
@Getter
private String httpProxyAddress = "";

public void setPlayerNameRegexp(String playerNameRegexp) {
this.playerNameRegexp = playerNameRegexp;
}
@YamlConfig
@Getter
private int httpProxyPort = 0;

public String formatMessage(String message){
return message.replaceAll("\\{url\\}",tokenManageUrl);
}

public String getNotRegister() {
return notRegister;
}

public void setNotRegister(String notRegister) {
this.notRegister = notRegister;
}

public String getTokenIsValid() {
return tokenIsValid;
}

public void setTokenIsValid(String tokenIsValid) {
this.tokenIsValid = tokenIsValid;
}

public String getTokenIsExpired() {
return tokenIsExpired;
}

public void setTokenIsExpired(String tokenIsExpired) {
this.tokenIsExpired = tokenIsExpired;
}

public static void setInstance(Config instance) {
Config.instance = instance;
}

public String getTokenManageUrl() {
return tokenManageUrl;
}

public void setTokenManageUrl(String tokenManageUrl) {
this.tokenManageUrl = tokenManageUrl;
}

public DatabaseConfig getDatabaseConfig() {
return databaseConfig;
}

public void setDatabaseConfig(DatabaseConfig databaseConfig) {
this.databaseConfig = databaseConfig;
}

public int getWebPort() {
return webPort;
}

public void setWebPort(int webPort) {
this.webPort = webPort;
}

public boolean isOpenRegister() {
return openRegister;
}

public void setOpenRegister(boolean openRegister) {
this.openRegister = openRegister;
}

public boolean isOpenChangePlayername() {
return openChangePlayername;
}

public void setOpenChangePlayername(boolean openChangePlayername) {
this.openChangePlayername = openChangePlayername;
}
}
6 changes: 0 additions & 6 deletions src/main/java/org/lintx/plugin/webauth/Listeners.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.lintx.plugin.webauth;

import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.event.PreLoginEvent;
Expand All @@ -11,9 +8,6 @@
import net.md_5.bungee.event.EventHandler;
import org.lintx.plugin.webauth.models.PlayerModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Listeners implements Listener {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/lintx/plugin/webauth/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class Message {
static final String passwordUpdateSuccess = "§a密码更新成功";
static final String addPlayerFail = "§c新增玩家失败";
static final String addPlayerSuccess = "§a新增玩家成功";
static final String addMojangPlayer = "§a新增玩家{name}经查询是正版玩家,UUID为{uuid}。\n" +
"§a新增并设置UUID为正版UUID请输入命令§b/webauth player add {name} 密码 confirm\n" +
"§a新增并不设置UUID为正版UUID请输入命令§b/webauth player add {name} 密码 ignore";
static final String playerNameRepeat = "§c玩家用户名或玩家名重复";
static final String reloadConfig = "§a重新加载配置文件";
static final String playerNameShort = "§c玩家名太短(不能小于4字符)";
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/lintx/plugin/webauth/WebAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import org.bstats.bungeecord.Metrics;
import org.lintx.plugin.webauth.config.DatabaseConfig;
import org.lintx.plugin.webauth.httpserver.Caches;
import org.lintx.plugin.webauth.httpserver.NettyHttpServer;
Expand Down Expand Up @@ -33,6 +34,8 @@ public void onEnable() {

getProxy().getPluginManager().registerListener(this,new Listeners(this));
getProxy().getPluginManager().registerCommand(this,new Commands(this,"webauth",null,"auth","wa"));

Metrics metrics = new Metrics(this);
}

@Override
Expand Down Expand Up @@ -128,7 +131,7 @@ void reload(){
if (mySql!=null){
mySql.close();
}
mySql = new MySql(config.getDatabaseConfig().getMysqlUri(),config.getDatabaseConfig().getMysqlUser(),config.getDatabaseConfig().getMysqlPassword());
mySql = new MySql(config.getDatabaseConfig().getMysqlUri(),config.getDatabaseConfig().getMysqlUser(),config.getDatabaseConfig().getMysqlPassword(),config.getDatabaseConfig().getTimeout());
model = new Model(mySql);
}else {
sqLite = new SQLite(getDataFolder(),"database");
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/lintx/plugin/webauth/config/DatabaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ public enum DatabaseType{
private String mysqlUser = "root";
@YamlConfig
private String mysqlPassword = "root";
@YamlConfig
private boolean printError = false;
@YamlConfig
private long timeout = 60 * 60 * 5;

public long getTimeout() {
return timeout;
}

public void setTimeout(long timeout) {
this.timeout = timeout;
}

public boolean isPrintError() {
return printError;
}

public void setPrintError(boolean printError) {
this.printError = printError;
}

public DatabaseType getType() {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class Messages {
static final String usernameShort = "用户名太短(不能小于4字符)";
static final String usernameLong = "用户名太长(不能大于16字符)";
static final String usernameRepeat = "用户名重复";
static final String usernameInMojang = "存在同名正版帐号";
static final String playerNameRepeat = "玩家名重复";
static final String playerNameShort = "玩家名太短(不能小于4字符)";
static final String playerNameLong = "玩家名太长(不能大于16字符)";
Expand Down
Loading

0 comments on commit 0a607b0

Please sign in to comment.