This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor commands + add more commands
- Loading branch information
Showing
17 changed files
with
227 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/me/vlod/pinto/consolehandler/commands/ChangePassword.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package me.vlod.pinto.consolehandler.commands; | ||
|
||
import me.vlod.pinto.PintoServer; | ||
import me.vlod.pinto.UserDatabaseEntry; | ||
import me.vlod.pinto.Utils; | ||
import me.vlod.pinto.consolehandler.ConsoleCaller; | ||
import me.vlod.pinto.consolehandler.ConsoleCommand; | ||
import me.vlod.pinto.networking.NetworkHandler; | ||
|
||
public class ChangePassword implements ConsoleCommand { | ||
@Override | ||
public String getName() { | ||
return "change-password"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Changes a user's password, they will be kicked"; | ||
} | ||
|
||
@Override | ||
public String getUsage() { | ||
return "change-password <user> <new password>"; | ||
} | ||
|
||
@Override | ||
public int getMinArgsCount() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public int getMaxArgsCount() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public void execute(PintoServer server, ConsoleCaller caller, String[] args) throws Exception { | ||
String user = args[0]; | ||
String password = args[1]; | ||
|
||
if (!UserDatabaseEntry.isRegistered(server, user)) { | ||
PintoServer.logger.error("The account %s is not registered", user); | ||
return; | ||
} | ||
|
||
UserDatabaseEntry userDatabaseEntry = new UserDatabaseEntry(server, user); | ||
userDatabaseEntry.load(); | ||
userDatabaseEntry.passwordHash = Utils.getSHA256HashFromStr("", password); | ||
userDatabaseEntry.save(); | ||
PintoServer.logger.info("Successfully changed %s's password", user); | ||
|
||
NetworkHandler netHandler = server.getHandlerByName(user); | ||
if (netHandler != null) { | ||
netHandler.kick("Your password has been modified!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/me/vlod/pinto/consolehandler/commands/ListUsers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package me.vlod.pinto.consolehandler.commands; | ||
|
||
import me.vlod.pinto.PintoServer; | ||
import me.vlod.pinto.configuration.MainConfig; | ||
import me.vlod.pinto.consolehandler.ConsoleCaller; | ||
import me.vlod.pinto.consolehandler.ConsoleCommand; | ||
import me.vlod.pinto.networking.NetworkHandler; | ||
|
||
public class ListUsers implements ConsoleCommand { | ||
@Override | ||
public String getName() { | ||
return "list-users"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Lists all connected users"; | ||
} | ||
|
||
@Override | ||
public String getUsage() { | ||
return "list-users"; | ||
} | ||
|
||
@Override | ||
public int getMinArgsCount() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getMaxArgsCount() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void execute(PintoServer server, ConsoleCaller caller, String[] args) throws Exception { | ||
PintoServer.logger.info("There are %d clients out of the max of %d connected%s", | ||
server.clients.size(), MainConfig.instance.maxUsers, server.clients.size() > 0 ? ":" : ""); | ||
|
||
for (NetworkHandler client : server.clients.toArray(new NetworkHandler[0])) { | ||
PintoServer.logger.info("- %s (%s)", client.networkAddress, | ||
client.userName != null ? client.userName : "** UNAUTHENTICATED **"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.