Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
d2038670d6
@ -144,6 +144,7 @@
|
||||
<zipfileset src="../Libraries/httpclient-cache-4.2.jar" />
|
||||
<zipfileset src="../Libraries/httpmime-4.2.jar" />
|
||||
<zipfileset src="../Libraries/gson-2.2.1.jar" />
|
||||
<zipfileset src="../Libraries/javax.mail.jar" />
|
||||
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
|
||||
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
||||
</jar>
|
||||
|
BIN
Plugins/Libraries/javax.mail.jar
Normal file
BIN
Plugins/Libraries/javax.mail.jar
Normal file
Binary file not shown.
@ -13,12 +13,14 @@ import mineplex.core.account.event.ClientUnloadEvent;
|
||||
import mineplex.core.account.event.ClientWebResponseEvent;
|
||||
import mineplex.core.account.event.RetrieveClientInformationEvent;
|
||||
import mineplex.core.account.repository.AccountRepository;
|
||||
import mineplex.core.account.repository.MysqlAccountRepository;
|
||||
import mineplex.core.account.repository.token.ClientToken;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.logger.Logger;
|
||||
import mineplex.core.timing.TimingManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
@ -39,6 +41,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
{
|
||||
private JavaPlugin _plugin;
|
||||
private AccountRepository _repository;
|
||||
private MysqlAccountRepository _mysqlRepository;
|
||||
private NautHashMap<String, CoreClient> _clientList;
|
||||
private HashSet<String> _duplicateLoginGlitchPreventionList;
|
||||
|
||||
@ -50,6 +53,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
_plugin = plugin;
|
||||
_repository = new AccountRepository(webServer);
|
||||
_mysqlRepository = new MysqlAccountRepository(plugin);
|
||||
_clientList = new NautHashMap<String, CoreClient>();
|
||||
_duplicateLoginGlitchPreventionList = new HashSet<String>();
|
||||
}
|
||||
@ -118,6 +122,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void AsyncLogin(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
TimingManager.start(event.getName() + " logging in ASYNC.");
|
||||
try
|
||||
{
|
||||
LoadClient(Add(event.getName()), event.getUniqueId(), event.getAddress().getHostAddress());
|
||||
@ -141,6 +146,8 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
event.disallow(Result.KICK_WHITELIST, "You are not whitelisted my friend.");
|
||||
}
|
||||
|
||||
TimingManager.stop(event.getName() + " logging in ASYNC.");
|
||||
}
|
||||
|
||||
private void LoadClient(CoreClient client, UUID uuid, String ipAddress)
|
||||
@ -156,6 +163,8 @@ public class CoreClientManager extends MiniPlugin
|
||||
client.SetAccountId(token.AccountId);
|
||||
client.SetRank(Rank.valueOf(token.Rank));
|
||||
|
||||
_mysqlRepository.login(uuid.toString(), client.GetPlayerName());
|
||||
|
||||
// JSON sql response
|
||||
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response));
|
||||
|
||||
@ -173,10 +182,18 @@ public class CoreClientManager extends MiniPlugin
|
||||
System.out.println("Error running RetrieveClientInformationEvent" + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void LoginTiming(PlayerLoginEvent event)
|
||||
{
|
||||
TimingManager.stop(event.getPlayer().getName() + " logging in SYNC.");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void Login(PlayerLoginEvent event)
|
||||
{
|
||||
TimingManager.start(event.getPlayer().getName() + " logging in SYNC.");
|
||||
|
||||
synchronized(_clientLock)
|
||||
{
|
||||
if (!_clientList.containsKey(event.getPlayer().getName()))
|
||||
|
@ -2,39 +2,30 @@ package mineplex.core.account.repository;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.mysql.RepositoryBase;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
|
||||
public class MysqlAccountRepository extends RepositoryBase
|
||||
{
|
||||
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS Accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), );";
|
||||
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));";
|
||||
private static String ACCOUNT_LOGIN = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now()) ON DUPLICATE KEY UPDATE name=VALUES(name), lastLogin=VALUES(lastLogin);";
|
||||
|
||||
public MysqlAccountRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin);
|
||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||
}
|
||||
|
||||
/*
|
||||
public String GetClient(String name, String ipAddress)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public void SaveRank(Callback<Rank> callback, String name, Rank rank, boolean perm)
|
||||
{
|
||||
RankUpdateToken token = new RankUpdateToken();
|
||||
token.Name = name;
|
||||
token.Rank = rank.toString();
|
||||
token.Perm = perm;
|
||||
|
||||
//new AsyncJsonWebCall(_webAddress + "PlayerAccount/RankUpdate").Execute(Rank.class, callback, token);
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
protected void initialize()
|
||||
{
|
||||
executeQuery(CREATE_ACCOUNT_TABLE);
|
||||
executeUpdate(CREATE_ACCOUNT_TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update() { }
|
||||
|
||||
public void login(String uuid, String name)
|
||||
{
|
||||
executeUpdate(ACCOUNT_LOGIN, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,232 @@
|
||||
package mineplex.core.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import mineplex.core.database.column.Column;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public abstract class RepositoryBase
|
||||
{
|
||||
protected static Object _connectionLock = new Object();
|
||||
|
||||
private Connection _connection = null;
|
||||
|
||||
private String _connectionString;
|
||||
private String _userName;
|
||||
private String _password;
|
||||
|
||||
public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_userName = username;
|
||||
_password = password;
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
initialize();
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract void initialize();
|
||||
|
||||
protected abstract void update();
|
||||
|
||||
protected Connection getConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_connection == null || !_connection.isValid(1))
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return _connection;
|
||||
}
|
||||
|
||||
protected int executeUpdate(String query, Column<?>...columns)
|
||||
{
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
int affectedRows = 0;
|
||||
|
||||
try
|
||||
{
|
||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
|
||||
for (int i=0; i < columns.length; i++)
|
||||
{
|
||||
columns[i].setValue(preparedStatement, i+1);
|
||||
}
|
||||
|
||||
affectedRows = preparedStatement.executeUpdate();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (connection != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return affectedRows;
|
||||
}
|
||||
|
||||
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
|
||||
{
|
||||
ResultSet resultSet = null;
|
||||
|
||||
try
|
||||
{
|
||||
for (int i=0; i < columns.length; i++)
|
||||
{
|
||||
columns[i].setValue(statement, i+1);
|
||||
}
|
||||
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
callable.processResultSet(resultSet);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (resultSet != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
resultSet.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
|
||||
{
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
|
||||
executeQuery(preparedStatement, callable, columns);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (connection != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected int executeUpdate(PreparedStatement preparedStatement, Column<?>...columns)
|
||||
{
|
||||
Connection connection = null;
|
||||
|
||||
int affectedRows = 0;
|
||||
|
||||
try
|
||||
{
|
||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
for (int i=0; i < columns.length; i++)
|
||||
{
|
||||
columns[i].setValue(preparedStatement, i+1);
|
||||
}
|
||||
|
||||
affectedRows = preparedStatement.executeUpdate();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return affectedRows;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package mineplex.core.database;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface ResultSetCallable
|
||||
{
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.stats;
|
||||
package mineplex.core.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
@ -11,7 +11,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.stats.column.Column;
|
||||
import mineplex.core.database.column.Column;
|
||||
import mineplex.core.stats.Row;
|
||||
|
||||
public class Table
|
||||
{
|
@ -1,5 +1,6 @@
|
||||
package mineplex.core.stats.column;
|
||||
package mineplex.core.database.column;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@ -23,5 +24,7 @@ public abstract class Column<Type>
|
||||
|
||||
public abstract Type getValue(ResultSet resultSet) throws SQLException;
|
||||
|
||||
public abstract void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException;
|
||||
|
||||
public abstract Column<Type> clone();
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package mineplex.core.stats.column;
|
||||
package mineplex.core.database.column;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@ -27,6 +28,12 @@ public class ColumnInt extends Column<Integer>
|
||||
{
|
||||
return resultSet.getInt(Name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException
|
||||
{
|
||||
preparedStatement.setInt(columnNumber, Value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnInt clone()
|
@ -1,5 +1,6 @@
|
||||
package mineplex.core.stats.column;
|
||||
package mineplex.core.database.column;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@ -27,6 +28,12 @@ public class ColumnLong extends Column<Long>
|
||||
{
|
||||
return resultSet.getLong(Name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException
|
||||
{
|
||||
preparedStatement.setLong(columnNumber, Value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnLong clone()
|
@ -1,5 +1,6 @@
|
||||
package mineplex.core.stats.column;
|
||||
package mineplex.core.database.column;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@ -30,6 +31,12 @@ public class ColumnVarChar extends Column<String>
|
||||
{
|
||||
return resultSet.getString(Name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException
|
||||
{
|
||||
preparedStatement.setString(columnNumber, Value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnVarChar clone()
|
@ -120,6 +120,10 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
|
||||
if (!_spawnPacketMap.containsKey(entity.getEntityId()))
|
||||
return;
|
||||
|
||||
_spawnPacketMap.remove(entity.getEntityId());
|
||||
_movePacketMap.remove(entity.getEntityId());
|
||||
_moveTempMap.remove(entity.getEntityId());
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (entity == player)
|
||||
@ -130,6 +134,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
|
||||
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
player.hidePlayer((Player)entity);
|
||||
player.showPlayer((Player)entity);
|
||||
}
|
||||
else
|
||||
@ -137,10 +142,6 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
|
||||
entityPlayer.playerConnection.sendPacket(new PacketPlayOutSpawnEntityLiving(((CraftLivingEntity)entity).getHandle()));
|
||||
}
|
||||
}
|
||||
|
||||
_spawnPacketMap.remove(entity.getEntityId());
|
||||
_movePacketMap.remove(entity.getEntityId());
|
||||
_moveTempMap.remove(entity.getEntityId());
|
||||
}
|
||||
|
||||
public void reApplyDisguise(final DisguiseBase disguise)
|
||||
|
@ -1,19 +1,154 @@
|
||||
package mineplex.core.friend;
|
||||
|
||||
import net.minecraft.server.v1_7_R3.Packet;
|
||||
import net.minecraft.server.v1_7_R3.PacketPlayOutPlayerInfo;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.account.event.RetrieveClientInformationEvent;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.friend.command.AddFriend;
|
||||
import mineplex.core.friend.command.DeleteFriend;
|
||||
import mineplex.core.friend.data.FriendData;
|
||||
import mineplex.core.friend.data.FriendRepository;
|
||||
import mineplex.core.friend.ui.FriendTabList;
|
||||
import mineplex.core.packethandler.IPacketRunnable;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.packethandler.PacketVerifier;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class FriendManager extends MiniPlugin
|
||||
public class FriendManager extends MiniClientPlugin<FriendData> implements IPacketRunnable
|
||||
{
|
||||
private FriendRepository _repository;
|
||||
|
||||
public FriendManager(JavaPlugin plugin)
|
||||
private NautHashMap<Player, FriendTabList> _playerTabMap;
|
||||
private boolean _sendingPackets = false;
|
||||
|
||||
public FriendManager(JavaPlugin plugin, PacketHandler packetHandler)
|
||||
{
|
||||
super("Friends", plugin);
|
||||
|
||||
_repository = new FriendRepository();
|
||||
_repository.initialize();
|
||||
_repository = new FriendRepository(plugin);
|
||||
_playerTabMap = new NautHashMap<Player, FriendTabList>();
|
||||
|
||||
packetHandler.AddPacketRunnable(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void AddCommands()
|
||||
{
|
||||
AddCommand(new AddFriend(this));
|
||||
AddCommand(new DeleteFriend(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FriendData AddPlayer(String player)
|
||||
{
|
||||
return new FriendData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadClientInformation(RetrieveClientInformationEvent event)
|
||||
{
|
||||
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateTabLists(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
return;
|
||||
|
||||
_sendingPackets = true;
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (!_playerTabMap.containsKey(player) || !_playerTabMap.get(player).shouldUpdate())
|
||||
continue;
|
||||
|
||||
_playerTabMap.get(player).refreshForPlayer(player);
|
||||
}
|
||||
_sendingPackets = false;
|
||||
}
|
||||
|
||||
public void updateFriends(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SLOW)
|
||||
return;
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
final NautHashMap<String, FriendData> newData = _repository.getFriendsForAll(Bukkit.getOnlinePlayers());
|
||||
|
||||
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
for (Player player : _playerTabMap.keySet())
|
||||
{
|
||||
if (newData.containsKey(player.getName()))
|
||||
{
|
||||
_playerTabMap.get(player).updateFriends(newData.get(player.getName()).Friends);
|
||||
Get(player).Friends = newData.get(player.getName()).Friends;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void addFriendTab(PlayerJoinEvent event)
|
||||
{
|
||||
_playerTabMap.put(event.getPlayer(), new FriendTabList(Get(event.getPlayer().getName()).Friends));
|
||||
_playerTabMap.get(event.getPlayer()).refreshForPlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void removeFriendTab(PlayerQuitEvent event)
|
||||
{
|
||||
_playerTabMap.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(Packet packet, Player owner, PacketVerifier packetList)
|
||||
{
|
||||
if (packet instanceof PacketPlayOutPlayerInfo)
|
||||
{
|
||||
return _sendingPackets;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addFriend(final Player caller, final String name)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_repository.addFriend(caller.getUniqueId().toString(), name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void removeFriend(final Player caller, final String name)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_repository.removeFriend(caller.getUniqueId().toString(), name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
package mineplex.core.friend;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import mineplex.core.friend.data.FriendStatus;
|
||||
|
||||
public class FriendSorter implements Comparator<FriendStatus>
|
||||
{
|
||||
public int compare(FriendStatus a, FriendStatus b)
|
||||
{
|
||||
if (a.Online && !b.Online)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (b.Online && !a.Online)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If online we sort by mutual
|
||||
if (a.Online && b.Online)
|
||||
{
|
||||
if (a.Mutual && !b.Mutual)
|
||||
return -1;
|
||||
else if (b.Mutual && !a.Mutual)
|
||||
return 1;
|
||||
|
||||
if (a.Name.compareTo(b.Name) > 0)
|
||||
return -1;
|
||||
else if (b.Name.compareTo(a.Name) > 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (a.LastSeenOnline < b.LastSeenOnline)
|
||||
return -1;
|
||||
|
||||
if (b.LastSeenOnline < a.LastSeenOnline)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package mineplex.core.friend.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
|
||||
public class AddFriend extends CommandBase<FriendManager>
|
||||
{
|
||||
public AddFriend(FriendManager plugin)
|
||||
{
|
||||
super(plugin, Rank.ALL, "friend");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(final Player caller, final String[] args)
|
||||
{
|
||||
if (args == null)
|
||||
F.main(Plugin.GetName(), "You need to include a player's name.");
|
||||
else
|
||||
{
|
||||
CommandCenter.GetClientManager().checkPlayerName(caller, args[0], new Callback<Boolean>()
|
||||
{
|
||||
public void run(Boolean result)
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
Plugin.addFriend(caller, args[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package mineplex.core.friend.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
|
||||
public class DeleteFriend extends CommandBase<FriendManager>
|
||||
{
|
||||
public DeleteFriend(FriendManager plugin)
|
||||
{
|
||||
super(plugin, Rank.ALL, "unfriend");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(final Player caller, final String[] args)
|
||||
{
|
||||
if (args == null)
|
||||
F.main(Plugin.GetName(), "You need to include a player's name.");
|
||||
else
|
||||
{
|
||||
CommandCenter.GetClientManager().checkPlayerName(caller, args[0], new Callback<Boolean>()
|
||||
{
|
||||
public void run(Boolean result)
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
Plugin.removeFriend(caller, args[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package mineplex.core.friend.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FriendData
|
||||
{
|
||||
public List<FriendStatus> Friends = new ArrayList<FriendStatus>();
|
||||
}
|
@ -1,33 +1,115 @@
|
||||
package mineplex.core.friend.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FriendRepository
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
|
||||
public class FriendRepository extends RepositoryBase
|
||||
{
|
||||
public void initialize()
|
||||
private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), mutual BOOL, PRIMARY KEY (id), INDEX uuidTargetIndex (uuidTarget));";
|
||||
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, mutual FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource IN ";
|
||||
private static String RETRIEVE_FRIEND_RECORDS = "SELECT tA.Name, mutual, serverName, tA.lastLogin FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = ?;";
|
||||
private static String ADD_FRIEND_RECORD = "INSERT INTO accountFriend (uuidSource, uuidTarget) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.uuid = ?;";
|
||||
private static String DELETE_FRIEND_RECORD = "DELETE aF FROM accountFriend AS aF INNER JOIN accounts ON accounts.name = ? WHERE uuidSource = ? AND uuidTarget = accounts.uuid;";
|
||||
|
||||
public FriendRepository(JavaPlugin plugin)
|
||||
{
|
||||
|
||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||
}
|
||||
|
||||
public boolean addFriend(String name)
|
||||
@Override
|
||||
protected void initialize()
|
||||
{
|
||||
executeUpdate(CREATE_FRIEND_TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update()
|
||||
{
|
||||
boolean success = true;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public boolean removeFriend(String name)
|
||||
public boolean addFriend(String uuid, String name)
|
||||
{
|
||||
boolean success = true;
|
||||
|
||||
return success;
|
||||
return executeUpdate(ADD_FRIEND_RECORD, new ColumnVarChar("name", 40, name), new ColumnVarChar("uuid", 100, uuid)) > 0;
|
||||
}
|
||||
|
||||
public List<FriendStatus> getFriends(String uuid)
|
||||
public boolean removeFriend(String uuid, String name)
|
||||
{
|
||||
List<FriendStatus> friends = new ArrayList<FriendStatus>();
|
||||
return executeUpdate(DELETE_FRIEND_RECORD, new ColumnVarChar("name", 40, name), new ColumnVarChar("uuid", 100, uuid)) > 0;
|
||||
}
|
||||
|
||||
public NautHashMap<String, FriendData> getFriendsForAll(Player...players)
|
||||
{
|
||||
final NautHashMap<String, FriendData> friends = new NautHashMap<String, FriendData>();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(RETRIEVE_MULTIPLE_FRIEND_RECORDS + "(");
|
||||
|
||||
for (Player player : players)
|
||||
{
|
||||
stringBuilder.append("'" + player.getUniqueId() + "', ");
|
||||
}
|
||||
|
||||
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
|
||||
stringBuilder.append(");");
|
||||
|
||||
executeQuery(stringBuilder.toString(), new ResultSetCallable()
|
||||
{
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while (resultSet.next())
|
||||
{
|
||||
FriendStatus friend = new FriendStatus();
|
||||
|
||||
String uuidSource = resultSet.getString(1);
|
||||
friend.Name = resultSet.getString(2);
|
||||
friend.Mutual = resultSet.getBoolean(3);
|
||||
friend.ServerName = resultSet.getString(4);
|
||||
friend.LastSeenOnline = resultSet.getLong(5);
|
||||
|
||||
if (!friends.containsKey(uuidSource))
|
||||
friends.put(uuidSource, new FriendData());
|
||||
|
||||
friends.get(uuidSource).Friends.add(friend);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return friends;
|
||||
}
|
||||
|
||||
public FriendData loadClientInformation(final UUID uniqueId)
|
||||
{
|
||||
final FriendData friendData = new FriendData();
|
||||
|
||||
executeQuery(RETRIEVE_FRIEND_RECORDS, new ResultSetCallable()
|
||||
{
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
while (resultSet.next())
|
||||
{
|
||||
FriendStatus friend = new FriendStatus();
|
||||
|
||||
friend.Name = resultSet.getString(1);
|
||||
friend.Mutual = resultSet.getBoolean(2);
|
||||
friend.ServerName = resultSet.getString(3);
|
||||
friend.LastSeenOnline = resultSet.getLong(4);
|
||||
|
||||
System.out.println("Adding friend " + friend.Name + " for UUID " + uniqueId.toString());
|
||||
|
||||
friendData.Friends.add(friend);
|
||||
}
|
||||
}
|
||||
}, new ColumnVarChar("uuidSource", 100, uniqueId.toString()));
|
||||
|
||||
return friendData;
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,7 @@ public class FriendStatus
|
||||
{
|
||||
public String Name;
|
||||
public String ServerName;
|
||||
public boolean Online;
|
||||
public long LastSeenOnline;
|
||||
public boolean Mutual;
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
package mineplex.core.friend.ui;
|
||||
|
||||
public class FriendPage
|
||||
{
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package mineplex.core.friend.ui;
|
||||
|
||||
public class FriendShop
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package mineplex.core.friend.ui;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import mineplex.core.friend.FriendSorter;
|
||||
import mineplex.core.friend.data.FriendStatus;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class FriendTabList extends TabList
|
||||
{
|
||||
private static FriendSorter _friendSorter = new FriendSorter();
|
||||
|
||||
public FriendTabList(List<FriendStatus> friends)
|
||||
{
|
||||
super();
|
||||
|
||||
set(0, 0, ChatColor.GOLD + " Name");
|
||||
set(1, 0, ChatColor.GOLD + " Location");
|
||||
set(2, 0, ChatColor.GOLD + " Status");
|
||||
|
||||
updateFriends(friends);
|
||||
|
||||
System.out.println("created friend tablist with " + friends.size() + " friends");
|
||||
}
|
||||
|
||||
public void updateFriends(List<FriendStatus> friends)
|
||||
{
|
||||
Collections.sort(friends, _friendSorter);
|
||||
|
||||
int row = 1;
|
||||
for (int i = 0; i < 20 && i < friends.size(); i++)
|
||||
{
|
||||
FriendStatus status = friends.get(i);
|
||||
|
||||
set(0, row, (status.Mutual ? ChatColor.GREEN : ChatColor.YELLOW) + status.Name);
|
||||
set(1, row, status.Mutual ? ChatColor.GREEN + status.ServerName : ChatColor.YELLOW + "Unknown");
|
||||
set(2, row, (status.Mutual ? ChatColor.GREEN : ChatColor.YELLOW) + (status.Online ? "Online" : UtilTime.convert(status.LastSeenOnline, 2, TimeUnit.MINUTES) + ""));
|
||||
System.out.println("Added friend " + status.Name + " to tablist");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
package mineplex.core.friend.ui;
|
||||
|
||||
public class InvitesPage
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package mineplex.core.friend.ui;
|
||||
|
||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R3.PacketPlayOutPlayerInfo;
|
||||
|
||||
public class LineTracker
|
||||
{
|
||||
private String _line = null;
|
||||
private String _oldLine = null;
|
||||
private PacketPlayOutPlayerInfo _clearOldPacket;
|
||||
private PacketPlayOutPlayerInfo _addNewPacket;
|
||||
private PacketPlayOutPlayerInfo _clearNewPacket;
|
||||
|
||||
public LineTracker(String line)
|
||||
{
|
||||
setLine(line);
|
||||
}
|
||||
|
||||
public boolean setLine(String s)
|
||||
{
|
||||
if (s != null && s.length() > 16)
|
||||
s = s.substring(0, 16);
|
||||
|
||||
if (_line != null && _line.compareTo(s) == 0)
|
||||
return false;
|
||||
|
||||
_oldLine = _line;
|
||||
_line = s;
|
||||
|
||||
if (_oldLine != null)
|
||||
{
|
||||
_clearOldPacket = new PacketPlayOutPlayerInfo(_oldLine, false, 0);
|
||||
}
|
||||
|
||||
if (_line != null)
|
||||
{
|
||||
_addNewPacket = new PacketPlayOutPlayerInfo(_line, true, 0);
|
||||
_clearNewPacket = new PacketPlayOutPlayerInfo(_line, false, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void displayLineToPlayer(EntityPlayer entityPlayer)
|
||||
{
|
||||
if (_oldLine != null)
|
||||
{
|
||||
entityPlayer.playerConnection.sendPacket(_clearOldPacket);
|
||||
}
|
||||
|
||||
if (_line != null)
|
||||
{
|
||||
entityPlayer.playerConnection.sendPacket(_addNewPacket);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLineForPlayer(EntityPlayer entityPlayer)
|
||||
{
|
||||
if (_line != null)
|
||||
{
|
||||
entityPlayer.playerConnection.sendPacket(_clearNewPacket);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearOldLine()
|
||||
{
|
||||
_oldLine = null;
|
||||
}
|
||||
}
|
113
Plugins/Mineplex.Core/src/mineplex/core/friend/ui/TabList.java
Normal file
113
Plugins/Mineplex.Core/src/mineplex/core/friend/ui/TabList.java
Normal file
@ -0,0 +1,113 @@
|
||||
package mineplex.core.friend.ui;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
|
||||
public class TabList implements Listener
|
||||
{
|
||||
private static NautHashMap<Integer, String> _invisibleHolders = new NautHashMap<Integer, String>();
|
||||
|
||||
private NautHashMap<Integer, LineTracker> _tabSlots = new NautHashMap<Integer, LineTracker>();
|
||||
private HashSet<Integer> _updatedSlots = new HashSet<Integer>();
|
||||
|
||||
private boolean _update;
|
||||
|
||||
static {
|
||||
String spaces = "";
|
||||
|
||||
for (int i=0; i < 60; i++)
|
||||
{
|
||||
int markerSymbol = i / 15;
|
||||
String symbol = null;
|
||||
|
||||
if (i % 15 == 0)
|
||||
spaces = "";
|
||||
else
|
||||
spaces += " ";
|
||||
|
||||
if (markerSymbol == 0)
|
||||
{
|
||||
symbol = ChatColor.GREEN + "";
|
||||
}
|
||||
else if (markerSymbol == 1)
|
||||
{
|
||||
symbol = ChatColor.RED + "";
|
||||
}
|
||||
else if (markerSymbol == 2)
|
||||
{
|
||||
symbol = ChatColor.BLUE + "";
|
||||
}
|
||||
else if (markerSymbol == 3)
|
||||
{
|
||||
symbol = ChatColor.BLACK + "";
|
||||
}
|
||||
|
||||
_invisibleHolders.put(i, symbol + spaces);
|
||||
}
|
||||
}
|
||||
|
||||
public TabList()
|
||||
{
|
||||
for (Integer i=0; i < 60; i++)
|
||||
{
|
||||
_tabSlots.put(i, new LineTracker(_invisibleHolders.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int column, int row, String lineContent)
|
||||
{
|
||||
int index = row * 3 + column;
|
||||
|
||||
if (index >= 60)
|
||||
return;
|
||||
|
||||
if (lineContent == null || lineContent.isEmpty())
|
||||
lineContent = _invisibleHolders.get(index);
|
||||
|
||||
if (_tabSlots.get(index).setLine(lineContent))
|
||||
{
|
||||
_updatedSlots.add(index);
|
||||
_update = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshForPlayer(Player player)
|
||||
{
|
||||
EntityPlayer entityPlayer = ((CraftPlayer)player).getHandle();
|
||||
|
||||
int indexChanged = 60;
|
||||
|
||||
for (int i=0; i < 60; i++)
|
||||
{
|
||||
if (indexChanged == 60 && _updatedSlots.contains(i))
|
||||
{
|
||||
indexChanged = i;
|
||||
}
|
||||
else if (indexChanged != 60 && !_updatedSlots.contains(i))
|
||||
{
|
||||
_tabSlots.get(i).removeLineForPlayer(entityPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=indexChanged; i < 60; i++)
|
||||
{
|
||||
_tabSlots.get(i).displayLineToPlayer(entityPlayer);
|
||||
}
|
||||
|
||||
_update = false;
|
||||
_updatedSlots.clear();
|
||||
}
|
||||
|
||||
public boolean shouldUpdate()
|
||||
{
|
||||
return _update;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package mineplex.core.mysql;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AccountPreferenceRepository extends RepositoryBase
|
||||
{
|
||||
private static String CREATE_ACCOUNT_PREFERENCE_TABLE = "CREATE TABLE IF NOT EXISTS AccountPreferences (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id));";
|
||||
|
||||
public AccountPreferenceRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize()
|
||||
{
|
||||
executeQuery(CREATE_ACCOUNT_PREFERENCE_TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update() { }
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package mineplex.core.mysql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public abstract class RepositoryBase
|
||||
{
|
||||
private String _connectionString;
|
||||
private String _userName;
|
||||
private String _password;
|
||||
|
||||
public RepositoryBase(JavaPlugin plugin)
|
||||
{
|
||||
_connectionString = plugin.getConfig().getString("serverstatus.connectionurl");
|
||||
_userName = plugin.getConfig().getString("serverstatus.username");
|
||||
_password = plugin.getConfig().getString("serverstatus.password");
|
||||
|
||||
initialize();
|
||||
update();
|
||||
}
|
||||
|
||||
protected abstract void initialize();
|
||||
|
||||
protected abstract void update();
|
||||
|
||||
protected Connection getConnection() throws SQLException
|
||||
{
|
||||
return DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
|
||||
protected int executeQuery(String query)
|
||||
{
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
int affectedRows = 0;
|
||||
|
||||
try
|
||||
{
|
||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
affectedRows = preparedStatement.executeUpdate();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (connection != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return affectedRows;
|
||||
}
|
||||
|
||||
protected int executeStatement(PreparedStatement preparedStatement)
|
||||
{
|
||||
Connection connection = null;
|
||||
|
||||
int affectedRows = 0;
|
||||
|
||||
try
|
||||
{
|
||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
affectedRows = preparedStatement.executeUpdate();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return affectedRows;
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ import mineplex.core.status.ServerStatusData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException;
|
||||
|
||||
public class PortalRepository
|
||||
{
|
||||
private static Object _connectionLock = new Object();
|
||||
@ -257,6 +259,10 @@ public class PortalRepository
|
||||
serverData.add(serverStatusData);
|
||||
}
|
||||
}
|
||||
catch (CommunicationsException exception)
|
||||
{
|
||||
return doesServerExist(serverName);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
|
@ -200,8 +200,6 @@ public class Punish extends MiniPlugin
|
||||
|
||||
long timeDifference = System.currentTimeMillis() - token.Time;
|
||||
|
||||
System.out.println("TimeDifference : " + timeDifference);
|
||||
|
||||
for (PunishmentToken punishment : token.Punishments)
|
||||
{
|
||||
client.AddPunishment(Category.valueOf(punishment.Category), new Punishment(punishment.PunishmentId, PunishmentSentence.valueOf(punishment.Sentence), Category.valueOf(punishment.Category), punishment.Reason, punishment.Admin, punishment.Duration, punishment.Severity, punishment.Time + timeDifference, punishment.Active, punishment.Removed, punishment.RemoveAdmin, punishment.RemoveReason));
|
||||
|
@ -1,8 +0,0 @@
|
||||
package mineplex.core.server;
|
||||
|
||||
import mineplex.core.common.util.Callback;
|
||||
|
||||
public interface IPurchaseRepository
|
||||
{
|
||||
void PurchaseSalesPackage(Callback<String> callback, String name, boolean usingCredits, int salesPackageId);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package mineplex.core.server;
|
||||
|
||||
public class Server
|
||||
{
|
||||
public String Address;
|
||||
public int Port;
|
||||
}
|
@ -1,212 +0,0 @@
|
||||
package mineplex.core.server;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
||||
|
||||
import mineplex.core.server.packet.Packet;
|
||||
import mineplex.core.server.remotecall.JsonWebCall;
|
||||
|
||||
public class ServerBroadcaster extends Thread
|
||||
{
|
||||
private static Object _queueLock = new Object();
|
||||
private static Object _serverMapLock = new Object();
|
||||
|
||||
private HashSet<String> _serverMap = new HashSet<String>();
|
||||
private List<Packet> _queue = new ArrayList<Packet>();
|
||||
|
||||
private String _webAddress;
|
||||
private boolean _running = true;
|
||||
private boolean _retrievingServers = false;
|
||||
|
||||
private long _updateInterval = 15000;
|
||||
private long _lastUpdate;
|
||||
|
||||
private boolean _debug = false;
|
||||
|
||||
public ServerBroadcaster(String webAddress)
|
||||
{
|
||||
_webAddress = webAddress;
|
||||
}
|
||||
|
||||
public void QueuePacket(Packet packet)
|
||||
{
|
||||
synchronized(_queueLock)
|
||||
{
|
||||
_queue.add(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (_running)
|
||||
{
|
||||
if (!HasPackets() || !HasServers())
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(25);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() - _lastUpdate > _updateInterval)
|
||||
{
|
||||
RetrieveActiveServers();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Packet packet = null;
|
||||
|
||||
synchronized(_queueLock)
|
||||
{
|
||||
packet = _queue.remove(0);
|
||||
}
|
||||
|
||||
synchronized(_serverMapLock)
|
||||
{
|
||||
for (String server : _serverMap)
|
||||
{
|
||||
Socket socket = null;
|
||||
DataOutputStream dataOutput = null;
|
||||
|
||||
try
|
||||
{
|
||||
socket = new Socket(server.split(":")[0], Integer.parseInt(server.split(":")[1]));
|
||||
dataOutput = new DataOutputStream(socket.getOutputStream());
|
||||
|
||||
packet.Write(dataOutput);
|
||||
dataOutput.flush();
|
||||
|
||||
if (_debug)
|
||||
System.out.println("Sent packet to : " + socket.getInetAddress().getHostAddress() + ":" + socket.getPort());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("ServerTalker.run Exception(" + server + ") : " + ex.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dataOutput != null)
|
||||
dataOutput.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (socket != null)
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean HasPackets()
|
||||
{
|
||||
synchronized(_queueLock)
|
||||
{
|
||||
return _queue.size() != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean HasServers()
|
||||
{
|
||||
synchronized(_serverMapLock)
|
||||
{
|
||||
return _serverMap.size() != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintPackets()
|
||||
{
|
||||
System.out.println("Listing Packets:");
|
||||
|
||||
synchronized(_queueLock)
|
||||
{
|
||||
if (_queue.isEmpty())
|
||||
{
|
||||
System.out.println("Packet queue empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Packet packet : _queue)
|
||||
{
|
||||
System.out.println(packet.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintServers()
|
||||
{
|
||||
System.out.println("Listing Servers:");
|
||||
|
||||
if (_retrievingServers)
|
||||
{
|
||||
System.out.println("Retrieving servers. Please check again in a few seconds.");
|
||||
}
|
||||
|
||||
synchronized(_serverMapLock)
|
||||
{
|
||||
if (_serverMap.isEmpty())
|
||||
{
|
||||
System.out.println("Server list empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String server : _serverMap)
|
||||
{
|
||||
System.out.println(server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RetrieveActiveServers()
|
||||
{
|
||||
if (_debug)
|
||||
System.out.println("Updating servers...");
|
||||
|
||||
List<String> servers = new JsonWebCall(_webAddress + "Servers/GetServers").Execute(new TypeToken<List<String>>(){}.getType(), null);
|
||||
|
||||
synchronized(_serverMapLock)
|
||||
{
|
||||
_serverMap.clear();
|
||||
|
||||
if (servers.size() > 0)
|
||||
{
|
||||
for (String server : servers)
|
||||
{
|
||||
_serverMap.add(server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("No servers registered at '" + _webAddress + "'!");
|
||||
}
|
||||
}
|
||||
|
||||
_lastUpdate = System.currentTimeMillis();
|
||||
}
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
package mineplex.core.server;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
import mineplex.core.server.packet.IPacketHandler;
|
||||
import mineplex.core.server.packet.PacketType;
|
||||
import mineplex.core.server.remotecall.JsonWebCall;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public class ServerListener extends Thread
|
||||
{
|
||||
private IPacketHandler _packetHandler;
|
||||
private final String _host;
|
||||
private final int _port;
|
||||
|
||||
private String _webServer;
|
||||
|
||||
private ServerSocket server;
|
||||
|
||||
private boolean running = true;
|
||||
|
||||
public ServerListener(IPacketHandler packetHandler, String webserver, String host, int port)
|
||||
{
|
||||
_packetHandler = packetHandler;
|
||||
_webServer = webserver;
|
||||
|
||||
_host = host;
|
||||
_port = port;
|
||||
|
||||
Initialize();
|
||||
|
||||
System.out.println("Initialized ServerListener");
|
||||
|
||||
new JsonWebCall(_webServer + "Servers/RegisterServer").Execute(host + ":" + port);
|
||||
|
||||
System.out.println("Finished with constructor");
|
||||
}
|
||||
|
||||
public ServerListener(String webserver, String host, int port)
|
||||
{
|
||||
this(null, webserver, host, port);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
server = new ServerSocket();
|
||||
server.bind(new InetSocketAddress(_host, _port));
|
||||
System.out.println("Listening to " + _host + ":" + _port);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
running = false;
|
||||
|
||||
if (server == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
server.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("ServerListener.Shutdown Exception : " + ex.getMessage());
|
||||
}
|
||||
|
||||
new JsonWebCall(_webServer + "Servers/RemoveServer").Execute(_host + ":" + _port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (running)
|
||||
{
|
||||
Socket socket = null;
|
||||
DataInputStream dataInput = null;
|
||||
|
||||
try
|
||||
{
|
||||
socket = server.accept();
|
||||
socket.setSoTimeout(5000);
|
||||
dataInput = new DataInputStream(socket.getInputStream());
|
||||
|
||||
if (_packetHandler != null)
|
||||
{
|
||||
_packetHandler.HandlePacketEvent(PacketType.GetPacketEventById(dataInput.readShort(), dataInput), socket);
|
||||
}
|
||||
else
|
||||
{
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
if (pluginManager != null)
|
||||
Bukkit.getPluginManager().callEvent(PacketType.GetPacketEventById(dataInput.readShort(), dataInput));
|
||||
}
|
||||
System.out.println("received packet");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("ServerListener.run Exception : " + ex.getMessage());
|
||||
try
|
||||
{
|
||||
throw ex;
|
||||
} catch (Exception e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dataInput != null)
|
||||
dataInput.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (socket != null)
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
package mineplex.core.server;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mineplex.core.server.packet.Packet;
|
||||
|
||||
public class ServerTalker extends Thread
|
||||
{
|
||||
private static Object _queueLock = new Object();
|
||||
|
||||
private List<Packet> _queue = new ArrayList<Packet>();
|
||||
|
||||
private String _serverAddress;
|
||||
private boolean _running = true;
|
||||
|
||||
private boolean _debug = false;
|
||||
|
||||
public ServerTalker(String serverAddress)
|
||||
{
|
||||
_serverAddress = serverAddress;
|
||||
}
|
||||
|
||||
public void QueuePacket(Packet packet)
|
||||
{
|
||||
synchronized(_queueLock)
|
||||
{
|
||||
_queue.add(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (_running)
|
||||
{
|
||||
if (!HasPackets())
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(25);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Packet packet = null;
|
||||
|
||||
synchronized(_queueLock)
|
||||
{
|
||||
packet = _queue.remove(0);
|
||||
}
|
||||
|
||||
Socket socket = null;
|
||||
DataOutputStream dataOutput = null;
|
||||
|
||||
try
|
||||
{
|
||||
socket = new Socket(_serverAddress.split(":")[0], Integer.parseInt(_serverAddress.split(":")[1]));
|
||||
dataOutput = new DataOutputStream(socket.getOutputStream());
|
||||
|
||||
packet.Write(dataOutput);
|
||||
dataOutput.flush();
|
||||
|
||||
if (_debug)
|
||||
System.out.println("Sent packet to : " + socket.getInetAddress().getHostAddress() + ":" + socket.getPort());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("ServerTalker.run Exception(" + _serverAddress + ") : " + ex.getMessage());
|
||||
_queue.add(packet);
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(15000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dataOutput != null)
|
||||
dataOutput.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (socket != null)
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean HasPackets()
|
||||
{
|
||||
synchronized(_queueLock)
|
||||
{
|
||||
return _queue.size() != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintPackets()
|
||||
{
|
||||
System.out.println("Listing Packets:");
|
||||
|
||||
synchronized(_queueLock)
|
||||
{
|
||||
if (_queue.isEmpty())
|
||||
{
|
||||
System.out.println("Packet queue empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Packet packet : _queue)
|
||||
{
|
||||
System.out.println(packet.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package mineplex.core.server.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class GameReadyEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private List<String> _players;
|
||||
|
||||
public GameReadyEvent(List<String> players)
|
||||
{
|
||||
_players = players;
|
||||
}
|
||||
|
||||
public List<String> GetPlayers()
|
||||
{
|
||||
return _players;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package mineplex.core.server.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class PlayerGameAssignmentEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String _playerName;
|
||||
|
||||
public PlayerGameAssignmentEvent(String playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public String GetPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package mineplex.core.server.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class PlayerGameRequestEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String _playerName;
|
||||
|
||||
public PlayerGameRequestEvent(String playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public String GetPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package mineplex.core.server.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class PlayerServerAssignmentEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String _playerName;
|
||||
private String _serverName;
|
||||
|
||||
public PlayerServerAssignmentEvent(String playerName, String serverName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
_serverName = serverName;
|
||||
}
|
||||
|
||||
public String GetPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
public String GetServerName()
|
||||
{
|
||||
return _serverName;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package mineplex.core.server.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class PlayerVoteEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String _playerName;
|
||||
private int _pointsReceived;
|
||||
|
||||
public PlayerVoteEvent(String playerName, int pointsReceived)
|
||||
{
|
||||
_playerName = playerName;
|
||||
_pointsReceived = pointsReceived;
|
||||
}
|
||||
|
||||
public String GetPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
public int GetPointsReceived()
|
||||
{
|
||||
return _pointsReceived;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package mineplex.core.server.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class ServerReadyEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String _serverPath;
|
||||
|
||||
public ServerReadyEvent(String serverName)
|
||||
{
|
||||
_serverPath = serverName;
|
||||
}
|
||||
|
||||
public String GetServerPath()
|
||||
{
|
||||
return _serverPath;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mineplex.core.server.event.GameReadyEvent;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public class GameReadyPacket extends Packet
|
||||
{
|
||||
private List<String> _players;
|
||||
|
||||
public GameReadyPacket() { }
|
||||
|
||||
public GameReadyPacket(List<String> players)
|
||||
{
|
||||
_players = players;
|
||||
}
|
||||
|
||||
public void ParseStream(DataInputStream dataInput) throws IOException
|
||||
{
|
||||
int playerCount = dataInput.readShort();
|
||||
|
||||
if (_players == null)
|
||||
_players = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < playerCount; i++)
|
||||
{
|
||||
_players.add(readString(dataInput, 16));
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(DataOutputStream dataOutput) throws IOException
|
||||
{
|
||||
dataOutput.writeShort(73);
|
||||
dataOutput.writeShort(_players.size());
|
||||
|
||||
for (int i = 0; i < _players.size(); i++)
|
||||
{
|
||||
writeString(_players.get(i), dataOutput);
|
||||
}
|
||||
}
|
||||
|
||||
public Event GetEvent()
|
||||
{
|
||||
return new GameReadyEvent(_players);
|
||||
}
|
||||
|
||||
public List<String> GetPlayers()
|
||||
{
|
||||
return _players;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public interface IPacketHandler
|
||||
{
|
||||
void HandlePacketEvent(Event packetEvent, Socket socket);
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public abstract class Packet
|
||||
{
|
||||
public abstract void ParseStream(DataInputStream inputStream) throws IOException;
|
||||
|
||||
public abstract void Write(DataOutputStream dataOutput) throws IOException;
|
||||
|
||||
public abstract Event GetEvent();
|
||||
|
||||
protected String readString(DataInputStream dataInputStream, int maxLength) throws IOException
|
||||
{
|
||||
short length = dataInputStream.readShort();
|
||||
|
||||
if (length > maxLength)
|
||||
{
|
||||
throw new IOException("Received string length longer than maximum allowed (" + length + " > " + maxLength + ")");
|
||||
}
|
||||
else if (length < 0)
|
||||
{
|
||||
throw new IOException("Received string length is less than zero! Weird string!");
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
stringBuilder.append(dataInputStream.readChar());
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeString(String string, DataOutputStream dataOutputStream) throws IOException
|
||||
{
|
||||
dataOutputStream.writeShort(string.length());
|
||||
dataOutputStream.writeChars(string);
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public enum PacketType
|
||||
{
|
||||
ServerReady((short)61, ServerReadyPacket.class),
|
||||
PlayerGameRequest((short)71, PlayerGameRequestPacket.class),
|
||||
PlayerServerAssignment((short)72, PlayerServerAssignmentPacket.class),
|
||||
GameReady((short)73, GameReadyPacket.class),
|
||||
PlayerVote((short)81, PlayerVotePacket.class);
|
||||
|
||||
private short _packetId;
|
||||
private Class<? extends Packet> _packetClass;
|
||||
|
||||
private static NautHashMap<Short, PacketType> _typeMapping;
|
||||
|
||||
private PacketType(short id, Class<? extends Packet> packetClass)
|
||||
{
|
||||
_packetId = id;
|
||||
_packetClass = packetClass;
|
||||
}
|
||||
|
||||
public short GetPacketId()
|
||||
{
|
||||
return _packetId;
|
||||
}
|
||||
|
||||
public Class<? extends Packet> GetPacketClass()
|
||||
{
|
||||
return _packetClass;
|
||||
}
|
||||
|
||||
public static Event GetPacketEventById(short id, DataInputStream dataInputStream) throws Exception
|
||||
{
|
||||
if (_typeMapping == null)
|
||||
{
|
||||
InitializeMapping();
|
||||
}
|
||||
|
||||
if (!_typeMapping.containsKey(id))
|
||||
{
|
||||
throw new Exception("Invalid packet id");
|
||||
}
|
||||
|
||||
Class<? extends Packet> packetClass = _typeMapping.get(id).GetPacketClass();
|
||||
|
||||
Packet newPacket = (Packet) packetClass.newInstance();
|
||||
|
||||
newPacket.ParseStream(dataInputStream);
|
||||
|
||||
return newPacket.GetEvent();
|
||||
}
|
||||
|
||||
private static void InitializeMapping()
|
||||
{
|
||||
_typeMapping = new NautHashMap<Short, PacketType>();
|
||||
|
||||
for (PacketType packetType : values())
|
||||
{
|
||||
_typeMapping.put(packetType.GetPacketId(), packetType);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import mineplex.core.server.event.PlayerGameAssignmentEvent;
|
||||
|
||||
public class PlayerGameAssignmentPacket extends Packet
|
||||
{
|
||||
private String _playerName;
|
||||
|
||||
public PlayerGameAssignmentPacket() { }
|
||||
|
||||
public PlayerGameAssignmentPacket(String playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public void ParseStream(DataInputStream dataInput) throws IOException
|
||||
{
|
||||
_playerName = readString(dataInput, 16);
|
||||
}
|
||||
|
||||
public void Write(DataOutputStream dataOutput) throws IOException
|
||||
{
|
||||
dataOutput.writeShort(71);
|
||||
writeString(_playerName, dataOutput);
|
||||
}
|
||||
|
||||
public Event GetEvent()
|
||||
{
|
||||
return new PlayerGameAssignmentEvent(_playerName);
|
||||
}
|
||||
|
||||
public String GetPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import mineplex.core.server.event.PlayerGameRequestEvent;
|
||||
|
||||
public class PlayerGameRequestPacket extends Packet
|
||||
{
|
||||
private String _playerName;
|
||||
|
||||
public PlayerGameRequestPacket() { }
|
||||
|
||||
public PlayerGameRequestPacket(String playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
}
|
||||
|
||||
public void ParseStream(DataInputStream dataInput) throws IOException
|
||||
{
|
||||
_playerName = readString(dataInput, 16);
|
||||
}
|
||||
|
||||
public void Write(DataOutputStream dataOutput) throws IOException
|
||||
{
|
||||
dataOutput.writeShort(71);
|
||||
writeString(_playerName, dataOutput);
|
||||
}
|
||||
|
||||
public Event GetEvent()
|
||||
{
|
||||
return new PlayerGameRequestEvent(_playerName);
|
||||
}
|
||||
|
||||
public String GetPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mineplex.core.server.event.PlayerServerAssignmentEvent;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public class PlayerServerAssignmentPacket extends Packet
|
||||
{
|
||||
private String _playerName;
|
||||
private String _serverName;
|
||||
|
||||
public PlayerServerAssignmentPacket() { }
|
||||
|
||||
public PlayerServerAssignmentPacket(String playerName, String serverName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
_serverName = serverName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ParseStream(DataInputStream inputStream) throws IOException
|
||||
{
|
||||
_playerName = readString(inputStream, 16);
|
||||
_serverName = readString(inputStream, 16);
|
||||
}
|
||||
|
||||
public void Write(DataOutputStream dataOutput) throws IOException
|
||||
{
|
||||
dataOutput.writeShort(72);
|
||||
writeString(_playerName, dataOutput);
|
||||
writeString(_serverName, dataOutput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event GetEvent()
|
||||
{
|
||||
return new PlayerServerAssignmentEvent(_playerName, _serverName);
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mineplex.core.server.event.PlayerVoteEvent;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public class PlayerVotePacket extends Packet
|
||||
{
|
||||
private String _playerName;
|
||||
private int _points;
|
||||
|
||||
public PlayerVotePacket() { }
|
||||
|
||||
public PlayerVotePacket(String playerName, int points)
|
||||
{
|
||||
_playerName = playerName;
|
||||
_points = points;
|
||||
}
|
||||
|
||||
public void ParseStream(DataInputStream dataInput) throws IOException
|
||||
{
|
||||
_playerName = readString(dataInput, 16);
|
||||
_points = dataInput.readInt();
|
||||
}
|
||||
|
||||
public void Write(DataOutputStream dataOutput) throws IOException
|
||||
{
|
||||
dataOutput.writeShort(81);
|
||||
writeString(_playerName, dataOutput);
|
||||
dataOutput.writeInt(_points);
|
||||
}
|
||||
|
||||
public String GetPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
public int GetPointReward()
|
||||
{
|
||||
return _points;
|
||||
}
|
||||
|
||||
public Event GetEvent()
|
||||
{
|
||||
return new PlayerVoteEvent(_playerName, _points);
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package mineplex.core.server.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mineplex.core.server.event.ServerReadyEvent;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public class ServerReadyPacket extends Packet
|
||||
{
|
||||
private String _serverPath;
|
||||
|
||||
public ServerReadyPacket() { }
|
||||
|
||||
public ServerReadyPacket(String serverPath)
|
||||
{
|
||||
_serverPath = serverPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ParseStream(DataInputStream inputStream) throws IOException
|
||||
{
|
||||
_serverPath = readString(inputStream, 21);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Write(DataOutputStream dataOutput) throws IOException
|
||||
{
|
||||
dataOutput.writeShort(61);
|
||||
writeString(_serverPath, dataOutput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event GetEvent()
|
||||
{
|
||||
return new ServerReadyEvent(_serverPath);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package mineplex.core.stats;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.stats.column.Column;
|
||||
import mineplex.core.database.column.Column;
|
||||
|
||||
public class Row
|
||||
{
|
||||
|
@ -16,10 +16,10 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.event.RetrieveClientInformationEvent;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.stats.column.Column;
|
||||
import mineplex.core.stats.column.ColumnInt;
|
||||
import mineplex.core.stats.column.ColumnUuid;
|
||||
import mineplex.core.stats.column.ColumnVarChar;
|
||||
import mineplex.core.database.Table;
|
||||
import mineplex.core.database.column.Column;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
|
||||
public class StatsManager extends MiniPlugin
|
||||
{
|
||||
@ -146,7 +146,7 @@ public class StatsManager extends MiniPlugin
|
||||
// playerName -> column name of UUID or uuid or UniqueID, whichever you choose
|
||||
// and event.getPlayerName() is still in this event, but so is getUniqueId
|
||||
List<Column<?>> columnList = new ArrayList<Column<?>>();
|
||||
columnList.add(new ColumnUuid("playerUuid", 256, event.getUniqueId()));
|
||||
columnList.add(new ColumnVarChar("playerUuid", 256, event.getUniqueId().toString()));
|
||||
List<Row> rows = table.retrieve(columnList);
|
||||
|
||||
// Same here.
|
||||
|
@ -1,41 +0,0 @@
|
||||
package mineplex.core.stats.column;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ColumnUuid extends Column<String>
|
||||
{
|
||||
public int Length = 256;
|
||||
public UUID Value = UUID.fromString("");
|
||||
|
||||
public ColumnUuid(String name, int length)
|
||||
{
|
||||
this(name, length, UUID.fromString(""));
|
||||
}
|
||||
|
||||
public ColumnUuid(String name, int length, UUID value)
|
||||
{
|
||||
super(name);
|
||||
|
||||
Length = length;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public String getCreateString()
|
||||
{
|
||||
return Name + " VARCHAR(" + Length + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
return resultSet.getString(Name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnUuid clone()
|
||||
{
|
||||
return new ColumnUuid(Name, Length, Value);
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class ServerStatusRepository
|
||||
|
@ -6,5 +6,6 @@
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/javax.mail.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -1,7 +1,23 @@
|
||||
package mineplex.ddos;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMessage.RecipientType;
|
||||
|
||||
import mineplex.ddos.api.ApiDeleteCall;
|
||||
import mineplex.ddos.api.ApiGetCall;
|
||||
@ -13,9 +29,10 @@ import mineplex.ddos.api.token.DomainRecords;
|
||||
public class DDoSProtectionSwitcher
|
||||
{
|
||||
private static DnsMadeEasyRepository _repository = null;
|
||||
private static HashSet<ProcessRunner> _processes = new HashSet<ProcessRunner>();
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
@ -24,18 +41,22 @@ public class DDoSProtectionSwitcher
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
_repository = new DnsMadeEasyRepository();
|
||||
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (_repository.switchToDDOSProt())
|
||||
{
|
||||
DomainRecords records = new ApiGetCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records", "").Execute(DomainRecords.class);
|
||||
System.out.println("Starting DDoS Protection Switch at " + dateFormat.format(new Date()));
|
||||
|
||||
DomainRecords records = new ApiGetCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728,
|
||||
"/records", "").Execute(DomainRecords.class);
|
||||
List<DnsRecord> recordsToDelete = new ArrayList<DnsRecord>();
|
||||
List<DnsRecord> recordsToAdd = new ArrayList<DnsRecord>();
|
||||
List<DnsRecord> recordsToModify = new ArrayList<DnsRecord>();
|
||||
|
||||
|
||||
// Switch on ddos protection
|
||||
for (DnsRecord record : records.data)
|
||||
{
|
||||
@ -58,19 +79,25 @@ public class DDoSProtectionSwitcher
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (recordsToAdd.size() > 0)
|
||||
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(records);
|
||||
{
|
||||
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti")
|
||||
.Execute(records);
|
||||
System.out.println("Created " + recordsToAdd.size() + " records.");
|
||||
}
|
||||
|
||||
if (recordsToModify.size() > 0)
|
||||
{
|
||||
new ApiPutCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "updateMulti").Execute(recordsToModify);
|
||||
new ApiPutCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "updateMulti")
|
||||
.Execute(recordsToModify);
|
||||
System.out.println("Modified " + recordsToModify.size() + " records.");
|
||||
}
|
||||
|
||||
if (recordsToDelete.size() > 0)
|
||||
{
|
||||
StringBuilder idBuilder = new StringBuilder();
|
||||
|
||||
|
||||
for (DnsRecord record : recordsToDelete)
|
||||
{
|
||||
if (idBuilder.length() != 0)
|
||||
@ -78,14 +105,98 @@ public class DDoSProtectionSwitcher
|
||||
|
||||
idBuilder.append("ids=" + record.id);
|
||||
}
|
||||
|
||||
new ApiDeleteCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records?" + idBuilder.toString()).Execute();
|
||||
|
||||
new ApiDeleteCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records?"
|
||||
+ idBuilder.toString()).Execute();
|
||||
System.out.println("Deleted " + recordsToDelete.size() + " records.");
|
||||
}
|
||||
|
||||
// Switching US Bungees
|
||||
switchServer("10.35.74.130", "108.178.20.166", "108.163.222.202", "108.178.20.165", "108.163.222.201");
|
||||
switchServer("10.35.74.132", "108.163.217.110", "108.178.44.50", "108.163.217.109", "108.178.44.49");
|
||||
switchServer("10.35.74.142", "108.178.16.90", "108.178.16.90", "108.178.16.89", "108.178.16.89");
|
||||
switchServer("10.35.74.135", "108.163.254.134", "108.178.16.106", "108.163.254.133", "108.178.16.105");
|
||||
switchServer("10.35.74.137", "108.163.216.250", "108.178.34.162", "108.163.216.249", "108.178.34.161");
|
||||
switchServer("10.35.74.147", "108.163.216.106", "184.154.39.126", "108.163.216.105", "184.154.39.125");
|
||||
switchServer("10.35.74.143", "184.154.215.170", "108.178.17.6", "184.154.215.169", "108.178.17.5");
|
||||
switchServer("10.35.74.145", "96.127.174.206", "108.178.7.118", "96.127.174.205", "108.178.7.117");
|
||||
switchServer("10.35.74.144", "184.154.127.10", "184.154.39.154", "184.154.127.9", "184.154.39.153");
|
||||
switchServer("10.35.74.146", "96.127.174.146", "108.178.16.26", "96.127.174.145", "108.178.16.25");
|
||||
switchServer("10.35.74.149", "108.178.7.206", "107.6.158.198", "108.178.7.205", "107.6.158.197");
|
||||
switchServer("10.35.74.136", "184.154.39.146", "184.154.13.218", "184.154.39.145", "184.154.13.217");
|
||||
switchServer("10.35.74.139", "108.163.217.250", "108.178.44.134", "108.163.217.249", "108.178.44.133");
|
||||
switchServer("10.35.74.140", "69.175.15.242", "108.163.216.38", "69.175.15.241", "108.163.216.37");
|
||||
switchServer("10.35.74.141", "107.6.129.126", "96.127.182.218", "107.6.129.125", "96.127.182.217");
|
||||
switchServer("10.35.74.134", "108.163.222.174", "108.163.216.82", "108.163.222.173", "108.163.216.81");
|
||||
switchServer("10.32.214.248", "108.178.34.118", "107.6.129.170", "108.178.34.117", "107.6.129.169");
|
||||
switchServer("10.32.214.250", "69.175.4.38", "107.6.129.250", "69.175.4.37", "107.6.129.249");
|
||||
switchServer("10.32.214.249", "107.6.158.78", "184.154.13.38", "107.6.158.77", "184.154.13.37");
|
||||
switchServer("10.32.214.247", "184.154.13.118", "108.163.242.98", "184.154.13.117", "108.163.242.97");
|
||||
|
||||
// Switching EU Bungees
|
||||
switchServer("10.82.2.202", "107.6.176.194", "107.6.176.34", "107.6.176.193", "107.6.176.33");
|
||||
switchServer("10.82.2.204", "107.6.176.122", "107.6.176.50", "107.6.176.121", "107.6.176.49");
|
||||
switchServer("10.82.2.206", "107.6.176.166", "107.6.176.126", "107.6.176.165", "107.6.176.125");
|
||||
switchServer("10.83.27.77", "107.6.176.14", "107.6.176.98", "107.6.176.13", "107.6.176.97");
|
||||
switchServer("10.82.2.225", "107.6.176.114", "107.6.176.58", "107.6.176.113", "107.6.176.57");
|
||||
switchServer("10.82.2.227", "107.6.176.26", "107.6.176.46", "107.6.176.25", "107.6.176.45");
|
||||
switchServer("10.82.2.228", "107.6.176.110", "107.6.176.70", "107.6.176.109", "107.6.176.69");
|
||||
switchServer("10.82.2.226", "107.6.176.138", "107.6.176.234", "107.6.176.137", "107.6.176.233");
|
||||
|
||||
sendMail();
|
||||
}
|
||||
|
||||
|
||||
int processWaits = 0;
|
||||
|
||||
while (_processes.size() > 0)
|
||||
{
|
||||
for (Iterator<ProcessRunner> iterator = _processes.iterator(); iterator.hasNext();)
|
||||
{
|
||||
ProcessRunner pr = iterator.next();
|
||||
|
||||
try
|
||||
{
|
||||
pr.join(100);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (pr.isDone())
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
if (_processes.size() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(6000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (processWaits >= 60)
|
||||
{
|
||||
System.out.println("Killing stale processes.");
|
||||
|
||||
for (Iterator<ProcessRunner> iterator = _processes.iterator(); iterator.hasNext();)
|
||||
{
|
||||
iterator.next().abort();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
processWaits++;
|
||||
}
|
||||
|
||||
processWaits = 0;
|
||||
|
||||
try
|
||||
{
|
||||
System.out.println("Natural Sleep");
|
||||
Thread.sleep(60000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
@ -93,38 +204,117 @@ public class DDoSProtectionSwitcher
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/*
|
||||
// Switch off ddos protection
|
||||
for (DnsRecord record : records.data)
|
||||
/*
|
||||
* // Switch off ddos protection for (DnsRecord record : records.data) {
|
||||
* if (record.type.equalsIgnoreCase("CNAME")) { if
|
||||
* (record.name.equalsIgnoreCase("eu")) recordsToDelete.add(record); }
|
||||
* else if (record.type.equalsIgnoreCase("A")) { if
|
||||
* (record.name.equalsIgnoreCase("us")) { record.name = "neustar";
|
||||
* recordsToModify.add(record); } else if
|
||||
* (record.name.equalsIgnoreCase("us2")) { record.name = "us";
|
||||
* recordsToModify.add(record); } else if
|
||||
* (record.name.equalsIgnoreCase("eu2")) { record.name = "eu";
|
||||
* recordsToModify.add(record); } } }
|
||||
*
|
||||
*
|
||||
*
|
||||
* recordsToAdd.add(new CNameRecord("eu", "us", 300));
|
||||
*/
|
||||
}
|
||||
|
||||
private static void sendMail()
|
||||
{
|
||||
Message message = new MimeMessage(getSession());
|
||||
|
||||
try
|
||||
{
|
||||
if (record.type.equalsIgnoreCase("CNAME"))
|
||||
message.addRecipient(RecipientType.TO, new InternetAddress("ultrasupport@neustar.biz"));
|
||||
message.addFrom(new InternetAddress[] { new InternetAddress("it@mineplex.com") });
|
||||
|
||||
message.setSubject("Start Mitigation Incident");
|
||||
message.setText("We need to start mitigation.\n\n"
|
||||
+ "Jonathan Williams\n"
|
||||
+ "Director of Gaming Software Development\n"
|
||||
+ "Mineplex, LLC\n"
|
||||
+ "PH: 805.231.0407\n"
|
||||
+ "http://www.mineplex.com");
|
||||
|
||||
|
||||
Transport.send(message);
|
||||
|
||||
System.out.println("Sent Neustar Mitigation Email at " + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date()));
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static Session getSession()
|
||||
{
|
||||
Authenticator authenticator = new Authenticator();
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName());
|
||||
|
||||
properties.setProperty("mail.smtp.host", "smtp.fatcow.com");
|
||||
properties.setProperty("mail.smtp.socketFactory.port", "465");
|
||||
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
properties.setProperty("mail.smtp.auth", "true");
|
||||
properties.setProperty("mail.smtp.port", "465");
|
||||
|
||||
return Session.getInstance(properties, authenticator);
|
||||
}
|
||||
|
||||
private static void switchServer(final String privateIp, String currentIp, String newIp, String currentGateway,
|
||||
String newGateway)
|
||||
{
|
||||
String cmd = "/home/mineplex/switchBungeeIp.sh";
|
||||
|
||||
ProcessRunner pr = new ProcessRunner(new String[] { "/bin/sh", cmd, privateIp, currentIp, newIp,
|
||||
currentGateway, newGateway });
|
||||
pr.start(new GenericRunnable<Boolean>()
|
||||
{
|
||||
public void run(Boolean error)
|
||||
{
|
||||
if (record.name.equalsIgnoreCase("eu"))
|
||||
recordsToDelete.add(record);
|
||||
}
|
||||
else if (record.type.equalsIgnoreCase("A"))
|
||||
{
|
||||
if (record.name.equalsIgnoreCase("us"))
|
||||
{
|
||||
record.name = "neustar";
|
||||
recordsToModify.add(record);
|
||||
}
|
||||
else if (record.name.equalsIgnoreCase("us2"))
|
||||
{
|
||||
record.name = "us";
|
||||
recordsToModify.add(record);
|
||||
}
|
||||
else if (record.name.equalsIgnoreCase("eu2"))
|
||||
{
|
||||
record.name = "eu";
|
||||
recordsToModify.add(record);
|
||||
}
|
||||
if (error)
|
||||
System.out.println("[" + privateIp + "] Errored!");
|
||||
else
|
||||
System.out.println("[" + privateIp + "] Switched!");
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
pr.join(500);
|
||||
}
|
||||
catch (InterruptedException e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
if (!pr.isDone())
|
||||
_processes.add(pr);
|
||||
}
|
||||
|
||||
private static class Authenticator extends javax.mail.Authenticator
|
||||
{
|
||||
private PasswordAuthentication authentication;
|
||||
|
||||
recordsToAdd.add(new CNameRecord("eu", "us", 300));
|
||||
*/
|
||||
public Authenticator()
|
||||
{
|
||||
String username = "it@mineplex.com";
|
||||
String password = "BearT4bl312ust";
|
||||
authentication = new PasswordAuthentication(username, password);
|
||||
}
|
||||
|
||||
protected PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return authentication;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,10 +118,7 @@ public class DnsMadeEasyRepository
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Offline count : " + countOffline);
|
||||
|
||||
return false;
|
||||
//countOffline >= 20;
|
||||
|
||||
return countOffline >= 20;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package mineplex.ddos;
|
||||
|
||||
public interface GenericRunnable<T>
|
||||
{
|
||||
void run(T t);
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package mineplex.ddos;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class ProcessRunner extends Thread
|
||||
{
|
||||
private ProcessBuilder _processBuilder;
|
||||
private Process _process;
|
||||
private GenericRunnable<Boolean> _runnable;
|
||||
|
||||
boolean _done = false;
|
||||
Boolean _error = false;
|
||||
|
||||
ProcessRunner(String[] args)
|
||||
{
|
||||
super("ProcessRunner " + args);
|
||||
_processBuilder = new ProcessBuilder(args);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
_process = _processBuilder.start();
|
||||
_process.waitFor();
|
||||
|
||||
BufferedReader reader=new BufferedReader(new InputStreamReader(_process.getInputStream()));
|
||||
String line = reader.readLine();
|
||||
|
||||
while(line != null)
|
||||
{
|
||||
if (line.equals("255"))
|
||||
_error = true;
|
||||
|
||||
line=reader.readLine();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
_done = true;
|
||||
|
||||
if (_runnable != null)
|
||||
_runnable.run(_error);
|
||||
}
|
||||
}
|
||||
|
||||
public void start(GenericRunnable<Boolean> runnable)
|
||||
{
|
||||
super.start();
|
||||
|
||||
_runnable = runnable;
|
||||
}
|
||||
|
||||
public int exitValue() throws IllegalStateException
|
||||
{
|
||||
if (_process != null)
|
||||
{
|
||||
return _process.exitValue();
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Process not started yet");
|
||||
}
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return _done;
|
||||
}
|
||||
|
||||
public void abort()
|
||||
{
|
||||
if (!isDone())
|
||||
{
|
||||
_process.destroy();
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ public class ApiPutCall extends DnsMadeEasyApiCallBase
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.out.println("Error executing ApiPostCall(Object): \n" + exception.getMessage());
|
||||
System.out.println("Error executing ApiPutCall(Object): \n" + exception.getMessage());
|
||||
|
||||
for (StackTraceElement trace : exception.getStackTrace())
|
||||
{
|
||||
|
@ -11,6 +11,7 @@ import mineplex.core.disguise.DisguiseManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.elo.EloManager;
|
||||
import mineplex.core.energy.Energy;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.logger.Logger;
|
||||
import mineplex.core.memory.MemoryFix;
|
||||
@ -73,10 +74,10 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
|
||||
ItemStackFactory.Initialize(this, false);
|
||||
Recharge.Initialize(this);
|
||||
Punish punish = new Punish(this, webServerAddress, clientManager);
|
||||
Punish punish = new Punish(this, webServerAddress, clientManager);
|
||||
|
||||
|
||||
DonationManager donationManager = new DonationManager(this, webServerAddress);
|
||||
DonationManager donationManager = new DonationManager(this, webServerAddress);
|
||||
|
||||
//Other Modules
|
||||
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
||||
@ -89,12 +90,13 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
|
||||
//Main Modules
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager));
|
||||
PacketHandler packetHandler = new PacketHandler(this);
|
||||
PacketHandler packetHandler = new PacketHandler(this);
|
||||
new FriendManager(this, packetHandler);
|
||||
PartyManager partyManager = new PartyManager(this, clientManager, preferenceManager);
|
||||
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
|
||||
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
|
||||
AntiHack.Initialize(this, punish, portal);
|
||||
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), new DisguiseManager(this, packetHandler), new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager);
|
||||
PlayerTracker tracker = new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
|
||||
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
|
||||
|
||||
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);
|
||||
|
||||
|
@ -30,9 +30,11 @@ public class HubRepository
|
||||
private static String RETRIEVE_NEWS_ENTRIES = "SELECT newsString, newsPosition FROM newsList;";
|
||||
private static String RETRIEVE_MAX_NEWS_POSITION = "SELECT MAX(newsPosition) AS newsPosition FROM newsList;";
|
||||
private static String ADD_NEWS_ENTRY = "INSERT INTO newsList (newsString, newsPosition) VALUES(?,?);";
|
||||
//private static String ADD_NEWS_ENTRY = "SET @max = (SELECT MAX(newsPosition) AS newsPosition FROM newsList);INSERT INTO newsList (newsString, newsPosition) VALUES(?,@max + 1);";
|
||||
private static String SET_NEWS_ENTRY = "UPDATE newsList SET newsString = ? WHERE newsPosition = ?;";
|
||||
private static String DELETE_NEWS_ENTRY = "DELETE FROM newsList WHERE newsPosition = ?;";
|
||||
private static String RECALC_NEWS_POSITIONS = "UPDATE newsList SET newsPosition = newsPosition - 1 WHERE newsPosition > ?;";
|
||||
//private static String DELETE_RECALC_NEWS_ENTRY = "SET @pos = ?;SET @max = (SELECT MAX(newsPosition) AS newsPosition FROM newsList);DELETE FROM newsList WHERE newsPosition = @pos;UPDATE newsList SET newsPosition = IF(@max <> @pos, newsPosition - 1, newsPosition) WHERE newsPosition > @pos;";
|
||||
|
||||
private Connection _connection = null;
|
||||
|
||||
@ -279,6 +281,7 @@ public class HubRepository
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
|
||||
//preparedStatement = _connection.prepareStatement(DELETE_RECALC_NEWS_ENTRY);
|
||||
preparedStatement = _connection.prepareStatement(DELETE_NEWS_ENTRY);
|
||||
preparedStatement.setInt(1, newsPosition);
|
||||
result = preparedStatement.executeUpdate();
|
||||
|
@ -11,6 +11,7 @@ import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.hub.HubManager;
|
||||
import mineplex.hub.modules.NewsManager;
|
||||
|
||||
@ -35,8 +36,8 @@ public class NewsCommand extends CommandBase<HubManager>
|
||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news add <newsEntry>" + C.cGray + " - Adds specified news entry string to database at end of table."));
|
||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news delete #" + C.cGray + " - Removes specified (numbered) news entry string from database."));
|
||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news set # <newsEntry>" + C.cGray + " - Updates specified (numbered) news entry string in database."));
|
||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "*Please Note: " + C.cGray + "Updates to server news entries from the database are on a 4 minute refresh cycle!"));
|
||||
return;
|
||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "*Please Note: " + C.cGray + "Updates to server news entries from the database are on a 4 minute refresh cycle!"));
|
||||
return;
|
||||
}
|
||||
else if (args.length == 1 && args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
@ -56,12 +57,11 @@ public class NewsCommand extends CommandBase<HubManager>
|
||||
{
|
||||
String newsPosition = iterator.next();
|
||||
newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition);
|
||||
//iterator.remove();
|
||||
}
|
||||
|
||||
for (int i = 0; i < newsStrings.length; i++)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGold + "News " + (i + 1) + C.cGray + " : " + newsStrings[i]));
|
||||
UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[DELETE] \", color:red, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news ¢¤₦₣¡₨₥ " + (i + 1) + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Deletes News Entry " + (i + 1) + " : " + newsStrings[i] + "\"}}, {\"text\":\"News " + (i + 1) + "\", color:gold}, {\"text\":\" : \", color:gray}, {\"text\":\"" + newsStrings[i] + "\", color:white}]}");
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -71,7 +71,23 @@ public class NewsCommand extends CommandBase<HubManager>
|
||||
}
|
||||
else if (args.length >= 2 && args.length <= 128)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("delete") && args.length == 2)
|
||||
if (args[0].equals("¢¤₦₣¡₨₥") && args.length == 2)
|
||||
{
|
||||
int newsPosition;
|
||||
try
|
||||
{
|
||||
newsPosition = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!"));
|
||||
return;
|
||||
}
|
||||
|
||||
UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[CONFIRM] \", color:green, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news delete " + newsPosition + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Are you absolutely sure???\"}}, {\"text\":\"News Entry " + newsPosition + "\", color:gold}, {\"text\":\" deletion?\", color:gray}]}");
|
||||
return;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("delete") && args.length == 2)
|
||||
{
|
||||
final int newsPosition;
|
||||
try
|
||||
@ -138,7 +154,7 @@ public class NewsCommand extends CommandBase<HubManager>
|
||||
});
|
||||
return;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("set"))
|
||||
else if (args[0].equalsIgnoreCase("set") && args.length >= 3)
|
||||
{
|
||||
final int newsPosition;
|
||||
String newsEntry = "";
|
||||
|
@ -69,7 +69,7 @@
|
||||
{
|
||||
var account = repository.Where<Account>(x => x.Uuid == loginToken.Uuid).FirstOrDefault() ?? CreateAccount(loginToken, repository);
|
||||
account.LoadNavigationProperties(repository.Context);
|
||||
bool edited = false;
|
||||
account.LastLogin = DateTime.Now.Ticks;
|
||||
|
||||
// Expire punishments
|
||||
if (account.Punishments != null)
|
||||
@ -77,7 +77,6 @@
|
||||
foreach (var expiredPunishment in account.Punishments.Where(x => x.Active && (x.Duration - 0d) > 0 && TimeUtil.GetCurrentMilliseconds() > (x.Time + (x.Duration * 3600000))))
|
||||
{
|
||||
expiredPunishment.Active = false;
|
||||
edited = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,14 +84,12 @@
|
||||
if (String.IsNullOrEmpty(account.Uuid) && !String.IsNullOrEmpty(loginToken.Uuid))
|
||||
{
|
||||
account.Uuid = loginToken.Uuid;
|
||||
edited = true;
|
||||
}
|
||||
|
||||
// Update account name if changed
|
||||
if (!String.Equals(account.Name, loginToken.Name))
|
||||
{
|
||||
account.Name = loginToken.Name;
|
||||
edited = true;
|
||||
}
|
||||
|
||||
// Expire ranks
|
||||
@ -100,11 +97,9 @@
|
||||
{
|
||||
account.Rank = repository.Where<Rank>(x => x.Name == "ALL").First();
|
||||
repository.Attach(account.Rank);
|
||||
edited = true;
|
||||
}
|
||||
|
||||
if (edited)
|
||||
repository.CommitChanges();
|
||||
repository.CommitChanges();
|
||||
|
||||
return account;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user