Files
prestonbane/src/engine/util/KeyCloneAudit.java
T

77 lines
2.6 KiB
Java
Raw Normal View History

2023-01-21 10:04:34 -05:00
package engine.util;
2022-04-30 09:41:17 -04:00
2025-02-09 14:37:44 -06:00
import engine.gameManager.ChatManager;
import engine.gameManager.ConfigManager;
2022-04-30 09:41:17 -04:00
import engine.gameManager.DbManager;
2025-02-09 14:37:44 -06:00
import engine.gameManager.SessionManager;
import engine.net.client.ClientConnection;
2025-02-09 14:13:28 -06:00
import engine.net.client.Protocol;
2025-02-09 14:08:17 -06:00
import engine.net.client.msg.ClientNetMsg;
2025-02-09 14:37:44 -06:00
import engine.net.client.msg.TargetObjectMsg;
2022-04-30 09:41:17 -04:00
import engine.objects.Group;
import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
public enum KeyCloneAudit {
KEYCLONEAUDIT;
2023-01-21 10:04:34 -05:00
public void audit(PlayerCharacter player, Group group) {
2022-04-30 09:41:17 -04:00
int machineCount = 0;
String machineID;
machineID = player.getClientConnection().machineID;
for (PlayerCharacter member : group.getMembers())
if (machineID.equals(member.getClientConnection().machineID))
machineCount = machineCount + 1;
2023-07-15 09:23:48 -04:00
if (machineCount > Integer.parseInt(ConfigManager.MB_WORLD_KEYCLONE_MAX.getValue())) {
Logger.error("Keyclone detected from: " + player.getAccount().getUname() +
" with machine count of: " + machineCount);
DbManager.AccountQueries.SET_TRASH(machineID);
}
2022-04-30 09:41:17 -04:00
}
2025-02-09 14:08:17 -06:00
2025-02-09 14:37:44 -06:00
public static boolean auditNetMsg(ClientNetMsg msg) {
2025-02-09 14:08:17 -06:00
boolean valid = true;
2025-02-09 14:37:44 -06:00
if (msg.getProtocolMsg().equals(Protocol.KEEPALIVESERVERCLIENT))
2025-02-09 14:13:28 -06:00
return true;
2025-02-09 14:37:44 -06:00
ClientConnection origin = (ClientConnection) msg.getOrigin();
long now = System.currentTimeMillis();
PlayerCharacter pc = SessionManager.getSession(origin).getPlayerCharacter();
2025-02-09 14:13:28 -06:00
2025-02-09 14:37:44 -06:00
if (msg.getProtocolMsg().equals(Protocol.SETSELECTEDOBECT)) {
TargetObjectMsg tarMsg = (TargetObjectMsg) msg;
2025-02-09 14:13:28 -06:00
2025-02-09 14:37:44 -06:00
// Calculate time since last target switch
long timeSinceLastTarget = now - origin.lastTargetSwitchTime;
origin.lastTargetSwitchTime = now;
2025-02-09 14:08:17 -06:00
2025-02-09 14:37:44 -06:00
// Check if the target has changed
if (tarMsg.getTargetID() != origin.lastTargetID) {
origin.lastTargetID = tarMsg.getTargetID();
origin.targetSwitchCount++;
// If switching too fast, flag as bot-like behavior
if (timeSinceLastTarget < 300) { // Adjust this threshold if needed
origin.fastTargetSwitchCount++;
} else {
origin.fastTargetSwitchCount = Math.max(0, origin.fastTargetSwitchCount - 1);
}
if (origin.fastTargetSwitchCount > 5) {
ChatManager.chatSystemInfo(pc, "Possible bot detected: Targeting too quickly.");
valid = false;
}
}
}
2025-02-09 14:08:17 -06:00
return valid;
}
2025-02-09 14:37:44 -06:00
2022-04-30 09:41:17 -04:00
}