Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bootstrap/geyser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

relocate("org.yaml.snakeyaml")
relocate("com.fasterxml.jackson")
relocate("org.spongepowered.configurate")
relocate("com.google.gson")
relocate("net.raphimc.minecraftauth")
relocate("org.bouncycastle")
Expand All @@ -19,7 +19,6 @@ configurations.all {

dependencies {
api(project(":core"))
api(libs.bundles.jackson)
compileOnly(libs.bundles.geyser)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import com.rtm516.mcxboxbroadcast.core.Logger;
import com.rtm516.mcxboxbroadcast.core.SessionInfo;
import com.rtm516.mcxboxbroadcast.core.SessionManager;
import com.rtm516.mcxboxbroadcast.core.configs.ConfigLoader;
import com.rtm516.mcxboxbroadcast.core.configs.CoreConfig;
import com.rtm516.mcxboxbroadcast.core.notifications.NotificationManager;
import com.rtm516.mcxboxbroadcast.core.notifications.SlackNotificationManager;
import com.rtm516.mcxboxbroadcast.core.configs.ExtensionConfig;
import com.rtm516.mcxboxbroadcast.core.exceptions.SessionCreationException;
import com.rtm516.mcxboxbroadcast.core.exceptions.SessionUpdateException;
import com.rtm516.mcxboxbroadcast.core.storage.FileStorageManager;
Expand All @@ -21,6 +22,7 @@
import org.geysermc.geyser.api.event.lifecycle.GeyserShutdownEvent;
import org.geysermc.geyser.api.extension.Extension;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
Expand All @@ -34,7 +36,7 @@ public class MCXboxBroadcastExtension implements Extension {
NotificationManager notificationManager;
SessionManager sessionManager;
SessionInfo sessionInfo;
ExtensionConfig config;
CoreConfig config;

@Subscribe
public void onCommandDefine(GeyserDefineCommandsEvent event) {
Expand Down Expand Up @@ -130,25 +132,35 @@ public void onPostInitialize(GeyserPostInitializeEvent event) {
logger.info("Starting MCXboxBroadcast Extension " + BuildData.VERSION + " for Bedrock " + Constants.BEDROCK_CODEC.getMinecraftVersion() + " (" + Constants.BEDROCK_CODEC.getProtocolVersion() + ")");

// Load the config file
config = ConfigLoader.load(this, MCXboxBroadcastExtension.class, ExtensionConfig.class);
File configFile = dataFolder().resolve("config.yml").toFile();

// Ensure the data folder exists
if (!dataFolder().toFile().exists()) {
if (!dataFolder().toFile().mkdirs()) {
logger.error("Failed to create data folder, extension will not start!");
this.disable();
return;
}
}

// Make sure we loaded a config and disable the extension if we didn't
if (config == null) {
logger.error("Failed to load config, extension will not start!");
try {
config = ConfigLoader.loadConfig(configFile, "Extension");
} catch (IOException e) {
logger.error("Failed to load config, extension will not start!", e);
this.disable();
return;
}

// TODO Support multiple notification types
notificationManager = new SlackNotificationManager(logger, config.slackWebhook());
notificationManager = new SlackNotificationManager(logger, config.notifications());

// Create the session manager
sessionManager = new SessionManager(new FileStorageManager(this.dataFolder().toString(), this.dataFolder().resolve("screenshot.jpg").toString()), notificationManager, logger);

// Pull onto another thread so we don't hang the main thread
sessionManager.scheduledThread().execute(() -> {
// Get the ip to broadcast
String ip = config.remoteAddress();
String ip = config.session().remoteAddress();
if (ip.equals("auto")) {
ip = this.geyserApi().bedrockListener().address();

Expand All @@ -171,8 +183,8 @@ public void onPostInitialize(GeyserPostInitializeEvent event) {

// Get the port to broadcast
int port = this.geyserApi().bedrockListener().port();
if (!config.remotePort().equals("auto")) {
port = Integer.parseInt(config.remotePort());
if (!config.session().remotePort().equals("auto")) {
port = Integer.parseInt(config.session().remotePort());
Comment thread
rtm516 marked this conversation as resolved.
}

// Create the session information based on the Geyser config
Expand Down Expand Up @@ -230,7 +242,7 @@ private void createSession() {
}

// Start the update timer
sessionManager.scheduledThread().scheduleWithFixedDelay(this::tick, config.updateInterval(), config.updateInterval(), TimeUnit.SECONDS);
sessionManager.scheduledThread().scheduleWithFixedDelay(this::tick, config.session().updateInterval(), config.session().updateInterval(), TimeUnit.SECONDS);
}

private void tick() {
Expand Down
55 changes: 0 additions & 55 deletions bootstrap/geyser/src/main/resources/config.yml

This file was deleted.

1 change: 0 additions & 1 deletion bootstrap/standalone/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {

dependencies {
api(project(":core"))
api(libs.bundles.jackson)

api(libs.terminalconsoleappender) {
exclude("org.apache.logging.log4j")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.rtm516.mcxboxbroadcast.bootstrap.standalone;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.rtm516.mcxboxbroadcast.core.BuildData;
import com.rtm516.mcxboxbroadcast.core.Constants;
import com.rtm516.mcxboxbroadcast.core.SessionInfo;
import com.rtm516.mcxboxbroadcast.core.SessionManager;
import com.rtm516.mcxboxbroadcast.core.configs.ConfigLoader;
import com.rtm516.mcxboxbroadcast.core.configs.CoreConfig;
import com.rtm516.mcxboxbroadcast.core.notifications.NotificationManager;
import com.rtm516.mcxboxbroadcast.core.notifications.SlackNotificationManager;
import com.rtm516.mcxboxbroadcast.core.configs.StandaloneConfig;
import com.rtm516.mcxboxbroadcast.core.exceptions.SessionCreationException;
import com.rtm516.mcxboxbroadcast.core.exceptions.SessionUpdateException;
import com.rtm516.mcxboxbroadcast.core.ping.PingUtil;
Expand All @@ -26,7 +24,7 @@
import java.util.concurrent.TimeUnit;

public class StandaloneMain {
private static StandaloneConfig config;
private static CoreConfig config;
private static StandaloneLoggerImpl logger;
private static SessionInfo sessionInfo;
private static NotificationManager notificationManager;
Expand All @@ -41,42 +39,21 @@ public static void main(String[] args) throws Exception {
String configFileName = "config.yml";
File configFile = new File(configFileName);

// Create the config file if it doesn't exist
if (!configFile.exists()) {
try (FileOutputStream fos = new FileOutputStream(configFileName)) {
try (InputStream input = StandaloneMain.class.getClassLoader().getResourceAsStream(configFileName)) {
byte[] bytes = new byte[input.available()];

//noinspection ResultOfMethodCallIgnored
input.read(bytes);

fos.write(bytes);

fos.flush();
}
} catch (IOException e) {
logger.error("Failed to create config", e);
return;
}
}

try {
config = new ObjectMapper(new YAMLFactory())
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.readValue(configFile, StandaloneConfig.class);
config = ConfigLoader.loadConfig(configFile, "Standalone");
} catch (IOException e) {
logger.error("Failed to load config", e);
return;
}

logger.setDebug(config.debugLog());
logger.setDebug(config.debugMode());

// TODO Support multiple notification types
notificationManager = new SlackNotificationManager(logger, config.slackWebhook());
notificationManager = new SlackNotificationManager(logger, config.notifications());

sessionManager = new SessionManager(new FileStorageManager("./cache", "./screenshot.jpg"), notificationManager, logger);

sessionInfo = (SessionInfo) config.session().sessionInfo().copy();
sessionInfo = new SessionInfo(config.session().sessionInfo());

// Fallback to the gamertag if the host name is empty
if (sessionInfo.getHostName().isEmpty()) {
Expand Down Expand Up @@ -116,7 +93,7 @@ private static void createSession() throws SessionCreationException, SessionUpda
try {
// Update the session
sessionManager.updateSession(sessionInfo);
if (config.suppressSessionUpdateInfo()) {
if (config.suppressSessionUpdateMessage()) {
sessionManager.logger().debug("Updated session!");
} else {
sessionManager.logger().info("Updated session!");
Expand Down Expand Up @@ -147,10 +124,10 @@ private static void updateSessionInfo(SessionInfo sessionInfo) {
if (config.session().configFallback()) {
sessionManager.logger().error("Failed to ping server, falling back to config values", e);

sessionInfo.setHostName(config.session().sessionInfo().getHostName());
sessionInfo.setWorldName(config.session().sessionInfo().getWorldName());
sessionInfo.setPlayers(config.session().sessionInfo().getPlayers());
sessionInfo.setMaxPlayers(config.session().sessionInfo().getMaxPlayers());
sessionInfo.setHostName(config.session().sessionInfo().hostName());
sessionInfo.setWorldName(config.session().sessionInfo().worldName());
sessionInfo.setPlayers(config.session().sessionInfo().players());
sessionInfo.setMaxPlayers(config.session().sessionInfo().maxPlayers());

// Fallback to the gamertag if the host name is empty
if (sessionInfo.getHostName().isEmpty()) {
Expand Down
Loading