Change ingoing message path to reroute through serversession.data_in before calling the inputfuncs. This allows users to view all incoming data in one place if they want to do eventual pre-processing. Resolves #1163.

This commit is contained in:
Griatch 2017-01-14 12:28:07 +01:00
parent 44bd403cc8
commit a403cc9576
2 changed files with 33 additions and 4 deletions

View file

@ -373,11 +373,25 @@ class ServerSession(Session):
"""
self.sessionhandler.data_out(self, **kwargs)
def data_in(self, **kwargs):
"""
Receiving data from the client, sending it off to
the respective inputfuncs.
Kwargs:
kwargs (any): Incoming data from protocol on
the form `{"commandname": ((args), {kwargs}),...}`
Notes:
This method is here in order to give the user
a single place to catch and possibly process all incoming data from
the client. It should usually always end by sending
this data off to `self.sessionhandler.call_inputfuncs(self, **kwargs)`.
"""
self.sessionhandler.call_inputfuncs(self, **kwargs)
def msg(self, text=None, **kwargs):
"""
Wrapper to mimic msg() functionality of Objects and Players
(server sessions don't use data_in since incoming data is
handled by inputfuncs).
Wrapper to mimic msg() functionality of Objects and Players.
Args:
text (str): String input.

View file

@ -691,7 +691,22 @@ class ServerSessionHandler(SessionHandler):
def data_in(self, session, **kwargs):
"""
Data Portal -> Server.
We let the data take a "detour" to session.data_in
so the user can override and see it all in one place.
That method is responsible to in turn always call
this class' `sessionhandler.call_inputfunc` with the
(possibly processed) data.
"""
if session:
session.data_in(**kwargs)
def call_inputfuncs(self, session, **kwargs):
"""
Split incoming data into its inputfunc counterparts.
This should be called by the serversession.data_in
as sessionhandler.call_inputfunc(self, **kwargs).
We also intercept OOB communication here.
Args: