Commit 79343b94da24cc14f71886b675844798efb28243
1 parent
0bc7907f
Allow correct plugin channel name length of 20, fixes #35
Showing
3 changed files
with
27 additions
and
3 deletions
src/client/java/com/mumfrey/liteloader/client/ClientPluginChannelsClient.java
@@ -7,6 +7,7 @@ package com.mumfrey.liteloader.client; | @@ -7,6 +7,7 @@ package com.mumfrey.liteloader.client; | ||
7 | 7 | ||
8 | import com.mumfrey.liteloader.client.ducks.IClientNetLoginHandler; | 8 | import com.mumfrey.liteloader.client.ducks.IClientNetLoginHandler; |
9 | import com.mumfrey.liteloader.core.ClientPluginChannels; | 9 | import com.mumfrey.liteloader.core.ClientPluginChannels; |
10 | +import com.mumfrey.liteloader.core.PluginChannels; | ||
10 | import com.mumfrey.liteloader.core.exceptions.UnregisteredChannelException; | 11 | import com.mumfrey.liteloader.core.exceptions.UnregisteredChannelException; |
11 | 12 | ||
12 | import net.minecraft.client.Minecraft; | 13 | import net.minecraft.client.Minecraft; |
@@ -89,7 +90,7 @@ public class ClientPluginChannelsClient extends ClientPluginChannels | @@ -89,7 +90,7 @@ public class ClientPluginChannelsClient extends ClientPluginChannels | ||
89 | @Override | 90 | @Override |
90 | protected boolean send(String channel, PacketBuffer data, ChannelPolicy policy) | 91 | protected boolean send(String channel, PacketBuffer data, ChannelPolicy policy) |
91 | { | 92 | { |
92 | - if (channel == null || channel.length() > 16 || CHANNEL_REGISTER.equals(channel) || CHANNEL_UNREGISTER.equals(channel)) | 93 | + if (!PluginChannels.isValidChannelName(channel)) |
93 | { | 94 | { |
94 | throw new RuntimeException("Invalid channel name specified"); | 95 | throw new RuntimeException("Invalid channel name specified"); |
95 | } | 96 | } |
src/main/java/com/mumfrey/liteloader/core/PluginChannels.java
@@ -32,6 +32,12 @@ public abstract class PluginChannels<L extends CommonPluginChannelListener> impl | @@ -32,6 +32,12 @@ public abstract class PluginChannels<L extends CommonPluginChannelListener> impl | ||
32 | // reserved channel consts | 32 | // reserved channel consts |
33 | protected static final String CHANNEL_REGISTER = "REGISTER"; | 33 | protected static final String CHANNEL_REGISTER = "REGISTER"; |
34 | protected static final String CHANNEL_UNREGISTER = "UNREGISTER"; | 34 | protected static final String CHANNEL_UNREGISTER = "UNREGISTER"; |
35 | + | ||
36 | + /** | ||
37 | + * Maximum allowable length of a channel name, previously 16 but increased | ||
38 | + * to 20 at some point. | ||
39 | + */ | ||
40 | + private static final int MAX_CHANNEL_NAME_LENGTH = 20; | ||
35 | 41 | ||
36 | /** | 42 | /** |
37 | * Number of faults for a specific listener before a warning is generated | 43 | * Number of faults for a specific listener before a warning is generated |
@@ -180,7 +186,7 @@ public abstract class PluginChannels<L extends CommonPluginChannelListener> impl | @@ -180,7 +186,7 @@ public abstract class PluginChannels<L extends CommonPluginChannelListener> impl | ||
180 | { | 186 | { |
181 | for (String channel : channels) | 187 | for (String channel : channels) |
182 | { | 188 | { |
183 | - if (channel.length() > 16 || channel.toUpperCase().equals(CHANNEL_REGISTER) || channel.toUpperCase().equals(CHANNEL_UNREGISTER)) | 189 | + if (!PluginChannels.isValidChannelName(channel)) |
184 | { | 190 | { |
185 | continue; | 191 | continue; |
186 | } | 192 | } |
@@ -194,6 +200,23 @@ public abstract class PluginChannels<L extends CommonPluginChannelListener> impl | @@ -194,6 +200,23 @@ public abstract class PluginChannels<L extends CommonPluginChannelListener> impl | ||
194 | } | 200 | } |
195 | } | 201 | } |
196 | } | 202 | } |
203 | + | ||
204 | + /** | ||
205 | + * Check whether the supplied channel name is valid. Valid channel names | ||
206 | + * must be between 1 and 20 characters long, and must not use the reserved | ||
207 | + * channel names <tt>REGISTER</tt> and <tt>UNREGISTER</tt> | ||
208 | + * | ||
209 | + * @param channel channel name to validate | ||
210 | + * @return true if the channel name is valid | ||
211 | + */ | ||
212 | + public static boolean isValidChannelName(String channel) | ||
213 | + { | ||
214 | + return channel != null | ||
215 | + && channel.length() > 0 | ||
216 | + && channel.length() <= PluginChannels.MAX_CHANNEL_NAME_LENGTH | ||
217 | + && !channel.toUpperCase().equals(PluginChannels.CHANNEL_REGISTER) | ||
218 | + && !channel.toUpperCase().equals(PluginChannels.CHANNEL_UNREGISTER); | ||
219 | + } | ||
197 | 220 | ||
198 | /** | 221 | /** |
199 | * Policy for dispatching plugin channel packets | 222 | * Policy for dispatching plugin channel packets |
src/main/java/com/mumfrey/liteloader/core/ServerPluginChannels.java
@@ -230,7 +230,7 @@ public class ServerPluginChannels extends PluginChannels<ServerPluginChannelList | @@ -230,7 +230,7 @@ public class ServerPluginChannels extends PluginChannels<ServerPluginChannelList | ||
230 | { | 230 | { |
231 | if (recipient == null) return false; | 231 | if (recipient == null) return false; |
232 | 232 | ||
233 | - if (channel == null || channel.length() > 16 || CHANNEL_REGISTER.equals(channel) || CHANNEL_UNREGISTER.equals(channel)) | 233 | + if (!PluginChannels.isValidChannelName(channel)) |
234 | { | 234 | { |
235 | throw new RuntimeException("Invalid channel name specified"); | 235 | throw new RuntimeException("Invalid channel name specified"); |
236 | } | 236 | } |