1 /* bot_DummyServ.c - NeonServ v5.2
2 * Copyright (C) 2011 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/>.
18 #include "bot_DummyServ.h"
20 #include "IRCParser.h"
21 #include "IRCEvents.h"
27 #include "ClientSocket.h"
28 #include "mysqlConn.h"
30 #include "HandleInfoHandler.h"
31 #include "WHOHandler.h"
36 #include "EventLogger.h"
38 #include "cmd_neonserv.h"
39 #include "cmd_neonspam.h"
43 static void dummyserv_bot_ready(struct ClientSocket *client) {
47 printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
49 if ((row = mysql_fetch_row(res)) != NULL) {
50 putsock(client, "MODE %s +%s", client->user->nick, row[0]);
53 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);
56 while ((row = mysql_fetch_row(res)) != NULL) {
57 putsock(client, "JOIN %s %s", row[0], row[1]);
61 static void dummyserv_trigger_callback(struct ChanNode *chan, char *trigger) {
62 //this bot doesn't have a trigger
66 static void start_bots() {
67 struct UserNode *user;
68 struct ClientSocket *client;
69 MYSQL_RES *res, *res2;
72 printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
75 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 printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", client->botid);
89 while ((row = mysql_fetch_row(res2)) != NULL) {
90 if(bind_cmd_to_command(BOTID, row[0], row[1])) {
91 if(row[2] && strcmp(row[2], "")) {
92 bind_set_parameters(BOTID, row[0], row[2]);
95 bind_set_global_access(BOTID, row[0], atoi(row[3]));
98 bind_set_channel_access(BOTID, row[0], row[4]);
105 void init_DummyServ() {
107 #define USER_COMMAND(NAME,FUNCTION,PARAMCOUNT,PRIVS,FLAGS) register_command(BOTID, NAME, FUNCTION, PARAMCOUNT, PRIVS, 0, FLAGS)
108 // NAME FUNCTION PARAMS PRIVS FLAGS
109 USER_COMMAND("netinfo", neonserv_cmd_netinfo, 0, NULL, 0);
110 USER_COMMAND("version", neonserv_cmd_version, 0, NULL, 0);
113 #define OPER_COMMAND(NAME,FUNCTION,PARAMCOUNT,GACCESS,FLAGS) register_command(BOTID, NAME, FUNCTION, PARAMCOUNT, NULL, GACCESS, FLAGS)
114 // NAME FUNCTION PARAMS ACCS FLAGS
115 OPER_COMMAND("register", neonserv_cmd_register, 1, 200, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
116 OPER_COMMAND("unregister", neonserv_cmd_unregister,1, 200, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
117 OPER_COMMAND("bind", neonserv_cmd_bind, 2, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
118 OPER_COMMAND("unbind", neonserv_cmd_unbind, 1, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
119 OPER_COMMAND("say", neonserv_cmd_say, 2, 600, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
120 OPER_COMMAND("emote", neonserv_cmd_emote, 2, 600, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
121 OPER_COMMAND("notice", neonserv_cmd_notice, 2, 600, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
122 OPER_COMMAND("raw", neonserv_cmd_raw, 1, 800, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
123 OPER_COMMAND("god", neonserv_cmd_god, 0, 1, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
129 bind_bot_ready(dummyserv_bot_ready);
131 set_trigger_callback(BOTID, dummyserv_trigger_callback);
134 void loop_DummyServ() {
138 void free_DummyServ() {