# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# timeout function with args in convenient order
timeout = (ms, func) -> setTimeout func, ms
# timeout function with args in convenient order
timeout = (ms, func) -> setTimeout func, ms
str = str.replace clean_pathname_regex2, '/_'
return str.replace clean_pathname_regex3, '_'
str = str.replace clean_pathname_regex2, '/_'
return str.replace clean_pathname_regex3, '_'
-# serve javascript files from within /usr/share/javascript
-javascript_handler = (args, out, request, url_parts) ->
- filename = clean_pathname "/usr/share/#{url_parts.pathname}"
+# serve javascript files from within external/
+external_javascript_handler = (args, out, request, url_parts) ->
+ filename = clean_pathname "external/#{url_parts.pathname.substr 10}"
fs.readFile filename, 'utf8', (err, data) ->
if err
out.writeHead 404
fs.readFile filename, 'utf8', (err, data) ->
if err
out.writeHead 404
waiter.end JSON.stringify queue
# this marks a game as "dirty" and makes sure there's exactly one timeout
waiter.end JSON.stringify queue
# this marks a game as "dirty" and makes sure there's exactly one timeout
+long_poll_keepalive = ->
+ for slug, g of games
+ if g.p1_waiter? and g.p1_waiter isnt false
+ g.p1_waiter.write '\n'
+ if g.p2_waiter? and g.p2_waiter isnt false
+ g.p2_waiter.write '\n'
+
+interval 12000, long_poll_keepalive
+
http_server = http.createServer (req, res) ->
url_parts = url.parse req.url, true
if url_parts.query is undefined
http_server = http.createServer (req, res) ->
url_parts = url.parse req.url, true
if url_parts.query is undefined
- if rel_path.substr(0, 11) is 'javascript/'
- return javascript_handler url_parts.query, res, req, url_parts
+ if rel_path.substr(0, 9) is 'external/'
+ return external_javascript_handler url_parts.query, res, req, url_parts
else if rel_path.substr(rel_path.length - 4) is '.css'
res.writeHead 200, 'Content-Type': 'text/css'
return css_handler url_parts.query, res, req, url_parts
else if rel_path.substr(rel_path.length - 3) is '.js'
res.writeHead 200, 'Content-Type': 'text/javascript'
return js_handler url_parts.query, res, req, url_parts
else if rel_path.substr(rel_path.length - 4) is '.css'
res.writeHead 200, 'Content-Type': 'text/css'
return css_handler url_parts.query, res, req, url_parts
else if rel_path.substr(rel_path.length - 3) is '.js'
res.writeHead 200, 'Content-Type': 'text/javascript'
return js_handler url_parts.query, res, req, url_parts
query[key] = parg
return set_handler query, res, req, url_parts
return
query[key] = parg
return set_handler query, res, req, url_parts
return
return get_handler url_parts.query, res, req, url_parts
else if rel_path.substr(rel_path.length - 4) is '.ico'
res.writeHead 404
return get_handler url_parts.query, res, req, url_parts
else if rel_path.substr(rel_path.length - 4) is '.ico'
res.writeHead 404
return html_handler url_parts.query, res, req, url_parts
################## INIT ####################
return html_handler url_parts.query, res, req, url_parts
################## INIT ####################