1 /* event_neonserv_kick.c - NeonServ v5.0
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 struct neonserv_event_kick_cache {
19 struct ClientSocket *client;
20 struct UserNode *user;
21 struct ChanUser *target;
25 static USERAUTH_CALLBACK(neonserv_event_kick_nick_lookup);
26 static void neonserv_event_kick_async1(struct neonserv_event_kick_cache *cache);
27 static void neonserv_event_kick_async2(struct ClientSocket *client, struct UserNode *user, struct ChanUser *target);
29 static void neonserv_event_kick(struct UserNode *user, struct ChanUser *target, char *reason) {
30 struct ClientSocket *client = getBotForChannel(chan);
31 if(!client) return; //we can't "see" this event
32 if(isNetworkService(user)) return;
33 loadChannelSettings(chan);
34 if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return;
35 struct neonserv_event_kick_cache *cache = malloc(sizeof(*cache));
37 perror("malloc() failed");
40 cache->client = client;
42 cache->target = target;
43 cache->userauth_pending++;
44 if(!(user->flags & USERFLAG_ISAUTHED)) {
45 get_userauth(user, neonserv_event_kick_nick_lookup, cache);
46 cache->userauth_pending++;
48 if(!(chanuser->user->flags & USERFLAG_ISAUTHED)) {
49 get_userauth(chanuser->user, neonserv_event_kick_nick_lookup, cache);
50 cache->userauth_pending++;
52 neonserv_event_kick_async1(cache);
55 static USERAUTH_CALLBACK(neonserv_event_kick_nick_lookup) {
56 struct neonserv_event_kick_cache *cache = data;
57 cache->userauth_pending--;
58 neonserv_event_kick_async1(cache);
61 static void neonserv_event_kick_async1(struct neonserv_event_kick_cache *cache) {
62 if(cache->userauth_pending == 0) {
63 neonserv_event_kick_async2(cache->client, cache->user, cache->chanuser);
68 static void neonserv_event_kick_async2(struct ClientSocket *client, struct UserNode *user, struct ChanUser *target) {
69 if(isUserProtected(target->chan, target->user, user)) {
71 putsock(client, "KICK %s %s :%s", target->chan->name, user->nick, build_language_string(user, buf, "NS_USER_PROTECTED", target->user->nick));
72 putsock(client, "INVITE %s %s", target->user->nick, target->chan->name);