@Override
public void processCommandPlayer(EntityPlayer sender, String[] args)
{
if (args.length == 0)
{
throw new WrongUsageException("command.auth.usage");
}
boolean hasAdmin = PermissionsManager.checkPermission(sender, getPermissionNode() + ".admin");
// one arg? must be help.
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("help"))
{
OutputHandler.chatConfirmation(sender, " - /auth register <password>");
OutputHandler.chatConfirmation(sender, " - /auth login <password>");
OutputHandler.chatConfirmation(sender, " - /auth changepass <oldpass> <newpass> - changes your password");
if (!hasAdmin)
{
return;
}
OutputHandler.chatConfirmation(sender, " - /auth kick <player> - forces the player to login again");
OutputHandler.chatConfirmation(sender, " - /auth setpass <player> <password> - sets the players password");
OutputHandler.chatConfirmation(sender, " - /auth unregister <player> - forces the player to register again");
return;
}
else
{
throw new WrongUsageException("/auth help");
}
}
// 2 args? seconds needs to be the player.
if (args.length == 2)
{
// parse login
if (args[0].equalsIgnoreCase("login"))
{
PlayerPassData data = PlayerPassData.getData(sender.getPersistentID());
if (data == null)
{
OutputHandler.chatError(sender, String.format("Player %s is not registered!", sender.getPersistentID()));
return;
}
String pass = ModuleAuth.encrypt(args[1]);
// login worked
if (data.password.equals(pass))
{
ModuleAuth.hasSession.add(sender.getPersistentID());
OutputHandler.chatConfirmation(sender, "Login successful.");
}
else
{
OutputHandler.chatError(sender, "Login failed.");
}
return;
}
// parse register
else if (args[0].equalsIgnoreCase("register"))
{
if (PlayerPassData.getData(sender.getPersistentID()) != null)
{
OutputHandler.chatError(sender, String.format("Player %s is already registered!", sender.getPersistentID()));
return;
}
if (ModuleAuth.isEnabled() && !ModuleAuth.allowOfflineReg)
{
OutputHandler.chatError(sender, "Registrations have been disabled.");
return;
}
String pass = ModuleAuth.encrypt(args[1]);
PlayerPassData.registerData(sender.getPersistentID(), pass);
OutputHandler.chatConfirmation(sender, "Registration successful.");
return;
}
// stop if unlogged.
if (!ModuleAuth.hasSession.contains(sender.getPersistentID()))
{
OutputHandler.chatError(sender, "Login required. Try /auth help.");
return;
}
// check for players.. all the rest of these should be greated than 1.
UUID name = UserIdent.getUuidByUsername(args[1]);
boolean isLogged = true;
// check if the player is logged.
EntityPlayerMP player = UserIdent.getPlayerByMatchOrUsername(sender, args[1]);
if (player == null)
{
OutputHandler.chatWarning(sender, "A player of that name is not on the server. Doing the action anyways.");
isLogged = false;
}
// parse ./auth kick
if (args[0].equalsIgnoreCase("kick"))
{
if (!hasAdmin)
{
throw new PermissionDeniedException();
}
else if (!isLogged)
{
throw new PlayerNotFoundException();
}
else
{
ModuleAuth.hasSession.remove(name);
OutputHandler.chatConfirmation(sender, String.format("Player %s was logged out from the authentication service.", name));
OutputHandler.chatWarning(player, "You have been logged out from the authentication service. Please login again.");
return;
}
}
// parse ./auth setpass
else if (args[0].equalsIgnoreCase("setPass"))
{
if (!hasAdmin)
{
throw new PermissionDeniedException();
}
throw new WrongUsageException("/auth setpass <player> <password>");
}
// parse ./auth unregister
else if (args[0].equalsIgnoreCase("unregister"))
{
if (!hasAdmin)
{
throw new PermissionDeniedException();
}
if (PlayerPassData.getData(name) == null)
{
throw new WrongUsageException(String.format("Player %s is not registered!", name));
}
PlayerPassData.deleteData(name);
OutputHandler.chatConfirmation(sender, String.format("Player %s has been removed from the authentication service.", name));
return;
}
// ERROR! :D
else
{
throw new WrongUsageException("/auth help");
}
}
// 3 args? must be a comtmand - player - pass
else if (args.length == 3)
{
if (!ModuleAuth.hasSession.contains(sender.getPersistentID()))
{
OutputHandler.chatError(sender, "Login required. Try /auth help.");
return;
}
// parse changePass
if (args[0].equalsIgnoreCase("changepass"))
{
UUID name = sender.getPersistentID();
PlayerPassData data = PlayerPassData.getData(name);
if (data == null)
{
throw new WrongUsageException(String.format("Player %s is not registered!", name));
}
String oldpass = ModuleAuth.encrypt(args[1]);
String newPass = ModuleAuth.encrypt(args[2]);
if (args[1].equals(args[2]))