+++ /dev/null
-/* cmd_neonserv_halfopall.c - NeonServ v5.3
- * Copyright (C) 2011-2012 Philipp Kreil (pk910)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "cmd_neonserv.h"
-
-/*
-* argv[0] "force"
-* argv[1] (optional) nick mask
-*/
-static USERLIST_CALLBACK(neonserv_cmd_halfopall_userlist_lookup);
-static void neonserv_cmd_halfopall_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nickmask);
-
-struct neonserv_cmd_halfopall_cache {
- struct ClientSocket *client, *textclient;
- struct UserNode *user;
- struct Event *event;
- char *nickmask;
-};
-
-CMD_BIND(neonserv_cmd_halfopall) {
- struct neonserv_cmd_halfopall_cache *cache = malloc(sizeof(*cache));
- if (!cache) {
- perror("malloc() failed");
- return;
- }
- cache->client = client;
- cache->textclient = getTextBot();
- cache->user = user;
- cache->event = event;
- if(argc) {
- cache->nickmask = strdup(argv[0]);
- } else
- cache->nickmask = NULL;
- get_userlist_if_invisible(chan, neonserv_cmd_halfopall_userlist_lookup, cache);
-}
-
-static USERLIST_CALLBACK(neonserv_cmd_halfopall_userlist_lookup) {
- struct neonserv_cmd_halfopall_cache *cache = data;
- neonserv_cmd_halfopall_async1(cache->client, cache->textclient, cache->user, chan, cache->event, cache->nickmask);
- if(cache->nickmask)
- free(cache->nickmask);
- free(cache);
-}
-
-static void neonserv_cmd_halfopall_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nickmask) {
- int done_users = 0;
- struct ChanUser *chanuser;
- struct ModeBuffer *modeBuf;
- modeBuf = initModeBuffer(client, chan);
- for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
- if(nickmask && match(nickmask, chanuser->user->nick)) continue;
- if(chanuser->flags & CHANUSERFLAG_OPPED) continue;
- modeBufferHalfop(modeBuf, chanuser->user->nick);
- done_users++;
- }
- freeModeBuffer(modeBuf);
- reply(textclient, user, "NS_HALFOPALL_DONE", done_users, chan->name);
- if(done_users)
- logEvent(event);
-}