mirror of
https://github.com/moparisthebest/MoparClassic
synced 2024-11-13 20:55:05 -05:00
Made block/unblock command come from the config.
This commit is contained in:
parent
c578718409
commit
c696c3ef94
@ -18,10 +18,11 @@ public class Config {
|
||||
public static String MYSQL_USER;
|
||||
public static String MYSQL_PASS;
|
||||
|
||||
public static String SERVER_IP, SERVER_NAME, RSCD_HOME, CONF_DIR,
|
||||
SERVER_LOCATION, LS_IP;
|
||||
|
||||
public static String SERVER_IP, SERVER_NAME, RSCD_HOME, CONF_DIR, SERVER_LOCATION, LS_IP;
|
||||
|
||||
public static int SERVER_PORT, SERVER_VERSION, MAX_PLAYERS, LS_PORT, SERVER_NUM;
|
||||
public static int SERVER_PORT, SERVER_VERSION, MAX_PLAYERS, LS_PORT,
|
||||
SERVER_NUM;
|
||||
|
||||
public static long START_TIME;
|
||||
|
||||
@ -30,17 +31,17 @@ public class Config {
|
||||
public static double expRate, subExpRate;
|
||||
|
||||
public static String[] pmods, mods, admins;
|
||||
public static String UNUSED_IP;
|
||||
public static int IP_BAN_REMOVAL_DELAY;
|
||||
public static int GARBAGE_COLLECT_INTERVAL;
|
||||
public static int SAVE_INTERVAL;
|
||||
public static String DATE_FORMAT;
|
||||
public static String BLOCK_COMMAND;
|
||||
public static String UNBLOCK_COMMAND;
|
||||
|
||||
static {
|
||||
loadEnv();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called to load config settings from the given file
|
||||
*
|
||||
@ -72,7 +73,6 @@ public class Config {
|
||||
LS_PORT = Integer.parseInt(props.getProperty("lsport"));
|
||||
SERVER_NUM = Integer.parseInt(props.getProperty("servernum"));
|
||||
|
||||
|
||||
members = Boolean.parseBoolean(props.getProperty("members", "false"));
|
||||
f2pWildy = Boolean.parseBoolean(props.getProperty("f2pWildy", "true"));
|
||||
expRate = Double.parseDouble(props.getProperty("expRate"));
|
||||
@ -82,17 +82,23 @@ public class Config {
|
||||
mods = props.getProperty("mods").replaceAll(", +", ",").split(",");
|
||||
admins = props.getProperty("admins").replaceAll(", +", ",").split(",");
|
||||
|
||||
UNUSED_IP = props.getProperty("unused-ip");
|
||||
IP_BAN_REMOVAL_DELAY = Integer.parseInt(props.getProperty("ip-ban-removal-delay"));
|
||||
IP_BAN_REMOVAL_DELAY = Integer.parseInt(props
|
||||
.getProperty("ip-ban-removal-delay"));
|
||||
BLOCK_COMMAND = props.getProperty("block-command");
|
||||
UNBLOCK_COMMAND = props.getProperty("unblock-command");
|
||||
|
||||
GARBAGE_COLLECT_INTERVAL = Integer.parseInt(props.getProperty("garbage-collect-interval"));
|
||||
GARBAGE_COLLECT_INTERVAL = Integer.parseInt(props
|
||||
.getProperty("garbage-collect-interval"));
|
||||
SAVE_INTERVAL = Integer.parseInt(props.getProperty("save-interval"));
|
||||
|
||||
DATE_FORMAT = props.getProperty("date-format");
|
||||
|
||||
props.clear();
|
||||
|
||||
Constants.GameServer.MOTD = "@yel@Welcome to @whi@" + Config.SERVER_NAME + "@yel@ - World @whi@" + (Config.SERVER_NUM == 0 ? 2 : Config.SERVER_NUM) + " (" + (Config.members ? "P2P" : "F2P") + ")";
|
||||
Constants.GameServer.MOTD = "@yel@Welcome to @whi@"
|
||||
+ Config.SERVER_NAME + "@yel@ - World @whi@"
|
||||
+ (Config.SERVER_NUM == 0 ? 2 : Config.SERVER_NUM) + " ("
|
||||
+ (Config.members ? "P2P" : "F2P") + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,36 +10,6 @@ import org.moparscape.msc.config.Config
|
||||
|
||||
object OSLevelBlocking {
|
||||
|
||||
private val block_ = {
|
||||
println(System.getProperty("os.name"))
|
||||
if (System.getProperty("os.name") startsWith "(?i)linux") {
|
||||
def b(ip: String) {
|
||||
Runtime.getRuntime().exec("sudo route add -host " + ip + " reject")
|
||||
}
|
||||
b _
|
||||
} else {
|
||||
// Windows blocking - untested - won't work on Windows 7
|
||||
def b(ip: String) {
|
||||
Runtime.getRuntime().exec("route ADD " + ip + " MASK 255.255.255.255 " + Config.UNUSED_IP)
|
||||
}
|
||||
b _
|
||||
}
|
||||
}
|
||||
private val unblock_ = {
|
||||
if (System.getProperty("os.name") startsWith "(?i)linux") {
|
||||
def u(ip: String) {
|
||||
Runtime.getRuntime().exec("sudo route del " + ip + " reject")
|
||||
}
|
||||
u _
|
||||
} else {
|
||||
// Windows blocking - untested - won't work on Windows 7
|
||||
def b(ip: String) {
|
||||
Runtime.getRuntime().exec("route DELETE " + ip)
|
||||
}
|
||||
b _
|
||||
}
|
||||
}
|
||||
|
||||
private val blocked = new CopyOnWriteArrayList[String];
|
||||
|
||||
private val events = Server.getServer().getEngine().getEventHandler()
|
||||
@ -49,19 +19,8 @@ object OSLevelBlocking {
|
||||
events.add(new DelayedEvent(null, Config.IP_BAN_REMOVAL_DELAY) {
|
||||
|
||||
def run() {
|
||||
unblock(ip)
|
||||
|
||||
}
|
||||
})
|
||||
block_(ip)
|
||||
blocked.add(ip)
|
||||
Logger.println("Blocked " + ip)
|
||||
}
|
||||
}
|
||||
|
||||
def unblock(ip: String) {
|
||||
try {
|
||||
unblock_(ip)
|
||||
Runtime.getRuntime.exec(Config.UNBLOCK_COMMAND.replaceAll("${ip}", ip));
|
||||
blocked.remove(ip)
|
||||
Logger.println("Unblocked " + ip)
|
||||
} catch {
|
||||
@ -71,4 +30,10 @@ object OSLevelBlocking {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Runtime.getRuntime.exec(Config.BLOCK_COMMAND.replaceAll("${ip}", ip));
|
||||
blocked.add(ip)
|
||||
Logger.println("Blocked " + ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,9 @@
|
||||
<entry key="mods">None</entry>
|
||||
<entry key="admins">None</entry>
|
||||
|
||||
<!-- This only needs to be specified if you're using a Windows machine -->
|
||||
<entry key="unused-ip">192.168.0.255</entry>
|
||||
<entry key="ip-ban-removal-delay">1800000</entry>
|
||||
<entry key="block-command">sudo route add -host ${ip} reject</entry>
|
||||
<entry key="unblock-command">sudo route del -host ${ip} reject</entry>
|
||||
|
||||
<!-- Every 100 minutes -->
|
||||
<entry key="garbage-collect-interval">6000000</entry>
|
||||
|
Loading…
Reference in New Issue
Block a user