Mercurial > hg > udpmsg3
annotate client/debugclient.php @ 1:7f01316130e8
Basic support for private messages in unrealircd proxy
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Fri, 01 Apr 2011 17:02:41 +0200 |
parents | dd81c38b513a |
children | 7e342a0a3b74 |
rev | line source |
---|---|
0 | 1 <?php |
2 /* Copyright 2010 Ivo Smits <Ivo@UCIS.nl>. All rights reserved. | |
3 Redistribution and use in source and binary forms, with or without modification, are | |
4 permitted provided that the following conditions are met: | |
5 | |
6 1. Redistributions of source code must retain the above copyright notice, this list of | |
7 conditions and the following disclaimer. | |
8 | |
9 2. Redistributions in binary form must reproduce the above copyright notice, this list | |
10 of conditions and the following disclaimer in the documentation and/or other materials | |
11 provided with the distribution. | |
12 | |
13 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
14 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
15 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR | |
16 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
17 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
18 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
19 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
20 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
21 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
22 | |
23 The views and conclusions contained in the software and documentation are those of the | |
24 authors and should not be interpreted as representing official policies, either expressed | |
25 or implied, of Ivo Smits.*/ | |
26 | |
27 $server = '127.0.0.1:15387'; | |
28 | |
29 $socket = stream_socket_client('tcp://'.$server) or die("Could not create socket\n"); | |
1
7f01316130e8
Basic support for private messages in unrealircd proxy
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
30 stream_set_timeout($socket, -1); |
0 | 31 $buffer = ''; |
32 | |
33 while (TRUE) { | |
34 $msg = fread($socket, 1024); | |
35 if (!strlen($msg)) die("Error: end of file\n"); | |
36 $buffer .= $msg; | |
37 while (strlen($buffer) > 2) { | |
38 $len = ord($buffer[0]) * 256 + ord($buffer[1]); | |
39 if ($len <= 0 || $len > 1024) die("Error: protocol error\n"); | |
40 if (strlen($buffer) < 2 + $len) break; | |
41 $msg = substr($buffer, 2, $len); | |
42 $buffer = substr($buffer, 2 + $len); | |
43 printf('Received message: '); | |
44 $parts = explode("\0", $msg); | |
45 $ret = array(); | |
46 for ($i = 0; $i < count($parts)-1; $i += 2) $ret[$parts[$i]] = $parts[$i+1]; | |
47 print_r($ret); | |
48 } | |
49 unset($msg, $len, $parts, $ret); | |
50 } |