added cmd_bots (lists all bots)
[NeonServV5.git] / src / bot_DummyServ.c
1 /* bot_DummyServ.c - NeonServ v5.2
2  * Copyright (C) 2011  Philipp Kreil (pk910)
3  * 
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.
8  * 
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.
13  * 
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/>. 
16  */
17
18 #include "bot_DummyServ.h"
19 #include "modcmd.h"
20 #include "IRCParser.h"
21 #include "IRCEvents.h"
22 #include "UserNode.h"
23 #include "ChanNode.h"
24 #include "ChanUser.h"
25 #include "ModeNode.h"
26 #include "BanNode.h"
27 #include "ClientSocket.h"
28 #include "mysqlConn.h"
29 #include "lang.h"
30 #include "HandleInfoHandler.h"
31 #include "WHOHandler.h"
32 #include "DBHelper.h"
33 #include "tools.h"
34 #include "timeq.h"
35 #include "version.h"
36 #include "EventLogger.h"
37 #include "bots.h"
38 #include "cmd_neonserv.h"
39 #include "cmd_neonspam.h"
40
41 #define BOTID 3
42 #define BOTALIAS "DummyServ"
43
44 static void dummyserv_bot_ready(struct ClientSocket *client) {
45     MYSQL_RES *res;
46     MYSQL_ROW row;
47     
48     printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
49     res = mysql_use();
50     if ((row = mysql_fetch_row(res)) != NULL) {
51         putsock(client, "MODE %s +%s", client->user->nick, row[0]);
52     }
53     
54     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);
55     res = mysql_use();
56     
57     while ((row = mysql_fetch_row(res)) != NULL) {
58         putsock(client, "JOIN %s %s", row[0], row[1]);
59     }
60 }
61
62 static void dummyserv_trigger_callback(struct ChanNode *chan, char *trigger) {
63     //this bot doesn't have a trigger
64     strcpy(trigger, "");
65 }
66
67 static void start_bots() {
68     struct UserNode *user;
69     struct ClientSocket *client;
70     MYSQL_RES *res, *res2;
71     MYSQL_ROW row;
72     
73     printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
74     res = mysql_use();
75     
76     while ((row = mysql_fetch_row(res)) != NULL) {
77         user = addUser(row[0]);
78         strcpy(user->ident, row[1]);
79         strcpy(user->realname, row[2]);
80         user->flags |= USERFLAG_ISBOT;
81         client = create_socket(row[3], atoi(row[4]), row[5], user);
82         client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
83         client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
84         client->botid = BOTID;
85         client->clientid = atoi(row[7]);
86         connect_socket(client);
87     }
88     
89     printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
90     res2 = mysql_use();
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]);
95             }
96             if(row[3]) {
97                 bind_set_global_access(BOTID, row[0], atoi(row[3]));
98             }
99             if(row[4]) {
100                 bind_set_channel_access(BOTID, row[0], row[4]);
101             }
102         }
103     }
104     bind_unbound_required_functions(BOTID);
105 }
106
107 void init_DummyServ() {
108     
109     set_bot_alias(BOTID, BOTALIAS);
110     start_bots();
111     
112     //register events
113     bind_bot_ready(dummyserv_bot_ready);
114     
115     set_trigger_callback(BOTID, dummyserv_trigger_callback);
116 }
117
118 void loop_DummyServ() {
119     
120 }
121
122 void free_DummyServ() {
123     
124 }
125
126 #undef BOTID
127 #undef BOTALIAS