Skip to content

Commit

Permalink
Make god-mode lag boundaries configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Feb 4, 2013
1 parent f126a13 commit fcd18ea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Expand Up @@ -77,6 +77,8 @@ public static FightConfig getConfig(final Player player) {
public final ActionList directionActions;

public final boolean godModeCheck;
public final long godModeLagMinAge;
public final long godModeLagMaxAge;
public final ActionList godModeActions;

public final boolean knockbackCheck;
Expand Down Expand Up @@ -131,6 +133,8 @@ public FightConfig(final ConfigFile data) {
directionActions = data.getOptimizedActionList(ConfPaths.FIGHT_DIRECTION_ACTIONS, Permissions.FIGHT_DIRECTION);

godModeCheck = data.getBoolean(ConfPaths.FIGHT_GODMODE_CHECK);
godModeLagMinAge = data.getLong(ConfPaths.FIGHT_GODMODE_LAGMINAGE);
godModeLagMaxAge = data.getLong(ConfPaths.FIGHT_GODMODE_LAGMAXAGE);
godModeActions = data.getOptimizedActionList(ConfPaths.FIGHT_GODMODE_ACTIONS, Permissions.FIGHT_GODMODE);

knockbackCheck = data.getBoolean(ConfPaths.FIGHT_KNOCKBACK_CHECK);
Expand Down
Expand Up @@ -120,6 +120,8 @@ public boolean check(final Player player, final int damage){
legit = set = resetAcc = true;
}

// TODO: Might account for ndt/2 on regain health (!).

// Invulnerable or inconsistent.
// TODO: might check as well if NCP has taken over invulnerable ticks of this player.
if (invulnerabilityTicks > 0 && noDamageTicks != invulnerabilityTicks || tick < data.lastDamageTick){
Expand Down Expand Up @@ -187,14 +189,18 @@ else if (legit){
if (dht <= 20) return false;
}

final FightConfig cc = FightConfig.getConfig(player);

// Check for client side lag.
final long now = System.currentTimeMillis();
final long maxAge = 5000; // Allows 5 seconds lag max. TODO: Balance, test.
final long maxAge = cc.godModeLagMaxAge;
long keepAlive = mcAccess.getKeepAliveTime(player);
if (keepAlive > now || keepAlive == Long.MIN_VALUE){
keepAlive = CheckUtils.guessKeepAliveTime(player, now, maxAge);
}
if (keepAlive != Double.MIN_VALUE && now - keepAlive > 1000 && now - keepAlive < maxAge){
// TODO: else: still check the other time stamp ?

if (keepAlive != Double.MIN_VALUE && now - keepAlive > cc.godModeLagMinAge && now - keepAlive < maxAge){
// Assume lag.
return false;
}
Expand Down
Expand Up @@ -369,6 +369,8 @@ public abstract class ConfPaths {

private static final String FIGHT_GODMODE = FIGHT + "godmode.";
public static final String FIGHT_GODMODE_CHECK = FIGHT_GODMODE + "active";
public static final String FIGHT_GODMODE_LAGMINAGE = FIGHT_GODMODE + "minage";
public static final String FIGHT_GODMODE_LAGMAXAGE = FIGHT_GODMODE + "maxage";
public static final String FIGHT_GODMODE_ACTIONS = FIGHT_GODMODE + "actions";

private static final String FIGHT_KNOCKBACK = FIGHT + "knockback.";
Expand Down
Expand Up @@ -293,6 +293,8 @@ public DefaultConfig() {
"cancel vl>5 log:fdirection:3:5:f cancel vl>20 log:fdirection:0:5:if cancel vl>50 log:fdirection:0:5:cif cancel");

set(ConfPaths.FIGHT_GODMODE_CHECK, true);
set(ConfPaths.FIGHT_GODMODE_LAGMINAGE, 1100); // TODO: ndt/2 => 500-600.
set(ConfPaths.FIGHT_GODMODE_LAGMAXAGE, 5000);
set(ConfPaths.FIGHT_GODMODE_ACTIONS, "log:godmode:2:5:if cancel vl>60 log:godmode:2:5:icf cancel"); // cmd:kickgod");

set(ConfPaths.FIGHT_KNOCKBACK_CHECK, true);
Expand Down

0 comments on commit fcd18ea

Please sign in to comment.