2018-07-06 13:30:00 +00:00
|
|
|
package com.eu.habbo;
|
|
|
|
|
2020-05-03 01:46:07 +02:00
|
|
|
import ch.qos.logback.classic.Level;
|
2020-05-05 00:20:07 +02:00
|
|
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
|
|
|
import ch.qos.logback.core.ConsoleAppender;
|
2020-05-02 02:18:09 +02:00
|
|
|
import com.eu.habbo.core.*;
|
2018-07-06 13:30:00 +00:00
|
|
|
import com.eu.habbo.core.consolecommands.ConsoleCommand;
|
|
|
|
import com.eu.habbo.database.Database;
|
|
|
|
import com.eu.habbo.habbohotel.GameEnvironment;
|
|
|
|
import com.eu.habbo.networking.camera.CameraClient;
|
|
|
|
import com.eu.habbo.networking.gameserver.GameServer;
|
|
|
|
import com.eu.habbo.networking.rconserver.RCONServer;
|
|
|
|
import com.eu.habbo.plugin.PluginManager;
|
|
|
|
import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent;
|
|
|
|
import com.eu.habbo.plugin.events.emulator.EmulatorLoadedEvent;
|
|
|
|
import com.eu.habbo.plugin.events.emulator.EmulatorStartShutdownEvent;
|
|
|
|
import com.eu.habbo.plugin.events.emulator.EmulatorStoppedEvent;
|
|
|
|
import com.eu.habbo.threading.ThreadPooling;
|
|
|
|
import com.eu.habbo.util.imager.badges.BadgeImager;
|
2020-05-03 01:46:07 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-07-24 15:59:20 +03:00
|
|
|
import java.io.*;
|
2019-05-12 21:31:59 +01:00
|
|
|
import java.security.MessageDigest;
|
2018-07-06 13:30:00 +00:00
|
|
|
import java.sql.Timestamp;
|
|
|
|
import java.text.SimpleDateFormat;
|
2020-10-04 00:25:55 +02:00
|
|
|
import java.util.*;
|
2020-05-03 01:46:07 +02:00
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
2020-10-04 00:25:55 +02:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public final class Emulator {
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2020-05-03 01:46:07 +02:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(Emulator.class);
|
2021-12-19 15:05:48 +00:00
|
|
|
private static final String OS_NAME = (System.getProperty("os.name") != null ? System.getProperty("os.name") : "Unknown");
|
|
|
|
private static final String CLASS_PATH = (System.getProperty("java.class.path") != null ? System.getProperty("java.class.path") : "Unknown");
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2022-04-15 15:38:08 -07:00
|
|
|
public final static int MAJOR = 4;
|
|
|
|
public final static int MINOR = 0;
|
2020-04-03 16:40:48 +01:00
|
|
|
public final static int BUILD = 0;
|
2022-04-15 15:38:08 -07:00
|
|
|
public final static String PREVIEW = "Developer Preview";
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2020-11-16 00:05:02 +00:00
|
|
|
public static final String version = "Arcturus Morningstar" + " " + MAJOR + "." + MINOR + "." + BUILD + " " + PREVIEW;
|
2019-05-26 21:14:53 +03:00
|
|
|
private static final String logo =
|
2020-01-21 23:35:33 +00:00
|
|
|
"\n" +
|
2022-04-15 15:38:08 -07:00
|
|
|
"███╗ ███╗ ██████╗ ██████╗ ███╗ ██╗██╗███╗ ██╗ ██████╗ ███████╗████████╗ █████╗ ██████╗ \n" +
|
2020-01-21 23:35:33 +00:00
|
|
|
"████╗ ████║██╔═══██╗██╔══██╗████╗ ██║██║████╗ ██║██╔════╝ ██╔════╝╚══██╔══╝██╔══██╗██╔══██╗\n" +
|
|
|
|
"██╔████╔██║██║ ██║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║ ███╗███████╗ ██║ ███████║██████╔╝\n" +
|
|
|
|
"██║╚██╔╝██║██║ ██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║ ██║╚════██║ ██║ ██╔══██║██╔══██╗\n" +
|
|
|
|
"██║ ╚═╝ ██║╚██████╔╝██║ ██║██║ ╚████║██║██║ ╚████║╚██████╔╝███████║ ██║ ██║ ██║██║ ██║\n" +
|
2022-04-15 15:38:08 -07:00
|
|
|
"╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝\n" +
|
|
|
|
"If u use this build on a live hotel and ask for help ill just send you a picture of wullez ass" ;
|
|
|
|
|
2020-11-16 00:03:26 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-12 21:31:59 +01:00
|
|
|
public static String build = "";
|
2018-07-06 13:30:00 +00:00
|
|
|
public static boolean isReady = false;
|
|
|
|
public static boolean isShuttingDown = false;
|
|
|
|
public static boolean stopped = false;
|
|
|
|
public static boolean debugging = false;
|
2019-05-26 21:14:53 +03:00
|
|
|
private static int timeStarted = 0;
|
|
|
|
private static Runtime runtime;
|
|
|
|
private static ConfigurationManager config;
|
2020-05-02 02:18:09 +02:00
|
|
|
private static CryptoConfig crypto;
|
2019-05-26 21:14:53 +03:00
|
|
|
private static TextsManager texts;
|
|
|
|
private static GameServer gameServer;
|
|
|
|
private static RCONServer rconServer;
|
|
|
|
private static CameraClient cameraClient;
|
2020-05-05 03:56:21 +02:00
|
|
|
private static Logging logging;
|
2019-05-26 21:14:53 +03:00
|
|
|
private static Database database;
|
2020-05-03 01:46:07 +02:00
|
|
|
private static DatabaseLogger databaseLogger;
|
2019-05-26 21:14:53 +03:00
|
|
|
private static ThreadPooling threading;
|
|
|
|
private static GameEnvironment gameEnvironment;
|
|
|
|
private static PluginManager pluginManager;
|
|
|
|
private static BadgeImager badgeImager;
|
|
|
|
|
|
|
|
static {
|
|
|
|
Thread hook = new Thread(new Runnable() {
|
|
|
|
public synchronized void run() {
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.dispose();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
hook.setPriority(10);
|
|
|
|
Runtime.getRuntime().addShutdownHook(hook);
|
|
|
|
}
|
|
|
|
|
2020-11-16 00:03:26 +00:00
|
|
|
public static void promptEnterKey(){
|
|
|
|
System.out.println("\n");
|
|
|
|
System.out.println("Press \"ENTER\" if you agree to the terms stated above...");
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
scanner.nextLine();
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
try {
|
2020-05-05 00:20:07 +02:00
|
|
|
// Check if running on Windows and not in IntelliJ.
|
|
|
|
// If so, we need to reconfigure the console appender and enable Jansi for colors.
|
|
|
|
if (OS_NAME.startsWith("Windows") && !CLASS_PATH.contains("idea_rt.jar")) {
|
|
|
|
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
|
|
|
ConsoleAppender<ILoggingEvent> appender = (ConsoleAppender<ILoggingEvent>) root.getAppender("Console");
|
|
|
|
|
|
|
|
appender.stop();
|
|
|
|
appender.setWithJansi(true);
|
|
|
|
appender.start();
|
|
|
|
}
|
|
|
|
|
2019-05-17 12:21:55 +03:00
|
|
|
Locale.setDefault(new Locale("en"));
|
2019-05-12 21:31:59 +01:00
|
|
|
setBuild();
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.stopped = false;
|
|
|
|
ConsoleCommand.load();
|
2020-05-05 03:56:21 +02:00
|
|
|
Emulator.logging = new Logging();
|
2020-05-03 01:46:07 +02:00
|
|
|
|
|
|
|
System.out.println(logo);
|
|
|
|
|
2020-11-16 00:03:26 +00:00
|
|
|
// Checks if this is a BETA build before allowing them to continue.
|
|
|
|
if (PREVIEW.toLowerCase().contains("beta")) {
|
2022-04-15 15:38:08 -07:00
|
|
|
System.out.println("");
|
2020-11-16 00:03:26 +00:00
|
|
|
promptEnterKey();
|
|
|
|
}
|
2022-04-20 16:48:38 -07:00
|
|
|
LOGGER.info("eek. Has it really been a year?");
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.info("This project is for educational purposes only. This Emulator is an open-source fork of Arcturus created by TheGeneral.");
|
|
|
|
LOGGER.info("Version: {}", version);
|
|
|
|
LOGGER.info("Build: {}", build);
|
2022-03-31 08:36:26 +00:00
|
|
|
LOGGER.info("Follow our development at https://git.krews.org/morningstar/Arcturus-Community");
|
2020-05-03 01:46:07 +02:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
long startTime = System.nanoTime();
|
|
|
|
|
|
|
|
Emulator.runtime = Runtime.getRuntime();
|
|
|
|
Emulator.config = new ConfigurationManager("config.ini");
|
2020-05-02 02:18:09 +02:00
|
|
|
Emulator.crypto = new CryptoConfig(
|
|
|
|
Emulator.getConfig().getBoolean("enc.enabled", false),
|
|
|
|
Emulator.getConfig().getValue("enc.e"),
|
|
|
|
Emulator.getConfig().getValue("enc.n"),
|
|
|
|
Emulator.getConfig().getValue("enc.d"));
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.database = new Database(Emulator.getConfig());
|
2020-05-03 01:46:07 +02:00
|
|
|
Emulator.databaseLogger = new DatabaseLogger();
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.config.loaded = true;
|
|
|
|
Emulator.config.loadFromDatabase();
|
|
|
|
Emulator.threading = new ThreadPooling(Emulator.getConfig().getInt("runtime.threads"));
|
|
|
|
Emulator.getDatabase().getDataSource().setMaximumPoolSize(Emulator.getConfig().getInt("runtime.threads") * 2);
|
|
|
|
Emulator.getDatabase().getDataSource().setMinimumIdle(10);
|
|
|
|
Emulator.pluginManager = new PluginManager();
|
|
|
|
Emulator.pluginManager.reload();
|
|
|
|
Emulator.getPluginManager().fireEvent(new EmulatorConfigUpdatedEvent());
|
|
|
|
Emulator.texts = new TextsManager();
|
|
|
|
new CleanerThread();
|
|
|
|
Emulator.gameServer = new GameServer(getConfig().getValue("game.host", "127.0.0.1"), getConfig().getInt("game.port", 30000));
|
2020-01-28 00:12:47 +02:00
|
|
|
Emulator.rconServer = new RCONServer(getConfig().getValue("rcon.host", "127.0.0.1"), getConfig().getInt("rcon.port", 30001));
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.gameEnvironment = new GameEnvironment();
|
|
|
|
Emulator.gameEnvironment.load();
|
2018-10-06 22:28:00 +00:00
|
|
|
Emulator.gameServer.initializePipeline();
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.gameServer.connect();
|
2020-01-28 00:12:47 +02:00
|
|
|
Emulator.rconServer.initializePipeline();
|
|
|
|
Emulator.rconServer.connect();
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.badgeImager = new BadgeImager();
|
2020-05-03 01:46:07 +02:00
|
|
|
|
2020-10-05 02:14:39 -04:00
|
|
|
LOGGER.info("Arcturus Morningstar has successfully loaded.");
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.info("System launched in: {}ms. Using {} threads!", (System.nanoTime() - startTime) / 1e6, Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
LOGGER.info("Memory: {}/{}MB", (runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024), (runtime.freeMemory()) / (1024 * 1024));
|
2018-07-06 13:30:00 +00:00
|
|
|
|
|
|
|
Emulator.debugging = Emulator.getConfig().getBoolean("debug.mode");
|
2020-05-03 01:46:07 +02:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (debugging) {
|
2020-05-03 01:46:07 +02:00
|
|
|
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
|
|
|
root.setLevel(Level.DEBUG);
|
|
|
|
LOGGER.debug("Debugging enabled.");
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Emulator.getPluginManager().fireEvent(new EmulatorLoadedEvent());
|
|
|
|
Emulator.isReady = true;
|
|
|
|
Emulator.timeStarted = getIntUnixTimestamp();
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (Emulator.getConfig().getInt("runtime.threads") < (Runtime.getRuntime().availableProcessors() * 2)) {
|
2021-05-26 06:29:52 +00:00
|
|
|
LOGGER.warn("Emulator settings runtime.threads ({}) can be increased to ({}) to possibly increase performance.",
|
2020-05-03 01:46:07 +02:00
|
|
|
Emulator.getConfig().getInt("runtime.threads"),
|
|
|
|
Runtime.getRuntime().availableProcessors() * 2);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-07-16 20:33:19 -04:00
|
|
|
Emulator.getThreading().run(() -> {
|
2019-07-24 12:12:53 +01:00
|
|
|
}, 1500);
|
2018-09-12 16:45:00 +00:00
|
|
|
|
2021-12-09 07:41:10 +00:00
|
|
|
// Check if console mode is true or false, default is true
|
|
|
|
if (Emulator.getConfig().getBoolean("console.mode", true)) {
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2021-12-09 07:41:10 +00:00
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2021-12-09 07:41:10 +00:00
|
|
|
while (!isShuttingDown && isReady) {
|
|
|
|
try {
|
|
|
|
String line = reader.readLine();
|
|
|
|
|
|
|
|
if (line != null) {
|
|
|
|
ConsoleCommand.handle(line);
|
|
|
|
}
|
|
|
|
System.out.println("Waiting for command: ");
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (!(e instanceof IOException && e.getMessage().equals("Bad file descriptor"))) {
|
|
|
|
LOGGER.error("Error while reading command", e);
|
|
|
|
}
|
2019-07-24 15:59:20 +03:00
|
|
|
}
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-09 07:41:10 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-12 21:31:59 +01:00
|
|
|
private static void setBuild() {
|
2019-09-10 21:37:06 +01:00
|
|
|
if (Emulator.class.getProtectionDomain().getCodeSource() == null) {
|
|
|
|
build = "UNKNOWN";
|
|
|
|
return;
|
|
|
|
}
|
2019-05-12 21:31:59 +01:00
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2019-09-10 21:37:06 +01:00
|
|
|
String filepath = new File(Emulator.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath();
|
2019-05-12 21:31:59 +01:00
|
|
|
MessageDigest md = MessageDigest.getInstance("MD5");// MD5
|
2019-09-10 21:37:06 +01:00
|
|
|
FileInputStream fis = new FileInputStream(filepath);
|
2019-05-12 21:31:59 +01:00
|
|
|
byte[] dataBytes = new byte[1024];
|
|
|
|
int nread = 0;
|
2019-09-10 21:37:06 +01:00
|
|
|
while ((nread = fis.read(dataBytes)) != -1)
|
2019-05-12 21:31:59 +01:00
|
|
|
md.update(dataBytes, 0, nread);
|
|
|
|
byte[] mdbytes = md.digest();
|
2019-05-26 21:14:53 +03:00
|
|
|
for (int i = 0; i < mdbytes.length; i++)
|
|
|
|
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
|
|
|
|
} catch (Exception e) {
|
2019-05-12 21:31:59 +01:00
|
|
|
build = "UNKNOWN";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
build = sb.toString();
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
private static void dispose() {
|
2019-04-21 23:42:00 +00:00
|
|
|
Emulator.getThreading().setCanAdd(false);
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.isShuttingDown = true;
|
|
|
|
Emulator.isReady = false;
|
2020-05-03 01:46:07 +02:00
|
|
|
|
|
|
|
LOGGER.info("Stopping Arcturus Morningstar {}", version);
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (Emulator.getPluginManager() != null)
|
|
|
|
Emulator.getPluginManager().fireEvent(new EmulatorStartShutdownEvent());
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (Emulator.cameraClient != null)
|
|
|
|
Emulator.cameraClient.disconnect();
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (Emulator.rconServer != null)
|
|
|
|
Emulator.rconServer.stop();
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (Emulator.gameEnvironment != null)
|
|
|
|
Emulator.gameEnvironment.dispose();
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (Emulator.getPluginManager() != null)
|
|
|
|
Emulator.getPluginManager().fireEvent(new EmulatorStoppedEvent());
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (Emulator.pluginManager != null)
|
|
|
|
Emulator.pluginManager.dispose();
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
|
|
|
if (Emulator.config != null) {
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.config.saveToDatabase();
|
|
|
|
}
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (Emulator.gameServer != null)
|
|
|
|
Emulator.gameServer.stop();
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
2020-05-03 01:46:07 +02:00
|
|
|
|
|
|
|
LOGGER.info("Stopped Arcturus Morningstar {}", version);
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (Emulator.database != null) {
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.getDatabase().dispose();
|
|
|
|
}
|
|
|
|
Emulator.stopped = true;
|
|
|
|
|
2020-05-03 01:46:07 +02:00
|
|
|
// if (osName.startsWith("Windows") && (!classPath.contains("idea_rt.jar"))) {
|
|
|
|
// AnsiConsole.systemUninstall();
|
|
|
|
// }
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (Emulator.threading != null)
|
2020-01-21 23:35:33 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
Emulator.threading.shutDown();
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static ConfigurationManager getConfig() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2020-05-02 02:18:09 +02:00
|
|
|
public static CryptoConfig getCrypto() {
|
|
|
|
return crypto;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static TextsManager getTexts() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return texts;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static Database getDatabase() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return database;
|
|
|
|
}
|
|
|
|
|
2020-05-03 01:46:07 +02:00
|
|
|
public static DatabaseLogger getDatabaseLogger() {
|
|
|
|
return databaseLogger;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static Runtime getRuntime() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return runtime;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static GameServer getGameServer() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return gameServer;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static RCONServer getRconServer() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return rconServer;
|
|
|
|
}
|
|
|
|
|
2020-05-05 03:56:21 +02:00
|
|
|
/**
|
|
|
|
* @deprecated Do not use. Please use LoggerFactory.getLogger(YourClass.class) to log.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public static Logging getLogging() {
|
|
|
|
return logging;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static ThreadPooling getThreading() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return threading;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static GameEnvironment getGameEnvironment() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return gameEnvironment;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static PluginManager getPluginManager() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return pluginManager;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static Random getRandom() {
|
2020-05-03 01:46:07 +02:00
|
|
|
return ThreadLocalRandom.current();
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static BadgeImager getBadgeImager() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return badgeImager;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static CameraClient getCameraClient() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return cameraClient;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static synchronized void setCameraClient(CameraClient client) {
|
2018-07-06 13:30:00 +00:00
|
|
|
cameraClient = client;
|
|
|
|
}
|
2018-12-22 10:39:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static int getTimeStarted() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return timeStarted;
|
|
|
|
}
|
2018-12-22 10:39:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static int getOnlineTime() {
|
2019-04-21 23:42:00 +00:00
|
|
|
return getIntUnixTimestamp() - timeStarted;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static void prepareShutdown() {
|
2018-07-06 13:30:00 +00:00
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:25:55 +02:00
|
|
|
public static int timeStringToSeconds(String timeString) {
|
|
|
|
int totalSeconds = 0;
|
|
|
|
|
|
|
|
Matcher m = Pattern.compile("(([0-9]*) (second|minute|hour|day|week|month|year))").matcher(timeString);
|
|
|
|
Map<String,Integer> map = new HashMap<String,Integer>() {
|
|
|
|
{
|
|
|
|
put("second", 1);
|
|
|
|
put("minute", 60);
|
|
|
|
put("hour", 3600);
|
|
|
|
put("day", 86400);
|
|
|
|
put("week", 604800);
|
|
|
|
put("month", 2628000);
|
|
|
|
put("year", 31536000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
while (m.find()) {
|
|
|
|
try {
|
|
|
|
int amount = Integer.parseInt(m.group(2));
|
|
|
|
String what = m.group(3);
|
|
|
|
totalSeconds += amount * map.get(what);
|
|
|
|
}
|
|
|
|
catch (Exception ignored) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
return totalSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Date modifyDate(Date date, String timeString) {
|
|
|
|
int totalSeconds = 0;
|
|
|
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.setTime(date);
|
|
|
|
|
|
|
|
Matcher m = Pattern.compile("(([0-9]*) (second|minute|hour|day|week|month|year))").matcher(timeString);
|
|
|
|
Map<String, Integer> map = new HashMap<String, Integer>() {
|
|
|
|
{
|
|
|
|
put("second", Calendar.SECOND);
|
|
|
|
put("minute", Calendar.MINUTE);
|
|
|
|
put("hour", Calendar.HOUR);
|
|
|
|
put("day", Calendar.DAY_OF_MONTH);
|
|
|
|
put("week", Calendar.WEEK_OF_MONTH);
|
|
|
|
put("month", Calendar.MONTH);
|
|
|
|
put("year", Calendar.YEAR);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
while (m.find()) {
|
|
|
|
try {
|
|
|
|
int amount = Integer.parseInt(m.group(2));
|
|
|
|
String what = m.group(3);
|
|
|
|
c.add(map.get(what), amount);
|
|
|
|
}
|
|
|
|
catch (Exception ignored) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.getTime();
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
private static String dateToUnixTimestamp(Date date) {
|
2018-07-06 13:30:00 +00:00
|
|
|
String res = "";
|
|
|
|
Date aux = stringToDate("1970-01-01 00:00:00");
|
|
|
|
Timestamp aux1 = dateToTimeStamp(aux);
|
|
|
|
Timestamp aux2 = dateToTimeStamp(date);
|
|
|
|
long difference = aux2.getTime() - aux1.getTime();
|
|
|
|
long seconds = difference / 1000L;
|
|
|
|
return res + seconds;
|
|
|
|
}
|
|
|
|
|
2020-10-04 00:25:55 +02:00
|
|
|
public static Date stringToDate(String date) {
|
2018-07-06 13:30:00 +00:00
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
Date res = null;
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
2018-07-06 13:30:00 +00:00
|
|
|
res = format.parse(date);
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.error("Error parsing date", e);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2018-12-22 10:39:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static Timestamp dateToTimeStamp(Date date) {
|
2018-07-06 13:30:00 +00:00
|
|
|
return new Timestamp(date.getTime());
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static Date getDate() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return new Date(System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static String getUnixTimestamp() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return dateToUnixTimestamp(getDate());
|
|
|
|
}
|
2018-12-22 10:39:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static int getIntUnixTimestamp() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return (int) (System.currentTimeMillis() / 1000);
|
|
|
|
}
|
2018-12-22 10:39:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public static boolean isNumeric(String string)
|
2019-05-26 21:14:53 +03:00
|
|
|
throws IllegalArgumentException {
|
2018-07-06 13:30:00 +00:00
|
|
|
boolean isnumeric = false;
|
2019-05-26 21:14:53 +03:00
|
|
|
if ((string != null) && (!string.equals(""))) {
|
2018-07-06 13:30:00 +00:00
|
|
|
isnumeric = true;
|
|
|
|
char[] chars = string.toCharArray();
|
2019-05-26 21:14:53 +03:00
|
|
|
for (char aChar : chars) {
|
2018-07-06 13:30:00 +00:00
|
|
|
isnumeric = Character.isDigit(aChar);
|
2019-05-26 21:14:53 +03:00
|
|
|
if (!isnumeric) {
|
2018-07-06 13:30:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isnumeric;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public int getUserCount() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return gameEnvironment.getHabboManager().getOnlineCount();
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public int getRoomCount() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return gameEnvironment.getRoomManager().getActiveRooms().size();
|
|
|
|
}
|
2021-05-26 06:29:52 +00:00
|
|
|
}
|