diff --git a/GameServer/conf/command-config.xml b/GameServer/conf/command-config.xml index 5c5ce87..871f393 100644 --- a/GameServer/conf/command-config.xml +++ b/GameServer/conf/command-config.xml @@ -44,6 +44,10 @@ 10 11 + + 7 + + 10 diff --git a/GameServer/src/org/moparscape/msc/gs/connection/filter/IPBanManager.scala b/GameServer/src/org/moparscape/msc/gs/connection/filter/IPBanManager.scala index ce92c71..ef844ee 100644 --- a/GameServer/src/org/moparscape/msc/gs/connection/filter/IPBanManager.scala +++ b/GameServer/src/org/moparscape/msc/gs/connection/filter/IPBanManager.scala @@ -41,30 +41,35 @@ object IPBanManager extends Blocker { throttle(lookupIP(ip)) } - override def block(ip: String) { + override def block(ip: String) = { + var ret = false if (ip != null && ip.length > 0) { if (Config.APPLICATION_LEVEL_BLOCKING) - ApplicationLevelBlocking.block(ip) + ret = ApplicationLevelBlocking.block(ip) if (Config.OS_LEVEL_BLOCKING) - OSLevelBlocking.block(ip) + ret = ret || OSLevelBlocking.block(ip) } - + ret } def block(ip: java.util.List[String]) { ip foreach { block(_) } } - def block(ip: SocketAddress) { + def block(ip: SocketAddress): Boolean = { block(lookupIP(ip)) } - override def unblock(ip: String) { - ApplicationLevelBlocking.unblock(ip) - OSLevelBlocking.unblock(ip) + override def unblock(ip: String) = { + var ret = false + if (ip != null && ip.length > 0) { + ret = ApplicationLevelBlocking.unblock(ip) + ret = ret || OSLevelBlocking.unblock(ip) + } + ret } - def unblock(ip: SocketAddress) { + def unblock(ip: SocketAddress): Boolean = { unblock(lookupIP(ip)) } @@ -79,8 +84,8 @@ object IPBanManager extends Blocker { trait Blocker { def isBlocked(ip: String): Boolean - def block(ip: String) - def unblock(ip: String) + def block(ip: String): Boolean + def unblock(ip: String): Boolean def throttle(ip: String) } @@ -92,17 +97,14 @@ private object ApplicationLevelBlocking extends Blocker { private val events = Server.getServer().getEngine().getEventHandler() override def isBlocked(ip: String) = { - if (blocked.contains(ip)) { - true - } - false + blocked.contains(ip) } - override def block(ip: String) { + override def block(ip: String) = { blocked.addIfAbsent(ip) } - override def unblock(ip: String) { + override def unblock(ip: String) = { blocked.remove(ip) } @@ -133,10 +135,7 @@ private object OSLevelBlocking extends Blocker { private val events = Server.getServer().getEngine().getEventHandler() override def isBlocked(ip: String) = { - if (blocked.contains(ip)) { - true - } - false + blocked.contains(ip) } override def throttle(ip: String) { @@ -156,23 +155,25 @@ private object OSLevelBlocking extends Blocker { } } - override def block(ip: String) { + override def block(ip: String) = { Runtime.getRuntime.exec(Config.BLOCK_COMMAND.replaceAll("${ip}", ip)) blocked addIfAbsent ip } - override def unblock(ip: String) { + override def unblock(ip: String) = { try { Runtime.getRuntime.exec(Config.UNBLOCK_COMMAND.replaceAll("${ip}", ip)) blocked remove ip throttled.remove(ip) Logger.println("OS - Unblocked " + ip) + true } catch { case e: Exception => { Logger.println("OS - Failed to unblock " + ip) Logger.error(e) if (Config.OS_LEVEL_UNBLOCK_FAILED_ALERT) AlertHandler.sendAlert("OS - Failed to unblock " + ip, 2) + false } } } diff --git a/GameServer/src/org/moparscape/msc/gs/phandler/client/CommandHandler.scala b/GameServer/src/org/moparscape/msc/gs/phandler/client/CommandHandler.scala index 48463f2..c5bc822 100644 --- a/GameServer/src/org/moparscape/msc/gs/phandler/client/CommandHandler.scala +++ b/GameServer/src/org/moparscape/msc/gs/phandler/client/CommandHandler.scala @@ -13,6 +13,7 @@ import org.moparscape.msc.gs.model.Point import org.moparscape.msc.config.Config import scala.collection.immutable.HashMap import scala.xml.NodeSeq +import org.moparscape.msc.gs.connection.filter.IPBanManager object CommandHandler { import scala.xml.XML @@ -98,6 +99,8 @@ class CommandHandler extends PacketHandler { case "update" => update(p, args, world) case "dropall" => clearInv(p) case "thread" => enableMultiThreading(p) + case "ipban" => ipban(p, args, world) + case "unipban" => unipban(p, args) case _ => none = true } if (!none) @@ -281,6 +284,36 @@ class CommandHandler extends PacketHandler { message(p, "Threaded client updater: " + ClientUpdater.threaded) } + def ipban(p: Player, args: Array[String], world: World) { + val hash = DataConversions.usernameToHash(args(0)) + + val itr = world.getPlayers.iterator + while (itr.hasNext) { + val p1 = itr.next + if (p1.getUsernameHash == hash) { + message(p, "IP ban on " + args(0) + ' ' + { + if (IPBanManager.block(p1.getCurrentIP)) + "succeeded" + else + "failed" + } + + '.') + return + } + } + message(p, "No user found with the name " + args(0)) + } + + def unipban(p: Player, args: Array[String]) { + message(p, "Removal of IP ban on " + args(0) + ' ' + { + if (IPBanManager.unblock(args(0))) + "succeeded" + else + "failed" + } + + '.') + } + // Helper methods def message(p: Player, msg: String) { diff --git a/LoginServer/conf/LSPacketHandlers.xml b/LoginServer/conf/LSPacketHandlers.xml index 4af6c7e..222d32b 100644 --- a/LoginServer/conf/LSPacketHandlers.xml +++ b/LoginServer/conf/LSPacketHandlers.xml @@ -4,51 +4,44 @@ 1 2 - org.moparscape.msc.ls.packethandler.loginserver.RegisterWorld - + org.moparscape.msc.ls.packethandler.loginserver.RegisterWorld 3 - org.moparscape.msc.ls.packethandler.loginserver.KillHandler - + org.moparscape.msc.ls.packethandler.loginserver.KillHandler 4 5 - org.moparscape.msc.ls.packethandler.loginserver.BanHandler - + org.moparscape.msc.ls.packethandler.loginserver.BanHandler 6 - org.moparscape.msc.ls.packethandler.loginserver.PrivacySettingHandler - + org.moparscape.msc.ls.packethandler.loginserver.PrivacySettingHandler 7 - org.moparscape.msc.ls.packethandler.loginserver.GameSettingHandler - + org.moparscape.msc.ls.packethandler.loginserver.GameSettingHandler 8 - org.moparscape.msc.ls.packethandler.loginserver.PlayerInfoRequestHandler - + org.moparscape.msc.ls.packethandler.loginserver.PlayerInfoRequestHandler 9 - org.moparscape.msc.ls.packethandler.loginserver.SaveProfilesRequestHandler - + org.moparscape.msc.ls.packethandler.loginserver.SaveProfilesRequestHandler @@ -58,49 +51,42 @@ 13 14 - org.moparscape.msc.ls.packethandler.loginserver.FriendHandler - + org.moparscape.msc.ls.packethandler.loginserver.FriendHandler 15 - org.moparscape.msc.ls.packethandler.loginserver.ReportHandler - + org.moparscape.msc.ls.packethandler.loginserver.ReportHandler 20 - org.moparscape.msc.ls.packethandler.loginserver.PlayerSaveHandler - + org.moparscape.msc.ls.packethandler.loginserver.PlayerSaveHandler 30 - org.moparscape.msc.ls.packethandler.loginserver.PlayerLogoutHandler - + org.moparscape.msc.ls.packethandler.loginserver.PlayerLogoutHandler 31 - org.moparscape.msc.ls.packethandler.loginserver.PlayerLoginHandler - + org.moparscape.msc.ls.packethandler.loginserver.PlayerLoginHandler 32 - org.moparscape.msc.ls.packethandler.loginserver.LogHandler - + org.moparscape.msc.ls.packethandler.loginserver.LogHandler 33 - org.moparscape.msc.ls.packethandler.loginserver.Tradelog - + org.moparscape.msc.ls.packethandler.loginserver.Tradelog diff --git a/LoginServer/logs/err.log b/LoginServer/logs/err.log index e69de29..b6ceb7a 100644 --- a/LoginServer/logs/err.log +++ b/LoginServer/logs/err.log @@ -0,0 +1,16 @@ +16:40:54 25-06-11: 20313 [SocketAcceptorIoProcessor-0.1] INFO org.moparscape.msc.gs.connection.RSCConnectionHandler - [/127.0.0.1:43186] Remote address in the blacklist; closing. + +16:40:54 25-06-11: 20315 [SocketAcceptorIoProcessor-0.1] INFO org.moparscape.msc.gs.connection.RSCConnectionHandler - [/127.0.0.1:43186] Remote address in the blacklist; closing. + +16:40:57 25-06-11: 23880 [SocketAcceptorIoProcessor-0.2] INFO org.moparscape.msc.gs.connection.RSCConnectionHandler - [/127.0.0.1:43187] Remote address in the blacklist; closing. + +16:40:57 25-06-11: 23882 [SocketAcceptorIoProcessor-0.2] INFO org.moparscape.msc.gs.connection.RSCConnectionHandler - [/127.0.0.1:43187] Remote address in the blacklist; closing. + +16:40:58 25-06-11: 24714 [SocketAcceptorIoProcessor-0.3] INFO org.moparscape.msc.gs.connection.RSCConnectionHandler - [/127.0.0.1:43188] Remote address in the blacklist; closing. + +16:40:58 25-06-11: 24715 [SocketAcceptorIoProcessor-0.3] INFO org.moparscape.msc.gs.connection.RSCConnectionHandler - [/127.0.0.1:43188] Remote address in the blacklist; closing. + +16:40:59 25-06-11: 25403 [SocketAcceptorIoProcessor-0.4] INFO org.moparscape.msc.gs.connection.RSCConnectionHandler - [/127.0.0.1:43189] Remote address in the blacklist; closing. + +16:40:59 25-06-11: 25405 [SocketAcceptorIoProcessor-0.4] INFO org.moparscape.msc.gs.connection.RSCConnectionHandler - [/127.0.0.1:43189] Remote address in the blacklist; closing. +