You know the game, fix URL, EOL.
[vomak.git] / irc_users.php
blob71360e91d4d62e76e005d34f0b5571e6d8c4a766
1 <?php
2 /*
3 * irc_users.php - this file is part of vomak - a very simple IRC bot
5 * Copyright 2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 /* This is a sample implementation in PHP to connect to vomak's socket
23 * and send/retrieve some data */
26 function not_empty($var)
28 return ($var != "");
32 $socket = @socket_create(AF_UNIX, SOCK_STREAM, 0);
33 if (! $socket)
35 echo "socket_create() failed:\nreason: " . socket_strerror($socket) . "\n";
37 else
39 $result = @socket_connect($socket, "/var/tmp/vomak_socket");
40 if (! $result)
42 echo "socket_connect() failed.\reason: " . socket_strerror($result) . "\n";
44 else
46 socket_write($socket, "userlist\r\n", 10);
47 $users_tmp = socket_read($socket, 2048);
48 socket_close($socket);
50 $users_tmp = str_replace("@ChanServ", "", $users_tmp);
51 $users_tmp = str_replace("GeanyBot", "", $users_tmp);
52 // remove op indicator
53 $users_tmp = str_replace("@", "", $users_tmp);
54 $users = explode(" ", trim($users_tmp));
55 //print_r($users);
56 $users = array_filter($users, "not_empty");
57 $user_count = count($users);
59 echo "Currently $user_count users are connected:<br/>";
60 foreach ($users as $u)
62 echo "$u ";