2009-12-17 15:27:57 -05:00
|
|
|
/*
|
2010-03-12 14:35:25 -05:00
|
|
|
Yaaic - Yet Another Android IRC Client
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-13 10:52:20 -05:00
|
|
|
Copyright 2009-2010 Sebastian Kaspari
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
This file is part of Yaaic.
|
|
|
|
|
|
|
|
Yaaic 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.
|
|
|
|
|
|
|
|
Yaaic 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 Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.yaaic.irc;
|
|
|
|
|
2010-03-09 15:58:05 -05:00
|
|
|
import java.util.Vector;
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.content.Intent;
|
2010-03-02 12:42:44 -05:00
|
|
|
import android.util.Log;
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-06 15:05:23 -05:00
|
|
|
import org.jibble.pircbot.Colors;
|
2009-12-17 15:27:57 -05:00
|
|
|
import org.jibble.pircbot.PircBot;
|
2010-03-02 12:42:44 -05:00
|
|
|
import org.jibble.pircbot.User;
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-06 13:15:27 -05:00
|
|
|
import org.yaaic.R;
|
2009-12-17 15:27:57 -05:00
|
|
|
import org.yaaic.Yaaic;
|
|
|
|
import org.yaaic.model.Broadcast;
|
2010-03-02 13:40:05 -05:00
|
|
|
import org.yaaic.model.Channel;
|
2010-03-10 15:34:20 -05:00
|
|
|
import org.yaaic.model.Conversation;
|
2010-03-06 11:52:22 -05:00
|
|
|
import org.yaaic.model.Message;
|
2010-03-10 15:34:20 -05:00
|
|
|
import org.yaaic.model.Query;
|
2009-12-17 15:27:57 -05:00
|
|
|
import org.yaaic.model.Server;
|
2010-03-10 17:06:40 -05:00
|
|
|
import org.yaaic.model.ServerInfo;
|
2009-12-17 15:27:57 -05:00
|
|
|
import org.yaaic.model.Status;
|
|
|
|
|
2010-03-17 14:38:58 -04:00
|
|
|
/**
|
|
|
|
* The class that actually handles the connection to an IRC server
|
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
public class IRCConnection extends PircBot
|
|
|
|
{
|
2010-03-17 14:38:58 -04:00
|
|
|
public static final String TAG = "Yaaic/IRCConnection";
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
private IRCService service;
|
|
|
|
private Server server;
|
|
|
|
|
2010-03-02 12:42:44 -05:00
|
|
|
// XXX: Print all IRC events to the debug console
|
2010-03-17 14:38:58 -04:00
|
|
|
private static final boolean DEBUG_EVENTS = false;
|
2010-03-02 12:42:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new connection
|
|
|
|
*
|
|
|
|
* @param service
|
|
|
|
* @param serverId
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
public IRCConnection(IRCService service, int serverId)
|
|
|
|
{
|
|
|
|
this.server = Yaaic.getInstance().getServerById(serverId);
|
|
|
|
this.service = service;
|
|
|
|
|
2010-03-14 18:34:51 -04:00
|
|
|
// XXX: Should be configurable via settings
|
2009-12-17 15:27:57 -05:00
|
|
|
this.setAutoNickChange(true);
|
2010-03-14 18:34:51 -04:00
|
|
|
|
|
|
|
this.setFinger("http://www.youtube.com/watch?v=oHg5SJYRHA0");
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
2010-03-13 08:58:01 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the nickname of the user
|
|
|
|
*
|
|
|
|
* @param nickname The nickname to use
|
|
|
|
*/
|
|
|
|
public void setNickname(String nickname)
|
|
|
|
{
|
|
|
|
this.setName(nickname);
|
|
|
|
}
|
2010-03-13 09:17:32 -05:00
|
|
|
|
2010-03-13 15:16:32 -05:00
|
|
|
/**
|
|
|
|
* Set the real name of the user
|
|
|
|
*
|
|
|
|
* @param realname The realname to use
|
|
|
|
*/
|
2010-03-13 09:17:32 -05:00
|
|
|
public void setRealName(String realname)
|
|
|
|
{
|
|
|
|
// XXX: Pircbot uses the version for "real name" and "version".
|
|
|
|
// The real "version" value is provided by onVersion()
|
|
|
|
this.setVersion(realname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On version (CTCP version)
|
|
|
|
*
|
|
|
|
* This is a fix for pircbot as pircbot uses the version as "real name" and as "version"
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-13 15:16:32 -05:00
|
|
|
protected void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target)
|
|
|
|
{
|
2010-03-13 09:17:32 -05:00
|
|
|
this.sendRawLine(
|
|
|
|
"NOTICE " + sourceNick + " :\u0001VERSION " +
|
|
|
|
"Yaaic - Yet another Android IRC client - http://www.yaaic.org" +
|
|
|
|
"\u0001"
|
|
|
|
);
|
|
|
|
}
|
2010-03-13 08:58:01 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the ident of the user
|
|
|
|
*
|
|
|
|
* @param ident The ident to use
|
|
|
|
*/
|
|
|
|
public void setIdent(String ident)
|
|
|
|
{
|
|
|
|
this.setLogin(ident);
|
|
|
|
}
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On connect
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onConnect()
|
|
|
|
{
|
2010-03-02 13:40:05 -05:00
|
|
|
debug("Connect", "");
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
server.setStatus(Status.CONNECTED);
|
|
|
|
service.sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
2010-03-10 17:57:31 -05:00
|
|
|
|
|
|
|
Message message = new Message("Connected to " + server.getTitle());
|
|
|
|
message.setColor(Message.COLOR_GREEN);
|
|
|
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-10 17:57:31 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
2010-03-10 17:57:31 -05:00
|
|
|
service.sendBroadcast(intent);
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
|
|
|
|
2010-03-02 12:42:44 -05:00
|
|
|
/**
|
|
|
|
* On channel action
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onAction(String sender, String login, String hostname, String target, String action)
|
|
|
|
{
|
|
|
|
debug("Action", target + " " + sender + " " + action);
|
2010-03-10 15:40:49 -05:00
|
|
|
|
2010-03-06 15:05:23 -05:00
|
|
|
// Strip mIRC colors and formatting
|
|
|
|
action = Colors.removeFormattingAndColors(action);
|
2010-03-10 15:46:12 -05:00
|
|
|
|
|
|
|
Message message = new Message(sender + " " + action);
|
|
|
|
message.setIcon(R.drawable.action);
|
2010-03-06 15:05:23 -05:00
|
|
|
|
2010-03-10 15:40:49 -05:00
|
|
|
if (target.equals(this.getNick())) {
|
|
|
|
// We are the target - this is an action in a query
|
2010-03-10 15:46:12 -05:00
|
|
|
Conversation conversation = server.getConversation(sender);
|
|
|
|
if (conversation == null) {
|
|
|
|
// Open a query if there's none yet
|
|
|
|
conversation = new Query(sender);
|
|
|
|
server.addConversationl(conversation);
|
|
|
|
conversation.addMessage(message);
|
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_NEW);
|
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, sender);
|
2010-03-10 15:46:12 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
|
|
service.sendBroadcast(intent);
|
|
|
|
} else {
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-10 15:46:12 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, sender);
|
2010-03-10 15:46:12 -05:00
|
|
|
service.sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// A action in a channel
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-10 15:46:12 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-10 15:46:12 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-10 15:40:49 -05:00
|
|
|
}
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Channel Info
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onChannelInfo(String channel, int userCount, String topic)
|
|
|
|
{
|
|
|
|
debug("ChannelInfo", channel + " " + userCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Deop
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 14:31:54 -05:00
|
|
|
protected void onDeop(String target, String sourceNick, String sourceLogin, String sourceHostname, String recipient)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 14:31:54 -05:00
|
|
|
debug("Deop", target + " " + recipient + "(" + sourceNick + ")");
|
|
|
|
|
2010-03-14 10:44:21 -04:00
|
|
|
Message message = new Message(sourceNick + " deopped " + recipient);
|
2010-03-06 13:15:27 -05:00
|
|
|
message.setIcon(R.drawable.op);
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_BLUE);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:31:54 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:31:54 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On DeVoice
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 14:31:54 -05:00
|
|
|
protected void onDeVoice(String target, String sourceNick, String sourceLogin, String sourceHostname, String recipient)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 14:31:54 -05:00
|
|
|
debug("DeVoice", target + " " + recipient + "(" + sourceNick + ")");
|
|
|
|
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message(sourceNick + " devoiced " + recipient);
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_BLUE);
|
2010-03-06 13:15:27 -05:00
|
|
|
message.setIcon(R.drawable.voice);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:31:54 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:31:54 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Invite
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 14:31:54 -05:00
|
|
|
protected void onInvite(String targetNick, String sourceNick, String sourceLogin, String sourceHostname, String target)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 14:31:54 -05:00
|
|
|
debug("Invite", target + " " + targetNick + "(" + sourceNick + ")");
|
|
|
|
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message(sourceNick + " invited " + targetNick);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:31:54 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:31:54 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Join
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 13:43:27 -05:00
|
|
|
protected void onJoin(String target, String sender, String login, String hostname)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 13:43:27 -05:00
|
|
|
debug("Join", target + " " + sender);
|
2010-03-02 13:40:05 -05:00
|
|
|
|
|
|
|
if (sender.equals(getNick())) {
|
|
|
|
// We joined a new channel
|
2010-03-10 15:12:07 -05:00
|
|
|
server.addConversationl(new Channel(target));
|
2010-03-05 08:25:33 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_NEW);
|
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-05 08:25:33 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 13:43:27 -05:00
|
|
|
} else {
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message(sender + " joined");
|
2010-03-06 13:15:27 -05:00
|
|
|
message.setIcon(R.drawable.join);
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_GREEN);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:28:32 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:28:32 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 13:40:05 -05:00
|
|
|
}
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Kick
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 13:47:43 -05:00
|
|
|
protected void onKick(String target, String kickerNick, String kickerLogin, String kickerHostname, String recipientNick, String reason)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 13:47:43 -05:00
|
|
|
debug("Kick", target + " " + recipientNick + "(" + kickerNick + ")");
|
|
|
|
|
|
|
|
if (recipientNick.equals(getNick())) {
|
|
|
|
// We are kicked
|
2010-03-10 15:12:07 -05:00
|
|
|
server.removeConversation(target);
|
2010-03-05 08:25:33 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_REMOVE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-05 08:25:33 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 13:47:43 -05:00
|
|
|
} else {
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message(kickerNick + " kicked " + recipientNick);
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_GREEN);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:28:32 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:28:32 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 13:47:43 -05:00
|
|
|
}
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Message
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-06 11:52:22 -05:00
|
|
|
protected void onMessage(String target, String sender, String login, String hostname, String text)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-06 11:52:22 -05:00
|
|
|
debug("Message", target + " " + sender + " " + text);
|
2010-03-06 15:05:23 -05:00
|
|
|
|
|
|
|
// Strip mIRC colors and formatting
|
|
|
|
text = Colors.removeFormattingAndColors(text);
|
2010-03-02 13:48:12 -05:00
|
|
|
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message("<" + sender + "> " + text);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:28:32 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:28:32 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Mode
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 13:48:59 -05:00
|
|
|
protected void onMode(String target, String sourceNick, String sourceLogin, String sourceHostname, String mode)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 13:48:59 -05:00
|
|
|
debug("Mode", target + " " + sourceNick + " " + mode);
|
|
|
|
|
2010-03-06 13:19:19 -05:00
|
|
|
/*//Disabled as it doubles events (e.g. onOp and onMode will be called)
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message(sourceNick + " sets mode " + mode);
|
|
|
|
server.getChannel(target).addMessage(message);
|
2010-03-02 14:28:32 -05:00
|
|
|
|
|
|
|
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-02 14:28:32 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
|
|
|
|
service.sendBroadcast(intent);
|
2010-03-06 13:19:19 -05:00
|
|
|
*/
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Nick Change
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onNickChange(String oldNick, String login, String hostname, String newNick)
|
|
|
|
{
|
|
|
|
debug("Nick", oldNick + " " + newNick);
|
2010-03-06 11:52:22 -05:00
|
|
|
|
2010-03-09 15:58:05 -05:00
|
|
|
for (String target : getChannelsByNickname(newNick)) {
|
|
|
|
Message message = new Message(oldNick + " is now known as " + newNick);
|
|
|
|
message.setColor(Message.COLOR_GREEN);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-09 15:58:05 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-09 15:58:05 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-09 15:58:05 -05:00
|
|
|
service.sendBroadcast(intent);
|
|
|
|
}
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Notice
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onNotice(String sourceNick, String sourceLogin, String sourceHostname, String target, String notice)
|
|
|
|
{
|
|
|
|
debug("Notice", sourceNick + " " + notice);
|
2010-03-06 11:52:22 -05:00
|
|
|
|
2010-03-06 15:05:23 -05:00
|
|
|
// Strip mIRC colors and formatting
|
|
|
|
notice = Colors.removeFormattingAndColors(notice);
|
|
|
|
|
2010-03-10 17:06:40 -05:00
|
|
|
// Post notice to currently selected conversation
|
|
|
|
Conversation conversation = server.getConversation(server.getSelectedConversation());
|
|
|
|
|
|
|
|
if (conversation == null) {
|
|
|
|
// Fallback: Use ServerInfo view
|
|
|
|
conversation = server.getConversation(ServerInfo.DEFAULT_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
Message message = new Message("-" + sourceNick + "- " + notice);
|
|
|
|
message.setIcon(R.drawable.info);
|
|
|
|
conversation.addMessage(message);
|
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-10 17:06:40 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
2010-03-10 17:06:40 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Op
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 13:52:49 -05:00
|
|
|
protected void onOp(String target, String sourceNick, String sourceLogin, String sourceHostname, String recipient)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 13:52:49 -05:00
|
|
|
debug("Op", target + " " + recipient + "(" + sourceNick + ")");
|
|
|
|
|
2010-03-14 10:44:21 -04:00
|
|
|
Message message = new Message(sourceNick + " opped " + recipient);
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_BLUE);
|
2010-03-06 13:15:27 -05:00
|
|
|
message.setIcon(R.drawable.op);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:28:32 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:28:32 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Part
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 13:54:34 -05:00
|
|
|
protected void onPart(String target, String sender, String login, String hostname)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 13:54:34 -05:00
|
|
|
debug("Part", target + " " + sender);
|
|
|
|
|
|
|
|
if (sender.equals(getNick())) {
|
2010-03-10 19:10:21 -05:00
|
|
|
// We parted a channel
|
2010-03-10 15:12:07 -05:00
|
|
|
server.removeConversation(target);
|
2010-03-05 08:25:33 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_REMOVE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-05 08:25:33 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 13:54:34 -05:00
|
|
|
} else {
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message(sender + " parted");
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_GREEN);
|
2010-03-06 13:15:27 -05:00
|
|
|
message.setIcon(R.drawable.part);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:28:32 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:28:32 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 13:54:34 -05:00
|
|
|
}
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Private Message
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-10 15:34:20 -05:00
|
|
|
protected void onPrivateMessage(String sender, String login, String hostname, String text)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-10 15:34:20 -05:00
|
|
|
debug("PrivateMessage", sender + " " + text);
|
2010-03-06 13:15:27 -05:00
|
|
|
|
2010-03-06 15:05:23 -05:00
|
|
|
// Strip mIRC colors and formatting
|
2010-03-10 15:34:20 -05:00
|
|
|
text = Colors.removeFormattingAndColors(text);
|
2010-03-10 15:46:12 -05:00
|
|
|
|
|
|
|
Message message = new Message("<" + sender + "> " + text);
|
|
|
|
|
2010-03-10 15:34:20 -05:00
|
|
|
Conversation conversation = server.getConversation(sender);
|
|
|
|
|
|
|
|
if (conversation == null) {
|
|
|
|
// Open a query if there's none yet
|
|
|
|
conversation = new Query(sender);
|
|
|
|
conversation.addMessage(message);
|
2010-03-10 15:46:12 -05:00
|
|
|
server.addConversationl(conversation);
|
2010-03-10 15:34:20 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_NEW);
|
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, sender);
|
2010-03-10 15:34:20 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
|
|
service.sendBroadcast(intent);
|
|
|
|
} else {
|
|
|
|
conversation.addMessage(message);
|
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-10 15:34:20 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, sender);
|
2010-03-10 15:34:20 -05:00
|
|
|
service.sendBroadcast(intent);
|
|
|
|
}
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Quit
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onQuit(String sourceNick, String sourceLogin, String sourceHostname, String reason)
|
|
|
|
{
|
|
|
|
debug("Quit", sourceNick);
|
2010-03-08 13:55:32 -05:00
|
|
|
|
2010-03-09 16:42:12 -05:00
|
|
|
if (!sourceNick.equals(this.getNick())) {
|
|
|
|
for (String target : getChannelsByNickname(sourceNick)) {
|
2010-03-11 16:58:01 -05:00
|
|
|
Message message = new Message(sourceNick + " quitted (" + reason + ")");
|
2010-03-09 16:42:12 -05:00
|
|
|
message.setColor(Message.COLOR_GREEN);
|
|
|
|
message.setIcon(R.drawable.quit);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-09 16:42:12 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-09 16:42:12 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-09 16:42:12 -05:00
|
|
|
service.sendBroadcast(intent);
|
|
|
|
}
|
2010-03-13 19:06:06 -05:00
|
|
|
|
|
|
|
// Look if there's a query to update
|
|
|
|
Conversation conversation = server.getConversation(sourceNick);
|
|
|
|
|
|
|
|
if (conversation != null) {
|
|
|
|
Message message = new Message(sourceNick + " quitted (" + reason + ")");
|
|
|
|
message.setColor(Message.COLOR_GREEN);
|
|
|
|
message.setIcon(R.drawable.quit);
|
|
|
|
conversation.addMessage(message);
|
|
|
|
|
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
|
|
|
service.sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
|
2010-03-09 16:42:12 -05:00
|
|
|
} else {
|
|
|
|
// XXX: We quitted
|
|
|
|
}
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Topic
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-09 17:35:40 -05:00
|
|
|
public void onTopic(String target, String topic, String setBy, long date, boolean changed)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 13:59:37 -05:00
|
|
|
debug("Topic", target + " " + setBy + " " + topic);
|
|
|
|
|
|
|
|
if (changed) {
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message(setBy + " sets topic: " + topic);
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_YELLOW);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 13:59:37 -05:00
|
|
|
} else {
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message("Topic: " + topic);
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_YELLOW);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 13:59:37 -05:00
|
|
|
}
|
|
|
|
|
2010-03-09 17:35:40 -05:00
|
|
|
// remember channel's topic
|
2010-03-10 15:12:07 -05:00
|
|
|
((Channel) server.getConversation(target)).setTopic(topic);
|
2010-03-09 17:35:40 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:28:32 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On User List
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onUserList(String channel, User[] users)
|
|
|
|
{
|
|
|
|
debug("UserList", channel + " (" + users.length + ")");
|
2010-03-06 11:52:22 -05:00
|
|
|
|
|
|
|
// XXX: Store user list somewhere and keep it updated or just broadcast some event?
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On Voice
|
|
|
|
*/
|
|
|
|
@Override
|
2010-03-02 14:31:54 -05:00
|
|
|
protected void onVoice(String target, String sourceNick, String sourceLogin, String sourceHostname, String recipient)
|
2010-03-02 12:42:44 -05:00
|
|
|
{
|
2010-03-02 14:31:54 -05:00
|
|
|
debug("Voice", target + " " + recipient + "(" + sourceNick + ")");
|
|
|
|
|
2010-03-06 11:52:22 -05:00
|
|
|
Message message = new Message(sourceNick + " voiced " + recipient);
|
2010-03-06 13:15:27 -05:00
|
|
|
message.setIcon(R.drawable.voice);
|
2010-03-06 14:58:53 -05:00
|
|
|
message.setColor(Message.COLOR_BLUE);
|
2010-03-10 15:12:07 -05:00
|
|
|
server.getConversation(target).addMessage(message);
|
2010-03-02 14:31:54 -05:00
|
|
|
|
2010-03-10 18:25:53 -05:00
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
2010-03-05 13:47:19 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
2010-03-10 18:25:53 -05:00
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
2010-03-02 14:31:54 -05:00
|
|
|
service.sendBroadcast(intent);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
|
2010-03-14 17:22:51 -04:00
|
|
|
/**
|
|
|
|
* On remove channel key
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRemoveChannelKey(String target, String sourceNick, String sourceLogin, String sourceHostname, String key)
|
|
|
|
{
|
|
|
|
debug("onRemoveChannelKey", target + " " + sourceNick + " " + key);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " removes channel key");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On set channel key
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSetChannelKey(String target, String sourceNick, String sourceLogin, String sourceHostname, String key)
|
|
|
|
{
|
|
|
|
debug("onSetChannelKey", target + " " + sourceNick + " " + key);
|
|
|
|
|
2010-03-15 18:48:44 -04:00
|
|
|
Message message = new Message(sourceNick + " sets channel key: " + key);
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On set secret
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSetSecret(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onSetSecret", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " sets channel secret");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On remove secret
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRemoveSecret(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onRemoveSecret", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " sets channel public");
|
2010-03-14 17:22:51 -04:00
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
2010-03-15 18:52:32 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On set channel limit
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSetChannelLimit(String target, String sourceNick, String sourceLogin, String sourceHostname, int limit)
|
|
|
|
{
|
|
|
|
debug("onSetChannelLimit", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " sets limit: " + limit);
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On remove channel limit
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRemoveChannelLimit(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onRemoveChannelLimit", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " removes limit");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
2010-03-14 17:22:51 -04:00
|
|
|
|
2010-03-18 14:38:55 -04:00
|
|
|
/**
|
|
|
|
* On set channel ban
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSetChannelBan(String target, String sourceNick, String sourceLogin, String sourceHostname, String hostmask)
|
|
|
|
{
|
|
|
|
debug("onSetChannelBan", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " sets ban: " + hostmask);
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On remove channel ban
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRemoveChannelBan(String target, String sourceNick, String sourceLogin, String sourceHostname, String hostmask)
|
|
|
|
{
|
|
|
|
debug("onRemoveChannelBan", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " removes ban: " + hostmask);
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
2010-03-18 14:41:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On set topic protection
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSetTopicProtection(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onSetTopicProtection", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " sets topic protection");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On remove topic protection
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRemoveTopicProtection(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onRemoveTopicProtection", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " removes topic protection");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
2010-03-18 14:38:55 -04:00
|
|
|
|
2010-03-18 14:43:54 -04:00
|
|
|
/**
|
|
|
|
* On set no external messages
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSetNoExternalMessages(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onSetNoExternalMessages", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " disables external messages");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On remove no external messages
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRemoveNoExternalMessages(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onRemoveNoExternalMessages", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " enables external messages");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
2010-03-18 14:46:09 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On set invite only
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSetInviteOnly(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onSetInviteOnly", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " sets invite only");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On remove invite only
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRemoveInviteOnly(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onRemoveInviteOnly", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " removes invite only");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
2010-03-18 14:43:54 -04:00
|
|
|
|
2010-03-18 14:48:11 -04:00
|
|
|
/**
|
|
|
|
* On set moderated
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSetModerated(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onSetModerated", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " sets moderated");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On remove moderated
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRemoveModerated(String target, String sourceNick, String sourceLogin, String sourceHostname)
|
|
|
|
{
|
|
|
|
debug("onRemoveModerated", sourceNick + " " + target);
|
|
|
|
|
|
|
|
Message message = new Message(sourceNick + " removes moderated");
|
|
|
|
message.setColor(Message.COLOR_BLUE);
|
|
|
|
server.getConversation(target).addMessage(message);
|
|
|
|
|
|
|
|
service.sendBroadcast(
|
|
|
|
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), target)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-03-13 15:16:32 -05:00
|
|
|
/**
|
|
|
|
* On unknown
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onUnknown(String line)
|
|
|
|
{
|
2010-03-13 15:55:21 -05:00
|
|
|
debug("Unknown", line);
|
|
|
|
|
2010-03-13 15:16:32 -05:00
|
|
|
Message message = new Message(line);
|
|
|
|
message.setIcon(R.drawable.action);
|
|
|
|
message.setColor(Message.COLOR_GREY);
|
|
|
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
|
|
|
|
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
|
|
|
service.sendBroadcast(intent);
|
2010-03-13 15:55:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On server response
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onServerResponse(int code, String response)
|
|
|
|
{
|
|
|
|
debug("ServerResponse", code + " " + response);
|
2010-03-17 18:50:31 -04:00
|
|
|
|
2010-03-13 15:55:21 -05:00
|
|
|
/*
|
|
|
|
// Currently disabled... to much text
|
|
|
|
Message message = new Message(response);
|
|
|
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
|
|
|
|
|
|
|
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
|
|
|
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
|
|
intent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
|
|
|
service.sendBroadcast(intent);
|
|
|
|
*/
|
2010-03-13 15:16:32 -05:00
|
|
|
}
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
/**
|
|
|
|
* On disconnect
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onDisconnect()
|
|
|
|
{
|
|
|
|
server.setStatus(Status.DISCONNECTED);
|
2010-03-14 07:42:29 -04:00
|
|
|
Intent sIntent = new Intent(Broadcast.SERVER_UPDATE);
|
|
|
|
sIntent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
|
|
service.sendBroadcast(sIntent);
|
|
|
|
|
|
|
|
Message message = new Message("Disconnected");
|
|
|
|
message.setIcon(R.drawable.error);
|
|
|
|
message.setColor(Message.COLOR_RED);
|
|
|
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
|
|
|
|
|
|
|
Intent cIntent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
|
|
|
cIntent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
|
|
cIntent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
|
|
|
service.sendBroadcast(cIntent);
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
|
|
|
|
2010-03-02 12:42:44 -05:00
|
|
|
/**
|
|
|
|
* Print an event to the debug console
|
|
|
|
*/
|
|
|
|
private void debug(String event, String params)
|
|
|
|
{
|
|
|
|
if (DEBUG_EVENTS) {
|
2010-03-02 13:40:05 -05:00
|
|
|
Log.d(TAG, "(" + server.getTitle() + ") [" + event + "]: " + params);
|
2010-03-02 12:42:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-09 15:58:05 -05:00
|
|
|
/**
|
|
|
|
* Get all channels where the user with the given nickname is online
|
|
|
|
*
|
|
|
|
* @param nickname
|
|
|
|
* @return Array of channel names
|
|
|
|
*/
|
|
|
|
private Vector<String> getChannelsByNickname(String nickname)
|
|
|
|
{
|
|
|
|
Vector<String> channels = new Vector<String>();
|
|
|
|
|
|
|
|
for (String channel : this.getChannels()) {
|
|
|
|
for (User user : this.getUsers(channel)) {
|
|
|
|
if (user.getNick().equals(nickname)) {
|
|
|
|
channels.add(channel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.d(TAG, "Found " + channels.size() + " channels for nickname " + nickname);
|
|
|
|
|
|
|
|
return channels;
|
|
|
|
}
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
/**
|
|
|
|
* Quits from the IRC server with default reason.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void quitServer()
|
|
|
|
{
|
|
|
|
quitServer("Yaaic - Yet another Android IRC client - http://www.yaaic.org");
|
|
|
|
}
|
|
|
|
}
|