/* * 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 . */ package de.steamwar.network; import de.steamwar.network.packets.NetworkPacket; import de.steamwar.network.packets.client.ExecuteCommandPacket; import de.steamwar.network.packets.client.ImALobbyPacket; import de.steamwar.network.packets.client.InventoryCallbackPacket; import de.steamwar.network.packets.client.PrepareSchemPacket; import de.steamwar.network.packets.common.FightEndsPacket; import de.steamwar.network.packets.common.FightInfoPacket; import de.steamwar.network.packets.server.*; import lombok.SneakyThrows; import java.lang.reflect.Constructor; import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.List; import static de.steamwar.RandomGenerator.*; public class AllPackets { public static final Class[] packets = new Class[]{ ExecuteCommandPacket.class, ImALobbyPacket.class, InventoryCallbackPacket.class, PrepareSchemPacket.class, FightEndsPacket.class, FightInfoPacket.class, BaumemberUpdatePacket.class, CloseInventoryPacket.class, InventoryPacket.class, PingPacket.class, StartingServerPacket.class }; @SneakyThrows public static List getAllPackets() { List packets = new ArrayList<>(); for (Class packet : AllPackets.packets) { Constructor longConstructor = (Constructor) packet.getConstructors()[0]; for (Constructor constructor : packet.getConstructors()) { if (constructor.getParameterCount() > longConstructor.getParameterCount()) { longConstructor = (Constructor) constructor; } } Object[] args = new Object[longConstructor.getParameterCount()]; Parameter[] parameters = longConstructor.getParameters(); for (int i = 0; i < parameters.length; i++) { Parameter parameter = parameters[i]; parameter.getName(); args[i] = generateRandom(parameter.getType()); } NetworkPacket packetInstance = longConstructor.newInstance(args); packets.add(packetInstance); } return packets; } }