Skip to content

Commit

Permalink
Command execution events & no more leaking uuid on trace
Browse files Browse the repository at this point in the history
  • Loading branch information
buj committed Jan 12, 2025
1 parent 29c6482 commit c4ca288
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/src/mindustry/core/NetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,14 @@ public static void sendChatMessage(Player player, String message){
//this is required so other clients get the correct name even if they don't know who's sending it yet
Call.sendMessage(netServer.chatFormatter.format(player, message), message, player);
}else{

//a command was sent, now get the output
if(response.type != ResponseType.valid){
String text = netServer.invalidHandler.handle(player, response);
if(text != null){
player.sendMessage(text);
}
}else{
Events.fire(new mindustry.hotfix.Events.CommandExecuted(player, response, netServer.clientCommands));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/core/NetServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public static void adminRequest(Player player, Player other, AdminAction action,
}
case trace -> {
PlayerInfo stats = netServer.admins.getInfo(other.uuid());
TraceInfo info = new TraceInfo(other.con.address, other.uuid(), other.con.modclient, other.con.mobile, stats.timesJoined, stats.timesKicked, stats.ips.toArray(String.class), stats.names.toArray(String.class));
TraceInfo info = new TraceInfo(other.con.address, String.valueOf(other.id()), other.con.modclient, other.con.mobile, stats.timesJoined, stats.timesKicked, stats.ips.toArray(String.class), stats.names.toArray(String.class));
if(player.con != null){
Call.traceInfo(player.con, other, info);
}else{
Expand Down
41 changes: 41 additions & 0 deletions core/src/mindustry/hotfix/Events.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package mindustry.hotfix;

import arc.util.CommandHandler;
import arc.util.CommandHandler.CommandResponse;
import mindustry.gen.*;

/**
* Events specific to MindustryHotfix. Only depend on this API if you're not planning
* to use any other server software.
*/
public class Events {
private Events() {}

/**
* Called after a player executes a command.
*/
public static class CommandExecuted {
public Player player;
public CommandResponse response;
public CommandHandler handler;
public CommandExecuted(Player player, CommandResponse response, CommandHandler handler) {
this.player = player;
this.response = response;
this.handler = handler;
}
}

/**
* Called after console executes a command.
*/
public static class ConsoleCommandExecuted {
public CommandResponse response;
public CommandHandler handler;
public Boolean cancel;

public ConsoleCommandExecuted(CommandResponse response, CommandHandler handler) {
this.response = response;
this.handler = handler;
}
}
}
2 changes: 1 addition & 1 deletion server/src/mindustry/server/ServerControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ public void handleCommandString(String line){
CommandResponse response = handler.handleMessage(line);

if(response.type == ResponseType.unknownCommand){

int minDst = 0;
Command closest = null;

Expand All @@ -1050,6 +1049,7 @@ public void handleCommandString(String line){
}else if(response.type == ResponseType.manyArguments){
err("Too many command arguments. Usage: " + response.command.text + " " + response.command.paramText);
}else if(response.type == ResponseType.valid){
Events.fire(new mindustry.hotfix.Events.ConsoleCommandExecuted(response, handler));
suggested = null;
}
}
Expand Down

0 comments on commit c4ca288

Please sign in to comment.