diff 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
line wrap: on
line diff
--- a/rlgwebd.js	Thu May 17 09:32:19 2012 -0700
+++ b/rlgwebd.js	Sun May 20 15:52:07 2012 -0700
@@ -296,7 +296,12 @@
     // check the password
     if (code != 0) {
       sendError(res, 3);
-      console.log("Password check failed for user " + username);
+      if (code == 1)
+        console.log("Password check failed for user " + username);
+      else if (code == 2)
+        console.log("Attempted login by nonexistent user " + username);
+      else
+        console.log("Login failed: sqlickrypt error " + code);
       return;
     }
     // check for an existing game
@@ -306,6 +311,7 @@
         for (var i = 0; i < files.length; i++) {
           if (files[i].match(fre)) {
             sendError(res, 4, null);
+            console.log(username + " is already playing " + gname);
             return;
           }
         }
@@ -314,27 +320,10 @@
       startgame();
     });
   }
-  /* Look for the user in the password file */
-  fs.readFile(passwdfile, "utf8", function(err, data) {
-    if (err) {
-      sendError(res, 3);
-      console.log("Can't authenticate: " + err.toString());
-      return;
-    }
-    var dlines = data.split('\n');
-    for (var n = 0; n < dlines.length; n++) {
-      var fields = dlines[n].split(':');
-      if (fields[0] == username) {
-        // check the password with the quickrypt utility
-        checker = require('child_process').spawn("/bin/quickrypt")
-        checker.on("exit", checkit);
-        checker.stdin.end(password + '\n' + fields[2] + '\n', "utf8");
-        return;
-      }
-    }
-    sendError(res, 3);
-    console.log("Attempted login by nonexistent user " + username);
-  });
+  /* Launch the sqlickrypt utility to check the password. */
+  var checker = require('child_process').spawn("/bin/sqlickrypt");
+  checker.on("exit", checkit);
+  checker.stdin.end(username + '\n' + password + '\n', "utf8");
   return;
 }