cmd_neonserv_deluser added
[NeonServV5.git] / bot_NeonServ.c
1
2 #include "bot_NeonServ.h"
3 #include "modcmd.h"
4 #include "IRCEvents.h"
5 #include "IRCParser.h"
6 #include "UserNode.h"
7 #include "ChanNode.h"
8 #include "ChanUser.h"
9 #include "ClientSocket.h"
10 #include "mysqlConn.h"
11 #include "lang.h"
12 #include "HandleInfoHandler.h"
13 #include "WHOHandler.h"
14
15 #define BOTID 1
16
17 static const struct default_language_entry msgtab[] = {
18     {"NS_USER_UNKNOWN", "User with nick \002%s\002 does not exist."},
19     {"NS_AUTH_UNKNOWN", "Account \002%s\002 has not been registered."},
20     {"NS_USER_NEED_AUTH", "%s must first authenticate with \002AuthServ\002."},
21     {"NS_INVALID_ACCESS", "\002%d\002 is an invalid access level."},
22     {"NS_ADDUSER_ALREADY_ADDED", "%s is already on the \002%s\002 user list (with access %d)."},
23     {"NS_ADDUSER_DONE", "Added %s to the %s user list with access %d."},
24     {"NS_NOT_ON_USERLIST", "%s lacks access to \002%s\002."},
25     {"NS_DELUSER_DONE", "Deleted %s (with access %d) from the %s user list."},
26     {NULL, NULL}
27 };
28
29 /*
30 INCLUDE ALL CMD's HERE
31 */
32 #include "cmd_neonserv_users.c"
33 #include "cmd_neonserv_modes.c"
34 #include "cmd_neonserv_adduser.c"
35 #include "cmd_neonserv_deluser.c"
36
37 static void neonserv_bot_ready(struct ClientSocket *client) {
38     MYSQL_RES *res;
39     MYSQL_ROW row;
40     
41     check_mysql();
42     printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
43     res = mysql_use();
44     if ((row = mysql_fetch_row(res)) != NULL) {
45         putsock(client, "MODE %s +%s", client->user->nick, row[0]);
46     }
47     
48     printf_mysql_query("SELECT `channel_name`, `channel_key` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `botid` = '%d'", client->clientid);
49     res = mysql_use();
50     
51     while ((row = mysql_fetch_row(res)) != NULL) {
52         putsock(client, "JOIN %s %s", row[0], row[1]);
53     }
54 }
55
56 static void neonserv_trigger_callback(struct ChanNode *chan, char *trigger) {
57     strcpy(trigger, "!");
58 }
59
60 static void start_bots() {
61     struct UserNode *user;
62     struct ClientSocket *client;
63     MYSQL_RES *res, *res2;
64     MYSQL_ROW row;
65     
66     printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `whoisbot`, `id` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
67     res = mysql_use();
68     
69     while ((row = mysql_fetch_row(res)) != NULL) {
70         
71         user = addUser(row[0]);
72         strcpy(user->ident, row[1]);
73         strcpy(user->realname, row[2]);
74         user->flags |= USERFLAG_ISBOT;
75         client = create_socket(row[3], atoi(row[4]), row[5], user);
76         client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
77         client->botid = BOTID;
78         client->clientid = atoi(row[7]);
79         connect_socket(client);
80         printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access` FROM `bot_binds` WHERE `botid` = '%d'", client->clientid);
81         res2 = mysql_use();
82         while ((row = mysql_fetch_row(res2)) != NULL) {
83             if(bind_cmd_to_command(BOTID, row[0], row[1])) {
84                 if(row[2] && strcmp(row[2], "")) {
85                     bind_set_parameters(BOTID, row[0], row[2]);
86                 }
87                 if(atoi(row[3]) > 0) {
88                     bind_set_gaccess(BOTID, row[0], atoi(row[3]));
89                 }
90             }
91         }
92     }
93 }
94
95 void init_NeonServ() {
96     check_mysql();
97     
98     register_command(BOTID, "users", neonserv_cmd_users, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REQUIRE_AUTH);
99     register_command(BOTID, "modes", neonserv_cmd_modes, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
100     
101     register_command(BOTID, "adduser", neonserv_cmd_adduser, 2, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
102     register_command(BOTID, "deluser", neonserv_cmd_deluser, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
103     
104     start_bots();
105     bind_bot_ready(neonserv_bot_ready);
106     set_trigger_callback(BOTID, neonserv_trigger_callback);
107     
108     register_default_language_table(msgtab);
109 }
110
111 void free_NeonServ() {
112     
113 }
114
115 #undef BOTID