diff --git a/Plugins/BuildFiles/common.xml b/Plugins/BuildFiles/common.xml index e398625a1..864e72ac3 100644 --- a/Plugins/BuildFiles/common.xml +++ b/Plugins/BuildFiles/common.xml @@ -227,7 +227,11 @@ - + + + + + diff --git a/Plugins/Mineplex.Bungee.Mineplexer/.classpath b/Plugins/Mineplex.Bungee.Mineplexer/.classpath index 03e6db6ae..1dd72efb3 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/.classpath +++ b/Plugins/Mineplex.Bungee.Mineplexer/.classpath @@ -6,5 +6,7 @@ + + diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java index 2a82089f7..9a1526d1c 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/Mineplexer.java @@ -1,5 +1,6 @@ package mineplex.bungee; +import mineplex.bungee.account.AccountManager; import mineplex.bungee.lobbyBalancer.LobbyBalancer; import mineplex.bungee.motd.MotdManager; import mineplex.bungee.playerCount.PlayerCount; @@ -15,10 +16,11 @@ public class Mineplexer extends Plugin { new MotdManager(this); new LobbyBalancer(this); - new PlayerCount(this); + PlayerCount playerCount = new PlayerCount(this); new FileUpdater(this); new PlayerStats(this); new InternetStatus(this); new PlayerTracker(this); + new AccountManager(this, playerCount); } } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountManager.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountManager.java new file mode 100644 index 000000000..cfbee9592 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountManager.java @@ -0,0 +1,71 @@ +package mineplex.bungee.account; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import com.google.gson.Gson; + +import mineplex.bungee.playerCount.PlayerCount; +import net.md_5.bungee.api.event.LoginEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.event.EventHandler; + +public class AccountManager implements Listener, Runnable +{ + private Plugin _plugin; + private PlayerCount _playerCount; + private int _playerCap = -1; + private AccountManagerRepository _repository; + + private Gson _gson = new Gson(); + + public AccountManager(Plugin plugin, PlayerCount playerCount) + { + _plugin = plugin; + _playerCount = playerCount; + + _plugin.getProxy().getPluginManager().registerListener(_plugin, this); + _plugin.getProxy().getScheduler().schedule(_plugin, this, 10L, 10L, TimeUnit.SECONDS); + + _repository = new AccountManagerRepository(); + _repository.initialize(); + _playerCap = _repository.retrievePlayerCap(); + } + + @EventHandler + public void login(LoginEvent event) + { + if (_playerCap == -1 || _playerCount.getTotalPlayers() <= _playerCap) + return; + + String response = getClient(event.getConnection().getName(), event.getConnection().getUniqueId(), event.getConnection().getAddress().toString()); + + ClientToken token = _gson.fromJson(response, ClientToken.class); + + if (token.Rank.equalsIgnoreCase("ALL")) + { + event.setCancelled(true); + event.setCancelReason("§fDue to server issues, we have added a §cplayer limit§f.\n" + + "§fWe hope to have this resolved soon, §nplease be ptient§r.\n" + + "§fPlayers with Ranks can still join the server!\n\n" + + "§fPurchase Ranks at §awww.mineplex.com/shop"); + } + } + + public String getClient(String name, UUID uuid, String ipAddress) + { + LoginToken token = new LoginToken(); + token.Name = name; + token.Uuid = uuid.toString(); + token.IpAddress = ipAddress; + + return new JsonWebCall("http://accounts.mineplex.com/PlayerAccount/Login").ExecuteReturnStream(token); + } + + @Override + public void run() + { + _playerCap = _repository.retrievePlayerCap(); + } +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountManagerRepository.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountManagerRepository.java new file mode 100644 index 000000000..536955204 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountManagerRepository.java @@ -0,0 +1,105 @@ +package mineplex.bungee.account; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class AccountManagerRepository +{ + private Connection _connection = null; + private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; + private String _userName = "root"; + private String _password = "tAbechAk3wR7tuTh"; + + private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS playerCap (id INT NOT NULL AUTO_INCREMENT, playerCap INT, PRIMARY KEY (id));"; + private static String RETRIEVE_PLAYERCAP = "SELECT playerCap FROM playerCap;"; + + public void initialize() + { + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + // Create table + preparedStatement = _connection.prepareStatement(CREATE_TABLE); + preparedStatement.execute(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + System.out.println("Initialized AccountManager."); + } + + public int retrievePlayerCap() + { + ResultSet resultSet = null; + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERCAP); + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) + { + return resultSet.getInt(1); + } + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + + if (resultSet != null) + { + try + { + resultSet.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + return -1; + } +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountToken.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountToken.java new file mode 100644 index 000000000..d410ebfc6 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/AccountToken.java @@ -0,0 +1,24 @@ +package mineplex.bungee.account; + +import java.util.HashSet; +import java.util.List; + + +public class AccountToken +{ + public int AccountId; + public String Name; + public RankToken Rank; + + public int LoginCount; + public long LastLogin; + public long TotalPlayingTime; + public HashSet IpAdddresses = new HashSet(); + + public boolean Banned; + public String Reason; + + public int BlueGems; + public int GreenGems; + public List SalesPackageIds; +} \ No newline at end of file diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/Callback.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/Callback.java new file mode 100644 index 000000000..a2e520ed9 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/Callback.java @@ -0,0 +1,6 @@ +package mineplex.bungee.account; + +public interface Callback +{ + public void run(T data); +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/ClientToken.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/ClientToken.java new file mode 100644 index 000000000..1d7cdcb45 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/ClientToken.java @@ -0,0 +1,14 @@ +package mineplex.bungee.account; + +public class ClientToken +{ + public int AccountId; + public String Name; + public String Rank; + public boolean RankPerm; + public String RankExpire; + public int EconomyBalance; + + public AccountToken AccountToken; + public long LastLogin; +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/JsonWebCall.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/JsonWebCall.java new file mode 100644 index 000000000..664e16ae5 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/JsonWebCall.java @@ -0,0 +1,355 @@ +package mineplex.bungee.account; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Type; + +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.scheme.PlainSocketFactory; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.http.message.BasicHeader; +import org.apache.http.protocol.HTTP; + +import com.google.gson.Gson; + +public class JsonWebCall +{ + private String _url; + private PoolingClientConnectionManager _connectionManager; + + public JsonWebCall(String url) + { + _url = url; + + SchemeRegistry schemeRegistry = new SchemeRegistry(); + schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); + + _connectionManager = new PoolingClientConnectionManager(schemeRegistry); + _connectionManager.setMaxTotal(200); + _connectionManager.setDefaultMaxPerRoute(20); + } + + public String ExecuteReturnStream(Object argument) + { + HttpClient httpClient = new DefaultHttpClient(_connectionManager); + InputStream in = null; + String result = null; + + try + { + HttpResponse response; + + Gson gson = new Gson(); + HttpPost request = new HttpPost(_url); + + if (argument != null) + { + StringEntity params = new StringEntity(gson.toJson(argument)); + params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); + request.setEntity(params); + } + + response = httpClient.execute(request); + + if (response != null) + { + in = response.getEntity().getContent(); + result = convertStreamToString(in); + } + } + catch (Exception ex) + { + System.out.println("Error executing JsonWebCall: \n" + ex.getMessage()); + System.out.println("Result: \n" + result); + + for (StackTraceElement trace : ex.getStackTrace()) + { + System.out.println(trace); + } + } + finally + { + httpClient.getConnectionManager().shutdown(); + + if (in != null) + { + try + { + in.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + return result; + } + + public void Execute() + { + Execute((Object)null); + } + + public void Execute(Object argument) + { + HttpClient httpClient = new DefaultHttpClient(_connectionManager); + InputStream in = null; + + try + { + Gson gson = new Gson(); + HttpPost request = new HttpPost(_url); + + if (argument != null) + { + StringEntity params = new StringEntity(gson.toJson(argument)); + params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); + request.setEntity(params); + } + + httpClient.execute(request); + } + catch (Exception ex) + { + System.out.println("JsonWebCall.Execute() Error:\n" + ex.getMessage()); + + for (StackTraceElement trace : ex.getStackTrace()) + { + System.out.println(trace); + } + } + finally + { + httpClient.getConnectionManager().shutdown(); + + if (in != null) + { + try + { + in.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + } + + public T Execute(Class returnClass) + { + return Execute(returnClass, (Object)null); + } + + public T Execute(Type returnType, Object argument) + { + HttpClient httpClient = new DefaultHttpClient(_connectionManager); + InputStream in = null; + T returnData = null; + String result = null; + + try + { + HttpResponse response; + + Gson gson = new Gson(); + HttpPost request = new HttpPost(_url); + + if (argument != null) + { + StringEntity params = new StringEntity(gson.toJson(argument)); + params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); + request.setEntity(params); + } + + response = httpClient.execute(request); + + if (response != null) + { + in = response.getEntity().getContent(); + + result = convertStreamToString(in); + returnData = new Gson().fromJson(result, returnType); + } + } + catch (Exception ex) + { + System.out.println("Error executing JsonWebCall: \n" + ex.getMessage()); + System.out.println("Result: \n" + result); + + for (StackTraceElement trace : ex.getStackTrace()) + { + System.out.println(trace); + } + } + finally + { + httpClient.getConnectionManager().shutdown(); + + if (in != null) + { + try + { + in.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + return returnData; + } + + public T Execute(Class returnClass, Object argument) + { + HttpClient httpClient = new DefaultHttpClient(_connectionManager); + InputStream in = null; + T returnData = null; + String result = null; + + try + { + HttpResponse response; + + Gson gson = new Gson(); + HttpPost request = new HttpPost(_url); + + if (argument != null) + { + StringEntity params = new StringEntity(gson.toJson(argument)); + params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); + request.setEntity(params); + } + + response = httpClient.execute(request); + + if (response != null) + { + in = response.getEntity().getContent(); + + result = convertStreamToString(in); + returnData = new Gson().fromJson(result, returnClass); + } + } + catch (Exception ex) + { + System.out.println("Error executing JsonWebCall: \n" + ex.getMessage()); + System.out.println("Result: \n" + result); + + for (StackTraceElement trace : ex.getStackTrace()) + { + System.out.println(trace); + } + } + finally + { + httpClient.getConnectionManager().shutdown(); + + if (in != null) + { + try + { + in.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + return returnData; + } + + public void Execute(Class callbackClass, Callback callback) + { + Execute(callbackClass, callback, (Object)null); + } + + public void Execute(Class callbackClass, Callback callback, Object argument) + { + HttpClient httpClient = new DefaultHttpClient(_connectionManager); + InputStream in = null; + String result = null; + + try + { + HttpResponse response; + + Gson gson = new Gson(); + HttpPost request = new HttpPost(_url); + + if (argument != null) + { + StringEntity params = new StringEntity(gson.toJson(argument)); + params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); + request.setEntity(params); + } + + response = httpClient.execute(request); + + if (response != null && callback != null) + { + in = response.getEntity().getContent(); + + result = convertStreamToString(in); + callback.run(new Gson().fromJson(result, callbackClass)); + } + } + catch (Exception ex) + { + System.out.println("Error executing JsonWebCall: \n" + ex.getMessage()); + System.out.println("Result: \n" + result); + } + finally + { + httpClient.getConnectionManager().shutdown(); + + if (in != null) + { + try + { + in.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + } + + protected String convertStreamToString(InputStream is) + { + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + StringBuilder sb = new StringBuilder(); + + String line = null; + try { + while ((line = reader.readLine()) != null) { + sb.append(line + "\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return sb.toString(); + } +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/LoginToken.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/LoginToken.java new file mode 100644 index 000000000..603259383 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/LoginToken.java @@ -0,0 +1,9 @@ +package mineplex.bungee.account; + +public class LoginToken +{ + public String Name; + public String IpAddress = "0.0.0.0"; + public String MacAddress = "00-00-00-00-00-00-00-00"; + public String Uuid; +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/RankToken.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/RankToken.java new file mode 100644 index 000000000..8af4ff6c7 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/account/RankToken.java @@ -0,0 +1,8 @@ +package mineplex.bungee.account; + +public class RankToken +{ + public int RankId; + + public String Name; +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerCount/PlayerCount.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerCount/PlayerCount.java index c6d9331b1..3afa6cf4c 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerCount/PlayerCount.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerCount/PlayerCount.java @@ -47,4 +47,9 @@ public class PlayerCount implements Listener, Runnable event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), new Players(_totalPlayers + 1, _totalPlayers, null), serverPing.getDescription(), serverPing.getFaviconObject())); } + + public int getTotalPlayers() + { + return _totalPlayers; + } } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java index 134b3d0ae..cf0267c36 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java @@ -80,7 +80,6 @@ public class RedisServerRepository implements ServerRepository Integer.parseInt(name); server.setGroup(name); - System.out.println("Changed to server group name : " + server.getGroup()); } catch (NumberFormatException ex) { diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java index 1d65a492c..4b2182bc4 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java @@ -39,6 +39,7 @@ public class ServerMonitor private static Collection _serverGroups = null; private static Map _serverGroupMap = null; private static List _dedicatedServers = null; + private static HashSet _deadServers = new HashSet(); private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); private static Logger _logger = Logger.getLogger("ServerMonitor"); @@ -192,7 +193,7 @@ public class ServerMonitor if (onlineServers.contains(entry.getKey())) iterator.remove(); - else if (System.currentTimeMillis() - entry.getValue().getValue() > 30000) + else if (System.currentTimeMillis() - entry.getValue().getValue() > 35000) { String serverName = entry.getKey(); String serverAddress = entry.getValue().getKey(); @@ -275,11 +276,23 @@ public class ServerMonitor private static void killDeadServers() { + HashSet deadServers = new HashSet(); + deadServers.addAll(_deadServers); + + _deadServers.clear(); for (MinecraftServer deadServer : _repository.getDeadServers()) { - killServer(deadServer.getName(), deadServer.getPublicAddress(), "[KILLED] [DEAD] " + deadServer.getName() + ":" + deadServer.getPublicAddress(), true); - - handleUserServerGroup(_serverGroupMap.get(deadServer.getGroup())); + if (deadServers.contains(deadServer.getName())) + { + killServer(deadServer.getName(), deadServer.getPublicAddress(), "[KILLED] [DEAD] " + deadServer.getName() + ":" + deadServer.getPublicAddress(), true); + + handleUserServerGroup(_serverGroupMap.get(deadServer.getGroup())); + } + else + { + _deadServers.add(deadServer.getName()); + System.out.println("[IMPENDING DEATH] : " + deadServer.getName() + ":" + deadServer.getPublicAddress()); + } } }