From 80344df9b0c4a08aa612382ca86f97e5b412ed54 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 24 Apr 2022 13:28:05 +0200 Subject: [PATCH] :tada: Add Network Packets --- .../network/packets/NetworkHandler.java | 28 ++++++ .../network/packets/NetworkPacket.java | 43 +++++++++ .../packets/client/ClientNetworkHandler.java | 30 +++++++ .../network/packets/client/ClientPacket.java | 37 ++++++++ .../packets/client/ExecuteCommandPacket.java | 36 ++++++++ .../packets/client/ImALobbyPacket.java | 33 +++++++ .../client/InventoryCallbackPacket.java | 87 +++++++++++++++++++ .../packets/client/PrepareSchemPacket.java | 37 ++++++++ .../packets/client/TablistNamePacket.java | 36 ++++++++ .../network/packets/common/CommonPacket.java | 28 ++++++ .../packets/common/FightEndsPacket.java | 42 +++++++++ .../packets/common/FightInfoPacket.java | 50 +++++++++++ .../packets/server/BaumemberUpdatePacket.java | 33 +++++++ .../packets/server/CloseInventoryPacket.java | 35 ++++++++ .../packets/server/InventoryPacket.java | 40 +++++++++ .../network/packets/server/PingPacket.java | 32 +++++++ .../packets/server/ServerNetworkHandler.java | 30 +++++++ .../network/packets/server/ServerPacket.java | 37 ++++++++ .../packets/server/StartingServerPacket.java | 34 ++++++++ 19 files changed, 728 insertions(+) create mode 100644 src/de/steamwar/network/packets/NetworkHandler.java create mode 100644 src/de/steamwar/network/packets/NetworkPacket.java create mode 100644 src/de/steamwar/network/packets/client/ClientNetworkHandler.java create mode 100644 src/de/steamwar/network/packets/client/ClientPacket.java create mode 100644 src/de/steamwar/network/packets/client/ExecuteCommandPacket.java create mode 100644 src/de/steamwar/network/packets/client/ImALobbyPacket.java create mode 100644 src/de/steamwar/network/packets/client/InventoryCallbackPacket.java create mode 100644 src/de/steamwar/network/packets/client/PrepareSchemPacket.java create mode 100644 src/de/steamwar/network/packets/client/TablistNamePacket.java create mode 100644 src/de/steamwar/network/packets/common/CommonPacket.java create mode 100644 src/de/steamwar/network/packets/common/FightEndsPacket.java create mode 100644 src/de/steamwar/network/packets/common/FightInfoPacket.java create mode 100644 src/de/steamwar/network/packets/server/BaumemberUpdatePacket.java create mode 100644 src/de/steamwar/network/packets/server/CloseInventoryPacket.java create mode 100644 src/de/steamwar/network/packets/server/InventoryPacket.java create mode 100644 src/de/steamwar/network/packets/server/PingPacket.java create mode 100644 src/de/steamwar/network/packets/server/ServerNetworkHandler.java create mode 100644 src/de/steamwar/network/packets/server/ServerPacket.java create mode 100644 src/de/steamwar/network/packets/server/StartingServerPacket.java diff --git a/src/de/steamwar/network/packets/NetworkHandler.java b/src/de/steamwar/network/packets/NetworkHandler.java new file mode 100644 index 0000000..cd068d0 --- /dev/null +++ b/src/de/steamwar/network/packets/NetworkHandler.java @@ -0,0 +1,28 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets; + +import de.steamwar.network.packets.common.FightInfoPacket; +import de.steamwar.network.packets.common.FightEndsPacket; + +public interface NetworkHandler { + void handle(FightEndsPacket packet); + void handle(FightInfoPacket packet); +} diff --git a/src/de/steamwar/network/packets/NetworkPacket.java b/src/de/steamwar/network/packets/NetworkPacket.java new file mode 100644 index 0000000..c146913 --- /dev/null +++ b/src/de/steamwar/network/packets/NetworkPacket.java @@ -0,0 +1,43 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets; + +import java.io.Serializable; + +public abstract class NetworkPacket implements Serializable { + + private final Sender sender; + + public NetworkPacket(Sender sender) { + this.sender = sender; + } + + public Sender getSender() { + return sender; + } + + public abstract void handle(NetworkHandler handler); + + public enum Sender { + SERVER, + CLIENT, + BOTH + } +} diff --git a/src/de/steamwar/network/packets/client/ClientNetworkHandler.java b/src/de/steamwar/network/packets/client/ClientNetworkHandler.java new file mode 100644 index 0000000..c8b7434 --- /dev/null +++ b/src/de/steamwar/network/packets/client/ClientNetworkHandler.java @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.client; + +import de.steamwar.network.packets.server.*; + +public interface ClientNetworkHandler { + void handle(BaumemberUpdatePacket packet); + void handle(CloseInventoryPacket packet); + void handle(InventoryPacket packet); + void handle(PingPacket packet); + void handle(StartingServerPacket packet); +} diff --git a/src/de/steamwar/network/packets/client/ClientPacket.java b/src/de/steamwar/network/packets/client/ClientPacket.java new file mode 100644 index 0000000..9829bf8 --- /dev/null +++ b/src/de/steamwar/network/packets/client/ClientPacket.java @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.client; + +import de.steamwar.network.packets.NetworkHandler; +import de.steamwar.network.packets.NetworkPacket; +import de.steamwar.network.packets.server.ServerNetworkHandler; + +public abstract class ClientPacket extends NetworkPacket { + public ClientPacket() { + super(Sender.CLIENT); + } + + @Override + public void handle(NetworkHandler handler) { + handle((ServerNetworkHandler) handler); + } + + public abstract void handle(ServerNetworkHandler handler); +} diff --git a/src/de/steamwar/network/packets/client/ExecuteCommandPacket.java b/src/de/steamwar/network/packets/client/ExecuteCommandPacket.java new file mode 100644 index 0000000..a2b6570 --- /dev/null +++ b/src/de/steamwar/network/packets/client/ExecuteCommandPacket.java @@ -0,0 +1,36 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.client; + +import de.steamwar.network.packets.server.ServerNetworkHandler; +import lombok.Data; + +@Data +public class ExecuteCommandPacket extends ClientPacket { + + private static final long serialVersionUID = 6283457297487602016L; + private int playerId; + private String command; + + @Override + public void handle(ServerNetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/client/ImALobbyPacket.java b/src/de/steamwar/network/packets/client/ImALobbyPacket.java new file mode 100644 index 0000000..5656f63 --- /dev/null +++ b/src/de/steamwar/network/packets/client/ImALobbyPacket.java @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.client; + +import de.steamwar.network.packets.server.ServerNetworkHandler; +import lombok.Data; + +@Data +public class ImALobbyPacket extends ClientPacket { + private static final long serialVersionUID = 8110246509205246654L; + + @Override + public void handle(ServerNetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/client/InventoryCallbackPacket.java b/src/de/steamwar/network/packets/client/InventoryCallbackPacket.java new file mode 100644 index 0000000..c461102 --- /dev/null +++ b/src/de/steamwar/network/packets/client/InventoryCallbackPacket.java @@ -0,0 +1,87 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.client; + +import de.steamwar.network.packets.server.ServerNetworkHandler; +import lombok.Data; + +@Data +public class InventoryCallbackPacket extends ClientPacket { + private static final long serialVersionUID = -261823209186008718L; + private int position; + private int owner; + private CallbackType type; + private ClickType clickType; + + @Override + public void handle(ServerNetworkHandler handler) { + handler.handle(this); + } + + public enum CallbackType { + CLICK, + CLOSE, + } + + public enum ClickType { + LEFT, + SHIFT_LEFT, + RIGHT, + SHIFT_RIGHT, + WINDOW_BORDER_LEFT, + WINDOW_BORDER_RIGHT, + MIDDLE, + NUMBER_KEY, + DOUBLE_CLICK, + DROP, + CONTROL_DROP, + CREATIVE, + UNKNOWN; + + public boolean isKeyboardClick() { + return this == NUMBER_KEY || this == DROP || this == CONTROL_DROP; + } + + public boolean isCreativeAction() { + return this == MIDDLE || this == CREATIVE; + } + + public boolean isRightClick() { + return this == RIGHT || this == SHIFT_RIGHT; + } + + public boolean isLeftClick() { + return this == LEFT || this == SHIFT_LEFT || this == DOUBLE_CLICK || this == CREATIVE; + } + + public boolean isShiftClick() { + return this == SHIFT_LEFT || this == SHIFT_RIGHT || this == CONTROL_DROP; + } + + public static ClickType getByName(String name) { + for (ClickType type : values()) { + if (type.name().equalsIgnoreCase(name)) { + return type; + } + } + return UNKNOWN; + } + } +} diff --git a/src/de/steamwar/network/packets/client/PrepareSchemPacket.java b/src/de/steamwar/network/packets/client/PrepareSchemPacket.java new file mode 100644 index 0000000..186b7b3 --- /dev/null +++ b/src/de/steamwar/network/packets/client/PrepareSchemPacket.java @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.client; + +import de.steamwar.network.packets.server.ServerNetworkHandler; +import lombok.Data; + +@Data +public class PrepareSchemPacket extends ClientPacket { + + private static final long serialVersionUID = -4798561188105813349L; + private int player; + private int schem; + private int schemType; + + @Override + public void handle(ServerNetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/client/TablistNamePacket.java b/src/de/steamwar/network/packets/client/TablistNamePacket.java new file mode 100644 index 0000000..c8d2fed --- /dev/null +++ b/src/de/steamwar/network/packets/client/TablistNamePacket.java @@ -0,0 +1,36 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.client; + +import de.steamwar.network.packets.server.ServerNetworkHandler; +import lombok.Data; + +@Data +public class TablistNamePacket extends ClientPacket { + + private static final long serialVersionUID = -1709089784235478752L; + private int player; + private String tablistName; + + @Override + public void handle(ServerNetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/common/CommonPacket.java b/src/de/steamwar/network/packets/common/CommonPacket.java new file mode 100644 index 0000000..ad58090 --- /dev/null +++ b/src/de/steamwar/network/packets/common/CommonPacket.java @@ -0,0 +1,28 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.common; + +import de.steamwar.network.packets.NetworkPacket; + +public abstract class CommonPacket extends NetworkPacket { + public CommonPacket() { + super(Sender.BOTH); + } +} diff --git a/src/de/steamwar/network/packets/common/FightEndsPacket.java b/src/de/steamwar/network/packets/common/FightEndsPacket.java new file mode 100644 index 0000000..2f91618 --- /dev/null +++ b/src/de/steamwar/network/packets/common/FightEndsPacket.java @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.common; + +import de.steamwar.network.packets.NetworkHandler; +import lombok.Data; + +import java.util.List; + +@Data +public class FightEndsPacket extends CommonPacket { + + private static final long serialVersionUID = 1279352415549011332L; + private byte win; + private int blueSchem; + private int redSchem; + private List bluePlayers; + private List redPlayers; + private String gameMode; + + @Override + public void handle(NetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/common/FightInfoPacket.java b/src/de/steamwar/network/packets/common/FightInfoPacket.java new file mode 100644 index 0000000..d0f416b --- /dev/null +++ b/src/de/steamwar/network/packets/common/FightInfoPacket.java @@ -0,0 +1,50 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.common; + +import de.steamwar.network.packets.NetworkHandler; +import lombok.Data; + +import java.util.List; + +@Data +public class FightInfoPacket extends CommonPacket{ + + private static final long serialVersionUID = 7448644597856605853L; + private String serverName; // Name of the Server + private String gameMode; // GameMode aka Schematictype (if known, else "") + private String arena; // Name of the arena + private String blueName; // Name of the blue team, expected to begin with "§a" colorcode + private String redName; // Name of the red team, expected to begin with "§a" colorcode + private String fightState; // Fight state (technical term) (if known, else "") + private int countdown; // Countdown state in seconds (if known, else 0) + private int blueLeader; // SWUserID of the blue team leader (if known, else 0) + private int redLeader; // SWUserID of the red team leader (if known, else 0) + private int blueSchem; // Blue SchemID (if known, else 0) + private int redSchem; // Red SchemID (if known, else 0) + private List bluePlayers; // List of Blue SWUserIDs + private List redPlayers; // List of Red SWUserIDs + private List spectators; // List of Spectator SWUserIDs + + @Override + public void handle(NetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/server/BaumemberUpdatePacket.java b/src/de/steamwar/network/packets/server/BaumemberUpdatePacket.java new file mode 100644 index 0000000..ac610d5 --- /dev/null +++ b/src/de/steamwar/network/packets/server/BaumemberUpdatePacket.java @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.server; + +import de.steamwar.network.packets.client.ClientNetworkHandler; +import lombok.Data; + +@Data +public class BaumemberUpdatePacket extends ServerPacket{ + private static final long serialVersionUID = 6863118892424244051L; + + @Override + public void handle(ClientNetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/server/CloseInventoryPacket.java b/src/de/steamwar/network/packets/server/CloseInventoryPacket.java new file mode 100644 index 0000000..691df1a --- /dev/null +++ b/src/de/steamwar/network/packets/server/CloseInventoryPacket.java @@ -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 . + */ + +package de.steamwar.network.packets.server; + +import de.steamwar.network.packets.client.ClientNetworkHandler; +import lombok.Data; + +@Data +public class CloseInventoryPacket extends ServerPacket { + + private static final long serialVersionUID = -2191021190060504521L; + private int playerId; + + @Override + public void handle(ClientNetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/server/InventoryPacket.java b/src/de/steamwar/network/packets/server/InventoryPacket.java new file mode 100644 index 0000000..9ec6a1d --- /dev/null +++ b/src/de/steamwar/network/packets/server/InventoryPacket.java @@ -0,0 +1,40 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.server; + +import de.steamwar.network.packets.client.ClientNetworkHandler; +import lombok.Data; + +import java.util.Map; + +@Data +public class InventoryPacket extends ServerPacket { + + private static final long serialVersionUID = 8071052544654047316L; + private String title; + private int player; + private int size; + private Map items; + + @Override + public void handle(ClientNetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/server/PingPacket.java b/src/de/steamwar/network/packets/server/PingPacket.java new file mode 100644 index 0000000..d9a07ec --- /dev/null +++ b/src/de/steamwar/network/packets/server/PingPacket.java @@ -0,0 +1,32 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.server; + +import de.steamwar.network.packets.client.ClientNetworkHandler; + +public class PingPacket extends ServerPacket { + private static final long serialVersionUID = 714647343959550378L; + private int id; + + @Override + public void handle(ClientNetworkHandler handler) { + handler.handle(this); + } +} diff --git a/src/de/steamwar/network/packets/server/ServerNetworkHandler.java b/src/de/steamwar/network/packets/server/ServerNetworkHandler.java new file mode 100644 index 0000000..0a8cb7c --- /dev/null +++ b/src/de/steamwar/network/packets/server/ServerNetworkHandler.java @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.server; + +import de.steamwar.network.packets.client.*; + +public interface ServerNetworkHandler { + void handle(ExecuteCommandPacket packet); + void handle(ImALobbyPacket packet); + void handle(InventoryCallbackPacket packet); + void handle(PrepareSchemPacket packet); + void handle(TablistNamePacket packet); +} diff --git a/src/de/steamwar/network/packets/server/ServerPacket.java b/src/de/steamwar/network/packets/server/ServerPacket.java new file mode 100644 index 0000000..bfab1e7 --- /dev/null +++ b/src/de/steamwar/network/packets/server/ServerPacket.java @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.server; + +import de.steamwar.network.packets.NetworkHandler; +import de.steamwar.network.packets.NetworkPacket; +import de.steamwar.network.packets.client.ClientNetworkHandler; + +public abstract class ServerPacket extends NetworkPacket { + public ServerPacket() { + super(Sender.SERVER); + } + + @Override + public void handle(NetworkHandler handler) { + handle((ClientNetworkHandler) handler); + } + + public abstract void handle(ClientNetworkHandler handler); +} diff --git a/src/de/steamwar/network/packets/server/StartingServerPacket.java b/src/de/steamwar/network/packets/server/StartingServerPacket.java new file mode 100644 index 0000000..b819e37 --- /dev/null +++ b/src/de/steamwar/network/packets/server/StartingServerPacket.java @@ -0,0 +1,34 @@ +/* + * 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 . + */ + +package de.steamwar.network.packets.server; + +import de.steamwar.network.packets.client.ClientNetworkHandler; +import lombok.Data; + +@Data +public class StartingServerPacket extends ServerPacket { + private static final long serialVersionUID = 2808607245898121801L; + private int user; + + @Override + public void handle(ClientNetworkHandler handler) { + handler.handle(this); + } +}