1 /* cmd_neonserv_halfop.c - NeonServ v5.6
2 * Copyright (C) 2011-2012 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 "cmd_neonserv.h"
23 static USERLIST_CALLBACK(neonserv_cmd_halfop_userlist_lookup);
24 static void neonserv_cmd_halfop_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nicks);
26 struct neonserv_cmd_halfop_cache {
27 struct ClientSocket *client, *textclient;
28 struct UserNode *user;
33 CMD_BIND(neonserv_cmd_halfop) {
34 struct neonserv_cmd_halfop_cache *cache = malloc(sizeof(*cache));
36 printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
39 cache->client = client;
40 cache->textclient = textclient;
43 cache->nicks = strdup(merge_argv(argv, 0, argc));
44 get_userlist_if_invisible(chan, module_id, neonserv_cmd_halfop_userlist_lookup, cache);
47 static USERLIST_CALLBACK(neonserv_cmd_halfop_userlist_lookup) {
48 struct neonserv_cmd_halfop_cache *cache = data;
49 neonserv_cmd_halfop_async1(cache->client, cache->textclient, cache->user, chan, cache->event, cache->nicks);
54 static void neonserv_cmd_halfop_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nicks) {
55 int total_users = 0, done_users = 0;
56 struct UserNode *cuser;
57 struct ChanUser *chanuser;
58 struct ModeBuffer *modeBuf;
59 modeBuf = initModeBuffer(client, chan);
65 cuser = searchUserByNick(b);
67 //check for an invisible user
68 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
69 if(!stricmp(chanuser->user->nick, b)) {
70 cuser = chanuser->user;
76 chanuser = getChanUser(cuser, chan);
77 if(!chanuser) continue;
80 if(chanuser->flags & CHANUSERFLAG_OPPED) continue;
81 modeBufferHalfop(modeBuf, b);
86 freeModeBuffer(modeBuf);
87 if(done_users == total_users)
88 reply(textclient, user, "NS_HALFOP_DONE", chan->name);
90 reply(textclient, user, "NS_HALFOP_FAIL", client->user->nick);