More metadata

This commit is contained in:
samczsun 2016-10-17 22:12:05 -04:00
parent 994d286abe
commit 77f1f18f27
7 changed files with 310 additions and 22 deletions

View File

@ -20,6 +20,11 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.mineplex</groupId>
<artifactId>mineplex-serverdata</artifactId>
<version>dev-SNAPSHOT</version>
</dependency>
</dependencies>
<build>

View File

@ -2,6 +2,8 @@ package mineplex.core.common.util;
import com.google.common.collect.Lists;
import mineplex.core.common.events.PlayerRecieveBroadcastEvent;
import mineplex.serverdata.Region;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.Sound;
@ -135,6 +137,16 @@ public class UtilServer
return getPlugin().getConfig().getString("serverstatus.name");
}
public static Region getRegion()
{
return getPlugin().getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
}
public static String getGroup()
{
return getPlugin().getConfig().getString("serverstatus.group");
}
public static boolean isTestServer()
{
return getPlugin().getConfig().getString("serverstatus.group").equalsIgnoreCase("Testing");

View File

@ -31,7 +31,8 @@ import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.ViolationLevels;
import mineplex.core.antihack.logging.builtin.VLTimestampMetadata;
import mineplex.core.antihack.logging.builtin.ServerInfoMetadata;
import mineplex.core.antihack.logging.builtin.ViolationInfoMetadata;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
@ -72,7 +73,8 @@ public class AntihackLogger extends MiniPlugin
20 * PUSH_QUEUE_TIME_IN_SECONDS
);
registerMetadata(new VLTimestampMetadata());
registerMetadata(new ServerInfoMetadata());
registerMetadata(new ViolationInfoMetadata());
}
@Override

View File

@ -0,0 +1,38 @@
package mineplex.core.antihack.logging.builtin;
import java.util.UUID;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import mineplex.core.antihack.logging.AnticheatMetadata;
import mineplex.core.common.util.UtilServer;
public class ServerInfoMetadata extends AnticheatMetadata
{
private static final String KEY_SERVER_NAME = "server-name";
private static final String KEY_SERVER_REGION = "server-region";
private static final String KEY_SERVER_GROUP = "server-group";
@Override
public String getId()
{
return "server-info";
}
@Override
public JsonElement build(UUID player)
{
JsonObject info = new JsonObject();
info.addProperty(KEY_SERVER_NAME, UtilServer.getServerName());
info.addProperty(KEY_SERVER_REGION, UtilServer.getRegion().name());
info.addProperty(KEY_SERVER_GROUP, UtilServer.getGroup());
return info;
}
@Override
public void remove(UUID player)
{
}
}

View File

@ -8,6 +8,7 @@ import java.util.UUID;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
@ -25,14 +26,23 @@ import gnu.trove.map.TObjectLongMap;
import gnu.trove.map.hash.TObjectIntHashMap;
import gnu.trove.map.hash.TObjectLongHashMap;
public class VLTimestampMetadata extends AnticheatMetadata
public class ViolationInfoMetadata extends AnticheatMetadata
{
private static final Location MUTABLE_LOCATION = new Location(null, 0, 0, 0);
private static final String KEY_JOIN_TIME_MS = "join-time-ms";
private static final String KEY_JOIN_TIME_TICK = "join-time-tick";
private static final String KEY_MESSAGE = "msg";
private static final String KEY_DELTA_MS = "current-time-ms";
private static final String KEY_DELTA_TICK = "current-time-tick";
private static final String KEY_CURRENT_TIME = "current-time";
private static final String KEY_MS = "ms";
private static final String KEY_TICK = "tick";
private static final String KEY_VIOLATION_INFO = "violation-info";
private static final String KEY_VL = "current-vl";
private static final String KEY_MESSAGE = "msg";
private static final String KEY_PLAYER_INFO = "player-info";
private static final String KEY_LOCATION = "loc";
private static final JsonObject VAL_CHECK_DISABLED;
@ -44,14 +54,12 @@ public class VLTimestampMetadata extends AnticheatMetadata
private TObjectLongMap<UUID> _joinTime = new TObjectLongHashMap<>();
private TObjectIntMap<UUID> _joinTimeTick = new TObjectIntHashMap<>();
private TObjectLongMap<UUID> _lastActive = new TObjectLongHashMap<>();
private TObjectIntMap<UUID> _lastActiveTick = new TObjectIntHashMap<>();
private Map<UUID, Map<Class<? extends Check>, List<JsonObject>>> _violations = new HashMap<>();
@Override
public String getId()
{
return "vl-timestamps";
return "violation-info";
}
@Override
@ -75,8 +83,6 @@ public class VLTimestampMetadata extends AnticheatMetadata
{
_joinTime.remove(player);
_joinTimeTick.remove(player);
_lastActive.remove(player);
_lastActiveTick.remove(player);
_violations.remove(player);
}
@ -87,8 +93,6 @@ public class VLTimestampMetadata extends AnticheatMetadata
int thisTick = MinecraftServer.getServer().at();
_joinTime.put(event.getPlayer().getUniqueId(), thisMs);
_joinTimeTick.put(event.getPlayer().getUniqueId(), thisTick);
_lastActive.put(event.getPlayer().getUniqueId(), thisMs);
_lastActiveTick.put(event.getPlayer().getUniqueId(), thisTick);
_violations.put(event.getPlayer().getUniqueId(), new HashMap<>());
}
@ -113,17 +117,35 @@ public class VLTimestampMetadata extends AnticheatMetadata
List<JsonObject> violations = _violations.get(event.getPlayer().getUniqueId()).computeIfAbsent(event.getCheckClass(), key -> new ArrayList<>());
int timeDelta = (int) (thisMs - _lastActive.get(event.getPlayer().getUniqueId()));
int tickDelta = thisTick - _lastActiveTick.get(event.getPlayer().getUniqueId());
_lastActive.put(event.getPlayer().getUniqueId(), thisMs);
_lastActiveTick.put(event.getPlayer().getUniqueId(), thisTick);
JsonObject currentTime = new JsonObject();
currentTime.addProperty(KEY_MS, thisMs);
currentTime.addProperty(KEY_TICK, thisTick);
JsonObject violationInfo = new JsonObject();
violationInfo.addProperty(KEY_VL, event.getViolations());
violationInfo.addProperty(KEY_MESSAGE, event.getMessage());
JsonObject playerInfo = new JsonObject();
playerInfo.addProperty(KEY_LOCATION, toString(event.getPlayer().getLocation(MUTABLE_LOCATION)));
JsonObject data = new JsonObject();
data.addProperty(KEY_DELTA_MS, thisMs);
data.addProperty(KEY_DELTA_TICK, thisTick);
data.addProperty(KEY_VL, event.getViolations());
data.addProperty(KEY_MESSAGE, event.getMessage());
data.add(KEY_CURRENT_TIME, currentTime);
data.add(KEY_VIOLATION_INFO, violationInfo);
data.add(KEY_PLAYER_INFO, playerInfo);
violations.add(data);
}
private String toString(Location location)
{
return location.getWorld().getName() + ", " +
fastRound2Digits(location.getX()) + ", " +
fastRound2Digits(location.getY()) + ", " +
fastRound2Digits(location.getZ());
}
private double fastRound2Digits(double in)
{
return (long) (in * 100 + 0.5) / 100.0;
}
}

View File

@ -4,6 +4,7 @@ import mineplex.core.CustomTagFix;
import mineplex.core.FoodDupeFix;
import mineplex.core.PacketsInteractionFix;
import mineplex.core.TimingsFix;
import mineplex.core.antihack.logging.AntihackLogger;
import mineplex.core.chatsnap.SnapshotRepository;
import mineplex.core.customdata.CustomDataManager;
import mineplex.core.chatsnap.SnapshotManager;
@ -65,6 +66,8 @@ import mineplex.core.velocity.VelocityFix;
import mineplex.core.visibility.VisibilityManager;
import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import nautilus.game.arcade.anticheatmetadata.GameInfoMetadata;
import nautilus.game.arcade.game.GameServerConfig;
import org.bukkit.Bukkit;
@ -184,7 +187,9 @@ public class Arcade extends JavaPlugin
//Arcade Manager
PollManager pollManager = new PollManager(this, _clientManager, _donationManager);
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, statsManager, incognito, achievementManager, disguiseManager, creature, teleport, new Blood(this), chat, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress, pollManager, npcmanager, customDataManager, punish, eloManager, thankManager, boosterManager);
require(AntihackLogger.class).registerMetadata(new GameInfoMetadata());
new GlobalPacketManager(this, _clientManager, serverStatusManager, inventoryManager, _donationManager, petManager, statsManager, _gameManager.getBonusManager().getRewardManager());
//new BroadcastManager(this, _gameManager);

View File

@ -0,0 +1,204 @@
package nautilus.game.arcade.anticheatmetadata;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import mineplex.core.antihack.logging.AnticheatMetadata;
import mineplex.core.common.util.UtilServer;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.managers.GameHostManager;
import static mineplex.core.Managers.require;
public class GameInfoMetadata extends AnticheatMetadata
{
private static final String KEY_GAME_INFO = "game-info";
private static final String KEY_GAME_MAP = "map";
private static final String KEY_GAME_TYPE = "type";
private static final String KEY_GAME_MODE = "mode";
private static final String KEY_CURRENT_STATE = "current-state";
private static final String KEY_STATE_START_TIME = "current-state-start-time";
private static final String KEY_JOIN_GAME_TIME = "join-game-time-ms";
private static final String KEY_STATE_TIMES = "state-times";
private static final String KEY_KIT_INFO = "kit-info";
private static final String KEY_KIT_NAME = "name";
private static final String KEY_KIT_LEVEL = "level";
private static final String KEY_MPS = "mps";
private static final String KEY_OWNER = "owner";
private static final String KEY_STATS = "stats";
private static final String KEY_WINNER = "winner";
private final Map<UUID, JsonArray> _allGames = new HashMap<>();
private final Map<UUID, JsonObject> _currentGame = new HashMap<>();
private final ArcadeManager _arcadeManager = require(ArcadeManager.class);
@Override
public String getId()
{
return "game-info";
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
_allGames.put(event.getPlayer().getUniqueId(), new JsonArray());
JsonObject currentGame = buildCurrentGame();
if (currentGame != null)
{
_currentGame.put(event.getPlayer().getUniqueId(), currentGame);
}
}
private JsonObject buildCurrentGame()
{
Game game = _arcadeManager.GetGame();
if (game == null)
return null;
JsonObject currentGame = new JsonObject();
JsonObject gameInfo = new JsonObject();
gameInfo.addProperty(KEY_GAME_MAP, game.WorldData.File);
gameInfo.addProperty(KEY_GAME_TYPE, game.GetName());
gameInfo.addProperty(KEY_GAME_MODE, game.GetMode());
gameInfo.addProperty(KEY_CURRENT_STATE, game.GetState().name());
gameInfo.addProperty(KEY_STATE_START_TIME, game.GetStateTime());
gameInfo.addProperty(KEY_JOIN_GAME_TIME, System.currentTimeMillis());
if (_arcadeManager.GetGameHostManager() != null && _arcadeManager.GetGameHostManager().isPrivateServer())
{
GameHostManager gameHostManager = _arcadeManager.GetGameHostManager();
JsonObject mpsInfo = new JsonObject();
mpsInfo.addProperty(KEY_OWNER, _arcadeManager.GetHost());
currentGame.add(KEY_MPS, mpsInfo);
}
currentGame.add(KEY_GAME_INFO, gameInfo);
JsonObject stateStartTimes = new JsonObject();
stateStartTimes.addProperty(game.GetState().name(), game.GetStateTime());
currentGame.add(KEY_STATE_TIMES, stateStartTimes);
return currentGame;
}
@EventHandler
public void onStateChange(GameStateChangeEvent event)
{
if (event.GetState() == Game.GameState.Recruit)
{
for (Player player : UtilServer.getPlayersCollection())
{
if (!_currentGame.containsKey(player.getUniqueId()))
{
_currentGame.put(player.getUniqueId(), buildCurrentGame());
}
}
}
if (event.GetState() == Game.GameState.Live)
{
_currentGame.forEach((id, obj) ->
{
Player player = Bukkit.getPlayer(id);
if (player != null)
{
Kit kit = event.GetGame().GetKit(player);
if (kit != null)
{
JsonObject kitInfo = new JsonObject();
kitInfo.addProperty(KEY_KIT_NAME, kit.GetName());
if (kit instanceof ProgressingKit)
{
ProgressingKit pk = (ProgressingKit) kit;
kitInfo.addProperty(KEY_KIT_LEVEL, pk.getLevel(player.getUniqueId()));
}
obj.add(KEY_KIT_INFO, kitInfo);
}
}
});
}
_currentGame.values().forEach(obj ->
{
obj.get(KEY_STATE_TIMES).getAsJsonObject().addProperty(event.GetState().name(), System.currentTimeMillis());
});
if (event.GetState() == Game.GameState.Dead)
{
new ArrayList<>(_currentGame.keySet()).forEach(ent -> archivePlayer(event.GetGame(), ent));
}
}
private void archivePlayer(Game game, UUID uuid)
{
JsonObject gameObj = _currentGame.remove(uuid);
if (gameObj == null)
return;
_allGames.get(uuid).add(gameObj);
if (game == null)
return;
Player player = Bukkit.getPlayer(uuid);
if (player == null)
return;
Map<String, Integer> stats = game.GetStats().get(player);
JsonObject statsObject = new JsonObject();
stats.forEach(statsObject::addProperty);
gameObj.add(KEY_STATS, statsObject);
gameObj.addProperty(KEY_WINNER, game.Winner);
}
@Override
public JsonElement build(UUID player)
{
archivePlayer(_arcadeManager.GetGame(), player);
return _allGames.get(player);
}
@Override
public void remove(UUID player)
{
_allGames.remove(player);
_currentGame.remove(player);
}
}