diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionClient.java b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionClient.java index a821072..6a0e910 100644 --- a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionClient.java +++ b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionClient.java @@ -15,58 +15,75 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; +/** + * A client for managing remote extensions. + * + * @author Dorving + */ public final class NetworkExtensionClient extends GEarthExtension { private final static Logger LOGGER = LoggerFactory.getLogger(NetworkExtensionClient.class); + private final Channel channel; + private final String title; private final String author; private final String version; private final String description; + private final String fileName; + private final String cookie; private final boolean fireEventButtonVisible; private final boolean leaveButtonVisible; private final boolean deleteButtonVisible; private final boolean isInstalledExtension; - private final String fileName; - private final String cookie; - private final Channel channel; - public NetworkExtensionClient(Incoming.ExtensionInfo msg, Channel channel) { - title = msg.getTitle(); - author = msg.getAuthor(); - version = msg.getVersion(); - description = msg.getDescription(); - fireEventButtonVisible = msg.isOnClickUsed(); - leaveButtonVisible = msg.isCanLeave(); - deleteButtonVisible = msg.isCanDelete(); - isInstalledExtension = msg.getFile() != null; - fileName = msg.getFile(); - cookie = msg.getCookie(); + /** + * Create a new {@link NetworkExtensionClient} instance. + * + * @param channel the channel through which to communicate with the remote extension. + * @param info the {@link Incoming.ExtensionInfo} detailing the extension. + */ + public NetworkExtensionClient(Channel channel, Incoming.ExtensionInfo info) { this.channel = channel; + title = info.getTitle(); + author = info.getAuthor(); + version = info.getVersion(); + description = info.getDescription(); + fireEventButtonVisible = info.isOnClickUsed(); + leaveButtonVisible = info.isCanLeave(); + deleteButtonVisible = info.isCanDelete(); + isInstalledExtension = info.getFile() != null; + fileName = info.getFile(); + cookie = info.getCookie(); } - public void handleIncomingMessage(Incoming msg) { + /** + * Handles {@link Incoming incoming messages}. + * + * @param incoming the {@link Incoming message} to be handled. + */ + public void handleIncomingMessage(Incoming incoming) { try { - if (msg instanceof Incoming.RequestFlags) + if (incoming instanceof Incoming.RequestFlags) requestFlags(); - else if (msg instanceof Incoming.SendMessage) { - final Incoming.SendMessage message = ((Incoming.SendMessage) msg); + else if (incoming instanceof Incoming.SendMessage) { + final Incoming.SendMessage message = ((Incoming.SendMessage) incoming); final HPacket packet = message.getPacket(); if (!packet.isCorrupted()) sendMessage(message.getDirection(), packet); - } else if (msg instanceof Incoming.ManipulatedPacket) { - sendManipulatedPacket(((Incoming.ManipulatedPacket) msg).gethMessage()); - } else if (msg instanceof Incoming.ExtensionConsoleLog) { - log(((Incoming.ExtensionConsoleLog) msg).getContents()); - } else if (msg instanceof Incoming.PacketToStringRequest) { + } else if (incoming instanceof Incoming.ManipulatedPacket) { + sendManipulatedPacket(((Incoming.ManipulatedPacket) incoming).gethMessage()); + } else if (incoming instanceof Incoming.ExtensionConsoleLog) { + log(((Incoming.ExtensionConsoleLog) incoming).getContents()); + } else if (incoming instanceof Incoming.PacketToStringRequest) { final HPacket hPacket = new HPacket(new byte[0]); - hPacket.constructFromString(((Incoming.PacketToStringRequest) msg).getString()); + hPacket.constructFromString(((Incoming.PacketToStringRequest) incoming).getString()); packetToStringRequest(hPacket); - } else if (msg instanceof Incoming.StringToPacketRequest) { - stringToPacketRequest(((Incoming.StringToPacketRequest) msg).getString()); + } else if (incoming instanceof Incoming.StringToPacketRequest) { + stringToPacketRequest(((Incoming.StringToPacketRequest) incoming).getString()); } } catch (Exception e){ - LOGGER.error("Failed to handle incoming message {} (channel={})", msg, channel, e); + LOGGER.error("Failed to handle incoming message {} (channel={})", incoming, channel, e); } } diff --git a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionServer.java b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionServer.java index 671af59..e27fbc8 100644 --- a/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionServer.java +++ b/G-Earth/src/main/java/gearth/services/extension_handler/extensions/implementations/network/NetworkExtensionServer.java @@ -230,7 +230,7 @@ public final class NetworkExtensionServer implements ExtensionProducer { if (msg instanceof Incoming.ExtensionInfo) { if (client != null) LOGGER.warn("Overriding pre-existing CLIENT for channel (client={}, channel={})", client, channel); - client = new NetworkExtensionClient((Incoming.ExtensionInfo) msg, channel); + client = new NetworkExtensionClient(channel, (Incoming.ExtensionInfo) msg); if (NetworkExtensionAuthenticator.evaluate(client)) { LOGGER.info("Successfully authenticated client {}", client); clientAttribute.set(client);