comparison rlgwebd.js @ 17:d3e3d6b4016b

rlgwebd: switch to dgamelaunch's SQLite database. The quickrypt utility is replaced with sqlickrypt, which takes a username and password pair and checks them against the SQLite password database used by dgamelaunch. This will be more extensible to using rlgwebd to register, change passwords, etc.
author John "Elwin" Edwards <elwin@sdf.org>
date Sun, 20 May 2012 15:52:07 -0700
parents ef6127ed6da3
children 188bbd857124
comparison
equal deleted inserted replaced
16:ef6127ed6da3 17:d3e3d6b4016b
294 } 294 }
295 function checkit(code, signal) { 295 function checkit(code, signal) {
296 // check the password 296 // check the password
297 if (code != 0) { 297 if (code != 0) {
298 sendError(res, 3); 298 sendError(res, 3);
299 console.log("Password check failed for user " + username); 299 if (code == 1)
300 console.log("Password check failed for user " + username);
301 else if (code == 2)
302 console.log("Attempted login by nonexistent user " + username);
303 else
304 console.log("Login failed: sqlickrypt error " + code);
300 return; 305 return;
301 } 306 }
302 // check for an existing game 307 // check for an existing game
303 fs.readdir(progressdir, function(err, files) { 308 fs.readdir(progressdir, function(err, files) {
304 if (!err) { 309 if (!err) {
305 var fre = RegExp("^" + username + ":"); 310 var fre = RegExp("^" + username + ":");
306 for (var i = 0; i < files.length; i++) { 311 for (var i = 0; i < files.length; i++) {
307 if (files[i].match(fre)) { 312 if (files[i].match(fre)) {
308 sendError(res, 4, null); 313 sendError(res, 4, null);
314 console.log(username + " is already playing " + gname);
309 return; 315 return;
310 } 316 }
311 } 317 }
312 } 318 }
313 // If progressdir isn't readable, start a new game anyway. 319 // If progressdir isn't readable, start a new game anyway.
314 startgame(); 320 startgame();
315 }); 321 });
316 } 322 }
317 /* Look for the user in the password file */ 323 /* Launch the sqlickrypt utility to check the password. */
318 fs.readFile(passwdfile, "utf8", function(err, data) { 324 var checker = require('child_process').spawn("/bin/sqlickrypt");
319 if (err) { 325 checker.on("exit", checkit);
320 sendError(res, 3); 326 checker.stdin.end(username + '\n' + password + '\n', "utf8");
321 console.log("Can't authenticate: " + err.toString());
322 return;
323 }
324 var dlines = data.split('\n');
325 for (var n = 0; n < dlines.length; n++) {
326 var fields = dlines[n].split(':');
327 if (fields[0] == username) {
328 // check the password with the quickrypt utility
329 checker = require('child_process').spawn("/bin/quickrypt")
330 checker.on("exit", checkit);
331 checker.stdin.end(password + '\n' + fields[2] + '\n', "utf8");
332 return;
333 }
334 }
335 sendError(res, 3);
336 console.log("Attempted login by nonexistent user " + username);
337 });
338 return; 327 return;
339 } 328 }
340 329
341 function logout(term, res) { 330 function logout(term, res) {
342 if (!term.alive) { 331 if (!term.alive) {