diff --git a/2006Redone Server/data/secrets.json b/2006Redone Server/data/secrets.json new file mode 100644 index 00000000..d0bd3246 --- /dev/null +++ b/2006Redone Server/data/secrets.json @@ -0,0 +1 @@ +{"bot-token":"","powpass":""} \ No newline at end of file diff --git a/2006Redone Server/src/redone/Server.java b/2006Redone Server/src/redone/Server.java index 5b6c0b39..e3763f44 100644 --- a/2006Redone Server/src/redone/Server.java +++ b/2006Redone Server/src/redone/Server.java @@ -8,7 +8,9 @@ import org.apache.mina.common.IoAcceptor; import org.apache.mina.transport.socket.nio.SocketAcceptor; import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; -import redone.discord.JavaCord; +import redone.integrations.PlayersOnlineWebsite; +import redone.integrations.SettingsLoader; +import redone.integrations.discord.JavaCord; import redone.event.CycleEventHandler; import redone.event.TaskScheduler; import redone.game.content.minigames.FightCaves; @@ -52,24 +54,24 @@ public class Server { public static int[] cannonsY = new int [50]; public static String[] cannonsO = new String [50]; public static boolean sleeping; - public static final int cycleRate; + private static final int cycleRate; public static boolean UpdateServer = false; public static long lastMassSave = System.currentTimeMillis(); private static IoAcceptor acceptor; private static ConnectionHandler connectionHandler; private static ConnectionThrottleFilter throttleFilter; - public static boolean shutdownServer = false; + private static boolean shutdownServer = false; public static int garbageCollectDelay = 40; public static boolean shutdownClientHandler; - public static int serverlistenerPort; + private static int serverlistenerPort; public static ItemHandler itemHandler = new ItemHandler(); public static PlayerHandler playerHandler = new PlayerHandler(); public static NpcHandler npcHandler = new NpcHandler(); - public static ShopHandler shopHandler = new ShopHandler(); + private static ShopHandler shopHandler = new ShopHandler(); public static ObjectHandler objectHandler = new ObjectHandler(); public static ObjectManager objectManager = new ObjectManager(); public static FightCaves fightCaves = new FightCaves(); - public static PestControl pestControl = new PestControl(); + private static PestControl pestControl = new PestControl(); public static Trawler trawler = new Trawler(); private static final TaskScheduler scheduler = new TaskScheduler(); public static ClanChatHandler clanChat = new ClanChatHandler(); @@ -82,7 +84,7 @@ public class Server { * Port and Cycle rate. */ static { - serverlistenerPort = 43594; + serverlistenerPort = 43595; cycleRate = 600; shutdownServer = false; } @@ -113,9 +115,9 @@ public class Server { System.out.println("Launching " + Constants.SERVER_NAME + "..."); /** - * Start Discord Bot - */ - + * Start Integration Services + **/ + SettingsLoader.loadSettings(); JavaCord.init(); /** @@ -168,6 +170,7 @@ public class Server { FightPits.process(); pestControl.process(); CycleEventHandler.getSingleton().process(); + PlayersOnlineWebsite.addUpdatePlayersOnlineTask(); if (System.currentTimeMillis() - lastMassSave > 300000) { for (Player p : PlayerHandler.players) { if (p == null) { diff --git a/2006Redone Server/src/redone/integrations/PlayersOnlineWebsite.java b/2006Redone Server/src/redone/integrations/PlayersOnlineWebsite.java new file mode 100644 index 00000000..4b970f45 --- /dev/null +++ b/2006Redone Server/src/redone/integrations/PlayersOnlineWebsite.java @@ -0,0 +1,37 @@ +package redone.integrations; + +import redone.game.players.PlayerHandler; + +import java.io.IOException; +import java.net.URL; + +public class PlayersOnlineWebsite { + + static String password; + + private static void setWebsitePlayersOnline(int amount) throws IOException { + URL url; + url = new URL("https://2006rebotted.tk/playersonline.php?pass=" + password + "&amount=" + amount); + url.openStream().close(); + System.out.println("Test!"); + } + + private static int count = 50; + public static void addUpdatePlayersOnlineTask() { + if (!password.equals("")) { + if (count == 0) { + try { + setWebsitePlayersOnline(PlayerHandler.getPlayerCount()); + count = 50; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + count--; + } + } else { + System.out.println("No Players Online On Website Password Set So Task Stopped"); + } + } +} diff --git a/2006Redone Server/src/redone/integrations/SettingsLoader.java b/2006Redone Server/src/redone/integrations/SettingsLoader.java new file mode 100644 index 00000000..04bbe4a0 --- /dev/null +++ b/2006Redone Server/src/redone/integrations/SettingsLoader.java @@ -0,0 +1,40 @@ +package redone.integrations; + +import org.json.JSONObject; +import redone.integrations.discord.JavaCord; + +import java.io.*; +import java.util.stream.Collectors; + +public class SettingsLoader { + private static void initialize() { + JSONObject main = new JSONObject(); + main + .put("bot-token", "") + .put("powpass", ""); + try { + BufferedWriter br = new BufferedWriter(new FileWriter("data/secrets.json")); + br.write(main.toString()); + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void loadSettings() throws IOException { + if (!new File("data/secrets.json").exists()) { + initialize(); + System.out.println("Please open \"data/secrets.json\" file and enter your discord token bot there!"); + System.out.println("Please open \"data/secrets.json\" file and enter your Players Online On Website Password there!"); + + } else { + BufferedReader br = new BufferedReader(new FileReader("data/secrets.json")); + String out = br.lines().collect(Collectors.joining("\n")); + JSONObject obj = new JSONObject(out); + + JavaCord.token = obj.getString("bot-token"); + PlayersOnlineWebsite.password = obj.getString("powpass"); + + } + } +} diff --git a/2006Redone Server/src/redone/discord/JavaCord.java b/2006Redone Server/src/redone/integrations/discord/JavaCord.java similarity index 71% rename from 2006Redone Server/src/redone/discord/JavaCord.java rename to 2006Redone Server/src/redone/integrations/discord/JavaCord.java index a2067a50..ee93b136 100644 --- a/2006Redone Server/src/redone/discord/JavaCord.java +++ b/2006Redone Server/src/redone/integrations/discord/JavaCord.java @@ -1,4 +1,4 @@ -package redone.discord; +package redone.integrations.discord; import org.javacord.api.DiscordApi; import org.javacord.api.DiscordApiBuilder; @@ -7,9 +7,9 @@ import org.javacord.api.entity.message.MessageBuilder; import org.javacord.api.util.logging.ExceptionLogger; import redone.game.players.PlayerHandler; -import java.io.*; -import java.util.stream.Collectors; -import org.json.JSONObject; +import java.io.IOException; + +import static redone.integrations.SettingsLoader.loadSettings; /** * @author Patrity || https://www.rune-server.ee/members/patrity/ @@ -18,7 +18,7 @@ import org.json.JSONObject; public class JavaCord { private static String serverName = "2006-ReBotted"; - private static String token; + public static String token; private static DiscordApi api = null; public static void init() throws IOException { @@ -66,30 +66,4 @@ public class JavaCord { e.printStackTrace(); } } - - private static void initialize() { - JSONObject main = new JSONObject(); - main.put("token", ""); - try { - BufferedWriter br = new BufferedWriter(new FileWriter("data/discord.json")); - br.write(main.toString()); - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static void loadSettings() throws IOException { - if (!new File("data/discord.json").exists()) { - initialize(); - System.out.println("Please open \"data/discord.json\" file and enter your discord token bot there!"); - } else { - BufferedReader br = new BufferedReader(new FileReader("data/discord.json")); - String out = br.lines().collect(Collectors.joining("\n")); - JSONObject obj = new JSONObject(out); - - token = obj.getString("token"); - - } - } } \ No newline at end of file diff --git a/CompiledServer/production/2006rebotted/META-INF/2006rebotted.kotlin_module b/CompiledServer/production/2006rebotted/META-INF/2006rebotted.kotlin_module new file mode 100644 index 00000000..2983af70 Binary files /dev/null and b/CompiledServer/production/2006rebotted/META-INF/2006rebotted.kotlin_module differ diff --git a/CompiledServer/production/2006rebotted/redone/Server.class b/CompiledServer/production/2006rebotted/redone/Server.class index 56c7f70b..29ee460d 100644 Binary files a/CompiledServer/production/2006rebotted/redone/Server.class and b/CompiledServer/production/2006rebotted/redone/Server.class differ diff --git a/CompiledServer/production/2006rebotted/redone/discord/JavaCord.class b/CompiledServer/production/2006rebotted/redone/discord/JavaCord.class deleted file mode 100644 index 026b5a0c..00000000 Binary files a/CompiledServer/production/2006rebotted/redone/discord/JavaCord.class and /dev/null differ diff --git a/CompiledServer/production/2006rebotted/redone/game/content/skills/core/Mining.class b/CompiledServer/production/2006rebotted/redone/game/content/skills/core/Mining.class index 20dd0b57..7a4bd2b1 100644 Binary files a/CompiledServer/production/2006rebotted/redone/game/content/skills/core/Mining.class and b/CompiledServer/production/2006rebotted/redone/game/content/skills/core/Mining.class differ diff --git a/CompiledServer/production/2006rebotted/redone/integrations/PlayersOnlineWebsite.class b/CompiledServer/production/2006rebotted/redone/integrations/PlayersOnlineWebsite.class new file mode 100644 index 00000000..2f180548 Binary files /dev/null and b/CompiledServer/production/2006rebotted/redone/integrations/PlayersOnlineWebsite.class differ diff --git a/CompiledServer/production/2006rebotted/redone/integrations/SettingsLoader.class b/CompiledServer/production/2006rebotted/redone/integrations/SettingsLoader.class new file mode 100644 index 00000000..65208ae3 Binary files /dev/null and b/CompiledServer/production/2006rebotted/redone/integrations/SettingsLoader.class differ diff --git a/CompiledServer/production/2006rebotted/redone/integrations/discord/JavaCord.class b/CompiledServer/production/2006rebotted/redone/integrations/discord/JavaCord.class new file mode 100644 index 00000000..7f56e5a9 Binary files /dev/null and b/CompiledServer/production/2006rebotted/redone/integrations/discord/JavaCord.class differ