use of net.modificationstation.stationapi.api.event.registry.MessageListenerRegistryEvent in project StationAPI by ModificationStation.
the class MessagePacketInit method registerPackets.
@EventListener(priority = ListenerPriority.HIGH)
private static void registerPackets(PacketRegisterEvent event) {
event.register(254, true, true, Message.class);
StationAPI.EVENT_BUS.post(new MessageListenerRegistryEvent());
}
use of net.modificationstation.stationapi.api.event.registry.MessageListenerRegistryEvent in project StationAPI by ModificationStation.
the class ServerVanillaChecker method registerMessages.
@EventListener(priority = ListenerPriority.HIGH)
private static void registerMessages(MessageListenerRegistryEvent event) {
event.registry.register(of(MODID, "modlist"), (player, message) -> {
if (!CLIENT_REQUIRED_MODS.isEmpty()) {
LOGGER.info("Received a list of mods from player \"" + player.name + "\", verifying...");
ServerPlayer serverPlayer = (ServerPlayer) player;
String version = message.strings[0];
String serverStationVersion = MODID.getVersion().getFriendlyString();
if (!version.equals(serverStationVersion)) {
LOGGER.error("Player \"" + player.name + "\" has a mismatching " + MODID.getName() + " version \"" + version + "\", disconnecting.");
serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:station_version_mismatch", serverStationVersion, version));
return;
}
Map<String, String> clientMods = new HashMap<>();
for (int i = 1; i < message.strings.length; i += 2) clientMods.put(message.strings[i], message.strings[i + 1]);
LOGGER.info("Player \"" + player.name + "\"'s mods: " + clientMods.entrySet().stream().map(stringStringEntry -> "modid=" + stringStringEntry.getKey() + " version=" + stringStringEntry.getValue()).collect(Collectors.joining(", ", "[", "]")));
String modid;
String clientVersion;
String serverVersion;
for (ModContainer serverMod : CLIENT_REQUIRED_MODS) {
ModMetadata modMetadata = serverMod.getMetadata();
modid = modMetadata.getId();
serverVersion = modMetadata.getVersion().getFriendlyString();
if (clientMods.containsKey(modid)) {
clientVersion = clientMods.get(modid);
if (clientVersion == null || !clientVersion.equals(serverVersion)) {
LOGGER.error("Player \"" + player.name + "\" has a mismatching " + modMetadata.getName() + " (" + modid + ")" + " version \"" + clientVersion + "\", disconnecting.");
serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:mod_version_mismatch", modMetadata.getName(), modid, serverVersion, clientVersion == null ? "null" : clientVersion));
return;
}
} else {
LOGGER.error("Player \"" + player.name + "\" has a missing mod " + modMetadata.getName() + " (" + modid + "), disconnecting.");
serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:missing_mod", modMetadata.getName(), modid, serverVersion));
return;
}
}
LOGGER.info("Player \"" + player.name + "\"'s mods have passed verification.");
}
});
}
Aggregations