Skip to content

Commit

Permalink
Updates:
Browse files Browse the repository at this point in the history
- Better handling of IPC message length calculation

Dependency Updates:
- Jetbrains annotations to 23.1.0 (was 23.0.0)
- Maven shade plugin to 3.4.1 (was 3.3.0)
  • Loading branch information
mciolkosz committed Dec 29, 2022
1 parent 6ab1e17 commit 60529b2
Show file tree
Hide file tree
Showing 19 changed files with 291 additions and 185 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BungeeIPC is a set of APIs and plugins meant for BungeeCord proxies and their ba
## Obtaining BungeeIPC

You can obtain a copy of BungeeIPC via the following methods:
- Download a pre-built copy from the [Releases page](https://github.com/bspfsystems/BungeeIPC/releases/latest/). The latest version is release 3.0.4.
- Download a pre-built copy from the [Releases page](https://github.com/bspfsystems/BungeeIPC/releases/latest/). The latest version is release 3.1.0.
- Build from source (see below).

If you need to use BungeeIPC as a dependency for your project, please see the Development API section below.
Expand Down Expand Up @@ -58,7 +58,7 @@ Include the following in your `pom.xml` file:<br />
<dependency>
<groupId>org.bspfsystems.bungeeipc</groupId>
<artifactId>bungeeipc-common-api</artifactId>
<version>3.0.4</version>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -68,7 +68,7 @@ Include the following in your `pom.xml` file:<br />
<dependency>
<groupId>org.bspfsystems.bungeeipc</groupId>
<artifactId>bungeeipc-client-api</artifactId>
<version>3.0.4</version>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -78,7 +78,7 @@ Include the following in your `pom.xml` file:<br />
<dependency>
<groupId>org.bspfsystems.bungeeipc</groupId>
<artifactId>bungeeipc-server-api</artifactId>
<version>3.0.4</version>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -95,17 +95,17 @@ repositories {
// For both Bukkit and BungeeCord
dependencies {
compileOnly "org.bspfsystems.bungeeipc:bungeeipc-common-api:3.0.4"
compileOnly "org.bspfsystems.bungeeipc:bungeeipc-common-api:3.1.0"
}
// For Bukkit
dependencies {
compileOnly "org.bspfsystems.bungeeipc:bungeeipc-client-api:3.0.4"
compileOnly "org.bspfsystems.bungeeipc:bungeeipc-client-api:3.1.0"
}
// For BungeeCord
dependencies {
compileOnly "org.bspfsystems.bungeeipc:bungeeipc-server-api:3.0.4"
compileOnly "org.bspfsystems.bungeeipc:bungeeipc-server-api:3.1.0"
}
```

Expand Down
8 changes: 4 additions & 4 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.bspfsystems.bungeeipc</groupId>
<artifactId>bungeeipc-parent</artifactId>
<version>3.0.4</version>
<version>3.1.0</version>
</parent>

<artifactId>bungeeipc-bukkit</artifactId>
Expand All @@ -37,13 +37,13 @@
<dependency>
<groupId>org.bspfsystems.bungeeipc</groupId>
<artifactId>bungeeipc-client-api</artifactId>
<version>3.0.4</version>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<version>23.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -59,7 +59,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
<configuration>
<filters>
<filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ final class BukkitClientIPCSocket implements ClientIPCSocket {
final String addressValue = config.getString("bungeecord_ip", "localhost");
final int portValue = config.getInt("port", -1);

BukkitClientIPCSocket.validateNotBlank(addressValue, "IP address cannot be blank.");
if (addressValue.trim().isEmpty()) {
throw new IllegalArgumentException("IP address cannot be blank.");
}
if (portValue == -1) {
throw new IllegalArgumentException("Port must be specified in the config.");
}
Expand All @@ -103,7 +105,7 @@ final class BukkitClientIPCSocket implements ClientIPCSocket {

try {
this.address = InetAddress.getByName(addressValue);
} catch (UnknownHostException e) {
} catch (final UnknownHostException e) {
throw new IllegalArgumentException("Unable to decipher IP address from config value.", e);
}
this.port = portValue;
Expand Down Expand Up @@ -165,7 +167,7 @@ public void run() {

this.connected.set(true);
this.logger.log(Level.INFO, "Connected to the IPC server.");
} catch (IOException e) {
} catch (final IOException e) {

this.logger.log(Level.INFO, "Unable to connect to IPC server.");
this.logger.log(Level.CONFIG, "IP Address - " + this.address.getHostAddress());
Expand All @@ -185,7 +187,7 @@ public void run() {
final IPCMessage message = SimpleClientIPCMessage.read(fromBungee.readUTF());
this.scheduler.runTask(this.ipcPlugin, () -> this.ipcPlugin.receiveMessage(message));
}
} catch (IOException e) {
} catch (final IOException e) {

this.logger.log(Level.INFO, "IPC connection broken.");
this.logger.log(Level.CONFIG, "IP Address - " + this.address.getHostAddress());
Expand All @@ -196,7 +198,7 @@ public void run() {
if (this.toBungee != null) {
this.toBungee.close();
}
} catch (IOException e1) {
} catch (final IOException e1) {
this.logger.log(Level.WARNING, "Failure for IPC client.");
this.logger.log(Level.WARNING, "Unable to close the DataOutputStream after the IPC connection was broken.");
this.logger.log(Level.WARNING, e1.getClass().getSimpleName() + " thrown.", e1);
Expand All @@ -206,7 +208,7 @@ public void run() {
if (this.socket != null) {
this.socket.close();
}
} catch (IOException e1) {
} catch (final IOException e1) {
this.logger.log(Level.WARNING, "Failure for IPC client.");
this.logger.log(Level.WARNING, "Unable to close the Socket after the IPC connection was broken.");
this.logger.log(Level.WARNING, e1.getClass().getSimpleName() + " thrown.", e1);
Expand All @@ -229,18 +231,21 @@ private static class SimpleClientIPCMessage extends AbstractIPCMessage {

/**
* Constructs a new {@link IPCMessage}.
*
*
* @param origin The origin {@link IPCSocket}.
* @param destination The destination {@link IPCSocket}.
* @param channel The channel the {@link IPCMessage} will be read by.
* @param data The initial data as a {@link Queue}. Order will be
* maintained.
* @see AbstractIPCMessage#AbstractIPCMessage(String, String, String, Queue)
* @throws IllegalArgumentException If {@code origin},
* {@code destination}, and/or
* {@code channel} are blank, or if any
* element in {@code data} is
* {@code null}.
* @throws IllegalStateException If the given parameters contain too much
* data to send in a single
* {@link IPCMessage}.
* @see AbstractIPCMessage#AbstractIPCMessage(String, String, String, Queue)
*/
private SimpleClientIPCMessage(@NotNull final String origin, @NotNull final String destination, @NotNull final String channel, @NotNull final Queue<String> data) {
super(origin, destination, channel, data);
Expand All @@ -253,11 +258,17 @@ private SimpleClientIPCMessage(@NotNull final String origin, @NotNull final Stri
* @param message The serialized {@link IPCMessage} as a {@link String}.
* @return The deserialized {@link IPCMessage}.
* @throws IllegalArgumentException If the given message is blank.
* @throws IllegalStateException If the given parameters contain too much
* data to send in a single
* {@link IPCMessage}.
*/
@NotNull
private static IPCMessage read(@NotNull String message) {
private static IPCMessage read(@NotNull String message) throws IllegalArgumentException, IllegalStateException {

if (message.trim().isEmpty()) {
throw new IllegalArgumentException("IPCMessage data cannot be blank, cannot recreate IPCMessage: " + message);
}

AbstractIPCMessage.validateNotBlank(message, "IPCMessage data cannot be blank, cannot recreate IPCMessage: " + message);
final Queue<String> split = new LinkedList<String>();

int index = message.indexOf(AbstractIPCMessage.SEPARATOR);
Expand Down Expand Up @@ -304,7 +315,7 @@ public void stop() {
if (this.toBungee != null) {
this.toBungee.close();
}
} catch (IOException e) {
} catch (final IOException e) {
this.logger.log(Level.WARNING, "Failure for IPC client.");
this.logger.log(Level.WARNING, "Unable to close the DataOutputStream during shutdown.");
this.logger.log(Level.WARNING, e.getClass().getSimpleName() + " thrown.", e);
Expand All @@ -314,7 +325,7 @@ public void stop() {
if (this.socket != null) {
this.socket.close();
}
} catch (IOException e) {
} catch (final IOException e) {
this.logger.log(Level.WARNING, "Failure for IPC client.");
this.logger.log(Level.WARNING, "Unable to close the Socket during shutdown.");
this.logger.log(Level.WARNING, e.getClass().getSimpleName() + " thrown.", e);
Expand Down Expand Up @@ -355,23 +366,9 @@ private synchronized void send(@NotNull final IPCMessage message) {

try {
this.toBungee.writeUTF(message.write());
} catch (IOException e) {
} catch (final IOException e) {
this.logger.log(Level.WARNING, "Cannot send IPC message to Bungee proxy.");
this.logger.log(Level.WARNING, e.getClass().getSimpleName() + " thrown.", e);
}
}

/**
* Validates that the given {@link String value} is not empty (or only
* whitespace).
*
* @param value The {@link String value} to check for being blank.
* @param message The error message to display if the value is blank.
* @throws IllegalArgumentException If the given value is blank.
*/
private static void validateNotBlank(@Nullable final String value, @NotNull final String message) throws IllegalArgumentException {
if (value != null && value.trim().isEmpty()) {
throw new IllegalArgumentException(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void onEnable() {
this.logger.log(Level.SEVERE, "IPC Client will not be started.");
return;
}
} catch (SecurityException e) {
} catch (final SecurityException e) {
this.logger.log(Level.SEVERE, "Unable to validate if the BungeeIPC data directory has been properly created at " + dataDirectory.getPath());
this.logger.log(Level.SEVERE, "IPC Client will not be started.");
this.logger.log(Level.SEVERE, e.getClass().getSimpleName() + " thrown.", e);
Expand Down Expand Up @@ -368,7 +368,7 @@ private void reloadConfig(@NotNull final CommandSender sender, final boolean com
}
return;
}
} catch (SecurityException | IOException e) {
} catch (final SecurityException | IOException e) {
this.logger.log(Level.WARNING, "Unable to load the BungeeIPC configuration file at " + configFile.getPath());
this.logger.log(Level.WARNING, "IPC Client will not be started.");
this.logger.log(Level.WARNING, e.getClass().getSimpleName() + " thrown.", e);
Expand All @@ -381,7 +381,7 @@ private void reloadConfig(@NotNull final CommandSender sender, final boolean com
final YamlConfiguration config = new YamlConfiguration();
try {
config.load(configFile);
} catch (IOException | InvalidConfigurationException | IllegalArgumentException e) {
} catch (final IOException | InvalidConfigurationException | IllegalArgumentException e) {
this.logger.log(Level.WARNING, "Unable to load BungeeIPC configuration.");
this.logger.log(Level.WARNING, "IPC Client will not be started.");
this.logger.log(Level.WARNING, e.getClass().getSimpleName() + " thrown.", e);
Expand All @@ -395,7 +395,7 @@ private void reloadConfig(@NotNull final CommandSender sender, final boolean com
Level rawLoggingLevel;
try {
rawLoggingLevel = Level.parse(config.getString("logging_level", "INFO"));
} catch (NullPointerException | IllegalArgumentException e) {
} catch (final NullPointerException | IllegalArgumentException e) {
this.logger.log(Level.WARNING, "Unable to load the BungeeIPC logging level.");
this.logger.log(Level.WARNING, "Will use the default level (INFO).");
this.logger.log(Level.WARNING, e.getClass().getSimpleName() + " thrown.", e);
Expand Down Expand Up @@ -456,7 +456,7 @@ private void reloadConfig(@NotNull final CommandSender sender, final boolean com
sslContext.init(null, null, null);

sslSocketFactory = sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
} catch (final NoSuchAlgorithmException | KeyManagementException e) {
this.logger.log(Level.WARNING, "Unable to create SSLSocketFactory.");
this.logger.log(Level.WARNING, "IPC Client will not be started.");
this.logger.log(Level.WARNING, e.getClass().getSimpleName() + "thrown.", e);
Expand All @@ -471,7 +471,7 @@ private void reloadConfig(@NotNull final CommandSender sender, final boolean com

try {
this.socket = new BukkitClientIPCSocket(this, config, sslSocketFactory, tlsVersionWhitelist, tlsCipherSuiteWhitelist);
} catch (IllegalArgumentException e) {
} catch (final IllegalArgumentException e) {
this.logger.log(Level.WARNING, "Unable to create IPC Client.");
this.logger.log(Level.WARNING, "IPC Client will not be started.");
this.logger.log(Level.WARNING, e.getClass().getSimpleName() + " thrown.", e);
Expand Down
2 changes: 1 addition & 1 deletion bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: BungeeIPC
main: org.bspfsystems.bungeeipc.bukkit.BukkitIPCPlugin
author: mciolkosz
website: https://github.com/bspfsystems/BungeeIPC/
version: 3.0.4
version: 3.1.0

commands:
ipc:
Expand Down
8 changes: 4 additions & 4 deletions bungeecord/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.bspfsystems.bungeeipc</groupId>
<artifactId>bungeeipc-parent</artifactId>
<version>3.0.4</version>
<version>3.1.0</version>
</parent>

<artifactId>bungeeipc-bungeecord</artifactId>
Expand All @@ -37,13 +37,13 @@
<dependency>
<groupId>org.bspfsystems.bungeeipc</groupId>
<artifactId>bungeeipc-server-api</artifactId>
<version>3.0.4</version>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<version>23.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -59,7 +59,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
<configuration>
<filters>
<filter>
Expand Down
Loading

0 comments on commit 60529b2

Please sign in to comment.