added language system
[NeonServV5.git] / bot_NeonServ.c
1
2 #include "bot_NeonServ.h"
3 #include "modcmd.h"
4 #include "IRCEvents.h"
5 #include "UserNode.h"
6 #include "ChanNode.h"
7 #include "ChanUser.h"
8 #include "ClientSocket.h"
9 #include "mysqlConn.h"
10
11 #define BOTID 1
12 #define CLASSNAME "NeonServ"
13
14 static const struct default_language_entry msgtab[] = {
15
16 };
17
18 static CMD_BIND(neonserv_cmd_users) {
19     struct ChanUser *chanuser;
20     putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name);
21     for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
22         putsock(client, "PRIVMSG %s :  %s!%s@%s [%s]  rights: %d", chan->name, chanuser->user->nick, chanuser->user->ident, chanuser->user->host, ((chanuser->user->flags & USERFLAG_ISAUTHED) ? chanuser->user->auth : "*"), chanuser->flags);
23     }
24 }
25
26 static CMD_BIND(neonserv_cmd_modes) {
27     char modeBuf[MAXLEN];
28     getModeString(chan, modeBuf);
29     putsock(client, "PRIVMSG %s :Modes: %s", chan->name, modeBuf);
30 }
31
32 static void neonserv_bot_ready(struct ClientSocket *client) {
33     MYSQL_RES *res;
34     MYSQL_ROW row;
35     
36     check_mysql();
37     printf_mysql_query("SELECT `channel_name`, `channel_key` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `botid` = '%d'", client->clientid);
38     res = mysql_use();
39     
40     while ((row = mysql_fetch_row(res)) != NULL) {
41         putsock(client, "JOIN %s %s", row[0], row[1]);
42     }
43 }
44
45 static void neonserv_trigger_callback(struct ChanNode *chan, char *trigger) {
46     strcpy(trigger, "!");
47 }
48
49 static void start_bots() {
50     struct UserNode *user;
51     struct ClientSocket *client;
52     MYSQL_RES *res, *res2;
53     MYSQL_ROW row;
54     
55     printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `whoisbot`, `id` FROM `bots` WHERE `botclass` = '%s' AND `active` = '1'", escape_string(CLASSNAME));
56     res = mysql_use();
57     
58     while ((row = mysql_fetch_row(res)) != NULL) {
59         
60         user = addUser(row[0]);
61         strcpy(user->ident, row[1]);
62         strcpy(user->realname, row[2]);
63         user->flags |= USERFLAG_ISBOT;
64         client = create_socket(row[3], atoi(row[4]), row[5], user);
65         client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
66         client->botid = BOTID;
67         client->clientid = atoi(row[7]);
68         connect_socket(client);
69         printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access` FROM `bot_binds` WHERE `botid` = '%d'", client->clientid);
70         res2 = mysql_use();
71         while ((row = mysql_fetch_row(res2)) != NULL) {
72             
73         }
74     }
75 }
76
77 void init_NeonServ() {
78     check_mysql();
79     
80     register_command(BOTID, "users", neonserv_cmd_users, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REQUIRE_AUTH);
81     register_command(BOTID, "modes", neonserv_cmd_modes, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
82     
83     start_bots();
84     bind_bot_ready(neonserv_bot_ready);
85     set_trigger_callback(BOTID, neonserv_trigger_callback);
86     bind_cmd_to_command(BOTID, "users", "users");
87     bind_cmd_to_command(BOTID, "modes", "modes");
88 }
89
90 void free_NeonServ() {
91     
92 }
93
94 #undef BOTID
95 #undef CLASSNAME