mirror of
https://github.com/moparisthebest/xAuth
synced 2024-12-21 22:58:51 -05:00
1. Major refactor of database related classes.
2. Added global teleport locations
This commit is contained in:
parent
13279eb61c
commit
06b56509ff
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,4 +4,5 @@
|
||||
/bin
|
||||
/target
|
||||
/.classpath
|
||||
/.project
|
||||
/.project
|
||||
/old
|
9
pom.xml
9
pom.xml
@ -59,6 +59,15 @@
|
||||
<include>messages.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<targetPath>sql</targetPath>
|
||||
<filtering>false</filtering>
|
||||
<directory>sql</directory>
|
||||
<includes>
|
||||
<include>h2/*.sql</include>
|
||||
<include>mysql/*.sql</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
44
sql/h2/0001_original_tables.sql
Normal file
44
sql/h2/0001_original_tables.sql
Normal file
@ -0,0 +1,44 @@
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_ACCOUNT}` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`playername` VARCHAR(255) NOT NULL,
|
||||
`password` CHAR(255) NOT NULL,
|
||||
`email` VARCHAR(100) NULL,
|
||||
`registerdate` DATETIME NULL,
|
||||
`registerip` CHAR(15) NULL,
|
||||
`lastlogindate` DATETIME NULL,
|
||||
`lastloginip` CHAR(15) NULL,
|
||||
`active` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_SESSION}` (
|
||||
`accountid` INT UNSIGNED NOT NULL,
|
||||
`host` CHAR(15) NOT NULL,
|
||||
`logintime` DATETIME NOT NULL,
|
||||
PRIMARY KEY(`accountid`),
|
||||
FOREIGN KEY (`accountid`) REFERENCES `{TABLE_ACCOUNT}`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_LOCATION}` (
|
||||
`worldname` VARCHAR(255) NOT NULL,
|
||||
`x` DOUBLE NOT NULL,
|
||||
`y` DOUBLE NOT NULL,
|
||||
`z` DOUBLE NOT NULL,
|
||||
`yaw` FLOAT NOT NULL,
|
||||
`pitch` FLOAT NOT NULL,
|
||||
PRIMARY KEY(`worldname`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_STRIKE}` (
|
||||
`host` CHAR(15) NOT NULL,
|
||||
`bantime` DATETIME NOT NULL,
|
||||
PRIMARY KEY(`host`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_INVENTORY}` (
|
||||
`playername` VARCHAR(255) NOT NULL,
|
||||
`itemid` TEXT NOT NULL,
|
||||
`amount` TEXT NOT NULL,
|
||||
`durability` TEXT NOT NULL,
|
||||
PRIMARY KEY (`playername`)
|
||||
);
|
6
sql/h2/0002_add_location_uid.sql
Normal file
6
sql/h2/0002_add_location_uid.sql
Normal file
@ -0,0 +1,6 @@
|
||||
ALTER TABLE `{TABLE_LOCATION}` ADD COLUMN `uid` VARCHAR(36) NULL BEFORE `worldname`;
|
||||
ALTER TABLE `{TABLE_LOCATION}` ADD COLUMN `global` TINYINT(1) NOT NULL DEFAULT 0;
|
||||
UPDATE `{TABLE_LOCATION}` SET `uid` = `worldname`;
|
||||
ALTER TABLE `{TABLE_LOCATION}` ALTER COLUMN `uid` VARCHAR(36) NOT NULL;
|
||||
ALTER TABLE `{TABLE_LOCATION}` DROP COLUMN `worldname`;
|
||||
ALTER TABLE `{TABLE_LOCATION}` ADD PRIMARY KEY (`uid`);
|
44
sql/mysql/0001_original_tables.sql
Normal file
44
sql/mysql/0001_original_tables.sql
Normal file
@ -0,0 +1,44 @@
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_ACCOUNT}` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`playername` VARCHAR(255) NOT NULL,
|
||||
`password` CHAR(255) NOT NULL,
|
||||
`email` VARCHAR(100) NULL,
|
||||
`registerdate` DATETIME NULL,
|
||||
`registerip` CHAR(15) NULL,
|
||||
`lastlogindate` DATETIME NULL,
|
||||
`lastloginip` CHAR(15) NULL,
|
||||
`active` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_SESSION}` (
|
||||
`accountid` INT UNSIGNED NOT NULL,
|
||||
`host` CHAR(15) NOT NULL,
|
||||
`logintime` DATETIME NOT NULL,
|
||||
PRIMARY KEY(`accountid`),
|
||||
FOREIGN KEY (`accountid`) REFERENCES `{TABLE_ACCOUNT}`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_LOCATION}` (
|
||||
`worldname` VARCHAR(255) NOT NULL,
|
||||
`x` DOUBLE NOT NULL,
|
||||
`y` DOUBLE NOT NULL,
|
||||
`z` DOUBLE NOT NULL,
|
||||
`yaw` FLOAT NOT NULL,
|
||||
`pitch` FLOAT NOT NULL,
|
||||
PRIMARY KEY(`worldname`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_STRIKE}` (
|
||||
`host` CHAR(15) NOT NULL,
|
||||
`bantime` DATETIME NOT NULL,
|
||||
PRIMARY KEY(`host`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `{TABLE_INVENTORY}` (
|
||||
`playername` VARCHAR(255) NOT NULL,
|
||||
`itemid` TEXT NOT NULL,
|
||||
`amount` TEXT NOT NULL,
|
||||
`durability` TEXT NOT NULL,
|
||||
PRIMARY KEY (`playername`)
|
||||
);
|
5
sql/mysql/0002_add_location_uid.sql
Normal file
5
sql/mysql/0002_add_location_uid.sql
Normal file
@ -0,0 +1,5 @@
|
||||
ALTER TABLE `{TABLE_LOCATION}` ADD COLUMN `uid` VARCHAR(36) NOT NULL FIRST;
|
||||
ALTER TABLE `{TABLE_LOCATION}` ADD COLUMN `global` TINYINT(1) NOT NULL DEFAULT 0;
|
||||
UPDATE `{TABLE_LOCATION}` SET `uid` = `worldname`;
|
||||
ALTER TABLE `{TABLE_LOCATION}` DROP COLUMN `worldname`;
|
||||
ALTER TABLE `{TABLE_LOCATION}` ADD PRIMARY KEY (`uid`);
|
@ -1,34 +1,39 @@
|
||||
package com.cypherx.xauth;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class TeleLocation {
|
||||
private String worldName;
|
||||
private UUID uid;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private int global;
|
||||
|
||||
public TeleLocation() {}
|
||||
|
||||
public TeleLocation(Location location) {
|
||||
worldName = location.getWorld().getName();
|
||||
public TeleLocation(Location location, boolean global) {
|
||||
World world = location.getWorld();
|
||||
uid = world.getUID();
|
||||
x = location.getX();
|
||||
y = location.getY();
|
||||
z = location.getZ();
|
||||
yaw = location.getYaw();
|
||||
pitch = location.getPitch();
|
||||
this.global = (global ? 1 : 0);
|
||||
}
|
||||
|
||||
public void setWorldName(String worldName) {
|
||||
this.worldName = worldName;
|
||||
public void setUID(UUID uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getWorldName() {
|
||||
return worldName;
|
||||
public UUID getUID() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
@ -71,8 +76,15 @@ public class TeleLocation {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public void setGlobal(int global) {
|
||||
this.global = global;
|
||||
}
|
||||
|
||||
public int getGlobal() {
|
||||
return global;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.worldName = location.getWorld().getName();
|
||||
this.x = location.getX();
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
@ -81,7 +93,7 @@ public class TeleLocation {
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
World world = Bukkit.getServer().getWorld(worldName);
|
||||
World world = Bukkit.getServer().getWorld(uid);
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
@ -22,7 +24,7 @@ import com.avaje.ebean.validation.factory.EmailValidatorFactory;
|
||||
public class Util {
|
||||
public static void writeConfig(File file, Class<?> c) {
|
||||
String fileName = file.getName();
|
||||
String content = getResourceAsString(fileName);
|
||||
String content = getResourceAsString("/res/" + fileName);
|
||||
|
||||
for (Field field : c.getFields()) {
|
||||
try {
|
||||
@ -45,8 +47,8 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getResourceAsString(String resource) {
|
||||
InputStream input = xAuth.class.getResourceAsStream("/res/" + resource);
|
||||
public static String getResourceAsString(String resource) {
|
||||
InputStream input = xAuth.class.getResourceAsStream(resource);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (input != null) {
|
||||
@ -182,4 +184,52 @@ public class Util {
|
||||
|
||||
return intArray;
|
||||
}
|
||||
|
||||
public static Account buildAccount(ResultSet rs) {
|
||||
Account account = null;
|
||||
try {
|
||||
account = new Account();
|
||||
account.setId(rs.getInt("id"));
|
||||
account.setPlayerName(rs.getString("playername"));
|
||||
account.setPassword(rs.getString("password"));
|
||||
account.setEmail(rs.getString("email"));
|
||||
account.setRegisterDate(rs.getTimestamp("registerdate"));
|
||||
account.setRegisterHost(rs.getString("registerip"));
|
||||
account.setLastLoginDate(rs.getTimestamp("lastlogindate"));
|
||||
account.setLastLoginHost(rs.getString("lastloginip"));
|
||||
account.setActive(rs.getInt("active"));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not build Account from ResultSet!", e);
|
||||
}
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
public static Session buildSession(ResultSet rs) {
|
||||
Session session = null;
|
||||
try {
|
||||
session = new Session();
|
||||
session.setAccountId(rs.getInt("accountid"));
|
||||
|
||||
if (rs.wasNull()) // no session data in database
|
||||
return null;
|
||||
|
||||
session.setHost(rs.getString("host"));
|
||||
session.setLoginTime(rs.getTimestamp("logintime"));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not build Session from ResultSet!", e);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
public static boolean isUUID(String str) {
|
||||
try {
|
||||
UUID.fromString(str);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ public class ChangePasswordCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player)sender;
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(player.getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(player.getName());
|
||||
|
||||
if (!xAuthSettings.pwAllowChange) {
|
||||
xAuthMessages.send("cpwErrDisabled", player);
|
||||
|
@ -11,6 +11,7 @@ import com.cypherx.xauth.xAuthLog;
|
||||
import com.cypherx.xauth.xAuthMessages;
|
||||
import com.cypherx.xauth.xAuthPlayer;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
import com.cypherx.xauth.database.DbUtil;
|
||||
|
||||
public class LoginCommand implements CommandExecutor {
|
||||
private final xAuth plugin;
|
||||
@ -22,7 +23,7 @@ public class LoginCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player)sender;
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(player.getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(player.getName());
|
||||
|
||||
if (args.length < 1) {
|
||||
xAuthMessages.send("loginUsage", player);
|
||||
@ -49,7 +50,7 @@ public class LoginCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
int active = plugin.getDataManager().getActive(player.getName());
|
||||
int active = DbUtil.getActive(player.getName());
|
||||
account.setActive(active);
|
||||
|
||||
if (xAuthSettings.activation && active == 0) {
|
||||
|
@ -19,7 +19,7 @@ public class LogoutCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player)sender;
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(player.getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(player.getName());
|
||||
|
||||
if (!xPlayer.hasSession()) {
|
||||
xAuthMessages.send("logoutErrLogged", player);
|
||||
|
@ -7,6 +7,7 @@ import com.cypherx.xauth.xAuthLog;
|
||||
import com.cypherx.xauth.xAuthMessages;
|
||||
import com.cypherx.xauth.xAuthPlayer;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
import com.cypherx.xauth.database.DbUtil;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -23,7 +24,7 @@ public class RegisterCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player)sender;
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(player.getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(player.getName());
|
||||
|
||||
if (!xAuthSettings.regEnabled) {
|
||||
xAuthMessages.send("regErrDisabled", player);
|
||||
@ -34,7 +35,7 @@ public class RegisterCommand implements CommandExecutor {
|
||||
} else if (xPlayer.isRegistered()) {
|
||||
xAuthMessages.send("regErrRegistered", player);
|
||||
return true;
|
||||
} else if (!xAuthSettings.allowMultiple && plugin.getDataManager().isHostUsed(Util.getHostFromPlayer(player))) {
|
||||
} else if (!xAuthSettings.allowMultiple && DbUtil.isHostUsed(Util.getHostFromPlayer(player))) {
|
||||
xAuthMessages.send("regErrMultiple", player);
|
||||
return true;
|
||||
}
|
||||
|
@ -17,15 +17,13 @@ import com.cypherx.xauth.xAuthMessages;
|
||||
import com.cypherx.xauth.xAuthPermissions;
|
||||
import com.cypherx.xauth.xAuthPlayer;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
import com.cypherx.xauth.datamanager.DataManager;
|
||||
import com.cypherx.xauth.database.DbUtil;
|
||||
|
||||
public class xAuthCommand implements CommandExecutor {
|
||||
private final xAuth plugin;
|
||||
private DataManager dataManager;
|
||||
|
||||
public xAuthCommand(xAuth plugin) {
|
||||
this.plugin = plugin;
|
||||
this.dataManager = plugin.getDataManager();
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
@ -83,7 +81,7 @@ public class xAuthCommand implements CommandExecutor {
|
||||
String targetName = args[1];
|
||||
String password = args[2];
|
||||
String email = (args.length > 3 ? args[3] : null);
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(targetName);
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(targetName);
|
||||
|
||||
if (xPlayer.isRegistered()) {
|
||||
xAuthMessages.send("admnRegRegistered", player, xPlayer.getPlayer());
|
||||
@ -92,7 +90,7 @@ public class xAuthCommand implements CommandExecutor {
|
||||
|
||||
Account account = new Account(targetName, Util.encrypt(password), email);
|
||||
xPlayer.setAccount(account);
|
||||
dataManager.saveAccount(account);
|
||||
DbUtil.saveAccount(account);
|
||||
|
||||
xAuthMessages.send("admnRegSuccess", player, xPlayer.getPlayer());
|
||||
xAuthLog.info(player.getName() + " has registered an account for " + targetName);
|
||||
@ -105,7 +103,7 @@ public class xAuthCommand implements CommandExecutor {
|
||||
String targetName = args[1];
|
||||
String password = args[2];
|
||||
String email = (args.length > 3 ? args[3] : null);
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(targetName);
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(targetName);
|
||||
|
||||
if (xPlayer.isRegistered()) {
|
||||
xAuthLog.info(targetName + " is already registered!");
|
||||
@ -114,7 +112,7 @@ public class xAuthCommand implements CommandExecutor {
|
||||
|
||||
Account account = new Account(targetName, Util.encrypt(password), email);
|
||||
xPlayer.setAccount(account);
|
||||
dataManager.saveAccount(account);
|
||||
DbUtil.saveAccount(account);
|
||||
|
||||
xAuthLog.info("Account successfully created for: " + targetName);
|
||||
}
|
||||
@ -135,7 +133,7 @@ public class xAuthCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
String targetName = args[1];
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(targetName);
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(targetName);
|
||||
|
||||
if (!xPlayer.isRegistered()) {
|
||||
xAuthMessages.send("admnCpwRegistered", player, xPlayer.getPlayer());
|
||||
@ -155,7 +153,7 @@ public class xAuthCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
String targetName = args[1];
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(targetName);
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(targetName);
|
||||
|
||||
if (!xPlayer.isRegistered()) {
|
||||
xAuthLog.info("This player is not registered!");
|
||||
@ -185,7 +183,7 @@ public class xAuthCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
String targetName = args[1];
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(targetName);
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(targetName);
|
||||
|
||||
if (!xPlayer.hasSession()) {
|
||||
xAuthMessages.send("admnLogoutLogged", player, xPlayer.getPlayer());
|
||||
@ -205,7 +203,7 @@ public class xAuthCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
String targetName = args[1];
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(targetName);
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(targetName);
|
||||
|
||||
if (!xPlayer.hasSession()) {
|
||||
xAuthLog.info(targetName + " is not logged in!");
|
||||
@ -235,14 +233,14 @@ public class xAuthCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
String targetName = args[1];
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(targetName);
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(targetName);
|
||||
|
||||
if (!xPlayer.isRegistered()) {
|
||||
xAuthMessages.send("admnUnregRegistered", player, xPlayer.getPlayer());
|
||||
return true;
|
||||
}
|
||||
|
||||
dataManager.deleteAccount(xPlayer);
|
||||
DbUtil.deleteAccount(xPlayer);
|
||||
|
||||
Player target = xPlayer.getPlayer();
|
||||
if (target != null) {
|
||||
@ -260,14 +258,14 @@ public class xAuthCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
String targetName = args[1];
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(targetName);
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(targetName);
|
||||
|
||||
if (!xPlayer.isRegistered()) {
|
||||
xAuthLog.info(targetName + " is not registered!");
|
||||
return true;
|
||||
}
|
||||
|
||||
dataManager.deleteAccount(xPlayer);
|
||||
DbUtil.deleteAccount(xPlayer);
|
||||
|
||||
Player target = xPlayer.getPlayer();
|
||||
if (target != null) {
|
||||
@ -295,19 +293,43 @@ public class xAuthCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
String action = args[1];
|
||||
Boolean global = (args.length > 2 && args[2].equals("global") ? true : false);
|
||||
|
||||
if (action.equals("set")) {
|
||||
dataManager.setTeleLocation(new TeleLocation(player.getLocation()));
|
||||
xAuthMessages.send("admnLocSetSuccess", player);
|
||||
} else {
|
||||
TeleLocation tLoc = dataManager.getTeleLocation(player.getWorld().getName());
|
||||
if (tLoc == null) {
|
||||
xAuthMessages.send("admnLocRmvNo", player);
|
||||
if (!global && player.getWorld().getUID().equals(plugin.getGlobalUID())) {
|
||||
xAuthMessages.send("admnLocSetErrGlobal", player);
|
||||
return true;
|
||||
}
|
||||
|
||||
dataManager.removeTeleLocation(tLoc);
|
||||
xAuthMessages.send("admnLocRmvSuccess", player);
|
||||
plugin.setTeleLocation(new TeleLocation(player.getLocation(), global));
|
||||
|
||||
if (global)
|
||||
xAuthMessages.send("admnLocSetGlobalSuccess", player);
|
||||
else
|
||||
xAuthMessages.send("admnLocSetSuccess", player);
|
||||
} else {
|
||||
if (global) {
|
||||
TeleLocation tLoc = plugin.getTeleLocation(plugin.getGlobalUID());
|
||||
if (tLoc == null) {
|
||||
xAuthMessages.send("admnLocRmvGlobalNo", player);
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.removeTeleLocation(tLoc);
|
||||
xAuthMessages.send("admnLocRmvGlobalSuccess", player);
|
||||
} else {
|
||||
TeleLocation tLoc = plugin.getTeleLocation(player.getWorld().getUID());
|
||||
if (tLoc == null) {
|
||||
xAuthMessages.send("admnLocRmvNo", player);
|
||||
return true;
|
||||
} else if (tLoc.getUID().equals(plugin.getGlobalUID())) {
|
||||
xAuthMessages.send("admnLocRmvErrGlobal", player);
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.removeTeleLocation(tLoc);
|
||||
xAuthMessages.send("admnLocRmvSuccess", player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
177
src/main/java/com/cypherx/xauth/database/Database.java
Normal file
177
src/main/java/com/cypherx/xauth/database/Database.java
Normal file
@ -0,0 +1,177 @@
|
||||
package com.cypherx.xauth.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.cypherx.xauth.xAuthLog;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
|
||||
public class Database {
|
||||
private static DBMS dbms = DBMS.H2;
|
||||
private static Connection connection = null;
|
||||
|
||||
public static void connect() {
|
||||
String driver = "";
|
||||
String username = "sa";
|
||||
String password = "";
|
||||
|
||||
switch (dbms) {
|
||||
case H2:
|
||||
driver = "org.h2.Driver";
|
||||
break;
|
||||
case MYSQL:
|
||||
driver = "com.mysql.jdbc.Driver";
|
||||
username = xAuthSettings.mysqlUser;
|
||||
password = xAuthSettings.mysqlPass;
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName(driver);
|
||||
connection = DriverManager.getConnection(getConnString(), username, password);
|
||||
xAuthLog.info("Connection to database established!");
|
||||
} catch (ClassNotFoundException e) {
|
||||
xAuthLog.severe("Missing database library!");
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not connect to database!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getConnString() {
|
||||
switch (dbms) {
|
||||
case H2:
|
||||
return "jdbc:h2:plugins" + File.separator + "xAuth" + File.separator + "xAuth;IGNORECASE=TRUE";
|
||||
case MYSQL:
|
||||
return "jdbc:mysql://" + xAuthSettings.mysqlHost + ":" + xAuthSettings.mysqlPort + "/" + xAuthSettings.mysqlDb + "?zeroDateTimeBehavior=convertToNull";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static ResultSet queryRead(String sql, Object... params) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
try {
|
||||
stmt = connection.prepareStatement(sql);
|
||||
|
||||
for (int i = 0; i < params.length; i++)
|
||||
stmt.setObject(i + 1, params[i]);
|
||||
|
||||
return stmt.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("SQL query failure [read] (" + sql + ")", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int queryWrite(String sql, Object... params) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
int result = -1;
|
||||
|
||||
try {
|
||||
stmt = connection.prepareStatement(sql);
|
||||
|
||||
for (int i = 0; i < params.length; i++)
|
||||
stmt.setObject(i + 1, params[i]);
|
||||
|
||||
result = stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("SQL query failure [write] (" + sql + ")", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void queryBatch(PreparedStatement stmt) {
|
||||
try {
|
||||
stmt.executeBatch();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("SQL query failure [batch]", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int lastInsertId() {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
int lastInsertId = -1;
|
||||
ResultSet rs = queryRead("SELECT LAST_INSERT_ID()");
|
||||
|
||||
try {
|
||||
if (rs.next())
|
||||
lastInsertId = rs.getInt(1);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not retrieve last insert ID!", e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
return lastInsertId;
|
||||
}
|
||||
|
||||
public static void printStats() {
|
||||
String sql = "SELECT" +
|
||||
" (SELECT COUNT(*) FROM `" + xAuthSettings.tblAccount + "`) AS accounts," +
|
||||
" (SELECT COUNT(*) FROM `" + xAuthSettings.tblSession + "`) AS sessions";
|
||||
ResultSet rs = queryRead(sql);
|
||||
|
||||
try {
|
||||
if (rs.next())
|
||||
xAuthLog.info("Accounts: " + rs.getInt("accounts") + ", Sessions: " + rs.getInt("sessions"));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not fetch xAuth statistics!", e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
public static boolean isConnected() {
|
||||
try {
|
||||
if (connection == null || connection.isClosed())
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public static void setDBMS(DBMS newDBMS) {
|
||||
dbms = newDBMS;
|
||||
}
|
||||
|
||||
public static DBMS getDBMS() {
|
||||
return dbms;
|
||||
}
|
||||
|
||||
public enum DBMS {
|
||||
H2,
|
||||
MYSQL
|
||||
}
|
||||
}
|
148
src/main/java/com/cypherx/xauth/database/DbUpdate.java
Normal file
148
src/main/java/com/cypherx/xauth/database/DbUpdate.java
Normal file
@ -0,0 +1,148 @@
|
||||
package com.cypherx.xauth.database;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import com.cypherx.xauth.Util;
|
||||
import com.cypherx.xauth.xAuth;
|
||||
import com.cypherx.xauth.xAuthLog;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
|
||||
public class DbUpdate {
|
||||
private File fVersion = new File(xAuth.dataFolder + File.separator + "DBVERSION");
|
||||
private int version; // Current database version
|
||||
private int sqlVersion = 0; // Version of the .sql files
|
||||
private Map<Integer, String> sqlFiles = new HashMap<Integer, String>();
|
||||
|
||||
public DbUpdate() {
|
||||
loadVersion();
|
||||
loadSQLFiles();
|
||||
}
|
||||
|
||||
public boolean checkVersion() {
|
||||
return sqlVersion <= version;
|
||||
}
|
||||
|
||||
// Updates the database to the latest version
|
||||
public void update() {
|
||||
update(sqlVersion);
|
||||
}
|
||||
|
||||
// Updates the database to the specified version
|
||||
public void update(int version) {
|
||||
if (version <= this.version)
|
||||
return;
|
||||
|
||||
for (int i = this.version + 1; i <= version; i++) {
|
||||
String sql = Util.getResourceAsString("/" + sqlFiles.get(i));
|
||||
sql = sql.replace("{TABLE_ACCOUNT}", xAuthSettings.tblAccount);
|
||||
sql = sql.replace("{TABLE_SESSION}", xAuthSettings.tblSession);
|
||||
sql = sql.replace("{TABLE_LOCATION}", xAuthSettings.tblLocation);
|
||||
sql = sql.replace("{TABLE_STRIKE}", xAuthSettings.tblStrike);
|
||||
sql = sql.replace("{TABLE_INVENTORY}", xAuthSettings.tblInventory);
|
||||
|
||||
String[] queries = sql.split(";");
|
||||
for (int j = 0; j < queries.length; j++) {
|
||||
String query = queries[j].trim();
|
||||
if (query.isEmpty())
|
||||
continue;
|
||||
|
||||
Database.queryWrite(query);
|
||||
}
|
||||
}
|
||||
|
||||
updateVersionFile(version);
|
||||
}
|
||||
|
||||
private void loadVersion() {
|
||||
BufferedReader reader = null;
|
||||
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(fVersion));
|
||||
version = Integer.parseInt(reader.readLine());
|
||||
} catch (FileNotFoundException e) {
|
||||
createVersionFile();
|
||||
version = 0;
|
||||
} catch (IOException e) {
|
||||
xAuthLog.severe("Could not load database version from file!", e);
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSQLFiles() {
|
||||
String jarPath = "plugins" + File.separator + "xAuth.jar";
|
||||
String sqlPath = "";
|
||||
|
||||
if (xAuthSettings.datasource.equals("mysql"))
|
||||
sqlPath = "sql/mysql/";
|
||||
else
|
||||
sqlPath = "sql/h2/";
|
||||
|
||||
try {
|
||||
JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
|
||||
Enumeration<JarEntry> entries = jar.entries();
|
||||
|
||||
while(entries.hasMoreElements()) {
|
||||
String name = entries.nextElement().getName();
|
||||
if (name.startsWith(sqlPath) && name.endsWith(".sql")) {
|
||||
int version = Integer.parseInt(name.substring(name.lastIndexOf("/") + 1, name.indexOf("_")));
|
||||
|
||||
if (sqlVersion < version)
|
||||
sqlVersion = version;
|
||||
|
||||
sqlFiles.put(version, name);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void createVersionFile() {
|
||||
BufferedWriter writer = null;
|
||||
|
||||
try {
|
||||
fVersion.createNewFile();
|
||||
writer = new BufferedWriter(new FileWriter(fVersion));
|
||||
writer.write("0");
|
||||
} catch (IOException e) {
|
||||
xAuthLog.severe("Could not create database version file!", e);
|
||||
} finally {
|
||||
try {
|
||||
if (writer != null)
|
||||
writer.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVersionFile(int version) {
|
||||
BufferedWriter writer = null;
|
||||
|
||||
try {
|
||||
writer = new BufferedWriter(new FileWriter(fVersion));
|
||||
writer.write(Integer.toString(version));
|
||||
} catch (IOException e) {
|
||||
xAuthLog.severe("Could not update database version file!", e);
|
||||
} finally {
|
||||
try {
|
||||
if (writer != null)
|
||||
writer.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
349
src/main/java/com/cypherx/xauth/database/DbUtil.java
Normal file
349
src/main/java/com/cypherx/xauth/database/DbUtil.java
Normal file
@ -0,0 +1,349 @@
|
||||
package com.cypherx.xauth.database;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.cypherx.xauth.Account;
|
||||
import com.cypherx.xauth.Session;
|
||||
import com.cypherx.xauth.StrikeBan;
|
||||
import com.cypherx.xauth.TeleLocation;
|
||||
import com.cypherx.xauth.Util;
|
||||
import com.cypherx.xauth.xAuthLog;
|
||||
import com.cypherx.xauth.xAuthPlayer;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
import com.cypherx.xauth.database.Database.DBMS;
|
||||
|
||||
public class DbUtil {
|
||||
/* START ACCOUNT METHODS */
|
||||
public static void saveAccount(Account account) {
|
||||
if (account.getId() == 0)
|
||||
insertAccount(account);
|
||||
else
|
||||
updateAccount(account);
|
||||
}
|
||||
|
||||
private static void insertAccount(Account account) {
|
||||
String sql = "INSERT INTO `" + xAuthSettings.tblAccount + "`" +
|
||||
" (`playername`, `password`, `email`, `registerdate`, `registerip`, `lastlogindate`, `lastloginip`, `active`)" +
|
||||
" VALUES" +
|
||||
" (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
Database.queryWrite(sql, account.getPlayerName(), account.getPassword(), account.getEmail(),
|
||||
account.getRegisterDate(), account.getRegisterHost(), account.getLastLoginDate(),
|
||||
account.getLastLoginHost(), account.getActive());
|
||||
account.setId(Database.lastInsertId());
|
||||
}
|
||||
|
||||
private static void updateAccount(Account account) {
|
||||
String sql = "UPDATE `" + xAuthSettings.tblAccount + "`" +
|
||||
" SET" +
|
||||
" `playername` = ?," +
|
||||
"`password` = ?," +
|
||||
"`email` = ?," +
|
||||
"`registerdate` = ?," +
|
||||
"`registerip` = ?," +
|
||||
"`lastlogindate` = ?," +
|
||||
"`lastloginip` = ?," +
|
||||
"`active` = ?" +
|
||||
" WHERE id = ?";
|
||||
|
||||
Database.queryWrite(sql, account.getPlayerName(), account.getPassword(), account.getEmail(),
|
||||
account.getRegisterDate(), account.getRegisterHost(), account.getLastLoginDate(),
|
||||
account.getLastLoginHost(), account.getActive(), account.getId());
|
||||
}
|
||||
|
||||
public static void insertAccounts(List<Account> accounts) {
|
||||
String sql = "INSERT INTO `" + xAuthSettings.tblAccount + "` (`playername`, `password`) VALUES (?, ?)";
|
||||
Account account;
|
||||
|
||||
try {
|
||||
PreparedStatement stmt = Database.getConnection().prepareStatement(sql);
|
||||
|
||||
for (int i = 0; i < accounts.size(); i++) {
|
||||
account = accounts.get(i);
|
||||
stmt.setString(1, account.getPlayerName());
|
||||
stmt.setString(2, account.getPassword());
|
||||
stmt.addBatch();
|
||||
}
|
||||
|
||||
Database.queryBatch(stmt);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteAccount(xAuthPlayer xPlayer) {
|
||||
String sql = "DELETE FROM `" + xAuthSettings.tblAccount + "` WHERE `id` = ?";
|
||||
Database.queryWrite(sql, xPlayer.getAccount().getId());
|
||||
xPlayer.setAccount(null);
|
||||
xPlayer.setSession(null);
|
||||
}
|
||||
/* END ACCOUNT METHODS */
|
||||
|
||||
/* START SESSION METHODS */
|
||||
public static void insertSession(Session session) {
|
||||
String sql = "INSERT INTO `" + xAuthSettings.tblSession + "` VALUES (?, ?, ?)";
|
||||
Database.queryWrite(sql, session.getAccountId(), session.getHost(), session.getLoginTime());
|
||||
}
|
||||
|
||||
public static void deleteSession(xAuthPlayer xPlayer) {
|
||||
String sql = "DELETE FROM `" + xAuthSettings.tblSession + "` WHERE `accountid` = ?";
|
||||
Database.queryWrite(sql, xPlayer.getSession().getAccountId());
|
||||
xPlayer.setSession(null);
|
||||
}
|
||||
/* END SESSION METHODS */
|
||||
|
||||
/* START LOCATION METHODS */
|
||||
public static void insertTeleLocation(TeleLocation teleLocation) {
|
||||
String sql = "INSERT INTO `" + xAuthSettings.tblLocation + "` VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
Database.queryWrite(sql, teleLocation.getUID().toString(), teleLocation.getX(), teleLocation.getY(), teleLocation.getZ(),
|
||||
teleLocation.getYaw(), teleLocation.getPitch(), teleLocation.getGlobal());
|
||||
}
|
||||
|
||||
public static void updateTeleLocation(TeleLocation teleLocation) {
|
||||
String sql = "UPDATE `" + xAuthSettings.tblLocation + "` " +
|
||||
"SET " +
|
||||
"`x` = ?, " +
|
||||
"`y` = ?, " +
|
||||
"`z` = ?, " +
|
||||
"`yaw` = ?, " +
|
||||
"`pitch` = ?, " +
|
||||
"`global` = ? " +
|
||||
"WHERE `uid` = ?";
|
||||
Database.queryWrite(sql, teleLocation.getX(), teleLocation.getY(), teleLocation.getZ(), teleLocation.getYaw(),
|
||||
teleLocation.getPitch(), teleLocation.getGlobal(), teleLocation.getUID().toString());
|
||||
}
|
||||
|
||||
public static void deleteTeleLocation(TeleLocation teleLocation) {
|
||||
String sql = "DELETE FROM `" + xAuthSettings.tblLocation + "` WHERE `uid` = ?";
|
||||
Database.queryWrite(sql, teleLocation.getUID().toString());
|
||||
}
|
||||
/* END LOCATION METHODS */
|
||||
|
||||
/* START STRIKE METHODS */
|
||||
public static StrikeBan loadStrikeBan(String host) {
|
||||
String sql = "SELECT * FROM `" + xAuthSettings.tblStrike + "` WHERE `host` = ?";
|
||||
ResultSet rs = Database.queryRead(sql, host);
|
||||
StrikeBan ban = null;
|
||||
|
||||
try {
|
||||
if (rs.next()) {
|
||||
ban = new StrikeBan();
|
||||
ban.setHost(rs.getString(host));
|
||||
ban.setBanTime(rs.getTimestamp("bantime"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not load StrikeBan for host: " + host, e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
return ban;
|
||||
}
|
||||
|
||||
public static void insertStrikeBan(StrikeBan ban) {
|
||||
String sql = "INSERT INTO `" + xAuthSettings.tblStrike + "` VALUES (?, ?)";
|
||||
Database.queryWrite(sql, ban.getHost(), ban.getBanTime());
|
||||
}
|
||||
|
||||
public static void deleteStrikeBan(StrikeBan ban) {
|
||||
String sql = "DELETE FROM `" + xAuthSettings.tblStrike + "` WHERE `host` = ?";
|
||||
Database.queryWrite(sql, ban.getHost());
|
||||
}
|
||||
/* END STRIKE METHODS */
|
||||
|
||||
/* START INVENTORY METHODS */
|
||||
public static ItemStack[] getInventory(xAuthPlayer xPlayer) {
|
||||
String sql = "SELECT * FROM `" + xAuthSettings.tblInventory + "` WHERE `playername` = ?";
|
||||
ResultSet rs = Database.queryRead(sql, xPlayer.getPlayerName());
|
||||
|
||||
try {
|
||||
if (rs.next()) {
|
||||
int[] itemid = Util.stringToInt(rs.getString("itemid").split(","));
|
||||
int[] amount = Util.stringToInt(rs.getString("amount").split(","));
|
||||
int[] durability = Util.stringToInt(rs.getString("durability").split(","));
|
||||
ItemStack[] inv = new ItemStack[itemid.length];
|
||||
|
||||
for (int i = 0; i < inv.length; i++)
|
||||
inv[i] = new ItemStack(itemid[i], amount[i], (short)durability[i]);
|
||||
|
||||
return inv;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not load inventory for player: " + xPlayer.getPlayerName(), e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void insertInventory(xAuthPlayer xPlayer) {
|
||||
String sql = "SELECT * FROM `" + xAuthSettings.tblInventory + "` WHERE `playername` = ?";
|
||||
ResultSet rs = Database.queryRead(sql, xPlayer.getPlayerName());
|
||||
|
||||
try {
|
||||
if (rs.next())
|
||||
return;
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not check inventory for player: " + xPlayer.getPlayerName(), e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
PlayerInventory inv = xPlayer.getPlayer().getInventory();
|
||||
StringBuilder sbItems = new StringBuilder();
|
||||
StringBuilder sbAmount = new StringBuilder();
|
||||
StringBuilder sbDurability = new StringBuilder();
|
||||
|
||||
for (ItemStack item : inv.getContents()) {
|
||||
int itemid = 0;
|
||||
int amount = 0;
|
||||
short durability = 0;
|
||||
|
||||
if (item != null) {
|
||||
itemid = item.getTypeId();
|
||||
amount = item.getAmount();
|
||||
durability = item.getDurability();
|
||||
}
|
||||
|
||||
sbItems.append(itemid + ",");
|
||||
sbAmount.append(amount + ",");
|
||||
sbDurability.append(durability + ",");
|
||||
}
|
||||
|
||||
for (ItemStack item : inv.getArmorContents()) {
|
||||
int itemid = 0;
|
||||
int amount = 0;
|
||||
short durability = 0;
|
||||
|
||||
if (item != null) {
|
||||
itemid = item.getTypeId();
|
||||
amount = item.getAmount();
|
||||
durability = item.getDurability();
|
||||
}
|
||||
|
||||
sbItems.append(itemid + ",");
|
||||
sbAmount.append(amount + ",");
|
||||
sbDurability.append(durability + ",");
|
||||
}
|
||||
|
||||
sbItems.deleteCharAt(sbItems.lastIndexOf(","));
|
||||
sbAmount.deleteCharAt(sbAmount.lastIndexOf(","));
|
||||
sbDurability.deleteCharAt(sbDurability.lastIndexOf(","));
|
||||
|
||||
sql = "INSERT INTO `" + xAuthSettings.tblInventory + "` VALUES (?, ?, ?, ?)";
|
||||
Database.queryWrite(sql, xPlayer.getPlayerName(), sbItems.toString(), sbAmount.toString(), sbDurability.toString());
|
||||
}
|
||||
|
||||
public static void deleteInventory(xAuthPlayer xPlayer) {
|
||||
String sql = "DELETE FROM `" + xAuthSettings.tblInventory + "` WHERE `playername` = ?";
|
||||
Database.queryWrite(sql, xPlayer.getPlayerName());
|
||||
}
|
||||
/* END INVENTORY FUNCTIONS */
|
||||
public static xAuthPlayer getPlayerFromDb(String playerName) {
|
||||
xAuthPlayer xPlayer = null;
|
||||
String sql = "SELECT a.*, s.*" +
|
||||
" FROM `" + xAuthSettings.tblAccount + "` a" +
|
||||
" LEFT JOIN `" + xAuthSettings.tblSession + "` s" +
|
||||
" ON a.id = s.accountid" +
|
||||
" WHERE `playername` = ?";
|
||||
ResultSet rs = Database.queryRead(sql, playerName);
|
||||
|
||||
try {
|
||||
if (rs.next())
|
||||
xPlayer = new xAuthPlayer(playerName, Util.buildAccount(rs), Util.buildSession(rs));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not load player: " + playerName, e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
return xPlayer;
|
||||
}
|
||||
|
||||
public static xAuthPlayer reloadPlayer(xAuthPlayer xPlayer) {
|
||||
String sql = "SELECT a.*, s.*" +
|
||||
" FROM `" + xAuthSettings.tblAccount + "` a" +
|
||||
" LEFT JOIN `" + xAuthSettings.tblSession + "` s" +
|
||||
" ON a.id = s.accountid" +
|
||||
" WHERE `playername` = ?";
|
||||
ResultSet rs = Database.queryRead(sql, xPlayer.getPlayerName());
|
||||
|
||||
try {
|
||||
if (rs.next()) {
|
||||
xPlayer.setAccount(Util.buildAccount(rs));
|
||||
xPlayer.setSession(Util.buildSession(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not reload player: " + xPlayer.getPlayerName(), e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
return xPlayer;
|
||||
}
|
||||
|
||||
public static int getActive(String playerName) {
|
||||
String sql = "SELECT `active` FROM `" + xAuthSettings.tblAccount + "` WHERE `playername` = ?";
|
||||
ResultSet rs = Database.queryRead(sql, playerName);
|
||||
|
||||
try {
|
||||
if (rs.next())
|
||||
return rs.getInt("active");
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not check active status of player: " + playerName, e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void deleteExpiredSessions() {
|
||||
String sql;
|
||||
|
||||
if (Database.getDBMS() == DBMS.H2)
|
||||
sql = "DELETE FROM `" + xAuthSettings.tblSession + "`" +
|
||||
" WHERE NOW() > DATEADD('SECOND', " + xAuthSettings.sessionLength + ", `logintime`)";
|
||||
else
|
||||
sql = "DELETE FROM `" + xAuthSettings.tblSession + "`" +
|
||||
" WHERE NOW() > ADDDATE(`logintime`, INTERVAL " + xAuthSettings.sessionLength + " SECOND)";
|
||||
|
||||
Database.queryWrite(sql);
|
||||
}
|
||||
|
||||
public static boolean isHostUsed(String host) {
|
||||
String sql = "SELECT * FROM `" + xAuthSettings.tblAccount + "` WHERE `registerip` = ?";
|
||||
ResultSet rs = Database.queryRead(sql, host);
|
||||
|
||||
try {
|
||||
if (rs.next())
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not check if IP address has been used!", e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,839 +0,0 @@
|
||||
package com.cypherx.xauth.datamanager;
|
||||
|
||||
import java.sql.Connection;
|
||||
//import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.cypherx.xauth.Account;
|
||||
import com.cypherx.xauth.Session;
|
||||
import com.cypherx.xauth.StrikeBan;
|
||||
import com.cypherx.xauth.TeleLocation;
|
||||
import com.cypherx.xauth.Util;
|
||||
//import com.cypherx.xauth.xAuth;
|
||||
import com.cypherx.xauth.xAuthLog;
|
||||
import com.cypherx.xauth.xAuthPlayer;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
|
||||
public abstract class DataManager {
|
||||
protected Connection connection = null;
|
||||
protected Statement stmt = null;
|
||||
private PreparedStatement prepStmt = null;
|
||||
private ResultSet rs = null;
|
||||
|
||||
private ConcurrentHashMap<String, xAuthPlayer> playerCache = new ConcurrentHashMap<String, xAuthPlayer>();
|
||||
private ConcurrentHashMap<String, TeleLocation> teleLocations = new ConcurrentHashMap<String, TeleLocation>();
|
||||
|
||||
public DataManager() {
|
||||
connect();
|
||||
|
||||
if (isConnected()) {
|
||||
try {
|
||||
stmt = connection.createStatement();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void connect();
|
||||
public abstract void deleteExpiredSessions();
|
||||
|
||||
/*private void connect() {
|
||||
if (xAuthSettings.datasource.equals("mysql"))
|
||||
connectMySQL();
|
||||
else
|
||||
connectH2();
|
||||
}
|
||||
|
||||
private void connectMySQL() {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
connection = DriverManager.getConnection("jdbc:mysql://" + xAuthSettings.mysqlHost + ":" + xAuthSettings.mysqlPort + "/" +
|
||||
xAuthSettings.mysqlDb + "?zeroDateTimeBehavior=convertToNull", xAuthSettings.mysqlUser, xAuthSettings.mysqlPass);
|
||||
stmt = connection.createStatement();
|
||||
xAuthLog.info("Connection to MySQL server established!");
|
||||
} catch (ClassNotFoundException e) {
|
||||
xAuthLog.severe("Missing MySQL library!", e);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not connect to MySQL server!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void connectH2() {
|
||||
if (!xAuthSettings.datasource.equals("default"))
|
||||
System.out.println("[" + xAuth.desc.getName() + "] Unknown datasource '" + xAuthSettings.datasource + "' - Using default (H2)");
|
||||
|
||||
try {
|
||||
Class.forName("org.h2.Driver");
|
||||
connection = DriverManager.getConnection("jdbc:h2:" + xAuth.dataFolder.toString() +
|
||||
System.getProperty("file.separator") + "xAuth;IGNORECASE=TRUE", "sa", "");
|
||||
stmt = connection.createStatement();
|
||||
xAuthLog.info("Connection to H2 database established!");
|
||||
} catch (ClassNotFoundException e) {
|
||||
xAuthLog.severe("Missing H2 library!", e);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not connect to H2 database!", e);
|
||||
}
|
||||
}*/
|
||||
|
||||
public void runStartupTasks() {
|
||||
createTables();
|
||||
loadTeleLocations();
|
||||
deleteExpiredSessions();
|
||||
|
||||
/*String sql;
|
||||
|
||||
if (xAuthSettings.datasource.equals("mysql")) {
|
||||
sql = "DELETE FROM `" + xAuthSettings.tblSession + "`" +
|
||||
"WHERE NOW() > ADDDATE(`logintime`, INTERVAL " + xAuthSettings.sessionLength + " SECOND)";
|
||||
} else {
|
||||
sql = "DELETE FROM `" + xAuthSettings.tblSession + "`" +
|
||||
"WHERE NOW() > DATEADD('SECOND', " + xAuthSettings.sessionLength + ", `logintime`)";
|
||||
}
|
||||
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
// delete expired sessions
|
||||
try {
|
||||
stmt.executeUpdate(sql);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not delete expired settings!", e);
|
||||
}*/
|
||||
}
|
||||
|
||||
public void createTables() {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
stmt.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `" + xAuthSettings.tblAccount + "` (" +
|
||||
"`id` INT UNSIGNED NOT NULL AUTO_INCREMENT," +
|
||||
"`playername` VARCHAR(255) NOT NULL," +
|
||||
"`password` CHAR(255) NOT NULL," +
|
||||
"`email` VARCHAR(100) NULL," +
|
||||
"`registerdate` DATETIME NULL," +
|
||||
"`registerip` CHAR(15) NULL," +
|
||||
"`lastlogindate` DATETIME NULL," +
|
||||
"`lastloginip` CHAR(15) NULL," +
|
||||
"`active` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0," +
|
||||
"PRIMARY KEY(`id`)" +
|
||||
")"
|
||||
);
|
||||
|
||||
stmt.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `" + xAuthSettings.tblSession + "` (" +
|
||||
"`accountid` INT UNSIGNED NOT NULL," +
|
||||
"`host` CHAR(15) NOT NULL," +
|
||||
"`logintime` DATETIME NOT NULL," +
|
||||
"PRIMARY KEY(`accountid`)," +
|
||||
"FOREIGN KEY (`accountid`) REFERENCES `" + xAuthSettings.tblAccount + "`(`id`) ON DELETE CASCADE" +
|
||||
")"
|
||||
);
|
||||
|
||||
stmt.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `" + xAuthSettings.tblLocation + "` (" +
|
||||
"`worldname` VARCHAR(255) NOT NULL," +
|
||||
"`x` DOUBLE NOT NULL," +
|
||||
"`y` DOUBLE NOT NULL," +
|
||||
"`z` DOUBLE NOT NULL," +
|
||||
"`yaw` FLOAT NOT NULL," +
|
||||
"`pitch` FLOAT NOT NULL," +
|
||||
"PRIMARY KEY(`worldname`)" +
|
||||
")"
|
||||
);
|
||||
|
||||
stmt.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `" + xAuthSettings.tblStrike + "` (" +
|
||||
"`host` CHAR(15) NOT NULL," +
|
||||
"`bantime` DATETIME NOT NULL," +
|
||||
"PRIMARY KEY(`host`)" +
|
||||
")"
|
||||
);
|
||||
|
||||
stmt.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `" + xAuthSettings.tblInventory + "` (" +
|
||||
"`playername` VARCHAR(255) NOT NULL," +
|
||||
"`itemid` TEXT NOT NULL," +
|
||||
"`amount` TEXT NOT NULL," +
|
||||
"`durability` TEXT NOT NULL," +
|
||||
"PRIMARY KEY (`playername`)" +
|
||||
")"
|
||||
);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not check/create database tables!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void printStats() {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
rs = stmt.executeQuery(
|
||||
"SELECT" +
|
||||
" (SELECT COUNT(*) FROM `" + xAuthSettings.tblAccount + "`) AS accounts," +
|
||||
" (SELECT COUNT(*) FROM `" + xAuthSettings.tblSession + "`) AS sessions"
|
||||
);
|
||||
|
||||
if (rs.next())
|
||||
xAuthLog.info("Accounts: " + rs.getInt("accounts") + ", Sessions: " + rs.getInt("sessions"));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not fetch xAuth statistics!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertInventory(xAuthPlayer xPlayer) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"SELECT *" +
|
||||
" FROM `" + xAuthSettings.tblInventory + "`" +
|
||||
" WHERE `playername` = ?"
|
||||
);
|
||||
prepStmt.setString(1, xPlayer.getPlayerName());
|
||||
rs = prepStmt.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
return;
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not check inventory for player: " + xPlayer.getPlayerName(), e);
|
||||
}
|
||||
|
||||
PlayerInventory inv = xPlayer.getPlayer().getInventory();
|
||||
StringBuilder sbItems = new StringBuilder();
|
||||
StringBuilder sbAmount = new StringBuilder();
|
||||
StringBuilder sbDurability = new StringBuilder();
|
||||
|
||||
for (ItemStack item : inv.getContents()) {
|
||||
int itemid = 0;
|
||||
int amount = 0;
|
||||
short durability = 0;
|
||||
|
||||
if (item != null) {
|
||||
itemid = item.getTypeId();
|
||||
amount = item.getAmount();
|
||||
durability = item.getDurability();
|
||||
}
|
||||
|
||||
sbItems.append(itemid + ",");
|
||||
sbAmount.append(amount + ",");
|
||||
sbDurability.append(durability + ",");
|
||||
}
|
||||
|
||||
for (ItemStack item : inv.getArmorContents()) {
|
||||
int itemid = 0;
|
||||
int amount = 0;
|
||||
short durability = 0;
|
||||
|
||||
if (item != null) {
|
||||
itemid = item.getTypeId();
|
||||
amount = item.getAmount();
|
||||
durability = item.getDurability();
|
||||
}
|
||||
|
||||
sbItems.append(itemid + ",");
|
||||
sbAmount.append(amount + ",");
|
||||
sbDurability.append(durability + ",");
|
||||
}
|
||||
|
||||
sbItems.deleteCharAt(sbItems.lastIndexOf(","));
|
||||
sbAmount.deleteCharAt(sbAmount.lastIndexOf(","));
|
||||
sbDurability.deleteCharAt(sbDurability.lastIndexOf(","));
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"INSERT INTO `" + xAuthSettings.tblInventory + "`" +
|
||||
" VALUES" +
|
||||
"(?, ?, ?, ?)"
|
||||
);
|
||||
prepStmt.setString(1, xPlayer.getPlayerName());
|
||||
prepStmt.setString(2, sbItems.toString());
|
||||
prepStmt.setString(3, sbAmount.toString());
|
||||
prepStmt.setString(4, sbDurability.toString());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not insert inventory for player: " + xPlayer.getPlayerName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory(xAuthPlayer xPlayer) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"SELECT *" +
|
||||
" FROM `" + xAuthSettings.tblInventory + "`" +
|
||||
" WHERE `playername` = ?"
|
||||
);
|
||||
prepStmt.setString(1, xPlayer.getPlayerName());
|
||||
rs = prepStmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int[] itemid = Util.stringToInt(rs.getString("itemid").split(","));
|
||||
int[] amount = Util.stringToInt(rs.getString("amount").split(","));
|
||||
int[] durability = Util.stringToInt(rs.getString("durability").split(","));
|
||||
ItemStack[] inv = new ItemStack[itemid.length];
|
||||
|
||||
for (int i = 0; i < inv.length; i++)
|
||||
inv[i] = new ItemStack(itemid[i], amount[i], (short)durability[i]);
|
||||
|
||||
return inv;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not load inventory for player: " + xPlayer.getPlayerName(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void deleteInventory(xAuthPlayer xPlayer) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"DELETE FROM `" + xAuthSettings.tblInventory + "`" +
|
||||
" WHERE `playername` = ?"
|
||||
);
|
||||
prepStmt.setString(1, xPlayer.getPlayerName());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not delete inventory for player: " + xPlayer.getPlayerName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public xAuthPlayer getPlayer(String playerName) {
|
||||
String lowPlayerName = playerName.toLowerCase();
|
||||
|
||||
if (playerCache.containsKey(lowPlayerName))
|
||||
return playerCache.get(lowPlayerName);
|
||||
|
||||
xAuthPlayer xPlayer = getPlayerFromDb(playerName);
|
||||
if (xPlayer == null)
|
||||
xPlayer = new xAuthPlayer(playerName);
|
||||
|
||||
playerCache.put(lowPlayerName, xPlayer);
|
||||
return xPlayer;
|
||||
}
|
||||
|
||||
public xAuthPlayer getPlayerJoin(String playerName) {
|
||||
String lowPlayerName = playerName.toLowerCase();
|
||||
|
||||
if (playerCache.containsKey(lowPlayerName))
|
||||
return reloadPlayer(playerCache.get(lowPlayerName));
|
||||
|
||||
xAuthPlayer xPlayer = getPlayerFromDb(playerName);
|
||||
if (xPlayer == null)
|
||||
xPlayer = new xAuthPlayer(playerName);
|
||||
|
||||
playerCache.put(lowPlayerName, xPlayer);
|
||||
return xPlayer;
|
||||
}
|
||||
|
||||
public xAuthPlayer getPlayerFromDb(String playerName) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
xAuthPlayer xPlayer = null;
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"SELECT a.*, s.*" +
|
||||
" FROM `" + xAuthSettings.tblAccount + "` a" +
|
||||
" LEFT JOIN `" + xAuthSettings.tblSession + "` s" +
|
||||
" ON a.id = s.accountid" +
|
||||
" WHERE `playername` = ?"
|
||||
);
|
||||
prepStmt.setString(1, playerName);
|
||||
rs = prepStmt.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
xPlayer = new xAuthPlayer(playerName, buildAccount(rs), buildSession(rs));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not load player: " + playerName, e);
|
||||
}
|
||||
|
||||
return xPlayer;
|
||||
}
|
||||
|
||||
public xAuthPlayer reloadPlayer(xAuthPlayer xPlayer) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"SELECT a.*, s.*" +
|
||||
" FROM `" + xAuthSettings.tblAccount + "` a" +
|
||||
" LEFT JOIN `" + xAuthSettings.tblSession + "` s" +
|
||||
" ON a.id = s.accountid" +
|
||||
" WHERE `playername` = ?"
|
||||
);
|
||||
prepStmt.setString(1, xPlayer.getPlayerName());
|
||||
rs = prepStmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
xPlayer.setAccount(buildAccount(rs));
|
||||
xPlayer.setSession(buildSession(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not reload player: " + xPlayer.getPlayerName(), e);
|
||||
}
|
||||
|
||||
return xPlayer;
|
||||
}
|
||||
|
||||
public int getActive(String playerName) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"SELECT `active`" +
|
||||
" FROM `" + xAuthSettings.tblAccount + "`" +
|
||||
" WHERE `playername` = ?"
|
||||
);
|
||||
prepStmt.setString(1, playerName);
|
||||
rs = prepStmt.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
return rs.getInt("active");
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not check active status of player: " + playerName, e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void saveAccount(Account account) {
|
||||
if (account.getId() == 0)
|
||||
insertAccount(account);
|
||||
else
|
||||
updateAccount(account);
|
||||
}
|
||||
|
||||
protected void insertAccount(Account account) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"INSERT INTO `" + xAuthSettings.tblAccount + "`" +
|
||||
" (`playername`, `password`, `email`, `registerdate`, `registerip`, `lastlogindate`, `lastloginip`, `active`)" +
|
||||
" VALUES" +
|
||||
" (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
prepStmt.setString(1, account.getPlayerName());
|
||||
prepStmt.setString(2, account.getPassword());
|
||||
prepStmt.setString(3, account.getEmail());
|
||||
prepStmt.setTimestamp(4, account.getRegisterDate());
|
||||
prepStmt.setString(5, account.getRegisterHost());
|
||||
prepStmt.setTimestamp(6, account.getLastLoginDate());
|
||||
prepStmt.setString(7, account.getLastLoginHost());
|
||||
prepStmt.setInt(8, account.getActive());
|
||||
prepStmt.executeUpdate();
|
||||
|
||||
rs = prepStmt.getGeneratedKeys();
|
||||
if (rs.next())
|
||||
account.setId(rs.getInt(1));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not insert account for player: " + account.getPlayerName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertAccounts(List<Account> accounts) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Account account;
|
||||
sb.append("INSERT INTO `" + xAuthSettings.tblAccount + "` (`playername`, `password`) VALUES");
|
||||
sb.append(" (?, ?)");
|
||||
|
||||
for (int i = 1; i < accounts.size(); i++)
|
||||
sb.append(", (?, ?)");
|
||||
sb.append(";");
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(sb.toString());
|
||||
for (int i = 0, j = 1; j < accounts.size() * 2; i++, j += 2) {
|
||||
account = accounts.get(i);
|
||||
prepStmt.setString(j, account.getPlayerName());
|
||||
prepStmt.setString(j + 1, account.getPassword().toLowerCase());
|
||||
}
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateAccount(Account account) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"UPDATE `" + xAuthSettings.tblAccount + "`" +
|
||||
" SET" +
|
||||
" `playername` = ?," +
|
||||
"`password` = ?," +
|
||||
"`email` = ?," +
|
||||
"`registerdate` = ?," +
|
||||
"`registerip` = ?," +
|
||||
"`lastlogindate` = ?," +
|
||||
"`lastloginip` = ?," +
|
||||
"`active` = ?" +
|
||||
" WHERE id = ?"
|
||||
);
|
||||
prepStmt.setString(1, account.getPlayerName());
|
||||
prepStmt.setString(2, account.getPassword());
|
||||
prepStmt.setString(3, account.getEmail());
|
||||
prepStmt.setTimestamp(4, account.getRegisterDate());
|
||||
prepStmt.setString(5, account.getRegisterHost());
|
||||
prepStmt.setTimestamp(6, account.getLastLoginDate());
|
||||
prepStmt.setString(7, account.getLastLoginHost());
|
||||
prepStmt.setInt(8, account.getActive());
|
||||
prepStmt.setInt(9, account.getId());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not update account for player: " + account.getPlayerName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAccount(xAuthPlayer xPlayer) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
Account account = xPlayer.getAccount();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"DELETE FROM `" + xAuthSettings.tblAccount + "`" +
|
||||
" WHERE `id` = ?"
|
||||
);
|
||||
prepStmt.setInt(1, account.getId());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not delete account for player: " + xPlayer.getPlayerName(), e);
|
||||
}
|
||||
|
||||
xPlayer.setAccount(null);
|
||||
xPlayer.setSession(null);
|
||||
}
|
||||
|
||||
public void insertSession(Session session) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"INSERT INTO `" + xAuthSettings.tblSession + "`" +
|
||||
" VALUES" +
|
||||
" (?, ?, ?)",
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
prepStmt.setInt(1, session.getAccountId());
|
||||
prepStmt.setString(2, session.getHost());
|
||||
prepStmt.setTimestamp(3, session.getLoginTime());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not insert session for account: " + session.getAccountId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteSession(xAuthPlayer xPlayer) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
Session session = xPlayer.getSession();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"DELETE FROM `" + xAuthSettings.tblSession + "`" +
|
||||
" WHERE `accountid` = ?"
|
||||
);
|
||||
prepStmt.setInt(1, session.getAccountId());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not delete session for player: " + xPlayer.getPlayerName(), e);
|
||||
}
|
||||
|
||||
xPlayer.setSession(null);
|
||||
}
|
||||
|
||||
public void loadTeleLocations() {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
rs = stmt.executeQuery(
|
||||
"SELECT * " +
|
||||
"FROM `" + xAuthSettings.tblLocation + "`"
|
||||
);
|
||||
|
||||
while (rs.next()) {
|
||||
TeleLocation teleLocation = new TeleLocation();
|
||||
teleLocation.setWorldName(rs.getString("worldname"));
|
||||
teleLocation.setX(rs.getDouble("x"));
|
||||
teleLocation.setY(rs.getDouble("y"));
|
||||
teleLocation.setZ(rs.getDouble("z"));
|
||||
teleLocation.setYaw(rs.getFloat("yaw"));
|
||||
teleLocation.setPitch(rs.getFloat("pitch"));
|
||||
teleLocations.put(teleLocation.getWorldName(), teleLocation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not load TeleLocations from database!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertTeleLocation(TeleLocation teleLocation) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"INSERT INTO `" + xAuthSettings.tblLocation + "`" +
|
||||
" VALUES" +
|
||||
" (?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
|
||||
prepStmt.setString(1, teleLocation.getWorldName());
|
||||
prepStmt.setDouble(2, teleLocation.getX());
|
||||
prepStmt.setDouble(3, teleLocation.getY());
|
||||
prepStmt.setDouble(4, teleLocation.getZ());
|
||||
prepStmt.setFloat(5, teleLocation.getYaw());
|
||||
prepStmt.setFloat(6, teleLocation.getPitch());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not insert TeleLocation for world: " + teleLocation.getWorldName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTeleLocation(TeleLocation teleLocation) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"UPDATE `" + xAuthSettings.tblLocation + "`" +
|
||||
" SET " +
|
||||
"`x` = ?," +
|
||||
"`y` = ?," +
|
||||
"`z` = ?," +
|
||||
"`yaw` = ?," +
|
||||
"`pitch` = ?" +
|
||||
" WHERE `worldname` = ?"
|
||||
);
|
||||
prepStmt.setDouble(1, teleLocation.getX());
|
||||
prepStmt.setDouble(2, teleLocation.getY());
|
||||
prepStmt.setDouble(3, teleLocation.getZ());
|
||||
prepStmt.setFloat(4, teleLocation.getYaw());
|
||||
prepStmt.setFloat(5, teleLocation.getPitch());
|
||||
prepStmt.setString(6, teleLocation.getWorldName());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not update TeleLocation for world: " + teleLocation.getWorldName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteTeleLocation(TeleLocation teleLocation) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"DELETE FROM `" + xAuthSettings.tblLocation + "`" +
|
||||
" WHERE `worldname` = ?"
|
||||
);
|
||||
|
||||
prepStmt.setString(1, teleLocation.getWorldName());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not delete TeleLocation for world: " + teleLocation.getWorldName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public StrikeBan loadStrikeBan(String host) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
StrikeBan ban = null;
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"SELECT * " +
|
||||
"FROM `" + xAuthSettings.tblStrike + "`" +
|
||||
" WHERE `host` = ?"
|
||||
);
|
||||
|
||||
prepStmt.setString(1, host);
|
||||
rs = prepStmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
ban = new StrikeBan();
|
||||
ban.setHost(rs.getString("host"));
|
||||
ban.setBanTime(rs.getTimestamp("bantime"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not load StrikeBan for host: " + host, e);
|
||||
}
|
||||
|
||||
return ban;
|
||||
}
|
||||
|
||||
public void insertStrikeBan(StrikeBan ban) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"INSERT INTO `" + xAuthSettings.tblStrike + "`" +
|
||||
" (`host`, `bantime`)" +
|
||||
" VALUES" +
|
||||
" (?, ?)"
|
||||
);
|
||||
|
||||
prepStmt.setString(1, ban.getHost());
|
||||
prepStmt.setTimestamp(2, ban.getBanTime());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not insert StrikeBan for host: " + ban.getHost(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteStrikeBan(StrikeBan ban) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"DELETE FROM `" + xAuthSettings.tblStrike + "`" +
|
||||
" WHERE `host` = ?"
|
||||
);
|
||||
|
||||
prepStmt.setString(1, ban.getHost());
|
||||
prepStmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not delete StrikeBan for host: " + ban.getHost(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isHostUsed(String host) {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
prepStmt = connection.prepareStatement(
|
||||
"SELECT `id`" +
|
||||
" FROM `" + xAuthSettings.tblAccount + "`" +
|
||||
" WHERE `registerip` = ?"
|
||||
);
|
||||
prepStmt.setString(1, host);
|
||||
rs = prepStmt.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not check if IP address has been used!", e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
|
||||
try {
|
||||
if (stmt != null)
|
||||
stmt.close();
|
||||
} catch (SQLException e) {}
|
||||
|
||||
try {
|
||||
if (prepStmt != null)
|
||||
prepStmt.close();
|
||||
} catch (SQLException e) {}
|
||||
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
private Account buildAccount(ResultSet rs) {
|
||||
Account account = null;
|
||||
try {
|
||||
account = new Account();
|
||||
account.setId(rs.getInt("id"));
|
||||
account.setPlayerName(rs.getString("playername"));
|
||||
account.setPassword(rs.getString("password"));
|
||||
account.setEmail(rs.getString("email"));
|
||||
account.setRegisterDate(rs.getTimestamp("registerdate"));
|
||||
account.setRegisterHost(rs.getString("registerip"));
|
||||
account.setLastLoginDate(rs.getTimestamp("lastlogindate"));
|
||||
account.setLastLoginHost(rs.getString("lastloginip"));
|
||||
account.setActive(rs.getInt("active"));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Error while building Account from ResultSet!", e);
|
||||
}
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
private Session buildSession(ResultSet rs) {
|
||||
Session session = null;
|
||||
try {
|
||||
session = new Session();
|
||||
session.setAccountId(rs.getInt("accountid"));
|
||||
|
||||
if (rs.wasNull()) // no session data in database
|
||||
return null;
|
||||
|
||||
session.setHost(rs.getString("host"));
|
||||
session.setLoginTime(rs.getTimestamp("logintime"));
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Error while building Session from ResultSet!", e);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
try {
|
||||
if (connection == null || connection.isClosed())
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public TeleLocation getTeleLocation(String worldName) {
|
||||
return teleLocations.get(worldName);
|
||||
}
|
||||
|
||||
public void setTeleLocation(TeleLocation teleLocation) {
|
||||
TeleLocation tOld = teleLocations.put(teleLocation.getWorldName(), teleLocation);
|
||||
if (tOld == null)
|
||||
insertTeleLocation(teleLocation);
|
||||
else
|
||||
updateTeleLocation(teleLocation);
|
||||
}
|
||||
|
||||
public void removeTeleLocation(TeleLocation teleLocation) {
|
||||
teleLocations.remove(teleLocation.getWorldName());
|
||||
deleteTeleLocation(teleLocation);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package com.cypherx.xauth.datamanager;
|
||||
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.cypherx.xauth.xAuth;
|
||||
import com.cypherx.xauth.xAuthLog;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
|
||||
public class H2 extends DataManager {
|
||||
public H2() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
if (!xAuthSettings.datasource.equals("default"))
|
||||
System.out.println("[" + xAuth.desc.getName() + "] Unknown datasource '" + xAuthSettings.datasource + "' - Using default (H2)");
|
||||
|
||||
try {
|
||||
Class.forName("org.h2.Driver");
|
||||
connection = DriverManager.getConnection("jdbc:h2:" + xAuth.dataFolder.toString() +
|
||||
System.getProperty("file.separator") + "xAuth;IGNORECASE=TRUE", "sa", "");
|
||||
xAuthLog.info("Connection to H2 database established!");
|
||||
} catch (ClassNotFoundException e) {
|
||||
xAuthLog.severe("Missing H2 library!", e);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not connect to H2 database!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteExpiredSessions() {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
stmt.executeUpdate(
|
||||
"DELETE FROM `" + xAuthSettings.tblSession + "`" +
|
||||
"WHERE NOW() > DATEADD('SECOND', " + xAuthSettings.sessionLength + ", `logintime`)"
|
||||
);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not delete expired settings!", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.cypherx.xauth.datamanager;
|
||||
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.cypherx.xauth.xAuthLog;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
|
||||
public class MySQL extends DataManager {
|
||||
public MySQL() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
connection = DriverManager.getConnection("jdbc:mysql://" + xAuthSettings.mysqlHost + ":" + xAuthSettings.mysqlPort + "/" +
|
||||
xAuthSettings.mysqlDb + "?zeroDateTimeBehavior=convertToNull", xAuthSettings.mysqlUser, xAuthSettings.mysqlPass);
|
||||
xAuthLog.info("Connection to MySQL server established!");
|
||||
} catch (ClassNotFoundException e) {
|
||||
xAuthLog.severe("Missing MySQL library!", e);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not connect to MySQL server!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteExpiredSessions() {
|
||||
if (!isConnected())
|
||||
connect();
|
||||
|
||||
try {
|
||||
stmt.executeUpdate(
|
||||
"DELETE FROM `" + xAuthSettings.tblSession + "`" +
|
||||
"WHERE NOW() > ADDDATE(`logintime`, INTERVAL " + xAuthSettings.sessionLength + " SECOND)"
|
||||
);
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not delete expired settings!", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ public class xAuthBlockListener extends BlockListener {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(event.getPlayer().getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
||||
//if (!xAuthSettings.rstrBreak && !xPlayer.isRegistered())
|
||||
//return;
|
||||
@ -43,7 +43,7 @@ public class xAuthBlockListener extends BlockListener {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(event.getPlayer().getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
||||
//if (!xAuthSettings.rstrPlace && !xPlayer.isRegistered())
|
||||
//return;
|
||||
|
@ -31,7 +31,7 @@ public class xAuthEntityListener extends EntityListener {
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player && ((Player)entity).isOnline()) { // player taking damage
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(((Player)entity).getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(((Player)entity).getName());
|
||||
|
||||
//if (!xAuthSettings.rstrDmgTaken && !xPlayer.isRegistered())
|
||||
//return;
|
||||
@ -46,7 +46,7 @@ public class xAuthEntityListener extends EntityListener {
|
||||
Entity damager = edbeEvent.getDamager();
|
||||
|
||||
if (damager instanceof Player) {
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(((Player)damager).getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(((Player)damager).getName());
|
||||
|
||||
//if (!xAuthSettings.rstrDmgGiven && !xPlayer.isRegistered())
|
||||
//return;
|
||||
@ -67,7 +67,7 @@ public class xAuthEntityListener extends EntityListener {
|
||||
|
||||
Entity target = event.getTarget();
|
||||
if (target instanceof Player) {
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(((Player)target).getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(((Player)target).getName());
|
||||
|
||||
//if (!xAuthSettings.rstrMobTarget && !xPlayer.isRegistered())
|
||||
//return;
|
||||
|
@ -15,6 +15,7 @@ import com.cypherx.xauth.xAuth;
|
||||
import com.cypherx.xauth.xAuthMessages;
|
||||
import com.cypherx.xauth.xAuthPlayer;
|
||||
import com.cypherx.xauth.xAuthSettings;
|
||||
import com.cypherx.xauth.database.DbUtil;
|
||||
|
||||
public class xAuthPlayerListener extends PlayerListener {
|
||||
private final xAuth plugin;
|
||||
@ -59,7 +60,7 @@ public class xAuthPlayerListener extends PlayerListener {
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayerJoin(player.getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayerJoin(player.getName());
|
||||
boolean isRegistered = xPlayer.isRegistered();
|
||||
|
||||
if (!xPlayer.isAuthenticated() && (isRegistered || (!isRegistered && xPlayer.mustRegister()))) {
|
||||
@ -93,14 +94,14 @@ public class xAuthPlayerListener extends PlayerListener {
|
||||
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(player.getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(player.getName());
|
||||
|
||||
if (xPlayer.isGuest())
|
||||
plugin.removeGuest(xPlayer);
|
||||
else if (xPlayer.hasSession()) {
|
||||
Session session = xPlayer.getSession();
|
||||
if (session.isExpired())
|
||||
plugin.getDataManager().deleteSession(xPlayer);
|
||||
DbUtil.deleteSession(xPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,7 +109,7 @@ public class xAuthPlayerListener extends PlayerListener {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(event.getPlayer().getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
||||
//if (!xAuthSettings.rstrChat && !xPlayer.isRegistered())
|
||||
//return;
|
||||
@ -125,7 +126,7 @@ public class xAuthPlayerListener extends PlayerListener {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(event.getPlayer().getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
||||
//if (!xAuthSettings.rstrCommands && !xPlayer.isRegistered())
|
||||
//return;
|
||||
@ -148,7 +149,7 @@ public class xAuthPlayerListener extends PlayerListener {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(event.getPlayer().getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
||||
//if (!xAuthSettings.rstrInteract && !xPlayer.isRegistered())
|
||||
//return;
|
||||
@ -200,7 +201,7 @@ public class xAuthPlayerListener extends PlayerListener {
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(player.getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(player.getName());
|
||||
|
||||
//if (!xAuthSettings.rstrMovement && !xPlayer.isRegistered())
|
||||
//return;
|
||||
@ -220,7 +221,7 @@ public class xAuthPlayerListener extends PlayerListener {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
xAuthPlayer xPlayer = plugin.getDataManager().getPlayer(event.getPlayer().getName());
|
||||
xAuthPlayer xPlayer = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
||||
//if (!xAuthSettings.rstrPickup && !xPlayer.isRegistered())
|
||||
//return;
|
||||
|
@ -1,16 +1,20 @@
|
||||
package com.cypherx.xauth;
|
||||
|
||||
import com.cypherx.xauth.commands.*;
|
||||
import com.cypherx.xauth.datamanager.*;
|
||||
import com.cypherx.xauth.database.*;
|
||||
import com.cypherx.xauth.listeners.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -23,21 +27,21 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
public class xAuth extends JavaPlugin {
|
||||
public static PluginDescriptionFile desc;
|
||||
public static File dataFolder;
|
||||
private DataManager dataManager;
|
||||
private ConcurrentHashMap<String, xAuthPlayer> playerCache = new ConcurrentHashMap<String, xAuthPlayer>();
|
||||
private ConcurrentHashMap<UUID, TeleLocation> teleLocations = new ConcurrentHashMap<UUID, TeleLocation>();
|
||||
private UUID globalUID = null;
|
||||
|
||||
public void onDisable() {
|
||||
Player[] players = getServer().getOnlinePlayers();
|
||||
if (players.length > 0) {
|
||||
for (Player player : players) {
|
||||
xAuthPlayer xPlayer = dataManager.getPlayer(player.getName());
|
||||
xAuthPlayer xPlayer = getPlayer(player.getName());
|
||||
if (xPlayer.isGuest())
|
||||
removeGuest(xPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
if (dataManager != null)
|
||||
dataManager.close();
|
||||
|
||||
Database.close();
|
||||
xAuthSettings.saveChanges();
|
||||
xAuthLog.info("v" + desc.getVersion() + " Disabled!");
|
||||
}
|
||||
@ -61,23 +65,27 @@ public class xAuth extends JavaPlugin {
|
||||
xAuthPermissions.setup(this);
|
||||
xAuthHelp.setup(this);
|
||||
|
||||
if (xAuthSettings.datasource.equals("mysql"))
|
||||
dataManager = new MySQL();
|
||||
else
|
||||
dataManager = new H2();
|
||||
|
||||
if (!dataManager.isConnected()) {
|
||||
Database.connect();
|
||||
if (!Database.isConnected()) {
|
||||
xAuthLog.severe("Disabling - No connection to database");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
dataManager.runStartupTasks();
|
||||
|
||||
DbUpdate dbUpdate = new DbUpdate();
|
||||
if (!dbUpdate.checkVersion()) {
|
||||
xAuthLog.info("Updating database..");
|
||||
dbUpdate.update();
|
||||
}
|
||||
|
||||
DbUtil.deleteExpiredSessions();
|
||||
loadTeleLocations();
|
||||
|
||||
File oldAuthFile = new File(dataFolder, "auths.txt");
|
||||
if (oldAuthFile.exists())
|
||||
importAccounts(oldAuthFile);
|
||||
|
||||
dataManager.printStats();
|
||||
Database.printStats();
|
||||
|
||||
Player[] players = getServer().getOnlinePlayers();
|
||||
if (players.length > 0) // /reload was used
|
||||
@ -119,7 +127,7 @@ public class xAuth extends JavaPlugin {
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
dataManager.insertAccounts(accounts);
|
||||
DbUtil.insertAccounts(accounts);
|
||||
|
||||
if (oldAuthFile.renameTo(new File(dataFolder, "auths.txt.old")))
|
||||
xAuthLog.info("Import complete! auths.txt renamed to auths.txt.old");
|
||||
@ -127,9 +135,37 @@ public class xAuth extends JavaPlugin {
|
||||
xAuthLog.info("Import complete! Verify that all accounts were imported then remove/rename auths.txt");
|
||||
}
|
||||
|
||||
public xAuthPlayer getPlayer(String playerName) {
|
||||
String lowPlayerName = playerName.toLowerCase();
|
||||
|
||||
if (playerCache.containsKey(lowPlayerName))
|
||||
return playerCache.get(lowPlayerName);
|
||||
|
||||
xAuthPlayer xPlayer = DbUtil.getPlayerFromDb(playerName);
|
||||
if (xPlayer == null)
|
||||
xPlayer = new xAuthPlayer(playerName);
|
||||
|
||||
playerCache.put(lowPlayerName, xPlayer);
|
||||
return xPlayer;
|
||||
}
|
||||
|
||||
public xAuthPlayer getPlayerJoin(String playerName) {
|
||||
String lowPlayerName = playerName.toLowerCase();
|
||||
|
||||
if (playerCache.containsKey(lowPlayerName))
|
||||
return DbUtil.reloadPlayer(playerCache.get(lowPlayerName));
|
||||
|
||||
xAuthPlayer xPlayer = DbUtil.getPlayerFromDb(playerName);
|
||||
if (xPlayer == null)
|
||||
xPlayer = new xAuthPlayer(playerName);
|
||||
|
||||
playerCache.put(lowPlayerName, xPlayer);
|
||||
return xPlayer;
|
||||
}
|
||||
|
||||
private void handleReload(Player[] players) {
|
||||
for (Player player : players) {
|
||||
xAuthPlayer xPlayer = dataManager.getPlayerJoin(player.getName());
|
||||
xAuthPlayer xPlayer = getPlayerJoin(player.getName());
|
||||
boolean isRegistered = xPlayer.isRegistered();
|
||||
|
||||
if (!xPlayer.isAuthenticated() && (isRegistered || (!isRegistered && xPlayer.mustRegister()))) {
|
||||
@ -144,7 +180,7 @@ public class xAuth extends JavaPlugin {
|
||||
|
||||
// remove old session (if any)
|
||||
if (xPlayer.hasSession())
|
||||
dataManager.deleteSession(xPlayer);
|
||||
DbUtil.deleteSession(xPlayer);
|
||||
|
||||
if (xAuthSettings.guestTimeout > 0 && xPlayer.isRegistered()) {
|
||||
int taskId = getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
|
||||
@ -174,7 +210,7 @@ public class xAuth extends JavaPlugin {
|
||||
Player player = xPlayer.getPlayer();
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
|
||||
dataManager.insertInventory(xPlayer);
|
||||
DbUtil.insertInventory(xPlayer);
|
||||
playerInv.clear();
|
||||
playerInv.setHelmet(null);
|
||||
playerInv.setChestplate(null);
|
||||
@ -193,7 +229,7 @@ public class xAuth extends JavaPlugin {
|
||||
Player player = xPlayer.getPlayer();
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
|
||||
ItemStack[] inv = dataManager.getInventory(xPlayer);
|
||||
ItemStack[] inv = DbUtil.getInventory(xPlayer);
|
||||
ItemStack[] items = new ItemStack[inv.length - 4];
|
||||
ItemStack[] armor = new ItemStack[4];
|
||||
|
||||
@ -218,7 +254,7 @@ public class xAuth extends JavaPlugin {
|
||||
|
||||
playerInv.setContents(items);
|
||||
playerInv.setArmorContents(armor);
|
||||
dataManager.deleteInventory(xPlayer);
|
||||
DbUtil.deleteInventory(xPlayer);
|
||||
|
||||
if (xPlayer.getLocation() != null)
|
||||
xPlayer.getPlayer().teleport(xPlayer.getLocation());
|
||||
@ -229,11 +265,11 @@ public class xAuth extends JavaPlugin {
|
||||
Account account = xPlayer.getAccount();
|
||||
account.setLastLoginDate(Util.getNow());
|
||||
account.setLastLoginHost(Util.getHostFromPlayer(xPlayer.getPlayer()));
|
||||
dataManager.saveAccount(account);
|
||||
DbUtil.saveAccount(account);
|
||||
|
||||
Session session = new Session(account.getId(), account.getLastLoginHost());
|
||||
xPlayer.setSession(session);
|
||||
dataManager.insertSession(session);
|
||||
DbUtil.insertSession(session);
|
||||
|
||||
removeGuest(xPlayer);
|
||||
xPlayer.setStrikes(0);
|
||||
@ -241,7 +277,7 @@ public class xAuth extends JavaPlugin {
|
||||
|
||||
public void changePassword(Account account, String newPass) {
|
||||
account.setPassword(Util.encrypt(newPass));
|
||||
dataManager.saveAccount(account);
|
||||
DbUtil.saveAccount(account);
|
||||
}
|
||||
|
||||
public boolean checkPassword(Account account, String checkPass) {
|
||||
@ -273,8 +309,77 @@ public class xAuth extends JavaPlugin {
|
||||
return (hash.substring(0, saltPos) + salt + hash.substring(saltPos)).equals(realPass);
|
||||
}
|
||||
|
||||
private void loadTeleLocations() {
|
||||
String sql = "SELECT * FROM `" + xAuthSettings.tblLocation + "`";
|
||||
ResultSet rs = Database.queryRead(sql);
|
||||
|
||||
try {
|
||||
while (rs.next()) {
|
||||
TeleLocation teleLocation = new TeleLocation();
|
||||
String uid = rs.getString("uid");
|
||||
boolean update = false;
|
||||
|
||||
// Database version 0001 -> 0002 fix
|
||||
if (Util.isUUID(uid))
|
||||
teleLocation.setUID(UUID.fromString(uid));
|
||||
else {
|
||||
teleLocation.setUID(getServer().getWorld(uid).getUID());
|
||||
update = true;
|
||||
}
|
||||
|
||||
teleLocation.setX(rs.getDouble("x"));
|
||||
teleLocation.setY(rs.getDouble("y"));
|
||||
teleLocation.setZ(rs.getDouble("z"));
|
||||
teleLocation.setYaw(rs.getFloat("yaw"));
|
||||
teleLocation.setPitch(rs.getFloat("pitch"));
|
||||
teleLocation.setGlobal(rs.getInt("global"));
|
||||
teleLocations.put(teleLocation.getUID(), teleLocation);
|
||||
|
||||
if (teleLocation.getGlobal() == 1)
|
||||
globalUID = teleLocation.getUID();
|
||||
|
||||
if (update) {
|
||||
sql = "UPDATE `" + xAuthSettings.tblLocation + "` SET `uid` = ? WHERE `uid` = ?";
|
||||
Database.queryWrite(sql, teleLocation.getUID().toString(), uid);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Could not load TeleLocations from database!", e);
|
||||
} finally {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public TeleLocation getTeleLocation(UUID uid) {
|
||||
if (uid == null)
|
||||
return null;
|
||||
|
||||
return teleLocations.get(uid);
|
||||
}
|
||||
|
||||
public void setTeleLocation(TeleLocation teleLocation) {
|
||||
TeleLocation tOld = teleLocations.put(teleLocation.getUID(), teleLocation);
|
||||
if (teleLocation.getGlobal() == 1)
|
||||
globalUID = teleLocation.getUID();
|
||||
|
||||
if (tOld == null)
|
||||
DbUtil.insertTeleLocation(teleLocation);
|
||||
else
|
||||
DbUtil.updateTeleLocation(teleLocation);
|
||||
}
|
||||
|
||||
public void removeTeleLocation(TeleLocation teleLocation) {
|
||||
teleLocations.remove(teleLocation.getUID());
|
||||
if (teleLocation.getGlobal() == 1)
|
||||
globalUID = null;
|
||||
|
||||
DbUtil.deleteTeleLocation(teleLocation);
|
||||
}
|
||||
|
||||
public Location getLocationToTeleport(World world) {
|
||||
TeleLocation teleLocation = dataManager.getTeleLocation(world.getName());
|
||||
TeleLocation teleLocation = getTeleLocation((globalUID == null ? world.getUID() : globalUID));
|
||||
return (teleLocation == null ? world.getSpawnLocation() : teleLocation.getLocation());
|
||||
}
|
||||
|
||||
@ -283,7 +388,7 @@ public class xAuth extends JavaPlugin {
|
||||
|
||||
if (xAuthSettings.strikeAction.equals("banip")) {
|
||||
StrikeBan ban = new StrikeBan(Util.getHostFromPlayer(player));
|
||||
getDataManager().insertStrikeBan(ban);
|
||||
DbUtil.insertStrikeBan(ban);
|
||||
xAuthLog.info(ban.getHost() + " banned by strike system");
|
||||
}
|
||||
|
||||
@ -295,7 +400,7 @@ public class xAuth extends JavaPlugin {
|
||||
}
|
||||
|
||||
public boolean isBanned(String host) {
|
||||
final StrikeBan ban = dataManager.loadStrikeBan(host);
|
||||
final StrikeBan ban = DbUtil.loadStrikeBan(host);
|
||||
if (ban == null)
|
||||
return false;
|
||||
|
||||
@ -306,7 +411,7 @@ public class xAuth extends JavaPlugin {
|
||||
if (unbanTime.compareTo(Util.getNow()) > 0) // still banned
|
||||
return true;
|
||||
else // no longer banned, remove from database
|
||||
dataManager.deleteStrikeBan(ban);
|
||||
DbUtil.deleteStrikeBan(ban);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -316,7 +421,7 @@ public class xAuth extends JavaPlugin {
|
||||
xAuthMessages.setup(dataFolder);
|
||||
}
|
||||
|
||||
public DataManager getDataManager() {
|
||||
return dataManager;
|
||||
public UUID getGlobalUID() {
|
||||
return globalUID;
|
||||
}
|
||||
}
|
@ -23,6 +23,6 @@ public class xAuthHelp {
|
||||
helpPlugin.registerCommand("xauth reload", "Reload the xAuth configuration and accounts", plugin, permissions[6]);
|
||||
xAuthLog.info("'Help' support enabled");
|
||||
} else
|
||||
xAuthLog.warning("'Help' isn't detected. No /help support");
|
||||
xAuthLog.info("'Help' isn't detected. No /help support");
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@ public class xAuthMessages {
|
||||
public static String admnRegSuccess = "{BRIGHTGREEN}Account successfully created for: {WHITE}{TARGET}";
|
||||
public static String admnCpwUsage = "{RED}Correct Usage: /xauth changepw <player> <new password>";
|
||||
public static String admnCpwRegistered = "{RED}This player is not registered!";
|
||||
public static String admnCpwSuccess = "{TARGET}''s {BRIGHTGREEN}password has been changed!";
|
||||
public static String admnCpwSuccess = "{TARGET}'s {BRIGHTGREEN}password has been changed!";
|
||||
public static String admnLogoutUsage = "{RED}Correct Usage: /xauth logout <player>";
|
||||
public static String admnLogoutLogged = "{TARGET} {RED}is not logged in!";
|
||||
public static String admnLogoutSuccess = "{TARGET} {BRIGHTGREEN}has been logged out!";
|
||||
@ -61,10 +61,15 @@ public class xAuthMessages {
|
||||
public static String admnUnregRegistered = "{RED}This player is not registered!";
|
||||
public static String admnUnregSuccessTgt = "{RED}You have been unregistered and logged out!";
|
||||
public static String admnUnregSuccessPlyr = "{TARGET} {BRIGHTGREEN}has been unregistered!";
|
||||
public static String admnLocUsage = "{RED}Correct Usage: /xauth location set|remove";
|
||||
public static String admnLocUsage = "{RED}Correct Usage: /xauth location set|remove [global]";
|
||||
public static String admnLocSetErrGlobal = "{YELLOW}{PLUGIN} {RED}Global teleport location is set to this world.{NEWLINE}{YELLOW}{PLUGIN} {RED}Please remove it first.";
|
||||
public static String admnLocSetSuccess = "{YELLOW}{PLUGIN} {BRIGHTGREEN}Teleport location for this world set to your location!";
|
||||
public static String admnLocSetGlobalSuccess = "{YELLOW}{PLUGIN} {BRIGHTGREEN}Global teleport location set to your location!";
|
||||
public static String admnLocRmvNo = "{YELLOW}{PLUGIN} {BRIGHTGREEN}This world does not have a teleport location!";
|
||||
public static String admnLocRmvErrGlobal = "{YELLOW}{PLUGIN} {RED}Global teleport location is set to this world.{NEWLINE}{YELLOW}{PLUGIN} {RED}Please use /xauth location remove global";
|
||||
public static String admnLocRmvGlobalNo = "{YELLOW}{PLUGIN} {BRIGHTGREEN}A global teleport location is not set!";
|
||||
public static String admnLocRmvSuccess = "{YELLOW}{PLUGIN} {BRIGHTGREEN}Teleport location for this world has been removed!";
|
||||
public static String admnLocRmvGlobalSuccess = "{YELLOW}{PLUGIN} {BRIGHTGREEN}Global teleport location has been removed!";
|
||||
public static String admnConfUsage = "{RED}Correct Usage: /xauth config <setting> [new value]";
|
||||
public static String admnConfNo = "{YELLOW}{PLUGIN} {RED}No such setting!";
|
||||
public static String admnConfDesc = "Setting: {SETTING}{NEWLINE}Type: {TYPE}{NEWLINE}Value: {VALUE}";
|
||||
@ -81,7 +86,7 @@ public class xAuthMessages {
|
||||
/*
|
||||
* REMEMBER TO CHANGE VERSION AFTER MODIFYING DEFAULT STRINGS
|
||||
*/
|
||||
public static int version = 1;
|
||||
public static int version = 2;
|
||||
|
||||
public static void setup(File dataFolder) {
|
||||
file = new File(dataFolder, "messages.yml");
|
||||
@ -145,9 +150,14 @@ public class xAuthMessages {
|
||||
admnUnregSuccessTgt = getString("admin.unregister.success.target", admnUnregSuccessTgt);
|
||||
admnUnregSuccessPlyr = getString("admin.unregister.success.player", admnUnregSuccessPlyr);
|
||||
admnLocUsage = getString("admin.location.usage", admnLocUsage);
|
||||
admnLocSetErrGlobal = getString("admin.location.set.isglobal", admnLocSetErrGlobal);
|
||||
admnLocSetSuccess = getString("admin.location.set.success", admnLocSetSuccess);
|
||||
admnLocSetGlobalSuccess = getString("admin.location.set.global.success", admnLocSetGlobalSuccess);
|
||||
admnLocRmvNo = getString("admin.location.remove.no", admnLocRmvNo);
|
||||
admnLocRmvErrGlobal = getString("admin.location.remove.isglobal", admnLocRmvErrGlobal);
|
||||
admnLocRmvSuccess = getString("admin.location.remove.success", admnLocRmvSuccess);
|
||||
admnLocRmvGlobalNo = getString("admin.location.remove.global.no", admnLocRmvGlobalNo);
|
||||
admnLocRmvGlobalSuccess = getString("admin.location.remove.global.success", admnLocRmvGlobalSuccess);
|
||||
admnConfUsage = getString("admin.config.usage", admnConfUsage);
|
||||
admnConfNo = getString("admin.config.no", admnConfNo);
|
||||
admnConfDesc = getString("admin.config.desc", admnConfDesc);
|
||||
@ -172,7 +182,7 @@ public class xAuthMessages {
|
||||
private static void update() {
|
||||
if (version > getInt("version", version)) {
|
||||
xAuthLog.info("Updating file: messages.yml");
|
||||
Util.writeConfig(file, xAuthSettings.class);
|
||||
Util.writeConfig(file, xAuthMessages.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class xAuthPermissions {
|
||||
permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||
xAuthLog.info("'Permission' support enabled");
|
||||
} else
|
||||
xAuthLog.warning("Permission system not detected, defaulting to OP");
|
||||
xAuthLog.info("Permission system not detected, defaulting to OP");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import com.cypherx.xauth.database.Database;
|
||||
|
||||
public class xAuthSettings {
|
||||
private static File file;
|
||||
private static Configuration config;
|
||||
@ -27,15 +29,6 @@ public class xAuthSettings {
|
||||
public static String tblStrike = "strike_bans";
|
||||
public static String tblLocation = "tele_locations";
|
||||
public static String tblInventory = "inventory";
|
||||
/*public static String colAccId = "id";
|
||||
public static String colAccPlayerName = "playername";
|
||||
public static String colAccPassword = "password";
|
||||
public static String colAccEmail = "email";
|
||||
public static String colAccRegDate = "registerdate";
|
||||
public static String colAccRegIp = "registerip";
|
||||
public static String colAccLastLoginDate = "lastlogindate";
|
||||
public static String colAccLastLoginIp = "lastloginip";
|
||||
public static String colAccActive = "active";*/
|
||||
|
||||
// registration
|
||||
public static boolean regEnabled = true;
|
||||
@ -120,15 +113,6 @@ public class xAuthSettings {
|
||||
tblStrike = getString("mysql.tables.strike", tblStrike);
|
||||
tblLocation = getString("mysql.tables.location", tblLocation);
|
||||
tblInventory = getString("mysql.tables.inventory", tblInventory);
|
||||
/*colAccId = getString("mysql.columns.account.id", colAccId);
|
||||
colAccPlayerName = getString("mysql.columns.account.playername", colAccPlayerName);
|
||||
colAccPassword = getString("mysql.columns.account.password", colAccPassword);
|
||||
colAccEmail = getString("mysql.columns.account.email", colAccEmail);
|
||||
colAccRegDate = getString("mysql.columns.account.registerdate", colAccRegDate);
|
||||
colAccRegIp = getString("mysql.columns.account.registerip", colAccRegIp);
|
||||
colAccLastLoginDate = getString("mysql.columns.account.lastlogindate", colAccLastLoginDate);
|
||||
colAccLastLoginIp = getString("mysql.columns.account.lastloginip", colAccLastLoginIp);
|
||||
colAccActive = getString("mysql.columns.account.active", colAccActive);*/
|
||||
|
||||
regEnabled = getBool("registration.enabled", regEnabled);
|
||||
regForced = getBool("registration.forced", regForced);
|
||||
@ -171,6 +155,9 @@ public class xAuthSettings {
|
||||
rstrDmgTaken = getBool("restrict.damage-taken", rstrDmgTaken);
|
||||
rstrDmgGiven = getBool("restrict.damage-given", rstrDmgGiven);
|
||||
rstrMobTarget = getBool("restrict.mob-target", rstrMobTarget);*/
|
||||
|
||||
if (datasource.equals("mysql"))
|
||||
Database.setDBMS(Database.DBMS.MYSQL);
|
||||
}
|
||||
|
||||
private static String getString(String key, String def) {
|
||||
|
@ -1,87 +1,94 @@
|
||||
join:
|
||||
register: '[joinRegister]'
|
||||
login: '[joinLogin]'
|
||||
register: "[joinRegister]"
|
||||
login: "[joinLogin]"
|
||||
error:
|
||||
banned: '[joinErrBanned]'
|
||||
online: '[joinErrOnline]'
|
||||
name: '[joinErrName]'
|
||||
banned: "[joinErrBanned]"
|
||||
online: "[joinErrOnline]"
|
||||
name: "[joinErrName]"
|
||||
|
||||
register:
|
||||
usage: '[regUsage]'
|
||||
success: '[regSuccess]'
|
||||
usage: "[regUsage]"
|
||||
success: "[regSuccess]"
|
||||
error:
|
||||
disabled: '[regErrDisabled]'
|
||||
registered: '[regErrRegistered]'
|
||||
multiple: '[regErrMultiple]'
|
||||
password: '[regErrPassword]'
|
||||
email: '[regErrEmail]'
|
||||
disabled: "[regErrDisabled]"
|
||||
registered: "[regErrRegistered]"
|
||||
multiple: "[regErrMultiple]"
|
||||
password: "[regErrPassword]"
|
||||
email: "[regErrEmail]"
|
||||
|
||||
login:
|
||||
usage: '[loginUsage]'
|
||||
success: '[loginSuccess]'
|
||||
usage: "[loginUsage]"
|
||||
success: "[loginSuccess]"
|
||||
error:
|
||||
registered: '[loginErrRegistered]'
|
||||
logged: '[loginErrLogged]'
|
||||
password: '[loginErrPassword]'
|
||||
activate: '[loginErrActivate]'
|
||||
registered: "[loginErrRegistered]"
|
||||
logged: "[loginErrLogged]"
|
||||
password: "[loginErrPassword]"
|
||||
activate: "[loginErrActivate]"
|
||||
|
||||
logout:
|
||||
success: '[logoutSuccess]'
|
||||
success: "[logoutSuccess]"
|
||||
error:
|
||||
logged: '[logoutErrLogged]'
|
||||
logged: "[logoutErrLogged]"
|
||||
|
||||
changepw:
|
||||
usage: '[cpwUsage]'
|
||||
success: '[cpwSuccess]'
|
||||
usage: "[cpwUsage]"
|
||||
success: "[cpwSuccess]"
|
||||
error:
|
||||
disabled: '[cpwErrDisabled]'
|
||||
logged: '[cpwErrLogged]'
|
||||
incorrect: '[cpwErrIncorrect]'
|
||||
invalid: '[cpwErrInvalid]'
|
||||
disabled: "[cpwErrDisabled]"
|
||||
logged: "[cpwErrLogged]"
|
||||
incorrect: "[cpwErrIncorrect]"
|
||||
invalid: "[cpwErrInvalid]"
|
||||
|
||||
admin:
|
||||
unknown: '[admnUnknown]'
|
||||
permission: '[admnPermission]'
|
||||
unknown: "[admnUnknown]"
|
||||
permission: "[admnPermission]"
|
||||
register:
|
||||
usage: '[admnRegUsage]'
|
||||
registered: '[admnRegRegistered]'
|
||||
success: '[admnRegSuccess]'
|
||||
usage: "[admnRegUsage]"
|
||||
registered: "[admnRegRegistered]"
|
||||
success: "[admnRegSuccess]"
|
||||
changepw:
|
||||
usage: '[admnCpwUsage]'
|
||||
registered: '[admnCpwRegistered]'
|
||||
success: '[admnCpwSuccess]'
|
||||
usage: "[admnCpwUsage]"
|
||||
registered: "[admnCpwRegistered]"
|
||||
success: "[admnCpwSuccess]"
|
||||
logout:
|
||||
usage: '[admnLogoutUsage]'
|
||||
logged: '[admnLogoutLogged]'
|
||||
success: '[admnLogoutSuccess]'
|
||||
usage: "[admnLogoutUsage]"
|
||||
logged: "[admnLogoutLogged]"
|
||||
success: "[admnLogoutSuccess]"
|
||||
unregister:
|
||||
usage: '[admnUnregUsage]'
|
||||
registered: '[admnUnregRegistered]'
|
||||
usage: "[admnUnregUsage]"
|
||||
registered: "[admnUnregRegistered]"
|
||||
success:
|
||||
target: '[admnUnregSuccessTgt]'
|
||||
player: '[admnUnregSuccessPlyr]'
|
||||
target: "[admnUnregSuccessTgt]"
|
||||
player: "[admnUnregSuccessPlyr]"
|
||||
location:
|
||||
usage: '[admnLocUsage]'
|
||||
usage: "[admnLocUsage]"
|
||||
set:
|
||||
success: '[admnLocSetSuccess]'
|
||||
isglobal: "[admnLocSetErrGlobal]"
|
||||
success: "[admnLocSetSuccess]"
|
||||
global:
|
||||
success: "[admnLocSetGlobalSuccess]"
|
||||
remove:
|
||||
no: '[admnLocRmvNo]'
|
||||
success: '[admnLocRmvSuccess]'
|
||||
no: "[admnLocRmvNo]"
|
||||
isglobal: "[admnLocRmvErrGlobal]"
|
||||
success: "[admnLocRmvSuccess]"
|
||||
global:
|
||||
no: "[admnLocRmvGlobalNo]"
|
||||
success: "[admnLocRmvGlobalSuccess]"
|
||||
config:
|
||||
usage: '[admnConfUsage]'
|
||||
no: '[admnConfNo]'
|
||||
desc: '[admnConfDesc]'
|
||||
invalid: '[admnConfInvalid]'
|
||||
success: '[admnConfSuccess]'
|
||||
usage: "[admnConfUsage]"
|
||||
no: "[admnConfNo]"
|
||||
desc: "[admnConfDesc]"
|
||||
invalid: "[admnConfInvalid]"
|
||||
success: "[admnConfSuccess]"
|
||||
reload:
|
||||
sucess: '[admnReloadSuccess]'
|
||||
sucess: "[admnReloadSuccess]"
|
||||
|
||||
misc:
|
||||
illegal: '[miscIllegal]'
|
||||
reloaded: '[miscReloaded]'
|
||||
illegal: "[miscIllegal]"
|
||||
reloaded: "[miscReloaded]"
|
||||
kick:
|
||||
timeout: '[miscKickTimeout]'
|
||||
strike: '[miscKickStrike]'
|
||||
timeout: "[miscKickTimeout]"
|
||||
strike: "[miscKickStrike]"
|
||||
|
||||
# INTERNAL USE ONLY! DO NOT TOUCH!
|
||||
version: [version]
|
@ -1,6 +1,6 @@
|
||||
name: xAuth
|
||||
main: com.cypherx.xauth.xAuth
|
||||
version: 2.0b3.5
|
||||
version: 2.0b4
|
||||
description: Offline-Mode Security Suite
|
||||
author: CypherX
|
||||
commands:
|
||||
@ -26,7 +26,7 @@ commands:
|
||||
/<command> changepw <player> <new password>
|
||||
/<command> logout <player>
|
||||
/<command> unregister <player>
|
||||
/<command> location set|remove
|
||||
/<command> location set|remove [global]
|
||||
/<command> config <setting> [value]
|
||||
/<command> reload
|
||||
/<command> version
|
Loading…
Reference in New Issue
Block a user