Implemented IRC account equality based on userID, host and port.

Implemented IRC account equality based on userID, host and port, instead
of only on userID, because there are different IRC networks where users
can have the same user ID without being the same person.
fix-message-formatting
Danny van Heumen 12 years ago
parent 14cc351de0
commit 4cd8dff0cd

@ -15,42 +15,102 @@
*
* @author Stephane Remy
* @author Loic Kempf
* @author Danny van Heumen
*/
public class IrcAccountID
extends AccountID
{
/**
* IRC account server host.
*/
private final String host;
/**
* IRC account server port.
*/
private final int port;
/**
* Creates an account id from the specified id and account properties.
*
* @param userID the user identifier corresponding to this account
* @param host IRC server host
* @param port IRC server port
* @param accountProperties any other properties necessary for the account.
*/
IrcAccountID(String userID, Map<String, String> accountProperties)
IrcAccountID(final String userID, final String host, final String port,
final Map<String, String> accountProperties)
{
super(userID, accountProperties, ProtocolNames.IRC,
getServiceName(accountProperties));
if (host == null)
{
throw new IllegalArgumentException("host cannot be null");
}
this.host = host;
if (port == null)
{
throw new IllegalArgumentException("port cannot be null");
}
this.port = Integer.parseInt(port);
}
/**
* Equality extended with checking IRC server host and port, since different
* IRC networks can have users with similar names.
*/
@Override
public boolean equals(Object obj)
{
super( userID,
accountProperties,
ProtocolNames.IRC,
getServiceName(accountProperties));
if (this == obj)
return true;
return super.equals(obj)
&& this.host.equals(((IrcAccountID) obj).host)
&& this.port == ((IrcAccountID) obj).port;
}
// TODO Danny: Fix equality: Since we can have completely different IRC
// networks, we should not limit account creation purely on the user's
// id/nickname.
/**
* Get the IRC server host.
*
* @return returns IRC server host
*/
public String getHost()
{
return this.host;
}
/**
* Get the IRC server port.
*
* @return returns IRC server port
*/
public int getPort()
{
return this.port;
}
/**
* Returns the service name - the server we are logging to
* if it is null which is not supposed to be - we return for compatibility
* the string we used in the first release for creating AccountID
* (Using this string is wrong, but used for compatibility for now)
* Returns the service name - the server we are logging to if it is null
* which is not supposed to be - we return for compatibility the string we
* used in the first release for creating AccountID (Using this string is
* wrong, but used for compatibility for now)
*
* @param accountProperties Map the properties table configuring the account
* @return String the service name
*/
private static String getServiceName(Map<String, String> accountProperties)
{
String serviceName
= accountProperties.get(ProtocolProviderFactory.SERVER_ADDRESS);
String serviceName =
accountProperties.get(ProtocolProviderFactory.SERVER_ADDRESS);
if (serviceName != null)
{
final String port =
accountProperties.get(ProtocolProviderFactory.SERVER_PORT);
if (port != null)
{
serviceName += ":" + port;
}
}
return (serviceName == null) ? ProtocolNames.IRC : serviceName;
}
}

@ -60,8 +60,12 @@ public AccountID installAccount( String userIDStr,
"The specified property map was null");
accountProperties.put(USER_ID, userIDStr);
AccountID accountID = new IrcAccountID(userIDStr, accountProperties);
final String host =
accountProperties.get(ProtocolProviderFactory.SERVER_ADDRESS);
final String port =
accountProperties.get(ProtocolProviderFactory.SERVER_PORT);
AccountID accountID =
new IrcAccountID(userIDStr, host, port, accountProperties);
//make sure we haven't seen this account id before.
if (registeredAccounts.containsKey(accountID))
@ -85,11 +89,14 @@ public AccountID installAccount( String userIDStr,
* {@inheritDoc}
*/
@Override
protected AccountID createAccountID(
String userID,
protected AccountID createAccountID(String userID,
Map<String, String> accountProperties)
{
return new IrcAccountID(userID, accountProperties);
final String host =
accountProperties.get(ProtocolProviderFactory.SERVER_ADDRESS);
final String port =
accountProperties.get(ProtocolProviderFactory.SERVER_PORT);
return new IrcAccountID(userID, host, port, accountProperties);
}
/**

Loading…
Cancel
Save