aboutsummaryrefslogtreecommitdiff
path: root/servermessage.py
diff options
context:
space:
mode:
authorDeclan Hoare <[email protected]>2020-04-16 22:58:21 +1000
committerDeclan Hoare <[email protected]>2020-04-16 23:10:44 +1000
commit7000fce72fbec34c6f4957a59d4146cc7148ee59 (patch)
tree5affe93d68a7fbcc6cf85a4d9a3eedecc730d1f7 /servermessage.py
downloadshiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.tar.gz
shiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.tar.bz2
shiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.zip
Initial Release
Diffstat (limited to 'servermessage.py')
-rw-r--r--servermessage.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/servermessage.py b/servermessage.py
new file mode 100644
index 0000000..d53e254
--- /dev/null
+++ b/servermessage.py
@@ -0,0 +1,24 @@
+
+from netclass import netclass
+from netobject import NetObject, NetObjectStream
+
+ServerMessage = netclass("ShiftOS.Objects.ServerMessage",
+ "ShiftOS.Objects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
+ [(str, "Name"), (str, "Contents"), (str, "GUID")])
+
+class ServerMessageStream(NetObjectStream):
+ def netObjectReceived(self, obj):
+ if not isinstance(obj.Object, ServerMessage):
+ raise TypeError(f"An object was received on the ServerMessageStream of type {type(obj.Object)}")
+
+ self.serverMessageReceived(obj.Object)
+
+ def sendServerMessage(self, message):
+ if not isinstance(message, ServerMessage):
+ raise TypeError(f"The ServerMessageStream can only send ServerMessage, not {type(obj)}")
+
+ # Although the real ShiftOS fills in the Name field on the
+ # NetObject, it does not ever read it, so it's not really
+ # part of the protocol.
+ self.sendNetObject(NetObject(None, message))
+