mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2025-01-24 00:11:21 +01:00
Add sasl capability
Add nickserv command
This commit is contained in:
parent
eb3c75b139
commit
195deaf28c
@ -72,6 +72,7 @@ public class CommandHandlers implements CommandExecutor {
|
|||||||
commands.put("motd", new Motd(plugin));
|
commands.put("motd", new Motd(plugin));
|
||||||
commands.put("mute", new Mute(plugin));
|
commands.put("mute", new Mute(plugin));
|
||||||
commands.put("mutelist", new MuteList(plugin));
|
commands.put("mutelist", new MuteList(plugin));
|
||||||
|
commands.put("nickserv", new Nickserv(plugin));
|
||||||
commands.put("nick", new Nick(plugin));
|
commands.put("nick", new Nick(plugin));
|
||||||
commands.put("notice", new Notice(plugin));
|
commands.put("notice", new Notice(plugin));
|
||||||
commands.put("op", new Op(plugin));
|
commands.put("op", new Op(plugin));
|
||||||
|
89
src/main/java/com/cnaude/purpleirc/Commands/Nickserv.java
Normal file
89
src/main/java/com/cnaude/purpleirc/Commands/Nickserv.java
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 cnaude
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.cnaude.purpleirc.Commands;
|
||||||
|
|
||||||
|
import com.cnaude.purpleirc.PurpleBot;
|
||||||
|
import com.cnaude.purpleirc.PurpleIRC;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Chris Naude
|
||||||
|
*/
|
||||||
|
public class Nickserv implements IRCCommandInterface {
|
||||||
|
|
||||||
|
private final PurpleIRC plugin;
|
||||||
|
private final String usage = "([bot]) [message]";
|
||||||
|
private final String desc = "Send nickserv commands to the IRC server.";
|
||||||
|
private final String name = "nickserv";
|
||||||
|
private final String fullUsage = ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/irc " + name + " " + usage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param plugin the PurpleIRC plugin
|
||||||
|
*/
|
||||||
|
public Nickserv(PurpleIRC plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param sender
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void dispatch(CommandSender sender, String[] args) {
|
||||||
|
if (args.length >= 2) {
|
||||||
|
int msgIdx = 1;
|
||||||
|
List<PurpleBot> myBots = new ArrayList<>();
|
||||||
|
if (plugin.ircBots.containsKey(args[1])) {
|
||||||
|
myBots.add(plugin.ircBots.get(args[1]));
|
||||||
|
msgIdx = 2;
|
||||||
|
} else {
|
||||||
|
myBots.addAll(plugin.ircBots.values());
|
||||||
|
}
|
||||||
|
for (PurpleBot ircBot : myBots) {
|
||||||
|
String msg = "";
|
||||||
|
for (int i = msgIdx; i < args.length; i++) {
|
||||||
|
msg = msg + " " + args[i];
|
||||||
|
}
|
||||||
|
plugin.logDebug("Sending nickserv message to the server: " + msg.substring(1));
|
||||||
|
ircBot.asyncRawlineNow(msg.substring(1));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(fullUsage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String desc() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
}
|
@ -82,6 +82,7 @@ import org.pircbotx.Configuration;
|
|||||||
import org.pircbotx.PircBotX;
|
import org.pircbotx.PircBotX;
|
||||||
import org.pircbotx.User;
|
import org.pircbotx.User;
|
||||||
import org.pircbotx.UtilSSLSocketFactory;
|
import org.pircbotx.UtilSSLSocketFactory;
|
||||||
|
import org.pircbotx.cap.SASLCapHandler;
|
||||||
import org.pircbotx.cap.TLSCapHandler;
|
import org.pircbotx.cap.TLSCapHandler;
|
||||||
import org.pircbotx.exception.IrcException;
|
import org.pircbotx.exception.IrcException;
|
||||||
import org.pircbotx.hooks.ListenerAdapter;
|
import org.pircbotx.hooks.ListenerAdapter;
|
||||||
@ -102,6 +103,7 @@ public final class PurpleBot {
|
|||||||
public boolean autoConnect;
|
public boolean autoConnect;
|
||||||
public boolean ssl;
|
public boolean ssl;
|
||||||
public boolean tls;
|
public boolean tls;
|
||||||
|
public boolean sasl;
|
||||||
public boolean trustAllCerts;
|
public boolean trustAllCerts;
|
||||||
public boolean disableDiffieHellman;
|
public boolean disableDiffieHellman;
|
||||||
public boolean sendRawMessageOnConnect;
|
public boolean sendRawMessageOnConnect;
|
||||||
@ -127,6 +129,8 @@ public final class PurpleBot {
|
|||||||
public String commandPrefix;
|
public String commandPrefix;
|
||||||
public String quitMessage;
|
public String quitMessage;
|
||||||
public String botIdentPassword;
|
public String botIdentPassword;
|
||||||
|
public String saslUsername;
|
||||||
|
public String saslPassword;
|
||||||
public List<String> rawMessages;
|
public List<String> rawMessages;
|
||||||
public String channelCmdNotifyMode;
|
public String channelCmdNotifyMode;
|
||||||
public String partInvalidChannelsMsg;
|
public String partInvalidChannelsMsg;
|
||||||
@ -323,6 +327,7 @@ public final class PurpleBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Configuration.Builder configBuilder = new Configuration.Builder()
|
Configuration.Builder configBuilder = new Configuration.Builder()
|
||||||
|
.setCapEnabled(sasl)
|
||||||
.setName(botNick)
|
.setName(botNick)
|
||||||
.setLogin(botLogin)
|
.setLogin(botLogin)
|
||||||
.setAutoNickChange(true)
|
.setAutoNickChange(true)
|
||||||
@ -347,6 +352,10 @@ public final class PurpleBot {
|
|||||||
}
|
}
|
||||||
configBuilder.setNickservPassword(botIdentPassword);
|
configBuilder.setNickservPassword(botIdentPassword);
|
||||||
}
|
}
|
||||||
|
if (sasl) {
|
||||||
|
plugin.logInfo("Enabling SASL ...");
|
||||||
|
configBuilder.addCapHandler(new SASLCapHandler(saslUsername, saslPassword));
|
||||||
|
}
|
||||||
if (tls) {
|
if (tls) {
|
||||||
plugin.logInfo("Enabling TLS ...");
|
plugin.logInfo("Enabling TLS ...");
|
||||||
configBuilder.addCapHandler(new TLSCapHandler());
|
configBuilder.addCapHandler(new TLSCapHandler());
|
||||||
@ -768,6 +777,7 @@ public final class PurpleBot {
|
|||||||
autoConnect = config.getBoolean("autoconnect", true);
|
autoConnect = config.getBoolean("autoconnect", true);
|
||||||
tls = config.getBoolean("tls", false);
|
tls = config.getBoolean("tls", false);
|
||||||
ssl = config.getBoolean("ssl", false);
|
ssl = config.getBoolean("ssl", false);
|
||||||
|
sasl = config.getBoolean("sasl", false);
|
||||||
ciphers = config.getStringList("ciphers");
|
ciphers = config.getStringList("ciphers");
|
||||||
plugin.logDebug("Ciphers => " + ciphers);
|
plugin.logDebug("Ciphers => " + ciphers);
|
||||||
trustAllCerts = config.getBoolean("trust-all-certs", false);
|
trustAllCerts = config.getBoolean("trust-all-certs", false);
|
||||||
@ -801,6 +811,8 @@ public final class PurpleBot {
|
|||||||
botServerPort = config.getInt("port");
|
botServerPort = config.getInt("port");
|
||||||
botServerPass = config.getString("password", "");
|
botServerPass = config.getString("password", "");
|
||||||
botIdentPassword = config.getString("ident-password", "");
|
botIdentPassword = config.getString("ident-password", "");
|
||||||
|
saslUsername = config.getString("sasl-username", "");
|
||||||
|
saslPassword = config.getString("sasl-password", "");
|
||||||
commandPrefix = config.getString("command-prefix", ".");
|
commandPrefix = config.getString("command-prefix", ".");
|
||||||
chatDelay = config.getLong("message-delay", 1000);
|
chatDelay = config.getLong("message-delay", 1000);
|
||||||
finger = config.getString("finger-reply", "PurpleIRC");
|
finger = config.getString("finger-reply", "PurpleIRC");
|
||||||
@ -1248,7 +1260,7 @@ public final class PurpleBot {
|
|||||||
connectMessage = "Connecting to " + botServer + ":"
|
connectMessage = "Connecting to " + botServer + ":"
|
||||||
+ botServerPort + ": [Nick: " + botNick
|
+ botServerPort + ": [Nick: " + botNick
|
||||||
+ "] [SSL: " + ssl + "]" + " [TrustAllCerts: "
|
+ "] [SSL: " + ssl + "]" + " [TrustAllCerts: "
|
||||||
+ trustAllCerts + "] [TLS: " + tls + "]";
|
+ trustAllCerts + "] [TLS: " + tls + "] [SASL: " + sasl + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException | InvalidConfigurationException ex) {
|
} catch (IOException | InvalidConfigurationException ex) {
|
||||||
|
@ -41,6 +41,12 @@ autoconnect: 'false'
|
|||||||
password: ''
|
password: ''
|
||||||
# identify password (sent to NickServ)
|
# identify password (sent to NickServ)
|
||||||
ident-password: ''
|
ident-password: ''
|
||||||
|
# Attempt sasl connection
|
||||||
|
sasl: false
|
||||||
|
# SASL password
|
||||||
|
sasl-password: ''
|
||||||
|
# SASL username
|
||||||
|
sasl-username: ''
|
||||||
# command-prefix - The bot will listen for commands that start with this.
|
# command-prefix - The bot will listen for commands that start with this.
|
||||||
command-prefix: '.'
|
command-prefix: '.'
|
||||||
# quit-message - Message the bot will send when it quits the server
|
# quit-message - Message the bot will send when it quits the server
|
||||||
|
Loading…
Reference in New Issue
Block a user