mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Added basic functionality for debug commands
This commit is contained in:
parent
187a828c79
commit
95a14ad1ab
@ -1,16 +0,0 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.ServerConfiguration;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
|
||||
public class VaultPlugin extends ServerPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public void init(ServerConfiguration config) {
|
||||
|
||||
|
||||
LogManager.LOGGER.info("Initialised Vault plugin");
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package net.simon987.server.webserver;
|
||||
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class DebugHandler implements MessageHandler {
|
||||
@Override
|
||||
public void handle(OnlineUser user, JSONObject json) {
|
||||
|
||||
if (json.get("t").equals("debug") && user.isModerator()) {
|
||||
|
||||
LogManager.LOGGER.fine("(WS) Debug command from " + user.getUser().getUsername());
|
||||
|
||||
String command = (String) json.get("command");
|
||||
|
||||
if (json.containsKey("command")) {
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
|
||||
switch (command) {
|
||||
|
||||
case "":
|
||||
break;
|
||||
|
||||
default:
|
||||
LogManager.LOGGER.severe("Unknown command: " + command);
|
||||
response.put("t", "debug");
|
||||
response.put("message", "Unknown command " + command);
|
||||
}
|
||||
|
||||
user.getWebSocket().send(response.toJSONString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@ public class OnlineUser {
|
||||
|
||||
private boolean guest;
|
||||
|
||||
private boolean moderator;
|
||||
|
||||
/**
|
||||
* Associated game user (if authenticated)
|
||||
*/
|
||||
@ -50,4 +52,12 @@ public class OnlineUser {
|
||||
public boolean isGuest() {
|
||||
return guest;
|
||||
}
|
||||
|
||||
public boolean isModerator() {
|
||||
return moderator;
|
||||
}
|
||||
|
||||
public void setModerator(boolean moderator) {
|
||||
this.moderator = moderator;
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ public class SocketServer extends WebSocketServer {
|
||||
messageEventDispatcher.addHandler(new CodeRequestHandler());
|
||||
messageEventDispatcher.addHandler(new KeypressHandler());
|
||||
messageEventDispatcher.addHandler(new FloppyHandler());
|
||||
messageEventDispatcher.addHandler(new DebugHandler());
|
||||
|
||||
}
|
||||
|
||||
@ -107,7 +108,10 @@ public class SocketServer extends WebSocketServer {
|
||||
if (username != null) {
|
||||
User user = GameServer.INSTANCE.getGameUniverse().getOrCreateUser(username, true);
|
||||
|
||||
LogManager.LOGGER.info("(WS) User was successfully authenticated: " + user.getUsername());
|
||||
onlineUser.setModerator(database.isModerator(username));
|
||||
|
||||
LogManager.LOGGER.info("(WS) User was successfully authenticated: " + user.getUsername() +
|
||||
" moderator: " + onlineUser.isModerator());
|
||||
|
||||
onlineUser.setUser(user);
|
||||
onlineUser.setAuthenticated(true);
|
||||
|
@ -45,6 +45,33 @@ class SocketServerDatabase extends DatabaseManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isModerator(String username) {
|
||||
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = getConnection();
|
||||
|
||||
PreparedStatement p = connection.prepareStatement("SELECT moderator FROM mar_user WHERE username=?");
|
||||
p.setString(1, username);
|
||||
|
||||
ResultSet rs = p.executeQuery();
|
||||
|
||||
return rs.next() && rs.getBoolean("moderator");
|
||||
|
||||
} catch (SQLException e) {
|
||||
LogManager.LOGGER.severe("MySQL Error " + e.getErrorCode() + ": " + e.getMessage());
|
||||
|
||||
} finally {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] getFloppy(String username) {
|
||||
|
||||
Connection connection = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user