Channel names should be lowercase according to the spec

Related #217, #218
This commit is contained in:
games647
2018-07-24 10:15:16 +02:00
parent 6604cca8bd
commit 260b93a565
8 changed files with 51 additions and 28 deletions

View File

@ -12,6 +12,7 @@ import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.PremiumStatus;
import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.LoginActionMessage;
import com.github.games647.fastlogin.core.message.NamespaceKey;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
import com.google.common.io.ByteArrayDataOutput;
@ -71,12 +72,14 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
setServerStarted();
// check for incoming messages from the bungeecord version of this plugin
String forceChannel = getName() + ':' + LoginActionMessage.FORCE_CHANNEL;
String forceChannel = new NamespaceKey(getName(), LoginActionMessage.FORCE_CHANNEL).getCombinedName();
getServer().getMessenger().registerIncomingPluginChannel(this, forceChannel, new BungeeListener(this));
// outgoing
getServer().getMessenger().registerOutgoingPluginChannel(this, getName() + ':' + SUCCESS_CHANNEL);
getServer().getMessenger().registerOutgoingPluginChannel(this, getName() + ':' + CHANGE_CHANNEL);
String successChannel = new NamespaceKey(getName(), SUCCESS_CHANNEL).getCombinedName();
String changeChannel = new NamespaceKey(getName(), CHANGE_CHANNEL).getCombinedName();
getServer().getMessenger().registerOutgoingPluginChannel(this, successChannel);
getServer().getMessenger().registerOutgoingPluginChannel(this, changeChannel);
} else {
if (!core.setupDatabase()) {
setEnabled(false);
@ -176,8 +179,9 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
if (player != null) {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
message.writeTo(dataOutput);
String channel = this.getName() + ':' + message.getChannelName();
player.sendPluginMessage(this, channel, dataOutput.toByteArray());
NamespaceKey channel = new NamespaceKey(getName(), message.getChannelName());
player.sendPluginMessage(this, channel.getCombinedName(), dataOutput.toByteArray());
}
}

View File

@ -46,16 +46,7 @@ public class BungeeListener implements PluginMessageListener {
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (!channel.equals(plugin.getName())) {
return;
}
ByteArrayDataInput dataInput = ByteStreams.newDataInput(message);
String subChannel = dataInput.readUTF();
if (!"LoginAction".equals(subChannel)) {
plugin.getLog().info("Unknown sub channel {}", subChannel);
return;
}
LoginActionMessage loginMessage = new LoginActionMessage();
loginMessage.readFrom(dataInput);

View File

@ -2,10 +2,11 @@ package com.github.games647.fastlogin.bungee;
import com.github.games647.fastlogin.bungee.hook.BungeeAuthHook;
import com.github.games647.fastlogin.bungee.listener.ConnectListener;
import com.github.games647.fastlogin.bungee.listener.MessageListener;
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.NamespaceKey;
import com.github.games647.fastlogin.core.message.SuccessMessage;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
@ -50,11 +51,11 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
//events
getProxy().getPluginManager().registerListener(this, new ConnectListener(this));
getProxy().getPluginManager().registerListener(this, new MessageListener(this));
getProxy().getPluginManager().registerListener(this, new PluginMessageListener(this));
//this is required to listen to incoming messages from the server
getProxy().registerChannel(getName() + ':' + ChangePremiumMessage.CHANGE_CHANNEL);
getProxy().registerChannel(getName() + ':' + SuccessMessage.SUCCESS_CHANNEL);
getProxy().registerChannel(new NamespaceKey(getName(), ChangePremiumMessage.CHANGE_CHANNEL).getCombinedName());
getProxy().registerChannel(new NamespaceKey(getName(), SuccessMessage.SUCCESS_CHANNEL).getCombinedName());
registerHook();
}
@ -86,7 +87,9 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
if (server != null) {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
message.writeTo(dataOutput);
server.sendData(core.getPlugin().getName() + ':' + message.getChannelName(), dataOutput.toByteArray());
NamespaceKey channel = new NamespaceKey(getName(), message.getChannelName());
server.sendData(channel.getCombinedName(), dataOutput.toByteArray());
}
}
@ -114,7 +117,7 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
@SuppressWarnings("deprecation")
public ThreadFactory getThreadFactory() {
return new ThreadFactoryBuilder()
.setNameFormat(core.getPlugin().getName() + " Database Pool Thread #%1$d")
.setNameFormat(getName() + " Database Pool Thread #%1$d")
//Hikari create daemons by default
.setDaemon(true)
.setThreadFactory(new GroupedThreadFactory(this, getName()))

View File

@ -5,6 +5,7 @@ import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.bungee.task.AsyncToggleMessage;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.NamespaceKey;
import com.github.games647.fastlogin.core.message.SuccessMessage;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.google.common.io.ByteArrayDataInput;
@ -21,24 +22,24 @@ import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
public class MessageListener implements Listener {
public class PluginMessageListener implements Listener {
private final FastLoginBungee plugin;
private final String successChannel;
private final String changeChannel;
public MessageListener(FastLoginBungee plugin) {
public PluginMessageListener(FastLoginBungee plugin) {
this.plugin = plugin;
this.successChannel = plugin.getName() + ':' + SuccessMessage.SUCCESS_CHANNEL;
this.changeChannel = plugin.getName() + ':' + ChangePremiumMessage.CHANGE_CHANNEL;
this.successChannel = new NamespaceKey(plugin.getName(), SuccessMessage.SUCCESS_CHANNEL).getCombinedName();
this.changeChannel = new NamespaceKey(plugin.getName(), ChangePremiumMessage.CHANGE_CHANNEL).getCombinedName();
}
@EventHandler
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
String channel = pluginMessageEvent.getTag();
if (pluginMessageEvent.isCancelled() || !channel.startsWith(plugin.getName())) {
if (pluginMessageEvent.isCancelled() || !channel.startsWith(plugin.getName().toLowerCase())) {
return;
}

View File

@ -5,7 +5,7 @@ import com.google.common.io.ByteArrayDataOutput;
public class ChangePremiumMessage implements ChannelMessage {
public static final String CHANGE_CHANNEL = "ChStatus";
public static final String CHANGE_CHANNEL = "ch-status";
private String playerName;
private boolean willEnable;

View File

@ -7,7 +7,7 @@ import java.util.UUID;
public class LoginActionMessage implements ChannelMessage {
public static final String FORCE_CHANNEL = "ForceAct";
public static final String FORCE_CHANNEL = "force-act";
private Type type;

View File

@ -0,0 +1,24 @@
package com.github.games647.fastlogin.core.message;
public class NamespaceKey {
private final String namespace;
private final String key;
private final String combined;
public NamespaceKey(String namespace, String key) {
this.namespace = namespace.toLowerCase();
this.key = key.toLowerCase();
this.combined = namespace + ':' + key;
}
public String getCombinedName() {
return combined;
}
public static String getCombined(String namespace, String key) {
return new NamespaceKey(namespace, key).combined;
}
}

View File

@ -5,7 +5,7 @@ import com.google.common.io.ByteArrayDataOutput;
public class SuccessMessage implements ChannelMessage {
public static final String SUCCESS_CHANNEL = "Success";
public static final String SUCCESS_CHANNEL = "success";
@Override
public String getChannelName() {