Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Actually listen for bot link commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Jun 24, 2015
1 parent f61a591 commit 33e6a07
Showing 1 changed file with 81 additions and 4 deletions.
Expand Up @@ -18,6 +18,9 @@

import com.cnaude.purpleirc.PurpleBot;
import com.cnaude.purpleirc.PurpleIRC;
import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap;
import java.util.ArrayList;
import org.apache.commons.codec.binary.Base64;
import org.pircbotx.Channel;
import org.pircbotx.User;
import org.pircbotx.hooks.ListenerAdapter;
Expand Down Expand Up @@ -49,14 +52,88 @@ public NoticeListener(PurpleIRC plugin, PurpleBot ircBot) {
@Override
public void onNotice(NoticeEvent event) {
Channel channel = event.getChannel();
String message = event.getMessage();
String message = event.getMessage().trim();
String notice = event.getNotice();
User user = event.getUser();
String nick = user.getNick();

plugin.logInfo("-" + user.getNick() + "-" + message);
if (message.contains("You are connected using SSL cipher ")) {
ircBot.sslInfo = message.split(" SSL cipher ")[1];
if (message.startsWith(PurpleIRC.LINK_CMD) && ircBot.botLinkingEnabled) {
String encodedText = message.replace(PurpleIRC.LINK_CMD, "");
String decodedText = new String(Base64.decodeBase64(encodedText.getBytes()));
String splitMsg[] = decodedText.split(":");

plugin.logDebug("REMOTE LINK COMMAND: " + encodedText + "(" + decodedText + ")");

if (splitMsg.length >= 2) {
String command = splitMsg[0];
String code = splitMsg[1];

if (command.equals("LINK_REQUEST")) {
ircBot.linkRequests.put(user.getNick(), code);
plugin.logInfo("PurpleIRC bot link request from " + user.getNick());
plugin.logInfo("To accept: /irc linkaccept "
+ ircBot.getFileName().replace(".yml", "") + " " + user.getNick());
return;
}

plugin.logDebug("Are we linked to " + user.getNick() + "?");
if (ircBot.botLinks.containsKey(nick)) {
plugin.logDebug("Yes we are linked. Is the code correct?");
if (ircBot.botLinks.get(nick).equals(code)) {
plugin.logDebug("Yes the code is correct!");
plugin.logDebug(" [COMMAND: " + command + "]");
plugin.logDebug(" [CODE: " + code + "]");

if (command.equals("PRIVATE_MSG") && splitMsg.length >= 5) {
String from = splitMsg[2];
String target = splitMsg[3];
String sMessage = decodedText.split(":", 5)[4];

plugin.logDebug(" [FROM:" + from + "]");
plugin.logDebug(" [TO:" + target + "]");
plugin.logDebug(" [MSG: " + sMessage + "]");
ircBot.playerCrossChat(user, from, target, sMessage);
} else if (command.equals("PLAYER_INFO") && splitMsg.length >= 4) {
String curCount = splitMsg[2];
String maxCount = splitMsg[3];
String players = "";
if (splitMsg.length == 5) {
players = splitMsg[4];
}
plugin.logDebug(" [CUR_COUNT:" + curCount + "]");
plugin.logDebug(" [MAX_COUNT:" + maxCount + "]");
plugin.logDebug(" [PLAYERS:" + players + "]");
if (!ircBot.remoteServerInfo.containsKey(nick)) {
ircBot.remoteServerInfo.put(nick, new CaseInsensitiveMap<String>());
}
if (ircBot.remoteServerInfo.containsKey(nick)) {
ircBot.remoteServerInfo.get(nick).put("CUR_COUNT", curCount);
ircBot.remoteServerInfo.get(nick).put("MAX_COUNT", maxCount);
}
if (!ircBot.remotePlayers.containsKey(nick)) {
ircBot.remotePlayers.put(nick, new ArrayList<String>());
}
if (ircBot.remotePlayers.containsKey(nick)) {
ircBot.remotePlayers.get(nick).clear();
if (!players.isEmpty()) {
for (String s : players.split(",")) {
plugin.logDebug(" [ADDING:" + s + "]");
ircBot.remotePlayers.get(nick).add(s);
}
}
}
}
} else {
plugin.logDebug("Invalid code from " + nick + "!");
}
} else {
plugin.logDebug("We are not linked to " + nick + "!");
}
}
return;
}

plugin.logInfo("-" + user.getNick() + "-" + message);
if (channel != null) {
if (ircBot.isValidChannel(channel.getName())) {
ircBot.broadcastIRCNotice(user, message, notice, channel);
Expand Down

0 comments on commit 33e6a07

Please sign in to comment.