Skip to content

Commit ff11ddd

Browse files
authored
Merge pull request #666 from ArikSquad/feat/sentry
Sentry & YAML Configuration
2 parents 377ee8c + 6741ee8 commit ff11ddd

File tree

56 files changed

+492
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+492
-301
lines changed

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ build/
4242
### Mac OS ###
4343
.DS_Store
4444

45-
### Islands ###
45+
46+
### Worlds ###
4647
/configuration/skyblock/islands/hypixel_skyblock_island_template/
4748
/configuration/skyblock/islands/hypixel_skyblock_hub/
4849
/configuration/skyblock/islands/hypixel_skyblock_gold_mine/
4950
/configuration/skyblock/islands/*
51+
/configuration/logs/configuration/murdermystery/*
5052
/configuration/hypixel_prototype_lobby/
51-
.gradle/
5253
/configuration/bedwars/*.polar
54+
55+
.gradle/
5356
/server/proxy/logs/
5457
/server/proxy/lang/
5558
/server/forwarding.secret
56-
/configuration/logs/configuration/murdermystery/aquarium.polar
59+
/configuration/config.yml
60+
/server/proxy/configuration/config.yml

DockerFiles/Dockerfile.game_server

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ COPY ./configuration /app/configuration_files
2222
# Create configuration folder
2323
RUN mkdir -p configuration
2424

25-
# Copy resources.json
26-
RUN cp configuration_files/resources.json ./configuration/resources.json
25+
# Copy config.yml
26+
RUN cp configuration_files/config.yml ./configuration/config.yml
2727

2828
# Make required folders
2929
RUN mkdir -p ./configuration/skyblock/islands

DockerFiles/Dockerfile.proxy

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@ RUN rm velocity.toml
3030
# Add back our velocity.toml
3131
RUN cp configuration_files/velocity.toml velocity.toml
3232

33-
# Download resources.json
33+
# Download config.yml
3434
RUN mkdir -p configuration
3535

36-
RUN cp configuration_files/resources.json ./configuration/resources.json
36+
RUN cp configuration_files/config.example.yml ./configuration/config.yml
3737

3838

39-
# Get Contents of the forwarding secret and add it to resources.json
39+
# Get Contents of the forwarding secret and add it to config.yml
4040
RUN secret=$(cat forwarding.secret) && \
41-
jq --arg secret "$secret" '.["velocity-secret"] = $secret' ./configuration/resources.json > ./configuration/resources.json.tmp && \
42-
mv ./configuration/resources.json.tmp ./configuration/resources.json
41+
sed -i "s/velocity-secret: .*/velocity-secret: '$secret'/" ./configuration/config.yml
4342

4443
# Expose the required port
4544
EXPOSE 25565

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
base
33
java
44
id("io.freefair.lombok") version "9.1.0"
5+
id("io.sentry.jvm.gradle") version "5.12.2"
56
}
67

78
group = "net.swofty"
@@ -31,6 +32,7 @@ subprojects {
3132

3233
implementation("org.reflections:reflections:0.10.2")
3334
implementation("org.json:json:20240303")
35+
implementation("io.sentry:sentry-async-profiler:8.29.0")
3436

3537
compileOnly("org.projectlombok:lombok:1.18.42")
3638

commons/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ dependencies {
2424
compileOnly("net.minestom:minestom:2025.12.20c-1.21.11") {
2525
exclude(group = "org.jboss.shrinkwrap.resolver", module = "shrinkwrap-resolver-depchain")
2626
}
27+
28+
implementation("org.spongepowered:configurate-yaml:4.2.0")
2729
}

commons/src/main/java/net/swofty/commons/Configuration.java

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package net.swofty.commons;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.Map;
6+
7+
import io.sentry.Sentry;
8+
import io.sentry.SentryLogLevel;
9+
import org.tinylog.Level;
10+
import org.tinylog.core.ConfigurationParser;
11+
import org.tinylog.core.LogEntry;
12+
import org.tinylog.core.LogEntryValue;
13+
import org.tinylog.provider.InternalLogger;
14+
import org.tinylog.writers.AbstractFormatPatternWriter;
15+
16+
17+
public final class SentryWriter extends AbstractFormatPatternWriter {
18+
19+
private final Level errorLevel;
20+
21+
public SentryWriter() {
22+
this(Collections.<String, String>emptyMap());
23+
}
24+
25+
/**
26+
* @param properties
27+
* Configuration for writer
28+
*/
29+
public SentryWriter(final Map<String, String> properties) {
30+
super(properties);
31+
32+
// Set the default level for stderr logging
33+
Level levelStream = Level.WARN;
34+
35+
// Check stream property
36+
String stream = getStringValue("stream");
37+
if (stream != null) {
38+
// Check whether we have the err@LEVEL syntax
39+
String[] streams = stream.split("@", 2);
40+
if (streams.length == 2) {
41+
levelStream = ConfigurationParser.parse(streams[1], levelStream);
42+
if (!streams[0].equals("err")) {
43+
InternalLogger.log(Level.ERROR, "Stream with level must be \"err\", \"" + streams[0] + "\" is an invalid name");
44+
}
45+
stream = null;
46+
}
47+
}
48+
49+
if (stream == null) {
50+
errorLevel = levelStream;
51+
} else if ("err".equalsIgnoreCase(stream)) {
52+
errorLevel = Level.TRACE;
53+
} else if ("out".equalsIgnoreCase(stream)) {
54+
errorLevel = Level.OFF;
55+
} else {
56+
InternalLogger.log(Level.ERROR, "Stream must be \"out\" or \"err\", \"" + stream + "\" is an invalid stream name");
57+
errorLevel = levelStream;
58+
}
59+
}
60+
61+
@Override
62+
public Collection<LogEntryValue> getRequiredLogEntryValues() {
63+
Collection<LogEntryValue> logEntryValues = super.getRequiredLogEntryValues();
64+
logEntryValues.add(LogEntryValue.LEVEL);
65+
return logEntryValues;
66+
}
67+
68+
@Override
69+
public void write(final LogEntry logEntry) {
70+
SentryLogLevel sentryLevel;
71+
try {
72+
sentryLevel = SentryLogLevel.valueOf(logEntry.getLevel().name());
73+
} catch (IllegalArgumentException e) {
74+
sentryLevel = SentryLogLevel.INFO;
75+
}
76+
77+
Sentry.logger().log(sentryLevel, render(logEntry));
78+
if (logEntry.getLevel().ordinal() < errorLevel.ordinal()) {
79+
System.out.print(render(logEntry));
80+
} else {
81+
System.err.print(render(logEntry));
82+
}
83+
}
84+
85+
@Override
86+
public void flush() {
87+
}
88+
89+
@Override
90+
public void close() {
91+
}
92+
93+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package net.swofty.commons.config;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import lombok.experimental.Accessors;
6+
import org.spongepowered.configurate.CommentedConfigurationNode;
7+
import org.spongepowered.configurate.yaml.NodeStyle;
8+
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
9+
import org.tinylog.Logger;
10+
11+
import java.io.IOException;
12+
import java.nio.file.Path;
13+
14+
public class ConfigProvider {
15+
16+
@Getter
17+
@Setter
18+
@Accessors(fluent = true)
19+
private static Settings settings;
20+
21+
static {
22+
try {
23+
Logger.info("Loading config...");
24+
YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
25+
.path(Path.of("./configuration/config.yml"))
26+
.nodeStyle(NodeStyle.BLOCK)
27+
.build();
28+
29+
CommentedConfigurationNode node = loader.load();
30+
Settings existingSettings = node.get(Settings.class);
31+
if (existingSettings == null) {
32+
existingSettings = new Settings();
33+
}
34+
Settings config = existingSettings;
35+
node.set(Settings.class, config);
36+
loader.save(node);
37+
38+
settings(config);
39+
} catch (IOException e) {
40+
throw new RuntimeException("Failed to load configuration", e);
41+
}
42+
}
43+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package net.swofty.commons.config;
2+
3+
import lombok.AccessLevel;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
7+
import org.spongepowered.configurate.objectmapping.meta.Comment;
8+
9+
@Getter
10+
@ConfigSerializable
11+
@SuppressWarnings({"unused", "FieldMayBeFinal"})
12+
public class Settings {
13+
14+
private String hostName = "0.0.0.0";
15+
private long transferTimeout = 800;
16+
17+
@Comment("The MongoDB connection URI")
18+
private String mongodb = "mongodb://localhost";
19+
20+
@Comment("The Redis connection URI")
21+
private String redisUri = "redis://localhost:6379";
22+
23+
@Comment("The secret key used to authenticate with Velocity proxy")
24+
private String velocitySecret = "ixmSUgWOgvs7";
25+
26+
private boolean requireAuth = false;
27+
28+
@Comment("Whether to enable sandbox features (such as editing items)")
29+
private boolean sandbox = false;
30+
31+
@Comment("Integrations with services")
32+
private IntegrationSettings integrations = new IntegrationSettings();
33+
34+
@Comment("Settings related to configuration of Limbo server connections")
35+
private LimboSettings limbo = new LimboSettings();
36+
37+
@Getter
38+
@ConfigSerializable
39+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
40+
public static class LimboSettings {
41+
private String hostName = "127.0.0.1";
42+
private int port = 65535;
43+
}
44+
45+
@Getter
46+
@ConfigSerializable
47+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
48+
public static class IntegrationSettings {
49+
@Comment("Whether to enable Spark for performance monitoring")
50+
private boolean spark = false;
51+
52+
@Comment("Whether to enable anti-cheat measures")
53+
private boolean anticheat = false;
54+
55+
@Comment("Whether to enable ViaVersion for supporting multiple Minecraft versions. This may cause issues of any kind")
56+
private boolean viaVersion = false;
57+
58+
private String sentryDsn = "";
59+
}
60+
61+
}

configuration/config.docker.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
host-name: 0.0.0.0
2+
transfer-timeout: 800
3+
mongodb: mongodb://localhost
4+
redis-url: redis://localhost:6379
5+
velocity-secret: ixmSUgWOgvs7
6+
require-auth: false
7+
sandbox: false
8+
spark: false
9+
anticheat: false
10+
redis-uri: redis://localhost:6379
11+
limbo:
12+
host-name: 127.0.0.1
13+
port: 65535

0 commit comments

Comments
 (0)