mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-01 06:33:35 +01:00
#430 Remove PlayerAuth constructors in favor of builder
- Remove various PlayerAuth constructors - Clean up FlatFile class - Add some javadoc to PlayerAuth
This commit is contained in:
parent
ef980bd654
commit
2de3848cc3
@ -677,7 +677,10 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead() && Settings.isSaveQuitLocationEnabled) {
|
if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead() && Settings.isSaveQuitLocationEnabled) {
|
||||||
final PlayerAuth auth = new PlayerAuth(player.getName().toLowerCase(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getWorld().getName(), player.getName());
|
final PlayerAuth auth = PlayerAuth.builder()
|
||||||
|
.name(player.getName().toLowerCase())
|
||||||
|
.realName(player.getName())
|
||||||
|
.location(player.getLocation()).build();
|
||||||
database.updateQuitLoc(auth);
|
database.updateQuitLoc(auth);
|
||||||
}
|
}
|
||||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||||
|
@ -8,20 +8,24 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* AuthMe player data.
|
||||||
*/
|
*/
|
||||||
public class PlayerAuth {
|
public class PlayerAuth {
|
||||||
|
|
||||||
|
/** The player's name in lowercase, e.g. "xephi". */
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
/** The player's name in the correct casing, e.g. "Xephi". */
|
||||||
|
private String realName;
|
||||||
private HashedPassword password;
|
private HashedPassword password;
|
||||||
|
private String email;
|
||||||
private String ip;
|
private String ip;
|
||||||
|
private int groupId;
|
||||||
private long lastLogin;
|
private long lastLogin;
|
||||||
|
// Fields storing the player's quit location
|
||||||
private double x;
|
private double x;
|
||||||
private double y;
|
private double y;
|
||||||
private double z;
|
private double z;
|
||||||
private String world;
|
private String world;
|
||||||
private int groupId;
|
|
||||||
private String email;
|
|
||||||
private String realName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param serialized String
|
* @param serialized String
|
||||||
@ -31,80 +35,19 @@ public class PlayerAuth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for PlayerAuth.
|
* Constructor. Instantiate objects with the {@link #builder() builder}.
|
||||||
*
|
*
|
||||||
* @param nickname String
|
* @param nickname all lowercase name of the player
|
||||||
* @param x double
|
* @param password password
|
||||||
* @param y double
|
* @param groupId the group id
|
||||||
* @param z double
|
* @param ip the associated ip address
|
||||||
* @param world String
|
* @param lastLogin player's last login (timestamp)
|
||||||
* @param realName String
|
* @param x quit location: x coordinate
|
||||||
*/
|
* @param y quit location: y coordinate
|
||||||
public PlayerAuth(String nickname, double x, double y, double z, String world, String realName) {
|
* @param z quit location: z coordinate
|
||||||
this(nickname, new HashedPassword(""), -1, "127.0.0.1", System.currentTimeMillis(), x, y, z, world,
|
* @param world quit location: world name
|
||||||
"your@email.com", realName);
|
* @param email the associated email
|
||||||
}
|
* @param realName the player's name with proper casing
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for PlayerAuth.
|
|
||||||
*
|
|
||||||
* @param nickname String
|
|
||||||
* @param hash String
|
|
||||||
* @param ip String
|
|
||||||
* @param lastLogin long
|
|
||||||
* @param realName String
|
|
||||||
*/
|
|
||||||
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String realName) {
|
|
||||||
this(nickname, new HashedPassword(hash), -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for PlayerAuth.
|
|
||||||
*
|
|
||||||
* @param nickname String
|
|
||||||
* @param hash String
|
|
||||||
* @param ip String
|
|
||||||
* @param lastLogin long
|
|
||||||
* @param email String
|
|
||||||
* @param realName String
|
|
||||||
*/
|
|
||||||
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String email, String realName) {
|
|
||||||
this(nickname, new HashedPassword(hash), -1, ip, lastLogin, 0, 0, 0, "world", email, realName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for PlayerAuth.
|
|
||||||
*
|
|
||||||
* @param nickname String
|
|
||||||
* @param hash String
|
|
||||||
* @param ip String
|
|
||||||
* @param lastLogin long
|
|
||||||
* @param x double
|
|
||||||
* @param y double
|
|
||||||
* @param z double
|
|
||||||
* @param world String
|
|
||||||
* @param email String
|
|
||||||
* @param realName String
|
|
||||||
*/
|
|
||||||
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, double x, double y, double z,
|
|
||||||
String world, String email, String realName) {
|
|
||||||
this(nickname, new HashedPassword(hash), -1, ip, lastLogin, x, y, z, world, email, realName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for PlayerAuth.
|
|
||||||
*
|
|
||||||
* @param nickname String
|
|
||||||
* @param password String
|
|
||||||
* @param groupId int
|
|
||||||
* @param ip String
|
|
||||||
* @param lastLogin long
|
|
||||||
* @param x double
|
|
||||||
* @param y double
|
|
||||||
* @param z double
|
|
||||||
* @param world String
|
|
||||||
* @param email String
|
|
||||||
* @param realName String
|
|
||||||
*/
|
*/
|
||||||
private PlayerAuth(String nickname, HashedPassword password, int groupId, String ip, long lastLogin,
|
private PlayerAuth(String nickname, HashedPassword password, int groupId, String ip, long lastLogin,
|
||||||
double x, double y, double z, String world, String email, String realName) {
|
double x, double y, double z, String world, String email, String realName) {
|
||||||
@ -121,24 +64,6 @@ public class PlayerAuth {
|
|||||||
this.realName = realName;
|
this.realName = realName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method set.
|
|
||||||
*
|
|
||||||
* @param auth PlayerAuth
|
|
||||||
*/
|
|
||||||
public void set(PlayerAuth auth) {
|
|
||||||
this.setEmail(auth.getEmail());
|
|
||||||
this.setPassword(auth.getPassword());
|
|
||||||
this.setIp(auth.getIp());
|
|
||||||
this.setLastLogin(auth.getLastLogin());
|
|
||||||
this.setNickname(auth.getNickname());
|
|
||||||
this.setQuitLocX(auth.getQuitLocX());
|
|
||||||
this.setQuitLocY(auth.getQuitLocY());
|
|
||||||
this.setQuitLocZ(auth.getQuitLocZ());
|
|
||||||
this.setWorld(auth.getWorld());
|
|
||||||
this.setRealName(auth.getRealName());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setNickname(String nickname) {
|
public void setNickname(String nickname) {
|
||||||
this.nickname = nickname.toLowerCase();
|
this.nickname = nickname.toLowerCase();
|
||||||
|
@ -31,27 +31,13 @@ public class CrazyLoginConverter implements Converter {
|
|||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method getInstance.
|
|
||||||
*
|
|
||||||
* @return CrazyLoginConverter
|
|
||||||
*/
|
|
||||||
public CrazyLoginConverter getInstance() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method run.
|
|
||||||
*
|
|
||||||
* @see java.lang.Runnable#run()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String fileName = Settings.crazyloginFileName;
|
String fileName = Settings.crazyloginFileName;
|
||||||
try {
|
try {
|
||||||
File source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
|
File source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
|
||||||
if (!source.exists()) {
|
if (!source.exists()) {
|
||||||
sender.sendMessage("Error while trying to import datas, please put " + fileName + " in AuthMe folder!");
|
sender.sendMessage("Error while trying to import data, please put " + fileName + " in AuthMe folder!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String line;
|
String line;
|
||||||
@ -59,14 +45,17 @@ public class CrazyLoginConverter implements Converter {
|
|||||||
while ((line = users.readLine()) != null) {
|
while ((line = users.readLine()) != null) {
|
||||||
if (line.contains("|")) {
|
if (line.contains("|")) {
|
||||||
String[] args = line.split("\\|");
|
String[] args = line.split("\\|");
|
||||||
if (args.length < 2)
|
if (args.length < 2 || "name".equalsIgnoreCase(args[0])) {
|
||||||
continue;
|
continue;
|
||||||
if (args[0].equalsIgnoreCase("name"))
|
}
|
||||||
continue;
|
String playerName = args[0];
|
||||||
String playerName = args[0].toLowerCase();
|
|
||||||
String psw = args[1];
|
String psw = args[1];
|
||||||
if (psw != null) {
|
if (psw != null) {
|
||||||
PlayerAuth auth = new PlayerAuth(playerName, psw, "127.0.0.1", System.currentTimeMillis(), playerName);
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
|
.name(playerName.toLowerCase())
|
||||||
|
.realName(playerName)
|
||||||
|
.password(psw, null)
|
||||||
|
.build();
|
||||||
database.saveAuth(auth);
|
database.saveAuth(auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ import java.io.IOException;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static fr.xephi.authme.util.StringUtils.makePath;
|
||||||
|
|
||||||
class vAuthFileReader {
|
class vAuthFileReader {
|
||||||
|
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
@ -28,7 +30,7 @@ class vAuthFileReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void convert() {
|
public void convert() {
|
||||||
final File file = new File(plugin.getDataFolder().getParent() + File.separator + "vAuth" + File.separator + "passwords.yml");
|
final File file = new File(plugin.getDataFolder().getParent(), makePath("vAuth", "passwords.yml"));
|
||||||
Scanner scanner;
|
Scanner scanner;
|
||||||
try {
|
try {
|
||||||
scanner = new Scanner(file);
|
scanner = new Scanner(file);
|
||||||
@ -46,9 +48,15 @@ class vAuthFileReader {
|
|||||||
}
|
}
|
||||||
if (pname == null)
|
if (pname == null)
|
||||||
continue;
|
continue;
|
||||||
auth = new PlayerAuth(pname.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", pname);
|
auth = PlayerAuth.builder()
|
||||||
|
.name(pname.toLowerCase())
|
||||||
|
.realName(pname)
|
||||||
|
.password(password, null).build();
|
||||||
} else {
|
} else {
|
||||||
auth = new PlayerAuth(name.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", name);
|
auth = PlayerAuth.builder()
|
||||||
|
.name(name.toLowerCase())
|
||||||
|
.realName(name)
|
||||||
|
.password(password, null).build();
|
||||||
}
|
}
|
||||||
database.saveAuth(auth);
|
database.saveAuth(auth);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,10 @@ class xAuthToFlat {
|
|||||||
String pl = getIdPlayer(id);
|
String pl = getIdPlayer(id);
|
||||||
String psw = getPassword(id);
|
String psw = getPassword(id);
|
||||||
if (psw != null && !psw.isEmpty() && pl != null) {
|
if (psw != null && !psw.isEmpty() && pl != null) {
|
||||||
PlayerAuth auth = new PlayerAuth(pl, psw, "192.168.0.1", 0, "your@email.com", pl);
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
|
.name(pl.toLowerCase())
|
||||||
|
.realName(pl)
|
||||||
|
.password(psw, null).build();
|
||||||
database.saveAuth(auth);
|
database.saveAuth(auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +72,8 @@ class xAuthToFlat {
|
|||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
String sql = String.format("SELECT `playername` FROM `%s` WHERE `id` = ?", xAuth.getPlugin().getDatabaseController().getTable(DatabaseTables.ACCOUNT));
|
String sql = String.format("SELECT `playername` FROM `%s` WHERE `id` = ?",
|
||||||
|
xAuth.getPlugin().getDatabaseController().getTable(DatabaseTables.ACCOUNT));
|
||||||
ps = conn.prepareStatement(sql);
|
ps = conn.prepareStatement(sql);
|
||||||
ps.setInt(1, id);
|
ps.setInt(1, id);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
@ -91,7 +95,8 @@ class xAuthToFlat {
|
|||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
String sql = String.format("SELECT * FROM `%s`", xAuth.getPlugin().getDatabaseController().getTable(DatabaseTables.ACCOUNT));
|
String sql = String.format("SELECT * FROM `%s`",
|
||||||
|
xAuth.getPlugin().getDatabaseController().getTable(DatabaseTables.ACCOUNT));
|
||||||
ps = conn.prepareStatement(sql);
|
ps = conn.prepareStatement(sql);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -112,7 +117,8 @@ class xAuthToFlat {
|
|||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
String sql = String.format("SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?", xAuth.getPlugin().getDatabaseController().getTable(DatabaseTables.ACCOUNT));
|
String sql = String.format("SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?",
|
||||||
|
xAuth.getPlugin().getDatabaseController().getTable(DatabaseTables.ACCOUNT));
|
||||||
ps = conn.prepareStatement(sql);
|
ps = conn.prepareStatement(sql);
|
||||||
ps.setInt(1, accountId);
|
ps.setInt(1, accountId);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
|
@ -10,6 +10,7 @@ import fr.xephi.authme.settings.Settings;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
@ -19,6 +20,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Deprecated flat file datasource. The only method guaranteed to work is {@link FlatFile#getAllAuths()}
|
||||||
|
* as to migrate the entries to {@link SQLite} when AuthMe starts.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class FlatFile implements DataSource {
|
public class FlatFile implements DataSource {
|
||||||
@ -76,19 +79,11 @@ public class FlatFile implements DataSource {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return false;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -110,17 +105,12 @@ public class FlatFile implements DataSource {
|
|||||||
BufferedWriter bw = null;
|
BufferedWriter bw = null;
|
||||||
try {
|
try {
|
||||||
bw = new BufferedWriter(new FileWriter(source, true));
|
bw = new BufferedWriter(new FileWriter(source, true));
|
||||||
bw.write(auth.getNickname() + ":" + auth.getPassword() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + ":" + auth.getEmail() + "\n");
|
bw.write(auth.getNickname() + ":" + auth.getPassword().getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + ":" + auth.getEmail() + "\n");
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (bw != null) {
|
silentClose(bw);
|
||||||
try {
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -131,6 +121,7 @@ public class FlatFile implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
// Note ljacqu 20151230: This does not persist the salt; it is not supported in flat file.
|
||||||
public boolean updatePassword(String user, HashedPassword password) {
|
public boolean updatePassword(String user, HashedPassword password) {
|
||||||
user = user.toLowerCase();
|
user = user.toLowerCase();
|
||||||
if (!isAuthAvailable(user)) {
|
if (!isAuthAvailable(user)) {
|
||||||
@ -144,45 +135,18 @@ public class FlatFile implements DataSource {
|
|||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
String[] args = line.split(":");
|
String[] args = line.split(":");
|
||||||
if (args[0].equals(user)) {
|
if (args[0].equals(user)) {
|
||||||
// Note ljacqu 20151230: This does not persist the salt; it is not supported in flat file.
|
newAuth = buildAuthFromArray(args);
|
||||||
switch (args.length) {
|
if (newAuth != null) {
|
||||||
case 4: {
|
newAuth.setPassword(password);
|
||||||
newAuth = new PlayerAuth(args[0], password.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com", args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 7: {
|
|
||||||
newAuth = new PlayerAuth(args[0], password.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 8: {
|
|
||||||
newAuth = new PlayerAuth(args[0], password.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 9: {
|
|
||||||
newAuth = new PlayerAuth(args[0], password.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
newAuth = new PlayerAuth(args[0], password.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com", args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return false;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (newAuth != null) {
|
if (newAuth != null) {
|
||||||
removeAuth(user);
|
removeAuth(user);
|
||||||
@ -204,44 +168,19 @@ public class FlatFile implements DataSource {
|
|||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
String[] args = line.split(":");
|
String[] args = line.split(":");
|
||||||
if (args[0].equalsIgnoreCase(auth.getNickname())) {
|
if (args[0].equalsIgnoreCase(auth.getNickname())) {
|
||||||
switch (args.length) {
|
newAuth = buildAuthFromArray(args);
|
||||||
case 4: {
|
if (newAuth != null) {
|
||||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]);
|
newAuth.setLastLogin(auth.getLastLogin());
|
||||||
break;
|
newAuth.setIp(auth.getIp());
|
||||||
}
|
|
||||||
case 7: {
|
|
||||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 8: {
|
|
||||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 9: {
|
|
||||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return false;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (newAuth != null) {
|
if (newAuth != null) {
|
||||||
removeAuth(auth.getNickname());
|
removeAuth(auth.getNickname());
|
||||||
@ -263,23 +202,22 @@ public class FlatFile implements DataSource {
|
|||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
String[] args = line.split(":");
|
String[] args = line.split(":");
|
||||||
if (args[0].equalsIgnoreCase(auth.getNickname())) {
|
if (args[0].equalsIgnoreCase(auth.getNickname())) {
|
||||||
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), args[0]);
|
newAuth = buildAuthFromArray(args);
|
||||||
|
if (newAuth != null) {
|
||||||
|
newAuth.setQuitLocX(auth.getQuitLocX());
|
||||||
|
newAuth.setQuitLocY(auth.getQuitLocY());
|
||||||
|
newAuth.setQuitLocZ(auth.getQuitLocZ());
|
||||||
|
newAuth.setWorld(auth.getWorld());
|
||||||
|
newAuth.setEmail(auth.getEmail());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return false;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (newAuth != null) {
|
if (newAuth != null) {
|
||||||
removeAuth(auth.getNickname());
|
removeAuth(auth.getNickname());
|
||||||
@ -311,25 +249,12 @@ public class FlatFile implements DataSource {
|
|||||||
for (String l : lines) {
|
for (String l : lines) {
|
||||||
bw.write(l + "\n");
|
bw.write(l + "\n");
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return cleared;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return cleared;
|
return cleared;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
silentClose(bw);
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bw != null) {
|
|
||||||
try {
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return cleared;
|
return cleared;
|
||||||
}
|
}
|
||||||
@ -355,25 +280,12 @@ public class FlatFile implements DataSource {
|
|||||||
for (String l : lines) {
|
for (String l : lines) {
|
||||||
bw.write(l + "\n");
|
bw.write(l + "\n");
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return false;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
silentClose(bw);
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bw != null) {
|
|
||||||
try {
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -387,35 +299,14 @@ public class FlatFile implements DataSource {
|
|||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
String[] args = line.split(":");
|
String[] args = line.split(":");
|
||||||
if (args[0].equalsIgnoreCase(user)) {
|
if (args[0].equalsIgnoreCase(user)) {
|
||||||
switch (args.length) {
|
return buildAuthFromArray(args);
|
||||||
case 2:
|
|
||||||
return new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0]);
|
|
||||||
case 3:
|
|
||||||
return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0]);
|
|
||||||
case 4:
|
|
||||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]);
|
|
||||||
case 7:
|
|
||||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]);
|
|
||||||
case 8:
|
|
||||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]);
|
|
||||||
case 9:
|
|
||||||
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return null;
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -437,7 +328,10 @@ public class FlatFile implements DataSource {
|
|||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
String[] args = line.split(":");
|
String[] args = line.split(":");
|
||||||
if (args[0].equals(auth.getNickname())) {
|
if (args[0].equals(auth.getNickname())) {
|
||||||
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth.getEmail(), args[0]);
|
newAuth = buildAuthFromArray(args);
|
||||||
|
if (newAuth != null) {
|
||||||
|
newAuth.setEmail(auth.getEmail());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,18 +439,8 @@ public class FlatFile implements DataSource {
|
|||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
silentClose(bw);
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bw != null) {
|
|
||||||
try {
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,12 +479,7 @@ public class FlatFile implements DataSource {
|
|||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return result;
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -624,32 +503,15 @@ public class FlatFile implements DataSource {
|
|||||||
String line;
|
String line;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
String[] args = line.split(":");
|
String[] args = line.split(":");
|
||||||
// We expect to encounter 2, 3, 4, 7, 8 or 9 fields. Ignore the line otherwise
|
PlayerAuth auth = buildAuthFromArray(args);
|
||||||
if (args.length >= 2 && args.length != 5 && args.length != 6 && args.length <= 9) {
|
if (auth != null) {
|
||||||
PlayerAuth.Builder builder = PlayerAuth.builder()
|
auths.add(auth);
|
||||||
.name(args[0]).realName(args[0])
|
|
||||||
.password(args[1], null);
|
|
||||||
if (args.length >= 3) builder.ip(args[2]);
|
|
||||||
if (args.length >= 4) builder.lastLogin(Long.parseLong(args[3]));
|
|
||||||
if (args.length >= 7) {
|
|
||||||
builder.locX(Double.parseDouble(args[4]))
|
|
||||||
.locY(Double.parseDouble(args[5]))
|
|
||||||
.locZ(Double.parseDouble(args[6]));
|
|
||||||
}
|
|
||||||
if (args.length >= 8) builder.locWorld(args[7]);
|
|
||||||
if (args.length >= 9) builder.email(args[8]);
|
|
||||||
auths.add(builder.build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.logException("Error while getting auths from flatfile:", ex);
|
ConsoleLogger.logException("Error while getting auths from flatfile:", ex);
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
silentClose(br);
|
||||||
try {
|
|
||||||
br.close();
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return auths;
|
return auths;
|
||||||
}
|
}
|
||||||
@ -663,4 +525,34 @@ public class FlatFile implements DataSource {
|
|||||||
public boolean isEmailStored(String email) {
|
public boolean isEmailStored(String email) {
|
||||||
throw new UnsupportedOperationException("Flat file no longer supported");
|
throw new UnsupportedOperationException("Flat file no longer supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static PlayerAuth buildAuthFromArray(String[] args) {
|
||||||
|
// Format allows 2, 3, 4, 7, 8, 9 fields. Anything else is unknown
|
||||||
|
if (args.length >= 2 && args.length <= 9 && args.length != 5 && args.length != 6) {
|
||||||
|
PlayerAuth.Builder builder = PlayerAuth.builder()
|
||||||
|
.name(args[0]).realName(args[0]).password(args[1], null);
|
||||||
|
|
||||||
|
if (args.length >= 3) builder.ip(args[2]);
|
||||||
|
if (args.length >= 4) builder.lastLogin(Long.parseLong(args[3]));
|
||||||
|
if (args.length >= 7) {
|
||||||
|
builder.locX(Double.parseDouble(args[4]))
|
||||||
|
.locY(Double.parseDouble(args[5]))
|
||||||
|
.locZ(Double.parseDouble(args[6]));
|
||||||
|
}
|
||||||
|
if (args.length >= 8) builder.locWorld(args[7]);
|
||||||
|
if (args.length >= 9) builder.email(args[8]);
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void silentClose(Closeable closeable) {
|
||||||
|
if (closeable != null) {
|
||||||
|
try {
|
||||||
|
closeable.close();
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
// silent close
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user