mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2025-02-20 13:31:33 +01:00
Split messages with \r\n and \n.
This commit is contained in:
parent
60dcc46328
commit
5654897419
@ -39,10 +39,8 @@ public class BotWatcher {
|
|||||||
bt = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new Runnable() {
|
bt = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
//plugin.logDebug("Checking connection status of IRC bots.");
|
|
||||||
for (PurpleBot ircBot : plugin.ircBots.values()) {
|
for (PurpleBot ircBot : plugin.ircBots.values()) {
|
||||||
if (ircBot.isConnectedBlocking()) {
|
if (ircBot.isConnectedBlocking()) {
|
||||||
//plugin.logDebug("[" + ircBot.botNick + "] CONNECTED");
|
|
||||||
ircBot.setConnected(true);
|
ircBot.setConnected(true);
|
||||||
} else {
|
} else {
|
||||||
ircBot.setConnected(false);
|
ircBot.setConnected(false);
|
||||||
|
@ -51,4 +51,5 @@ public class ChannelWatcher {
|
|||||||
public void cancel() {
|
public void cancel() {
|
||||||
bt.cancel();
|
bt.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.cnaude.purpleirc.Commands;
|
package com.cnaude.purpleirc.Commands;
|
||||||
|
|
||||||
|
import com.cnaude.purpleirc.PurpleBot;
|
||||||
import com.cnaude.purpleirc.PurpleIRC;
|
import com.cnaude.purpleirc.PurpleIRC;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -27,7 +33,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
public class Test implements IRCCommandInterface {
|
public class Test implements IRCCommandInterface {
|
||||||
|
|
||||||
private final PurpleIRC plugin;
|
private final PurpleIRC plugin;
|
||||||
private final String usage = "[player name]";
|
private final String usage = "[name|sslciphers]";
|
||||||
private final String desc = "Testing various Vault methods.";
|
private final String desc = "Testing various Vault methods.";
|
||||||
private final String name = "test";
|
private final String name = "test";
|
||||||
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
|
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
|
||||||
@ -49,12 +55,32 @@ public class Test implements IRCCommandInterface {
|
|||||||
public void dispatch(CommandSender sender, String[] args) {
|
public void dispatch(CommandSender sender, String[] args) {
|
||||||
//irc test <username>
|
//irc test <username>
|
||||||
if (plugin.vaultHelpers == null) {
|
if (plugin.vaultHelpers == null) {
|
||||||
sender.sendMessage(ChatColor.RED + "Vault is not enabled!");
|
sender.sendMessage(ChatColor.RED + "Vault is no enabled!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (plugin.debugMode()) {
|
if (plugin.debugMode()) {
|
||||||
if (args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
String playername = args[1];
|
String playername = args[1];
|
||||||
|
if (playername.equalsIgnoreCase("sslciphers")) {
|
||||||
|
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Available SSL ciphers");
|
||||||
|
SSLContext context;
|
||||||
|
try {
|
||||||
|
context = SSLContext.getDefault();
|
||||||
|
SSLSocketFactory sf = context.getSocketFactory();
|
||||||
|
String[] cipherSuites = sf.getSupportedCipherSuites();
|
||||||
|
for (String s : cipherSuites) {
|
||||||
|
sender.sendMessage(ChatColor.WHITE + "-- " + ChatColor.GOLD + s);
|
||||||
|
}
|
||||||
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
} else if (playername.equalsIgnoreCase("splits")) {
|
||||||
|
for (PurpleBot ircBot : plugin.ircBots.values()) {
|
||||||
|
for (String channelName : ircBot.botChannels) {
|
||||||
|
ircBot.asyncIRCMessage(channelName, "Test\r\nTest2\r\nTest3\nTest4\nTest5");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Testing " + playername);
|
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Testing " + playername);
|
||||||
sender.sendMessage("displayName : " + plugin.getDisplayName(name));
|
sender.sendMessage("displayName : " + plugin.getDisplayName(name));
|
||||||
sender.sendMessage("getGroupPrefix : " + plugin.getGroupPrefix(plugin.defaultPlayerWorld, playername));
|
sender.sendMessage("getGroupPrefix : " + plugin.getGroupPrefix(plugin.defaultPlayerWorld, playername));
|
||||||
@ -62,6 +88,7 @@ public class Test implements IRCCommandInterface {
|
|||||||
sender.sendMessage("getPlayerPrefix : " + plugin.getPlayerPrefix(plugin.defaultPlayerWorld, playername));
|
sender.sendMessage("getPlayerPrefix : " + plugin.getPlayerPrefix(plugin.defaultPlayerWorld, playername));
|
||||||
sender.sendMessage("getPlayerSuffix : " + plugin.getPlayerSuffix(plugin.defaultPlayerWorld, playername));
|
sender.sendMessage("getPlayerSuffix : " + plugin.getPlayerSuffix(plugin.defaultPlayerWorld, playername));
|
||||||
sender.sendMessage("getPlayerGroup : " + plugin.getPlayerGroup(plugin.defaultPlayerWorld, playername));
|
sender.sendMessage("getPlayerGroup : " + plugin.getPlayerGroup(plugin.defaultPlayerWorld, playername));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(fullUsage);
|
sender.sendMessage(fullUsage);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,9 @@ public class IRCMessageQueueWatcher {
|
|||||||
private final PurpleBot ircBot;
|
private final PurpleBot ircBot;
|
||||||
private final Timer timer;
|
private final Timer timer;
|
||||||
private final BlockingQueue<IRCMessage> queue = new LinkedBlockingQueue<>();
|
private final BlockingQueue<IRCMessage> queue = new LinkedBlockingQueue<>();
|
||||||
|
private final String REGEX_CLEAN = "^[\\r\\n]|[\\r\\n]$";
|
||||||
|
private final String REGEX_CRLF = "\\r\\n";
|
||||||
|
private final String LF = "\\n";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -58,13 +61,15 @@ public class IRCMessageQueueWatcher {
|
|||||||
IRCMessage ircMessage = queue.poll();
|
IRCMessage ircMessage = queue.poll();
|
||||||
if (ircMessage != null) {
|
if (ircMessage != null) {
|
||||||
plugin.logDebug("[" + queue.size() + "]: queueAndSend message detected");
|
plugin.logDebug("[" + queue.size() + "]: queueAndSend message detected");
|
||||||
|
for (String s : cleanupAndSplitMessage(ircMessage.message)) {
|
||||||
if (ircMessage.ctcpResponse) {
|
if (ircMessage.ctcpResponse) {
|
||||||
blockingCTCPMessage(ircMessage.target, ircMessage.message);
|
blockingCTCPMessage(ircMessage.target, s);
|
||||||
} else {
|
} else {
|
||||||
blockingIRCMessage(ircMessage.target, ircMessage.message);
|
blockingIRCMessage(ircMessage.target, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void blockingIRCMessage(final String target, final String message) {
|
private void blockingIRCMessage(final String target, final String message) {
|
||||||
if (!ircBot.isConnected()) {
|
if (!ircBot.isConnected()) {
|
||||||
@ -72,7 +77,6 @@ public class IRCMessageQueueWatcher {
|
|||||||
}
|
}
|
||||||
plugin.logDebug("[blockingIRCMessage] About to send IRC message to " + target + ": " + message);
|
plugin.logDebug("[blockingIRCMessage] About to send IRC message to " + target + ": " + message);
|
||||||
ircBot.bot.sendIRC().message(target, message);
|
ircBot.bot.sendIRC().message(target, message);
|
||||||
//ircBot.bot.sendRaw().rawLineNow("PRIVMSG " + target + " :" + message);
|
|
||||||
plugin.logDebug("[blockingIRCMessage] Message sent to " + target + ": " + message);
|
plugin.logDebug("[blockingIRCMessage] Message sent to " + target + ": " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +89,10 @@ public class IRCMessageQueueWatcher {
|
|||||||
plugin.logDebug("[blockingCTCPMessage] Message sent to " + target + ": " + message);
|
plugin.logDebug("[blockingCTCPMessage] Message sent to " + target + ": " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String[] cleanupAndSplitMessage(String message) {
|
||||||
|
return message.replaceAll(REGEX_CLEAN, "").replaceAll(REGEX_CRLF, "\n").split(LF);
|
||||||
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
}
|
}
|
||||||
@ -104,4 +112,5 @@ public class IRCMessageQueueWatcher {
|
|||||||
public void add(IRCMessage ircMessage) {
|
public void add(IRCMessage ircMessage) {
|
||||||
queue.offer(ircMessage);
|
queue.offer(ircMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -479,13 +479,14 @@ public final class PurpleBot {
|
|||||||
|
|
||||||
public void asyncIRCMessage(final String target, final String message) {
|
public void asyncIRCMessage(final String target, final String message) {
|
||||||
plugin.logDebug("Entering aysncIRCMessage");
|
plugin.logDebug("Entering aysncIRCMessage");
|
||||||
messageQueue.add(new IRCMessage(target, plugin.colorConverter.
|
IRCMessage ircMessage = new IRCMessage(target, plugin.colorConverter.gameColorsToIrc(message), false);
|
||||||
gameColorsToIrc(message), false));
|
messageQueue.add(ircMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void asyncCTCPMessage(final String target, final String message) {
|
public void asyncCTCPMessage(final String target, final String message) {
|
||||||
plugin.logDebug("Entering asyncCTCPMessage");
|
plugin.logDebug("Entering asyncCTCPMessage");
|
||||||
messageQueue.add(new IRCMessage(target, plugin.colorConverter.gameColorsToIrc(message), true));
|
IRCMessage ircMessage = new IRCMessage(target, plugin.colorConverter.gameColorsToIrc(message), true);
|
||||||
|
messageQueue.add(ircMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void asyncCTCPCommand(final String target, final String command) {
|
public void asyncCTCPCommand(final String target, final String command) {
|
||||||
|
Loading…
Reference in New Issue
Block a user