spaces to tabs (sorry guys)

This commit is contained in:
LAX1DUDE 2022-07-24 12:38:53 -07:00
parent c4bda6bec5
commit d403cb8086
4 changed files with 405 additions and 389 deletions

View File

@ -9,7 +9,8 @@ public class CommandChangePassword extends Command {
private final AuthSystem authSystem;
public CommandChangePassword(AuthSystem authSystem) {
super("changepassword", "bungeecord.command.eag.changepassword", new String[] { "changepwd", "changepasswd", "changepass" });
super("changepassword", "bungeecord.command.eag.changepassword",
new String[] { "changepwd", "changepasswd", "changepass" });
this.authSystem = authSystem;
}

View File

@ -37,16 +37,20 @@ public class AuthHandler extends PacketHandler {
new Thread(() -> {
for (int i = 0; i < 120; i++) {
if (this.loggedIn) break;
if (this.loggedIn)
break;
try {
Thread.sleep(250);
} catch (InterruptedException ignored) { }
} catch (InterruptedException ignored) {
}
if (this.loggedIn) return;
}
if (this.loggedIn)
return;
this.con.disconnect("You did not login in time!");
}).start();
this.con.unsafe().sendPacket(new Packet1Login(0, "END", (byte) 2, 1, (byte) 0, (byte) 0, (byte) this.con.getPendingConnection().getListener().getTabListSize()));
this.con.unsafe().sendPacket(new Packet1Login(0, "END", (byte) 2, 1, (byte) 0, (byte) 0,
(byte) this.con.getPendingConnection().getListener().getTabListSize()));
this.con.unsafe().sendPacket(new Packet9Respawn(1, (byte) 0, (byte) 2, (short) 255, "END"));
this.con.unsafe().sendPacket(new Packet0DPositionAndLook(0, 0, 0, 0, 0f, 0f, true));
@ -104,7 +108,8 @@ public class AuthHandler extends PacketHandler {
this.con.sendMessage("\u00A7cThose passwords do not match!");
} else if (authSystem.isRegistered(this.username)) {
this.con.sendMessage("\u00A7cThis username is already registered!");
} else if (authSystem.register(this.username, args[1], this.con.getAddress().getAddress().getHostAddress())) {
} else if (authSystem.register(this.username, args[1],
this.con.getAddress().getAddress().getHostAddress())) {
this.con.sendMessage("\u00A7cSuccessfully registered and logging in...");
this.onLogin();
} else {

View File

@ -53,8 +53,10 @@ public class AuthSystem {
public boolean register(String username, String password, String ip) {
synchronized (database) {
AuthData authData = database.get(username);
if (authData != null) return false;
if (isIpAtTheLimit(ip)) return false;
if (authData != null)
return false;
if (isIpAtTheLimit(ip))
return false;
String salt = createSalt(16);
String hash = getSaltedHash(password, salt);
database.put(username, new AuthData(salt, hash, ip, System.currentTimeMillis()));
@ -82,17 +84,20 @@ public class AuthSystem {
public boolean login(String username, String password) {
synchronized (database) {
AuthData authData = database.get(username);
if (authData == null) return false;
if (authData == null)
return false;
return authData.hash.equals(getSaltedHash(password, authData.salt));
}
}
private boolean isIpAtTheLimit(String ip) {
synchronized (database) {
if (this.ipLimit <= 0) return false;
if (this.ipLimit <= 0)
return false;
int num = 0;
for (AuthData authData : database.values()) {
if (authData.ip.equals(ip)) num++;
if (authData.ip.equals(ip))
num++;
if (num >= this.ipLimit) {
return true;
}
@ -106,24 +111,28 @@ public class AuthSystem {
synchronized (database) {
try {
File authFile = new File(this.authFileName);
if (!authFile.exists()) authFile.createNewFile();
if (!authFile.exists())
authFile.createNewFile();
database.clear();
String[] lines = new String(Files.readAllBytes(authFile.toPath())).trim().split("\n");
if (lines.length == 1 && lines[0].isEmpty()) return;
if (lines.length == 1 && lines[0].isEmpty())
return;
boolean alreadyLogged = false;
for (String line : lines) {
String[] pieces = line.split(":");
if (!pieces[1].startsWith("$SHA$")) {
if (!alreadyLogged) {
alreadyLogged = true;
BungeeCord.getInstance().getLogger().warning("One or more entries in the auth file are hashed in an unsupported format! (not SHA-256!)");
BungeeCord.getInstance().getLogger().warning(
"One or more entries in the auth file are hashed in an unsupported format! (not SHA-256!)");
}
// continue;
}
String[] saltHash = pieces[1].substring(pieces[1].substring(1).indexOf('$') + 2).split("\\$");
database.put(pieces[0], new AuthData(saltHash[0], saltHash[1], pieces[2], Long.parseLong(pieces[3])));
database.put(pieces[0],
new AuthData(saltHash[0], saltHash[1], pieces[2], Long.parseLong(pieces[3])));
}
} catch (IOException e) {

View File

@ -15,7 +15,8 @@ public class Packet0DPositionAndLook extends DefinedPacket {
super(13);
}
public Packet0DPositionAndLook(final int x, final int y, final double stance, final double z, final float yaw, final float pitch, final boolean onGround) {
public Packet0DPositionAndLook(final int x, final int y, final double stance, final double z, final float yaw,
final float pitch, final boolean onGround) {
this();
this.x = x;
this.y = y;