+ return array("state" => FALSE, "statereply" => $status);
+ }
+
+}
+
+
+
+//
+// Fetch the list of known rooms.
+//
+function ctdl_knrooms() {
+ global $clientsocket;
+
+ serv_puts("LKRA");
+ $response = serv_gets();
+ if (substr($response, 0, 1) != "1") {
+ return array(0, NULL);
+ }
+ $results = read_array();
+ $all_lines = array();
+ $num_lines = 0;
+
+ foreach ($results as $result){
+ $oneline = array();
+ $tokens = explode("|",$result);
+
+ $oneline["name"] = $tokens[0];
+ $oneline["flags"] = $tokens[1];
+ $oneline["floor"] = $tokens[2];
+ $oneline["order"] = $tokens[3];
+ $oneline["flags2"] = $tokens[4];
+ $oneline["access"] = $tokens[5];
+
+ if ($oneline["access"] & 8) {
+ $oneline["hasnewmsgs"] = TRUE;
+ }
+ else {
+ $oneline["hasnewmsgs"] = FALSE;
+ }
+
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ {
+ dbgprintf_wrapout("<pre>", false);
+ dbgprintf_wrapout(print_r($oneline, true), true);
+ dbgprintf_wrapout("</pre>", false);
+
+ }
+ $num_lines = array_push($all_lines, $oneline);
+ }
+
+ return array($num_lines, $all_lines);
+
+}
+
+//
+// Fetch the list of known floors.
+//
+/* http://www.citadel.org/doku.php/documentation:appproto:rooms#lflr.list.all.known.floors */
+function ctdl_knfloors() {
+ global $clientsocket;
+
+ serv_puts("LFLR");
+ $response = serv_gets();
+ if (substr($response, 0, 1) != "1") {
+ return array(0, NULL);
+ }
+
+ $results = read_array();
+ $all_lines = array();
+ $num_lines = 0;
+
+ foreach ($results as $result){
+ $oneline = array();
+ $tokens = explode("|",$result);
+
+ $oneline["id"] = $tokens[0];
+ $oneline["name"] = $tokens[1];
+ $oneline["nref"] = $tokens[2];
+
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ {
+ dbgprintf_wrapout("<pre>", false);
+ dbgprintf_wrapout(print_r($oneline, true), true);
+ dbgprintf_wrapout("</pre>", false);
+ }
+ $num_lines = array_push($all_lines, $oneline);
+ }
+
+ return array($num_lines, $all_lines);
+
+}
+
+/* http://www.citadel.org/doku.php/documentation:appproto:rooms#cflr.create.a.new.floor */
+
+//
+// Fetch the list of messages in one room.
+// Returns: count, response, message array
+//
+function ctdl_msgs($mode, $count) {
+ global $clientsocket;
+
+ serv_puts("MSGS " . $mode . "|" . $count);
+ $responses = read_array();
+ dbgprintf_wrapout(print_r($responses, true), false);
+
+ $response = array_shift($responses);
+
+ $num_msgs = count($responses);
+ if (substr($response, 0, 1) != "1") {
+ return array(0, substr($response, 4), NULL);
+ }
+
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ {
+ dbgprintf_wrapout("found ".$num_msgs." messages.", true);
+ }
+ return array($num_msgs, $response, $responses);
+}
+
+
+// Load a message from the server.
+function ctdl_fetch_message($msgnum) {
+ global $clientsocket;
+
+ serv_puts("MSG4 " . $msgnum);
+
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ dbgprintf_wrapout("<div class='ctdldbgRead'>", false);
+ $response = serv_gets(TRUE);
+
+ if (substr($response, 0, 1) != "1") {
+ return array(FALSE, substr($response, 4), NULL);
+ }
+
+ $fields = array();
+ while (strcmp($buf = serv_gets(TRUE), "000")) {
+ if (substr($buf, 0, 4) == "text") {
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ dbgprintf_wrapout("</div>\n<h3>Message Body Follows</h3><div class='ctdldbgRead'>", false);
+ // We're in the text body. New loop here.
+ $texts = ctdl_msg4_from_server();
+ $fields["text"] = $texts[0];
+ $fields["formated_text"]=$texts[1];
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ dbgprintf_wrapout ("</div>", false);
+ return array(TRUE, substr($response, 4), $fields);
+ }
+ else {
+ $fields[substr($buf, 0, 4)] = substr($buf, 5);
+ }
+ }
+
+ // Message terminated prematurely (no text body)
+ return array(FALSE, substr($response, 4), $fields);
+}
+
+// Load a message from the server.
+function ctdl_fetch_message_rfc822($msgnum) {
+ global $clientsocket;
+
+ serv_puts("MSG2 " . $msgnum);
+
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ dbgprintf_wrapout("<div class='ctdldbgRead'>", false);
+ $response = serv_gets(TRUE);
+
+ if (substr($response, 0, 1) != "1") {
+ return array(FALSE, NULL);
+ }
+ $message = "";
+ $buf="";
+ while ($buf = serv_gets(TRUE)) {
+// dbgprintf_wrapout($buf, true);
+ if ($buf=="000")
+ {
+ $message .= "\n.\n";
+ break;
+ }
+ $message = $message . "\n" . $buf;
+ $buf = "";