SteamWar/BungeeCore
Archiviert
13
2

Bungee Network #362

Zusammengeführt
Lixfel hat 5 Commits von network nach master 2022-06-14 08:50:05 +02:00 zusammengeführt
29 geänderte Dateien mit 158 neuen und 804 gelöschten Zeilen
Nur Änderungen aus Commit 446b4ad519 werden angezeigt - Alle Commits anzeigen

@ -1 +1 @@
Subproject commit 919c4d525ea39756b24bd961bb72d8d58bdd5bd4
Subproject commit 492894ca8d41ee0bde4dcb9d520db5f7478c50c7

Datei anzeigen

@ -22,9 +22,9 @@ 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.NetworkReceiver;
import de.steamwar.bungeecore.sql.*;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
@ -156,7 +156,7 @@ public class BungeeCore extends Plugin {
new EventStarter();
new SessionManager();
new SpigotReceiver();
new NetworkReceiver();
new TablistManager();
new SettingsChangedListener();

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;
@ -195,7 +196,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;
}
}

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 LocaleInvalidationPacket extends BungeePacket {
private int userId;
public LocaleInvalidationPacket(int userId) {
this.userId = userId;
}
@Override
public int getId() {
return PacketIdManager.LOCALE_INVALIDATION;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(userId);
}
}

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).getAsString()));
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,10 @@ 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.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;
@ -202,7 +203,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,9 +26,9 @@ 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 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

@ -0,0 +1,16 @@
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,27 @@
package de.steamwar.bungeecore.network;
import de.steamwar.bungeecore.listeners.BasicListener;
import de.steamwar.network.packets.NetworkPacket;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.event.EventHandler;
public class NetworkReceiver extends BasicListener {
public static ServerInfo sender;
@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
if(!event.getTag().equalsIgnoreCase("sw:bridge"))
return;
event.setCancelled(true);
if(!(event.getSender() instanceof Server))
return;
sender = (ServerInfo) event.getSender();
NetworkPacket.handle(event.getData());
sender = null;
}
}

Datei anzeigen

@ -0,0 +1,22 @@
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;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
public class NetworkSender {
@SneakyThrows
public static void send(ProxiedPlayer player, NetworkPacket packet) {
player.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,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,13 @@
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.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 +31,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 +43,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 = NetworkReceiver.sender;
FightInfoPacket lobbyPacket = packet.withServerName(info.getName());
TablistManager.newFightInfo(info, packet);
@ -58,7 +60,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.NetworkReceiver;
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(NetworkReceiver.sender);
}
}

Datei anzeigen

@ -17,41 +17,42 @@
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.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(NetworkReceiver.sender, 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 +60,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));
}
}