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)
32 $socket = socket_create(AF_UNIX
, SOCK_STREAM
, 0);
35 echo "socket_create() failed:\nreason: " . socket_strerror($socket) . "\n";
38 $result = socket_connect($socket, "/var/tmp/vomak_socket");
41 echo "socket_connect() failed.\reason: ($result) " . socket_strerror($result) . "\n";
44 socket_write($socket, "userlist\r\n", 10);
45 $users_tmp = socket_read($socket, 2048);
46 socket_close($socket);
48 $users_tmp = str_replace("@ChanServ", "", $users_tmp);
49 $users_tmp = str_replace("GeanyBot", "", $users_tmp);
50 $users = explode(" ", trim($users_tmp));
52 $users = array_filter($users, "not_empty");
53 $user_count = count($users);
55 echo "Currently $user_count users are connected:<br/>";
56 foreach ($users as $u)