1 /* statistics.c - NeonServ v5.6
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "statistics.h"
19 #include "ConfigParser.h"
20 #include "ClientSocket.h"
25 #include "IRCParser.h"
28 int statistics_requested_lusers = 0;
30 static TIMEQ_CALLBACK(main_statistics) {
31 int update_minutes = get_int_field("statistics.frequency");
32 if(!update_minutes) update_minutes = 2;
33 timeq_add(update_minutes * 60, 0, main_statistics, NULL);
34 if(get_int_field("statistics.enable")) {
35 statistics_requested_lusers = 1;
36 if(get_int_field("statistics.include_lusers")) {
37 struct ClientSocket *bot, *lusersbot = NULL;
38 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
39 if(bot->flags & SOCKET_FLAG_PREFERRED)
43 if(bot == NULL) bot = getBots(SOCKET_FLAG_READY, NULL);
44 putsock(bot, "LUSERS");
48 statistics_privmsg = 0;
49 statistics_commands = 0;
53 int statistics_update() {
54 if(get_int_field("statistics.enable") && statistics_requested_lusers && get_string_field("statistics.execute")) {
55 statistics_requested_lusers = 0;
66 sprintf(command, "%s %d %d %d %d %d %d %d", get_string_field("statistics.execute"), getUserCount(), getChanUserCount(), getChannelCount(), statistics_privmsg, statistics_commands, statistics_network_users, statistics_network_channels);
67 statistics_privmsg = 0;
68 statistics_commands = 0;
69 return system(command);
74 void init_statistics() {
75 int update_minutes = get_int_field("statistics.frequency");
76 if(!update_minutes) update_minutes = 2;
77 timeq_add(update_minutes * 60 + 10, 0, main_statistics, NULL);