Fixed naming in some hub modules.
Fixed StatusManager ip and DynamicServer comparison. Tweaked Bungee Lobby selection so it doesn't select a Lobby with < 10 slots left Added client cleanup in CoreClientManager Added Paintball cleanup Added AntiHack ignore list cleanup. Added clearDisguises call in DisguiseManager Added ServerMonitor tracking based on Private Address.
This commit is contained in:
parent
dd7b178a9f
commit
93c0575fe2
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,3 +13,5 @@ MagicMC
|
|||||||
/Plugins/Mineplex.AntiCheat
|
/Plugins/Mineplex.AntiCheat
|
||||||
|
|
||||||
update
|
update
|
||||||
|
|
||||||
|
Reference
|
||||||
|
@ -17,7 +17,7 @@ public class LobbyBalancerRepository
|
|||||||
private boolean _us;
|
private boolean _us;
|
||||||
|
|
||||||
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS ServerStatus (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), serverGroup VARCHAR(256), address VARCHAR(256), updated LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));";
|
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS ServerStatus (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), serverGroup VARCHAR(256), address VARCHAR(256), updated LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));";
|
||||||
private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, ServerStatus.address, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = ? AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;";
|
private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, ServerStatus.address, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = ? AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;";
|
||||||
|
|
||||||
public void initialize(boolean us)
|
public void initialize(boolean us)
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,12 @@ public class LobbySorter implements Comparator<ServerStatusData>
|
|||||||
if (first.Players == 999)
|
if (first.Players == 999)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
if (first.MaxPlayers - first.Players > 10 && second.MaxPlayers - second.Players <= 10)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (second.MaxPlayers - second.Players > 10 && first.MaxPlayers - first.Players <= 10)
|
||||||
|
return 1;
|
||||||
|
|
||||||
if (first.Players < (first.MaxPlayers / 2) && second.Players >= (second.MaxPlayers / 2))
|
if (first.Players < (first.MaxPlayers / 2) && second.Players >= (second.MaxPlayers / 2))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package mineplex.core.account;
|
|||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import mineplex.core.account.event.AsyncClientLoadEvent;
|
import mineplex.core.account.event.AsyncClientLoadEvent;
|
||||||
import mineplex.core.account.event.ClientUnloadEvent;
|
import mineplex.core.account.event.ClientUnloadEvent;
|
||||||
@ -13,6 +15,8 @@ import mineplex.core.account.repository.token.ClientToken;
|
|||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.updater.UpdateType;
|
||||||
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
|
import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
|
||||||
@ -223,7 +227,6 @@ public class CoreClientManager implements Listener
|
|||||||
}, name, rank, perm);
|
}, name, rank, perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void cleanGlitchedClients(UpdateEvent event)
|
public void cleanGlitchedClients(UpdateEvent event)
|
||||||
{
|
{
|
||||||
@ -233,9 +236,16 @@ public class CoreClientManager implements Listener
|
|||||||
for (Iterator<Entry<String, CoreClient>> clientIterator = _clientList.entrySet().iterator(); clientIterator.hasNext();)
|
for (Iterator<Entry<String, CoreClient>> clientIterator = _clientList.entrySet().iterator(); clientIterator.hasNext();)
|
||||||
{
|
{
|
||||||
Player clientPlayer = clientIterator.next().getValue().GetPlayer();
|
Player clientPlayer = clientIterator.next().getValue().GetPlayer();
|
||||||
if (clientPlayer == null || !clientPlayer.isOnline())
|
|
||||||
|
if ((clientPlayer == null || !clientPlayer.isOnline()) && !_dontRemoveList.contains(clientPlayer.getName()))
|
||||||
|
{
|
||||||
|
synchronized(_clientLock)
|
||||||
|
{
|
||||||
clientIterator.remove();
|
clientIterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_plugin.getServer().getPluginManager().callEvent(new ClientUnloadEvent(clientPlayer.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
import mineplex.core.antihack.types.*;
|
import mineplex.core.antihack.types.*;
|
||||||
@ -13,7 +14,6 @@ import mineplex.core.common.util.UtilPlayer;
|
|||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.core.common.util.UtilTime;
|
import mineplex.core.common.util.UtilTime;
|
||||||
import mineplex.core.portal.Portal;
|
import mineplex.core.portal.Portal;
|
||||||
import mineplex.core.punish.Category;
|
|
||||||
import mineplex.core.punish.Punish;
|
import mineplex.core.punish.Punish;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
@ -22,7 +22,6 @@ import org.bukkit.GameMode;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
@ -303,4 +302,30 @@ public class AntiHack extends MiniPlugin
|
|||||||
for (Detector detector : _detectors)
|
for (Detector detector : _detectors)
|
||||||
detector.Reset(player);
|
detector.Reset(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void cleanupPlayers(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (event.getType() != UpdateType.SLOW)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (Iterator<Entry<Player, Long>> playerIterator = _ignore.entrySet().iterator(); playerIterator.hasNext();)
|
||||||
|
{
|
||||||
|
Player player = playerIterator.next().getKey();
|
||||||
|
|
||||||
|
if (!player.isOnline() || player.isDead() || !player.isValid())
|
||||||
|
{
|
||||||
|
playerIterator.remove();
|
||||||
|
|
||||||
|
_velocityEvent.remove(player);
|
||||||
|
_lastMoveEvent.remove(player);
|
||||||
|
|
||||||
|
_offense.remove(player);
|
||||||
|
_suspicion.remove(player);
|
||||||
|
|
||||||
|
for (Detector detector : _detectors)
|
||||||
|
detector.Reset(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@ package mineplex.core.disguise;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_6_R3.ChunkAddEntityEvent;
|
import net.minecraft.server.v1_6_R3.ChunkAddEntityEvent;
|
||||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
||||||
@ -248,24 +246,15 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void clearOldDisguises(UpdateEvent event)
|
public void clearDisguises()
|
||||||
{
|
{
|
||||||
if (event.getType() != UpdateType.SEC)
|
_spawnPacketMap.clear();
|
||||||
return;
|
_movePacketMap.clear();
|
||||||
|
_moveTempMap.clear();
|
||||||
Iterator<Entry<Integer, DisguiseBase>> spawnPacketMapIterator = _spawnPacketMap.entrySet().iterator();
|
_goingUp.clear();
|
||||||
while (spawnPacketMapIterator.hasNext())
|
_entityDisguiseMap.clear();
|
||||||
{
|
_addTempList.clear();
|
||||||
Entry<Integer, DisguiseBase> entry = spawnPacketMapIterator.next();
|
_delTempList.clear();
|
||||||
|
|
||||||
if (!entry.getValue().GetEntity().isAlive() || !entry.getValue().GetEntity().valid)
|
|
||||||
{
|
|
||||||
_movePacketMap.remove(entry.getValue().GetEntity().id);
|
|
||||||
_moveTempMap.remove(entry.getValue().GetEntity().id);
|
|
||||||
_entityDisguiseMap.remove(entry.getValue().GetEntity().getUniqueID().toString());
|
|
||||||
spawnPacketMapIterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -28,7 +28,7 @@ public class Map extends MiniPlugin
|
|||||||
|
|
||||||
public Map(JavaPlugin plugin)
|
public Map(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super("Map Manager", plugin);
|
super("Map", plugin);
|
||||||
|
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
package mineplex.core.status;
|
package mineplex.core.status;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -44,36 +39,7 @@ public class ServerStatusManager extends MiniPlugin
|
|||||||
|
|
||||||
setupConfigValues();
|
setupConfigValues();
|
||||||
|
|
||||||
String address = "localhost";
|
String address = Bukkit.getServer().getIp().isEmpty() ? "localhost" : Bukkit.getServer().getIp();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
|
|
||||||
|
|
||||||
for (NetworkInterface netint : Collections.list(nets))
|
|
||||||
{
|
|
||||||
if (netint.getDisplayName().equalsIgnoreCase("eth1"))
|
|
||||||
{
|
|
||||||
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
|
|
||||||
for (InetAddress inetAddress : Collections.list(inetAddresses))
|
|
||||||
{
|
|
||||||
if (inetAddress.getHostAddress().contains(":"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
address = inetAddress.getHostAddress();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Address : " + address);
|
|
||||||
|
|
||||||
_name = plugin.getConfig().getString("serverstatus.name");
|
_name = plugin.getConfig().getString("serverstatus.name");
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class ServerStatusRepository
|
|||||||
private static String UPDATE_PLAYER_COUNT_WITH_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ?, lastTimeWithPlayers = now() WHERE id = ?;";
|
private static String UPDATE_PLAYER_COUNT_WITH_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ?, lastTimeWithPlayers = now() WHERE id = ?;";
|
||||||
private static String UPDATE_PLAYER_COUNT_WITHOUT_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ? WHERE id = ?;";
|
private static String UPDATE_PLAYER_COUNT_WITHOUT_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ? WHERE id = ?;";
|
||||||
private static String RETRIEVE_ID = "SELECT id FROM ServerStatus WHERE address = ?;";
|
private static String RETRIEVE_ID = "SELECT id FROM ServerStatus WHERE address = ?;";
|
||||||
private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = ? AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;";
|
private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = ? AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;";
|
||||||
|
|
||||||
private int _id = -1;
|
private int _id = -1;
|
||||||
private boolean _us;
|
private boolean _us;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package mineplex.hub.gadget.gadgets;
|
package mineplex.hub.gadget.gadgets;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -22,6 +23,8 @@ import mineplex.core.common.util.F;
|
|||||||
import mineplex.core.common.util.UtilBlock;
|
import mineplex.core.common.util.UtilBlock;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
|
import mineplex.core.updater.UpdateType;
|
||||||
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
import mineplex.hub.gadget.GadgetManager;
|
import mineplex.hub.gadget.GadgetManager;
|
||||||
import mineplex.hub.gadget.types.ItemGadget;
|
import mineplex.hub.gadget.types.ItemGadget;
|
||||||
|
|
||||||
@ -130,4 +133,19 @@ public class PaintballGun extends ItemGadget
|
|||||||
if (event.getCause() == TeleportCause.ENDER_PEARL)
|
if (event.getCause() == TeleportCause.ENDER_PEARL)
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void cleanupBalls(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (event.getType() != UpdateType.SLOW)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (Iterator<Projectile> ballIterator = _balls.iterator(); ballIterator.hasNext();)
|
||||||
|
{
|
||||||
|
Projectile ball = ballIterator.next();
|
||||||
|
|
||||||
|
if (ball.isDead() || !ball.isValid())
|
||||||
|
ballIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class MountManager extends MiniPlugin
|
|||||||
|
|
||||||
public MountManager(HubManager manager)
|
public MountManager(HubManager manager)
|
||||||
{
|
{
|
||||||
super("Gadget Manager", manager.GetPlugin());
|
super("Mount Manager", manager.GetPlugin());
|
||||||
|
|
||||||
Manager = manager;
|
Manager = manager;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class Tutorial extends MiniPlugin
|
|||||||
|
|
||||||
public Tutorial(HubManager manager, String name, int gems, String task)
|
public Tutorial(HubManager manager, String name, int gems, String task)
|
||||||
{
|
{
|
||||||
super("Hub Tutorial", manager.GetPlugin());
|
super(task, manager.GetPlugin());
|
||||||
|
|
||||||
_name = name;
|
_name = name;
|
||||||
_gems = gems;
|
_gems = gems;
|
||||||
|
@ -11,6 +11,7 @@ public class DynamicServerData
|
|||||||
|
|
||||||
public HashMap<String, Integer> ServerGroupCount = new HashMap<String, Integer>();
|
public HashMap<String, Integer> ServerGroupCount = new HashMap<String, Integer>();
|
||||||
public boolean US;
|
public boolean US;
|
||||||
|
public String PrivateAddress;
|
||||||
|
|
||||||
public void setServerGroupCount(ServerGroupData groupData, int count)
|
public void setServerGroupCount(ServerGroupData groupData, int count)
|
||||||
{
|
{
|
||||||
|
@ -17,23 +17,25 @@ public class Repository
|
|||||||
private String _password = "y2D4atu3Pene2asw";
|
private String _password = "y2D4atu3Pene2asw";
|
||||||
|
|
||||||
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS ServerStatus (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), serverGroup VARCHAR(256), address VARCHAR(256), updated LONG, lastTimeWithPlayers LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));";
|
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS ServerStatus (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), serverGroup VARCHAR(256), address VARCHAR(256), updated LONG, lastTimeWithPlayers LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));";
|
||||||
private static String RETRIEVE_OLD_SERVER_STATUSES = "SELECT ServerStatus.serverName, ServerStatus.address, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) > 10;";
|
private static String RETRIEVE_OLD_SERVER_STATUSES = "SELECT ServerStatus.serverName, ServerStatus.address, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = false AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) > 10;";
|
||||||
|
|
||||||
private static String CREATE_DYNAMIC_TABLE = "CREATE TABLE IF NOT EXISTS DynamicServers (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), address VARCHAR(256), US BOOLEAN NOT NULL DEFAULT 'true', PRIMARY KEY (id));";
|
private static String CREATE_DYNAMIC_TABLE = "CREATE TABLE IF NOT EXISTS DynamicServers (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), address VARCHAR(256), privateAddress VARCHAR(256), US BOOLEAN NOT NULL DEFAULT 'true', PRIMARY KEY (id));";
|
||||||
private static String RETRIEVE_AVAILABLE_SERVERS = "SELECT DynamicServers.serverName, DynamicServers.address, DynamicServers.US, DynamicServers.availableCpu, DynamicServers.availableRam, ServerStatus.serverGroup, COUNT(*) As serverCount FROM DynamicServers LEFT JOIN ServerStatus ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false GROUP BY DynamicServers.address, ServerStatus.serverGroup;";
|
private static String RETRIEVE_AVAILABLE_SERVERS = "SELECT DynamicServers.serverName, DynamicServers.address, DynamicServers.privateAddress, DynamicServers.US, DynamicServers.availableCpu, DynamicServers.availableRam, ServerStatus.serverGroup, COUNT(*) As serverCount FROM DynamicServers LEFT JOIN ServerStatus ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false GROUP BY DynamicServers.address, ServerStatus.serverGroup;";
|
||||||
private static String RETRIEVE_SERVERGROUP_STATUSES = "SELECT ServerStatus.serverName, serverGroup, motd, ServerStatus.address, players, maxPlayers, case when TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.lastTimeWithPlayers)) > 300 then 1 else 0 end as empty FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) <= 10";
|
private static String RETRIEVE_SERVERGROUP_STATUSES = "SELECT ServerStatus.serverName, serverGroup, motd, ServerStatus.address, players, maxPlayers, case when TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.lastTimeWithPlayers)) > 300 then 1 else 0 end as empty FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = false AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) <= 10";
|
||||||
private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable FROM ServerGroups;";
|
private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable FROM ServerGroups;";
|
||||||
private static String DELETE_SERVER_STATUS = "DELETE FROM ServerStatus WHERE address = ? AND serverName = ?;";
|
private static String DELETE_SERVER_STATUS = "DELETE FROM ServerStatus WHERE address = ? AND serverName = ?;";
|
||||||
|
|
||||||
|
public static Connection connection;
|
||||||
|
|
||||||
public void initialize()
|
public void initialize()
|
||||||
{
|
{
|
||||||
Connection connection = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
|
||||||
|
if (connection == null || connection.isClosed())
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
@ -57,29 +59,14 @@ public class Repository
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = null;
|
|
||||||
preparedStatement = null;
|
preparedStatement = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = connection.prepareStatement(CREATE_DYNAMIC_TABLE);
|
preparedStatement = connection.prepareStatement(CREATE_DYNAMIC_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
@ -101,30 +88,18 @@ public class Repository
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ServerStatusData> retrieveOldServerStatuses()
|
public List<ServerStatusData> retrieveOldServerStatuses()
|
||||||
{
|
{
|
||||||
Connection connection = null;
|
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
|
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (connection == null || connection.isClosed())
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
|
preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
|
||||||
@ -175,18 +150,6 @@ public class Repository
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return serverData;
|
return serverData;
|
||||||
@ -194,13 +157,13 @@ public class Repository
|
|||||||
|
|
||||||
public HashMap<String, GroupStatusData> retrieveGroupStatusData()
|
public HashMap<String, GroupStatusData> retrieveGroupStatusData()
|
||||||
{
|
{
|
||||||
Connection connection = null;
|
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
HashMap<String, GroupStatusData> groupData = new HashMap<String, GroupStatusData>();
|
HashMap<String, GroupStatusData> groupData = new HashMap<String, GroupStatusData>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (connection == null || connection.isClosed())
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_SERVERGROUP_STATUSES);
|
preparedStatement = connection.prepareStatement(RETRIEVE_SERVERGROUP_STATUSES);
|
||||||
@ -257,18 +220,6 @@ public class Repository
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupData;
|
return groupData;
|
||||||
@ -276,7 +227,6 @@ public class Repository
|
|||||||
|
|
||||||
public Collection<DynamicServerData> retrieveDynamicServers()
|
public Collection<DynamicServerData> retrieveDynamicServers()
|
||||||
{
|
{
|
||||||
Connection connection = null;
|
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
HashMap<String, DynamicServerData> serverMap = new HashMap<String, DynamicServerData>();
|
HashMap<String, DynamicServerData> serverMap = new HashMap<String, DynamicServerData>();
|
||||||
@ -284,6 +234,7 @@ public class Repository
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (connection == null || connection.isClosed())
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_GROUP_DATA);
|
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_GROUP_DATA);
|
||||||
@ -317,16 +268,17 @@ public class Repository
|
|||||||
|
|
||||||
dynamicServer.Name = resultSet.getString(1);
|
dynamicServer.Name = resultSet.getString(1);
|
||||||
dynamicServer.Address = resultSet.getString(2);
|
dynamicServer.Address = resultSet.getString(2);
|
||||||
dynamicServer.US = resultSet.getBoolean(3);
|
dynamicServer.PrivateAddress = resultSet.getString(3);
|
||||||
dynamicServer.AvailableCPU = resultSet.getInt(4);
|
dynamicServer.US = resultSet.getBoolean(4);
|
||||||
dynamicServer.AvailableRAM = resultSet.getInt(5);
|
dynamicServer.AvailableCPU = resultSet.getInt(5);
|
||||||
|
dynamicServer.AvailableRAM = resultSet.getInt(6);
|
||||||
|
|
||||||
if (!serverMap.containsKey(dynamicServer.Name))
|
if (!serverMap.containsKey(dynamicServer.Name))
|
||||||
serverMap.put(dynamicServer.Name, dynamicServer);
|
serverMap.put(dynamicServer.Name, dynamicServer);
|
||||||
|
|
||||||
String serverGroupName = resultSet.getString(6);
|
String serverGroupName = resultSet.getString(7);
|
||||||
if (serverGroupMap.containsKey(serverGroupName))
|
if (serverGroupMap.containsKey(serverGroupName))
|
||||||
serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(7));
|
serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -358,18 +310,6 @@ public class Repository
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return serverMap.values();
|
return serverMap.values();
|
||||||
@ -377,13 +317,14 @@ public class Repository
|
|||||||
|
|
||||||
public Collection<ServerGroupData> retrieveServerGroups()
|
public Collection<ServerGroupData> retrieveServerGroups()
|
||||||
{
|
{
|
||||||
Connection connection = null;
|
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
HashMap<String, ServerGroupData> serverGroupMap = new HashMap<String, ServerGroupData>();
|
HashMap<String, ServerGroupData> serverGroupMap = new HashMap<String, ServerGroupData>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (connection == null || connection.isClosed())
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_GROUP_DATA);
|
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_GROUP_DATA);
|
||||||
@ -434,18 +375,6 @@ public class Repository
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return serverGroupMap.values();
|
return serverGroupMap.values();
|
||||||
@ -453,11 +382,11 @@ public class Repository
|
|||||||
|
|
||||||
public void removeServerRecord(ServerStatusData serverToKill)
|
public void removeServerRecord(ServerStatusData serverToKill)
|
||||||
{
|
{
|
||||||
Connection connection = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (connection == null || connection.isClosed())
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(DELETE_SERVER_STATUS);
|
preparedStatement = connection.prepareStatement(DELETE_SERVER_STATUS);
|
||||||
@ -482,18 +411,6 @@ public class Repository
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public class ServerMonitor
|
|||||||
{
|
{
|
||||||
System.out.println("----Old Server Status----> " + statusData.Address + ", " + statusData.Name);
|
System.out.println("----Old Server Status----> " + statusData.Address + ", " + statusData.Name);
|
||||||
killServer(statusData);
|
killServer(statusData);
|
||||||
|
//restartServer(statusData);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DynamicServerData> dynamicServers = new ArrayList<DynamicServerData>(_repository.retrieveDynamicServers());
|
List<DynamicServerData> dynamicServers = new ArrayList<DynamicServerData>(_repository.retrieveDynamicServers());
|
||||||
@ -114,7 +115,45 @@ public class ServerMonitor
|
|||||||
return bestServer;
|
return bestServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void killServer(ServerStatusData serverToKill)
|
private static void restartServer(final ServerStatusData serverToKill)
|
||||||
|
{
|
||||||
|
String cmd = "/home/mineplex/restartServer.sh";
|
||||||
|
Process process = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
process = new ProcessBuilder(new String[] {"/bin/sh", cmd, serverToKill.Address, serverToKill.Name}).start();
|
||||||
|
|
||||||
|
synchronized (process)
|
||||||
|
{
|
||||||
|
process.wait(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
String line = reader.readLine();
|
||||||
|
|
||||||
|
while(line != null)
|
||||||
|
{
|
||||||
|
System.out.println(line);
|
||||||
|
line=reader.readLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (process != null)
|
||||||
|
{
|
||||||
|
process.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Sent restart command to " + serverToKill.Address + " for " + serverToKill.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void killServer(final ServerStatusData serverToKill)
|
||||||
{
|
{
|
||||||
String cmd = "/home/mineplex/easyRemoteKillServer.sh";
|
String cmd = "/home/mineplex/easyRemoteKillServer.sh";
|
||||||
Process process = null;
|
Process process = null;
|
||||||
@ -122,7 +161,12 @@ public class ServerMonitor
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
process = new ProcessBuilder(new String[] {"/bin/sh", cmd, serverToKill.Address, serverToKill.Name}).start();
|
process = new ProcessBuilder(new String[] {"/bin/sh", cmd, serverToKill.Address, serverToKill.Name}).start();
|
||||||
|
|
||||||
|
synchronized (process)
|
||||||
|
{
|
||||||
process.wait(1000);
|
process.wait(1000);
|
||||||
|
}
|
||||||
|
|
||||||
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
|
|
||||||
@ -148,15 +192,20 @@ public class ServerMonitor
|
|||||||
System.out.println("Sent kill command to " + serverToKill.Address + " for " + serverToKill.Name);
|
System.out.println("Sent kill command to " + serverToKill.Address + " for " + serverToKill.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startServer(DynamicServerData serverSpace, ServerGroupData serverGroup, int serverNum)
|
private static void startServer(final DynamicServerData serverSpace, final ServerGroupData serverGroup, final int serverNum)
|
||||||
{
|
{
|
||||||
String cmd = "/home/mineplex/easyRemoteStartServer.sh";
|
String cmd = "/home/mineplex/easyRemoteStartServer.sh";
|
||||||
Process process = null;
|
Process process = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
process = new ProcessBuilder(new String[] {"/bin/sh", cmd, serverSpace.Address, serverGroup.ScriptName, serverGroup.Prefix + "-" + serverNum, "1", serverSpace.US ? "us" : "eu"}).start();
|
process = new ProcessBuilder(new String[] {"/bin/sh", cmd, serverSpace.Address, serverSpace.PrivateAddress, serverGroup.ScriptName, serverGroup.Prefix + "-" + serverNum, "1", serverSpace.US ? "us" : "eu"}).start();
|
||||||
process.wait(3000);
|
|
||||||
|
synchronized (process)
|
||||||
|
{
|
||||||
|
process.wait(1000);
|
||||||
|
}
|
||||||
|
|
||||||
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
|
|
||||||
|
@ -507,6 +507,14 @@ public class GameManager implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void disguiseClean(GameStateChangeEvent event)
|
||||||
|
{
|
||||||
|
if (event.GetState() != GameState.Dead)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Manager.GetDisguise().clearDisguises();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
Loading…
Reference in New Issue
Block a user