diff --git a/Plugins/BuildFiles/common.xml b/Plugins/BuildFiles/common.xml index 962deced7..484184d44 100644 --- a/Plugins/BuildFiles/common.xml +++ b/Plugins/BuildFiles/common.xml @@ -144,6 +144,7 @@ + diff --git a/Plugins/Libraries/javax.mail.jar b/Plugins/Libraries/javax.mail.jar new file mode 100644 index 000000000..ca7eca7d9 Binary files /dev/null and b/Plugins/Libraries/javax.mail.jar differ diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index dd96fd705..32500667c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -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 _clientList; private HashSet _duplicateLoginGlitchPreventionList; @@ -50,6 +53,7 @@ public class CoreClientManager extends MiniPlugin _plugin = plugin; _repository = new AccountRepository(webServer); + _mysqlRepository = new MysqlAccountRepository(plugin); _clientList = new NautHashMap(); _duplicateLoginGlitchPreventionList = new HashSet(); } @@ -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())) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/MysqlAccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/MysqlAccountRepository.java index 4721d3a54..899fd2228 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/MysqlAccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/MysqlAccountRepository.java @@ -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 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)); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java new file mode 100644 index 000000000..a8f280fd3 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java @@ -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; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/ResultSetCallable.java b/Plugins/Mineplex.Core/src/mineplex/core/database/ResultSetCallable.java new file mode 100644 index 000000000..2972d5f4a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/ResultSetCallable.java @@ -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; +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/Table.java b/Plugins/Mineplex.Core/src/mineplex/core/database/Table.java similarity index 98% rename from Plugins/Mineplex.Core/src/mineplex/core/stats/Table.java rename to Plugins/Mineplex.Core/src/mineplex/core/database/Table.java index 708cbc9bd..af2261434 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/Table.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/Table.java @@ -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 { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/Column.java b/Plugins/Mineplex.Core/src/mineplex/core/database/column/Column.java similarity index 70% rename from Plugins/Mineplex.Core/src/mineplex/core/stats/column/Column.java rename to Plugins/Mineplex.Core/src/mineplex/core/database/column/Column.java index 7b93cad74..d73d6da05 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/Column.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/column/Column.java @@ -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 public abstract Type getValue(ResultSet resultSet) throws SQLException; + public abstract void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException; + public abstract Column clone(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnInt.java b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnInt.java similarity index 68% rename from Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnInt.java rename to Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnInt.java index 24a1ba097..25ed6a705 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnInt.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnInt.java @@ -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 { return resultSet.getInt(Name); } + + @Override + public void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException + { + preparedStatement.setInt(columnNumber, Value); + } @Override public ColumnInt clone() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnLong.java b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnLong.java similarity index 68% rename from Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnLong.java rename to Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnLong.java index 8fda5099f..d8c8815b5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnLong.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnLong.java @@ -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 { return resultSet.getLong(Name); } + + @Override + public void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException + { + preparedStatement.setLong(columnNumber, Value); + } @Override public ColumnLong clone() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnVarChar.java b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnVarChar.java similarity index 72% rename from Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnVarChar.java rename to Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnVarChar.java index c4ab8edda..da5c484c1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnVarChar.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnVarChar.java @@ -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 { return resultSet.getString(Name); } + + @Override + public void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException + { + preparedStatement.setString(columnNumber, Value); + } @Override public ColumnVarChar clone() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java index 3d4f82cf2..fbe373ac9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java @@ -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 implements IPacketRunnable { private FriendRepository _repository; - public FriendManager(JavaPlugin plugin) + private NautHashMap _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(); + + 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 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); + } + }); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendSorter.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendSorter.java new file mode 100644 index 000000000..6951a362c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendSorter.java @@ -0,0 +1,43 @@ +package mineplex.core.friend; + +import java.util.Comparator; + +import mineplex.core.friend.data.FriendStatus; + +public class FriendSorter implements Comparator +{ + 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; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java new file mode 100644 index 000000000..4a16c5858 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/AddFriend.java @@ -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 +{ + 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() + { + public void run(Boolean result) + { + if (result) + { + Plugin.addFriend(caller, args[0]); + } + } + }); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/command/DeleteFriend.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/DeleteFriend.java new file mode 100644 index 000000000..36fe4583e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/command/DeleteFriend.java @@ -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 +{ + 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() + { + public void run(Boolean result) + { + if (result) + { + Plugin.removeFriend(caller, args[0]); + } + } + }); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendData.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendData.java new file mode 100644 index 000000000..95d1c5217 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendData.java @@ -0,0 +1,9 @@ +package mineplex.core.friend.data; + +import java.util.ArrayList; +import java.util.List; + +public class FriendData +{ + public List Friends = new ArrayList(); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java index f7b5f4d82..697c971f3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java @@ -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 getFriends(String uuid) + public boolean removeFriend(String uuid, String name) { - List friends = new ArrayList(); + return executeUpdate(DELETE_FRIEND_RECORD, new ColumnVarChar("name", 40, name), new ColumnVarChar("uuid", 100, uuid)) > 0; + } + + public NautHashMap getFriendsForAll(Player...players) + { + final NautHashMap friends = new NautHashMap(); + + 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; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendStatus.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendStatus.java index e5e600833..b173b2fd9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendStatus.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendStatus.java @@ -4,5 +4,7 @@ public class FriendStatus { public String Name; public String ServerName; + public boolean Online; public long LastSeenOnline; + public boolean Mutual; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendPage.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendPage.java deleted file mode 100644 index 21d0f5501..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendPage.java +++ /dev/null @@ -1,6 +0,0 @@ -package mineplex.core.friend.ui; - -public class FriendPage -{ - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendShop.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendShop.java deleted file mode 100644 index 180cfa08c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendShop.java +++ /dev/null @@ -1,6 +0,0 @@ -package mineplex.core.friend.ui; - -public class FriendShop -{ - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendTabList.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendTabList.java new file mode 100644 index 000000000..5a9d0e006 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/FriendTabList.java @@ -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 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 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"); + } + } +} + diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/InvitesPage.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/InvitesPage.java deleted file mode 100644 index f9ee9d93b..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/InvitesPage.java +++ /dev/null @@ -1,6 +0,0 @@ -package mineplex.core.friend.ui; - -public class InvitesPage -{ - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/LineTracker.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/LineTracker.java new file mode 100644 index 000000000..50776725d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/LineTracker.java @@ -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; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/TabList.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/TabList.java new file mode 100644 index 000000000..ee40c61d0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/ui/TabList.java @@ -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 _invisibleHolders = new NautHashMap(); + + private NautHashMap _tabSlots = new NautHashMap(); + private HashSet _updatedSlots = new HashSet(); + + 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; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/mysql/AccountPreferenceRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/mysql/AccountPreferenceRepository.java deleted file mode 100644 index 1e988caeb..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/mysql/AccountPreferenceRepository.java +++ /dev/null @@ -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() { } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/mysql/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/mysql/RepositoryBase.java deleted file mode 100644 index f774f734a..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/mysql/RepositoryBase.java +++ /dev/null @@ -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; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/PortalRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/PortalRepository.java index 03d313689..70b8b6751 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/PortalRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/PortalRepository.java @@ -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(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java index 4ee2bfc91..324958a50 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java @@ -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)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/IPurchaseRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/server/IPurchaseRepository.java deleted file mode 100644 index af643544d..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/IPurchaseRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package mineplex.core.server; - -import mineplex.core.common.util.Callback; - -public interface IPurchaseRepository -{ - void PurchaseSalesPackage(Callback callback, String name, boolean usingCredits, int salesPackageId); -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/Server.java b/Plugins/Mineplex.Core/src/mineplex/core/server/Server.java deleted file mode 100644 index b6c16fa4e..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/Server.java +++ /dev/null @@ -1,7 +0,0 @@ -package mineplex.core.server; - -public class Server -{ - public String Address; - public int Port; -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/ServerBroadcaster.java b/Plugins/Mineplex.Core/src/mineplex/core/server/ServerBroadcaster.java deleted file mode 100644 index 8f82fb999..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/ServerBroadcaster.java +++ /dev/null @@ -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 _serverMap = new HashSet(); - private List _queue = new ArrayList(); - - 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 servers = new JsonWebCall(_webAddress + "Servers/GetServers").Execute(new TypeToken>(){}.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(); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/ServerListener.java b/Plugins/Mineplex.Core/src/mineplex/core/server/ServerListener.java deleted file mode 100644 index 93e3373ae..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/ServerListener.java +++ /dev/null @@ -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(); - } - } - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/ServerTalker.java b/Plugins/Mineplex.Core/src/mineplex/core/server/ServerTalker.java deleted file mode 100644 index 6082b8051..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/ServerTalker.java +++ /dev/null @@ -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 _queue = new ArrayList(); - - 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()); - } - } - } - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/event/GameReadyEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/server/event/GameReadyEvent.java deleted file mode 100644 index 1c59fce43..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/event/GameReadyEvent.java +++ /dev/null @@ -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 _players; - - public GameReadyEvent(List players) - { - _players = players; - } - - public List GetPlayers() - { - return _players; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerGameAssignmentEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerGameAssignmentEvent.java deleted file mode 100644 index e14fa70e5..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerGameAssignmentEvent.java +++ /dev/null @@ -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; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerGameRequestEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerGameRequestEvent.java deleted file mode 100644 index efa247998..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerGameRequestEvent.java +++ /dev/null @@ -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; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerServerAssignmentEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerServerAssignmentEvent.java deleted file mode 100644 index 7b95663f5..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerServerAssignmentEvent.java +++ /dev/null @@ -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; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerVoteEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerVoteEvent.java deleted file mode 100644 index 1dccb0f7e..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/event/PlayerVoteEvent.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/event/ServerReadyEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/server/event/ServerReadyEvent.java deleted file mode 100644 index e76d2b172..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/event/ServerReadyEvent.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/GameReadyPacket.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/GameReadyPacket.java deleted file mode 100644 index c4de24728..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/GameReadyPacket.java +++ /dev/null @@ -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 _players; - - public GameReadyPacket() { } - - public GameReadyPacket(List players) - { - _players = players; - } - - public void ParseStream(DataInputStream dataInput) throws IOException - { - int playerCount = dataInput.readShort(); - - if (_players == null) - _players = new ArrayList(); - - 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 GetPlayers() - { - return _players; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/IPacketHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/IPacketHandler.java deleted file mode 100644 index e86223c9e..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/IPacketHandler.java +++ /dev/null @@ -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); -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/Packet.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/Packet.java deleted file mode 100644 index 39fe9b2d0..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/Packet.java +++ /dev/null @@ -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); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PacketType.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PacketType.java deleted file mode 100644 index 86d758294..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PacketType.java +++ /dev/null @@ -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 _packetClass; - - private static NautHashMap _typeMapping; - - private PacketType(short id, Class packetClass) - { - _packetId = id; - _packetClass = packetClass; - } - - public short GetPacketId() - { - return _packetId; - } - - public Class 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 packetClass = _typeMapping.get(id).GetPacketClass(); - - Packet newPacket = (Packet) packetClass.newInstance(); - - newPacket.ParseStream(dataInputStream); - - return newPacket.GetEvent(); - } - - private static void InitializeMapping() - { - _typeMapping = new NautHashMap(); - - for (PacketType packetType : values()) - { - _typeMapping.put(packetType.GetPacketId(), packetType); - } - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerGameAssignmentPacket.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerGameAssignmentPacket.java deleted file mode 100644 index 7593ecccd..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerGameAssignmentPacket.java +++ /dev/null @@ -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; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerGameRequestPacket.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerGameRequestPacket.java deleted file mode 100644 index 5938282fc..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerGameRequestPacket.java +++ /dev/null @@ -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; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerServerAssignmentPacket.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerServerAssignmentPacket.java deleted file mode 100644 index 0e88d8b55..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerServerAssignmentPacket.java +++ /dev/null @@ -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); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerVotePacket.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerVotePacket.java deleted file mode 100644 index 908d7ed52..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/PlayerVotePacket.java +++ /dev/null @@ -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); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/ServerReadyPacket.java b/Plugins/Mineplex.Core/src/mineplex/core/server/packet/ServerReadyPacket.java deleted file mode 100644 index 1b55b767e..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/server/packet/ServerReadyPacket.java +++ /dev/null @@ -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); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/Row.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/Row.java index 51f43e244..083f43413 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/Row.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/Row.java @@ -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 { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java index e682ab51e..9bae81a48 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java @@ -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> columnList = new ArrayList>(); - columnList.add(new ColumnUuid("playerUuid", 256, event.getUniqueId())); + columnList.add(new ColumnVarChar("playerUuid", 256, event.getUniqueId().toString())); List rows = table.retrieve(columnList); // Same here. diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnUuid.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnUuid.java deleted file mode 100644 index 6c83cc976..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/column/ColumnUuid.java +++ /dev/null @@ -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 -{ - 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); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusRepository.java index 64bbf8260..b66fa0cf4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusRepository.java @@ -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 diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/.classpath b/Plugins/Mineplex.DDoSProtectionSwitcher/.classpath index dadc9af73..a622fd726 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/.classpath +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/.classpath @@ -6,5 +6,6 @@ + diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java index a1778b1ad..af5042bc5 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java @@ -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 _processes = new HashSet(); 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 recordsToDelete = new ArrayList(); List recordsToAdd = new ArrayList(); List recordsToModify = new ArrayList(); - + // 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 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 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() + { + 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; + } } } diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java index 1b4d15573..f3d0edc77 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java @@ -118,10 +118,7 @@ public class DnsMadeEasyRepository } } } - - System.out.println("Offline count : " + countOffline); - - return false; - //countOffline >= 20; + + return countOffline >= 20; } } diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/GenericRunnable.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/GenericRunnable.java new file mode 100644 index 000000000..dd6cc1a7b --- /dev/null +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/GenericRunnable.java @@ -0,0 +1,6 @@ +package mineplex.ddos; + +public interface GenericRunnable +{ + void run(T t); +} diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/ProcessRunner.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/ProcessRunner.java new file mode 100644 index 000000000..744cab76f --- /dev/null +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/ProcessRunner.java @@ -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 _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 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(); + } + } + } diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiPutCall.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiPutCall.java index abb6def19..e5cf95b52 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiPutCall.java +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiPutCall.java @@ -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()) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 7a0649531..d4e894465 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -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); diff --git a/Website/LOC.Website.Common/Models/AccountAdministrator.cs b/Website/LOC.Website.Common/Models/AccountAdministrator.cs index a9f4d8da5..9dfd7d5f8 100644 --- a/Website/LOC.Website.Common/Models/AccountAdministrator.cs +++ b/Website/LOC.Website.Common/Models/AccountAdministrator.cs @@ -69,7 +69,7 @@ { var account = repository.Where(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(x => x.Name == "ALL").First(); repository.Attach(account.Rank); - edited = true; } - if (edited) - repository.CommitChanges(); + repository.CommitChanges(); return account; } diff --git a/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml b/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml index bc5c764cc..c87a6e316 100644 --- a/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml +++ b/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml @@ -1,11 +1,13 @@  + + @@ -16,50 +18,53 @@ - + + + - + + + - + - + - + - + + - + - - - + @@ -70,32 +75,31 @@ - + + - - + - - - + + - - + + @@ -103,40 +107,42 @@ - - + - - + - - + + + - + + + - + + - - + + @@ -150,61 +156,54 @@ - - - - + - - - + - - - + + + - + - - - + - - + + - + - + @@ -212,61 +211,62 @@ - - + + - + - - - - + + + - + - + - + + - - + + - + + - - + + - + - - + + - - + + - + + - @@ -280,26 +280,21 @@ - + - - - - - + - @@ -307,16 +302,16 @@ - + + - @@ -325,7 +320,9 @@ + + @@ -336,20 +333,23 @@ - - + + + - + + + @@ -357,6 +357,8 @@ + + @@ -364,77 +366,78 @@ + - - - + - - + - - - - + - - + + - + - + + + + + + - - + + + @@ -442,98 +445,94 @@ - + - + - + - - + - + - - + + - + - + - + - - + - - + - - + + - + - - + + - + - - - - - + + + + + - + + - - @@ -544,19 +543,16 @@ - + - - + - - - + @@ -570,15 +566,17 @@ + + + - @@ -588,6 +586,7 @@ + @@ -598,21 +597,22 @@ - - + + + - - + + @@ -620,51 +620,48 @@ - + - + - - + + - - + - - + - + - - + @@ -675,128 +672,130 @@ - + - + - + + + + + + - - - - + + + - + - - + + - + - + - + + - - + - + - + - - + + - + - + - - + - + - - + - - + + - + - - + + - + - - - - - + + + + + + - + + - - @@ -807,19 +806,16 @@ - + - - + - - - + @@ -833,15 +829,17 @@ + + + - @@ -851,6 +849,7 @@ + @@ -861,21 +860,22 @@ - - + + + - - + + @@ -883,7 +883,7 @@ - + @@ -891,43 +891,40 @@ - - + + - - + - - + - + - - + @@ -938,118 +935,121 @@ - + - + - + + + + + + - - + - + - - + + - + - + - + + - - + - + - + - - + + - + - + - - + - - + - - + + - + - - + + - + - - - - - + + + + + + - + \ No newline at end of file