mirror of
https://e.coding.net/circlecloud/AuthMe.git
synced 2024-12-22 06:48:55 +00:00
clean up UUID and fix Message Error...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
f0b74ad048
commit
66117b6cb0
19
.classpath
19
.classpath
@ -1,27 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" including="**/*.java" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
147
pom.xml
147
pom.xml
@ -48,6 +48,8 @@
|
||||
<!-- Change Compiler Version (JDK) HERE! -->
|
||||
<javaVersion>1.7</javaVersion>
|
||||
<!-- Change MC Version HERE! -->
|
||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||
<update.description>测试版本发布...</update.description>
|
||||
<bukkitVersion>1.8.8-R0.1-SNAPSHOT</bukkitVersion>
|
||||
</properties>
|
||||
|
||||
@ -98,10 +100,12 @@
|
||||
<include>cn.citycraft:PluginHelper</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocation>
|
||||
<pattern>cn.citycraft.PluginHelper</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
</relocation>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>cn.citycraft.PluginHelper</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
@ -116,43 +120,15 @@
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
|
||||
<!-- SpigotMC Repo (Bukkit and SpigotAPI) -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>http://hub.spigotmc.org/nexus/content/groups/public</url>
|
||||
</repository>
|
||||
|
||||
<!-- EssentialsX Repo -->
|
||||
<!-- <repository> <id>ess-repo</id> <url>http://ci.drtshock.net/plugin/repository/everything</url>
|
||||
</repository> -->
|
||||
|
||||
<!-- CombatTagPlus Repo -->
|
||||
<!-- <repository> <id>minelink-thirdparty</id> <url>http://repo.minelink.net/content/repositories/public</url>
|
||||
</repository> -->
|
||||
|
||||
<!-- Attribute Repo -->
|
||||
<!-- <repository> <id>comphenix-snapshots</id> <url>http://repo.comphenix.net/content/repositories/public</url>
|
||||
</repository> -->
|
||||
|
||||
<!-- Multiverse Repo -->
|
||||
<!-- <repository> <id>onarandombox</id> <url>http://repo.onarandombox.com/content/groups/public</url>
|
||||
</repository> -->
|
||||
|
||||
<!-- Vault Repo -->
|
||||
<!-- <repository> <id>vault-repo</id> <url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
|
||||
</repository> -->
|
||||
|
||||
<!-- XAuth Repo -->
|
||||
<!-- <repository> <id>luricos-releases</id> <url>http://repo.luricos.de/content/repositories/releases</url>
|
||||
</repository> -->
|
||||
<!-- Xephi Repo <repository> <id>xephi-repo</id> <url>http://ci.xephi.fr/plugin/repository/everything/</url>
|
||||
</repository> -->
|
||||
|
||||
<!-- Metrics Snapshots Repo -->
|
||||
<!-- <repository> <id>mcstats-snapshots</id> <url>http://repo.mcstats.org/content/repositories/snapshots/</url>
|
||||
</repository> -->
|
||||
|
||||
<repository>
|
||||
<id>citycraft-repo</id>
|
||||
<url>${jenkins.url}/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -211,104 +187,5 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/ProtocolLib-3.6.5-SNAPSHOT.jar</systemPath>
|
||||
</dependency>
|
||||
<!-- Maven Dependencies -->
|
||||
|
||||
<!-- Database Connection Pool -->
|
||||
<!-- <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId>
|
||||
<version>2.4.1</version> <scope>compile</scope> <exclusions> <exclusion>
|
||||
<artifactId>slf4j-api</artifactId> <groupId>org.slf4j</groupId> </exclusion>
|
||||
</exclusions> <optional>true</optional> </dependency> <dependency> <groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId> <version>1.7.12</version> <scope>compile</scope>
|
||||
<optional>true</optional> </dependency> Log4J Logger (for the filter) <dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId>
|
||||
<version>2.0-beta9</version> <scope>provided</scope> <optional>true</optional>
|
||||
</dependency> SQLite Connector <dependency> <groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId> <version>3.8.11.2</version> <scope>compile</scope>
|
||||
<optional>true</optional> </dependency> Java Email API and Implementation
|
||||
<dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId>
|
||||
<version>1.5.4</version> <scope>compile</scope> <optional>true</optional>
|
||||
</dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId>
|
||||
<version>1.5.4</version> <scope>compile</scope> <exclusions> <exclusion>
|
||||
<artifactId>activation</artifactId> <groupId>javax.activation</groupId> </exclusion>
|
||||
</exclusions> <optional>true</optional> </dependency> GSON required for 1.7.X
|
||||
compatibility <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId>
|
||||
<version>2.4</version> <scope>compile</scope> <optional>true</optional> </dependency>
|
||||
Maxmind GeoIp API <dependency> <groupId>com.maxmind.geoip</groupId> <artifactId>geoip-api</artifactId>
|
||||
<version>1.2.15</version> <scope>compile</scope> <optional>true</optional>
|
||||
</dependency> Metrics API <dependency> <groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId> <version>R8-SNAPSHOT</version> <scope>compile</scope>
|
||||
<exclusions> <exclusion> <groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId>
|
||||
</exclusion> </exclusions> <optional>true</optional> </dependency> Bukkit
|
||||
API, http://www.spigotmc.org/ or http://bukkit.org/ <dependency> <groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId> <version>${bukkitVersion}</version> <scope>provided</scope>
|
||||
<optional>true</optional> <exclusions> <exclusion> <artifactId>junit</artifactId>
|
||||
<groupId>junit</groupId> </exclusion> <exclusion> <artifactId>json-simple</artifactId>
|
||||
<groupId>com.googlecode.json-simple</groupId> </exclusion> <exclusion> <artifactId>persistence-api</artifactId>
|
||||
<groupId>javax.persistence</groupId> </exclusion> </exclusions> </dependency>
|
||||
Attribute <dependency> <groupId>com.comphenix.attribute</groupId> <artifactId>AttributeStorage</artifactId>
|
||||
<version>0.0.2-SNAPSHOT</version> <scope>compile</scope> <exclusions> <exclusion>
|
||||
<groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId> </exclusion>
|
||||
<exclusion> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId>
|
||||
</exclusion> </exclusions> <optional>true</optional> </dependency> ProtocolLib
|
||||
http://dev.bukkit.org/bukkit-plugins/protocollib/ <dependency> <groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId> <version>3.4.0</version> <scope>provided</scope>
|
||||
<optional>true</optional> <exclusions> <exclusion> <artifactId>cglib-nodep</artifactId>
|
||||
<groupId>cglib</groupId> </exclusion> <exclusion> <artifactId>BukkitExecutors</artifactId>
|
||||
<groupId>com.comphenix.executors</groupId> </exclusion> </exclusions> </dependency>
|
||||
Vault, http://dev.bukkit.org/bukkit-plugins/vault/ <dependency> <groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId> <version>1.5</version> <scope>provided</scope>
|
||||
<exclusions> <exclusion> <groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId>
|
||||
</exclusion> <exclusion> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId>
|
||||
</exclusion> </exclusions> <optional>true</optional> </dependency> Multi
|
||||
World plugin, http://www.spigotmc.org/resources/multiverse-core.390/ <dependency>
|
||||
<groupId>com.onarandombox.multiversecore</groupId> <artifactId>Multiverse-Core</artifactId>
|
||||
<version>2.5</version> <type>jar</type> <scope>provided</scope> <exclusions>
|
||||
<exclusion> <groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId>
|
||||
</exclusion> <exclusion> <groupId>org.bukkit</groupId> <artifactId>craftbukkit</artifactId>
|
||||
</exclusion> <exclusion> <artifactId>AllPay</artifactId> <groupId>com.fernferret.allpay</groupId>
|
||||
</exclusion> <exclusion> <artifactId>Vault</artifactId> <groupId>net.milkbowl.vault</groupId>
|
||||
</exclusion> <exclusion> <artifactId>CommandHandler</artifactId> <groupId>com.pneumaticraft.commandhandler</groupId>
|
||||
</exclusion> <exclusion> <artifactId>SerializationConfig</artifactId> <groupId>me.main__.util</groupId>
|
||||
</exclusion> <exclusion> <artifactId>Logging</artifactId> <groupId>com.dumptruckman.minecraft</groupId>
|
||||
</exclusion> <exclusion> <artifactId>metrics</artifactId> <groupId>org.mcstats.bukkit</groupId>
|
||||
</exclusion> <exclusion> <artifactId>buscript</artifactId> <groupId>com.dumptruckman.minecraft</groupId>
|
||||
</exclusion> <exclusion> <artifactId>junit</artifactId> <groupId>junit</groupId>
|
||||
</exclusion> </exclusions> <optional>true</optional> </dependency> Essentials
|
||||
plugin <dependency> <groupId>net.ess3</groupId> <artifactId>EssentialsX</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version> <scope>provided</scope> <exclusions> <exclusion>
|
||||
<groupId>org.spigotmc</groupId> <artifactId>spigot-api</artifactId> </exclusion>
|
||||
</exclusions> <optional>true</optional> </dependency> Anti PvPLogging plugin,
|
||||
https://github.com/MinelinkNetwork/CombatTagPlus <dependency> <groupId>net.minelink</groupId>
|
||||
<artifactId>CombatTagPlus</artifactId> <version>1.2.1-SNAPSHOT</version>
|
||||
<scope>provided</scope> <exclusions> <exclusion> <groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId> </exclusion> <exclusion> <groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId> </exclusion> <exclusion> <artifactId>CombatTagPlusHook</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusFactions-v1_6</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_7_R3</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusFactions-v1_8</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_7_R4</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusWG-v5</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusWG-v6</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-API</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusFactions-v2_6</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_8_R3</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusFactions-v2_7</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_8_R2</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>CombatTagPlusCompat-v1_8_R1</artifactId>
|
||||
<groupId>net.minelink</groupId> </exclusion> <exclusion> <artifactId>metrics-lite</artifactId>
|
||||
<groupId>org.mcstats.bukkit</groupId> </exclusion> </exclusions> <optional>true</optional>
|
||||
</dependency> XAuth, another authentication plugin, required by the database
|
||||
converter <dependency> <groupId>de.luricos.bukkit</groupId> <artifactId>xAuth</artifactId>
|
||||
<version>2.6</version> <scope>provided</scope> <exclusions> <exclusion> <groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId> </exclusion> <exclusion> <groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId> </exclusion> <exclusion> <artifactId>updater</artifactId>
|
||||
<groupId>net.gravitydevelopment.updater</groupId> </exclusion> <exclusion>
|
||||
<artifactId>lombok</artifactId> <groupId>org.projectlombok</groupId> </exclusion>
|
||||
<exclusion> <artifactId>EssentialsGroupManager</artifactId> <groupId>net.ess3</groupId>
|
||||
</exclusion> <exclusion> <artifactId>PermissionsEx</artifactId> <groupId>ru.tehkode</groupId>
|
||||
</exclusion> <exclusion> <artifactId>AccountsClient</artifactId> <groupId>com.mojang</groupId>
|
||||
</exclusion> <exclusion> <artifactId>log4j-core</artifactId> <groupId>org.apache.logging.log4j</groupId>
|
||||
</exclusion> </exclusions> <optional>true</optional> </dependency> -->
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -163,7 +163,7 @@ public class AuthMe extends JavaPlugin {
|
||||
final RegisteredServiceProvider<Permission> permissionProvider = server.getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
permission = permissionProvider.getProvider();
|
||||
ConsoleLogger.info("发现 Vault 使用经济系统: " + permission.getName());
|
||||
ConsoleLogger.info("发现 Vault 使用权限系统: " + permission.getName());
|
||||
} else {
|
||||
ConsoleLogger.showError("发现 Vault, 但是 Vault 未找到权限系统...");
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class Utils {
|
||||
if (lookupService != null) {
|
||||
return true;
|
||||
}
|
||||
ConsoleLogger.info("[LICENSE] IP数据来自 CityCraft 的 Yum 源 原始数据来自 http://www.maxmind.com");
|
||||
ConsoleLogger.info("从 CityCraft 的 Yum 源 下载IP缓存库...");
|
||||
final File file = new File(Settings.APLUGIN_FOLDER, "GeoIP.dat");
|
||||
try {
|
||||
if (file.exists()) {
|
||||
|
@ -30,7 +30,7 @@ public class JsonCache {
|
||||
public JsonCache() {
|
||||
cacheDir = Settings.CACHE_FOLDER;
|
||||
if (!cacheDir.exists() && !cacheDir.isDirectory() && !cacheDir.mkdir()) {
|
||||
ConsoleLogger.showError("Failed to create cache directory.");
|
||||
ConsoleLogger.showError("创建缓存目录失败.");
|
||||
}
|
||||
gson = new GsonBuilder()
|
||||
.registerTypeAdapter(DataFileCache.class, new PlayerDataSerializer())
|
||||
@ -39,7 +39,7 @@ public class JsonCache {
|
||||
.create();
|
||||
}
|
||||
|
||||
public void createCache(Player player, DataFileCache playerData) {
|
||||
public void createCache(final Player player, final DataFileCache playerData) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
@ -51,7 +51,7 @@ public class JsonCache {
|
||||
path = player.getName().toLowerCase();
|
||||
}
|
||||
|
||||
File file = new File(cacheDir, path + File.separator + "cache.json");
|
||||
final File file = new File(cacheDir, path + File.separator + "cache.json");
|
||||
if (file.exists()) {
|
||||
return;
|
||||
}
|
||||
@ -60,26 +60,26 @@ public class JsonCache {
|
||||
}
|
||||
|
||||
try {
|
||||
String data = gson.toJson(playerData);
|
||||
final String data = gson.toJson(playerData);
|
||||
Files.touch(file);
|
||||
Files.write(data, file, Charsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean doesCacheExist(Player player) {
|
||||
public boolean doesCacheExist(final Player player) {
|
||||
String path;
|
||||
try {
|
||||
path = player.getUniqueId().toString();
|
||||
} catch (Exception | Error e) {
|
||||
path = player.getName().toLowerCase();
|
||||
}
|
||||
File file = new File(cacheDir, path + File.separator + "cache.json");
|
||||
final File file = new File(cacheDir, path + File.separator + "cache.json");
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
public DataFileCache readCache(Player player) {
|
||||
public DataFileCache readCache(final Player player) {
|
||||
String path;
|
||||
try {
|
||||
path = player.getUniqueId().toString();
|
||||
@ -87,40 +87,40 @@ public class JsonCache {
|
||||
path = player.getName().toLowerCase();
|
||||
}
|
||||
|
||||
File file = new File(cacheDir, path + File.separator + "cache.json");
|
||||
final File file = new File(cacheDir, path + File.separator + "cache.json");
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
String str = Files.toString(file, Charsets.UTF_8);
|
||||
final String str = Files.toString(file, Charsets.UTF_8);
|
||||
return gson.fromJson(str, DataFileCache.class);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCache(Player player) {
|
||||
public void removeCache(final Player player) {
|
||||
String path;
|
||||
try {
|
||||
path = player.getUniqueId().toString();
|
||||
} catch (Exception | Error e) {
|
||||
path = player.getName().toLowerCase();
|
||||
}
|
||||
File file = new File(cacheDir, path);
|
||||
final File file = new File(cacheDir, path);
|
||||
if (file.exists()) {
|
||||
Utils.purgeDirectory(file);
|
||||
if (!file.delete()) {
|
||||
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
|
||||
ConsoleLogger.showError("移除玩家 " + player.getName() + " 缓存数据失败.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
|
||||
@Override
|
||||
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
public DataFileCache deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
final JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
if (jsonObject == null) {
|
||||
return null;
|
||||
}
|
||||
@ -145,12 +145,11 @@ public class JsonCache {
|
||||
|
||||
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
|
||||
@Override
|
||||
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
public JsonElement serialize(final DataFileCache dataFileCache, final Type type, final JsonSerializationContext jsonSerializationContext) {
|
||||
final JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("group", dataFileCache.getGroup());
|
||||
jsonObject.addProperty("operator", dataFileCache.getOperator());
|
||||
jsonObject.addProperty("flying", dataFileCache.isFlying());
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,16 @@ public class FlatFile implements DataSource {
|
||||
* :LASTPOSZ:LASTPOSWORLD PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS
|
||||
* PLAYERNAME:HASHSUM:IP PLAYERNAME:HASHSUM
|
||||
*/
|
||||
private File source;
|
||||
private final File source;
|
||||
|
||||
public FlatFile() {
|
||||
source = Settings.AUTH_FILE;
|
||||
try {
|
||||
source.createNewFile();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
if (Settings.isStopEnabled) {
|
||||
ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN...");
|
||||
ConsoleLogger.showError("无法读取用户数据文件... 关闭服务器...");
|
||||
AuthMe.getInstance().getServer().shutdown();
|
||||
}
|
||||
if (!Settings.isStopEnabled) {
|
||||
@ -49,16 +49,16 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> autoPurgeDatabase(long until) {
|
||||
public List<String> autoPurgeDatabase(final long until) {
|
||||
BufferedReader br = null;
|
||||
BufferedWriter bw = null;
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
List<String> cleared = new ArrayList<>();
|
||||
final ArrayList<String> lines = new ArrayList<>();
|
||||
final List<String> cleared = new ArrayList<>();
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args.length >= 4) {
|
||||
if (Long.parseLong(args[3]) >= until) {
|
||||
lines.add(line);
|
||||
@ -68,26 +68,26 @@ public class FlatFile implements DataSource {
|
||||
cleared.add(args[0]);
|
||||
}
|
||||
bw = new BufferedWriter(new FileWriter(source));
|
||||
for (String l : lines) {
|
||||
for (final String l : lines) {
|
||||
bw.write(l + "\n");
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return cleared;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return cleared;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
if (bw != null) {
|
||||
try {
|
||||
bw.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,14 +107,14 @@ public class FlatFile implements DataSource {
|
||||
while ((br.readLine()) != null) {
|
||||
result++;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,12 +124,12 @@ public class FlatFile implements DataSource {
|
||||
@Override
|
||||
public List<PlayerAuth> getAllAuths() {
|
||||
BufferedReader br = null;
|
||||
List<PlayerAuth> auths = new ArrayList<>();
|
||||
final List<PlayerAuth> auths = new ArrayList<>();
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0]));
|
||||
@ -141,30 +141,30 @@ public class FlatFile implements DataSource {
|
||||
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]));
|
||||
break;
|
||||
case 7:
|
||||
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]),
|
||||
"unavailableworld", "your@email.com", args[0]));
|
||||
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]));
|
||||
break;
|
||||
case 8:
|
||||
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7],
|
||||
"your@email.com", args[0]));
|
||||
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), args[7], "your@email.com", args[0]));
|
||||
break;
|
||||
case 9:
|
||||
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7],
|
||||
args[8], args[0]));
|
||||
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), args[7], args[8], args[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return auths;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return auths;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -172,103 +172,103 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllAuthsByEmail(String email) {
|
||||
public List<String> getAllAuthsByEmail(final String email) {
|
||||
BufferedReader br = null;
|
||||
List<String> countEmail = new ArrayList<>();
|
||||
final List<String> countEmail = new ArrayList<>();
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args.length > 8 && args[8].equals(email)) {
|
||||
countEmail.add(args[0]);
|
||||
}
|
||||
}
|
||||
return countEmail;
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllAuthsByIp(String ip) {
|
||||
public List<String> getAllAuthsByIp(final String ip) {
|
||||
BufferedReader br = null;
|
||||
List<String> countIp = new ArrayList<>();
|
||||
final List<String> countIp = new ArrayList<>();
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args.length > 3 && args[2].equals(ip)) {
|
||||
countIp.add(args[0]);
|
||||
}
|
||||
}
|
||||
return countIp;
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||
public List<String> getAllAuthsByName(final PlayerAuth auth) {
|
||||
BufferedReader br = null;
|
||||
List<String> countIp = new ArrayList<>();
|
||||
final List<String> countIp = new ArrayList<>();
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args.length > 3 && args[2].equals(auth.getIp())) {
|
||||
countIp.add(args[0]);
|
||||
}
|
||||
}
|
||||
return countIp;
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PlayerAuth getAuth(String user) {
|
||||
public synchronized PlayerAuth getAuth(final String user) {
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args[0].equalsIgnoreCase(user)) {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
@ -278,28 +278,28 @@ public class FlatFile implements DataSource {
|
||||
case 4:
|
||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]);
|
||||
case 7:
|
||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]),
|
||||
"unavailableworld", "your@email.com", args[0]);
|
||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]);
|
||||
case 8:
|
||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7],
|
||||
"your@email.com", args[0]);
|
||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), args[7], "your@email.com", args[0]);
|
||||
case 9:
|
||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7],
|
||||
args[8], args[0]);
|
||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), args[7], args[8], args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return null;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return null;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -307,30 +307,30 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIps(String ip) {
|
||||
public int getIps(final String ip) {
|
||||
BufferedReader br = null;
|
||||
int countIp = 0;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args.length > 3 && args[2].equals(ip)) {
|
||||
countIp++;
|
||||
}
|
||||
}
|
||||
return countIp;
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return 0;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return 0;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,28 +347,28 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAuthAvailable(String user) {
|
||||
public synchronized boolean isAuthAvailable(final String user) {
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args.length > 1 && args[0].equalsIgnoreCase(user)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -376,20 +376,20 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogged(String user) {
|
||||
public boolean isLogged(final String user) {
|
||||
return PlayerCache.getInstance().isAuthenticated(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void purgeBanned(List<String> banned) {
|
||||
public void purgeBanned(final List<String> banned) {
|
||||
BufferedReader br = null;
|
||||
BufferedWriter bw = null;
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
final ArrayList<String> lines = new ArrayList<>();
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
try {
|
||||
if (banned.contains(args[0])) {
|
||||
lines.add(line);
|
||||
@ -398,26 +398,26 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
}
|
||||
bw = new BufferedWriter(new FileWriter(source));
|
||||
for (String l : lines) {
|
||||
for (final String l : lines) {
|
||||
bw.write(l + "\n");
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
if (bw != null) {
|
||||
try {
|
||||
bw.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -425,16 +425,16 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int purgeDatabase(long until) {
|
||||
public int purgeDatabase(final long until) {
|
||||
BufferedReader br = null;
|
||||
BufferedWriter bw = null;
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
final ArrayList<String> lines = new ArrayList<>();
|
||||
int cleared = 0;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args.length >= 4) {
|
||||
if (Long.parseLong(args[3]) >= until) {
|
||||
lines.add(line);
|
||||
@ -444,26 +444,26 @@ public class FlatFile implements DataSource {
|
||||
cleared++;
|
||||
}
|
||||
bw = new BufferedWriter(new FileWriter(source));
|
||||
for (String l : lines) {
|
||||
for (final String l : lines) {
|
||||
bw.write(l + "\n");
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return cleared;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return cleared;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
if (bw != null) {
|
||||
try {
|
||||
bw.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -479,43 +479,43 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean removeAuth(String user) {
|
||||
public synchronized boolean removeAuth(final String user) {
|
||||
if (!isAuthAvailable(user)) {
|
||||
return false;
|
||||
}
|
||||
BufferedReader br = null;
|
||||
BufferedWriter bw = null;
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
final ArrayList<String> lines = new ArrayList<>();
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args.length > 1 && !args[0].equals(user)) {
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
bw = new BufferedWriter(new FileWriter(source));
|
||||
for (String l : lines) {
|
||||
for (final String l : lines) {
|
||||
bw.write(l + "\n");
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
if (bw != null) {
|
||||
try {
|
||||
bw.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -523,7 +523,7 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
||||
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
||||
if (isAuthAvailable(auth.getNickname())) {
|
||||
return false;
|
||||
}
|
||||
@ -532,14 +532,14 @@ public class FlatFile implements DataSource {
|
||||
bw = new BufferedWriter(new FileWriter(source, true));
|
||||
bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":"
|
||||
+ auth.getWorld() + ":" + auth.getEmail() + "\n");
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
if (bw != null) {
|
||||
try {
|
||||
bw.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -547,15 +547,15 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogged(String user) {
|
||||
public void setLogged(final String user) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(String user) {
|
||||
public void setUnlogged(final String user) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateEmail(PlayerAuth auth) {
|
||||
public boolean updateEmail(final PlayerAuth auth) {
|
||||
if (!isAuthAvailable(auth.getNickname())) {
|
||||
return false;
|
||||
}
|
||||
@ -565,24 +565,24 @@ public class FlatFile implements DataSource {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line = "";
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args[0].equals(auth.getNickname())) {
|
||||
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7],
|
||||
auth.getEmail(), args[0]);
|
||||
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth
|
||||
.getEmail(), args[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -594,15 +594,15 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(String oldone, String newone) {
|
||||
PlayerAuth auth = this.getAuth(oldone);
|
||||
public void updateName(final String oldone, final String newone) {
|
||||
final PlayerAuth auth = this.getAuth(oldone);
|
||||
auth.setName(newone);
|
||||
this.saveAuth(auth);
|
||||
this.removeAuth(oldone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updatePassword(PlayerAuth auth) {
|
||||
public synchronized boolean updatePassword(final PlayerAuth auth) {
|
||||
if (!isAuthAvailable(auth.getNickname())) {
|
||||
return false;
|
||||
}
|
||||
@ -612,7 +612,7 @@ public class FlatFile implements DataSource {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args[0].equals(auth.getNickname())) {
|
||||
switch (args.length) {
|
||||
case 4: {
|
||||
@ -620,18 +620,18 @@ public class FlatFile implements DataSource {
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]),
|
||||
"world", "your@email.com", args[0]);
|
||||
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), "world", "your@email.com", args[0]);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]),
|
||||
args[7], "your@email.com", args[0]);
|
||||
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), args[7], "your@email.com", args[0]);
|
||||
break;
|
||||
}
|
||||
case 9: {
|
||||
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]),
|
||||
args[7], args[8], args[0]);
|
||||
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), args[7], args[8], args[0]);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -642,17 +642,17 @@ public class FlatFile implements DataSource {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -664,7 +664,7 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||
public boolean updateQuitLoc(final PlayerAuth auth) {
|
||||
if (!isAuthAvailable(auth.getNickname())) {
|
||||
return false;
|
||||
}
|
||||
@ -674,23 +674,23 @@ public class FlatFile implements DataSource {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args[0].equalsIgnoreCase(auth.getNickname())) {
|
||||
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), args[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -702,12 +702,12 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSalt(PlayerAuth auth) {
|
||||
public boolean updateSalt(final PlayerAuth auth) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSession(PlayerAuth auth) {
|
||||
public boolean updateSession(final PlayerAuth auth) {
|
||||
if (!isAuthAvailable(auth.getNickname())) {
|
||||
return false;
|
||||
}
|
||||
@ -717,7 +717,7 @@ public class FlatFile implements DataSource {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
final String[] args = line.split(":");
|
||||
if (args[0].equalsIgnoreCase(auth.getNickname())) {
|
||||
switch (args.length) {
|
||||
case 4: {
|
||||
@ -725,18 +725,18 @@ public class FlatFile implements DataSource {
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world",
|
||||
"your@email.com", args[0]);
|
||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), "world", "your@email.com", args[0]);
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7],
|
||||
"your@email.com", args[0]);
|
||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), args[7], "your@email.com", args[0]);
|
||||
break;
|
||||
}
|
||||
case 9: {
|
||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7],
|
||||
args[8], args[0]);
|
||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double
|
||||
.parseDouble(args[6]), args[7], args[8], args[0]);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -747,17 +747,17 @@ public class FlatFile implements DataSource {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (final FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,29 +21,29 @@ import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class MySQL implements DataSource {
|
||||
|
||||
private String columnEmail;
|
||||
private String columnGroup;
|
||||
private String columnID;
|
||||
private String columnIp;
|
||||
private String columnLastLogin;
|
||||
private String columnLogged;
|
||||
private String columnName;
|
||||
private List<String> columnOthers;
|
||||
private String columnPassword;
|
||||
private String columnRealName;
|
||||
private String columnSalt;
|
||||
private String database;
|
||||
private final String columnEmail;
|
||||
private final String columnGroup;
|
||||
private final String columnID;
|
||||
private final String columnIp;
|
||||
private final String columnLastLogin;
|
||||
private final String columnLogged;
|
||||
private final String columnName;
|
||||
private final List<String> columnOthers;
|
||||
private final String columnPassword;
|
||||
private final String columnRealName;
|
||||
private final String columnSalt;
|
||||
private final String database;
|
||||
private HikariDataSource ds;
|
||||
private String host;
|
||||
private String lastlocWorld;
|
||||
private String lastlocX;
|
||||
private String lastlocY;
|
||||
private String lastlocZ;
|
||||
private int maxConnections;
|
||||
private String password;
|
||||
private String port;
|
||||
private String tableName;
|
||||
private String username;
|
||||
private final String host;
|
||||
private final String lastlocWorld;
|
||||
private final String lastlocX;
|
||||
private final String lastlocY;
|
||||
private final String lastlocZ;
|
||||
private final int maxConnections;
|
||||
private final String password;
|
||||
private final String port;
|
||||
private final String tableName;
|
||||
private final String username;
|
||||
|
||||
public MySQL() throws ClassNotFoundException, SQLException, PoolInitializationException {
|
||||
this.host = Settings.getMySQLHost;
|
||||
@ -72,38 +72,34 @@ public class MySQL implements DataSource {
|
||||
// Set the connection arguments (and check if connection is ok)
|
||||
try {
|
||||
this.setConnectionArguments();
|
||||
} catch (RuntimeException e) {
|
||||
} catch (final RuntimeException e) {
|
||||
if (e instanceof IllegalArgumentException) {
|
||||
ConsoleLogger.showError("Invalid database arguments! Please check your configuration!");
|
||||
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||
throw new IllegalArgumentException(e);
|
||||
ConsoleLogger.showError("错误的数据库信息! 请检查您的配置是否正确!");
|
||||
}
|
||||
if (e instanceof PoolInitializationException) {
|
||||
ConsoleLogger.showError("Can't initialize database connection! Please check your configuration!");
|
||||
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||
throw new PoolInitializationException(e);
|
||||
ConsoleLogger.showError("无法初始化数据库连接池! 请检查您的配置是否正确!");
|
||||
}
|
||||
ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer! SHUTDOWN...");
|
||||
ConsoleLogger.showError("MySQL数据库加载失败! 如果你认为配置文件没问题 请报告此错误给开发者! 关闭服务器...");
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Initialize the database
|
||||
try {
|
||||
this.setupConnection();
|
||||
} catch (SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
this.close();
|
||||
ConsoleLogger.showError("Can't initialize the MySQL database... Please check your database settings in the config.yml file! SHUTDOWN...");
|
||||
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||
ConsoleLogger.showError("无法初始化 MySQL 数据库连接池... 请检查您的配置是否正确! 关闭服务器...");
|
||||
ConsoleLogger.showError("如果你认为配置文件没问题 请报告此错误给开发者! 关闭服务器...");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> autoPurgeDatabase(long until) {
|
||||
public synchronized List<String> autoPurgeDatabase(final long until) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> list = new ArrayList<>();
|
||||
final List<String> list = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||
@ -117,7 +113,7 @@ public class MySQL implements DataSource {
|
||||
pst.setLong(1, until);
|
||||
pst.executeUpdate();
|
||||
return list;
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
@ -129,8 +125,9 @@ public class MySQL implements DataSource {
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
if (ds != null)
|
||||
if (ds != null) {
|
||||
ds.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,7 +143,7 @@ public class MySQL implements DataSource {
|
||||
if (rs != null && rs.next()) {
|
||||
result = rs.getInt(1);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} finally {
|
||||
@ -158,7 +155,7 @@ public class MySQL implements DataSource {
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getAllAuths() {
|
||||
List<PlayerAuth> auths = new ArrayList<>();
|
||||
final List<PlayerAuth> auths = new ArrayList<>();
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -168,22 +165,23 @@ public class MySQL implements DataSource {
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
PlayerAuth pAuth;
|
||||
int id = rs.getInt(columnID);
|
||||
final int id = rs.getInt(columnID);
|
||||
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY),
|
||||
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
|
||||
.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
} else {
|
||||
if (!columnSalt.isEmpty()) {
|
||||
if (!columnGroup.isEmpty())
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp),
|
||||
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail),
|
||||
rs.getString(columnRealName));
|
||||
else
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin),
|
||||
rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
if (!columnGroup.isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
|
||||
.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
|
||||
.getString(columnRealName));
|
||||
} else {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs
|
||||
.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
} else {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX),
|
||||
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
|
||||
.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
}
|
||||
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
|
||||
@ -192,15 +190,15 @@ public class MySQL implements DataSource {
|
||||
pst.setInt(1, id);
|
||||
rsid = pst.executeQuery();
|
||||
if (rsid.next()) {
|
||||
Blob blob = rsid.getBlob("data");
|
||||
byte[] bytes = blob.getBytes(1, (int) blob.length());
|
||||
final Blob blob = rsid.getBlob("data");
|
||||
final byte[] bytes = blob.getBytes(1, (int) blob.length());
|
||||
pAuth.setHash(new String(bytes));
|
||||
}
|
||||
rsid.close();
|
||||
}
|
||||
auths.add(pAuth);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return auths;
|
||||
} finally {
|
||||
@ -212,11 +210,11 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByEmail(String email) {
|
||||
public synchronized List<String> getAllAuthsByEmail(final String email) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countEmail = new ArrayList<>();
|
||||
final List<String> countEmail = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||
@ -226,7 +224,7 @@ public class MySQL implements DataSource {
|
||||
countEmail.add(rs.getString(columnName));
|
||||
}
|
||||
return countEmail;
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
@ -237,11 +235,11 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByIp(String ip) {
|
||||
public synchronized List<String> getAllAuthsByIp(final String ip) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countIp = new ArrayList<>();
|
||||
final List<String> countIp = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||
@ -251,7 +249,7 @@ public class MySQL implements DataSource {
|
||||
countIp.add(rs.getString(columnName));
|
||||
}
|
||||
return countIp;
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
@ -262,11 +260,11 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||
public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countIp = new ArrayList<>();
|
||||
final List<String> countIp = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||
@ -276,7 +274,7 @@ public class MySQL implements DataSource {
|
||||
countIp.add(rs.getString(columnName));
|
||||
}
|
||||
return countIp;
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
@ -287,7 +285,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PlayerAuth getAuth(String user) {
|
||||
public synchronized PlayerAuth getAuth(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -301,20 +299,22 @@ public class MySQL implements DataSource {
|
||||
if (rs.next()) {
|
||||
id = rs.getInt(columnID);
|
||||
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX),
|
||||
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
|
||||
.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
} else {
|
||||
if (!columnSalt.isEmpty()) {
|
||||
if (!columnGroup.isEmpty())
|
||||
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp),
|
||||
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail),
|
||||
rs.getString(columnRealName));
|
||||
else
|
||||
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin),
|
||||
rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
if (!columnGroup.isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
|
||||
.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
|
||||
.getString(columnRealName));
|
||||
} else {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs
|
||||
.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
|
||||
.getString(columnRealName));
|
||||
}
|
||||
} else {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX),
|
||||
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
|
||||
.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
}
|
||||
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
|
||||
@ -324,15 +324,15 @@ public class MySQL implements DataSource {
|
||||
pst.setInt(1, id);
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
Blob blob = rs.getBlob("data");
|
||||
byte[] bytes = blob.getBytes(1, (int) blob.length());
|
||||
final Blob blob = rs.getBlob("data");
|
||||
final byte[] bytes = blob.getBytes(1, (int) blob.length());
|
||||
pAuth.setHash(new String(bytes));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return null;
|
||||
} finally {
|
||||
@ -344,7 +344,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getIps(String ip) {
|
||||
public synchronized int getIps(final String ip) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -358,7 +358,7 @@ public class MySQL implements DataSource {
|
||||
countIp++;
|
||||
}
|
||||
return countIp;
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return 0;
|
||||
} finally {
|
||||
@ -370,7 +370,7 @@ public class MySQL implements DataSource {
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getLoggedPlayers() {
|
||||
List<PlayerAuth> auths = new ArrayList<>();
|
||||
final List<PlayerAuth> auths = new ArrayList<>();
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -380,22 +380,23 @@ public class MySQL implements DataSource {
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
PlayerAuth pAuth;
|
||||
int id = rs.getInt(columnID);
|
||||
final int id = rs.getInt(columnID);
|
||||
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY),
|
||||
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
|
||||
.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
} else {
|
||||
if (!columnSalt.isEmpty()) {
|
||||
if (!columnGroup.isEmpty())
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp),
|
||||
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail),
|
||||
rs.getString(columnRealName));
|
||||
else
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin),
|
||||
rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
if (!columnGroup.isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
|
||||
.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
|
||||
.getString(columnRealName));
|
||||
} else {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs
|
||||
.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
} else {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX),
|
||||
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
|
||||
.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
}
|
||||
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
|
||||
@ -404,15 +405,15 @@ public class MySQL implements DataSource {
|
||||
pst.setInt(1, id);
|
||||
rsid = pst.executeQuery();
|
||||
if (rsid.next()) {
|
||||
Blob blob = rsid.getBlob("data");
|
||||
byte[] bytes = blob.getBytes(1, (int) blob.length());
|
||||
final Blob blob = rsid.getBlob("data");
|
||||
final byte[] bytes = blob.getBytes(1, (int) blob.length());
|
||||
pAuth.setHash(new String(bytes));
|
||||
}
|
||||
rsid.close();
|
||||
}
|
||||
auths.add(pAuth);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return auths;
|
||||
} finally {
|
||||
@ -429,7 +430,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAuthAvailable(String user) {
|
||||
public synchronized boolean isAuthAvailable(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -439,7 +440,7 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, user);
|
||||
rs = pst.executeQuery();
|
||||
return rs.next();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -450,7 +451,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogged(String user) {
|
||||
public boolean isLogged(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -459,9 +460,10 @@ public class MySQL implements DataSource {
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||
pst.setString(1, user);
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next())
|
||||
if (rs.next()) {
|
||||
return (rs.getInt(columnLogged) == 1);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -473,17 +475,17 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void purgeBanned(List<String> banned) {
|
||||
public synchronized void purgeBanned(final List<String> banned) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
for (String name : banned) {
|
||||
for (final String name : banned) {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||
pst.setString(1, name);
|
||||
pst.executeUpdate();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -492,7 +494,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int purgeDatabase(long until) {
|
||||
public synchronized int purgeDatabase(final long until) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -500,7 +502,7 @@ public class MySQL implements DataSource {
|
||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||
pst.setLong(1, until);
|
||||
return pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return 0;
|
||||
} finally {
|
||||
@ -519,7 +521,7 @@ public class MySQL implements DataSource {
|
||||
pst.setInt(1, 0);
|
||||
pst.setInt(2, 1);
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -531,19 +533,20 @@ public class MySQL implements DataSource {
|
||||
public void reload() {
|
||||
try {
|
||||
reloadArguments();
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN...");
|
||||
ConsoleLogger.showError("无法再次连接到 MySQL 数据库... 请检查您 MySQL 数据库服务器是否正常 ! 关闭服务器...");
|
||||
if (Settings.isStopEnabled) {
|
||||
AuthMe.getInstance().getServer().shutdown();
|
||||
}
|
||||
if (!Settings.isStopEnabled)
|
||||
if (!Settings.isStopEnabled) {
|
||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean removeAuth(String user) {
|
||||
public synchronized boolean removeAuth(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -557,18 +560,19 @@ public class MySQL implements DataSource {
|
||||
if (rs.next()) {
|
||||
id = rs.getInt(columnID);
|
||||
// Remove data
|
||||
PreparedStatement pst2 = con.prepareStatement("DELETE FROM xf_user_authenticate WHERE " + columnID + "=?;");
|
||||
final PreparedStatement pst2 = con.prepareStatement("DELETE FROM xf_user_authenticate WHERE " + columnID + "=?;");
|
||||
pst2.setInt(1, id);
|
||||
pst2.executeUpdate();
|
||||
pst2.close();
|
||||
}
|
||||
}
|
||||
if (pst != null && !pst.isClosed())
|
||||
if (pst != null && !pst.isClosed()) {
|
||||
pst.close();
|
||||
}
|
||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||
pst.setString(1, user);
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -579,7 +583,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
||||
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -608,7 +612,7 @@ public class MySQL implements DataSource {
|
||||
pst.close();
|
||||
}
|
||||
if (!columnOthers.isEmpty()) {
|
||||
for (String column : columnOthers) {
|
||||
for (final String column : columnOthers) {
|
||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;");
|
||||
pst.setString(1, auth.getRealName());
|
||||
pst.setString(2, auth.getNickname());
|
||||
@ -617,11 +621,11 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
}
|
||||
if (Settings.getPasswordHash == HashAlgorithm.PHPBB) {
|
||||
PreparedStatement pst2 = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;");
|
||||
final PreparedStatement pst2 = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;");
|
||||
pst2.setString(1, auth.getNickname());
|
||||
rs = pst2.executeQuery();
|
||||
if (rs.next()) {
|
||||
int id = rs.getInt(columnID);
|
||||
final int id = rs.getInt(columnID);
|
||||
// Insert player in phpbb_user_group
|
||||
pst = con.prepareStatement("INSERT INTO " + Settings.getPhpbbPrefix + "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);");
|
||||
pst.setInt(1, Settings.getPhpbbGroup);
|
||||
@ -643,7 +647,7 @@ public class MySQL implements DataSource {
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
// Get current time without ms
|
||||
long time = System.currentTimeMillis() / 1000;
|
||||
final long time = System.currentTimeMillis() / 1000;
|
||||
// Update user_regdate
|
||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + tableName + ".user_regdate=? WHERE " + columnName + "=?;");
|
||||
pst.setLong(1, time);
|
||||
@ -669,7 +673,7 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, auth.getNickname());
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
int id = rs.getInt(columnID);
|
||||
final int id = rs.getInt(columnID);
|
||||
// First Name
|
||||
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
|
||||
pst.setInt(1, id);
|
||||
@ -762,20 +766,20 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, auth.getNickname());
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
int id = rs.getInt(columnID);
|
||||
final int id = rs.getInt(columnID);
|
||||
// Insert password in the correct table
|
||||
pst = con.prepareStatement("INSERT INTO xf_user_authenticate (user_id, scheme_class, data) VALUES (?,?,?);");
|
||||
pst.setInt(1, id);
|
||||
pst.setString(2, "XenForo_Authentication_Core12");
|
||||
byte[] bytes = auth.getHash().getBytes();
|
||||
Blob blob = con.createBlob();
|
||||
final byte[] bytes = auth.getHash().getBytes();
|
||||
final Blob blob = con.createBlob();
|
||||
blob.setBytes(1, bytes);
|
||||
pst.setBlob(3, blob);
|
||||
pst.executeUpdate();
|
||||
}
|
||||
rs.close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -787,7 +791,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogged(String user) {
|
||||
public void setLogged(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -796,7 +800,7 @@ public class MySQL implements DataSource {
|
||||
pst.setInt(1, 1);
|
||||
pst.setString(2, user);
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -805,26 +809,27 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(String user) {
|
||||
public void setUnlogged(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
if (user != null)
|
||||
if (user != null) {
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||
pst.setInt(1, 0);
|
||||
pst.setString(2, user);
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
close(con);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateEmail(PlayerAuth auth) {
|
||||
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -833,7 +838,7 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, auth.getEmail());
|
||||
pst.setString(2, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -844,7 +849,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(String oldone, String newone) {
|
||||
public void updateName(final String oldone, final String newone) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -853,7 +858,7 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, newone);
|
||||
pst.setString(2, oldone);
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -862,7 +867,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updatePassword(PlayerAuth auth) {
|
||||
public synchronized boolean updatePassword(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -878,11 +883,11 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, auth.getNickname());
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
int id = rs.getInt(columnID);
|
||||
final int id = rs.getInt(columnID);
|
||||
// Insert password in the correct table
|
||||
pst = con.prepareStatement("UPDATE xf_user_authenticate SET data=? WHERE " + columnID + "=?;");
|
||||
byte[] bytes = auth.getHash().getBytes();
|
||||
Blob blob = con.createBlob();
|
||||
final byte[] bytes = auth.getHash().getBytes();
|
||||
final Blob blob = con.createBlob();
|
||||
blob.setBytes(1, bytes);
|
||||
pst.setBlob(1, blob);
|
||||
pst.setInt(2, id);
|
||||
@ -894,7 +899,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
rs.close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -906,7 +911,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateQuitLoc(PlayerAuth auth) {
|
||||
public synchronized boolean updateQuitLoc(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -918,7 +923,7 @@ public class MySQL implements DataSource {
|
||||
pst.setString(4, auth.getWorld());
|
||||
pst.setString(5, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -929,7 +934,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateSalt(PlayerAuth auth) {
|
||||
public synchronized boolean updateSalt(final PlayerAuth auth) {
|
||||
if (columnSalt.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -941,7 +946,7 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, auth.getSalt());
|
||||
pst.setString(2, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -952,7 +957,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateSession(PlayerAuth auth) {
|
||||
public synchronized boolean updateSession(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -963,7 +968,7 @@ public class MySQL implements DataSource {
|
||||
pst.setString(3, auth.getRealName());
|
||||
pst.setString(4, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -973,11 +978,11 @@ public class MySQL implements DataSource {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void close(AutoCloseable o) {
|
||||
private void close(final AutoCloseable o) {
|
||||
if (o != null) {
|
||||
try {
|
||||
o.close();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
@ -998,7 +1003,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
private synchronized void setConnectionArguments() throws ClassNotFoundException, IllegalArgumentException {
|
||||
HikariConfig config = new HikariConfig();
|
||||
final HikariConfig config = new HikariConfig();
|
||||
config.setPoolName("AuthMeMYSQLPool");
|
||||
config.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
||||
@ -1079,7 +1084,7 @@ public class MySQL implements DataSource {
|
||||
close(st);
|
||||
close(con);
|
||||
}
|
||||
ConsoleLogger.info("MySQL Setup finished");
|
||||
ConsoleLogger.info("MySQL 数据表已初始化并载入完毕...");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -672,6 +672,6 @@ public class SQLite implements DataSource {
|
||||
close(rs);
|
||||
close(st);
|
||||
}
|
||||
ConsoleLogger.info("SQLite 数据表已初始化并载入完毕...");
|
||||
ConsoleLogger.info("SQLite 数据库已初始化并载入完毕...");
|
||||
}
|
||||
}
|
||||
|
@ -18,23 +18,23 @@ import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class SQLite_HIKARI implements DataSource {
|
||||
|
||||
private String columnEmail;
|
||||
private String columnGroup;
|
||||
private String columnID;
|
||||
private String columnIp;
|
||||
private String columnLastLogin;
|
||||
private String columnLogged;
|
||||
private String columnName;
|
||||
private String columnPassword;
|
||||
private String columnRealName;
|
||||
private String columnSalt;
|
||||
private String database;
|
||||
private final String columnEmail;
|
||||
private final String columnGroup;
|
||||
private final String columnID;
|
||||
private final String columnIp;
|
||||
private final String columnLastLogin;
|
||||
private final String columnLogged;
|
||||
private final String columnName;
|
||||
private final String columnPassword;
|
||||
private final String columnRealName;
|
||||
private final String columnSalt;
|
||||
private final String database;
|
||||
private HikariDataSource ds;
|
||||
private String lastlocWorld;
|
||||
private String lastlocX;
|
||||
private String lastlocY;
|
||||
private String lastlocZ;
|
||||
private String tableName;
|
||||
private final String lastlocWorld;
|
||||
private final String lastlocX;
|
||||
private final String lastlocY;
|
||||
private final String lastlocZ;
|
||||
private final String tableName;
|
||||
|
||||
public SQLite_HIKARI() throws ClassNotFoundException, SQLException {
|
||||
this.database = Settings.getMySQLDatabase;
|
||||
@ -57,28 +57,28 @@ public class SQLite_HIKARI implements DataSource {
|
||||
// Set the connection arguments
|
||||
try {
|
||||
this.setConnectionArguments();
|
||||
} catch (RuntimeException rt) {
|
||||
ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer!");
|
||||
} catch (final RuntimeException rt) {
|
||||
ConsoleLogger.showError("无法初始化数据库连接池! 请报告此错误给开发者!");
|
||||
throw rt;
|
||||
}
|
||||
|
||||
// Initialize the database
|
||||
try {
|
||||
this.setupConnection();
|
||||
} catch (SQLException e) {
|
||||
} catch (final SQLException e) {
|
||||
this.close();
|
||||
ConsoleLogger.showError("Can't initialize the SQLite database... Please check your database settings in the config.yml file! SHUTDOWN...");
|
||||
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||
ConsoleLogger.showError("无法初始化 Hikari SQLite 数据库连接池... 请检查您的配置是否正确! 关闭服务器...");
|
||||
ConsoleLogger.showError("如果你认为配置文件没问题 请报告此错误给开发者! 关闭服务器...");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> autoPurgeDatabase(long until) {
|
||||
public List<String> autoPurgeDatabase(final long until) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> list = new ArrayList<>();
|
||||
final List<String> list = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||
@ -88,7 +88,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
list.add(rs.getString(columnName));
|
||||
}
|
||||
return list;
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
@ -100,8 +100,9 @@ public class SQLite_HIKARI implements DataSource {
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
if (ds != null)
|
||||
if (ds != null) {
|
||||
ds.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -117,7 +118,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
if (rs != null && rs.next()) {
|
||||
result = rs.getInt(1);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} finally {
|
||||
@ -132,7 +133,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs;
|
||||
List<PlayerAuth> auths = new ArrayList<>();
|
||||
final List<PlayerAuth> auths = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
||||
@ -140,21 +141,21 @@ public class SQLite_HIKARI implements DataSource {
|
||||
while (rs.next()) {
|
||||
PlayerAuth pAuth;
|
||||
if (rs.getString(columnIp).isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY),
|
||||
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
|
||||
.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
} else {
|
||||
if (!columnSalt.isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp),
|
||||
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail),
|
||||
rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
|
||||
.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
|
||||
.getString(columnRealName));
|
||||
} else {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX),
|
||||
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
|
||||
.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
}
|
||||
auths.add(pAuth);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return auths;
|
||||
} finally {
|
||||
@ -165,11 +166,11 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllAuthsByEmail(String email) {
|
||||
public List<String> getAllAuthsByEmail(final String email) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countEmail = new ArrayList<>();
|
||||
final List<String> countEmail = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||
@ -179,10 +180,10 @@ public class SQLite_HIKARI implements DataSource {
|
||||
countEmail.add(rs.getString(columnName));
|
||||
}
|
||||
return countEmail;
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} catch (NullPointerException npe) {
|
||||
} catch (final NullPointerException npe) {
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
close(rs);
|
||||
@ -192,11 +193,11 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllAuthsByIp(String ip) {
|
||||
public List<String> getAllAuthsByIp(final String ip) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countIp = new ArrayList<>();
|
||||
final List<String> countIp = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||
@ -206,10 +207,10 @@ public class SQLite_HIKARI implements DataSource {
|
||||
countIp.add(rs.getString(columnName));
|
||||
}
|
||||
return countIp;
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} catch (NullPointerException npe) {
|
||||
} catch (final NullPointerException npe) {
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
close(rs);
|
||||
@ -219,11 +220,11 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||
public List<String> getAllAuthsByName(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countIp = new ArrayList<>();
|
||||
final List<String> countIp = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||
@ -233,10 +234,10 @@ public class SQLite_HIKARI implements DataSource {
|
||||
countIp.add(rs.getString(columnName));
|
||||
}
|
||||
return countIp;
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} catch (NullPointerException npe) {
|
||||
} catch (final NullPointerException npe) {
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
close(rs);
|
||||
@ -246,7 +247,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PlayerAuth getAuth(String user) {
|
||||
public synchronized PlayerAuth getAuth(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -257,22 +258,22 @@ public class SQLite_HIKARI implements DataSource {
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next()) {
|
||||
if (rs.getString(columnIp).isEmpty()) {
|
||||
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY),
|
||||
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
|
||||
.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
} else {
|
||||
if (!columnSalt.isEmpty()) {
|
||||
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp),
|
||||
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail),
|
||||
rs.getString(columnRealName));
|
||||
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
|
||||
.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
|
||||
.getString(columnRealName));
|
||||
} else {
|
||||
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX),
|
||||
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
|
||||
.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return null;
|
||||
} finally {
|
||||
@ -283,7 +284,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIps(String ip) {
|
||||
public int getIps(final String ip) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -297,7 +298,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
countIp++;
|
||||
}
|
||||
return countIp;
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return 0;
|
||||
} finally {
|
||||
@ -312,7 +313,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs;
|
||||
List<PlayerAuth> auths = new ArrayList<>();
|
||||
final List<PlayerAuth> auths = new ArrayList<>();
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
||||
@ -320,21 +321,21 @@ public class SQLite_HIKARI implements DataSource {
|
||||
while (rs.next()) {
|
||||
PlayerAuth pAuth;
|
||||
if (rs.getString(columnIp).isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY),
|
||||
rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs
|
||||
.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
} else {
|
||||
if (!columnSalt.isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp),
|
||||
rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail),
|
||||
rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs
|
||||
.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
|
||||
.getString(columnRealName));
|
||||
} else {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX),
|
||||
rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs
|
||||
.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
}
|
||||
auths.add(pAuth);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -349,7 +350,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAuthAvailable(String user) {
|
||||
public synchronized boolean isAuthAvailable(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -359,7 +360,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setString(1, user);
|
||||
rs = pst.executeQuery();
|
||||
return rs.next();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -370,7 +371,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogged(String user) {
|
||||
public boolean isLogged(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
@ -379,9 +380,10 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||
pst.setString(1, user);
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next())
|
||||
if (rs.next()) {
|
||||
return (rs.getInt(columnLogged) == 1);
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -393,17 +395,17 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void purgeBanned(List<String> banned) {
|
||||
public void purgeBanned(final List<String> banned) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
con = getConnection();
|
||||
for (String name : banned) {
|
||||
for (final String name : banned) {
|
||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
|
||||
pst.setString(1, name);
|
||||
pst.executeUpdate();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -412,7 +414,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int purgeDatabase(long until) {
|
||||
public int purgeDatabase(final long until) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -420,7 +422,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||
pst.setLong(1, until);
|
||||
return pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return 0;
|
||||
} finally {
|
||||
@ -439,7 +441,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setInt(1, 0);
|
||||
pst.setInt(2, 1);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -451,19 +453,20 @@ public class SQLite_HIKARI implements DataSource {
|
||||
public void reload() {
|
||||
try {
|
||||
reloadArguments();
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
ConsoleLogger.showError("Can't reconnect to SQLite database... Please check your SQLite informations ! SHUTDOWN...");
|
||||
if (Settings.isStopEnabled) {
|
||||
AuthMe.getInstance().getServer().shutdown();
|
||||
}
|
||||
if (!Settings.isStopEnabled)
|
||||
if (!Settings.isStopEnabled) {
|
||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean removeAuth(String user) {
|
||||
public synchronized boolean removeAuth(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -471,7 +474,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
|
||||
pst.setString(1, user);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -482,7 +485,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
||||
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -507,7 +510,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setString(6, auth.getRealName());
|
||||
pst.executeUpdate();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -518,7 +521,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogged(String user) {
|
||||
public void setLogged(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -527,7 +530,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setInt(1, 1);
|
||||
pst.setString(2, user);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -536,26 +539,27 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(String user) {
|
||||
public void setUnlogged(final String user) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
if (user != null)
|
||||
if (user != null) {
|
||||
try {
|
||||
con = getConnection();
|
||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||
pst.setInt(1, 0);
|
||||
pst.setString(2, user);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
close(con);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateEmail(PlayerAuth auth) {
|
||||
public boolean updateEmail(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -564,7 +568,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setString(1, auth.getEmail());
|
||||
pst.setString(2, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -575,7 +579,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(String oldone, String newone) {
|
||||
public void updateName(final String oldone, final String newone) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -584,7 +588,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setString(1, newone);
|
||||
pst.setString(2, oldone);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} finally {
|
||||
close(pst);
|
||||
@ -593,7 +597,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updatePassword(PlayerAuth auth) {
|
||||
public synchronized boolean updatePassword(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -602,7 +606,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setString(1, auth.getHash());
|
||||
pst.setString(2, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -613,7 +617,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||
public boolean updateQuitLoc(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -625,7 +629,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setString(4, auth.getWorld());
|
||||
pst.setString(5, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -636,7 +640,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSalt(PlayerAuth auth) {
|
||||
public boolean updateSalt(final PlayerAuth auth) {
|
||||
if (columnSalt.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -648,7 +652,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setString(1, auth.getSalt());
|
||||
pst.setString(2, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -659,7 +663,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSession(PlayerAuth auth) {
|
||||
public boolean updateSession(final PlayerAuth auth) {
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
@ -670,7 +674,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
pst.setString(3, auth.getRealName());
|
||||
pst.setString(4, auth.getNickname());
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
@ -680,11 +684,11 @@ public class SQLite_HIKARI implements DataSource {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void close(AutoCloseable o) {
|
||||
private void close(final AutoCloseable o) {
|
||||
if (o != null) {
|
||||
try {
|
||||
o.close();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
@ -703,7 +707,7 @@ public class SQLite_HIKARI implements DataSource {
|
||||
}
|
||||
|
||||
private synchronized void setConnectionArguments() throws RuntimeException {
|
||||
HikariConfig config = new HikariConfig();
|
||||
final HikariConfig config = new HikariConfig();
|
||||
config.setPoolName("AuthMeSQLitePool");
|
||||
config.setDriverClassName("org.sqlite.JDBC"); // RuntimeException
|
||||
config.setJdbcUrl("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
||||
|
@ -31,13 +31,13 @@ import fr.xephi.authme.task.TimeoutTask;
|
||||
|
||||
public class AsyncronousJoin {
|
||||
|
||||
private Messages m = Messages.getInstance();
|
||||
private final Messages m = Messages.getInstance();
|
||||
protected DataSource database;
|
||||
protected String name;
|
||||
protected Player player;
|
||||
protected AuthMe plugin;
|
||||
|
||||
public AsyncronousJoin(Player player, AuthMe plugin, DataSource database) {
|
||||
public AsyncronousJoin(final Player player, final AuthMe plugin, final DataSource database) {
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
@ -45,10 +45,11 @@ public class AsyncronousJoin {
|
||||
}
|
||||
|
||||
public void process() {
|
||||
if (AuthMePlayerListener.gameMode.containsKey(name))
|
||||
if (AuthMePlayerListener.gameMode.containsKey(name)) {
|
||||
AuthMePlayerListener.gameMode.remove(name);
|
||||
}
|
||||
AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode());
|
||||
BukkitScheduler sched = plugin.getServer().getScheduler();
|
||||
final BukkitScheduler sched = plugin.getServer().getScheduler();
|
||||
|
||||
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
@ -68,8 +69,9 @@ public class AsyncronousJoin {
|
||||
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
|
||||
player.setGameMode(gM);
|
||||
player.kickPlayer("You are not the Owner of this account, please try another name!");
|
||||
if (Settings.banUnsafeIp)
|
||||
if (Settings.banUnsafeIp) {
|
||||
plugin.getServer().banIP(ip);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@ -81,7 +83,7 @@ public class AsyncronousJoin {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
player.kickPlayer("A player with the same IP is already in game!");
|
||||
player.kickPlayer("§c同一个IP只允许一个玩家进入!");
|
||||
}
|
||||
|
||||
});
|
||||
@ -102,34 +104,37 @@ public class AsyncronousJoin {
|
||||
|
||||
});
|
||||
}
|
||||
if (!Settings.noTeleport)
|
||||
if (!Settings.noTeleport) {
|
||||
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
||||
final SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (player.isOnline() && tpEvent.getTo() != null) {
|
||||
if (tpEvent.getTo().getWorld() != null)
|
||||
if (tpEvent.getTo().getWorld() != null) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
placePlayerSafely(player, spawnLoc);
|
||||
LimboCache.getInstance().updateLimboPlayer(player);
|
||||
// protect inventory
|
||||
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
|
||||
ProtectInventoryEvent ev = new ProtectInventoryEvent(player);
|
||||
final ProtectInventoryEvent ev = new ProtectInventoryEvent(player);
|
||||
plugin.getServer().getPluginManager().callEvent(ev);
|
||||
if (ev.isCancelled()) {
|
||||
plugin.inventoryProtector.sendInventoryPacket(player);
|
||||
if (!Settings.noConsoleSpam)
|
||||
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
|
||||
if (!Settings.noConsoleSpam) {
|
||||
ConsoleLogger.info("玩家 " + player.getName() + " 的背包保护事件已被取消...");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -150,23 +155,25 @@ public class AsyncronousJoin {
|
||||
if (!Settings.isForcedRegistrationEnabled) {
|
||||
return;
|
||||
}
|
||||
if (!Settings.noTeleport)
|
||||
if (!Settings.noTeleport) {
|
||||
if (!needFirstspawn() && Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
||||
final SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (player.isOnline() && tpEvent.getTo() != null) {
|
||||
if (tpEvent.getTo().getWorld() != null)
|
||||
if (tpEvent.getTo().getWorld() != null) {
|
||||
player.teleport(tpEvent.getTo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
String[] msg;
|
||||
@ -175,16 +182,18 @@ public class AsyncronousJoin {
|
||||
} else {
|
||||
msg = isAuthAvailable ? m.send("login_msg") : m.send("reg_msg");
|
||||
}
|
||||
int time = Settings.getRegistrationTimeout * 20;
|
||||
int msgInterval = Settings.getWarnMessageInterval;
|
||||
final int time = Settings.getRegistrationTimeout * 20;
|
||||
final int msgInterval = Settings.getWarnMessageInterval;
|
||||
if (time != 0) {
|
||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time);
|
||||
if (!LimboCache.getInstance().hasLimboPlayer(name))
|
||||
final BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time);
|
||||
if (!LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||
}
|
||||
if (!LimboCache.getInstance().hasLimboPlayer(name))
|
||||
if (!LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
}
|
||||
if (isAuthAvailable) {
|
||||
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
|
||||
} else {
|
||||
@ -194,17 +203,20 @@ public class AsyncronousJoin {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (player.isOp())
|
||||
if (player.isOp()) {
|
||||
player.setOp(false);
|
||||
}
|
||||
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
|
||||
player.setAllowFlight(true);
|
||||
player.setFlying(true);
|
||||
}
|
||||
player.setNoDamageTicks(Settings.getRegistrationTimeout * 20);
|
||||
if (Settings.useEssentialsMotd)
|
||||
if (Settings.useEssentialsMotd) {
|
||||
player.performCommand("motd");
|
||||
if (Settings.applyBlindEffect)
|
||||
}
|
||||
if (Settings.applyBlindEffect) {
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||
}
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
player.setWalkSpeed(0.0f);
|
||||
player.setFlySpeed(0.0f);
|
||||
@ -213,10 +225,11 @@ public class AsyncronousJoin {
|
||||
|
||||
});
|
||||
if (Settings.isSessionsEnabled && isAuthAvailable && (PlayerCache.getInstance().isAuthenticated(name) || database.isLogged(name))) {
|
||||
if (plugin.sessions.containsKey(name))
|
||||
if (plugin.sessions.containsKey(name)) {
|
||||
plugin.sessions.get(name).cancel();
|
||||
}
|
||||
plugin.sessions.remove(name);
|
||||
PlayerAuth auth = database.getAuth(name);
|
||||
final PlayerAuth auth = database.getAuth(name);
|
||||
if (auth != null && auth.getIp().equals(ip)) {
|
||||
m.send(player, "valid_session");
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
@ -229,16 +242,18 @@ public class AsyncronousJoin {
|
||||
}
|
||||
return;
|
||||
}
|
||||
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
|
||||
final BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||
}
|
||||
|
||||
private boolean needFirstspawn() {
|
||||
if (player.hasPlayedBefore())
|
||||
if (player.hasPlayedBefore()) {
|
||||
return false;
|
||||
if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null)
|
||||
}
|
||||
if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null) {
|
||||
return false;
|
||||
FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), Spawn.getInstance().getFirstSpawn());
|
||||
}
|
||||
final FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), Spawn.getInstance().getFirstSpawn());
|
||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||
if (!tpEvent.isCancelled()) {
|
||||
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
|
||||
@ -259,25 +274,31 @@ public class AsyncronousJoin {
|
||||
|
||||
private void placePlayerSafely(final Player player, final Location spawnLoc) {
|
||||
Location loc = null;
|
||||
if (spawnLoc == null)
|
||||
if (spawnLoc == null) {
|
||||
return;
|
||||
if (!Settings.noTeleport)
|
||||
}
|
||||
if (!Settings.noTeleport) {
|
||||
return;
|
||||
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())))
|
||||
}
|
||||
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||
return;
|
||||
if (!player.hasPlayedBefore())
|
||||
}
|
||||
if (!player.hasPlayedBefore()) {
|
||||
return;
|
||||
Block b = player.getLocation().getBlock();
|
||||
}
|
||||
final Block b = player.getLocation().getBlock();
|
||||
if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL) {
|
||||
m.send(player, "unsafe_spawn");
|
||||
if (spawnLoc.getWorld() != null)
|
||||
if (spawnLoc.getWorld() != null) {
|
||||
loc = spawnLoc;
|
||||
}
|
||||
} else {
|
||||
Block c = player.getLocation().add(0D, 1D, 0D).getBlock();
|
||||
final Block c = player.getLocation().add(0D, 1D, 0D).getBlock();
|
||||
if (c.getType() == Material.PORTAL || c.getType() == Material.ENDER_PORTAL) {
|
||||
m.send(player, "unsafe_spawn");
|
||||
if (spawnLoc.getWorld() != null)
|
||||
if (spawnLoc.getWorld() != null) {
|
||||
loc = spawnLoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (loc != null) {
|
||||
|
@ -25,16 +25,16 @@ import fr.xephi.authme.task.MessageTask;
|
||||
public class AsyncronousLogin {
|
||||
|
||||
private static RandomString rdm = new RandomString(Settings.captchaLength);
|
||||
private DataSource database;
|
||||
private Messages m = Messages.getInstance();
|
||||
private AuthMe plugin;
|
||||
private final DataSource database;
|
||||
private final Messages m = Messages.getInstance();
|
||||
private final AuthMe plugin;
|
||||
protected boolean forceLogin;
|
||||
protected String name;
|
||||
protected String password;
|
||||
protected Player player;
|
||||
protected String realName;
|
||||
|
||||
public AsyncronousLogin(Player player, String password, boolean forceLogin, AuthMe plugin, DataSource data) {
|
||||
public AsyncronousLogin(final Player player, final String password, final boolean forceLogin, final AuthMe plugin, final DataSource data) {
|
||||
this.player = player;
|
||||
this.password = password;
|
||||
name = player.getName().toLowerCase();
|
||||
@ -44,27 +44,27 @@ public class AsyncronousLogin {
|
||||
this.database = data;
|
||||
}
|
||||
|
||||
public void displayOtherAccounts(PlayerAuth auth, Player p) {
|
||||
public void displayOtherAccounts(final PlayerAuth auth, final Player p) {
|
||||
if (!Settings.displayOtherAccounts) {
|
||||
return;
|
||||
}
|
||||
if (auth == null) {
|
||||
return;
|
||||
}
|
||||
List<String> auths = this.database.getAllAuthsByName(auth);
|
||||
final List<String> auths = this.database.getAllAuthsByName(auth);
|
||||
// List<String> uuidlist =
|
||||
// plugin.otherAccounts.getAllPlayersByUUID(player.getUniqueId());
|
||||
// plugin.otherAccounts.getAllPlayersByUUID(player);
|
||||
if (auths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (auths.size() == 1) {
|
||||
return;
|
||||
}
|
||||
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||
final StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||
// String uuidaccounts =
|
||||
// "[AuthMe] PlayerNames has %size% links to this UUID : ";
|
||||
int i = 0;
|
||||
for (String account : auths) {
|
||||
for (final String account : auths) {
|
||||
i++;
|
||||
message.append(account);
|
||||
if (i != auths.size()) {
|
||||
@ -79,9 +79,9 @@ public class AsyncronousLogin {
|
||||
* uuidaccounts = uuidaccounts + ", "; } else { uuidaccounts =
|
||||
* uuidaccounts + "."; } }
|
||||
*/
|
||||
for (Player player : Utils.getOnlinePlayers()) {
|
||||
for (final Player player : Utils.getOnlinePlayers()) {
|
||||
if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) {
|
||||
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts");
|
||||
player.sendMessage("[AuthMe] 当前玩家 " + auth.getNickname() + " 拥有 " + auths.size() + " 个账户!");
|
||||
player.sendMessage(message.toString());
|
||||
// player.sendMessage(uuidaccounts.replace("%size%",
|
||||
// ""+uuidlist.size()));
|
||||
@ -90,23 +90,25 @@ public class AsyncronousLogin {
|
||||
}
|
||||
|
||||
public void process() {
|
||||
PlayerAuth pAuth = preAuth();
|
||||
if (pAuth == null || needsCaptcha())
|
||||
final PlayerAuth pAuth = preAuth();
|
||||
if (pAuth == null || needsCaptcha()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String hash = pAuth.getHash();
|
||||
String email = pAuth.getEmail();
|
||||
final String hash = pAuth.getHash();
|
||||
final String email = pAuth.getEmail();
|
||||
boolean passwordVerified = true;
|
||||
if (!forceLogin)
|
||||
if (!forceLogin) {
|
||||
try {
|
||||
passwordVerified = PasswordSecurity.comparePasswordWithHash(password, hash, realName);
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
m.send(player, "error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (passwordVerified && player.isOnline()) {
|
||||
PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName);
|
||||
final PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName);
|
||||
database.updateSession(auth);
|
||||
|
||||
if (Settings.useCaptcha) {
|
||||
@ -119,39 +121,45 @@ public class AsyncronousLogin {
|
||||
}
|
||||
|
||||
player.setNoDamageTicks(0);
|
||||
if (!forceLogin)
|
||||
if (!forceLogin) {
|
||||
m.send(player, "login");
|
||||
}
|
||||
|
||||
displayOtherAccounts(auth, player);
|
||||
|
||||
if (Settings.recallEmail) {
|
||||
if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com"))
|
||||
if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) {
|
||||
m.send(player, "add_email");
|
||||
}
|
||||
}
|
||||
|
||||
if (!Settings.noConsoleSpam)
|
||||
ConsoleLogger.info(realName + " logged in!");
|
||||
if (!Settings.noConsoleSpam) {
|
||||
ConsoleLogger.info(realName + " 登陆成功!");
|
||||
}
|
||||
|
||||
// makes player isLoggedin via API
|
||||
PlayerCache.getInstance().addPlayer(auth);
|
||||
database.setLogged(name);
|
||||
plugin.otherAccounts.addPlayer(player.getUniqueId());
|
||||
plugin.otherAccounts.addPlayer(player.getName());
|
||||
|
||||
// As the scheduling executes the Task most likely after the current
|
||||
// task, we schedule it in the end
|
||||
// so that we can be sure, and have not to care if it might be
|
||||
// processed in other order.
|
||||
ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player, plugin, database);
|
||||
final ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player, plugin, database);
|
||||
if (syncronousPlayerLogin.getLimbo() != null) {
|
||||
if (syncronousPlayerLogin.getLimbo().getTimeoutTaskId() != null)
|
||||
if (syncronousPlayerLogin.getLimbo().getTimeoutTaskId() != null) {
|
||||
syncronousPlayerLogin.getLimbo().getTimeoutTaskId().cancel();
|
||||
if (syncronousPlayerLogin.getLimbo().getMessageTaskId() != null)
|
||||
}
|
||||
if (syncronousPlayerLogin.getLimbo().getMessageTaskId() != null) {
|
||||
syncronousPlayerLogin.getLimbo().getMessageTaskId().cancel();
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin);
|
||||
} else if (player.isOnline()) {
|
||||
if (!Settings.noConsoleSpam)
|
||||
ConsoleLogger.info(realName + " used the wrong password");
|
||||
if (!Settings.noConsoleSpam) {
|
||||
ConsoleLogger.info(realName + " 输入了错误的密码");
|
||||
}
|
||||
if (Settings.isKickOnWrongPasswordEnabled) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@ -167,7 +175,7 @@ public class AsyncronousLogin {
|
||||
m.send(player, "wrong_pwd");
|
||||
}
|
||||
} else {
|
||||
ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... ");
|
||||
ConsoleLogger.showError("玩家 " + name + " 在进行登陆流程时下线了, 已中断... ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,13 +188,13 @@ public class AsyncronousLogin {
|
||||
if (!plugin.captcha.containsKey(name)) {
|
||||
plugin.captcha.putIfAbsent(name, 1);
|
||||
} else {
|
||||
int i = plugin.captcha.get(name) + 1;
|
||||
final int i = plugin.captcha.get(name) + 1;
|
||||
plugin.captcha.remove(name);
|
||||
plugin.captcha.putIfAbsent(name, i);
|
||||
}
|
||||
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
|
||||
plugin.cap.put(name, rdm.nextString());
|
||||
for (String s : m.send("usage_captcha")) {
|
||||
for (final String s : m.send("usage_captcha")) {
|
||||
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name)));
|
||||
}
|
||||
return true;
|
||||
@ -217,7 +225,7 @@ public class AsyncronousLogin {
|
||||
} else {
|
||||
msg = m.send("reg_msg");
|
||||
}
|
||||
BukkitTask msgT = Bukkit.getScheduler().runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval));
|
||||
final BukkitTask msgT = Bukkit.getScheduler().runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval));
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||
}
|
||||
return null;
|
||||
@ -228,7 +236,7 @@ public class AsyncronousLogin {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
PlayerAuth pAuth = database.getAuth(name);
|
||||
final PlayerAuth pAuth = database.getAuth(name);
|
||||
if (pAuth == null) {
|
||||
m.send(player, "user_unknown");
|
||||
return null;
|
||||
@ -237,10 +245,11 @@ public class AsyncronousLogin {
|
||||
m.send(player, "vb_nonActiv");
|
||||
return null;
|
||||
}
|
||||
AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player);
|
||||
final AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.canLogin())
|
||||
if (!event.canLogin()) {
|
||||
return null;
|
||||
}
|
||||
return pAuth;
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,10 @@ public class AsyncronousRegister {
|
||||
PlayerAuth auth;
|
||||
try {
|
||||
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||
auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(),
|
||||
player.getLocation().getWorld().getName(), email, player.getName());
|
||||
auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player
|
||||
.getLocation()
|
||||
.getWorld()
|
||||
.getName(), email, player.getName());
|
||||
} catch (final NoSuchAlgorithmException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
m.send(player, "error");
|
||||
@ -107,7 +109,7 @@ public class AsyncronousRegister {
|
||||
PlayerCache.getInstance().addPlayer(auth);
|
||||
database.setLogged(name);
|
||||
}
|
||||
plugin.otherAccounts.addPlayer(player.getUniqueId());
|
||||
plugin.otherAccounts.addPlayer(player.getName());
|
||||
final ProcessSyncronousPasswordRegister syncronous = new ProcessSyncronousPasswordRegister(player, plugin);
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
||||
}
|
||||
|
@ -1,70 +1,57 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
|
||||
public class Messages {
|
||||
|
||||
private static Messages singleton = null;
|
||||
private final FileConfig config;
|
||||
private String lang = "zhcn";
|
||||
private final FileConfig msgcfg;
|
||||
|
||||
public Messages(final File file, final String lang) {
|
||||
config = new FileConfig(file);
|
||||
public Messages() {
|
||||
msgcfg = new FileConfig(AuthMe.getInstance(), "messages_zhcn.yml");
|
||||
singleton = this;
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public static Messages getInstance() {
|
||||
if (singleton == null) {
|
||||
singleton = new Messages(Settings.messageFile, Settings.messagesLanguage);
|
||||
singleton = new Messages();
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public String getString(final String string) {
|
||||
return config.getMessage(string);
|
||||
return msgcfg.getMessage(string);
|
||||
}
|
||||
|
||||
public void reloadMessages() {
|
||||
config.reload();
|
||||
msgcfg.reload();
|
||||
}
|
||||
|
||||
public void send(final CommandSender sender, final String msg) {
|
||||
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang)) {
|
||||
singleton.reloadMessages();
|
||||
}
|
||||
String loc = config.getMessage(msg);
|
||||
if (loc == null) {
|
||||
String loc = msgcfg.getMessage(msg);
|
||||
if (loc == null || loc.isEmpty()) {
|
||||
loc = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件";
|
||||
ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + config.getName() + " !");
|
||||
ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + msgcfg.getName() + " !");
|
||||
}
|
||||
for (final String l : loc.split("&n")) {
|
||||
sender.sendMessage(l.replace("&", "§"));
|
||||
sender.sendMessage(l);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] send(final String msg) {
|
||||
if (!Settings.messagesLanguage.equalsIgnoreCase(singleton.lang)) {
|
||||
singleton.reloadMessages();
|
||||
}
|
||||
final String s = config.getMessage(msg);
|
||||
if (s == null) {
|
||||
ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + config.getName() + " !");
|
||||
final String s = msgcfg.getMessage(msg);
|
||||
if (s == null || s.isEmpty()) {
|
||||
ConsoleLogger.showError("错误的语言文件 " + msg + " 请检查您的配置文件" + msgcfg.getName() + " !");
|
||||
final String[] loc = new String[1];
|
||||
loc[0] = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件";
|
||||
return (loc);
|
||||
}
|
||||
final int i = s.split("&n").length;
|
||||
final String[] loc = new String[i];
|
||||
int a;
|
||||
for (a = 0; a < i; a++) {
|
||||
loc[a] = config.getMessage(msg).split("&n")[a].replace("&", "§");
|
||||
}
|
||||
if (loc.length == 0) {
|
||||
loc[0] = "错误的语言文件 " + msg + " ; 请联系管理员升级语言文件";
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -8,19 +7,20 @@ import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class OtherAccounts extends CustomConfiguration {
|
||||
public class OtherAccounts extends FileConfig {
|
||||
|
||||
private static OtherAccounts others = null;
|
||||
|
||||
public OtherAccounts() {
|
||||
super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "otheraccounts.yml"));
|
||||
super(AuthMe.getInstance(), "otheraccounts.yml");
|
||||
others = this;
|
||||
load();
|
||||
save();
|
||||
}
|
||||
|
||||
public static OtherAccounts getInstance() {
|
||||
@ -30,40 +30,40 @@ public class OtherAccounts extends CustomConfiguration {
|
||||
return others;
|
||||
}
|
||||
|
||||
public void addPlayer(UUID uuid) {
|
||||
public void addPlayer(final String pname) {
|
||||
try {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null)
|
||||
final Player player = Bukkit.getPlayer(pname);
|
||||
if (player == null) {
|
||||
return;
|
||||
if (!this.getStringList(uuid.toString()).contains(player.getName())) {
|
||||
this.getStringList(uuid.toString()).add(player.getName());
|
||||
}
|
||||
if (!this.getStringList(pname).contains(player.getName())) {
|
||||
this.getStringList(pname).add(player.getName());
|
||||
save();
|
||||
}
|
||||
} catch (NoSuchMethodError | Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public void clear(UUID uuid) {
|
||||
set(uuid.toString(), new ArrayList<String>());
|
||||
public void clear(final String pname) {
|
||||
set(pname, new ArrayList<String>());
|
||||
save();
|
||||
}
|
||||
|
||||
public List<String> getAllPlayersByUUID(UUID uuid) {
|
||||
public List<String> getAllPlayersByUUID(final UUID uuid) {
|
||||
return this.getStringList(uuid.toString());
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
public void removePlayer(final String pname) {
|
||||
try {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null)
|
||||
final Player player = Bukkit.getPlayer(pname);
|
||||
if (player == null) {
|
||||
return;
|
||||
if (this.getStringList(uuid.toString()).contains(player.getName())) {
|
||||
this.getStringList(uuid.toString()).remove(player.getName());
|
||||
}
|
||||
if (this.getStringList(pname).contains(player.getName())) {
|
||||
this.getStringList(pname).remove(player.getName());
|
||||
save();
|
||||
}
|
||||
} catch (NoSuchMethodError | Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSource.DataSourceType;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
|
||||
public final class Settings extends FileConfig {
|
||||
public final class Settings {
|
||||
|
||||
public static List<String> allowCommands;
|
||||
// This is not an option!
|
||||
@ -42,9 +42,8 @@ public final class Settings extends FileConfig {
|
||||
public static List<String> getMySQLOtherUsernameColumn;
|
||||
public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename, getMySQLColumnName,
|
||||
getMySQLColumnPassword, getMySQLColumnIp, getMySQLColumnLastLogin, getMySQLColumnSalt, getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, backupWindowsPath, getRegisteredGroup,
|
||||
messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName,
|
||||
getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld, getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, spawnPriority, crazyloginFileName, getPassRegex,
|
||||
getMySQLColumnRealName;
|
||||
getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, getMailSubject,
|
||||
getMailText, getMySQLlastlocWorld, defaultWorld, getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, spawnPriority, crazyloginFileName, getPassRegex, getMySQLColumnRealName;
|
||||
public static HashAlgorithm getPasswordHash;
|
||||
public static List<String> getRestrictedIp;
|
||||
public static List<String> getUnrestrictedName;
|
||||
@ -59,7 +58,6 @@ public final class Settings extends FileConfig {
|
||||
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect,
|
||||
customAttributes, generateImage, isRemoveSpeedEnabled;
|
||||
public static final File LOG_FILE = new File(APLUGIN_FOLDER, "authme.log");
|
||||
public static File messageFile;
|
||||
public static int purgeDelay = 60;
|
||||
public static final File SETTINGS_FILE = new File(APLUGIN_FOLDER, "config.yml");
|
||||
public static List<String> unsafePasswords;
|
||||
@ -67,14 +65,11 @@ public final class Settings extends FileConfig {
|
||||
|
||||
public static List<String> welcomeMsg;
|
||||
|
||||
private static Settings instance;
|
||||
|
||||
private static AuthMe plugin;
|
||||
|
||||
protected static FileConfig configFile;
|
||||
|
||||
public Settings(final AuthMe pl) {
|
||||
instance = this;
|
||||
plugin = pl;
|
||||
configFile = (FileConfig) plugin.getConfig();
|
||||
}
|
||||
@ -296,19 +291,18 @@ public final class Settings extends FileConfig {
|
||||
forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole");
|
||||
customAttributes = configFile.getBoolean("Hooks.customAttributes");
|
||||
generateImage = configFile.getBoolean("Email.generateImage", true);
|
||||
messageFile = new File(APLUGIN_FOLDER, "messages_zhcn.yml");
|
||||
// Load the welcome message
|
||||
getWelcomeMessage();
|
||||
|
||||
}
|
||||
|
||||
public static boolean reloadcfg() {
|
||||
return instance.save();
|
||||
return configFile.reload();
|
||||
}
|
||||
|
||||
public static void setValue(final String key, final Object value) {
|
||||
instance.set(key, value);
|
||||
instance.save();
|
||||
configFile.set(key, value);
|
||||
configFile.save();
|
||||
}
|
||||
|
||||
public static void switchAntiBotMod(final boolean mode) {
|
||||
@ -374,193 +368,193 @@ public final class Settings extends FileConfig {
|
||||
|
||||
public void mergeConfig() {
|
||||
boolean changes = false;
|
||||
if (contains("Xenoforo.predefinedSalt")) {
|
||||
set("Xenoforo.predefinedSalt", null);
|
||||
if (configFile.contains("Xenoforo.predefinedSalt")) {
|
||||
configFile.set("Xenoforo.predefinedSalt", null);
|
||||
changes = true;
|
||||
}
|
||||
if (configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA1")
|
||||
|| configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256")) {
|
||||
set("settings.security.passwordHash", "XENFORO");
|
||||
configFile.set("settings.security.passwordHash", "XENFORO");
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Protection.enableProtection")) {
|
||||
set("Protection.enableProtection", false);
|
||||
if (!configFile.contains("Protection.enableProtection")) {
|
||||
configFile.set("Protection.enableProtection", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.restrictions.removeSpeed")) {
|
||||
set("settings.restrictions.removeSpeed", true);
|
||||
if (!configFile.contains("settings.restrictions.removeSpeed")) {
|
||||
configFile.set("settings.restrictions.removeSpeed", true);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("DataSource.mySQLMaxConections")) {
|
||||
set("DataSource.mySQLMaxConections", 25);
|
||||
if (!configFile.contains("DataSource.mySQLMaxConections")) {
|
||||
configFile.set("DataSource.mySQLMaxConections", 25);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Protection.countries")) {
|
||||
if (!configFile.contains("Protection.countries")) {
|
||||
countries = new ArrayList<>();
|
||||
countries.add("US");
|
||||
countries.add("GB");
|
||||
set("Protection.countries", countries);
|
||||
configFile.set("Protection.countries", countries);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Protection.enableAntiBot")) {
|
||||
set("Protection.enableAntiBot", false);
|
||||
if (!configFile.contains("Protection.enableAntiBot")) {
|
||||
configFile.set("Protection.enableAntiBot", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Protection.antiBotSensibility")) {
|
||||
set("Protection.antiBotSensibility", 5);
|
||||
if (!configFile.contains("Protection.antiBotSensibility")) {
|
||||
configFile.set("Protection.antiBotSensibility", 5);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Protection.antiBotDuration")) {
|
||||
set("Protection.antiBotDuration", 10);
|
||||
if (!configFile.contains("Protection.antiBotDuration")) {
|
||||
configFile.set("Protection.antiBotDuration", 10);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.forceCommands")) {
|
||||
set("settings.forceCommands", new ArrayList<String>());
|
||||
if (!configFile.contains("settings.forceCommands")) {
|
||||
configFile.set("settings.forceCommands", new ArrayList<String>());
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.forceCommandsAsConsole")) {
|
||||
set("settings.forceCommandsAsConsole", new ArrayList<String>());
|
||||
if (!configFile.contains("settings.forceCommandsAsConsole")) {
|
||||
configFile.set("settings.forceCommandsAsConsole", new ArrayList<String>());
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Email.recallPlayers")) {
|
||||
set("Email.recallPlayers", false);
|
||||
if (!configFile.contains("Email.recallPlayers")) {
|
||||
configFile.set("Email.recallPlayers", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Email.delayRecall")) {
|
||||
set("Email.delayRecall", 5);
|
||||
if (!configFile.contains("Email.delayRecall")) {
|
||||
configFile.set("Email.delayRecall", 5);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.useWelcomeMessage")) {
|
||||
set("settings.useWelcomeMessage", true);
|
||||
if (!configFile.contains("settings.useWelcomeMessage")) {
|
||||
configFile.set("settings.useWelcomeMessage", true);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.security.unsafePasswords")) {
|
||||
if (!configFile.contains("settings.security.unsafePasswords")) {
|
||||
final List<String> str = new ArrayList<>();
|
||||
str.add("123456");
|
||||
str.add("password");
|
||||
set("settings.security.unsafePasswords", str);
|
||||
configFile.set("settings.security.unsafePasswords", str);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Protection.countriesBlacklist")) {
|
||||
if (!configFile.contains("Protection.countriesBlacklist")) {
|
||||
countriesBlacklist = new ArrayList<>();
|
||||
countriesBlacklist.add("A1");
|
||||
set("Protection.countriesBlacklist", countriesBlacklist);
|
||||
configFile.set("Protection.countriesBlacklist", countriesBlacklist);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.broadcastWelcomeMessage")) {
|
||||
set("settings.broadcastWelcomeMessage", false);
|
||||
if (!configFile.contains("settings.broadcastWelcomeMessage")) {
|
||||
configFile.set("settings.broadcastWelcomeMessage", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.registration.forceKickAfterRegister")) {
|
||||
set("settings.registration.forceKickAfterRegister", false);
|
||||
if (!configFile.contains("settings.registration.forceKickAfterRegister")) {
|
||||
configFile.set("settings.registration.forceKickAfterRegister", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.registration.forceLoginAfterRegister")) {
|
||||
set("settings.registration.forceLoginAfterRegister", false);
|
||||
if (!configFile.contains("settings.registration.forceLoginAfterRegister")) {
|
||||
configFile.set("settings.registration.forceLoginAfterRegister", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("DataSource.mySQLColumnLogged")) {
|
||||
set("DataSource.mySQLColumnLogged", "isLogged");
|
||||
if (!configFile.contains("DataSource.mySQLColumnLogged")) {
|
||||
configFile.set("DataSource.mySQLColumnLogged", "isLogged");
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.restrictions.spawnPriority")) {
|
||||
set("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default");
|
||||
if (!configFile.contains("settings.restrictions.spawnPriority")) {
|
||||
configFile.set("settings.restrictions.spawnPriority", "authme,essentials,multiverse,default");
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.restrictions.maxLoginPerIp")) {
|
||||
set("settings.restrictions.maxLoginPerIp", 0);
|
||||
if (!configFile.contains("settings.restrictions.maxLoginPerIp")) {
|
||||
configFile.set("settings.restrictions.maxLoginPerIp", 0);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.restrictions.maxJoinPerIp")) {
|
||||
set("settings.restrictions.maxJoinPerIp", 0);
|
||||
if (!configFile.contains("settings.restrictions.maxJoinPerIp")) {
|
||||
configFile.set("settings.restrictions.maxJoinPerIp", 0);
|
||||
changes = true;
|
||||
}
|
||||
if (getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) {
|
||||
set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*");
|
||||
if (configFile.getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) {
|
||||
configFile.set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*");
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.delayJoinMessage")) {
|
||||
set("settings.delayJoinMessage", false);
|
||||
if (!configFile.contains("settings.delayJoinMessage")) {
|
||||
configFile.set("settings.delayJoinMessage", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.restrictions.noTeleport")) {
|
||||
set("settings.restrictions.noTeleport", false);
|
||||
if (!configFile.contains("settings.restrictions.noTeleport")) {
|
||||
configFile.set("settings.restrictions.noTeleport", false);
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Converter.Rakamak.newPasswordHash")) {
|
||||
set("Converter.Rakamak.newPasswordHash", null);
|
||||
if (configFile.contains("Converter.Rakamak.newPasswordHash")) {
|
||||
configFile.set("Converter.Rakamak.newPasswordHash", null);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Converter.CrazyLogin.fileName")) {
|
||||
set("Converter.CrazyLogin.fileName", "accounts.db");
|
||||
if (!configFile.contains("Converter.CrazyLogin.fileName")) {
|
||||
configFile.set("Converter.CrazyLogin.fileName", "accounts.db");
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.restrictions.allowedPasswordCharacters")) {
|
||||
set("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
|
||||
if (!configFile.contains("settings.restrictions.allowedPasswordCharacters")) {
|
||||
configFile.set("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.applyBlindEffect")) {
|
||||
set("settings.applyBlindEffect", false);
|
||||
if (!configFile.contains("settings.applyBlindEffect")) {
|
||||
configFile.set("settings.applyBlindEffect", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Email.emailBlacklisted")) {
|
||||
set("Email.emailBlacklisted", new ArrayList<String>());
|
||||
if (!configFile.contains("Email.emailBlacklisted")) {
|
||||
configFile.set("Email.emailBlacklisted", new ArrayList<String>());
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Performances.useMultiThreading")) {
|
||||
set("Performances.useMultiThreading", null);
|
||||
if (configFile.contains("Performances.useMultiThreading")) {
|
||||
configFile.set("Performances.useMultiThreading", null);
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Performances")) {
|
||||
set("Performances", null);
|
||||
if (configFile.contains("Performances")) {
|
||||
configFile.set("Performances", null);
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Passpartu.enablePasspartu")) {
|
||||
set("Passpartu.enablePasspartu", null);
|
||||
if (configFile.contains("Passpartu.enablePasspartu")) {
|
||||
configFile.set("Passpartu.enablePasspartu", null);
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Passpartu")) {
|
||||
set("Passpartu", null);
|
||||
if (configFile.contains("Passpartu")) {
|
||||
configFile.set("Passpartu", null);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Email.emailWhitelisted")) {
|
||||
set("Email.emailWhitelisted", new ArrayList<String>());
|
||||
if (!configFile.contains("Email.emailWhitelisted")) {
|
||||
configFile.set("Email.emailWhitelisted", new ArrayList<String>());
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.forceRegisterCommands")) {
|
||||
set("settings.forceRegisterCommands", new ArrayList<String>());
|
||||
if (!configFile.contains("settings.forceRegisterCommands")) {
|
||||
configFile.set("settings.forceRegisterCommands", new ArrayList<String>());
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("settings.forceRegisterCommandsAsConsole")) {
|
||||
set("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
|
||||
if (!configFile.contains("settings.forceRegisterCommandsAsConsole")) {
|
||||
configFile.set("settings.forceRegisterCommandsAsConsole", new ArrayList<String>());
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Hooks.customAttributes")) {
|
||||
set("Hooks.customAttributes", false);
|
||||
if (!configFile.contains("Hooks.customAttributes")) {
|
||||
configFile.set("Hooks.customAttributes", false);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Purge.removePermissions")) {
|
||||
set("Purge.removePermissions", false);
|
||||
if (!configFile.contains("Purge.removePermissions")) {
|
||||
configFile.set("Purge.removePermissions", false);
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Hooks.notifications")) {
|
||||
set("Hooks.notifications", null);
|
||||
if (configFile.contains("Hooks.notifications")) {
|
||||
configFile.set("Hooks.notifications", null);
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Hooks.chestshop")) {
|
||||
set("Hooks.chestshop", null);
|
||||
if (configFile.contains("Hooks.chestshop")) {
|
||||
configFile.set("Hooks.chestshop", null);
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Hooks.legacyChestshop")) {
|
||||
set("Hooks.legacyChestshop", null);
|
||||
if (configFile.contains("Hooks.legacyChestshop")) {
|
||||
configFile.set("Hooks.legacyChestshop", null);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("Email.generateImage")) {
|
||||
set("Email.generateImage", true);
|
||||
if (!configFile.contains("Email.generateImage")) {
|
||||
configFile.set("Email.generateImage", true);
|
||||
changes = true;
|
||||
}
|
||||
if (!contains("DataSource.mySQLRealName")) {
|
||||
set("DataSource.mySQLRealName", "realname");
|
||||
if (!configFile.contains("DataSource.mySQLRealName")) {
|
||||
configFile.set("DataSource.mySQLRealName", "realname");
|
||||
changes = true;
|
||||
}
|
||||
|
||||
@ -569,20 +563,4 @@ public final class Settings extends FileConfig {
|
||||
plugin.getLogger().warning("请检查新的 config.yml 文件 并修改相关配置!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves current configuration (plus defaults) to disk.
|
||||
* <p>
|
||||
* If defaults and configuration are empty, saves blank file.
|
||||
*
|
||||
* @return True if saved successfully
|
||||
*/
|
||||
public final boolean saveDefaults() {
|
||||
options().copyDefaults(true);
|
||||
options().copyHeader(true);
|
||||
final boolean success = instance.save();
|
||||
options().copyDefaults(false);
|
||||
options().copyHeader(false);
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user