13
0
Dieser Commit ist enthalten in:
yoyosource 2022-04-23 21:45:49 +02:00
Ursprung f1241d8b1e
Commit 1925e5008c
4 geänderte Dateien mit 140 neuen und 6 gelöschten Zeilen

16
src/config.yml Normale Datei
Datei anzeigen

@ -0,0 +1,16 @@
# Config for SteamWar TeamServer-Integration.
# Every setting is locally and will not be sent to SteamWar.
# Set this to 'false' to disable the TeamServer-Integration completely.
plugin-enabled: true
# Set this to 'true' to force the joining coming from SteamWar.
force-only-steamwar-join: false
# Set this to 'true' to enable the TeamServer-Integration whitelist.
# This will not affect normal connections, only those coming from SteamWar.
whitelist-enabled: false
# You can either whitelist a UUID(recommended) or a UserName.
# UUID's need to be in the format of 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
whitelisted-players: []

Datei anzeigen

@ -0,0 +1,95 @@
package de.steamwar;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
@UtilityClass
public class ConfigSystem {
private File configFile;
private boolean enabled = false;
private long lastModified = 0;
private Configuration config;
private Set<String> whitelist = null;
static {
configFile = new File(SteamWarBungeeTeamserver.plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) {
try {
configFile.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(configFile);
InputStream inputStream = SteamWarBungeeTeamserver.plugin.getResourceAsStream("config.yml");
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
}
fileOutputStream.close();
inputStream.close();
enabled = true;
} catch (Exception e) {
}
}
}
private synchronized void load() {
if (!enabled) return;
if (lastModified >= configFile.lastModified()) return;
try {
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
whitelist = null;
lastModified = configFile.lastModified();
} catch (IOException e) {
// Ignored
}
}
public boolean isEnabled() {
load();
if (config != null) {
return config.getBoolean("plugin-enabled", false) && enabled;
}
return enabled;
}
public boolean isOnlySteamWarJoin() {
load();
if (config != null) {
return config.getBoolean("force-only-steamwar-join", false);
}
return false;
}
public boolean isWhitelistEnabled() {
load();
if (config != null) {
return config.getBoolean("whitelist-enabled", false);
}
return false;
}
public Set<String> getWhitelist() {
load();
if (whitelist == null) {
if (config != null) {
whitelist = new HashSet<>(config.getStringList("whitelisted-players"));
} else {
whitelist = new HashSet<>();
}
}
return whitelist;
}
}

Datei anzeigen

@ -5,12 +5,16 @@ import net.md_5.bungee.api.plugin.Plugin;
public final class SteamWarBungeeTeamserver extends Plugin {
public static SteamWarBungeeTeamserver plugin;
@Override
public void onEnable() {
plugin = this;
getProxy().getPluginManager().registerListener(this, new SteamwarConnectionListener());
}
@Override
public void onDisable() {
plugin = null;
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package de.steamwar.listener;
import de.steamwar.ConfigSystem;
import io.netty.buffer.ByteBuf;
import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.api.plugin.Listener;
@ -15,6 +16,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Set;
import java.util.UUID;
import java.util.function.Supplier;
@ -68,12 +70,32 @@ public class SteamwarConnectionListener implements Listener {
@EventHandler
public void preLoginEvent(PreLoginEvent preLoginEvent) {
if (!ConfigSystem.isEnabled()) return;
String address = preLoginEvent.getConnection().getSocketAddress().toString();
if (address.startsWith("/78.31.71.136:")) {
InitialHandler initialHandler = (InitialHandler) preLoginEvent.getConnection();
String extraData = initialHandler.getExtraDataInHandshake();
String[] split = extraData.split("\0");
StringBuilder uuidStringBuilder = new StringBuilder(split[2]);
uuidStringBuilder.insert(8, '-');
uuidStringBuilder.insert(13, '-');
uuidStringBuilder.insert(18, '-');
uuidStringBuilder.insert(23, '-');
if (ConfigSystem.isWhitelistEnabled()) {
Set<String> whitelist = ConfigSystem.getWhitelist();
if (!whitelist.contains(uuidStringBuilder.toString())) {
preLoginEvent.setCancelled(true);
return;
}
if (!whitelist.contains(preLoginEvent.getConnection().getName())) {
preLoginEvent.setCancelled(true);
return;
}
}
try {
ChannelWrapper channelWrapper = ((ChannelWrapper) chField.get(initialHandler));
channelWrapper.setRemoteAddress(new InetSocketAddress(split[1], ((InetSocketAddress) channelWrapper.getRemoteAddress()).getPort()));
@ -85,12 +107,9 @@ public class SteamwarConnectionListener implements Listener {
// 0: host, 1: address, 2: uuid, (3): mojangProfile (properties, so skin data)
preLoginEvent.getConnection().setOnlineMode(false);
StringBuilder st = new StringBuilder(split[2]);
st.insert(8, '-');
st.insert(13, '-');
st.insert(18, '-');
st.insert(23, '-');
initialHandler.setUniqueId(UUID.fromString(st.toString()));
initialHandler.setUniqueId(UUID.fromString(uuidStringBuilder.toString()));
} else if (ConfigSystem.isOnlySteamWarJoin()) {
preLoginEvent.setCancelled(true);
}
}
}