[pypy-svn] r28766 - in pypy/dist/pypy/translator/js/proxy/testme: . static/javascript

ericvrp at codespeak.net ericvrp at codespeak.net
Wed Jun 14 12:43:12 CEST 2006


Author: ericvrp
Date: Wed Jun 14 12:43:08 2006
New Revision: 28766

Modified:
   pypy/dist/pypy/translator/js/proxy/testme/controllers.py
   pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
   pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
Log:
slight refactoring and working towards supporting protocol version #2


Modified: pypy/dist/pypy/translator/js/proxy/testme/controllers.py
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/controllers.py	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/controllers.py	Wed Jun 14 12:43:08 2006
@@ -30,6 +30,7 @@
         if sm.socket is None:
             sm.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             sm.socket.connect((self.host, self.port))
+            sm.socket.send(message(CMSG_PROTO_VERSION, 1))  #XXX we would like version 2
             #XXX todo: session.socket.close() after a timeout
         return sm.socket
 
@@ -40,9 +41,8 @@
         return dict()
 
     @expose(format='json')
-    def send(self, data=message(CMSG_PING)):
-        self.sessionSocket().send(data)
-        log('SENT: %s' % repr(data))
+    def ping(self):
+        self.sessionSocket().send(message(CMSG_PING))
         return self.recv()
 
     @expose(format='json')
@@ -68,7 +68,8 @@
         sm.data = data
         #log('RECEIVED DATA REMAINING CONTAINS %d BYTES' % len(data))
 
-        log('MESSAGES:%s' % messages)
+        if messages:
+            log('MESSAGES:%s' % messages)
         return dict(messages=messages)
 
     def _close(self):

Modified: pypy/dist/pypy/translator/js/proxy/testme/servermessage.py
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/servermessage.py	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/servermessage.py	Wed Jun 14 12:43:08 2006
@@ -115,7 +115,12 @@
     def def_key(self, keyname, num, *ico_codes):
         log('MESSAGE:def_key keyname=%s, num=%d, ico_codes=%s' % (keyname, num, str(ico_codes)))
         return dict(type=PMSG_DEF_KEY, keyname=keyname, num=num, ico_codes=ico_codes)
- 
+
+    def md5_file(self, fileid, protofilepath, offset, len_data, checksum):
+        log('MESSAGE:md5_file fileid=%d, protofilepath=%s, offset=%d, len_data=%d, checksum=...' % (
+            fileid, protofilepath, offset, len_data))
+        #skip for now...
+
     MESSAGES = {
         MSG_BROADCAST_PORT : broadcast_port,
         MSG_PING           : ping,
@@ -126,4 +131,5 @@
         MSG_PLAYER_JOIN    : player_join,
         MSG_PONG           : pong,
         MSG_DEF_KEY        : def_key,
+        MSG_MD5_FILE       : md5_file,
         }

Modified: pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js
==============================================================================
--- pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js	(original)
+++ pypy/dist/pypy/translator/js/proxy/testme/static/javascript/bnb.js	Wed Jun 14 12:43:08 2006
@@ -5,7 +5,7 @@
 	x = 0; y = 0; //for filling the playfield with loaded icons
 	doc = currentDocument();
 	body = doc.body;
-	sendToServer();
+	sendPing();
 }
 
 function BnBColorToHexString(c) {
@@ -15,27 +15,31 @@
 	return Color.fromRGB(r,g,b).toHexString();
 }
 
-function sendToServer() { //XXX for now, just get (proxy) server data
-    loadJSONDoc('send').addCallback(
-        function (json_doc) {
-            for (var i in json_doc.messages) {
-                var msg = json_doc.messages[i];
-		if (msg.type == 'def_playfield') { //XXX refactor to helper functions
-		    var bgcolor = BnBColorToHexString(msg.backcolor);
-		    updateNodeAttributes(playfield,
-			{'bgcolor':bgcolor, 'width':msg.width, 'height':msg.height});
-		    replaceChildNodes(body, playfield);
-		    body.setAttribute('bgcolor', bgcolor); //XXX hack!
-		} else if (msg.type == 'def_icon') {
-		    if (!(msg.code in icon)) {
-			icon[msg.code] = true; //new Image();
-			var img = IMG({'src':msg.filename, 'title':msg.filename,
-				'width':msg.width, 'height':msg.height});
-			appendChildNodes(playfield, img);
-		    }
-		}
+function handleServerResponse(json_doc) {
+    for (var i in json_doc.messages) {
+        var msg = json_doc.messages[i];
+        if (msg.type == 'def_playfield') { //XXX refactor to helper functions
+            var bgcolor = BnBColorToHexString(msg.backcolor);
+            updateNodeAttributes(playfield,
+                {'bgcolor':bgcolor, 'width':msg.width, 'height':msg.height});
+            replaceChildNodes(body, playfield);
+            body.setAttribute('bgcolor', bgcolor); //XXX hack!
+        } else if (msg.type == 'def_icon') {
+            if (!(msg.code in icon)) {
+                icon[msg.code] = new Image();
+                //icon[msg.code].src = msg.filename;
+                var img = IMG({'src':msg.filename, 'title':msg.filename,
+                    'width':msg.width, 'height':msg.height});
+                appendChildNodes(playfield, img);
             }
-            sendToServer();
         }
-    );
+        else {
+            logWarning('unknown msg.type: ' + msg.type + ', msg: ' + msg);
+        }
+    }
+    sendPing();
+}
+
+function sendPing() {
+    loadJSONDoc('ping').addCallback(handleServerResponse);
 }



More information about the Pypy-commit mailing list