root/trunk/rms-web/rms.php

Revision 4570, 4.3 kB (checked in by erijo, 2 years ago)

Undo r4567 since rms-web has not been replaced by licqweb.
Also fixed most of the images (they were broken) by copying them from
licqweb.

  • Property svn:eol-style set to native
Line 
1<?php
2
3include "config.php";
4
5function readSocket()
6{
7  global $sock, $packet;
8  $packet = "";
9  $packet = socket_read($sock, 512, PHP_NORMAL_READ);
10}
11
12function sendData($cmd)
13{
14  global $sock;
15  socket_write($sock, $cmd, strlen($cmd));
16}
17
18function rmsLogin($uin, $passwd)
19{
20  global $errmsg, $sock, $server, $port, $loggedIn;
21 
22  if ($loggedIn == true)
23    return;
24   
25  $loggedIn = true;
26 
27  // Connect to the RMS server
28  socket_connect($sock, $server, $port);
29   
30  // Get the version prompt
31  $packet = socket_read($sock, 512, PHP_NORMAL_READ);
32 
33  // Get the UIN prompt
34  $packet = socket_read($sock, 512, PHP_NORMAL_READ);
35 
36  if (!preg_match("/^300\s{1}.*/", $packet))
37  {
38     echo "Invalid response";
39     socket_close($sock);
40     $sock = 0;
41     $loggedIn = false;
42     return false;
43  }
44   
45  //sendData($uin);
46  socket_write($sock, $uin, strlen($uin));
47   
48  $packet = socket_read($sock, 512, PHP_NORMAL_READ);
49 
50  if (!preg_match("/^301\s{1}.*/", $packet))
51  {
52    echo "Invalid response";
53    socket_close($sock);
54    $sock = 0;
55    $loggedIn = false;
56    return false;
57  }
58   
59  sendData($passwd);
60 
61  $packet = socket_read($sock, 512, PHP_NORMAL_READ);
62   
63  if (!preg_match("/^200\s{1}.*/", $packet))
64  {
65    $errmsg = $packet;
66    socket_close($sock);
67    $sock = 0;
68    $loggedIn = false;
69    return false;
70  }
71 
72  $_SESSION["username"] = $uin;
73  $_SESSION["password"] = $passwd;
74
75    return true;
76}
77
78function rmsGetOwnerStatus()
79{
80  global $sock, $ownerStatus;
81  $packet = " ";
82  $cmd = "STATUS\r\n";
83   
84  if ($sock == 0) return;
85 
86  socket_write($sock, $cmd, strlen($cmd));
87  $packet = socket_read($sock, 512, PHP_NORMAL_READ);
88 
89  if (preg_match("/^202\s{1}.*/", $packet))
90  {
91    //TODO Handle all the protocols seperately
92    $i = 5;
93    while ($packet{$i} == ' ')
94    {
95      $i++;
96    }
97   
98    $ownerStatus = "";
99    while ($i < strlen($packet))
100    {
101      if ($packet{$i} != "\n")
102        $ownerStatus .= $packet{$i};
103      $i++;
104    } 
105  }
106  else
107  {
108    $ownerStatus = "Unknown";
109  }
110}
111
112function rmsChangeStatus($newStatus)
113{
114  global $sock, $ownerStatus;
115  $packet = " ";
116  $cmd = "STATUS " . $newStatus . "\r\n";
117 
118  if ($sock == 0) return;
119 
120  socket_write($sock, $cmd, strlen($cmd));
121  $packet = socket_read($sock, 512, PHP_NORMAL_READ);
122}
123
124function rmsGetlist()
125{
126  global $sock, $allusers, $showonlyonline, $userArray;
127  $packet = " ";
128  $cmd = "LIST";
129  $cmd .= "\r\n";
130 
131  if ($sock == 0) return;
132 
133  socket_write($sock, $cmd, strlen($cmd));
134  $packet = socket_read($sock, 512, PHP_NORMAL_READ);
135 
136  while (!preg_match("/^206$/", $packet))
137  {
138    if (preg_match("/^204\s{1}.*/", $packet))
139    {
140      $id = " ";
141      $status = " ";
142      $nick = " ";
143      $newmsgs = " ";
144      $pp = " ";
145     
146      // We have a user now, time to manipulate the string!
147      $i = 3;
148      while ($packet{$i} == ' ')
149      {
150        $i++;
151      }
152     
153      // Grab the id
154      while ($packet{$i} != ' ')
155      {
156        $id .= $packet{$i};
157        $i++;
158      }
159      $id = trim($id);
160     
161      while ($packet{$i} == ' ')
162        $i++;
163       
164      // Grab the Protocol
165      while ($packet{$i} != ' ')
166      {
167        $pp .= $packet{$i};
168        $i++;
169      }
170      $stop = $i;
171      $pp = trim($pp);
172     
173      // Grab the status
174      $i = strlen($packet) - 1;
175      while ($packet{$i} == ' ')
176        $i--;
177      while (!($packet{$i} >= '0' && $packet{$i} <= '9'))
178      {
179        $status .= $packet{$i};
180        $i--;
181      }
182      $status = strrev($status);
183      $status = trim($status);
184     
185      // Grab the number of new messages
186      while ($packet{$i} == ' ')
187        $i--;
188      while ($packet{$i} != ' ')
189      {
190        $newmsgs .= $packet{$i};
191        $i--;
192      }
193      $newmsgs = strrev($newmsgs);
194      $newmsgs = trim($newmsgs);
195     
196      // Grab the nick
197      while ($packet{$i} == ' ')
198        $i--;
199      while ($i > $stop)
200      {
201        $nick .= $packet{$i};
202        $i--;
203      }
204      $nick = strrev($nick);
205      $nick = trim($nick);
206     
207      // Now we have a user, lets build a list struct then display the list
208      $user = array($id, $nick, $newmsgs, $status, $pp);
209      if ($allusers == 0)
210        $allusers = array($user);
211      else
212        array_push($allusers, $user);
213       
214      $packet = socket_read($sock, 512, PHP_NORMAL_READ);
215    }
216  }
217}
218
219?>
Note: See TracBrowser for help on using the browser.