Merge remote-tracking branch 'origin/CommandFramework' into CommandFramework
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-06-16 17:28:20 +02:00
Commit 2402537968
3 geänderte Dateien mit 37 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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 {
}

Datei anzeigen

@ -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);

Datei anzeigen

@ -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);