mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 08:39:04 +00:00
Merge The File&Game Servers Into One Module (#519)
* Merge The File&Game Servers Into One Module * Make SettingsLoader A GameConstants ConfigLoader If A Config File Isn't Used, The Server Will Fall Back To The Defaults Set In GameConstants.java Config Files Can Be Loaded With The "-c/-config configfilelocation.json" Added A Default Prefilled ServerConfig.json * Update ConfigLoader * Bring Back Independant "Secrets" Loader For External Password Stuff * Added A Bunch More Vars To The ConfigLoader * Included A Sample "Server Config" * Also Updated README.md As Parabot Is No Longer Maintained & We No Longer Have A FileServer Module * Bundle FileServer with Server (docker) * Remove /udp and http port * Update .gitignore * Move FileServer from `org.apollo.jagcached` → `org/apollo/jagcached` * Tidy GameConstants & Add More Vars To ConfigLoader * Organised Up GameConstants A Little To Separate ConfigLoader Vars From The Rest * Added Some More Variables To Be Loaded Through The ConfigLoader * Fix A Derp Caused By Laziness * Add -c/-config arg to README.md * Enable FileServer By Default Co-authored-by: Danial <admin@redsparr0w.com>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package com.rs2;
|
||||
|
||||
import com.rs2.integrations.PlayersOnlineWebsite;
|
||||
import com.rs2.integrations.RegisteredAccsWebsite;
|
||||
import com.rs2.integrations.discord.JavaCord;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConfigLoader {
|
||||
|
||||
public static void loadSettings(String config) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new FileReader(config));
|
||||
String out = br.lines().collect(Collectors.joining("\n"));
|
||||
JSONObject obj = new JSONObject(out);
|
||||
|
||||
if(obj.has("server_name"))
|
||||
GameConstants.SERVER_NAME = obj.getString("server_name");
|
||||
if(obj.has("website_link"))
|
||||
GameConstants.WEBSITE_LINK = obj.getString("website_link");
|
||||
if(obj.has("debug"))
|
||||
GameConstants.SERVER_DEBUG = obj.getBoolean("debug");
|
||||
if(obj.has("file_server"))
|
||||
GameConstants.FILE_SERVER = obj.getBoolean("file_server");
|
||||
if(obj.has("world_id"))
|
||||
GameConstants.WORLD = obj.getInt("world_id");
|
||||
if(obj.has("members_only"))
|
||||
GameConstants.MEMBERS_ONLY = obj.getBoolean("members_only");
|
||||
if(obj.has("tutorial_island_enabled"))
|
||||
GameConstants.TUTORIAL_ISLAND = obj.getBoolean("tutorial_island_enabled");
|
||||
if(obj.has("party_room_enabled"))
|
||||
GameConstants.PARTY_ROOM_DISABLED = !obj.getBoolean("party_room_enabled");
|
||||
if(obj.has("clues_enabled"))
|
||||
GameConstants.CLUES_ENABLED = obj.getBoolean("clues_enabled");
|
||||
if(obj.has("admin_can_trade"))
|
||||
GameConstants.ADMIN_CAN_TRADE = obj.getBoolean("admin_can_trade");
|
||||
if(obj.has("admin_can_drop_items"))
|
||||
GameConstants.ADMIN_DROP_ITEMS = obj.getBoolean("admin_can_drop_items");
|
||||
if(obj.has("admin_can_sell"))
|
||||
GameConstants.ADMIN_CAN_SELL_ITEMS = obj.getBoolean("admin_can_sell");
|
||||
if(obj.has("respawn_x"))
|
||||
GameConstants.RESPAWN_X = obj.getInt("respawn_x");
|
||||
if(obj.has("respawn_y"))
|
||||
GameConstants.RESPAWN_Y = obj.getInt("respawn_y");
|
||||
if(obj.has("save_timer"))
|
||||
GameConstants.SAVE_TIMER = obj.getInt("save_timer");
|
||||
if(obj.has("timeout"))
|
||||
GameConstants.TIMEOUT = obj.getInt("timeout");
|
||||
if(obj.has("item_requirements"))
|
||||
GameConstants.ITEM_REQUIREMENTS = obj.getBoolean("item_requirements");
|
||||
if(obj.has("xp_rate"))
|
||||
GameConstants.XP_RATE = obj.getDouble("xp_rate");
|
||||
if(obj.has("max_players"))
|
||||
GameConstants.MAX_PLAYERS = obj.getInt("max_players");
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
JSONObject main = new JSONObject();
|
||||
main
|
||||
.put("bot-token", "")
|
||||
.put("websitepass", "")
|
||||
.put("erssecret", "");
|
||||
try {
|
||||
BufferedWriter br = new BufferedWriter(new FileWriter("data/secrets.json"));
|
||||
br.write(main.toString());
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadSecrets() 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 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);
|
||||
|
||||
/*
|
||||
* Sets External Services Vars
|
||||
*/
|
||||
if(obj.has("bot-token"))
|
||||
JavaCord.token = obj.getString("bot-token");
|
||||
if(obj.has("websitepass"))
|
||||
PlayersOnlineWebsite.password = obj.getString("websitepass");
|
||||
RegisteredAccsWebsite.password = obj.getString("websitepass");
|
||||
if(obj.has("erssecret"))
|
||||
GameEngine.ersSecret = obj.getString("erssecret");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,43 +2,60 @@ package com.rs2;
|
||||
|
||||
public class GameConstants {
|
||||
|
||||
public final static boolean SERVER_DEBUG = false;
|
||||
/**
|
||||
* The Variables Below Can Be Also Changed On Server Startup By Using The ConfigLoader
|
||||
*
|
||||
* SERVER_NAME Sets The Name The Server Will Use
|
||||
* WEBSITE_LINK Defines The Server Website Links
|
||||
* WORLD Sets The Servers World ID
|
||||
* MAX_PLAYERS Sets The Maximum Amount Of Players Allow To Be Logged In At Once
|
||||
* TIMEOUT Sets The Amount Of Time Before A Player Timeouts From A Bad Connection
|
||||
* SAVE_TIMER Sets In Seconds How Often The Server Shouls Auto-Save All Characters
|
||||
* RESPAWN_X Sets The X Coordinate That You Will Respawn At After Death
|
||||
* RESPAWN_Y Sets The Y Coordinate That You Will Respawn At After Death
|
||||
* FILE_SERVER Sets Whether The FileServer Should Run With The Server
|
||||
* SERVER_DEBUG Sets Whether The Server Should Start In Debug Mode
|
||||
* MEMBERS_ONLY Sets Whether The World Is Members Only
|
||||
* TUTORIAL_ISLAND Sets Enables/Disables Tutorial Island For Players On First Login
|
||||
* PARTY_ROOM_DISABLED Enables/Disables The Party Room Should Be Disabled
|
||||
* CLUES_ENABLED Enables/Disables Clue Scrolls
|
||||
* ITEM_REQUIREMENTS Enables/Disables Item Requirements for All Players
|
||||
* ADMIN_CAN_TRADE Defines Whether Admins Can Trade
|
||||
* ADMIN_DROP_ITEMS Defines Whether Admins Can Drop Items
|
||||
* ADMIN_CAN_SELL_ITEMS Defines Whether Admins Can Sell Items
|
||||
* XP_RATE Sets The XP Rate Multiplier For All Players/Skills
|
||||
*/
|
||||
public static String SERVER_NAME = "2006Scape", WEBSITE_LINK = "https://2006Scape.org";
|
||||
public static int WORLD = 1, MAX_PLAYERS = 200, TIMEOUT = 60, SAVE_TIMER = 120,
|
||||
RESPAWN_X = 3222, RESPAWN_Y = 3218;
|
||||
public static boolean FILE_SERVER = true, SERVER_DEBUG = false, MEMBERS_ONLY = false, TUTORIAL_ISLAND = false,
|
||||
PARTY_ROOM_DISABLED = false, CLUES_ENABLED = true, ITEM_REQUIREMENTS = true,
|
||||
ADMIN_CAN_TRADE = false, ADMIN_DROP_ITEMS = false, ADMIN_CAN_SELL_ITEMS = false;
|
||||
public static double XP_RATE = 1;
|
||||
|
||||
public final static String SERVER_NAME = "2006Scape", SERVER_VERSION = "Server Stage v " + GameConstants.TEST_VERSION + ".";
|
||||
|
||||
public final static String WEBSITE_LINK = "https://2006Scape.org";
|
||||
|
||||
/**
|
||||
* The Variables Below Should Only Be Changed If You Understand What You Are Doing
|
||||
*/
|
||||
|
||||
public final static String SERVER_VERSION = "Server Stage v " + GameConstants.TEST_VERSION + ".";
|
||||
public final static boolean WEBSITE_TOTAL_CHARACTERS_INTEGRATION = false;
|
||||
public final static double TEST_VERSION = 2.3;
|
||||
|
||||
public final static int ITEM_LIMIT = 15000, MAXITEM_AMOUNT = Integer.MAX_VALUE, CLIENT_VERSION = 999999,
|
||||
WORLD = 1, IPS_ALLOWED = 250, CONNECTION_DELAY = 100,
|
||||
MESSAGE_DELAY = 6000, MAX_PLAYERS = 200, REQ_AMOUNT = 150;
|
||||
IPS_ALLOWED = 250, CONNECTION_DELAY = 100,
|
||||
MESSAGE_DELAY = 6000, REQ_AMOUNT = 150;
|
||||
|
||||
public final static boolean SOUND = true,
|
||||
GUILDS = true,
|
||||
PARTY_ROOM_DISABLED = false,
|
||||
public final static boolean sendServerPackets = false, SOUND = true, GUILDS = true,
|
||||
PRINT_OBJECT_ID = false, EXPERIMENTS = false;
|
||||
|
||||
public static int[] SIDEBARS = { 2423, 3917, 638, 3213, 1644, 5608, 1151,
|
||||
18128, 5065, 5715, 2449, 904, 147, 962 };
|
||||
|
||||
public static boolean TUTORIAL_ISLAND = false,
|
||||
MEMBERS_ONLY = false, sendServerPackets = false,
|
||||
CLUES_ENABLED = true;
|
||||
|
||||
public final static int[] FUN_WEAPONS = { 2460, 2461, 2462, 2463, 2464,
|
||||
2465, 2466, 2467, 2468, 2469, 2470, 2471, 2471, 2473, 2474, 2475,
|
||||
2476, 2477 }; // fun weapons for dueling
|
||||
|
||||
public static boolean ADMIN_CAN_TRADE = false; // can admins trade?
|
||||
|
||||
public final static boolean ADMIN_DROP_ITEMS = false;
|
||||
|
||||
public final static boolean ADMIN_CAN_SELL_ITEMS = false;
|
||||
|
||||
public final static int RESPAWN_X = 3222; // when dead respawn here
|
||||
|
||||
public final static int RESPAWN_Y = 3218;
|
||||
|
||||
public final static int DUELING_RESPAWN_X = 3362;
|
||||
|
||||
@@ -46,16 +63,10 @@ public class GameConstants {
|
||||
|
||||
public final static int NO_TELEPORT_WILD_LEVEL = 20;
|
||||
|
||||
public final static boolean ITEM_REQUIREMENTS = true;
|
||||
|
||||
public final static int CASTLE_WARS_X = 2439;
|
||||
|
||||
public final static int CASTLE_WARS_Y = 3087;
|
||||
|
||||
public static double XP_RATE = 1;
|
||||
|
||||
public final static int SAVE_TIMER = 120; // save every x seconds
|
||||
|
||||
public final static int NPC_RANDOM_WALK_DISTANCE = 5;
|
||||
|
||||
public final static int NPC_FOLLOW_DISTANCE = 10;
|
||||
@@ -69,8 +80,6 @@ public class GameConstants {
|
||||
"skorge", "tortured soul", "undead chicken", "undead cow", "undead one", "undead troll", "zombie", "zombie rat", "zogre"
|
||||
};
|
||||
|
||||
public final static int TIMEOUT = 60;
|
||||
|
||||
public final static int CYCLE_TIME = 600;
|
||||
|
||||
public final static int BUFFER_SIZE = 10000;
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.rs2.game.players.PlayerSave;
|
||||
import com.rs2.game.shops.ShopHandler;
|
||||
import com.rs2.integrations.PlayersOnlineWebsite;
|
||||
import com.rs2.integrations.RegisteredAccsWebsite;
|
||||
import com.rs2.integrations.SettingsLoader;
|
||||
import com.rs2.integrations.discord.DiscordActivity;
|
||||
import com.rs2.integrations.discord.JavaCord;
|
||||
import com.rs2.net.ConnectionHandler;
|
||||
@@ -49,6 +48,7 @@ import com.rs2.world.ObjectHandler;
|
||||
import com.rs2.world.ObjectManager;
|
||||
import com.rs2.world.clip.ObjectDefinition;
|
||||
import com.rs2.world.clip.RegionFactory;
|
||||
import org.apollo.jagcached.FileServer;
|
||||
|
||||
/**
|
||||
* Server.java
|
||||
@@ -141,6 +141,24 @@ public class GameEngine {
|
||||
|
||||
public static void main(java.lang.String[] args)
|
||||
throws NullPointerException, IOException {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i].startsWith("-") && (i + 1) < args.length && !args[i + 1].startsWith("-")) {
|
||||
switch(args[i]) {
|
||||
case "-c":
|
||||
case "-config":
|
||||
try {
|
||||
//TODO Load A Default Config File When Arg Not Used
|
||||
System.out.println("Loading External Config..");
|
||||
ConfigLoader.loadSettings(args[++i]);
|
||||
System.out.println("Loaded Config File " + args[i]);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Config File Not Found");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Starting game engine..");
|
||||
if (GameConstants.SERVER_DEBUG) {
|
||||
System.out.println("@@@@ DEBUG MODE IS ENABLED @@@@");
|
||||
@@ -163,12 +181,24 @@ public class GameEngine {
|
||||
/**
|
||||
* Starting Up Server
|
||||
*/
|
||||
System.out.println("Launching " + GameConstants.SERVER_NAME + "...");
|
||||
System.out.println("Launching " + GameConstants.SERVER_NAME + " World: " + GameConstants.WORLD + "...");
|
||||
|
||||
/**
|
||||
* Starts The File Server If Enabled In GameConstants
|
||||
*/
|
||||
if(GameConstants.FILE_SERVER) {
|
||||
FileServer fs = new FileServer();
|
||||
try {
|
||||
fs.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Integration Services
|
||||
**/
|
||||
SettingsLoader.loadSettings();
|
||||
ConfigLoader.loadSecrets();
|
||||
JavaCord.init();
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.rs2.game.players.PlayerHandler;
|
||||
|
||||
public class PlayersOnlineWebsite {
|
||||
|
||||
static String password;
|
||||
public static String password;
|
||||
private static boolean hasntwared = true;
|
||||
|
||||
private static void setWebsitePlayersOnline(int amount) throws IOException {
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.net.URL;
|
||||
import com.rs2.GameConstants;
|
||||
|
||||
public class RegisteredAccsWebsite {
|
||||
static String password;
|
||||
public static String password;
|
||||
private static boolean hasntwarned = true;
|
||||
|
||||
private static void setAccountsRegistered(int amount) throws IOException {
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.rs2.integrations;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.rs2.GameEngine;
|
||||
import com.rs2.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("websitepass", "")
|
||||
.put("erssecret", "");
|
||||
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 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("websitepass");
|
||||
RegisteredAccsWebsite.password = obj.getString("websitepass");
|
||||
GameEngine.ersSecret = obj.getString("erssecret");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user