1 /* bot_DummyServ.c - NeonServ v5.3
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 "../module.h"
19 #include "bot_DummyServ.h"
21 #include "IRCParser.h"
22 #include "IRCEvents.h"
28 #include "ClientSocket.h"
29 #include "mysqlConn.h"
31 #include "HandleInfoHandler.h"
32 #include "WHOHandler.h"
37 #include "EventLogger.h"
39 #include "cmd_neonserv.h"
40 #include "cmd_neonspam.h"
43 #define BOTALIAS "DummyServ"
45 static void dummyserv_bot_ready(struct ClientSocket *client) {
49 printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
51 if ((row = mysql_fetch_row(res)) != NULL) {
52 putsock(client, "MODE %s +%s", client->user->nick, row[0]);
55 printf_mysql_query("SELECT `channel_name`, `channel_key` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `botid` = '%d' AND `suspended` = '0'", client->clientid);
58 while ((row = mysql_fetch_row(res)) != NULL) {
59 putsock(client, "JOIN %s %s", row[0], row[1]);
63 static void dummyserv_trigger_callback(int clientid, struct ChanNode *chan, char *trigger) {
64 //this bot doesn't have a trigger
68 static void start_bots(int type) {
69 struct ClientSocket *client;
70 MYSQL_RES *res, *res2;
73 if(type == MODSTATE_STARTSTOP) {
74 printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue`, `ssl`, `bind` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
77 while ((row = mysql_fetch_row(res)) != NULL) {
78 client = create_socket(row[3], atoi(row[4]), row[10], row[5], row[0], row[1], row[2]);
79 client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
80 client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
81 client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0);
82 client->flags |= SOCKET_FLAG_SILENT;
83 client->botid = BOTID;
84 client->clientid = atoi(row[7]);
85 connect_socket(client);
89 printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
91 while ((row = mysql_fetch_row(res2)) != NULL) {
92 if(bind_cmd_to_command(BOTID, row[0], row[1])) {
93 if(row[2] && strcmp(row[2], "")) {
94 bind_set_parameters(BOTID, row[0], row[2]);
97 bind_set_global_access(BOTID, row[0], atoi(row[3]));
100 bind_set_channel_access(BOTID, row[0], row[4]);
102 if(strcmp(row[5], "0"))
103 bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
106 bind_unbound_required_functions(BOTID);
109 void init_DummyServ(int type) {
110 set_bot_alias(BOTID, BOTALIAS);
113 if(type == MODSTATE_REBIND) return;
116 bind_bot_ready(dummyserv_bot_ready);
118 set_trigger_callback(BOTID, dummyserv_trigger_callback);
121 void loop_DummyServ() {
125 void free_DummyServ(int type) {
126 unbind_allcmd(BOTID);
127 if(type == MODSTATE_STARTSTOP) {
128 //disconnect all our bots
129 struct ClientSocket *client;
130 for(client = getBots(0, NULL); client; client = getBots(0, client)) {
131 if(client->botid == BOTID) {
132 unbind_botwise_allcmd(0, client->clientid);
133 close_socket(client);