SteamWar/BungeeCore
Archiviert
13
2

Merge branch 'master' into tablist

# Conflicts:
#	src/de/steamwar/bungeecore/BungeeCore.java
Dieser Commit ist enthalten in:
Lixfel 2022-06-15 21:36:56 +02:00
Commit 41a5c3b207
41 geänderte Dateien mit 642 neuen und 815 gelöschten Zeilen

@ -1 +1 @@
Subproject commit 492894ca8d41ee0bde4dcb9d520db5f7478c50c7
Subproject commit 8dbab5b132d2fd84db202d691fd1f817f91579d6

Datei anzeigen

@ -22,11 +22,15 @@ package de.steamwar.bungeecore;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.bungeecore.commands.*;
import de.steamwar.bungeecore.comms.SpigotReceiver;
import de.steamwar.bungeecore.listeners.*;
import de.steamwar.bungeecore.listeners.mods.*;
import de.steamwar.bungeecore.network.BungeeNetworkHandler;
import de.steamwar.bungeecore.network.NetworkReceiver;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.bungeecore.tablist.TablistManager;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.SWTypeMapperCreator;
import de.steamwar.command.TypeMapper;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
@ -42,6 +46,7 @@ import net.md_5.bungee.config.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -68,6 +73,18 @@ public class BungeeCore extends Plugin {
@Override
public void onEnable(){
SWCommandUtils.init((SWTypeMapperCreator<TypeMapper<Object>, CommandSender, Object>) (mapper, tabCompleter) -> new TypeMapper<Object>() {
@Override
public Object map(CommandSender commandSender, String[] previousArguments, String s) {
return mapper.apply(s);
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
return tabCompleter.apply(sender, s);
}
});
getProxy().registerChannel("sw:bridge");
getProxy().registerChannel("fabricmodsender:mods");
@ -158,7 +175,8 @@ public class BungeeCore extends Plugin {
new EventStarter();
new SessionManager();
new SpigotReceiver();
new NetworkReceiver();
BungeeNetworkHandler.register();
tablistManager = new TablistManager();
new SettingsChangedListener();
@ -249,6 +267,7 @@ public class BungeeCore extends Plugin {
get().getLogger().log(Level.SEVERE, msg, e);
}
private static void loadConfig(){
Configuration config;
try{

Datei anzeigen

@ -26,7 +26,7 @@ public class ServerStarter {
private static final String EVENT_PATH = BACKBONE + "event/";
public static final String TEMP_WORLD_PATH = BACKBONE + "arenaserver/";
public static final String TUTORIAL_PATH = BACKBONE + "tutorials/";
public static final String WORLDS18_PATH = BACKBONE + "userworlds18/";
public static final String WORLDS19_PATH = BACKBONE + "userworlds19/";
private File directory = null;
private String worldDir = null;
@ -109,10 +109,10 @@ public class ServerStarter {
return this;
}
public ServerStarter build18(UUID owner) {
directory = new File(SERVER_PATH, "Bau18");
serverJar = "paper-1.18.2.jar";
worldDir = WORLDS18_PATH;
public ServerStarter build19(UUID owner) {
directory = new File(SERVER_PATH, "Bau19");
serverJar = "paper-1.19.jar";
worldDir = WORLDS19_PATH;
worldName = String.valueOf(SteamwarUser.get(owner).getId());
buildWithWorld(owner, new File(directory, "Bauwelt").getPath());
return this;

Datei anzeigen

@ -19,10 +19,11 @@
package de.steamwar.bungeecore;
import de.steamwar.bungeecore.comms.handlers.FightInfoHandler;
import de.steamwar.bungeecore.comms.packets.StartingServerPacket;
import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.network.handlers.FightInfoHandler;
import de.steamwar.bungeecore.sql.IgnoreSystem;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.network.packets.server.StartingServerPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -53,6 +54,6 @@ public class SubserverSystem {
public static void sendPlayer(Subserver subserver, ProxiedPlayer player) {
subserver.sendPlayer(player);
if(!subserver.hasStarted() && FightInfoHandler.onLobby(player))
new StartingServerPacket(SteamwarUser.get(player.getUniqueId())).send(player);
NetworkSender.send(player, new StartingServerPacket(SteamwarUser.get(player.getUniqueId()).getId()));
}
}

Datei anzeigen

@ -20,12 +20,13 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.comms.packets.BaumemberUpdatePacket;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.sql.BauweltMember;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.messages.ChatSender;
import de.steamwar.network.packets.server.BaumemberUpdatePacket;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
@ -46,7 +47,7 @@ public class BauCommand extends BasicCommand {
ProxiedPlayer p = (ProxiedPlayer) sender;
versionSelector(p, args, 0,
() -> new ServerStarter().build18(p.getUniqueId()).send(p).start(),
() -> new ServerStarter().build19(p.getUniqueId()).send(p).start(),
() -> new ServerStarter().build15(p.getUniqueId()).send(p).start(),
() -> new ServerStarter().build12(p.getUniqueId()).send(p).start(),
() -> {
@ -128,13 +129,13 @@ public class BauCommand extends BasicCommand {
}
versionSelector(p, args, 2,
() -> new ServerStarter().build18(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build19(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build15(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build12(worldOwner.getUuid()).send(p).start(),
() -> HelpCommand.sendBauHelp(ChatSender.of(p)));
}
private static void versionSelector(ProxiedPlayer p, String[] args, int pos, Runnable run18, Runnable run15, Runnable run12, Runnable runElse) {
private static void versionSelector(ProxiedPlayer p, String[] args, int pos, Runnable run19, Runnable run15, Runnable run12, Runnable runElse) {
if(args.length <= pos) {
int version = p.getPendingConnection().getVersion();
if(version > 340) { // Version > 1.12.2
@ -146,9 +147,11 @@ public class BauCommand extends BasicCommand {
}
switch (args[pos].toLowerCase()) {
case "19":
case "1.19":
case "18":
case "1.18":
run18.run();
run19.run();
break;
case "ws":
case "warship":
@ -195,7 +198,7 @@ public class BauCommand extends BasicCommand {
for(ServerInfo info : ProxyServer.getInstance().getServers().values()){
Subserver server = Subserver.getSubserver(info);
if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())){
info.getPlayers().stream().findAny().ifPresent(player -> new BaumemberUpdatePacket().send(player));
info.getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket()));
break;
}
}
@ -231,7 +234,7 @@ public class BauCommand extends BasicCommand {
private static void delete(ProxiedPlayer p, String[] args){
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
versionSelector(p, args, 1,
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS18_PATH + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS19_PATH + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, BungeeCore.WORLD_FOLDER + p.getUniqueId().toString())),
() -> HelpCommand.sendBauHelp(ChatSender.of(p)));

Datei anzeigen

@ -25,9 +25,7 @@ import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.messages.ChatSender;
import io.netty.channel.ConnectTimeoutException;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
@ -566,11 +564,6 @@ public class TeamCommand extends BasicCommand {
}
private void tp(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if (!user.getUserGroup().isAdminGroup()) {
Message.send("DISABLED", player);
return;
}
if(args.length == 1){
if(notInTeam(player, user))
return;
@ -617,11 +610,6 @@ public class TeamCommand extends BasicCommand {
}
private void server(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if (!user.getUserGroup().isAdminGroup()) {
Message.send("DISABLED", player);
return;
}
if(notLeader(player, user, team))
return;
if (user.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) {
@ -660,7 +648,7 @@ public class TeamCommand extends BasicCommand {
Message.send("TEAM_SERVER_SET", player);
}
private static boolean isLocalhost(InetAddress addr) {
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;

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.CommandSender;
@ -55,7 +56,7 @@ public class TpCommand extends BasicCommand {
//Give control of teleport command to server
if(server == null) {
player.chat("/tp " + String.join(" ", args));
Chat19.chat(player, "/tp " + String.join(" ", args));
return;
}

Datei anzeigen

@ -1,47 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import java.io.ByteArrayOutputStream;
public abstract class BungeePacket {
public void send(Server server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeByte(getId());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writeVars(out);
out.writeUTF(outputStream.toByteArray().toString());
server.sendData("sw:bridge", out.toByteArray());
}
public void send(ProxiedPlayer player) {
send(player.getServer());
}
public abstract int getId();
public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput);
}

Datei anzeigen

@ -1,43 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms;
public class PacketIdManager {
//0x0(X) Standalone Packets
public static final byte PING_PACKET = 0x01;
public static final byte TABLIST_NAME = 0x02;
public static final byte PREPARE_SCHEM = 0x03;
public static final byte BAUMEMBER_UPDATE = 0x04;
public static final byte EXECUTE_COMMAND = 0x05;
public static final byte LOCALE_INVALIDATION = 0x06;
//0x1(X) Bungee Inventory
public static final byte INVENTORY_PACKET = 0x10;
public static final byte INVENTORY_CALLBACK_PACKET = 0x11;
public static final byte INVENTORY_CLOSE_PACKET = 0x12;
//0x2(X) Server Information System
public static final byte I_AM_A_LOBBY = 0x20;
public static final byte FIGHT_INFO = 0x21;
public static final byte FIGHT_ENDS = 0x22;
public static final byte STARTING_SERVER = 0x23;
}

Datei anzeigen

@ -1,28 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms;
import com.google.common.io.ByteArrayDataInput;
import net.md_5.bungee.api.config.ServerInfo;
public interface SpigotHandler {
void handle(ByteArrayDataInput in, ServerInfo info);
}

Datei anzeigen

@ -1,66 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.comms.handlers.*;
import de.steamwar.bungeecore.listeners.BasicListener;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.event.EventHandler;
import java.util.HashMap;
import java.util.Map;
public class SpigotReceiver extends BasicListener {
private static final Map<Byte, SpigotHandler> handlerMap = new HashMap<>();
@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
return;
event.setCancelled(true);
if(!(event.getSender() instanceof Server))
return;
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
Byte handler = in.readByte();
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> handlerMap.get(handler).handle(in, ((Server) event.getSender()).getInfo()));
}
public static void registerHandler(Byte id, SpigotHandler handler) {
handlerMap.put(id, handler);
}
static {
registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler());
registerHandler(PacketIdManager.TABLIST_NAME, (in, info) -> {});
registerHandler(PacketIdManager.PREPARE_SCHEM, new PrepareSchemHandler());
registerHandler(PacketIdManager.I_AM_A_LOBBY, new ImALobbyHandler());
registerHandler(PacketIdManager.FIGHT_INFO, new FightInfoHandler());
registerHandler(PacketIdManager.EXECUTE_COMMAND, new ExecuteCommandHandler());
registerHandler(PacketIdManager.FIGHT_ENDS, new FightEndsHandler());
}
}

Datei anzeigen

@ -1,36 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
public class BaumemberUpdatePacket extends BungeePacket {
@Override
public int getId() {
return PacketIdManager.BAUMEMBER_UPDATE;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
// empty
}
}

Datei anzeigen

@ -1,43 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
public class CloseInventoryPacket extends BungeePacket {
final int player;
@Override
public int getId() {
return PacketIdManager.INVENTORY_CLOSE_PACKET;
}
public CloseInventoryPacket(int player) {
this.player = player;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(player);
}
}

Datei anzeigen

@ -1,80 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.comms.packets;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor
@Getter
public class FightEndsPacket extends BungeePacket {
private byte win;
private int blueSchem;
private int redSchem;
private List<Integer> bluePlayers;
private List<Integer> redPlayers;
private String gameMode;
public FightEndsPacket(ByteArrayDataInput byteArrayDataInput) {
win = byteArrayDataInput.readByte();
blueSchem = byteArrayDataInput.readInt();
redSchem = byteArrayDataInput.readInt();
int blueSize = byteArrayDataInput.readInt();
bluePlayers = new ArrayList<>(blueSize);
for (int i = 0; i < blueSize; i++) {
bluePlayers.add(byteArrayDataInput.readInt());
}
int redSize = byteArrayDataInput.readInt();
redPlayers = new ArrayList<>(redSize);
for (int i = 0; i < redSize; i++) {
redPlayers.add(byteArrayDataInput.readInt());
}
gameMode = byteArrayDataInput.readUTF();
}
@Override
public int getId() {
return PacketIdManager.FIGHT_ENDS;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeByte(win);
byteArrayDataOutput.writeInt(blueSchem);
byteArrayDataOutput.writeInt(redSchem);
byteArrayDataOutput.writeInt(bluePlayers.size());
for (int i : bluePlayers) {
byteArrayDataOutput.writeInt(i);
}
byteArrayDataOutput.writeInt(redPlayers.size());
for (int i : redPlayers) {
byteArrayDataOutput.writeInt(i);
}
byteArrayDataOutput.writeUTF(gameMode);
}
}

Datei anzeigen

@ -1,183 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms.packets;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
import java.util.ArrayList;
import java.util.List;
public class FightInfoPacket extends BungeePacket {
private String serverName; // Name of the Server
private final String gameMode; // GameMode aka Schematictype (if known, else "")
private final String arena; // Name of the arena
private final String blueName; // Name of the blue team, expected to begin with "§a" colorcode
private final String redName; // Name of the red team, expected to begin with "§a" colorcode
private final String fightState; // Fight state (technical term) (if known, else "")
private final int countdown; // Countdown state in seconds (if known, else 0)
private final int blueLeader; // SWUserID of the blue team leader (if known, else 0)
private final int redLeader; // SWUserID of the red team leader (if known, else 0)
private final int blueSchem; // Blue SchemID (if known, else 0)
private final int redSchem; // Red SchemID (if known, else 0)
private final List<Integer> bluePlayers; // List of Blue SWUserIDs
private final List<Integer> redPlayers; // List of Red SWUserIDs
private final List<Integer> spectators; // List of Spectator SWUserIDs
public FightInfoPacket(String serverName, String gameMode, String arena, String blueName, String redName, String fightState, int countdown, int blueLeader, int redLeader, int blueSchem, int redSchem, List<Integer> bluePlayers, List<Integer> redPlayers, List<Integer> spectators) {
this.serverName = serverName;
this.gameMode = gameMode;
this.arena = arena;
this.blueName = blueName;
this.redName = redName;
this.fightState = fightState;
this.countdown = countdown;
this.blueLeader = blueLeader;
this.redLeader = redLeader;
this.blueSchem = blueSchem;
this.redSchem = redSchem;
this.bluePlayers = bluePlayers;
this.redPlayers = redPlayers;
this.spectators = spectators;
}
public FightInfoPacket(ByteArrayDataInput in) {
this.serverName = in.readUTF();
this.gameMode = in.readUTF();
this.arena = in.readUTF();
this.blueName = in.readUTF();
this.redName = in.readUTF();
this.fightState = in.readUTF();
this.countdown = in.readInt();
this.blueLeader = in.readInt();
this.redLeader = in.readInt();
this.blueSchem = in.readInt();
this.redSchem = in.readInt();
this.bluePlayers = readPlayerList(in);
this.redPlayers = readPlayerList(in);
this.spectators = readPlayerList(in);
}
@Override
public int getId() {
return PacketIdManager.FIGHT_INFO;
}
@Override
public void writeVars(ByteArrayDataOutput out) {
out.writeUTF(serverName);
out.writeUTF(gameMode);
out.writeUTF(arena);
out.writeUTF(blueName);
out.writeUTF(redName);
out.writeUTF(fightState);
out.writeInt(countdown);
out.writeInt(blueLeader);
out.writeInt(redLeader);
out.writeInt(blueSchem);
out.writeInt(redSchem);
writePlayerList(out, bluePlayers);
writePlayerList(out, redPlayers);
writePlayerList(out, spectators);
}
public String getServerName() {
return serverName;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
public String getGameMode() {
return gameMode;
}
public String getArena() {
return arena;
}
public String getBlueName() {
return blueName;
}
public String getRedName() {
return redName;
}
public String getFightState() {
return fightState;
}
public int getCountdown() {
return countdown;
}
public int getBlueLeader() {
return blueLeader;
}
public int getRedLeader() {
return redLeader;
}
public int getBlueSchem() {
return blueSchem;
}
public int getRedSchem() {
return redSchem;
}
public List<Integer> getBluePlayers() {
return bluePlayers;
}
public List<Integer> getRedPlayers() {
return redPlayers;
}
public List<Integer> getSpectators() {
return spectators;
}
public int playerSize(){
return bluePlayers.size() + redPlayers.size() + spectators.size();
}
private static List<Integer> readPlayerList(ByteArrayDataInput in) {
int length = in.readInt();
List<Integer> players = new ArrayList<>(length);
for(int i = 0; i < length; i++) {
players.add(in.readInt());
}
return players;
}
private void writePlayerList(ByteArrayDataOutput out, List<Integer> players) {
out.writeInt(players.size());
for(Integer player : players) {
out.writeInt(player);
}
}
}

Datei anzeigen

@ -1,80 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import de.steamwar.bungeecore.comms.PacketIdManager;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.HashMap;
import java.util.Map;
public class InventoryPacket extends BungeePacket {
final String title;
final int player;
final int size;
final Map<Integer, SWItem> items;
public InventoryPacket(int size, String title, ProxiedPlayer player) {
items = new HashMap<>();
this.title = title;
this.size = size;
this.player = SteamwarUser.get(player).getId();
}
public InventoryPacket(SWInventory inventory) {
items = inventory.getItems();
this.title = inventory.getTitle();
this.size = inventory.getSize();
this.player = SteamwarUser.get(inventory.getPlayer()).getId();
}
@Override
public int getId() {
return PacketIdManager.INVENTORY_PACKET;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
JsonObject object = new JsonObject();
object.addProperty("id", player);
object.addProperty("title", title);
object.addProperty("size", size);
object.addProperty("itemcount", items.size());
JsonArray array = new JsonArray();
for (int i = 0; i < size; i++) {
if(items.get(i) != null)
array.add(items.get(i).writeToString(i));
}
object.add("items", array);
byteArrayDataOutput.writeUTF(object.toString());
}
public void setItem(int index, SWItem item) {
items.put(index, item);
}
}

Datei anzeigen

@ -1,43 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
public class PingPacket extends BungeePacket {
final int id;
@Override
public int getId() {
return PacketIdManager.PING_PACKET;
}
public PingPacket(int id) {
this.id = id;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(id);
}
}

Datei anzeigen

@ -1,25 +0,0 @@
package de.steamwar.bungeecore.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
import de.steamwar.bungeecore.sql.SteamwarUser;
public class StartingServerPacket extends BungeePacket {
private final int user;
public StartingServerPacket(SteamwarUser user) {
this.user = user.getId();
}
@Override
public int getId() {
return PacketIdManager.STARTING_SERVER;
}
@Override
public void writeVars(ByteArrayDataOutput out) {
out.writeInt(user);
}
}

Datei anzeigen

@ -19,10 +19,11 @@
package de.steamwar.bungeecore.inventory;
import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
import de.steamwar.bungeecore.comms.packets.InventoryPacket;
import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.network.packets.server.CloseInventoryPacket;
import de.steamwar.network.packets.server.InventoryPacket;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.ArrayList;
@ -30,6 +31,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiFunction;
public class SWInventory {
@ -120,8 +122,14 @@ public class SWInventory {
}
public void open() {
InventoryPacket inv = new InventoryPacket(this);
inv.send(player);
InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).toString()));
NetworkSender.send(player, inv);
}
private static <T, K, J> Map<T, J> map(Map<T, K> map, BiFunction<T, K, J> function) {
Map<T, J> result = new HashMap<>();
map.forEach((key, value) -> result.put(key, function.apply(key, value)));
return result;
}
public void close() {
@ -129,7 +137,7 @@ public class SWInventory {
}
public static void close(ProxiedPlayer player) {
new CloseInventoryPacket(SteamwarUser.get(player).getId()).send(player);
NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player).getId()));
}
public void setClose(InvCallback close) {

Datei anzeigen

@ -21,9 +21,11 @@ package de.steamwar.bungeecore.listeners;
import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.bungeecore.comms.packets.PingPacket;
import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.messages.ChatSender;
import de.steamwar.network.packets.server.PingPacket;
import net.md_5.bungee.api.*;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
@ -123,7 +125,7 @@ public class ChatListener extends BasicListener {
return;
}
player.chat(message);
Chat19.chat(player, message);
}
private static String modifyFilter(ChatSender sender, String message) {
@ -202,7 +204,7 @@ public class ChatListener extends BasicListener {
String mark = "@" + player.user().getUserName();
return Arrays.stream(message.split(" ")).map(cur -> {
if(cur.equalsIgnoreCase(mark)) {
new PingPacket(player.user().getId()).send(player.user().getPlayer());
NetworkSender.send(player.user().getPlayer(), new PingPacket(player.user().getId()));
return "§e" + cur + returnColor;
}
return cur;

Datei anzeigen

@ -26,10 +26,10 @@ import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.comms.packets.FightInfoPacket;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.UserGroup;
import net.md_5.bungee.BungeeCord;
import de.steamwar.network.packets.common.FightInfoPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;

Datei anzeigen

@ -41,6 +41,7 @@ import java.nio.charset.UnsupportedCharsetException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class Fabric extends BasicListener {
@ -59,7 +60,7 @@ public class Fabric extends BasicListener {
continue;
}
if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) {
banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey());
banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey(), "Expected message not received");
return;
}
}
@ -82,7 +83,7 @@ public class Fabric extends BasicListener {
if (!Storage.fabricCheckedPlayers.containsKey(player)) {
synchronized (Storage.fabricExpectPluginMessage) {
if (Storage.fabricExpectPluginMessage.containsKey(player)) {
banPlayer(user, player);
banPlayer(user, player, "Was not fabric checked but send message nonetheless");
return;
}
}
@ -95,7 +96,7 @@ public class Fabric extends BasicListener {
Utils.VarInt varInt = Utils.readVarInt(data,0);
if(data.length != varInt.length + varInt.value) {
banPlayer(user,player);
banPlayer(user,player, "Invalid message length");
return;
}
@ -106,7 +107,7 @@ public class Fabric extends BasicListener {
try{
dataString = new String(data, StandardCharsets.UTF_8);
}catch (UnsupportedCharsetException exception) {
banPlayer(user, player);
banPlayer(user, player, "Unsupported charset");
return;
}
@ -115,7 +116,7 @@ public class Fabric extends BasicListener {
try {
array = new JsonParser().parse(dataString).getAsJsonArray();
}catch (JsonSyntaxException exception) {
banPlayer(user, player);
banPlayer(user, player, "Invalid json");
return;
}
@ -126,12 +127,12 @@ public class Fabric extends BasicListener {
boolean isSorted = isSortedAlphabetically(mods);
if(!isSorted) {
banPlayer(user, player);
banPlayer(user, player, "Mods are not sorted alphabetically: " + mods.stream().map(Mod::getModName).collect(Collectors.joining(", ")));
return;
}
if(!neededModsContained(mods)) {
banPlayer(user, player);
banPlayer(user, player, "Needed mods are not contained");
return;
}
@ -139,7 +140,7 @@ public class Fabric extends BasicListener {
if (Storage.fabricCheckedPlayers.containsKey(player)) {
long current = Storage.fabricCheckedPlayers.get(player);
if (current != dataString.hashCode()) {
banPlayer(user, player);
banPlayer(user, player, "");
return;
}
} else {
@ -176,11 +177,11 @@ public class Fabric extends BasicListener {
.count() == neededMods.size();
}
public void banPlayer(SteamwarUser user, ProxiedPlayer player) {
public void banPlayer(SteamwarUser user, ProxiedPlayer player, String reason) {
user.punishPerma(Punishment.PunishmentType.Ban,
Message.parse("MODIFICATION_BAN_MESSAGE", player, user.getUserName(), user.getId()),
0);
BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName()));
BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName(), reason));
}
public static void remove(ProxiedPlayer player) {

Datei anzeigen

@ -0,0 +1,35 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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.network;
import de.steamwar.bungeecore.network.handlers.*;
import lombok.experimental.UtilityClass;
@UtilityClass
public class BungeeNetworkHandler {
public static void register() {
new ExecuteCommandHandler().register();
new FightEndsHandler().register();
new FightInfoHandler().register();
new ImALobbyHandler().register();
new InventoryCallbackHandler().register();
new PrepareSchemHandler().register();
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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.network;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.commands.TeamCommand;
import de.steamwar.bungeecore.listeners.BasicListener;
import de.steamwar.network.packets.NetworkPacket;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
public class NetworkReceiver extends BasicListener {
private static final List<String> blockedTags = Arrays.asList("bungeecord:main", "BungeeCord", "sw:bridge");
@EventHandler(priority = EventPriority.HIGHEST)
public void onPluginMessage(PluginMessageEvent event) {
if (blockedTags.contains(event.getTag()) && !TeamCommand.isLocalhost(((InetSocketAddress) event.getSender().getSocketAddress()).getAddress())) {
BungeeCore.log(Level.SEVERE, ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag());
event.setCancelled(true);
return;
}
if(!event.getTag().equals("sw:bridge"))
return;
event.setCancelled(true);
if(!(event.getSender() instanceof Server))
return;
NetworkPacket.handle(new ServerMetaInfo(((Server) event.getSender()).getInfo()), event.getData());
}
}

Datei anzeigen

@ -0,0 +1,38 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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.network;
import de.steamwar.network.packets.NetworkPacket;
import lombok.SneakyThrows;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class NetworkSender {
@SneakyThrows
public static void send(ProxiedPlayer player, NetworkPacket packet) {
player.getServer().sendData("sw:bridge", packet.serialize());
}
public static void send(ServerInfo serverInfo, NetworkPacket packet) {
ProxiedPlayer player = serverInfo.getPlayers().iterator().next();
send(player, packet);
}
}

Datei anzeigen

@ -17,27 +17,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.packets;
package de.steamwar.bungeecore.network;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.bungeecore.comms.BungeePacket;
import de.steamwar.bungeecore.comms.PacketIdManager;
import de.steamwar.network.packets.MetaInfos;
import net.md_5.bungee.api.config.ServerInfo;
public class LocaleInvalidationPacket extends BungeePacket {
public class ServerMetaInfo implements MetaInfos {
private int userId;
private ServerInfo sender;
public LocaleInvalidationPacket(int userId) {
this.userId = userId;
public ServerMetaInfo(ServerInfo sender) {
this.sender = sender;
}
@Override
public int getId() {
return PacketIdManager.LOCALE_INVALIDATION;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(userId);
public ServerInfo getSender() {
return sender;
}
}

Datei anzeigen

@ -17,19 +17,19 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.handlers;
package de.steamwar.bungeecore.network.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.client.ExecuteCommandPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
public class ExecuteCommandHandler implements SpigotHandler {
@Override
public void handle(ByteArrayDataInput in, ServerInfo info) {
SteamwarUser target = SteamwarUser.get(in.readInt());
String command = in.readUTF();
public class ExecuteCommandHandler extends PacketHandler {
@Handler
public void handle(ExecuteCommandPacket packet) {
SteamwarUser target = SteamwarUser.get(packet.getPlayerId());
String command = packet.getCommand();
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getPlayer(target.getUuid()), command);
}

Datei anzeigen

@ -17,20 +17,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.handlers;
package de.steamwar.bungeecore.network.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.comms.packets.FightEndsPacket;
import de.steamwar.bungeecore.sql.*;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.common.FightEndsPacket;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.config.ServerInfo;
import java.util.*;
import java.util.stream.Collectors;
public class FightEndsHandler implements SpigotHandler {
public class FightEndsHandler extends PacketHandler {
private Map<String, LinkedList<Game>> gameModeGames = new HashMap<>();
@ -46,10 +44,8 @@ public class FightEndsHandler implements SpigotHandler {
fightCounts.put("miniwargear", 3L);
}
@Override
public void handle(ByteArrayDataInput in, ServerInfo info) {
FightEndsPacket fightEndsPacket = new FightEndsPacket(in);
@Handler
public void handle(FightEndsPacket fightEndsPacket) {
if (!ArenaMode.getBySchemType(SchematicType.fromDB(fightEndsPacket.getGameMode())).isRanked()) {
return;
}

Datei anzeigen

@ -17,12 +17,14 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.handlers;
package de.steamwar.bungeecore.network.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.comms.packets.FightInfoPacket;
import de.steamwar.bungeecore.listeners.TablistManager;
import de.steamwar.bungeecore.network.NetworkReceiver;
import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.network.ServerMetaInfo;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.common.FightInfoPacket;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -30,7 +32,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class FightInfoHandler implements SpigotHandler {
public class FightInfoHandler extends PacketHandler {
private static final Set<ServerInfo> lobbys = new HashSet<>();
@ -42,10 +44,11 @@ public class FightInfoHandler implements SpigotHandler {
return lobbys.contains(player.getServer().getInfo());
}
@Override
public void handle(ByteArrayDataInput in, ServerInfo info) {
FightInfoPacket packet = new FightInfoPacket(in);
packet.setServerName(info.getName());
@Handler
public void handle(FightInfoPacket packet) {
ServerInfo info = ((ServerMetaInfo) packet.getMetaInfos()).getSender();
FightInfoPacket lobbyPacket = packet.withServerName(info.getName());
TablistManager.newFightInfo(info, packet);
@ -58,7 +61,7 @@ public class FightInfoHandler implements SpigotHandler {
continue;
}
packet.send(it.next());
NetworkSender.send(lobby, lobbyPacket);
}
}
}

Datei anzeigen

@ -17,16 +17,16 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.handlers;
package de.steamwar.bungeecore.network.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.comms.SpigotHandler;
import net.md_5.bungee.api.config.ServerInfo;
import de.steamwar.bungeecore.network.ServerMetaInfo;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.client.ImALobbyPacket;
public class ImALobbyHandler implements SpigotHandler {
public class ImALobbyHandler extends PacketHandler {
@Override
public void handle(ByteArrayDataInput in, ServerInfo info) {
FightInfoHandler.addLobby(info);
@Handler
public void handle(ImALobbyPacket packet) {
FightInfoHandler.addLobby(((ServerMetaInfo) packet.getMetaInfos()).getSender());
}
}

Datei anzeigen

@ -17,41 +17,44 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.handlers;
package de.steamwar.bungeecore.network.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.comms.packets.CloseInventoryPacket;
import de.steamwar.bungeecore.inventory.InvCallback;
import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.network.NetworkReceiver;
import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.network.ServerMetaInfo;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.client.InventoryCallbackPacket;
import de.steamwar.network.packets.server.CloseInventoryPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import java.util.HashMap;
import java.util.Map;
public class InventoryCallbackHandler implements SpigotHandler {
public class InventoryCallbackHandler extends PacketHandler {
public static final Map<Integer, SWInventory> inventoryHashMap = new HashMap<>();
@Override
public void handle(ByteArrayDataInput in, ServerInfo info) {
SteamwarUser owner = SteamwarUser.get(in.readInt());
CallbackType type = CallbackType.valueOf(in.readUTF());
@Handler
public void handle(InventoryCallbackPacket packet) {
SteamwarUser owner = SteamwarUser.get(packet.getOwner());
InventoryCallbackPacket.CallbackType type = packet.getType();
if(!inventoryHashMap.containsKey(owner.getId())) {
BungeeCore.send(ProxyServer.getInstance().getPlayer(owner.getUuid()), BungeeCore.CHAT_PREFIX + "§cBitte erneut versuchen. Durch ein Softwareupdate konnte die übliche Aktion nicht durchgeführt werden.");
if(type == CallbackType.CLICK) {
new CloseInventoryPacket(owner.getId()).send(ProxyServer.getInstance().getPlayer(owner.getUuid()));
if(type == InventoryCallbackPacket.CallbackType.CLICK) {
NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).getSender(), new CloseInventoryPacket(owner.getId()));
}
return;
}
if(type == CallbackType.CLICK) {
int pos = in.readInt();
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(in.readUTF());
if(type == InventoryCallbackPacket.CallbackType.CLICK) {
int pos = packet.getPosition();
InvCallback.ClickType clickType = InvCallback.ClickType.valueOf(packet.getClickType().name());
inventoryHashMap.get(owner.getId()).handleCallback(clickType, pos);
}else if(type == CallbackType.CLOSE) {
}else if(type == InventoryCallbackPacket.CallbackType.CLOSE) {
if(inventoryHashMap.get(owner.getId()).isNext()) {
inventoryHashMap.get(owner.getId()).handleClose();
return;
@ -59,9 +62,4 @@ public class InventoryCallbackHandler implements SpigotHandler {
inventoryHashMap.get(owner.getId()).setNext(true);
}
}
public enum CallbackType {
CLICK,
CLOSE,
}
}

Datei anzeigen

@ -17,24 +17,24 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.comms.handlers;
package de.steamwar.bungeecore.network.handlers;
import com.google.common.io.ByteArrayDataInput;
import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.ServerStarter;
import de.steamwar.bungeecore.comms.SpigotHandler;
import de.steamwar.bungeecore.sql.SchematicType;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.network.packets.client.PrepareSchemPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class PrepareSchemHandler implements SpigotHandler {
@Override
public void handle(ByteArrayDataInput in, ServerInfo info) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(in.readInt()).getUuid());
int schematicID = in.readInt();
ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(in.readUTF()));
public class PrepareSchemHandler extends PacketHandler {
@Handler
public void handle(PrepareSchemPacket packet) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(packet.getPlayer()).getUuid());
int schematicID = packet.getSchem();
ArenaMode mode = ArenaMode.getBySchemType(SchematicType.fromDB(packet.getSchemType()));
new ServerStarter().test(mode, mode.getRandomMap(), player).prepare(schematicID).start();
}

Datei anzeigen

@ -23,9 +23,10 @@ import com.google.gson.JsonParser;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.WebregisterCommand;
import de.steamwar.bungeecore.comms.packets.LocaleInvalidationPacket;
import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.messages.ChatSender;
import de.steamwar.network.packets.server.LocaleInvalidationPacket;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -388,6 +389,6 @@ public class SteamwarUser {
this.locale = locale;
this.manualLocale = manualLocale;
updateLocale.update(locale.toLanguageTag(), manualLocale, id);
new LocaleInvalidationPacket(id).send(getPlayer());
NetworkSender.send(getPlayer(), new LocaleInvalidationPacket(id));
}
}

Datei anzeigen

@ -0,0 +1,67 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 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.util;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.md_5.bungee.ServerConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.protocol.PacketWrapper;
import net.md_5.bungee.protocol.ProtocolConstants;
import net.md_5.bungee.protocol.packet.Chat;
import java.time.Instant;
public class Chat19 extends Chat {
public static void chat(ProxiedPlayer p, String message) {
if(p.getPendingConnection().getVersion() >= 759) {
Chat19 packet = new Chat19(message);
ByteBuf buf = Unpooled.buffer();
writeVarInt(0x04, buf);
packet.write(buf, ProtocolConstants.Direction.TO_SERVER, p.getPendingConnection().getVersion());
((ServerConnection) p.getServer()).getCh().write(new PacketWrapper(packet, buf));
} else {
p.chat(message);
}
}
private final Instant timestamp = Instant.now();
private final long salt = 0L;
private final byte[] signature = new byte[0];
private final boolean signedPreview = false;
public Chat19 (String message) {
super(message);
}
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
if (direction == ProtocolConstants.Direction.TO_CLIENT || protocolVersion != 759)
throw new UnsupportedOperationException();
writeString(getMessage(), buf);
buf.writeLong(timestamp.toEpochMilli());
buf.writeLong(salt);
writeArray(signature, buf);
buf.writeBoolean(signedPreview);
}
}

Datei anzeigen

@ -0,0 +1,37 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.command;
import de.steamwar.bungeecore.BungeeCore;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Command;
@UtilityClass
class CommandRegistering {
static void unregister(Command command) {
ProxyServer.getInstance().getPluginManager().unregisterCommand(command);
}
static void register(Command command) {
ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), command);
}
}

Datei anzeigen

@ -0,0 +1,30 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.command;
import net.md_5.bungee.api.CommandSender;
@FunctionalInterface
public interface GuardChecker extends AbstractGuardChecker<CommandSender> {
/**
* While guarding the first parameter of the command the parameter s of this method is {@code null}
*/
GuardResult guard(CommandSender commandSender, GuardCheckType guardCheckType, String[] previousArguments, String s);
}

Datei anzeigen

@ -0,0 +1,154 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.command;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.logging.Level;
public class SWCommand extends AbstractSWCommand<CommandSender> {
static {
TypeUtils.init();
}
private String permission;
private Command command;
private List<String> defaultHelpMessages = new ArrayList<>();
protected SWCommand(String command) {
this(command, null);
}
protected SWCommand(String command, String permission) {
super(CommandSender.class, command);
this.permission = permission;
}
protected SWCommand(String command, String permission, String... aliases) {
super(CommandSender.class, command, aliases);
this.permission = permission;
}
@Override
protected void createAndSafeCommand(String command, String[] aliases) {
this.command = new TabCompletableCommand(command, permission, aliases) {
@Override
public void execute(CommandSender commandSender, String[] strings) {
SWCommand.this.execute(commandSender, null, strings);
}
@Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] strings) {
return SWCommand.this.tabComplete(commandSender, null, strings);
}
};
}
private abstract static class TabCompletableCommand extends Command implements TabExecutor {
public TabCompletableCommand(String name, String permission, String... aliases) {
super(name, permission, aliases);
}
}
@Override
public void unregister() {
CommandRegistering.unregister(this.command);
}
@Override
public void register() {
CommandRegistering.register(this.command);
}
@Override
protected void commandSystemError(CommandSender sender, CommandFrameworkException e) {
BungeeCore.get().getLogger().log(Level.SEVERE, e.getMessage(), e);
ChatSender.of(sender).prefixless("COMMAND_SYSTEM_ERROR");
}
@Override
protected void commandSystemWarning(Supplier<String> message) {
BungeeCore.get().getLogger().log(Level.WARNING, message);
}
public void addDefaultHelpMessage(String message) {
defaultHelpMessages.add(message);
}
@Register(help = true)
private void internalHelp(ProxiedPlayer p, String... args) {
ChatSender chatSender = ChatSender.of(p);
try {
chatSender.prefixless("COMMAND_HELP_HEAD", command.getName());
defaultHelpMessages.forEach(chatSender::prefixless);
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send help message", e);
return;
}
AtomicInteger atomicInteger = new AtomicInteger();
if (args.length != 0) {
commandList.forEach(subCommand -> {
List<String> tabCompletes = subCommand.tabComplete(p, args);
if (tabCompletes == null || tabCompletes.isEmpty()) {
atomicInteger.incrementAndGet();
return;
}
boolean hasTabCompletes = tabCompletes.stream()
.anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase()));
if (hasTabCompletes) {
send(chatSender, subCommand);
} else {
atomicInteger.incrementAndGet();
}
});
}
if (args.length == 0 || atomicInteger.get() == commandList.size()) {
commandList.forEach(subCommand -> {
if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) {
send(chatSender, subCommand);
}
});
}
}
private void send(ChatSender chatSender, SubCommand<CommandSender> subCommand) {
try {
for (String s : subCommand.description) {
String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand);
String suggest = "/" + command.getName() + " " + String.join(" ", subCommand.subCommand);
chatSender.prefixless(s, hover, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest));
}
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e);
}
}
}

Datei anzeigen

@ -0,0 +1,29 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.command;
import net.md_5.bungee.api.CommandSender;
public interface TypeMapper<T> extends AbstractTypeMapper<CommandSender, T> {
/**
* The CommandSender can be null!
*/
T map(CommandSender commandSender, String[] previousArguments, String s);
}

Datei anzeigen

@ -0,0 +1,36 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.command;
import de.steamwar.bungeecore.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.stream.Collectors;
@UtilityClass
public class TypeUtils {
static void init() {
SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, (s) -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())));
SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())));
}
}

Datei anzeigen

@ -1,3 +1,6 @@
COMMAND_SYSTEM_ERROR = §cError executing the command!
COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===---
PREFIX=§eSteam§8War»
SPACER=
TIMEFORMAT=dd.MM.yyyy HH:mm
@ -212,7 +215,7 @@ BAU_MEMBER_TOGGLE_WORLD_EDIT = use WorldEdit
BAU_MEMBER_TOGGLE_WORLD = change Settings
#ChallengeCommand
CHALLENGE_USAGE=§8/§7challenge §8[§eSpieler§8]
CHALLENGE_USAGE=§8/§7challenge §8[§eplayer§8]
CHALLENGE_OFFLINE=§cThe challenged player isn't online.
CHALLENGE_SELF=§cSchizophrenia?
CHALLENGE_IGNORED=§cThe challenged player has blocked you.
@ -293,7 +296,7 @@ HISTORIC_BROADCAST_HOVER=§afight against §7{1}
JOIN_PLAYER_BLOCK=§cYou currently cannot follow this player.
#JoinmeCommand
JOINME_USAGE=§8/§7join §8[§eSpieler§8].
JOINME_USAGE=§8/§7join §8[§eplayer§8].
JOINME_BROADCAST=§7Click §ehere§8 §7to join §e{0} §7on §e{1}§8!
JOINME_BROADCAST_HOVER=§aJoin player
JOINME_PLAYER_OFFLINE=§cThis player is offline.
@ -615,7 +618,7 @@ RANK_NEEDED_FIGHTS_LEFT={0} §8(§e{1}§7 fights needed§8)
#Fabric Mod Sender
MODIFICATION_BAN_MESSAGE=You tried to bypass / modify the FabricModSender!
MODIFICATION_BAN_LOG={0} has tried to edit / bypass the FabricModSender!
MODIFICATION_BAN_LOG={0} has tried to edit / bypass the FabricModSender! Reason: {1}
MODIFICATION_CHECK_SUCCESS=§eYour mods have been checked and you are now allowed to join arenas!
#Arena Merging

Datei anzeigen

@ -1,3 +1,5 @@
COMMAND_SYSTEM_ERROR = §cFehler beim Ausführen des Befehls!
PREFIX=§eSteam§8War»
SPACER=
TIMEFORMAT=dd.MM.yyyy HH:mm
@ -595,7 +597,7 @@ RANK_NEEDED_FIGHTS_LEFT={0} §8(§7noch §e{1}§7 Kämpfe nötig§8)
#Fabric Mod Sender
MODIFICATION_BAN_MESSAGE=Du hast probiert den FabricModSender zu umgehen / zu modifizieren!
MODIFICATION_BAN_LOG={0} hat probiert den Fabric Mod Sender zu editieren / umzugehen!
MODIFICATION_BAN_LOG={0} hat probiert den Fabric Mod Sender zu editieren / umzugehen! Grund: {1}
MODIFICATION_CHECK_SUCCESS=§eDeine Mods wurden geprüft und du darfst nun auf Arenen joinen!
#Arena Merging