mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-07-13 07:24:57 +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
|
val GenericResponseEnvelope(_, guid, reply) = envelope
|
||||||
//try the expected handler with the input response
|
//try the expected handler with the input response
|
||||||
val filter = HandlerFilter.set(data.handlerFilter, guid, data.player)
|
val filter = HandlerFilter.set(data.handlerFilter, guid, data.player)
|
||||||
if (responseHandler.isDefinedAt(reply)) {
|
if (!responseHandler.tryToApply(reply)) {
|
||||||
responseHandler.receive.apply(reply)
|
|
||||||
} else {
|
|
||||||
//find any handler that might receive the response (ignore guard booleans during search)
|
//find any handler that might receive the response (ignore guard booleans during search)
|
||||||
data.handlerFilter.set(guid, guid, notSame = true, same = true)
|
data.handlerFilter.set(guid, guid, notSame = true, same = true)
|
||||||
if (!responseHandler.isDefinedAt(reply)) {
|
if (!responseHandler.isDefinedAt(reply)) {
|
||||||
val potentiallyValidHandlers = listOfHandlers.filter(_.isDefinedAt(reply))
|
val potentiallyValidHandlers = listOfHandlers.filter(_.isDefinedAt(reply))
|
||||||
if (potentiallyValidHandlers.nonEmpty) {
|
if (potentiallyValidHandlers.nonEmpty) {
|
||||||
data.handlerFilter.set(filter)
|
data.handlerFilter.set(filter)
|
||||||
potentiallyValidHandlers
|
potentiallyValidHandlers.find(_.tryToApply(reply))
|
||||||
.find(_.isDefinedAt(reply))
|
|
||||||
.foreach(_.receive.apply(reply))
|
|
||||||
} else {
|
} else {
|
||||||
log.error(s"received completely unhandled response message - $envelope for ${envelope.stamp}")
|
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 handle(toChannel: String, guid: PlanetSideGUID, reply: EventResponse): Unit
|
||||||
|
|
||||||
def handleWith(guid: PlanetSideGUID): Receive
|
|
||||||
|
|
||||||
def handleWith(filter: HandlerFilter): Receive
|
|
||||||
|
|
||||||
def receive: Receive
|
def receive: Receive
|
||||||
|
|
||||||
def isDefinedAt(x: Any): Boolean = receive.isDefinedAt(x)
|
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 {
|
trait CommonHandlerFunctions extends CommonHandlerFunctionsBase {
|
||||||
|
|
@ -89,15 +91,5 @@ trait CommonHandlerFunctions extends CommonHandlerFunctionsBase {
|
||||||
receive.apply(reply)
|
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
|
def receive: Receive
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue