diff options
| author | Declan Hoare <[email protected]> | 2020-04-16 22:58:21 +1000 |
|---|---|---|
| committer | Declan Hoare <[email protected]> | 2020-04-16 23:10:44 +1000 |
| commit | 7000fce72fbec34c6f4957a59d4146cc7148ee59 (patch) | |
| tree | 5affe93d68a7fbcc6cf85a4d9a3eedecc730d1f7 /messagehandler.py | |
| download | shiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.tar.gz shiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.tar.bz2 shiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.zip | |
Initial Release
Diffstat (limited to 'messagehandler.py')
| -rw-r--r-- | messagehandler.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/messagehandler.py b/messagehandler.py new file mode 100644 index 0000000..dd061cc --- /dev/null +++ b/messagehandler.py @@ -0,0 +1,30 @@ + +from netclass.jsonconverter import from_json, to_json +from servermessage import ServerMessage + +handlers = {} +forwardhandlers = {} + +def handler(name, t = None, dct = handlers): + def decorator(fun): + dct[name] = (fun if t is None + else lambda conn, c, *a: fun(conn, from_json(t, c), *a)) + return fun + return decorator + +def forwardhandler(name, t = None): + return handler(name, t, dct = forwardhandlers) + +# "Forward" messages are meant to be sent to other clients, and the +# original server did this without validating them at all. This +# gives clients all the same power over each other as the server has +# over them, all the way up to arbitrary code execution...not a good +# idea. Instead forwards are treated as just a different kind of +# message for the server to handle. Forward-handlers get the GUID +# which in this case is a target, unlike normal handlers, where it is +# discarded because it is on the source connection. +@handler("mud_forward", ServerMessage) +def mud_forward(connection, contents): + if contents.Name in forwardhandlers: + return forwardhandlers[contents.Name](connection, contents.Contents, contents.GUID) + |
