Merge remote-tracking branch 'origin/CommandFramework' into CommandFramework
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Commit
2402537968
23
src/de/steamwar/network/packets/MetaInfos.java
Normale Datei
23
src/de/steamwar/network/packets/MetaInfos.java
Normale Datei
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public interface MetaInfos {
|
||||
}
|
@ -27,6 +27,13 @@ import java.io.*;
|
||||
@EqualsAndHashCode
|
||||
public abstract class NetworkPacket implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3168992457669156473L;
|
||||
private transient MetaInfos metaInfos;
|
||||
|
||||
public MetaInfos getMetaInfos() {
|
||||
return metaInfos;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public byte[] serialize() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
@ -40,6 +47,12 @@ public abstract class NetworkPacket implements Serializable {
|
||||
PacketHandler.handlePacket(deserialize(data));
|
||||
}
|
||||
|
||||
public static void handle(MetaInfos metaInfos, byte[] data) {
|
||||
NetworkPacket networkPacket = deserialize(data);
|
||||
networkPacket.metaInfos = metaInfos;
|
||||
PacketHandler.handlePacket(networkPacket);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static NetworkPacket deserialize(byte[] data) {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||
|
@ -47,6 +47,7 @@ public abstract class PacketHandler {
|
||||
if(method.getParameterCount() != 1 || !NetworkPacket.class.isAssignableFrom(method.getParameterTypes()[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (method.isAnnotationPresent(Handler.class)) {
|
||||
Class<? extends NetworkPacket> packetClass = (Class<? extends NetworkPacket>) method.getParameterTypes()[0];
|
||||
HANDLER_MAP.put(packetClass, method);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren