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>
<!-- Uses threaded client update (messed up) -->
<permission name="thread">11</permission>
<!-- IP bans a user -->
<permission name="ipban">7</permission>
<!-- Removes IP ban -->
<permission name="unipban">10</permission>
<setting>
<!-- Minimum delay between commands -->

View File

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

View File

@ -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) {

View File

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