mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-06-25 06:44:19 +00:00
special applyOrElse and isDefinedAt and guards
This commit is contained in:
parent
1e34e8239c
commit
67990ecb83
2 changed files with 8 additions and 20 deletions
|
|
@ -401,18 +401,14 @@ class SessionActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], con
|
|||
val GenericResponseEnvelope(_, guid, reply) = envelope
|
||||
//try the expected handler with the input response
|
||||
val filter = HandlerFilter.set(data.handlerFilter, guid, data.player)
|
||||
if (responseHandler.isDefinedAt(reply)) {
|
||||
responseHandler.receive.apply(reply)
|
||||
} else {
|
||||
if (!responseHandler.tryToApply(reply)) {
|
||||
//find any handler that might receive the response (ignore guard booleans during search)
|
||||
data.handlerFilter.set(guid, guid, notSame = true, same = true)
|
||||
if (!responseHandler.isDefinedAt(reply)) {
|
||||
val potentiallyValidHandlers = listOfHandlers.filter(_.isDefinedAt(reply))
|
||||
if (potentiallyValidHandlers.nonEmpty) {
|
||||
data.handlerFilter.set(filter)
|
||||
potentiallyValidHandlers
|
||||
.find(_.isDefinedAt(reply))
|
||||
.foreach(_.receive.apply(reply))
|
||||
potentiallyValidHandlers.find(_.tryToApply(reply))
|
||||
} else {
|
||||
log.error(s"received completely unhandled response message - $envelope for ${envelope.stamp}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,13 +59,15 @@ trait CommonHandlerFunctionsBase {
|
|||
*/
|
||||
def handle(toChannel: String, guid: PlanetSideGUID, reply: EventResponse): Unit
|
||||
|
||||
def handleWith(guid: PlanetSideGUID): Receive
|
||||
|
||||
def handleWith(filter: HandlerFilter): Receive
|
||||
|
||||
def receive: Receive
|
||||
|
||||
def isDefinedAt(x: Any): Boolean = receive.isDefinedAt(x)
|
||||
|
||||
def tryToApply(x: Any): Boolean = {
|
||||
var passed = true
|
||||
receive.applyOrElse(x, (_: Any) => { passed = false })
|
||||
passed
|
||||
}
|
||||
}
|
||||
|
||||
trait CommonHandlerFunctions extends CommonHandlerFunctionsBase {
|
||||
|
|
@ -89,15 +91,5 @@ trait CommonHandlerFunctions extends CommonHandlerFunctionsBase {
|
|||
receive.apply(reply)
|
||||
}
|
||||
|
||||
def handleWith(guid: PlanetSideGUID): Receive = {
|
||||
HandlerFilter.set(sessionLogic.handlerFilter, guid, player)
|
||||
receive
|
||||
}
|
||||
|
||||
def handleWith(giveFilter: HandlerFilter): Receive = {
|
||||
sessionLogic.handlerFilter = giveFilter
|
||||
receive
|
||||
}
|
||||
|
||||
def receive: Receive
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue