From: <Blu...@us...> - 2010-08-24 23:40:57
|
Revision: 369 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=369&view=rev Author: BlueWolf_ Date: 2010-08-24 23:40:51 +0000 (Tue, 24 Aug 2010) Log Message: ----------- Added the possibility for the client to send and receive custom commands to app directly, making it easier to send stuff like money Modified Paths: -------------- trunk/client/core/callback.py trunk/client/core/client.py trunk/client/core/parser.py Modified: trunk/client/core/callback.py =================================================================== --- trunk/client/core/callback.py 2010-08-23 21:59:40 UTC (rev 368) +++ trunk/client/core/callback.py 2010-08-24 23:40:51 UTC (rev 369) @@ -101,6 +101,20 @@ """ pass + def custom_receive(self, header, body): + """ + This is when custom data from the server's app has been send. This can + be used to send custom stuff like money e.d + + header: + What type the body is (string) + body: + The body of the message (can basically be every kind of object) + + This is a placeholder. If you want to catch this event, overwrite this + in your own callback + """ + def logged_in(self, username, cid, owner): """ Called when we are logged in. Modified: trunk/client/core/client.py =================================================================== --- trunk/client/core/client.py 2010-08-23 21:59:40 UTC (rev 368) +++ trunk/client/core/client.py 2010-08-24 23:40:51 UTC (rev 369) @@ -288,6 +288,16 @@ try: self.__sock.send(data + chr(1)) except: pass + + + def custom_send(self, data_header, data_body = {}): + """ + Sends custom data 'data_body' of type 'data_header' directly to the + others custom_receive of the server's app. This can be used to send + money and other custom events. + """ + + self.send("custom", {"header": data_header, "body": data_body}) def close(self, reason = "manual"): Modified: trunk/client/core/parser.py =================================================================== --- trunk/client/core/parser.py 2010-08-23 21:59:40 UTC (rev 368) +++ trunk/client/core/parser.py 2010-08-24 23:40:51 UTC (rev 369) @@ -105,7 +105,7 @@ def useronline(self, msg): """ - Called after a user (or bot) has signed on. + Called after an user (or bot) has signed on. * cid - The unique ID for this connection * user - The username * app - [Appname, Appversion] @@ -123,7 +123,7 @@ def useroffline(self, msg): """ - Some user has gone offline + An user has gone offline * cid - The connection-id for this client """ @@ -154,4 +154,16 @@ self.call.failed_logging_in("login blocked") elif msg['reason'] == "duplicate user": self.call.failed_logging_in("duplicate user") + + def custom(self, msg): + """ + A custom command send from the server' app. + * header: + The type of the message + * body: + The message itself + """ + + self.call.custom(msg['header'], msg['body']) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |