Add sasl capability

Add nickserv command
This commit is contained in:
cnaude 2017-06-17 12:29:31 -07:00
parent eb3c75b139
commit 195deaf28c
4 changed files with 114 additions and 6 deletions

View File

@ -72,6 +72,7 @@ public class CommandHandlers implements CommandExecutor {
commands.put("motd", new Motd(plugin));
commands.put("mute", new Mute(plugin));
commands.put("mutelist", new MuteList(plugin));
commands.put("nickserv", new Nickserv(plugin));
commands.put("nick", new Nick(plugin));
commands.put("notice", new Notice(plugin));
commands.put("op", new Op(plugin));

View 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;
}
}

View File

@ -82,6 +82,7 @@ import org.pircbotx.Configuration;
import org.pircbotx.PircBotX;
import org.pircbotx.User;
import org.pircbotx.UtilSSLSocketFactory;
import org.pircbotx.cap.SASLCapHandler;
import org.pircbotx.cap.TLSCapHandler;
import org.pircbotx.exception.IrcException;
import org.pircbotx.hooks.ListenerAdapter;
@ -102,6 +103,7 @@ public final class PurpleBot {
public boolean autoConnect;
public boolean ssl;
public boolean tls;
public boolean sasl;
public boolean trustAllCerts;
public boolean disableDiffieHellman;
public boolean sendRawMessageOnConnect;
@ -127,6 +129,8 @@ public final class PurpleBot {
public String commandPrefix;
public String quitMessage;
public String botIdentPassword;
public String saslUsername;
public String saslPassword;
public List<String> rawMessages;
public String channelCmdNotifyMode;
public String partInvalidChannelsMsg;
@ -323,6 +327,7 @@ public final class PurpleBot {
}
}
Configuration.Builder configBuilder = new Configuration.Builder()
.setCapEnabled(sasl)
.setName(botNick)
.setLogin(botLogin)
.setAutoNickChange(true)
@ -347,6 +352,10 @@ public final class PurpleBot {
}
configBuilder.setNickservPassword(botIdentPassword);
}
if (sasl) {
plugin.logInfo("Enabling SASL ...");
configBuilder.addCapHandler(new SASLCapHandler(saslUsername, saslPassword));
}
if (tls) {
plugin.logInfo("Enabling TLS ...");
configBuilder.addCapHandler(new TLSCapHandler());
@ -768,6 +777,7 @@ public final class PurpleBot {
autoConnect = config.getBoolean("autoconnect", true);
tls = config.getBoolean("tls", false);
ssl = config.getBoolean("ssl", false);
sasl = config.getBoolean("sasl", false);
ciphers = config.getStringList("ciphers");
plugin.logDebug("Ciphers => " + ciphers);
trustAllCerts = config.getBoolean("trust-all-certs", false);
@ -801,6 +811,8 @@ public final class PurpleBot {
botServerPort = config.getInt("port");
botServerPass = config.getString("password", "");
botIdentPassword = config.getString("ident-password", "");
saslUsername = config.getString("sasl-username", "");
saslPassword = config.getString("sasl-password", "");
commandPrefix = config.getString("command-prefix", ".");
chatDelay = config.getLong("message-delay", 1000);
finger = config.getString("finger-reply", "PurpleIRC");
@ -1248,7 +1260,7 @@ public final class PurpleBot {
connectMessage = "Connecting to " + botServer + ":"
+ botServerPort + ": [Nick: " + botNick
+ "] [SSL: " + ssl + "]" + " [TrustAllCerts: "
+ trustAllCerts + "] [TLS: " + tls + "]";
+ trustAllCerts + "] [TLS: " + tls + "] [SASL: " + sasl + "]";
}
}
} catch (IOException | InvalidConfigurationException ex) {

View File

@ -41,6 +41,12 @@ autoconnect: 'false'
password: ''
# identify password (sent to NickServ)
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: '.'
# quit-message - Message the bot will send when it quits the server