spaces to tabs (sorry guys)
This commit is contained in:
parent
c4bda6bec5
commit
d403cb8086
|
@ -6,29 +6,30 @@ import net.md_5.bungee.api.plugin.Command;
|
|||
import net.md_5.bungee.eaglercraft.AuthSystem;
|
||||
|
||||
public class CommandChangePassword extends Command {
|
||||
private final AuthSystem authSystem;
|
||||
private final AuthSystem authSystem;
|
||||
|
||||
public CommandChangePassword(AuthSystem authSystem) {
|
||||
super("changepassword", "bungeecord.command.eag.changepassword", new String[] { "changepwd", "changepasswd", "changepass" });
|
||||
this.authSystem = authSystem;
|
||||
}
|
||||
public CommandChangePassword(AuthSystem authSystem) {
|
||||
super("changepassword", "bungeecord.command.eag.changepassword",
|
||||
new String[] { "changepwd", "changepasswd", "changepass" });
|
||||
this.authSystem = authSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
if (!(sender instanceof ProxiedPlayer)) {
|
||||
return;
|
||||
}
|
||||
String username = sender.getName();
|
||||
if (args.length == 0 || args.length == 1) {
|
||||
sender.sendMessage("\u00A7cUsage: /changepassword <oldPassword> <newPassword>");
|
||||
} else if (this.authSystem.login(username, args[0])) {
|
||||
if (this.authSystem.changePass(username, args[1])) {
|
||||
sender.sendMessage("\u00A7cPassword changed successfully!");
|
||||
} else {
|
||||
sender.sendMessage("\u00A7cUnable to change your password...");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("\u00A7cThe old password specified is incorrect!");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
if (!(sender instanceof ProxiedPlayer)) {
|
||||
return;
|
||||
}
|
||||
String username = sender.getName();
|
||||
if (args.length == 0 || args.length == 1) {
|
||||
sender.sendMessage("\u00A7cUsage: /changepassword <oldPassword> <newPassword>");
|
||||
} else if (this.authSystem.login(username, args[0])) {
|
||||
if (this.authSystem.changePass(username, args[1])) {
|
||||
sender.sendMessage("\u00A7cPassword changed successfully!");
|
||||
} else {
|
||||
sender.sendMessage("\u00A7cUnable to change your password...");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("\u00A7cThe old password specified is incorrect!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,135 +19,140 @@ import net.md_5.bungee.protocol.packet.Packet0KeepAlive;
|
|||
import net.md_5.bungee.protocol.packet.PacketCCSettings;
|
||||
|
||||
public class AuthHandler extends PacketHandler {
|
||||
private static final AuthSystem authSystem = BungeeCord.getInstance().authSystem;
|
||||
private static final AuthSystem authSystem = BungeeCord.getInstance().authSystem;
|
||||
|
||||
private final ProxyServer bungee;
|
||||
private final UserConnection con;
|
||||
private final HandlerBoss handlerBoss;
|
||||
private final String username;
|
||||
private final ProxyServer bungee;
|
||||
private final UserConnection con;
|
||||
private final HandlerBoss handlerBoss;
|
||||
private final String username;
|
||||
|
||||
private boolean loggedIn = false;
|
||||
private boolean loggedIn = false;
|
||||
|
||||
public AuthHandler(final ProxyServer bungee, final UserConnection con, final HandlerBoss handlerBoss) {
|
||||
this.bungee = bungee;
|
||||
this.con = con;
|
||||
this.handlerBoss = handlerBoss;
|
||||
public AuthHandler(final ProxyServer bungee, final UserConnection con, final HandlerBoss handlerBoss) {
|
||||
this.bungee = bungee;
|
||||
this.con = con;
|
||||
this.handlerBoss = handlerBoss;
|
||||
|
||||
this.username = this.con.getName();
|
||||
this.username = this.con.getName();
|
||||
|
||||
new Thread(() -> {
|
||||
for (int i = 0; i < 120; i++) {
|
||||
if (this.loggedIn) break;
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException ignored) { }
|
||||
}
|
||||
if (this.loggedIn) return;
|
||||
this.con.disconnect("You did not login in time!");
|
||||
}).start();
|
||||
new Thread(() -> {
|
||||
for (int i = 0; i < 120; i++) {
|
||||
if (this.loggedIn)
|
||||
break;
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
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 Packet9Respawn(1, (byte) 0, (byte) 2, (short) 255, "END"));
|
||||
this.con.unsafe().sendPacket(new Packet0DPositionAndLook(0, 0, 0, 0, 0f, 0f, true));
|
||||
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));
|
||||
|
||||
this.con.sendMessages(authSystem.joinMessages);
|
||||
this.con.sendMessages(authSystem.joinMessages);
|
||||
|
||||
if (authSystem.isRegistered(this.username)) {
|
||||
this.con.sendMessage("\u00A7cPlease login to continue! /login <password>");
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cPlease register to continue! /register <password> <confirmPassword>");
|
||||
}
|
||||
}
|
||||
if (authSystem.isRegistered(this.username)) {
|
||||
this.con.sendMessage("\u00A7cPlease login to continue! /login <password>");
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cPlease register to continue! /register <password> <confirmPassword>");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exception(final Throwable t) throws Exception {
|
||||
this.con.disconnect(Util.exception(t));
|
||||
}
|
||||
@Override
|
||||
public void exception(final Throwable t) throws Exception {
|
||||
this.con.disconnect(Util.exception(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(final ChannelWrapper channel) {
|
||||
this.loggedIn = true;
|
||||
}
|
||||
@Override
|
||||
public void disconnected(final ChannelWrapper channel) {
|
||||
this.loggedIn = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(final Packet0KeepAlive alive) throws Exception {
|
||||
if (alive.getRandomId() == this.con.getSentPingId()) {
|
||||
final int newPing = (int) (System.currentTimeMillis() - this.con.getSentPingTime());
|
||||
this.con.setPing(newPing);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void handle(final Packet0KeepAlive alive) throws Exception {
|
||||
if (alive.getRandomId() == this.con.getSentPingId()) {
|
||||
final int newPing = (int) (System.currentTimeMillis() - this.con.getSentPingTime());
|
||||
this.con.setPing(newPing);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(final Packet3Chat chat) throws Exception {
|
||||
String message = chat.getMessage();
|
||||
if (message.startsWith("/")) {
|
||||
String[] args = message.substring(1).trim().split(" ");
|
||||
switch (args[0]) {
|
||||
case "login":
|
||||
case "l":
|
||||
if (args.length == 1) {
|
||||
this.con.sendMessage("\u00A7cYou must specify a password to login! /login <password>");
|
||||
} else if (!authSystem.isRegistered(this.username)) {
|
||||
this.con.sendMessage("\u00A7cThis username is not registered on this server!");
|
||||
} else if (authSystem.login(this.username, args[1])) {
|
||||
this.con.sendMessage("\u00A7cLogging in...");
|
||||
this.onLogin();
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cThat password is invalid!");
|
||||
}
|
||||
break;
|
||||
case "register":
|
||||
case "reg":
|
||||
if (args.length == 1 || args.length == 2) {
|
||||
this.con.sendMessage("\u00A7cUsage: /" + args[0].toLowerCase() + " <password> <confirmPassword>");
|
||||
} else if (!args[1].equals(args[2])) {
|
||||
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())) {
|
||||
this.con.sendMessage("\u00A7cSuccessfully registered and logging in...");
|
||||
this.onLogin();
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cUnable to register...");
|
||||
}
|
||||
break;
|
||||
case "changepassword":
|
||||
case "changepasswd":
|
||||
case "changepwd":
|
||||
case "changepass":
|
||||
if (args.length == 1 || args.length == 2) {
|
||||
this.con.sendMessage("\u00A7cUsage: /" + args[0].toLowerCase() + " <oldPassword> <newPassword>");
|
||||
} else if (authSystem.login(this.username, args[1])) {
|
||||
if (authSystem.changePass(this.username, args[2])) {
|
||||
this.con.sendMessage("\u00A7cPassword changed successfully!");
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cUnable to change your password...");
|
||||
}
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cThe old password specified is incorrect!");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void handle(final Packet3Chat chat) throws Exception {
|
||||
String message = chat.getMessage();
|
||||
if (message.startsWith("/")) {
|
||||
String[] args = message.substring(1).trim().split(" ");
|
||||
switch (args[0]) {
|
||||
case "login":
|
||||
case "l":
|
||||
if (args.length == 1) {
|
||||
this.con.sendMessage("\u00A7cYou must specify a password to login! /login <password>");
|
||||
} else if (!authSystem.isRegistered(this.username)) {
|
||||
this.con.sendMessage("\u00A7cThis username is not registered on this server!");
|
||||
} else if (authSystem.login(this.username, args[1])) {
|
||||
this.con.sendMessage("\u00A7cLogging in...");
|
||||
this.onLogin();
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cThat password is invalid!");
|
||||
}
|
||||
break;
|
||||
case "register":
|
||||
case "reg":
|
||||
if (args.length == 1 || args.length == 2) {
|
||||
this.con.sendMessage("\u00A7cUsage: /" + args[0].toLowerCase() + " <password> <confirmPassword>");
|
||||
} else if (!args[1].equals(args[2])) {
|
||||
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())) {
|
||||
this.con.sendMessage("\u00A7cSuccessfully registered and logging in...");
|
||||
this.onLogin();
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cUnable to register...");
|
||||
}
|
||||
break;
|
||||
case "changepassword":
|
||||
case "changepasswd":
|
||||
case "changepwd":
|
||||
case "changepass":
|
||||
if (args.length == 1 || args.length == 2) {
|
||||
this.con.sendMessage("\u00A7cUsage: /" + args[0].toLowerCase() + " <oldPassword> <newPassword>");
|
||||
} else if (authSystem.login(this.username, args[1])) {
|
||||
if (authSystem.changePass(this.username, args[2])) {
|
||||
this.con.sendMessage("\u00A7cPassword changed successfully!");
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cUnable to change your password...");
|
||||
}
|
||||
} else {
|
||||
this.con.sendMessage("\u00A7cThe old password specified is incorrect!");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onLogin() {
|
||||
this.loggedIn = true;
|
||||
this.bungee.getPluginManager().callEvent(new PostLoginEvent(this.con));
|
||||
handlerBoss.setHandler(new UpstreamBridge(this.bungee, this.con));
|
||||
final ServerInfo server = this.bungee.getReconnectHandler().getServer(this.con);
|
||||
this.con.setServer(new ServerConnection(null, null));
|
||||
this.con.connect(server, true);
|
||||
}
|
||||
private void onLogin() {
|
||||
this.loggedIn = true;
|
||||
this.bungee.getPluginManager().callEvent(new PostLoginEvent(this.con));
|
||||
handlerBoss.setHandler(new UpstreamBridge(this.bungee, this.con));
|
||||
final ServerInfo server = this.bungee.getReconnectHandler().getServer(this.con);
|
||||
this.con.setServer(new ServerConnection(null, null));
|
||||
this.con.connect(server, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(final PacketCCSettings settings) throws Exception {
|
||||
this.con.setSettings(settings);
|
||||
}
|
||||
@Override
|
||||
public void handle(final PacketCCSettings settings) throws Exception {
|
||||
this.con.setSettings(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + this.con.getName() + "] -> AuthHandler";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + this.con.getName() + "] -> AuthHandler";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,177 +17,186 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
public class AuthSystem {
|
||||
private final String authFileName;
|
||||
private final int ipLimit;
|
||||
public final String[] joinMessages;
|
||||
private final String authFileName;
|
||||
private final int ipLimit;
|
||||
public final String[] joinMessages;
|
||||
|
||||
public AuthSystem(AuthServiceInfo authInfo) {
|
||||
this.authFileName = authInfo.getAuthfile();
|
||||
this.ipLimit = authInfo.getIpLimit();
|
||||
List<String> listJoinMessages = authInfo.getJoinMessages();
|
||||
String[] arrayJoinMessages = new String[listJoinMessages.size()];
|
||||
for (int i = 0; i < listJoinMessages.size(); i++) {
|
||||
arrayJoinMessages[i] = ChatColor.translateAlternateColorCodes('&', listJoinMessages.get(i));
|
||||
}
|
||||
this.joinMessages = arrayJoinMessages;
|
||||
public AuthSystem(AuthServiceInfo authInfo) {
|
||||
this.authFileName = authInfo.getAuthfile();
|
||||
this.ipLimit = authInfo.getIpLimit();
|
||||
List<String> listJoinMessages = authInfo.getJoinMessages();
|
||||
String[] arrayJoinMessages = new String[listJoinMessages.size()];
|
||||
for (int i = 0; i < listJoinMessages.size(); i++) {
|
||||
arrayJoinMessages[i] = ChatColor.translateAlternateColorCodes('&', listJoinMessages.get(i));
|
||||
}
|
||||
this.joinMessages = arrayJoinMessages;
|
||||
|
||||
this.readDatabase();
|
||||
}
|
||||
this.readDatabase();
|
||||
}
|
||||
|
||||
private static class AuthData {
|
||||
public String salt;
|
||||
public String hash;
|
||||
public String ip;
|
||||
public long timestamp;
|
||||
private static class AuthData {
|
||||
public String salt;
|
||||
public String hash;
|
||||
public String ip;
|
||||
public long timestamp;
|
||||
|
||||
public AuthData(String salt, String hash, String ip, long timestamp) {
|
||||
this.salt = salt;
|
||||
this.hash = hash;
|
||||
this.ip = ip;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
public AuthData(String salt, String hash, String ip, long timestamp) {
|
||||
this.salt = salt;
|
||||
this.hash = hash;
|
||||
this.ip = ip;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<String, AuthData> database = new HashMap<>();
|
||||
private final Map<String, AuthData> database = new HashMap<>();
|
||||
|
||||
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;
|
||||
String salt = createSalt(16);
|
||||
String hash = getSaltedHash(password, salt);
|
||||
database.put(username, new AuthData(salt, hash, ip, System.currentTimeMillis()));
|
||||
writeDatabase();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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;
|
||||
String salt = createSalt(16);
|
||||
String hash = getSaltedHash(password, salt);
|
||||
database.put(username, new AuthData(salt, hash, ip, System.currentTimeMillis()));
|
||||
writeDatabase();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRegistered(String username) {
|
||||
synchronized (database) {
|
||||
return database.containsKey(username);
|
||||
}
|
||||
}
|
||||
public boolean isRegistered(String username) {
|
||||
synchronized (database) {
|
||||
return database.containsKey(username);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean changePass(String username, String password) {
|
||||
synchronized (database) {
|
||||
AuthData authData = database.get(username);
|
||||
authData.salt = createSalt(16);
|
||||
authData.hash = getSaltedHash(password, authData.salt);
|
||||
writeDatabase();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public boolean changePass(String username, String password) {
|
||||
synchronized (database) {
|
||||
AuthData authData = database.get(username);
|
||||
authData.salt = createSalt(16);
|
||||
authData.hash = getSaltedHash(password, authData.salt);
|
||||
writeDatabase();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean login(String username, String password) {
|
||||
synchronized (database) {
|
||||
AuthData authData = database.get(username);
|
||||
if (authData == null) return false;
|
||||
return authData.hash.equals(getSaltedHash(password, authData.salt));
|
||||
}
|
||||
}
|
||||
public boolean login(String username, String password) {
|
||||
synchronized (database) {
|
||||
AuthData authData = database.get(username);
|
||||
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;
|
||||
int num = 0;
|
||||
for (AuthData authData : database.values()) {
|
||||
if (authData.ip.equals(ip)) num++;
|
||||
if (num >= this.ipLimit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private boolean isIpAtTheLimit(String ip) {
|
||||
synchronized (database) {
|
||||
if (this.ipLimit <= 0)
|
||||
return false;
|
||||
int num = 0;
|
||||
for (AuthData authData : database.values()) {
|
||||
if (authData.ip.equals(ip))
|
||||
num++;
|
||||
if (num >= this.ipLimit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// only use once, on load
|
||||
public void readDatabase() {
|
||||
synchronized (database) {
|
||||
try {
|
||||
File authFile = new File(this.authFileName);
|
||||
if (!authFile.exists()) authFile.createNewFile();
|
||||
// only use once, on load
|
||||
public void readDatabase() {
|
||||
synchronized (database) {
|
||||
try {
|
||||
File authFile = new File(this.authFileName);
|
||||
if (!authFile.exists())
|
||||
authFile.createNewFile();
|
||||
|
||||
database.clear();
|
||||
database.clear();
|
||||
|
||||
String[] lines = new String(Files.readAllBytes(authFile.toPath())).trim().split("\n");
|
||||
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!)");
|
||||
}
|
||||
// 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])));
|
||||
}
|
||||
String[] lines = new String(Files.readAllBytes(authFile.toPath())).trim().split("\n");
|
||||
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!)");
|
||||
}
|
||||
// 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])));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDatabase() {
|
||||
synchronized (database) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
private void writeDatabase() {
|
||||
synchronized (database) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
||||
for (String username : database.keySet()) {
|
||||
AuthData entry = database.get(username);
|
||||
out.append(username);
|
||||
out.append(":$SHA$");
|
||||
out.append(entry.salt);
|
||||
out.append("$");
|
||||
out.append(entry.hash);
|
||||
out.append(":");
|
||||
out.append(entry.ip);
|
||||
out.append(":");
|
||||
out.append(entry.timestamp);
|
||||
out.append("\n");
|
||||
}
|
||||
for (String username : database.keySet()) {
|
||||
AuthData entry = database.get(username);
|
||||
out.append(username);
|
||||
out.append(":$SHA$");
|
||||
out.append(entry.salt);
|
||||
out.append("$");
|
||||
out.append(entry.hash);
|
||||
out.append(":");
|
||||
out.append(entry.ip);
|
||||
out.append(":");
|
||||
out.append(entry.timestamp);
|
||||
out.append("\n");
|
||||
}
|
||||
|
||||
try {
|
||||
Files.write(Paths.get(this.authFileName), out.toString().getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
Files.write(Paths.get(this.authFileName), out.toString().getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hashing used is based on hashing from AuthMe
|
||||
// hashing used is based on hashing from AuthMe
|
||||
|
||||
private static final SecureRandom rnd = new SecureRandom();
|
||||
private static final SecureRandom rnd = new SecureRandom();
|
||||
|
||||
private static String getSHA256(String message) {
|
||||
try {
|
||||
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
|
||||
sha256.reset();
|
||||
sha256.update(message.getBytes());
|
||||
byte[] digest = sha256.digest();
|
||||
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
private static String getSHA256(String message) {
|
||||
try {
|
||||
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
|
||||
sha256.reset();
|
||||
sha256.update(message.getBytes());
|
||||
byte[] digest = sha256.digest();
|
||||
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSaltedHash(String message, String salt) {
|
||||
return getSHA256(getSHA256(message) + salt);
|
||||
}
|
||||
private static String getSaltedHash(String message, String salt) {
|
||||
return getSHA256(getSHA256(message) + salt);
|
||||
}
|
||||
|
||||
private static String createSalt(int length) {
|
||||
try {
|
||||
byte[] msg = new byte[40];
|
||||
rnd.nextBytes(msg);
|
||||
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
|
||||
sha1.reset();
|
||||
byte[] digest = sha1.digest(msg);
|
||||
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest)).substring(0, length);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
private static String createSalt(int length) {
|
||||
try {
|
||||
byte[] msg = new byte[40];
|
||||
rnd.nextBytes(msg);
|
||||
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
|
||||
sha1.reset();
|
||||
byte[] digest = sha1.digest(msg);
|
||||
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest)).substring(0, length);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,112 +3,113 @@ package net.md_5.bungee.protocol.packet;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class Packet0DPositionAndLook extends DefinedPacket {
|
||||
private double x;
|
||||
private double y;
|
||||
private double stance;
|
||||
private double z;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private boolean onGround;
|
||||
private double x;
|
||||
private double y;
|
||||
private double stance;
|
||||
private double z;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private boolean onGround;
|
||||
|
||||
private Packet0DPositionAndLook() {
|
||||
super(13);
|
||||
}
|
||||
private Packet0DPositionAndLook() {
|
||||
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) {
|
||||
this();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.stance = stance;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
this.onGround = 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;
|
||||
this.stance = stance;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
this.onGround = onGround;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(final ByteBuf buf) {
|
||||
this.x = buf.readDouble();
|
||||
this.y = buf.readDouble();
|
||||
this.stance = buf.readDouble();
|
||||
this.z = buf.readDouble();
|
||||
this.yaw = buf.readFloat();
|
||||
this.pitch = buf.readFloat();
|
||||
this.onGround = buf.readBoolean();
|
||||
}
|
||||
@Override
|
||||
public void read(final ByteBuf buf) {
|
||||
this.x = buf.readDouble();
|
||||
this.y = buf.readDouble();
|
||||
this.stance = buf.readDouble();
|
||||
this.z = buf.readDouble();
|
||||
this.yaw = buf.readFloat();
|
||||
this.pitch = buf.readFloat();
|
||||
this.onGround = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buf) {
|
||||
buf.writeDouble(this.x);
|
||||
buf.writeDouble(this.y);
|
||||
buf.writeDouble(this.stance);
|
||||
buf.writeDouble(this.z);
|
||||
buf.writeFloat(this.yaw);
|
||||
buf.writeFloat(this.pitch);
|
||||
buf.writeBoolean(this.onGround);
|
||||
}
|
||||
@Override
|
||||
public void write(final ByteBuf buf) {
|
||||
buf.writeDouble(this.x);
|
||||
buf.writeDouble(this.y);
|
||||
buf.writeDouble(this.stance);
|
||||
buf.writeDouble(this.z);
|
||||
buf.writeFloat(this.yaw);
|
||||
buf.writeFloat(this.pitch);
|
||||
buf.writeBoolean(this.onGround);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(final AbstractPacketHandler handler) throws Exception {
|
||||
handler.handle(this);
|
||||
}
|
||||
@Override
|
||||
public void handle(final AbstractPacketHandler handler) throws Exception {
|
||||
handler.handle(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Packet0DPositionAndLook(tooLazyToFillThisInLOL)";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Packet0DPositionAndLook(tooLazyToFillThisInLOL)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof Packet0DPositionAndLook)) {
|
||||
return false;
|
||||
}
|
||||
final Packet0DPositionAndLook other = (Packet0DPositionAndLook) o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
if (this.x != other.x) {
|
||||
return false;
|
||||
}
|
||||
if (this.y != other.y) {
|
||||
return false;
|
||||
}
|
||||
if (this.stance != other.stance) {
|
||||
return false;
|
||||
}
|
||||
if (this.z != other.z) {
|
||||
return false;
|
||||
}
|
||||
if (this.yaw != other.yaw) {
|
||||
return false;
|
||||
}
|
||||
if (this.pitch != other.pitch) {
|
||||
return false;
|
||||
}
|
||||
if (this.onGround != other.onGround) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof Packet0DPositionAndLook)) {
|
||||
return false;
|
||||
}
|
||||
final Packet0DPositionAndLook other = (Packet0DPositionAndLook) o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
if (this.x != other.x) {
|
||||
return false;
|
||||
}
|
||||
if (this.y != other.y) {
|
||||
return false;
|
||||
}
|
||||
if (this.stance != other.stance) {
|
||||
return false;
|
||||
}
|
||||
if (this.z != other.z) {
|
||||
return false;
|
||||
}
|
||||
if (this.yaw != other.yaw) {
|
||||
return false;
|
||||
}
|
||||
if (this.pitch != other.pitch) {
|
||||
return false;
|
||||
}
|
||||
if (this.onGround != other.onGround) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
result = result * 31 + Double.hashCode(this.x);
|
||||
result = result * 31 + Double.hashCode(this.y);
|
||||
result = result * 31 + Double.hashCode(this.stance);
|
||||
result = result * 31 + Double.hashCode(this.z);
|
||||
result = result * 31 + Float.hashCode(this.yaw);
|
||||
result = result * 31 + Float.hashCode(this.pitch);
|
||||
result = result * 31 + Boolean.hashCode(this.onGround);
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
result = result * 31 + Double.hashCode(this.x);
|
||||
result = result * 31 + Double.hashCode(this.y);
|
||||
result = result * 31 + Double.hashCode(this.stance);
|
||||
result = result * 31 + Double.hashCode(this.z);
|
||||
result = result * 31 + Float.hashCode(this.yaw);
|
||||
result = result * 31 + Float.hashCode(this.pitch);
|
||||
result = result * 31 + Boolean.hashCode(this.onGround);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean canEqual(final Object other) {
|
||||
return other instanceof Packet0DPositionAndLook;
|
||||
}
|
||||
public boolean canEqual(final Object other) {
|
||||
return other instanceof Packet0DPositionAndLook;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user