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

Commit

Permalink
Asynchronous hostname lookups.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Nov 6, 2014
1 parent 38176a3 commit 7832b11
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -1200,34 +1200,34 @@ public void loadDisplayNameCache() {
}

public String getPlayerHost(Player player) {
String playerIP = player.getAddress().getAddress().getHostAddress();
final String playerIP = player.getAddress().getAddress().getHostAddress();
if (hostCache.containsKey(playerIP)) {
return hostCache.get(playerIP);
} else {
getServer().getScheduler().runTaskLaterAsynchronously(this, new Runnable() {
@Override
public void run() {
logDebug("Asynchronously looking up hostname for " + playerIP);
InetAddress addr = null;
try {
addr = InetAddress.getByName(playerIP);
} catch (UnknownHostException ex) {
logError(ex.getMessage());
}
if (addr != null) {
hostCache.put(playerIP, addr.getHostName());
}
}
}, 5);
return "";
}
InetAddress addr = null;
try {
addr = InetAddress.getByName(playerIP);
} catch (UnknownHostException ex) {
logError(ex.getMessage());
}
String host = "UnknownHost";
if (addr != null) {
host = addr.getHostName();
hostCache.put(playerIP, host);
}
return host;
}

public void clearHostCache(final Player player) {
getServer().getScheduler().runTaskLaterAsynchronously(this, new Runnable() {
@Override
public void run() {
String playerIP = player.getAddress().getAddress().getHostAddress();
if (hostCache.containsKey(playerIP)) {
hostCache.remove(playerIP);
}
}
}, 5);
String playerIP = player.getAddress().getAddress().getHostAddress();
if (hostCache.containsKey(playerIP)) {
hostCache.remove(playerIP);
}
}

public String botify(String bot) {
Expand Down

0 comments on commit 7832b11

Please sign in to comment.