5 // Implements various Citadel server commands.
7 // Copyright (c) 2003 by Art Cancro <ajc@uncensored.citadel.org>
8 // This program is released under the terms of the GNU General Public License.
13 // serv_gets() -- generic function to read one line of text from the server
15 function serv_gets() {
18 $buf = fgets($clientsocket, 4096); // Read line
19 $buf = substr($buf, 0, (strlen($buf)-1) ); // strip trailing LF
25 // serv_puts() -- generic function to write one line of text to the server
27 function serv_puts($buf) {
30 fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) );
34 // login_existing_user() -- attempt to login using a supplied username/password
35 // Returns an array with two variables:
36 // 0. TRUE or FALSE to determine success or failure
37 // 1. String error message (if relevant)
39 function login_existing_user($user, $pass) {
42 serv_puts("USER " . $user);
44 if (substr($resp, 0, 1) != "3") {
45 return array(FALSE, substr($resp, 4));
48 serv_puts("PASS " . $pass);
50 if (substr($resp, 0, 1) != "2") {
51 return array(FALSE, substr($resp, 4));
54 $_SESSION["username"] = $user;
55 $_SESSION["password"] = $pass;
56 become_logged_in(substr($resp, 4));
58 return array(TRUE, "Login successful. Have fun.");
63 // create_new_user() -- attempt to create a new user
64 // using a supplied username/password
65 // Returns an array with two variables:
66 // 0. TRUE or FALSE to determine success or failure
67 // 1. String error message (if relevant)
69 function create_new_user($user, $pass) {
72 serv_puts("NEWU " . $user);
74 if (substr($resp, 0, 1) != "2") {
75 return array(FALSE, substr($resp, 4));
78 serv_puts("SETP " . $pass);
80 if (substr($resp, 0, 1) != "2") {
81 return array(FALSE, substr($resp, 4));
84 $_SESSION["username"] = $user;
85 $_SESSION["password"] = $pass;
86 become_logged_in(substr($resp, 4));
88 return array(TRUE, "Login successful. Have fun.");
93 // Code common to both existing-user and new-user logins
95 function become_logged_in($server_parms) {
96 $_SESSION["logged_in"] = 1;
102 // Learn all sorts of interesting things about the Citadel server to
103 // which we are connected.
105 function ctdl_get_serv_info() {
108 if (substr($buf, 0, 1) == "1") {
112 if ($i == 2) $_SESSION["serv_humannode"] = $buf;
113 if ($i == 4) $_SESSION["serv_software"] = $buf;
115 } while (strcasecmp($buf, "000"));
122 // Temporary function to verify communication with the Citadel server.
124 function test_for_echo() {
125 global $clientsocket, $session;
127 $command = "ECHO Video vertigo ... test for echo.";
129 $response = serv_gets();
130 echo $response, "<BR>";
136 // Display a system banner.
137 // (This is probably temporary because it outputs more or less finalized
138 // markup. For now it's just usable.)
140 function ctdl_mesg($msgname) {
141 global $clientsocket;
143 serv_puts("MESG " . $msgname);
144 $response = serv_gets();
146 if (substr($response, 0, 1) == "1") {
147 echo "<DIV ALIGN=CENTER>\n";
150 if (strcasecmp($buf, "000")) {
151 echo "<TT>", $buf, "</TT><BR>\n" ;
153 } while (strcasecmp($buf, "000"));
157 echo "<B><I>", substr($response, 4), "</I></B><BR>\n";