RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
OSRoyale.java
1package com.osroyale;
2
3import com.osroyale.content.WellOfGoodwill;
4import com.osroyale.content.bloodmoney.BloodChestEvent;
5import com.osroyale.content.clanchannel.ClanRepository;
6import com.osroyale.content.itemaction.ItemActionRepository;
7import com.osroyale.content.lms.LMSGameEvent;
8import com.osroyale.content.lms.loadouts.LMSLoadoutManager;
9import com.osroyale.content.lms.lobby.LMSLobbyEvent;
10import com.osroyale.content.mysterybox.MysteryBox;
11import com.osroyale.content.preloads.PreloadRepository;
12import com.osroyale.content.shootingstar.ShootingStar;
13import com.osroyale.content.skill.SkillRepository;
14import com.osroyale.content.tradingpost.TradingPost;
15import com.osroyale.content.triviabot.TriviaBot;
16import com.osroyale.content.wintertodt.Wintertodt;
17import com.osroyale.fs.cache.FileSystem;
18import com.osroyale.fs.cache.decoder.*;
19import com.osroyale.game.engine.GameEngine;
20import com.osroyale.game.plugin.PluginManager;
21import com.osroyale.game.service.*;
22import com.osroyale.game.task.impl.ClanUpdateEvent;
23import com.osroyale.game.task.impl.DoubleExperienceEvent;
24import com.osroyale.game.task.impl.MessageEvent;
25import com.osroyale.game.task.impl.PlayerSaveEvent;
26import com.osroyale.game.world.World;
27import com.osroyale.game.world.WorldType;
28import com.osroyale.game.world.cronjobs.Jobs;
29import com.osroyale.game.world.entity.combat.attack.listener.CombatListenerManager;
30import com.osroyale.game.world.entity.combat.strategy.npc.boss.skotizo.SkotizoEvent;
31import com.osroyale.game.world.entity.mob.npc.definition.NpcDefinition;
32import com.osroyale.game.world.entity.mob.player.BannedPlayers;
33import com.osroyale.game.world.entity.mob.player.IPBannedPlayers;
34import com.osroyale.game.world.entity.mob.player.IPMutedPlayers;
35import com.osroyale.game.world.entity.mob.player.profile.ProfileRepository;
36import com.osroyale.game.world.items.ItemDefinition;
37import com.osroyale.io.PacketListenerLoader;
38import com.osroyale.net.LoginExecutorService;
39import com.osroyale.net.discord.Discord;
40import com.osroyale.net.discord.DiscordPlugin;
41import com.osroyale.util.GameSaver;
42import com.osroyale.util.Stopwatch;
43import com.osroyale.util.parser.impl.*;
44import dev.advo.fs.FileServer;
45import org.apache.logging.log4j.LogManager;
46import org.apache.logging.log4j.Logger;
47import org.jire.tarnishps.OldToNew;
48import org.jire.tarnishps.objectexamines.ObjectExamines;
49import org.joda.time.DateTime;
50import org.joda.time.DateTimeZone;
51import plugin.click.item.ClueScrollPlugin;
52
53import java.io.IOException;
54import java.util.concurrent.TimeUnit;
55import java.util.concurrent.atomic.AtomicBoolean;
56
88
89public final class OSRoyale {
90
91 private static final Logger logger = LogManager.getLogger(OSRoyale.class);
92
93 public static final AtomicBoolean serverStarted = new AtomicBoolean(false);
94 public static final Stopwatch UPTIME = Stopwatch.start();
95
96 // services
97 private static final StartupService startupService = new StartupService();
98 private static final GameEngine gameService = new GameEngine();
99 private static final NetworkService networkService = new NetworkService();
100
101 private static final OSRoyale INSTANCE = new OSRoyale();
102
103 private final LoginExecutorService loginExecutorService;
104
105 private OSRoyale() {
106 loginExecutorService = new LoginExecutorService(Runtime.getRuntime().availableProcessors());
107 }
108
109 private void processSequentialStatupTasks() {
110 OldToNew.load();
111 try {
112 //object/region decoding must be done before parallel.
113 new ObjectRemovalParser().run();
114 final FileSystem fs = FileSystem.create("data/cache");
115 new ObjectDefinitionDecoder(fs).run();
116 new MapDefinitionDecoder(fs).run();
117 new RegionDecoder(fs).run();
118 new AnimationDefinitionDecoder(fs).run();
119 CacheNpcDefinition.unpackConfig(fs.getArchive(FileSystem.CONFIG_ARCHIVE));
120 } catch (IOException e) {
121 e.printStackTrace();
122 }
123 ItemDefinition.createParser().run();
124 NpcDefinition.createParser().run();
125 ObjectExamines.loadObjectExamines();
126 new CombatProjectileParser().run();
128 new NpcSpawnParser().run();
129 new NpcDropParser().run();
130 new NpcForceChatParser().run();
131 new StoreParser().run();
132 new GlobalObjectParser().run();
133 com.osroyale.content.dialogue.script.DialogueScriptParser.loadAll();
135 Wintertodt.init();
136 }
137
143 private void processParallelStatupTasks() {
144 startupService.submit(new PacketSizeParser());
145 startupService.submit(new PacketListenerLoader());
146 startupService.submit(TriviaBot::declare);
147// startupService.submit(PersonalStoreSaver::loadPayments);
148 startupService.submit(ClanRepository::loadChannels);
149 // startupService.submit(GlobalRecords::load);
150 startupService.submit(SkillRepository::load);
151 startupService.submit(ProfileRepository::load);
152 startupService.submit(ItemActionRepository::declare);
153 startupService.submit(ClueScrollPlugin::declare);
154 startupService.submit(MysteryBox::load);
155 startupService.submit(Discord::start);
156 startupService.submit(GameSaver::load);
157 startupService.submit(PreloadRepository::declare);
158 startupService.submit(TradingPost::loadAllListings);
159 startupService.submit(TradingPost::loadItemHistory);
160 startupService.submit(TradingPost::loadRecentItemHistory);
161 startupService.shutdown();
162 }
163
167 private void onStart() {
168 if (WellOfGoodwill.isActive()) {
170 }
171
176// World.schedule(new BotStartupEvent());
180 logger.info("Events have been scheduled");
181 }
182
183 public void start() throws Exception {
185 ForumService.start(); // used to check users logging in with website credentials
186
187 if (Config.WORLD_TYPE == WorldType.LIVE) {
188 PostgreService.start(); // used to start the postgres connection pool
189 WebsitePlayerCountService.getInstance().startAsync(); // used to display player count on website
190 }
191 }
192
193 new FileServer().start();
194
195 logger.info("Tarnish is running (client version " + Config.CLIENT_VERSION + ")");
196 logger.info(String.format("Game Engine=%s", Config.PARALLEL_GAME_ENGINE ? "Parallel" : "Sequential"));
197 processSequentialStatupTasks();
198 processParallelStatupTasks();
199
200 startupService.awaitUntilFinished(5, TimeUnit.MINUTES);
201 logger.info("Startup service finished");
202
203 LMSLoadoutManager.load();
204
205 PluginManager.load("plugin");
206
207 gameService.startAsync().awaitRunning();
208 logger.info("Game service started");
209
210 onStart();
211
212 Jobs.load();
213
214 BannedPlayers.load();
215 IPBannedPlayers.load();
216 IPMutedPlayers.load();
217
218 networkService.start(Config.SERVER_PORT);
219 }
220
221 public static void main(String[] args) {
222 Runtime.getRuntime().addShutdownHook(new Thread(() -> {
223 logger.info("shutting down server, initializing shutdown hook");
224 World.save();
225 }));
226
227 try {
228 INSTANCE.start();
229 } catch (Throwable t) {
230 logger.error("A problem has been encountered while starting the server.", t);
231 }
232
233 }
234
235 public static OSRoyale getInstance() {
236 return INSTANCE;
237 }
238
239 public static DateTime currentDateTime() {
240 return new DateTime(timeZone());
241 }
242
243 public static DateTimeZone timeZone() {
244 return DateTimeZone.UTC;
245 }
246
247 public LoginExecutorService getLoginExecutorService() {
248 return this.loginExecutorService;
249 }
250}
static final int SERVER_PORT
Definition Config.java:192
static final boolean PARALLEL_GAME_ENGINE
Definition Config.java:149
static final boolean FORUM_INTEGRATION
Definition Config.java:158
static FileSystem create(String directory)
static void schedule(Task task)
Definition World.java:284