]> code.citadel.org Git - citadel.git/blobdiff - ctdlphp/ctdlprotocol.php
* Identify ourselves to Citadel using IDEN
[citadel.git] / ctdlphp / ctdlprotocol.php
index 2fd38d4f3a16dae766565b65b1bfd3af10d1f0d8..e197952cdf304a64191ebe850effbf5849d56a8a 100644 (file)
@@ -30,6 +30,20 @@ function serv_puts($buf) {
        fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) );
 }
 
+
+
+//
+// Identify this client, and the hostname where the user is, to Citadel.
+//
+function ctdl_iden() {
+       global $clientsocket;
+
+       serv_puts("IDEN 0|8|001|PHP web client|" . $_SERVER['REMOTE_ADDR'] );
+       $buf = serv_gets();
+}
+
+
+
 //
 // login_existing_user() -- attempt to login using a supplied username/password
 // Returns an array with two variables:
@@ -145,12 +159,9 @@ function ctdl_mesg($msgname) {
        
        if (substr($response, 0, 1) == "1") {
                echo "<DIV ALIGN=CENTER>\n";
-               do {
-                       $buf = serv_gets();
-                       if (strcasecmp($buf, "000")) {
-                               echo "<TT>", $buf, "</TT><BR>\n" ;
-                       }
-               } while (strcasecmp($buf, "000"));
+               while (strcmp($buf = serv_gets(), "000")) {
+                       echo "<TT>", $buf, "</TT><BR>\n" ;
+               }
                echo "</DIV>\n";
        }
        else {
@@ -159,4 +170,50 @@ function ctdl_mesg($msgname) {
 }
 
 
+//
+// Fetch the list of users currently logged in.
+//
+function ctdl_rwho() {
+       global $clientsocket;
+
+       serv_puts("RWHO");
+       $response = serv_gets();
+
+       if (substr($response, 0, 1) != "1") {
+               return array(0, NULL);
+       }
+       
+       $all_lines = array();
+       $num_lines = 0;
+
+       while (strcmp($buf = serv_gets(), "000")) {
+
+               $thisline = array();
+
+               $tok = strtok($buf, "|");
+               if ($tok) $thisline["session"] = $tok;
+
+               $tok = strtok("|");
+               if ($tok) $thisline["user"] = $tok;
+               
+               $tok = strtok("|");
+               if ($tok) $thisline["room"] = $tok;
+               
+               $tok = strtok("|");
+               if ($tok) $thisline["host"] = $tok;
+               
+               $tok = strtok("|");
+               if ($tok) $thisline["client"] = $tok;
+
+               // IGnore the rest of the fields for now.
+
+               $num_lines = array_push($all_lines, $thisline);
+       }
+
+       return array($num_lines, $all_lines);
+
+}
+
+
+
 ?>