added "nowho" parameter to debug userlist and fixed memory leak in DBHelper.c
[NeonServV5.git] / src / cmd_neonserv_up.c
index a9fbc0025a606e342d70a6209bfa92277a6d9049..930df02331b38d57241671a41490da682d4cfb72 100644 (file)
@@ -1,5 +1,5 @@
-/* cmd_neonserv_up.c - NeonServ v5.1
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* 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
 * 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);
@@ -45,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);