2 struct neonserv_event_notice_cache {
3 struct ClientSocket *client;
9 static USERAUTH_CALLBACK(neonserv_event_notice_nick_lookup);
10 static void neonserv_event_notice_async1(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message);
12 static void neonserv_event_channotice(struct UserNode *user, struct ChanNode *chan, char *message) {
13 struct ClientSocket *client = getBotForChannel(chan);
14 if(!client) return; //we can't "see" this event
15 if(user->flags & (USERFLAG_ISBOT | USERFLAG_ISIRCOP)) return;
16 loadChannelSettings(chan);
17 if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return;
18 if(!(user->flags & USERFLAG_ISAUTHED)) {
19 struct neonserv_event_notice_cache *cache = malloc(sizeof(*cache));
21 perror("malloc() failed");
24 cache->client = client;
27 cache->message = strdup(message);
28 get_userauth(user, neonserv_event_notice_nick_lookup, cache);
30 neonserv_event_notice_async1(client, user, chan, message);
33 static USERAUTH_CALLBACK(neonserv_event_notice_nick_lookup) {
34 struct neonserv_event_notice_cache *cache = data;
36 neonserv_event_notice_async1(cache->client, cache->user, cache->chan, cache->message);
42 static void neonserv_event_notice_async1(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
44 MYSQL_ROW row, defaultrow = NULL, chanuser;
46 printf_mysql_query("SELECT `channel_ctcp`, `channel_ctcpreaction` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
48 if ((row = mysql_fetch_row(res)) == NULL) return;
49 if(!row[0] || !row[1]) {
50 printf_mysql_query("SELECT `channel_ctcp`, `channel_ctcpreaction` FROM `channels` WHERE `channel_name` = 'defaults'");
52 defaultrow = mysql_fetch_row(res);
54 int noticeaccess = atoi((row[0] ? row[0] : defaultrow[0]));
55 if((user->flags & USERFLAG_ISAUTHED)) {
56 printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags` FROM `chanusers` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `chanuser_cid` = '%d' AND `user_user` = '%s'", chan->channel_id, escape_string(user->auth));
58 chanuser = mysql_fetch_row(res);
60 uaccess = ((atoi(chanuser[1]) & DB_CHANUSER_SUSPENDED) ? 0 : atoi(chanuser[0]));
63 char banmaskBuf[NICKLEN+USERLEN+HOSTLEN+3];
65 char *reason = "disallowed channel NOTICE";
66 if(uaccess < noticeaccess) {
67 switch(atoi((row[1] ? row[1] : defaultrow[1]))) {
68 case 2: //TIMEBAN: 3min
73 banmask = generate_banmask(user, banmaskBuf);
74 printf_mysql_query("INSERT INTO `bans` (`ban_channel`, `ban_mask`, `ban_triggered`, `ban_timeout`, `ban_owner`, `ban_reason`) VALUES ('%d', '%s', UNIX_TIMESTAMP(), '%lu', '%d', '%s')", chan->channel_id, escape_string(banmask), (unsigned long) (time(0) + duration), 0, escape_string(reason));
75 int banid = (int) mysql_insert_id(mysql_conn);
78 sprintf(nameBuf, "ban_%d", banid);
79 sprintf(banidBuf, "%d", banid);
80 timeq_add_name(nameBuf, duration, channel_ban_timeout, strdup(banidBuf));
83 banmask = generate_banmask(user, banmaskBuf);
84 putsock(client, "MODE %s +b %s", chan->name, banmask);
86 putsock(client, "KICK %s %s :%s", chan->name, user->nick, reason);