SteamWar/BungeeCore
Archiviert
13
2

Add known Hostnames #511

Zusammengeführt
Lixfel hat 2 Commits von chaoscaot-add-hostnames-1 nach master 2024-03-14 21:47:54 +01:00 zusammengeführt
Nur Änderungen aus Commit 2c6de937b3 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -1,61 +1,63 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.mods;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.listeners.BasicListener;
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.event.EventHandler;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
public class Hostname extends BasicListener {
private final Set<String> knownHostnames = new HashSet<>();
private final Set<String> knownExtraData = new HashSet<>();
public Hostname() {
knownHostnames.add("steamwar.de");
knownHostnames.add("78.31.71.136");
knownHostnames.add("@mat:matdoes.dev"); //https://github.com/mat-1/matscan
knownHostnames.add("wtf.mynx.lol"); //https://discord.com/invite/serverseeker
knownHostnames.add("127.0.0.1"); // Geyser
knownExtraData.add("");
knownExtraData.add("\0FML\0");
knownExtraData.add("\0FML2\0");
knownExtraData.add("\0FML3\0");
knownExtraData.add("\0FORGE");
}
@EventHandler
public void onHandshake(PlayerHandshakeEvent event) {
String extraDataInHandshake = ((InitialHandler) event.getConnection()).getExtraDataInHandshake();
if (!knownHostnames.contains(event.getHandshake().getHost().toLowerCase())) {
BungeeCore.get().getLogger().log(Level.WARNING, () -> event.getConnection().getSocketAddress() + " connected with unknown hostname " + event.getHandshake() + " " + extraDataInHandshake);
} else if (!knownExtraData.contains(extraDataInHandshake)) {
BungeeCore.get().getLogger().log(Level.WARNING, () -> event.getConnection().getSocketAddress() + " connected with unknown extra data " + event.getHandshake() + " " + extraDataInHandshake);
}
}
}
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.mods;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.listeners.BasicListener;
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.event.EventHandler;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
public class Hostname extends BasicListener {
private final Set<String> knownHostnames = new HashSet<>();
private final Set<String> knownExtraData = new HashSet<>();
public Hostname() {
knownHostnames.add("steamwar.de");
knownHostnames.add("78.31.71.136");
knownHostnames.add("@mat:matdoes.dev"); //https://github.com/mat-1/matscan
knownHostnames.add("wtf.mynx.lol"); //https://discord.com/invite/serverseeker
knownHostnames.add("127.0.0.1"); // Geyser
knownHostnames.add("memewar.de");
knownHostnames.add("dampfkrieg.de");
knownExtraData.add("");
knownExtraData.add("\0FML\0");
knownExtraData.add("\0FML2\0");
knownExtraData.add("\0FML3\0");
knownExtraData.add("\0FORGE");
}
@EventHandler
public void onHandshake(PlayerHandshakeEvent event) {
String extraDataInHandshake = ((InitialHandler) event.getConnection()).getExtraDataInHandshake();
if (!knownHostnames.contains(event.getHandshake().getHost().toLowerCase())) {
BungeeCore.get().getLogger().log(Level.WARNING, () -> event.getConnection().getSocketAddress() + " connected with unknown hostname " + event.getHandshake() + " " + extraDataInHandshake);
} else if (!knownExtraData.contains(extraDataInHandshake)) {
BungeeCore.get().getLogger().log(Level.WARNING, () -> event.getConnection().getSocketAddress() + " connected with unknown extra data " + event.getHandshake() + " " + extraDataInHandshake);
}
}
}