mirror of
https://github.com/moparisthebest/MoparClassic
synced 2024-11-11 11:45:09 -05:00
Alerts are now sent on their own thread (one thread for all alerts).
OSLevelBlocking sends alerts. The priority is number of blocked ips / 10.
This commit is contained in:
parent
5540cc3083
commit
40b78d9254
@ -10,12 +10,15 @@ import javax.mail.Session
|
||||
import javax.mail.internet.MimeMessage
|
||||
import javax.mail.Message
|
||||
import javax.mail.internet.InternetAddress
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
/**
|
||||
* This is for out-of-game alerts.
|
||||
*/
|
||||
object AlertHandler extends Application {
|
||||
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
|
||||
private var users: List[User] = Nil
|
||||
|
||||
load
|
||||
@ -26,21 +29,21 @@ object AlertHandler extends Application {
|
||||
}
|
||||
|
||||
private def sendAlert(msg: String, recip: User, priority: Int) {
|
||||
executor.execute(new Runnable() {
|
||||
override def run() {
|
||||
val meds = recip.data.filter(p => p._1 <= priority)
|
||||
for (m <- meds) {
|
||||
Medium.send(m._2, msg)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
def sendAlert(msg: String, priority: Int) {
|
||||
for (u <- users)
|
||||
sendAlert(msg, u, priority)
|
||||
}
|
||||
|
||||
def reload {
|
||||
load
|
||||
}
|
||||
|
||||
def load {
|
||||
val config = XML.loadFile("alert-config.xml")
|
||||
val users1 = (config \\ "user")
|
||||
|
@ -5,8 +5,9 @@ import java.util.concurrent.CopyOnWriteArrayList
|
||||
import org.moparscape.msc.gs.Server
|
||||
import org.moparscape.msc.gs.core.DelayedEventHandler
|
||||
import org.moparscape.msc.gs.event.DelayedEvent
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.gs.util.Logger
|
||||
import org.moparscape.msc.config.Config
|
||||
import org.moparscape.msc.gs.alert.AlertHandler
|
||||
|
||||
object OSLevelBlocking {
|
||||
|
||||
@ -27,12 +28,14 @@ object OSLevelBlocking {
|
||||
case e: Exception => {
|
||||
Logger.error(e)
|
||||
Logger.println("Failed to unblock " + ip)
|
||||
AlertHandler.sendAlert("Failed to unblock " + ip, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Runtime.getRuntime.exec(Config.BLOCK_COMMAND.replaceAll("${ip}", ip));
|
||||
blocked.add(ip)
|
||||
AlertHandler.sendAlert("Blocked " + ip, blocked.size / 10);
|
||||
Logger.println("Blocked " + ip)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user