2a6545187f5e6ff8bd0895d1460fc2120e161b07
[citadel.git] / ctdlphp / ctdlprotocol.php
1 <?PHP
2
3 // $Id$
4 // 
5 // Implements various Citadel server commands.
6 //
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.
9 //
10
11
12 //
13 // serv_gets() -- generic function to read one line of text from the server
14 //
15 function serv_gets() {
16         global $clientsocket;
17
18         $buf = fgets($clientsocket, 4096);              // Read line
19         $buf = substr($buf, 0, (strlen($buf)-1) );      // strip trailing LF
20         return $buf;
21 }
22
23
24 //
25 // serv_puts() -- generic function to write one line of text to the server
26 //
27 function serv_puts($buf) {
28         global $clientsocket;
29         
30         fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) );
31 }
32
33
34 //
35 // Learn all sorts of interesting things about the Citadel server to
36 // which we are connected.
37 //
38 function ctdl_get_serv_info() {
39         global $serv_humannode;
40         global $serv_software;
41
42         serv_puts("INFO");
43         serv_gets($buf);
44         if (substr($buf, 0, 1) == "1") {
45                 $i = 0;
46                 do {
47                         $buf = serv_gets();
48                         if ($i == 2) $serv_humannode = $buf;
49                         if ($i == 4) $serv_software = $buf;
50                         $i = $i + 1;
51                 } while ($buf != "000");
52         }
53
54 }
55
56
57
58 function test_for_echo() {
59
60         global $clientsocket, $session;
61
62         $command = "ECHO Video vertigo ... test for echo.";
63
64         serv_puts($command);
65         $response = serv_gets();
66         echo $response, "<BR>";
67         flush();
68 }
69
70 function ctdl_mesg($msgname) {
71         global $clientsocket;
72
73         serv_puts("MESG " . $msgname);
74         $response = serv_gets();
75         
76         if (substr($response, 0, 1) == "1") {
77                 echo "<DIV ALIGN=CENTER>\n";
78                 do {
79                         $buf = serv_gets();
80                         if ($buf != "000") {
81                                 echo "<TT>", $buf, "</TT><BR>\n" ;
82                         }
83                 } while ($buf != "000");
84                 echo "</DIV>\n";
85         }
86         else {
87                 echo "<B><I>", substr($response, 4), "</I></B><BR>\n";
88         }
89 }
90
91 ?>