Skip to content

Commit

Permalink
Refactor the comet view into a binary application so that an upstream…
Browse files Browse the repository at this point in the history
… app can feed it player info
  • Loading branch information
eee-c committed May 14, 2010
1 parent 7aa4987 commit 6525949
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions game.js
Expand Up @@ -23,25 +23,7 @@ with ( require( "fab" ) )

( /^\/comet_view/ )
( init_comet )

(
function() {
var out = this;
return function( head ) {
var search = head.url.search.substring(1);
var q = require('querystring').parse(search);
for (var prop in q) {
puts(prop + ": " + q[prop]);
}
puts(q.x);


var app = out({ body: {x: q.x || 0, y: q.y || 0} });
if ( app ) app();
};
}
)

( player_from_querystring )

(/^\/(javascript|stylesheets)/)
(/^\/([_\w]+)\.(js|css)$/)
Expand Down Expand Up @@ -76,10 +58,10 @@ function init_comet (app) {
var out = this;

return app.call( function listener(obj) {

players.push( out );
out({ headers: { "content-type": "text/html" },
body: "<html><body>\n" })
if (obj && obj.body) {
players.push(out);
out({ headers: { "content-type": "text/html" },
body: "<html><body>\n" })

({body: "<script type=\"text/javascript\">\"123456789 123456789 123456789 123456789 123456789 12345\";</script>\n"})
({body: "<script type=\"text/javascript\">\"123456789 123456789 123456789 123456789 123456789 12345\";</script>\n"})
Expand All @@ -92,8 +74,23 @@ function init_comet (app) {
({body: "<script type=\"text/javascript\">\"123456789 123456789 123456789 123456789 123456789 12345\";</script>\n"})
({body: "<script type=\"text/javascript\">\"123456789 123456789 123456789 123456789 123456789 12345\";</script>\n"})
({body: "<script type=\"text/javascript\">\"123456789 123456789 123456789 123456789 123456789 12345\";</script>\n"});

}
return listener;
});
};
}

function player_from_querystring() {
var out = this;
return function(head) {
if (head.url.search) {
var search = head.url.search.substring(1);
var q = require('querystring').parse(search);
var app = out({ body: {id: q.id, x: q.x || 0, y: q.y || 0} });
if ( app ) app();
}
else {
out();
}
};
}

0 comments on commit 6525949

Please sign in to comment.