Add getSessionsForAddress to return all the active sessions for a given IP address.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5682 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Charlie Groves
2009-03-06 21:29:01 +00:00
parent d67bcc5e01
commit 8f05b41c6a
@@ -21,11 +21,13 @@
package com.threerings.presents.server;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.net.InetAddress;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -179,6 +181,23 @@ public class ClientManager
}
}
/**
* Returns all sessions logged in from the given IP in the form returned from
* {@link InetAddress#getAddress()}.
*/
public List<PresentsSession> getSessionsForAddress (byte[] addr)
{
List<PresentsSession> sessions = Lists.newArrayListWithExpectedSize(1);
synchronized (_usermap) {
for (PresentsSession session : _usermap.values()) {
if (Arrays.equals(addr, session.getInetAddress().getAddress())) {
sessions.add(session);
}
}
}
return sessions;
}
/**
* Returns the number of connected clients.
*/