|
|
|
@ -39,12 +39,12 @@ public class IrcStack
|
|
|
|
private static final long CHAT_ROOM_LIST_CACHE_EXPIRATION = 60000000000L;
|
|
|
|
private static final long CHAT_ROOM_LIST_CACHE_EXPIRATION = 60000000000L;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Logger
|
|
|
|
* Logger.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(IrcStack.class);
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(IrcStack.class);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Parent provider for IRC
|
|
|
|
* Parent provider for IRC.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private final ProtocolProviderServiceIrcImpl provider;
|
|
|
|
private final ProtocolProviderServiceIrcImpl provider;
|
|
|
|
|
|
|
|
|
|
|
|
@ -98,7 +98,7 @@ public class IrcStack
|
|
|
|
new Container<List<String>>(null);
|
|
|
|
new Container<List<String>>(null);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param parentProvider Parent provider
|
|
|
|
* @param parentProvider Parent provider
|
|
|
|
* @param nick User's nick name
|
|
|
|
* @param nick User's nick name
|
|
|
|
@ -145,16 +145,21 @@ public boolean isSecureConnection()
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param host IRC server's host name
|
|
|
|
* @param host IRC server's host name
|
|
|
|
* @param port IRC port
|
|
|
|
* @param port IRC port
|
|
|
|
* @param password
|
|
|
|
* @param password password for the specified nick name
|
|
|
|
* @param autoNickChange
|
|
|
|
* @param secureConnection true to set up secure connection, or false if
|
|
|
|
* @throws Exception
|
|
|
|
* not.
|
|
|
|
|
|
|
|
* @param autoNickChange do automatic nick changes if nick is in use
|
|
|
|
|
|
|
|
* @throws Exception throws exceptions
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void connect(String host, int port, String password,
|
|
|
|
public void connect(final String host, final int port,
|
|
|
|
boolean secureConnection, boolean autoNickChange) throws Exception
|
|
|
|
final String password, final boolean secureConnection,
|
|
|
|
|
|
|
|
final boolean autoNickChange) throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.session.get() != null && this.connectionState != null
|
|
|
|
if (this.session.get() != null && this.connectionState != null
|
|
|
|
&& this.connectionState.isConnected())
|
|
|
|
&& this.connectionState.isConnected())
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure we start with an empty joined-channel list.
|
|
|
|
// Make sure we start with an empty joined-channel list.
|
|
|
|
this.joined.clear();
|
|
|
|
this.joined.clear();
|
|
|
|
@ -186,7 +191,7 @@ public void connect(String host, int port, String password,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onMessage(IMessage aMessage)
|
|
|
|
public void onMessage(final IMessage aMessage)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOGGER.trace("(" + aMessage + ") " + aMessage.asRaw());
|
|
|
|
LOGGER.trace("(" + aMessage + ") " + aMessage.asRaw());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -204,7 +209,6 @@ public void onMessage(IMessage aMessage)
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Perform synchronized connect operation.
|
|
|
|
* Perform synchronized connect operation.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return returns true upon successful connection, false otherwise
|
|
|
|
|
|
|
|
* @throws Exception exception thrown when connect fails
|
|
|
|
* @throws Exception exception thrown when connect fails
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void connectSynchronized() throws Exception
|
|
|
|
private void connectSynchronized() throws Exception
|
|
|
|
@ -226,7 +230,7 @@ private void connectSynchronized() throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onSuccess(IIRCState state)
|
|
|
|
public void onSuccess(final IIRCState state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
synchronized (result)
|
|
|
|
synchronized (result)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -237,7 +241,7 @@ public void onSuccess(IIRCState state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onFailure(Exception e)
|
|
|
|
public void onFailure(final Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
synchronized (result)
|
|
|
|
synchronized (result)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -277,7 +281,9 @@ public void onFailure(Exception e)
|
|
|
|
RegistrationState.CONNECTION_FAILED);
|
|
|
|
RegistrationState.CONNECTION_FAILED);
|
|
|
|
Exception e = result.getException();
|
|
|
|
Exception e = result.getException();
|
|
|
|
if (e != null)
|
|
|
|
if (e != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
throw e;
|
|
|
|
throw e;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
catch (IOException e)
|
|
|
|
@ -301,10 +307,13 @@ public void onFailure(Exception e)
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a custom SSL context for this particular server.
|
|
|
|
* Create a custom SSL context for this particular server.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param hostname host name of the host we are connecting to such that we
|
|
|
|
|
|
|
|
* can verify that the same host name is on the server
|
|
|
|
|
|
|
|
* certificate
|
|
|
|
* @return returns a customized SSL context or <tt>null</tt> if one cannot
|
|
|
|
* @return returns a customized SSL context or <tt>null</tt> if one cannot
|
|
|
|
* be created.
|
|
|
|
* be created.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private SSLContext getCustomSSLContext(String hostname)
|
|
|
|
private SSLContext getCustomSSLContext(final String hostname)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SSLContext context = null;
|
|
|
|
SSLContext context = null;
|
|
|
|
try
|
|
|
|
try
|
|
|
|
@ -323,12 +332,14 @@ private SSLContext getCustomSSLContext(String hostname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Disconnect from the IRC server
|
|
|
|
* Disconnect from the IRC server.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void disconnect()
|
|
|
|
public void disconnect()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.connectionState == null && this.session.get() == null)
|
|
|
|
if (this.connectionState == null && this.session.get() == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
synchronized (this.joined)
|
|
|
|
synchronized (this.joined)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -365,7 +376,7 @@ public void disconnect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Dispose
|
|
|
|
* Dispose.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void dispose()
|
|
|
|
public void dispose()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -380,7 +391,9 @@ public void dispose()
|
|
|
|
public Set<Character> getChannelTypes()
|
|
|
|
public Set<Character> getChannelTypes()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
if (!isConnected())
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalStateException("not connected to IRC server");
|
|
|
|
throw new IllegalStateException("not connected to IRC server");
|
|
|
|
|
|
|
|
}
|
|
|
|
return this.connectionState.getServerOptions().getChanTypes();
|
|
|
|
return this.connectionState.getServerOptions().getChanTypes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -392,8 +405,14 @@ public Set<Character> getChannelTypes()
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public String getNick()
|
|
|
|
public String getNick()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (this.connectionState == null) ? this.params.getNickname()
|
|
|
|
if (this.connectionState == null)
|
|
|
|
: this.connectionState.getNickname();
|
|
|
|
{
|
|
|
|
|
|
|
|
return this.params.getNickname();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return this.connectionState.getNickname();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -401,7 +420,7 @@ public String getNick()
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param nick the new nick name
|
|
|
|
* @param nick the new nick name
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setUserNickname(String nick)
|
|
|
|
public void setUserNickname(final String nick)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOGGER.trace("Setting user's nick name to " + nick);
|
|
|
|
LOGGER.trace("Setting user's nick name to " + nick);
|
|
|
|
if (isConnected())
|
|
|
|
if (isConnected())
|
|
|
|
@ -421,13 +440,17 @@ public void setUserNickname(String nick)
|
|
|
|
* @param chatroom The chat room for which to set the subject.
|
|
|
|
* @param chatroom The chat room for which to set the subject.
|
|
|
|
* @param subject The subject.
|
|
|
|
* @param subject The subject.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setSubject(ChatRoomIrcImpl chatroom, String subject)
|
|
|
|
public void setSubject(final ChatRoomIrcImpl chatroom, final String subject)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
if (!isConnected())
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalStateException(
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Please connect to an IRC server first.");
|
|
|
|
"Please connect to an IRC server first.");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (chatroom == null)
|
|
|
|
if (chatroom == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("Cannot have a null chatroom");
|
|
|
|
throw new IllegalArgumentException("Cannot have a null chatroom");
|
|
|
|
|
|
|
|
}
|
|
|
|
LOGGER.trace("Setting chat room topic to '" + subject + "'");
|
|
|
|
LOGGER.trace("Setting chat room topic to '" + subject + "'");
|
|
|
|
this.session.get().changeTopic(chatroom.getIdentifier(),
|
|
|
|
this.session.get().changeTopic(chatroom.getIdentifier(),
|
|
|
|
subject == null ? "" : subject);
|
|
|
|
subject == null ? "" : subject);
|
|
|
|
@ -440,7 +463,7 @@ public void setSubject(ChatRoomIrcImpl chatroom, String subject)
|
|
|
|
* @return Returns true in case the user is already joined, or false if the
|
|
|
|
* @return Returns true in case the user is already joined, or false if the
|
|
|
|
* user has not joined.
|
|
|
|
* user has not joined.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public boolean isJoined(ChatRoomIrcImpl chatroom)
|
|
|
|
public boolean isJoined(final ChatRoomIrcImpl chatroom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return this.joined.get(chatroom.getIdentifier()) != null;
|
|
|
|
return this.joined.get(chatroom.getIdentifier()) != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -510,7 +533,8 @@ public List<String> getServerChatRoomList()
|
|
|
|
* @param chatroom Chat room to join.
|
|
|
|
* @param chatroom Chat room to join.
|
|
|
|
* @throws OperationFailedException failed to join the chat room
|
|
|
|
* @throws OperationFailedException failed to join the chat room
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void join(ChatRoomIrcImpl chatroom) throws OperationFailedException
|
|
|
|
public void join(final ChatRoomIrcImpl chatroom)
|
|
|
|
|
|
|
|
throws OperationFailedException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
join(chatroom, "");
|
|
|
|
join(chatroom, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -530,14 +554,20 @@ public void join(final ChatRoomIrcImpl chatroom, final String password)
|
|
|
|
throws OperationFailedException
|
|
|
|
throws OperationFailedException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
if (!isConnected())
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalStateException(
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Please connect to an IRC server first");
|
|
|
|
"Please connect to an IRC server first");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (chatroom == null || chatroom.getIdentifier() == null
|
|
|
|
if (chatroom == null || chatroom.getIdentifier() == null
|
|
|
|
|| chatroom.getIdentifier().isEmpty())
|
|
|
|
|| chatroom.getIdentifier().isEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"chatroom cannot be null or emtpy");
|
|
|
|
"chatroom cannot be null or emtpy");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (password == null)
|
|
|
|
if (password == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("password cannot be null");
|
|
|
|
throw new IllegalArgumentException("password cannot be null");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get instance of irc client api.
|
|
|
|
// Get instance of irc client api.
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
@ -579,7 +609,7 @@ public void join(final ChatRoomIrcImpl chatroom, final String password)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onSuccess(IRCChannel channel)
|
|
|
|
public void onSuccess(final IRCChannel channel)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (LOGGER.isTraceEnabled())
|
|
|
|
if (LOGGER.isTraceEnabled())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -661,7 +691,7 @@ public void onSuccess(IRCChannel channel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onFailure(Exception e)
|
|
|
|
public void onFailure(final Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOGGER.trace("Started callback for failed attempt to "
|
|
|
|
LOGGER.trace("Started callback for failed attempt to "
|
|
|
|
+ "join channel '" + chatRoomId + "'.");
|
|
|
|
+ "join channel '" + chatRoomId + "'.");
|
|
|
|
@ -722,7 +752,7 @@ public void onFailure(Exception e)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param chatroom The chat room to part from.
|
|
|
|
* @param chatroom The chat room to part from.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void leave(ChatRoomIrcImpl chatroom)
|
|
|
|
public void leave(final ChatRoomIrcImpl chatroom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOGGER.trace("Leaving chat room '" + chatroom.getIdentifier() + "'.");
|
|
|
|
LOGGER.trace("Leaving chat room '" + chatroom.getIdentifier() + "'.");
|
|
|
|
|
|
|
|
|
|
|
|
@ -736,10 +766,12 @@ public void leave(ChatRoomIrcImpl chatroom)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param chatRoomName The chat room to part from.
|
|
|
|
* @param chatRoomName The chat room to part from.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void leave(String chatRoomName)
|
|
|
|
private void leave(final String chatRoomName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
if (!isConnected())
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
try
|
|
|
|
try
|
|
|
|
@ -758,10 +790,12 @@ private void leave(String chatRoomName)
|
|
|
|
* @param chatroom chat room to ban from
|
|
|
|
* @param chatroom chat room to ban from
|
|
|
|
* @param member member to ban
|
|
|
|
* @param member member to ban
|
|
|
|
* @param reason reason for banning
|
|
|
|
* @param reason reason for banning
|
|
|
|
* @throws OperationFailedException
|
|
|
|
* @throws OperationFailedException throws operation failed in case of
|
|
|
|
|
|
|
|
* trouble.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void banParticipant(ChatRoomIrcImpl chatroom, ChatRoomMember member,
|
|
|
|
public void banParticipant(final ChatRoomIrcImpl chatroom,
|
|
|
|
String reason) throws OperationFailedException
|
|
|
|
final ChatRoomMember member, final String reason)
|
|
|
|
|
|
|
|
throws OperationFailedException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO Implement banParticipant.
|
|
|
|
// TODO Implement banParticipant.
|
|
|
|
throw new OperationFailedException("Not implemented yet.",
|
|
|
|
throw new OperationFailedException("Not implemented yet.",
|
|
|
|
@ -775,11 +809,13 @@ public void banParticipant(ChatRoomIrcImpl chatroom, ChatRoomMember member,
|
|
|
|
* @param member member to kick
|
|
|
|
* @param member member to kick
|
|
|
|
* @param reason kick message to deliver
|
|
|
|
* @param reason kick message to deliver
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void kickParticipant(ChatRoomIrcImpl chatroom,
|
|
|
|
public void kickParticipant(final ChatRoomIrcImpl chatroom,
|
|
|
|
ChatRoomMember member, String reason)
|
|
|
|
final ChatRoomMember member, final String reason)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
if (!isConnected())
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
irc.kick(chatroom.getIdentifier(), member.getContactAddress(), reason);
|
|
|
|
irc.kick(chatroom.getIdentifier(), member.getContactAddress(), reason);
|
|
|
|
@ -791,10 +827,12 @@ public void kickParticipant(ChatRoomIrcImpl chatroom,
|
|
|
|
* @param memberId member to invite
|
|
|
|
* @param memberId member to invite
|
|
|
|
* @param chatroom channel to invite to
|
|
|
|
* @param chatroom channel to invite to
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void invite(String memberId, ChatRoomIrcImpl chatroom)
|
|
|
|
public void invite(final String memberId, final ChatRoomIrcImpl chatroom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
if (!isConnected())
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
irc.rawMessage("INVITE " + memberId + " " + chatroom.getIdentifier());
|
|
|
|
irc.rawMessage("INVITE " + memberId + " " + chatroom.getIdentifier());
|
|
|
|
@ -804,7 +842,7 @@ public void invite(String memberId, ChatRoomIrcImpl chatroom)
|
|
|
|
* Send a command to the IRC server.
|
|
|
|
* Send a command to the IRC server.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param chatroom the chat room
|
|
|
|
* @param chatroom the chat room
|
|
|
|
* @param command the command message
|
|
|
|
* @param message the command message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void command(final ChatRoomIrcImpl chatroom, final String message)
|
|
|
|
public void command(final ChatRoomIrcImpl chatroom, final String message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -814,8 +852,8 @@ public void command(final ChatRoomIrcImpl chatroom, final String message)
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Send a command to the IRC server.
|
|
|
|
* Send a command to the IRC server.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param chatroom the chat room
|
|
|
|
* @param contact the chat room
|
|
|
|
* @param command the command message
|
|
|
|
* @param message the command message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void command(final Contact contact, final String message)
|
|
|
|
public void command(final Contact contact, final String message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -861,7 +899,7 @@ private void command(final String source, final String message)
|
|
|
|
* @param chatroom The chat room to send the message to.
|
|
|
|
* @param chatroom The chat room to send the message to.
|
|
|
|
* @param message The message to send.
|
|
|
|
* @param message The message to send.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void message(ChatRoomIrcImpl chatroom, String message)
|
|
|
|
public void message(final ChatRoomIrcImpl chatroom, final String message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
final IRCApi irc = this.session.get();
|
|
|
|
String target = chatroom.getIdentifier();
|
|
|
|
String target = chatroom.getIdentifier();
|
|
|
|
@ -901,7 +939,8 @@ public void message(final Contact contact, final Message message)
|
|
|
|
* @param userAddress user to grant permissions to
|
|
|
|
* @param userAddress user to grant permissions to
|
|
|
|
* @param mode mode to grant
|
|
|
|
* @param mode mode to grant
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void grant(ChatRoomIrcImpl chatRoom, String userAddress, Mode mode)
|
|
|
|
public void grant(final ChatRoomIrcImpl chatRoom, final String userAddress,
|
|
|
|
|
|
|
|
final Mode mode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mode.getRole() == null)
|
|
|
|
if (mode.getRole() == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -920,7 +959,8 @@ public void grant(ChatRoomIrcImpl chatRoom, String userAddress, Mode mode)
|
|
|
|
* @param userAddress user
|
|
|
|
* @param userAddress user
|
|
|
|
* @param mode mode
|
|
|
|
* @param mode mode
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void revoke(ChatRoomIrcImpl chatRoom, String userAddress, Mode mode)
|
|
|
|
public void revoke(final ChatRoomIrcImpl chatRoom,
|
|
|
|
|
|
|
|
final String userAddress, final Mode mode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mode.getRole() == null)
|
|
|
|
if (mode.getRole() == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -978,7 +1018,7 @@ private void prepareChatRoom(final ChatRoomIrcImpl chatRoom,
|
|
|
|
* @return Return the instance of ChatRoomMemberRole corresponding to the
|
|
|
|
* @return Return the instance of ChatRoomMemberRole corresponding to the
|
|
|
|
* member mode character.
|
|
|
|
* member mode character.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static ChatRoomMemberRole convertMemberMode(char modeSymbol)
|
|
|
|
private static ChatRoomMemberRole convertMemberMode(final char modeSymbol)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Mode.bySymbol(modeSymbol).getRole();
|
|
|
|
return Mode.bySymbol(modeSymbol).getRole();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -998,7 +1038,7 @@ private class ServerListener
|
|
|
|
* @param msg the server notice
|
|
|
|
* @param msg the server notice
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onServerNotice(ServerNotice msg)
|
|
|
|
public void onServerNotice(final ServerNotice msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOGGER.debug("NOTICE: " + msg.getText());
|
|
|
|
LOGGER.debug("NOTICE: " + msg.getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1010,7 +1050,7 @@ public void onServerNotice(ServerNotice msg)
|
|
|
|
* @param msg the numeric message
|
|
|
|
* @param msg the numeric message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onServerNumericMessage(ServerNumericMessage msg)
|
|
|
|
public void onServerNumericMessage(final ServerNumericMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (LOGGER.isDebugEnabled())
|
|
|
|
if (LOGGER.isDebugEnabled())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1110,7 +1150,7 @@ public void onServerNumericMessage(ServerNumericMessage msg)
|
|
|
|
* @param msg the error message
|
|
|
|
* @param msg the error message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onError(ErrorMessage msg)
|
|
|
|
public void onError(final ErrorMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (LOGGER.isDebugEnabled())
|
|
|
|
if (LOGGER.isDebugEnabled())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1162,8 +1202,8 @@ public void onUserPrivMessage(final UserPrivMsg msg)
|
|
|
|
// MetaContactGroup for NonPersistent group, since this is an
|
|
|
|
// MetaContactGroup for NonPersistent group, since this is an
|
|
|
|
// outstanding error.
|
|
|
|
// outstanding error.
|
|
|
|
LOGGER.error(
|
|
|
|
LOGGER.error(
|
|
|
|
"Error occurred while delivering private message from user '"
|
|
|
|
"Error occurred while delivering private message from user"
|
|
|
|
+ user + "': " + text, e);
|
|
|
|
+ " '" + user + "': " + text, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -1174,8 +1214,13 @@ public void onUserPrivMessage(final UserPrivMsg msg)
|
|
|
|
* @param msg user notice message
|
|
|
|
* @param msg user notice message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onUserNotice(UserNotice msg)
|
|
|
|
public void onUserNotice(final UserNotice msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
// TODO Probably better to deliver NOTICEs to all channels, instead
|
|
|
|
|
|
|
|
// of setting up private chat. You are not supposed to reply to
|
|
|
|
|
|
|
|
// NOTICEs and setting up a private chat session kind of does that.
|
|
|
|
|
|
|
|
// Even though the user should respond themslves in the default
|
|
|
|
|
|
|
|
// Jitsi set up.
|
|
|
|
final String user = msg.getSource().getNick();
|
|
|
|
final String user = msg.getSource().getNick();
|
|
|
|
final String text =
|
|
|
|
final String text =
|
|
|
|
Utils.formatNotice(Utils.parse(msg.getText()), user);
|
|
|
|
Utils.formatNotice(Utils.parse(msg.getText()), user);
|
|
|
|
@ -1198,7 +1243,7 @@ public void onUserNotice(UserNotice msg)
|
|
|
|
* @param msg user action message
|
|
|
|
* @param msg user action message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onUserAction(UserActionMsg msg)
|
|
|
|
public void onUserAction(final UserActionMsg msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
final String user = msg.getSource().getNick();
|
|
|
|
final String user = msg.getSource().getNick();
|
|
|
|
final String text =
|
|
|
|
final String text =
|
|
|
|
@ -1284,7 +1329,7 @@ public void onUserQuit(QuitMessage msg)
|
|
|
|
* @author Danny van Heumen
|
|
|
|
* @author Danny van Heumen
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private class ChatRoomListener
|
|
|
|
private final class ChatRoomListener
|
|
|
|
extends VariousMessageListenerAdapter
|
|
|
|
extends VariousMessageListenerAdapter
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -1300,12 +1345,14 @@ private class ChatRoomListener
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Constructor. Instantiate listener for the provided chat room.
|
|
|
|
* Constructor. Instantiate listener for the provided chat room.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param chatroom
|
|
|
|
* @param chatroom the chat room
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ChatRoomListener(ChatRoomIrcImpl chatroom)
|
|
|
|
private ChatRoomListener(final ChatRoomIrcImpl chatroom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (chatroom == null)
|
|
|
|
if (chatroom == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("chatroom cannot be null");
|
|
|
|
throw new IllegalArgumentException("chatroom cannot be null");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.chatroom = chatroom;
|
|
|
|
this.chatroom = chatroom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1316,10 +1363,12 @@ private ChatRoomListener(ChatRoomIrcImpl chatroom)
|
|
|
|
* @param msg topic change message
|
|
|
|
* @param msg topic change message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onTopicChange(TopicMessage msg)
|
|
|
|
public void onTopicChange(final TopicMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.chatroom.updateSubject(msg.getTopic().getValue());
|
|
|
|
this.chatroom.updateSubject(msg.getTopic().getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1330,10 +1379,12 @@ public void onTopicChange(TopicMessage msg)
|
|
|
|
* @param msg channel mode message
|
|
|
|
* @param msg channel mode message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChannelMode(ChannelModeMessage msg)
|
|
|
|
public void onChannelMode(final ChannelModeMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
processModeMessage(msg);
|
|
|
|
processModeMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1344,10 +1395,12 @@ public void onChannelMode(ChannelModeMessage msg)
|
|
|
|
* @param msg channel join message
|
|
|
|
* @param msg channel join message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChannelJoin(ChanJoinMessage msg)
|
|
|
|
public void onChannelJoin(final ChanJoinMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String user = msg.getSource().getNick();
|
|
|
|
String user = msg.getSource().getNick();
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
@ -1363,10 +1416,12 @@ public void onChannelJoin(ChanJoinMessage msg)
|
|
|
|
* @param msg channel part message
|
|
|
|
* @param msg channel part message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChannelPart(ChanPartMessage msg)
|
|
|
|
public void onChannelPart(final ChanPartMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IRCUser user = msg.getSource();
|
|
|
|
IRCUser user = msg.getSource();
|
|
|
|
if (isMe(user))
|
|
|
|
if (isMe(user))
|
|
|
|
@ -1399,7 +1454,7 @@ public void onChannelPart(ChanPartMessage msg)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param msg IRC server numeric message
|
|
|
|
* @param msg IRC server numeric message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void onServerNumericMessage(ServerNumericMessage msg)
|
|
|
|
public void onServerNumericMessage(final ServerNumericMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Integer code = msg.getNumericCode();
|
|
|
|
Integer code = msg.getNumericCode();
|
|
|
|
if (code == null)
|
|
|
|
if (code == null)
|
|
|
|
@ -1432,10 +1487,12 @@ public void onServerNumericMessage(ServerNumericMessage msg)
|
|
|
|
* @param msg channel kick message
|
|
|
|
* @param msg channel kick message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChannelKick(ChannelKick msg)
|
|
|
|
public void onChannelKick(final ChannelKick msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!IrcStack.this.isConnected())
|
|
|
|
if (!IrcStack.this.isConnected())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1475,7 +1532,7 @@ public void onChannelKick(ChannelKick msg)
|
|
|
|
* @param msg user quit message
|
|
|
|
* @param msg user quit message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onUserQuit(QuitMessage msg)
|
|
|
|
public void onUserQuit(final QuitMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String user = msg.getSource().getNick();
|
|
|
|
String user = msg.getSource().getNick();
|
|
|
|
ChatRoomMember member = this.chatroom.getChatRoomMember(user);
|
|
|
|
ChatRoomMember member = this.chatroom.getChatRoomMember(user);
|
|
|
|
@ -1493,10 +1550,12 @@ public void onUserQuit(QuitMessage msg)
|
|
|
|
* @param msg nick change message
|
|
|
|
* @param msg nick change message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onNickChange(NickMessage msg)
|
|
|
|
public void onNickChange(final NickMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (msg == null)
|
|
|
|
if (msg == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String oldNick = msg.getSource().getNick();
|
|
|
|
String oldNick = msg.getSource().getNick();
|
|
|
|
String newNick = msg.getNewNick();
|
|
|
|
String newNick = msg.getNewNick();
|
|
|
|
@ -1523,10 +1582,12 @@ public void onNickChange(NickMessage msg)
|
|
|
|
* @param msg channel message
|
|
|
|
* @param msg channel message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChannelMessage(ChannelPrivMsg msg)
|
|
|
|
public void onChannelMessage(final ChannelPrivMsg msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String text = Utils.formatMessage(Utils.parse(msg.getText()));
|
|
|
|
String text = Utils.formatMessage(Utils.parse(msg.getText()));
|
|
|
|
MessageIrcImpl message =
|
|
|
|
MessageIrcImpl message =
|
|
|
|
@ -1545,10 +1606,12 @@ public void onChannelMessage(ChannelPrivMsg msg)
|
|
|
|
* @param msg channel action message
|
|
|
|
* @param msg channel action message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChannelAction(ChannelActionMsg msg)
|
|
|
|
public void onChannelAction(final ChannelActionMsg msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String userNick = msg.getSource().getNick();
|
|
|
|
String userNick = msg.getSource().getNick();
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
@ -1568,10 +1631,12 @@ public void onChannelAction(ChannelActionMsg msg)
|
|
|
|
* @param msg channel notice message
|
|
|
|
* @param msg channel notice message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChannelNotice(ChannelNotice msg)
|
|
|
|
public void onChannelNotice(final ChannelNotice msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
if (!isThisChatRoom(msg.getChannelName()))
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String userNick = msg.getSource().getNick();
|
|
|
|
String userNick = msg.getSource().getNick();
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
ChatRoomMemberIrcImpl member =
|
|
|
|
@ -1603,7 +1668,7 @@ private void leaveChatRoom()
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param msg raw mode message
|
|
|
|
* @param msg raw mode message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void processModeMessage(ChannelModeMessage msg)
|
|
|
|
private void processModeMessage(final ChannelModeMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ChatRoomMemberIrcImpl sourceMember = extractChatRoomMember(msg);
|
|
|
|
ChatRoomMemberIrcImpl sourceMember = extractChatRoomMember(msg);
|
|
|
|
|
|
|
|
|
|
|
|
@ -1754,7 +1819,7 @@ sourceMember, new Date(),
|
|
|
|
* @return returns member instance
|
|
|
|
* @return returns member instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ChatRoomMemberIrcImpl extractChatRoomMember(
|
|
|
|
private ChatRoomMemberIrcImpl extractChatRoomMember(
|
|
|
|
ChannelModeMessage msg)
|
|
|
|
final ChannelModeMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ChatRoomMemberIrcImpl member;
|
|
|
|
ChatRoomMemberIrcImpl member;
|
|
|
|
ISource source = msg.getSource();
|
|
|
|
ISource source = msg.getSource();
|
|
|
|
@ -1789,7 +1854,7 @@ else if (source instanceof IRCUser)
|
|
|
|
* @param chatRoomName chat room name
|
|
|
|
* @param chatRoomName chat room name
|
|
|
|
* @return returns true if this listener applies, false otherwise
|
|
|
|
* @return returns true if this listener applies, false otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean isThisChatRoom(String chatRoomName)
|
|
|
|
private boolean isThisChatRoom(final String chatRoomName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return this.chatroom.getIdentifier().equalsIgnoreCase(chatRoomName);
|
|
|
|
return this.chatroom.getIdentifier().equalsIgnoreCase(chatRoomName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1800,7 +1865,7 @@ private boolean isThisChatRoom(String chatRoomName)
|
|
|
|
* @param user the source user
|
|
|
|
* @param user the source user
|
|
|
|
* @return returns true if this use, or false otherwise
|
|
|
|
* @return returns true if this use, or false otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean isMe(IRCUser user)
|
|
|
|
private boolean isMe(final IRCUser user)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return IrcStack.this.connectionState.getNickname().equals(
|
|
|
|
return IrcStack.this.connectionState.getNickname().equals(
|
|
|
|
user.getNick());
|
|
|
|
user.getNick());
|
|
|
|
@ -1812,7 +1877,7 @@ private boolean isMe(IRCUser user)
|
|
|
|
* @param name nick of the user
|
|
|
|
* @param name nick of the user
|
|
|
|
* @return returns true if so, false otherwise
|
|
|
|
* @return returns true if so, false otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean isMe(String name)
|
|
|
|
private boolean isMe(final String name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return IrcStack.this.connectionState.getNickname().equals(name);
|
|
|
|
return IrcStack.this.connectionState.getNickname().equals(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1822,7 +1887,7 @@ private boolean isMe(String name)
|
|
|
|
* Special listener that processes LIST replies and signals once the list is
|
|
|
|
* Special listener that processes LIST replies and signals once the list is
|
|
|
|
* completely filled.
|
|
|
|
* completely filled.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static class ChannelListListener
|
|
|
|
private static final class ChannelListListener
|
|
|
|
extends VariousMessageListenerAdapter
|
|
|
|
extends VariousMessageListenerAdapter
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -1840,12 +1905,14 @@ private static class ChannelListListener
|
|
|
|
* @param api irc-api library instance
|
|
|
|
* @param api irc-api library instance
|
|
|
|
* @param list signal for sync signaling
|
|
|
|
* @param list signal for sync signaling
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ChannelListListener(IRCApi api,
|
|
|
|
private ChannelListListener(final IRCApi api,
|
|
|
|
Result<List<String>, Exception> list)
|
|
|
|
final Result<List<String>, Exception> list)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (api == null)
|
|
|
|
if (api == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"IRC api instance cannot be null");
|
|
|
|
"IRC api instance cannot be null");
|
|
|
|
|
|
|
|
}
|
|
|
|
this.api = api;
|
|
|
|
this.api = api;
|
|
|
|
this.signal = list;
|
|
|
|
this.signal = list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1857,12 +1924,16 @@ private ChannelListListener(IRCApi api,
|
|
|
|
* Clears the list upon starting. All received channels are added to the
|
|
|
|
* Clears the list upon starting. All received channels are added to the
|
|
|
|
* list. Upon receiving RPL_LISTEND finalize the list and signal the
|
|
|
|
* list. Upon receiving RPL_LISTEND finalize the list and signal the
|
|
|
|
* waiting thread that it can continue processing the list.
|
|
|
|
* waiting thread that it can continue processing the list.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param msg The numeric server message.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onServerNumericMessage(ServerNumericMessage msg)
|
|
|
|
public void onServerNumericMessage(final ServerNumericMessage msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.signal.isDone())
|
|
|
|
if (this.signal.isDone())
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (msg.getNumericCode())
|
|
|
|
switch (msg.getNumericCode())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1904,11 +1975,13 @@ public void onServerNumericMessage(ServerNumericMessage msg)
|
|
|
|
* @param text raw server response
|
|
|
|
* @param text raw server response
|
|
|
|
* @return returns the channel name
|
|
|
|
* @return returns the channel name
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String parse(String text)
|
|
|
|
private String parse(final String text)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int endOfChannelName = text.indexOf(' ');
|
|
|
|
int endOfChannelName = text.indexOf(' ');
|
|
|
|
if (endOfChannelName == -1)
|
|
|
|
if (endOfChannelName == -1)
|
|
|
|
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
// Create a new string to make sure that the original (larger)
|
|
|
|
// Create a new string to make sure that the original (larger)
|
|
|
|
// strings can be GC'ed.
|
|
|
|
// strings can be GC'ed.
|
|
|
|
return new String(text.substring(0, endOfChannelName));
|
|
|
|
return new String(text.substring(0, endOfChannelName));
|
|
|
|
@ -1918,7 +1991,7 @@ private String parse(String text)
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Container for storing server parameters.
|
|
|
|
* Container for storing server parameters.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static class ServerParameters
|
|
|
|
private static final class ServerParameters
|
|
|
|
implements IServerParameters
|
|
|
|
implements IServerParameters
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
@ -1954,8 +2027,8 @@ private static class ServerParameters
|
|
|
|
* @param ident ident
|
|
|
|
* @param ident ident
|
|
|
|
* @param server IRC server instance
|
|
|
|
* @param server IRC server instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ServerParameters(String nickName, String realName,
|
|
|
|
private ServerParameters(final String nickName, final String realName,
|
|
|
|
String ident, IRCServer server)
|
|
|
|
final String ident, final IRCServer server)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.nick = checkNick(nickName);
|
|
|
|
this.nick = checkNick(nickName);
|
|
|
|
this.alternativeNicks.add(nickName + "_");
|
|
|
|
this.alternativeNicks.add(nickName + "_");
|
|
|
|
@ -1987,7 +2060,7 @@ public String getNickname()
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param nick nick name
|
|
|
|
* @param nick nick name
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setNickname(String nick)
|
|
|
|
public void setNickname(final String nick)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.nick = checkNick(nick);
|
|
|
|
this.nick = checkNick(nick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1997,19 +2070,20 @@ public void setNickname(String nick)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param nick nick name
|
|
|
|
* @param nick nick name
|
|
|
|
* @return returns nick name
|
|
|
|
* @return returns nick name
|
|
|
|
* @throws IllegalArgumentException throws
|
|
|
|
|
|
|
|
* <tt>IllegalArgumentException</tt> if an invalid nick name
|
|
|
|
|
|
|
|
* is provided.
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String checkNick(String nick)
|
|
|
|
private String checkNick(final String nick)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (nick == null)
|
|
|
|
if (nick == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"a nick name must be provided");
|
|
|
|
"a nick name must be provided");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (nick.startsWith("#") || nick.startsWith("&"))
|
|
|
|
if (nick.startsWith("#") || nick.startsWith("&"))
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"the nick name must not start with '#' or '&' "
|
|
|
|
"the nick name must not start with '#' or '&' "
|
|
|
|
+ "since this is reserved for IRC channels");
|
|
|
|
+ "since this is reserved for IRC channels");
|
|
|
|
|
|
|
|
}
|
|
|
|
return nick;
|
|
|
|
return nick;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -2036,7 +2110,7 @@ public String getIdent()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get real name
|
|
|
|
* Get real name.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return returns real name
|
|
|
|
* @return returns real name
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -2047,7 +2121,7 @@ public String getRealname()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get server
|
|
|
|
* Get server.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return returns server instance
|
|
|
|
* @return returns server instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -2062,11 +2136,12 @@ public IRCServer getServer()
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param server IRC server instance
|
|
|
|
* @param server IRC server instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setServer(IRCServer server)
|
|
|
|
public void setServer(final IRCServer server)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (server == null)
|
|
|
|
if (server == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("server cannot be null");
|
|
|
|
throw new IllegalArgumentException("server cannot be null");
|
|
|
|
|
|
|
|
}
|
|
|
|
this.server = server;
|
|
|
|
this.server = server;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -2077,7 +2152,7 @@ public void setServer(IRCServer server)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param <T> The type of instance to store in the container
|
|
|
|
* @param <T> The type of instance to store in the container
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static class Container<T>
|
|
|
|
private static final class Container<T>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The stored instance. (Can be null)
|
|
|
|
* The stored instance. (Can be null)
|
|
|
|
@ -2094,7 +2169,7 @@ private static class Container<T>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param instance the instance to set
|
|
|
|
* @param instance the instance to set
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Container(T instance)
|
|
|
|
private Container(final T instance)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.instance = instance;
|
|
|
|
this.instance = instance;
|
|
|
|
this.time = System.nanoTime();
|
|
|
|
this.time = System.nanoTime();
|
|
|
|
@ -2107,7 +2182,7 @@ private Container(T instance)
|
|
|
|
* @param bound maximum time difference that is allowed.
|
|
|
|
* @param bound maximum time difference that is allowed.
|
|
|
|
* @return returns instance if within bounds, or null otherwise
|
|
|
|
* @return returns instance if within bounds, or null otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public T get(long bound)
|
|
|
|
public T get(final long bound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (System.nanoTime() - this.time > bound)
|
|
|
|
if (System.nanoTime() - this.time > bound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -2117,11 +2192,11 @@ public T get(long bound)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set an instance
|
|
|
|
* Set an instance.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param instance the instance
|
|
|
|
* @param instance the instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void set(T instance)
|
|
|
|
public void set(final T instance)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.instance = instance;
|
|
|
|
this.instance = instance;
|
|
|
|
this.time = System.nanoTime();
|
|
|
|
this.time = System.nanoTime();
|
|
|
|
|