Merge pull request 'Add MetaInfos' (#5) from MetaInfos into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #5
Dieser Commit ist enthalten in:
Commit
c96efa9a50
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,12 @@ import java.io.*;
|
|||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
public abstract class NetworkPacket implements Serializable {
|
public abstract class NetworkPacket implements Serializable {
|
||||||
|
|
||||||
|
private transient MetaInfos metaInfos;
|
||||||
|
|
||||||
|
public MetaInfos getMetaInfos() {
|
||||||
|
return metaInfos;
|
||||||
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public byte[] serialize() {
|
public byte[] serialize() {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
@ -40,6 +46,12 @@ public abstract class NetworkPacket implements Serializable {
|
|||||||
PacketHandler.handlePacket(deserialize(data));
|
PacketHandler.handlePacket(deserialize(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void handle(MetaInfos metaInfos, byte[] data) {
|
||||||
|
NetworkPacket networkPacket = deserialize(data);
|
||||||
|
networkPacket.metaInfos = metaInfos;
|
||||||
|
PacketHandler.handlePacket(networkPacket);
|
||||||
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static NetworkPacket deserialize(byte[] data) {
|
public static NetworkPacket deserialize(byte[] data) {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||||
|
@ -47,6 +47,7 @@ public abstract class PacketHandler {
|
|||||||
if(method.getParameterCount() != 1 || !NetworkPacket.class.isAssignableFrom(method.getParameterTypes()[0])) {
|
if(method.getParameterCount() != 1 || !NetworkPacket.class.isAssignableFrom(method.getParameterTypes()[0])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method.isAnnotationPresent(Handler.class)) {
|
if (method.isAnnotationPresent(Handler.class)) {
|
||||||
Class<? extends NetworkPacket> packetClass = (Class<? extends NetworkPacket>) method.getParameterTypes()[0];
|
Class<? extends NetworkPacket> packetClass = (Class<? extends NetworkPacket>) method.getParameterTypes()[0];
|
||||||
HANDLER_MAP.put(packetClass, method);
|
HANDLER_MAP.put(packetClass, method);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren