Players Online On Website, Changed packaging a little & added SettingsLoader (#44)

This commit is contained in:
Daniel Ginovker
2019-10-09 17:30:43 -04:00
committed by GitHub
parent 1f49bff69d
commit b97a843428
12 changed files with 96 additions and 41 deletions
+1
View File
@@ -0,0 +1 @@
{"bot-token":"","powpass":""}
+13 -10
View File
@@ -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) {
@@ -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");
}
}
}
@@ -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");
}
}
}
@@ -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");
}
}
}