added "nowho" parameter to debug userlist and fixed memory leak in DBHelper.c
[NeonServV5.git] / src / cmd_neonserv_up.c
index a81de4aae4dc65530cae90f8dc52c476fa407c49..930df02331b38d57241671a41490da682d4cfb72 100644 (file)
@@ -1,3 +1,19 @@
+/* cmd_neonserv_up.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"
 
@@ -5,7 +21,40 @@
 * no arguments
 */
 
+struct neonserv_cmd_up_cache {
+    struct ClientSocket *client;
+    struct ClientSocket *textclient;
+    struct UserNode *user;
+    struct Event *event;
+};
+
+static void neonserv_cmd_up_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event);
+static USERLIST_CALLBACK(neonserv_cmd_up_userlist_lookup);
+
 CMD_BIND(neonserv_cmd_up) {
+    if(isModeSet(chan->modes, 'd') || isModeSet(chan->modes, 'D')) {
+        struct neonserv_cmd_up_cache *cache = malloc(sizeof(*cache));
+        if (!cache) {
+            perror("malloc() failed");
+            return;
+        }
+        cache->client = client;
+        cache->textclient = getTextBot();
+        cache->user = user;
+        cache->event = event;
+        get_userlist_if_invisible(chan, neonserv_cmd_up_userlist_lookup, cache);
+    } else {
+        neonserv_cmd_up_async1(client, getTextBot(), user, chan, event);
+    }
+}
+
+static USERLIST_CALLBACK(neonserv_cmd_up_userlist_lookup) {
+    struct neonserv_cmd_up_cache *cache = data;
+    neonserv_cmd_up_async1(cache->client, cache->textclient, cache->user, chan, cache->event);
+    free(cache);
+}
+
+static void neonserv_cmd_up_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event) {
     struct ChanUser *chanuser = getChanUser(user, chan);
     if(!chanuser) {
         reply(getTextBot(), user, "NS_NOT_ON_CHANNEL_YOU", chan->name);
@@ -29,7 +78,7 @@ CMD_BIND(neonserv_cmd_up) {
         chan_getop = atoi(row[0]);
         chan_getvoice = atoi(row[1]);
     }
-    caccess = getChannelAccess(user, chan, 1);
+    caccess = getChannelAccess(user, chan);
     if(caccess >= chan_getop) {
         if(!(chanuser->flags & CHANUSERFLAG_OPPED)) {
             putsock(client, "MODE %s +o %s", chan->name, user->nick);