forked from SteamWar/SteamWar
Remove SWTSI (SteamWar Teamserver Integration)
This commit is contained in:
@@ -430,83 +430,6 @@ public class TeamCommand extends SWCommand {
|
||||
DiscordBot.withBot(bot -> bot.getEventChannel().update());
|
||||
}
|
||||
|
||||
@Register("tp")
|
||||
public void tp(@Validator("isInTeam") PlayerChatter sender) {
|
||||
Team team = Team.byId(sender.user().getTeam());
|
||||
tp(sender, team);
|
||||
}
|
||||
|
||||
@Register("tp")
|
||||
public void tp(PlayerChatter sender, @ErrorMessage("TEAM_TP_NO_TEAM") Team targetTeam) {
|
||||
if (targetTeam.getAddress() == null || targetTeam.getAddress().isEmpty()) {
|
||||
sender.system("TEAM_NO_ADDRESS");
|
||||
return;
|
||||
}
|
||||
|
||||
InetSocketAddress address;
|
||||
ServerInfo serverInfo;
|
||||
try {
|
||||
address = new InetSocketAddress(targetTeam.getAddress(), targetTeam.getPort());
|
||||
serverInfo = Storage.teamServers.computeIfAbsent(targetTeam.getTeamId(), integer -> {
|
||||
ServerInfo info = new ServerInfo("Team " + targetTeam.getTeamKuerzel(), address);
|
||||
RegisteredServer server = VelocityCore.getProxy().registerServer(info);
|
||||
ServerPing serverPing = server.ping().join();
|
||||
((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().put(info.getName(), serverPing.getVersion().getProtocol());
|
||||
return info;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
sender.system("TEAM_NO_ADDRESS");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!address.equals(serverInfo.getAddress())) {
|
||||
VelocityCore.getProxy().unregisterServer(Storage.teamServers.remove(targetTeam.getTeamId()));
|
||||
tp(sender, targetTeam);
|
||||
return;
|
||||
}
|
||||
|
||||
sender.getPlayer().createConnectionRequest(VelocityCore.getProxy().getServer(serverInfo.getName()).orElseThrow()).connect().whenComplete((result, throwable) -> {
|
||||
if(result.getStatus() != ConnectionRequestBuilder.Status.SUCCESS || throwable != null)
|
||||
sender.system("TEAM_OFFLINE");
|
||||
});
|
||||
}
|
||||
|
||||
@Register(value = "server", description = "TEAM_SERVER_USAGE")
|
||||
public void server(@Validator("isLeader") Chatter sender, String server, @Min(intValue = 1) @Max(intValue = 65535) @ErrorMessage("TEAM_SERVER_PORT_INVALID") int port){
|
||||
Team team = Team.byId(sender.user().getTeam());
|
||||
if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoTeamServer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isLocalhost(InetAddress.getByName(server))) {
|
||||
sender.system("TEAM_SERVER_ADDRESS_INVALID");
|
||||
return;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
sender.system("TEAM_SERVER_ADDRESS_INVALID");
|
||||
return;
|
||||
}
|
||||
|
||||
team.setAddress(server);
|
||||
team.setPort(port);
|
||||
Storage.teamServers.remove(team.getTeamId());
|
||||
sender.system("TEAM_SERVER_SET");
|
||||
}
|
||||
|
||||
public static boolean isLocalhost(InetAddress addr) {
|
||||
// Check if the address is a valid special local or loop back
|
||||
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
|
||||
return true;
|
||||
|
||||
// Check if the address is defined on any interface
|
||||
try {
|
||||
return NetworkInterface.getByInetAddress(addr) != null;
|
||||
} catch (SocketException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<String, Integer> COLOR_CODES = new HashMap<>();
|
||||
|
||||
static {
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
|
||||
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
@@ -37,7 +36,6 @@ import de.steamwar.network.packets.NetworkPacket;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import de.steamwar.velocitycore.VelocityCore;
|
||||
import de.steamwar.velocitycore.commands.TeamCommand;
|
||||
import de.steamwar.velocitycore.mods.*;
|
||||
import de.steamwar.velocitycore.network.ServerMetaInfo;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -470,7 +468,7 @@ public class PluginMessage extends BasicListener {
|
||||
register("minecraft:brand", false, directional(this::steamWarBrand, UNKNOWN));
|
||||
|
||||
//Needs to be registered cause paper refuses to send PluginMessages on unregistered channels...
|
||||
register("sw:bridge", true, directional(onlySWSource(async(event -> NetworkPacket.handle(new ServerMetaInfo((ServerConnection) event.getSource()), event.getData()))), UNKNOWN));
|
||||
register("sw:bridge", true, directional(async(event -> NetworkPacket.handle(new ServerMetaInfo((ServerConnection) event.getSource()), event.getData())), UNKNOWN));
|
||||
registerPassthroughToServer("sw:hotkeys");
|
||||
register("fabricmodsender:mods", true, directional(UNKNOWN, async(new FabricModSender()::handlePluginMessage)));
|
||||
|
||||
@@ -574,16 +572,6 @@ public class PluginMessage extends BasicListener {
|
||||
};
|
||||
}
|
||||
|
||||
private Parser onlySWSource(Parser parser) {
|
||||
return event -> {
|
||||
ChannelMessageSource sender = event.getSource();
|
||||
if(TeamCommand.isLocalhost(sender instanceof Player player ? IPSanitizer.getTrueAddress(player) : ((ServerConnection) sender).getServerInfo().getAddress().getAddress()))
|
||||
parser.handle(event);
|
||||
else
|
||||
UNKNOWN.handle(event);
|
||||
};
|
||||
}
|
||||
|
||||
private Parser async(Parser parser) {
|
||||
return event -> VelocityCore.schedule(() -> parser.handle(event)).schedule();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user