--- /dev/null
+/* cmd_neonserv_dehalfop.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-*] nicks
+*/
+static USERLIST_CALLBACK(neonserv_cmd_dehalfop_userlist_lookup);
+static void neonserv_cmd_dehalfop_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char **argv, int argc);
+
+struct neonserv_cmd_dehalfop_cache {
+ struct ClientSocket *client, *textclient;
+ struct UserNode *user;
+ struct Event *event;
+ char **argv;
+ int argc;
+};
+
+CMD_BIND(neonserv_cmd_dehalfop) {
+ struct neonserv_cmd_dehalfop_cache *cache = malloc(sizeof(*cache));
+ if (!cache) {
+ perror("malloc() failed");
+ return;
+ }
+ cache->client = client;
+ cache->textclient = getTextBot();
+ cache->user = user;
+ cache->event = event;
+ cache->argv = calloc(argc, sizeof(char*));
+ int i;
+ for(i = 0; i < argc; i++) {
+ cache->argv[i] = strdup(argv[i]);
+ }
+ cache->argc = argc;
+ get_userlist(chan, neonserv_cmd_dehalfop_userlist_lookup, cache);
+}
+
+static USERLIST_CALLBACK(neonserv_cmd_dehalfop_userlist_lookup) {
+ struct neonserv_cmd_dehalfop_cache *cache = data;
+ neonserv_cmd_dehalfop_async1(cache->client, cache->textclient, cache->user, chan, cache->event, cache->argv, cache->argc);
+ int i;
+ for(i = 0; i < cache->argc; i++) {
+ free(cache->argv[i]);
+ }
+ free(cache->argv);
+ free(cache);
+}
+
+static void neonserv_cmd_dehalfop_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char **argv, int argc) {
+ int i, done_users = 0;
+ struct UserNode *cuser;
+ struct ChanUser *chanuser;
+ struct ModeBuffer *modeBuf;
+ modeBuf = initModeBuffer(client, chan);
+ for(i = 0; i < argc; i++) {
+ cuser = searchUserByNick(argv[i]);
+ if(!cuser) continue;
+ chanuser = getChanUser(cuser, chan);
+ if(!chanuser) continue;
+ if(isNetworkService(cuser)) {
+ reply(textclient, user, "NS_SERVICE_IMMUNE", cuser->nick);
+ continue;
+ }
+ if(isUserProtected(chan, cuser, user)) {
+ reply(textclient, user, "NS_USER_PROTECTED", cuser->nick);
+ continue;
+ }
+ done_users++;
+ if(!(chanuser->flags & CHANUSERFLAG_OPPED)) continue;
+ modeBufferDehalfop(modeBuf, argv[i]);
+ }
+ freeModeBuffer(modeBuf);
+ if(done_users == argc)
+ reply(textclient, user, "NS_DEHALFOP_DONE", chan->name);
+ else
+ reply(textclient, user, "NS_DEHALFOP_FAIL", client->user->nick);
+ if(done_users)
+ logEvent(event);
+}