Added ip ban and unban commands.

Fixed formatting of LSPacketHandlers.xml
This commit is contained in:
CodeForFame 2011-06-25 16:42:55 -05:00
parent 4fcb575620
commit 7ccbc743b9
5 changed files with 91 additions and 51 deletions

View File

@ -44,6 +44,10 @@
<permission name="dropall">10</permission> <permission name="dropall">10</permission>
<!-- Uses threaded client update (messed up) --> <!-- Uses threaded client update (messed up) -->
<permission name="thread">11</permission> <permission name="thread">11</permission>
<!-- IP bans a user -->
<permission name="ipban">7</permission>
<!-- Removes IP ban -->
<permission name="unipban">10</permission>
<setting> <setting>
<!-- Minimum delay between commands --> <!-- Minimum delay between commands -->

View File

@ -41,30 +41,35 @@ object IPBanManager extends Blocker {
throttle(lookupIP(ip)) throttle(lookupIP(ip))
} }
override def block(ip: String) { override def block(ip: String) = {
var ret = false
if (ip != null && ip.length > 0) { if (ip != null && ip.length > 0) {
if (Config.APPLICATION_LEVEL_BLOCKING) if (Config.APPLICATION_LEVEL_BLOCKING)
ApplicationLevelBlocking.block(ip) ret = ApplicationLevelBlocking.block(ip)
if (Config.OS_LEVEL_BLOCKING) if (Config.OS_LEVEL_BLOCKING)
OSLevelBlocking.block(ip) ret = ret || OSLevelBlocking.block(ip)
} }
ret
} }
def block(ip: java.util.List[String]) { def block(ip: java.util.List[String]) {
ip foreach { block(_) } ip foreach { block(_) }
} }
def block(ip: SocketAddress) { def block(ip: SocketAddress): Boolean = {
block(lookupIP(ip)) block(lookupIP(ip))
} }
override def unblock(ip: String) { override def unblock(ip: String) = {
ApplicationLevelBlocking.unblock(ip) var ret = false
OSLevelBlocking.unblock(ip) 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)) unblock(lookupIP(ip))
} }
@ -79,8 +84,8 @@ object IPBanManager extends Blocker {
trait Blocker { trait Blocker {
def isBlocked(ip: String): Boolean def isBlocked(ip: String): Boolean
def block(ip: String) def block(ip: String): Boolean
def unblock(ip: String) def unblock(ip: String): Boolean
def throttle(ip: String) def throttle(ip: String)
} }
@ -92,17 +97,14 @@ private object ApplicationLevelBlocking extends Blocker {
private val events = Server.getServer().getEngine().getEventHandler() private val events = Server.getServer().getEngine().getEventHandler()
override def isBlocked(ip: String) = { override def isBlocked(ip: String) = {
if (blocked.contains(ip)) { blocked.contains(ip)
true
}
false
} }
override def block(ip: String) { override def block(ip: String) = {
blocked.addIfAbsent(ip) blocked.addIfAbsent(ip)
} }
override def unblock(ip: String) { override def unblock(ip: String) = {
blocked.remove(ip) blocked.remove(ip)
} }
@ -133,10 +135,7 @@ private object OSLevelBlocking extends Blocker {
private val events = Server.getServer().getEngine().getEventHandler() private val events = Server.getServer().getEngine().getEventHandler()
override def isBlocked(ip: String) = { override def isBlocked(ip: String) = {
if (blocked.contains(ip)) { blocked.contains(ip)
true
}
false
} }
override def throttle(ip: String) { 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)) Runtime.getRuntime.exec(Config.BLOCK_COMMAND.replaceAll("${ip}", ip))
blocked addIfAbsent ip blocked addIfAbsent ip
} }
override def unblock(ip: String) { override def unblock(ip: String) = {
try { try {
Runtime.getRuntime.exec(Config.UNBLOCK_COMMAND.replaceAll("${ip}", ip)) Runtime.getRuntime.exec(Config.UNBLOCK_COMMAND.replaceAll("${ip}", ip))
blocked remove ip blocked remove ip
throttled.remove(ip) throttled.remove(ip)
Logger.println("OS - Unblocked " + ip) Logger.println("OS - Unblocked " + ip)
true
} catch { } catch {
case e: Exception => { case e: Exception => {
Logger.println("OS - Failed to unblock " + ip) Logger.println("OS - Failed to unblock " + ip)
Logger.error(e) Logger.error(e)
if (Config.OS_LEVEL_UNBLOCK_FAILED_ALERT) if (Config.OS_LEVEL_UNBLOCK_FAILED_ALERT)
AlertHandler.sendAlert("OS - Failed to unblock " + ip, 2) AlertHandler.sendAlert("OS - Failed to unblock " + ip, 2)
false
} }
} }
} }

View File

@ -13,6 +13,7 @@ import org.moparscape.msc.gs.model.Point
import org.moparscape.msc.config.Config import org.moparscape.msc.config.Config
import scala.collection.immutable.HashMap import scala.collection.immutable.HashMap
import scala.xml.NodeSeq import scala.xml.NodeSeq
import org.moparscape.msc.gs.connection.filter.IPBanManager
object CommandHandler { object CommandHandler {
import scala.xml.XML import scala.xml.XML
@ -98,6 +99,8 @@ class CommandHandler extends PacketHandler {
case "update" => update(p, args, world) case "update" => update(p, args, world)
case "dropall" => clearInv(p) case "dropall" => clearInv(p)
case "thread" => enableMultiThreading(p) case "thread" => enableMultiThreading(p)
case "ipban" => ipban(p, args, world)
case "unipban" => unipban(p, args)
case _ => none = true case _ => none = true
} }
if (!none) if (!none)
@ -281,6 +284,36 @@ class CommandHandler extends PacketHandler {
message(p, "Threaded client updater: " + ClientUpdater.threaded) 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 // Helper methods
def message(p: Player, msg: String) { def message(p: Player, msg: String) {

View File

@ -4,51 +4,44 @@
<int>1</int> <int>1</int>
<int>2</int> <int>2</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.RegisterWorld <className>org.moparscape.msc.ls.packethandler.loginserver.RegisterWorld</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>3</int> <int>3</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.KillHandler <className>org.moparscape.msc.ls.packethandler.loginserver.KillHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>4</int> <int>4</int>
<int>5</int> <int>5</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.BanHandler <className>org.moparscape.msc.ls.packethandler.loginserver.BanHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>6</int> <int>6</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.PrivacySettingHandler <className>org.moparscape.msc.ls.packethandler.loginserver.PrivacySettingHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>7</int> <int>7</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.GameSettingHandler <className>org.moparscape.msc.ls.packethandler.loginserver.GameSettingHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>8</int> <int>8</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.PlayerInfoRequestHandler <className>org.moparscape.msc.ls.packethandler.loginserver.PlayerInfoRequestHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>9</int> <int>9</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.SaveProfilesRequestHandler <className>org.moparscape.msc.ls.packethandler.loginserver.SaveProfilesRequestHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
@ -58,49 +51,42 @@
<int>13</int> <int>13</int>
<int>14</int> <int>14</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.FriendHandler <className>org.moparscape.msc.ls.packethandler.loginserver.FriendHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>15</int> <int>15</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.ReportHandler <className>org.moparscape.msc.ls.packethandler.loginserver.ReportHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>20</int> <int>20</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.PlayerSaveHandler <className>org.moparscape.msc.ls.packethandler.loginserver.PlayerSaveHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>30</int> <int>30</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.PlayerLogoutHandler <className>org.moparscape.msc.ls.packethandler.loginserver.PlayerLogoutHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>31</int> <int>31</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.PlayerLoginHandler <className>org.moparscape.msc.ls.packethandler.loginserver.PlayerLoginHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>32</int> <int>32</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.LogHandler <className>org.moparscape.msc.ls.packethandler.loginserver.LogHandler</className>
</className>
</PacketHandler> </PacketHandler>
<PacketHandler> <PacketHandler>
<ids> <ids>
<int>33</int> <int>33</int>
</ids> </ids>
<className>org.moparscape.msc.ls.packethandler.loginserver.Tradelog <className>org.moparscape.msc.ls.packethandler.loginserver.Tradelog</className>
</className>
</PacketHandler> </PacketHandler>
</PacketHandler-array> </PacketHandler-array>

View File

@ -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.