Networking #2

Zusammengeführt
Lixfel hat 16 Commits von network nach master 2022-05-10 08:53:36 +02:00 zusammengeführt
19 geänderte Dateien mit 728 neuen und 0 gelöschten Zeilen
Nur Änderungen aus Commit 80344df9b0 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.network.packets;
import java.io.Serializable;
public abstract class NetworkPacket implements Serializable {
private final Sender sender;
Lixfel markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Brauchts das ganze EqualsAndHashCode-Zeug tatsächlich?

Brauchts das ganze EqualsAndHashCode-Zeug tatsächlich?
Veraltet
Review

wegen den Tests

wegen den Tests
public NetworkPacket(Sender sender) {
this.sender = sender;
}
public Sender getSender() {
return sender;
}
Chaoscaot markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Wären das nicht nur IOExceptions? Ansonsten gäbe es ja auch die ExceptionA | ExceptionB -Syntax.

Wären das nicht nur IOExceptions? Ansonsten gäbe es ja auch die ExceptionA | ExceptionB -Syntax.
public abstract void handle(NetworkHandler handler);
public enum Sender {
SERVER,
CLIENT,
BOTH
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
Review

Überlegung (nichts für diesen PR, aber potentiell etwas für einen NachfolgePR): CommonGUI?

Überlegung (nichts für diesen PR, aber potentiell etwas für einen NachfolgePR): CommonGUI?
Review

Möglich, kann ich mich hiernach mal dran setzen

Möglich, kann ich mich hiernach mal dran setzen
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;
}
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.network.packets.common;
import de.steamwar.network.packets.NetworkPacket;
public abstract class CommonPacket extends NetworkPacket {
public CommonPacket() {
super(Sender.BOTH);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Integer> bluePlayers;
private List<Integer> redPlayers;
private String gameMode;
@Override
Lixfel markierte diese Unterhaltung als gelöst
Review

Sind ArrayLists Serializable? Ansonsten müsste es auch mit int[] gehen...

Sind ArrayLists Serializable? Ansonsten müsste es auch mit int[] gehen...
Review

ja

ja
public void handle(NetworkHandler handler) {
handler.handle(this);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Integer> bluePlayers; // List of Blue SWUserIDs
private List<Integer> redPlayers; // List of Red SWUserIDs
private List<Integer> spectators; // List of Spectator SWUserIDs
@Override
Lixfel markierte diese Unterhaltung als gelöst
Review

Selbe Frage hier.

Selbe Frage hier.
public void handle(NetworkHandler handler) {
handler.handle(this);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

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.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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Integer, String> items;
@Override
public void handle(ClientNetworkHandler handler) {
handler.handle(this);
}
}
Lixfel markierte diese Unterhaltung als gelöst
Review

Serializable?

Serializable?
Review

Ja

Ja

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}