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.PremiumStatus;
import com.github.games647.fastlogin.core.message.ChannelMessage; import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.LoginActionMessage; 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.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin; import com.github.games647.fastlogin.core.shared.PlatformPlugin;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
@ -71,12 +72,14 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
setServerStarted(); setServerStarted();
// check for incoming messages from the bungeecord version of this plugin // 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)); getServer().getMessenger().registerIncomingPluginChannel(this, forceChannel, new BungeeListener(this));
// outgoing // outgoing
getServer().getMessenger().registerOutgoingPluginChannel(this, getName() + ':' + SUCCESS_CHANNEL); String successChannel = new NamespaceKey(getName(), SUCCESS_CHANNEL).getCombinedName();
getServer().getMessenger().registerOutgoingPluginChannel(this, getName() + ':' + CHANGE_CHANNEL); String changeChannel = new NamespaceKey(getName(), CHANGE_CHANNEL).getCombinedName();
getServer().getMessenger().registerOutgoingPluginChannel(this, successChannel);
getServer().getMessenger().registerOutgoingPluginChannel(this, changeChannel);
} else { } else {
if (!core.setupDatabase()) { if (!core.setupDatabase()) {
setEnabled(false); setEnabled(false);
@ -176,8 +179,9 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
if (player != null) { if (player != null) {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
message.writeTo(dataOutput); 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 @Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) { public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (!channel.equals(plugin.getName())) {
return;
}
ByteArrayDataInput dataInput = ByteStreams.newDataInput(message); 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(); LoginActionMessage loginMessage = new LoginActionMessage();
loginMessage.readFrom(dataInput); 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.hook.BungeeAuthHook;
import com.github.games647.fastlogin.bungee.listener.ConnectListener; 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.CommonUtil;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.ChannelMessage; 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.message.SuccessMessage;
import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin; import com.github.games647.fastlogin.core.shared.PlatformPlugin;
@ -50,11 +51,11 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
//events //events
getProxy().getPluginManager().registerListener(this, new ConnectListener(this)); 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 //this is required to listen to incoming messages from the server
getProxy().registerChannel(getName() + ':' + ChangePremiumMessage.CHANGE_CHANNEL); getProxy().registerChannel(new NamespaceKey(getName(), ChangePremiumMessage.CHANGE_CHANNEL).getCombinedName());
getProxy().registerChannel(getName() + ':' + SuccessMessage.SUCCESS_CHANNEL); getProxy().registerChannel(new NamespaceKey(getName(), SuccessMessage.SUCCESS_CHANNEL).getCombinedName());
registerHook(); registerHook();
} }
@ -86,7 +87,9 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
if (server != null) { if (server != null) {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
message.writeTo(dataOutput); 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") @SuppressWarnings("deprecation")
public ThreadFactory getThreadFactory() { public ThreadFactory getThreadFactory() {
return new ThreadFactoryBuilder() return new ThreadFactoryBuilder()
.setNameFormat(core.getPlugin().getName() + " Database Pool Thread #%1$d") .setNameFormat(getName() + " Database Pool Thread #%1$d")
//Hikari create daemons by default //Hikari create daemons by default
.setDaemon(true) .setDaemon(true)
.setThreadFactory(new GroupedThreadFactory(this, getName())) .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.bungee.task.AsyncToggleMessage;
import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage; 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.message.SuccessMessage;
import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.google.common.io.ByteArrayDataInput; 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.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
public class MessageListener implements Listener { public class PluginMessageListener implements Listener {
private final FastLoginBungee plugin; private final FastLoginBungee plugin;
private final String successChannel; private final String successChannel;
private final String changeChannel; private final String changeChannel;
public MessageListener(FastLoginBungee plugin) { public PluginMessageListener(FastLoginBungee plugin) {
this.plugin = plugin; this.plugin = plugin;
this.successChannel = plugin.getName() + ':' + SuccessMessage.SUCCESS_CHANNEL; this.successChannel = new NamespaceKey(plugin.getName(), SuccessMessage.SUCCESS_CHANNEL).getCombinedName();
this.changeChannel = plugin.getName() + ':' + ChangePremiumMessage.CHANGE_CHANNEL; this.changeChannel = new NamespaceKey(plugin.getName(), ChangePremiumMessage.CHANGE_CHANNEL).getCombinedName();
} }
@EventHandler @EventHandler
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) { public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
String channel = pluginMessageEvent.getTag(); String channel = pluginMessageEvent.getTag();
if (pluginMessageEvent.isCancelled() || !channel.startsWith(plugin.getName())) { if (pluginMessageEvent.isCancelled() || !channel.startsWith(plugin.getName().toLowerCase())) {
return; return;
} }

View File

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

View File

@ -7,7 +7,7 @@ import java.util.UUID;
public class LoginActionMessage implements ChannelMessage { public class LoginActionMessage implements ChannelMessage {
public static final String FORCE_CHANNEL = "ForceAct"; public static final String FORCE_CHANNEL = "force-act";
private Type type; 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 class SuccessMessage implements ChannelMessage {
public static final String SUCCESS_CHANNEL = "Success"; public static final String SUCCESS_CHANNEL = "success";
@Override @Override
public String getChannelName() { public String getChannelName() {