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,35 +10,38 @@ import javax.mail.Session
|
|||||||
import javax.mail.internet.MimeMessage
|
import javax.mail.internet.MimeMessage
|
||||||
import javax.mail.Message
|
import javax.mail.Message
|
||||||
import javax.mail.internet.InternetAddress
|
import javax.mail.internet.InternetAddress
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is for out-of-game alerts.
|
* This is for out-of-game alerts.
|
||||||
*/
|
*/
|
||||||
object AlertHandler extends Application {
|
object AlertHandler extends Application {
|
||||||
|
|
||||||
private var users : List[User] = Nil
|
private val executor = Executors.newSingleThreadExecutor()
|
||||||
|
|
||||||
|
private var users: List[User] = Nil
|
||||||
|
|
||||||
load
|
load
|
||||||
|
|
||||||
def sendAlert(msg : String, recip : String, priority : Int) {
|
def sendAlert(msg: String, recip: String, priority: Int) {
|
||||||
for (u <- users; if (u.name == recip))
|
for (u <- users; if (u.name == recip))
|
||||||
sendAlert(msg, u, priority)
|
sendAlert(msg, u, priority)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def sendAlert(msg : String, recip : User, priority : Int) {
|
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)
|
val meds = recip.data.filter(p => p._1 <= priority)
|
||||||
for (m <- meds) {
|
for (m <- meds) {
|
||||||
Medium.send(m._2, msg)
|
Medium.send(m._2, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
def sendAlert(msg : String, priority : Int) {
|
|
||||||
for (u <- users)
|
|
||||||
sendAlert(msg, u, priority)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def reload {
|
def sendAlert(msg: String, priority: Int) {
|
||||||
load
|
for (u <- users)
|
||||||
|
sendAlert(msg, u, priority)
|
||||||
}
|
}
|
||||||
|
|
||||||
def load {
|
def load {
|
||||||
@ -51,7 +54,7 @@ object AlertHandler extends Application {
|
|||||||
users = list.toList
|
users = list.toList
|
||||||
}
|
}
|
||||||
|
|
||||||
private def parseUser(u : Node) = {
|
private def parseUser(u: Node) = {
|
||||||
val name = (u \ "name").text
|
val name = (u \ "name").text
|
||||||
val credentials = {
|
val credentials = {
|
||||||
val map = new HashMap[Int, Medium]
|
val map = new HashMap[Int, Medium]
|
||||||
@ -78,7 +81,7 @@ private object Medium {
|
|||||||
meds += (("email", EMail.send _))
|
meds += (("email", EMail.send _))
|
||||||
}
|
}
|
||||||
|
|
||||||
def send(m : Medium, msg: String) {
|
def send(m: Medium, msg: String) {
|
||||||
val pf = meds.get(m.identifier).get
|
val pf = meds.get(m.identifier).get
|
||||||
pf(msg, m.recip)
|
pf(msg, m.recip)
|
||||||
}
|
}
|
||||||
@ -90,11 +93,11 @@ private class Medium(identifier_ : String, recip_ : String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private trait Protocol {
|
private trait Protocol {
|
||||||
def send(msg : String, recip : String)
|
def send(msg: String, recip: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
private object EMail extends Protocol {
|
private object EMail extends Protocol {
|
||||||
override def send(msg : String, recip : String) = {
|
override def send(msg: String, recip: String) = {
|
||||||
val props = new Properties()
|
val props = new Properties()
|
||||||
val config = XML.loadFile("alert-config.xml") \\ "credentials"
|
val config = XML.loadFile("alert-config.xml") \\ "credentials"
|
||||||
val sender = config \ "user" text
|
val sender = config \ "user" text
|
||||||
|
@ -5,8 +5,9 @@ import java.util.concurrent.CopyOnWriteArrayList
|
|||||||
import org.moparscape.msc.gs.Server
|
import org.moparscape.msc.gs.Server
|
||||||
import org.moparscape.msc.gs.core.DelayedEventHandler
|
import org.moparscape.msc.gs.core.DelayedEventHandler
|
||||||
import org.moparscape.msc.gs.event.DelayedEvent
|
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.config.Config
|
||||||
|
import org.moparscape.msc.gs.alert.AlertHandler
|
||||||
|
|
||||||
object OSLevelBlocking {
|
object OSLevelBlocking {
|
||||||
|
|
||||||
@ -27,12 +28,14 @@ object OSLevelBlocking {
|
|||||||
case e: Exception => {
|
case e: Exception => {
|
||||||
Logger.error(e)
|
Logger.error(e)
|
||||||
Logger.println("Failed to unblock " + ip)
|
Logger.println("Failed to unblock " + ip)
|
||||||
|
AlertHandler.sendAlert("Failed to unblock " + ip, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Runtime.getRuntime.exec(Config.BLOCK_COMMAND.replaceAll("${ip}", ip));
|
Runtime.getRuntime.exec(Config.BLOCK_COMMAND.replaceAll("${ip}", ip));
|
||||||
blocked.add(ip)
|
blocked.add(ip)
|
||||||
|
AlertHandler.sendAlert("Blocked " + ip, blocked.size / 10);
|
||||||
Logger.println("Blocked " + ip)
|
Logger.println("Blocked " + ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user