Add MetaInfos #5

Zusammengeführt
Lixfel hat 4 Commits von MetaInfos nach master 2022-06-14 15:21:22 +02:00 zusammengeführt
3 geänderte Dateien mit 36 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,12 @@ import java.io.*;
@EqualsAndHashCode
public abstract class NetworkPacket implements Serializable {
private transient MetaInfos metaInfos;
public MetaInfos getMetaInfos() {
return metaInfos;
}
@SneakyThrows
public byte[] serialize() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -40,6 +46,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);