diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java index 4ad382fbf..008d6bc91 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/InternetStatus.java @@ -24,7 +24,7 @@ public class InternetStatus implements Runnable _repository = new StatusRepository(address, us); _repository.initialize(); - _plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 5L, TimeUnit.MINUTES); + _plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.MINUTES); } @Override @@ -41,7 +41,7 @@ public class InternetStatus implements Runnable return true; else if (testUrl("www.bing.com")) return true; - + return false; } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java index c9a4a77cc..3b300b28d 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/status/StatusRepository.java @@ -15,8 +15,8 @@ public class StatusRepository private boolean _us; private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));"; - private static String INSERT_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated) values(?, ?, ?, now()) ON DUPLICATE KEY UPDATE online = VALUES(online);"; - private static String INSERT_ONLINE_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated, lastOnline) values(?, ?, ?, now(), now()) ON DUPLICATE KEY UPDATE online = VALUES(online), lastOnline = VALUES(lastOnline);"; + private static String INSERT_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated) values(?, ?, ?, now()) ON DUPLICATE KEY UPDATE online = VALUES(online), updated = VALUES(updated);"; + private static String INSERT_ONLINE_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated, lastOnline) values(?, ?, ?, now(), now()) ON DUPLICATE KEY UPDATE online = VALUES(online), updated = VALUES(updated), lastOnline = VALUES(lastOnline);"; public StatusRepository(String address, boolean us) { diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java index ed9cf05be..a1778b1ad 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DDoSProtectionSwitcher.java @@ -1,103 +1,130 @@ package mineplex.ddos; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; +import mineplex.ddos.api.ApiDeleteCall; import mineplex.ddos.api.ApiGetCall; import mineplex.ddos.api.ApiPostCall; import mineplex.ddos.api.ApiPutCall; -import mineplex.ddos.api.token.ARecord; -import mineplex.ddos.api.token.CNameRecord; import mineplex.ddos.api.token.DnsRecord; import mineplex.ddos.api.token.DomainRecords; public class DDoSProtectionSwitcher { + private static DnsMadeEasyRepository _repository = null; + public static void main(String args[]) { - - List records = new ArrayList(); + try + { + Class.forName("com.mysql.jdbc.Driver"); + } + catch (ClassNotFoundException e1) + { + e1.printStackTrace(); + } - /* - records.add(new ARecord("us", "108.178.20.166", 300)); - records.add(new ARecord("us", "108.163.217.110", 300)); - records.add(new ARecord("us", "108.178.34.142", 300)); - records.add(new ARecord("us", "108.163.254.134", 300)); - records.add(new ARecord("us", "108.163.216.250", 300)); - records.add(new ARecord("us", "108.163.216.106", 300)); - records.add(new ARecord("us", "184.154.215.170", 300)); - records.add(new ARecord("us", "96.127.174.206", 300)); - records.add(new ARecord("us", "184.154.127.10", 300)); - records.add(new ARecord("us", "96.127.174.146", 300)); - records.add(new ARecord("us", "108.178.7.206", 300)); - records.add(new ARecord("us", "184.154.39.146", 300)); - records.add(new ARecord("us", "108.163.217.250", 300)); - records.add(new ARecord("us", "69.175.15.242", 300)); - records.add(new ARecord("us", "107.6.129.126", 300)); - records.add(new ARecord("us", "108.163.222.174", 300)); - records.add(new ARecord("us", "108.178.34.118", 300)); - records.add(new ARecord("us", "69.175.4.38", 300)); - records.add(new ARecord("us", "107.6.158.78", 300)); - records.add(new ARecord("us", "184.154.13.118", 300)); - */ + _repository = new DnsMadeEasyRepository(); - records.add(new ARecord("eu", "107.6.176.194", 300)); - records.add(new ARecord("eu", "107.6.176.122", 300)); - records.add(new ARecord("eu", "107.6.176.166", 300)); - records.add(new ARecord("eu", "107.6.176.14", 300)); - records.add(new ARecord("eu", "107.6.176.114", 300)); - records.add(new ARecord("eu", "107.6.176.26", 300)); - records.add(new ARecord("eu", "107.6.176.110", 300)); - records.add(new ARecord("eu", "107.6.176.138", 300)); + while (true) + { + if (_repository.switchToDDOSProt()) + { + 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) + { + if (record.type.equalsIgnoreCase("A")) + { + if (record.name.equalsIgnoreCase("neustar")) + { + record.name = "us"; + recordsToModify.add(record); + } + else if (record.name.equalsIgnoreCase("us")) + { + record.name = "us2"; + recordsToModify.add(record); + } + else if (record.name.equalsIgnoreCase("eu")) + { + record.name = "eu2"; + recordsToModify.add(record); + } + } + } + + 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); - /* - * - * 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 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); } } } - * - * /* // Switch on ddos protection for (DnsRecord record : records.data) - * { if (record.type.equalsIgnoreCase("A")) { if - * (record.name.equalsIgnoreCase("neustar")) { record.name = "us"; - * recordsToModify.put(record.id, record); } else if - * (record.name.equalsIgnoreCase("us")) { record.name = "us2"; - * recordsToModify.put(record.id, record); } else if - * (record.name.equalsIgnoreCase("eu")) { record.name = "eu2"; - * recordsToModify.put(record.id, record); } } } - * - * recordsToAdd.add(new CNameRecord("eu", "us", 300)); - * - * - * if (recordsToAdd.size() > 0) new - * ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, - * "/records/", "createMulti").Execute(records); - * - * if (recordsToModify.size() > 0) { new - * ApiPutCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, - * "/records/", "updateMulti").Execute(recordsToModify); } - * - * if (recordsToDelete.size() > 0) new - * ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, - * "/records/", "createMulti").Execute(records); - * - * System.exit(0); - */ + if (recordsToModify.size() > 0) + { + new ApiPutCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "updateMulti").Execute(recordsToModify); + } + + if (recordsToDelete.size() > 0) + { + StringBuilder idBuilder = new StringBuilder(); + + for (DnsRecord record : recordsToDelete) + { + if (idBuilder.length() != 0) + idBuilder.append("&"); + + idBuilder.append("ids=" + record.id); + } + + new ApiDeleteCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records?" + idBuilder.toString()).Execute(); + } + } + + try + { + System.out.println("Natural Sleep"); + Thread.sleep(60000); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } +/* + // 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)); +*/ } } diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java index 6f190aa2e..1b4d15573 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java @@ -1,9 +1,127 @@ package mineplex.ddos; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; + public class DnsMadeEasyRepository { - public DnsMadeEasyRepository() + private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; + private String _userName = "root"; + private String _password = "tAbechAk3wR7tuTh"; + + private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));"; + private static String SELECT_SERVERS = "SELECT updated, lastOnline, us, now() FROM bungeeOnlineStatus;"; + + public void initialize() { + Connection connection = null; + PreparedStatement preparedStatement = null; + try + { + connection = DriverManager.getConnection(_connectionString, _userName, _password); + + // Create table + preparedStatement = connection.prepareStatement(CREATE_TABLE); + preparedStatement.execute(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + + if (connection != null) + { + try + { + connection.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } + + public boolean switchToDDOSProt() + { + Connection connection = null; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + int countOffline = 0; + + try + { + connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = connection.prepareStatement(SELECT_SERVERS); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) + { + long current = dateFormat.parse(resultSet.getString(4)).getTime(); + long updated = dateFormat.parse(resultSet.getString(1)).getTime(); + long lastOnline = dateFormat.parse(resultSet.getString(2)).getTime(); + + if (current - updated < 70000 && current - lastOnline > 660000) + countOffline++; + } + } + 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(); + } + } + } + + System.out.println("Offline count : " + countOffline); + + return false; + //countOffline >= 20; } } diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiDeleteCall.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiDeleteCall.java new file mode 100644 index 000000000..5e91aab89 --- /dev/null +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/api/ApiDeleteCall.java @@ -0,0 +1,19 @@ +package mineplex.ddos.api; + +import org.apache.http.client.methods.HttpDelete; + +public class ApiDeleteCall extends DnsMadeEasyApiCallBase +{ + public ApiDeleteCall(String apiUrl, int domainId, String category) + { + super(apiUrl, domainId, category); + } + + public void Execute() + { + HttpDelete request = new HttpDelete(ApiUrl + DomainId + Category); + System.out.println(request.getURI().toString()); + + System.out.println(execute(request)); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 1fce65064..ae8c909c4 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_7_R3.CraftWorld; import org.bukkit.entity.Egg; @@ -26,6 +27,8 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; @@ -53,6 +56,7 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.disguise.disguises.DisguiseSlime; import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.logger.Logger; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; @@ -101,6 +105,8 @@ public class HubManager extends MiniClientPlugin private HashMap _scoreboards = new HashMap(); private String _pigStacker = "0 - Nobody"; + + private ItemStack _ruleBook = null; private boolean _shuttingDown; @@ -146,6 +152,136 @@ public class HubManager extends MiniClientPlugin _statsManager = new StatsManager(plugin); ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true; + + _ruleBook = ItemStackFactory.Instance.CreateStack(Material.WRITTEN_BOOK, (byte)0, 1, "Rule Book", new String[] { }); + BookMeta meta = (BookMeta)_ruleBook.getItemMeta(); + + meta.addPage("§m-------------------§r\n" + + "Welcome to §6§lMineplex§r\n" + + "§r§0§l§r§m§0§m-------------------§r§0\n" + + "\n" + + "§2Please §0take a moment to read through this book!\n" + + "\n" + + "\n" + + "Part 1 - Rules\n" + + "\n" + + "Part 2 - FAQ\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l1.§§§r §4No§r spamming.\n" + + "\n" + + "§0This is sending too many messages and/or repeating the same message in a short period of time.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l2.§m§r §4No§0 use of excessive caps.\n" + + "\n" + + "This is sending messages with an excessive amount of capital letters.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l3.§r §4No§0 hacking or use of any unapproved mods.\n" + + "\n" + + "This means we do not tolerate any sort of hacked client or any unapproved mods, such as fly hacks.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l4.§r §4No§0 advertising non-Mineplex related links.\n" + + "\n" + + "This is when a link is sent in chat which directs others to non-Mineplex related content.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l5.§r §4No§0 trolling or use of any exploits.\n" + + "\n" + + "This means that abuse of bugs/glitches is not tolerated. You also may not do things such as teamkilling and/or blocking spawns.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§l6.§r §2Be§0 respectful to others, yourself, and the environment around you.\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lRules§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§rPlease report any bugs, exploits, and/or rule breakers on our forums with evidence.\n" + + "§omineplex.com/forums\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lWhat is stacker and how do you play it?\n" + + "\n" + + "§rStacker is a hub game where you can stack & throw players/mobs.\n" + + "\n" + + "§9Right-Click: pick up\n" + + "Left-Click: throw\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lHow do I get §b§lUltra§0 §lor §5§lHero§0§l?\n" + + "\n" + + "§r§0You are able to purchase these ranks through our shop on our website at:\n" + + "\n" + + "§owww.mineplex.com/shop\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lWhy hasn't my rank been applied yet?\n" + + "\n" + + "§m§rYour rank may take a while to be applied. If it has been over 24 hours please email:\n" + + "\n" + + "§osupport@mineplex.com\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lWhat do I do if I was wrongfully punished?\n" + + "\n" + + "§0If you believe you were wrongfully punished, please submit an appeal at:\n" + + "\n" + + "§omineplex.com/forums\n"); + + meta.addPage("§m-------------------\n" + + "§r §2§lFAQ§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "§lHow do I apply for Helper?\n" + + "\n" + + "§rYou may only apply for Helper if you have §bUltra §0or §5Hero§0.\n" + + "Apply at:\n" + + "§omineplex.com/application\n"); + + meta.addPage("§m-------------------\n" + + "§r §6§lThank you for \n" + + " reading!§r§0\n" + + "§m-------------------\n" + + "§r\n" + + "Remember to visit our website §2mineplex.com§0 for important news & updates!\n" + + "\n" + + "\n" + + " §c§lH§6§lA§a§lV§9§lE §c§lF§6§lU§a§lN§9§l!\n"); + + _ruleBook.setItemMeta(meta); } @Override @@ -288,6 +424,8 @@ public class HubManager extends MiniClientPlugin UtilInv.Clear(player); + player.getInventory().setItem(6, _ruleBook); + //Scoreboard Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); player.setScoreboard(board);