forked from MagicBane/Server
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.0 KiB
90 lines
3.0 KiB
package engine.util; |
|
|
|
import engine.gameManager.ChatManager; |
|
import engine.gameManager.ConfigManager; |
|
import engine.gameManager.DbManager; |
|
import engine.gameManager.SessionManager; |
|
import engine.net.client.ClientConnection; |
|
import engine.net.client.Protocol; |
|
import engine.net.client.msg.ClientNetMsg; |
|
import engine.net.client.msg.TargetObjectMsg; |
|
import engine.objects.Group; |
|
import engine.objects.PlayerCharacter; |
|
import org.pmw.tinylog.Logger; |
|
|
|
public enum KeyCloneAudit { |
|
KEYCLONEAUDIT; |
|
|
|
public void audit(PlayerCharacter player, Group group) { |
|
|
|
int machineCount = 0; |
|
String machineID; |
|
|
|
machineID = player.getClientConnection().machineID; |
|
|
|
for (PlayerCharacter member : group.getMembers()) |
|
if (machineID.equals(member.getClientConnection().machineID)) |
|
machineCount = machineCount + 1; |
|
|
|
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); |
|
} |
|
|
|
} |
|
|
|
public static boolean auditNetMsg(ClientNetMsg msg) { |
|
boolean valid = true; |
|
try { |
|
if (msg.getProtocolMsg().equals(Protocol.KEEPALIVESERVERCLIENT)) |
|
return true; |
|
|
|
ClientConnection origin = (ClientConnection) msg.getOrigin(); |
|
long now = System.currentTimeMillis(); |
|
PlayerCharacter pc = SessionManager.getSession(origin).getPlayerCharacter(); |
|
|
|
if (msg.getProtocolMsg().equals(Protocol.SETSELECTEDOBECT)) { |
|
TargetObjectMsg tarMsg = (TargetObjectMsg) msg; |
|
|
|
// Calculate time since last target switch |
|
long timeSinceLastTarget = now - origin.lastTargetSwitchTime; |
|
origin.lastTargetSwitchTime = now; |
|
|
|
// 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) { |
|
valid = false; |
|
} |
|
} |
|
} |
|
if(origin.lastStrike + 2000L < System.currentTimeMillis()) { |
|
if (!valid) { |
|
origin.strikes++; |
|
origin.lastStrike = System.currentTimeMillis(); |
|
} |
|
}else{ |
|
origin.strikes = 0; |
|
} |
|
|
|
if(origin.strikes > 10){ |
|
//origin.forceDisconnect(); |
|
ChatManager.chatSystemInfo(pc, "Cheater Cheater Pumpkin Eater"); |
|
} |
|
}catch(Exception e) { |
|
|
|
} |
|
return valid; |
|
} |
|
|
|
}
|
|
|