Added rank pulling on bungee login and the ability to put a cap on network player count.

Removed log message for converted server group.
This commit is contained in:
Jonathan Williams 2015-01-03 23:37:04 -06:00
parent a472404316
commit fc45b80e2b
13 changed files with 607 additions and 3 deletions

View File

@ -228,6 +228,10 @@
<zipfileset src="../Libraries/commons-io-2.4.jar" /> <zipfileset src="../Libraries/commons-io-2.4.jar" />
<zipfileset src="../Libraries/jedis-2.4.2.jar" /> <zipfileset src="../Libraries/jedis-2.4.2.jar" />
<zipfileset src="../Libraries/commons-pool2-2.2.jar" /> <zipfileset src="../Libraries/commons-pool2-2.2.jar" />
<zipfileset src="../Libraries/jooq-3.4.2.jar" />
<zipfileset src="../Libraries/httpclient-4.2.jar" />
<zipfileset src="../Libraries/httpcore-4.2.jar" />
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
</jar> </jar>
<copy file="../bin/Mineplexer.jar" todir="../../Testing/Proxy/plugins"/> <copy file="../bin/Mineplexer.jar" todir="../../Testing/Proxy/plugins"/>
</target> </target>

View File

@ -6,5 +6,7 @@
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/> <classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-io-2.4.jar"/> <classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-io-2.4.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/> <classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -1,5 +1,6 @@
package mineplex.bungee; package mineplex.bungee;
import mineplex.bungee.account.AccountManager;
import mineplex.bungee.lobbyBalancer.LobbyBalancer; import mineplex.bungee.lobbyBalancer.LobbyBalancer;
import mineplex.bungee.motd.MotdManager; import mineplex.bungee.motd.MotdManager;
import mineplex.bungee.playerCount.PlayerCount; import mineplex.bungee.playerCount.PlayerCount;
@ -15,10 +16,11 @@ public class Mineplexer extends Plugin
{ {
new MotdManager(this); new MotdManager(this);
new LobbyBalancer(this); new LobbyBalancer(this);
new PlayerCount(this); PlayerCount playerCount = new PlayerCount(this);
new FileUpdater(this); new FileUpdater(this);
new PlayerStats(this); new PlayerStats(this);
new InternetStatus(this); new InternetStatus(this);
new PlayerTracker(this); new PlayerTracker(this);
new AccountManager(this, playerCount);
} }
} }

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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<String> IpAdddresses = new HashSet<String>();
public boolean Banned;
public String Reason;
public int BlueGems;
public int GreenGems;
public List<Integer> SalesPackageIds;
}

View File

@ -0,0 +1,6 @@
package mineplex.bungee.account;
public interface Callback<T>
{
public void run(T data);
}

View File

@ -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;
}

View File

@ -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> T Execute(Class<T> returnClass)
{
return Execute(returnClass, (Object)null);
}
public <T> 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> T Execute(Class<T> 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 <T> void Execute(Class<T> callbackClass, Callback<T> callback)
{
Execute(callbackClass, callback, (Object)null);
}
public <T> void Execute(Class<T> callbackClass, Callback<T> 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();
}
}

View File

@ -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;
}

View File

@ -0,0 +1,8 @@
package mineplex.bungee.account;
public class RankToken
{
public int RankId;
public String Name;
}

View File

@ -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())); 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;
}
} }

View File

@ -80,7 +80,6 @@ public class RedisServerRepository implements ServerRepository
Integer.parseInt(name); Integer.parseInt(name);
server.setGroup(name); server.setGroup(name);
System.out.println("Changed to server group name : " + server.getGroup());
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {