mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-04 08:39:05 +00:00
d876a923b9
* Clean up part 1 - Removed lots of dead code - Removed unncessary files not in use - Cleaned up small bits of code - Removed a few warnings - Server.java ---> GameEngine.java - Constants.java ---> GameConstants.java * Cape Dye Rewrote cape dying * Packaging - redone ----> com.rebotted * PacketSender/clean up - ActionSender ---> PacketSender - Moved many more packets to packetsender - Cleaned up more dead code * Merge Client/Player - Merged Client.java with Player.java (both were doing same thing so redundant to have both) - Removed some more dead code - Tidy a few small things up * Quests/more clean up - Removed more dead code - Made quests static in order to clean them up a bit * More cleanup - Removed some more of the dead quest code - Correcting naming of some of the shop variables
58 lines
1.2 KiB
Java
58 lines
1.2 KiB
Java
package com.rebotted.net;
|
|
|
|
import java.net.InetSocketAddress;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import org.apache.mina.common.IoSession;
|
|
|
|
import com.rebotted.Connection;
|
|
import com.rebotted.GameConstants;
|
|
|
|
public class HostList {
|
|
|
|
private static HostList list = new HostList();
|
|
|
|
public static HostList getHostList() {
|
|
return list;
|
|
}
|
|
|
|
private final Map<String, Integer> connections = new HashMap<String, Integer>();
|
|
|
|
public synchronized boolean add(IoSession session) {
|
|
String addr = ((InetSocketAddress) session.getRemoteAddress())
|
|
.getAddress().getHostAddress();
|
|
Integer amt = connections.get(addr);
|
|
if (amt == null) {
|
|
amt = 1;
|
|
} else {
|
|
amt += 1;
|
|
}
|
|
if (amt > GameConstants.IPS_ALLOWED || Connection.isIpBanned(addr)) {
|
|
return false;
|
|
} else {
|
|
connections.put(addr, amt);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public synchronized void remove(IoSession session) {
|
|
if (session.getAttribute("inList") != Boolean.TRUE) {
|
|
return;
|
|
}
|
|
String addr = ((InetSocketAddress) session.getRemoteAddress())
|
|
.getAddress().getHostAddress();
|
|
Integer amt = connections.get(addr);
|
|
if (amt == null) {
|
|
return;
|
|
}
|
|
amt -= 1;
|
|
if (amt <= 0) {
|
|
connections.remove(addr);
|
|
} else {
|
|
connections.put(addr, amt);
|
|
}
|
|
}
|
|
|
|
}
|