*** VERSION 5.2.0 ***
[NeonServV5.git] / src / cmd_neonserv_myaccess.c
index 093e28a65bfbc33df9b5b3e2512994d9d6e7d7ed..6480f7aad10cde03408da7d706cc0f4331026f73 100644 (file)
@@ -1,3 +1,19 @@
+/* cmd_neonserv_myaccess.c - NeonServ v5.2
+ * Copyright (C) 2011  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"
 
@@ -99,18 +115,15 @@ static void neonserv_cmd_myaccess_async1(struct ClientSocket *client, struct Cli
     MYSQL_ROW user_row, chanuser_row, default_chan = NULL;
     char flagBuf[5];
     int userid, cflags, caccess, flagPos;
-    int i, total_count, match_count = 0, owner_count = 0;
-    struct Table *table;
+    int i, total_count = 0, match_count = 0, owner_count = 0;
+    struct Table *table = NULL;
     printf_mysql_query("SELECT `user_id`, `user_access`, `user_god` FROM `users` WHERE `user_user` = '%s'", escape_string(auth));
     res = mysql_use();
-    total_count = mysql_num_rows(res);
-    table = table_init(4, total_count + 1, 0);
     char *content[4];
     content[0] = get_language_string(user, "NS_MYACCESS_HEADER_NAME");
     content[1] = get_language_string(user, "NS_MYACCESS_HEADER_ACCESS");
     content[2] = get_language_string(user, "NS_MYACCESS_HEADER_FLAGS");
     content[3] = get_language_string(user, "NS_MYACCESS_HEADER_INFO");
-    table_add(table, content);
     if(chanmatch)
         reply(textclient, user, "NS_MYACCESS_HEADER_MATCH", auth, chanmatch);
     else
@@ -118,8 +131,11 @@ static void neonserv_cmd_myaccess_async1(struct ClientSocket *client, struct Cli
     if ((user_row = mysql_fetch_row(res)) != NULL) {
         userid = atoi(user_row[0]);
         //check if the user is already added
-        printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `chanuser_infoline`, `channel_name`, `channel_getop`, `channel_getvoice` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d' ORDER BY `chanuser_access` DESC, `channel_name` ASC", userid);
+        printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags`, `chanuser_infoline`, `channel_name`, `channel_getop`, `channel_getvoice`, `botid` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` LEFT JOIN `bot_channels` ON `chanuser_cid` = `chanid` LEFT JOIN `bots` ON `bots`.`id` = `botid` WHERE `chanuser_uid` = '%d' AND `botclass` = '%d' ORDER BY `chanuser_access` DESC, `channel_name` ASC", userid, client->botid);
         res = mysql_use();
+        total_count = mysql_num_rows(res);
+        table = table_init(4, total_count + 1, 0);
+        table_add(table, content);
         while ((chanuser_row = mysql_fetch_row(res)) != NULL) {
             if(!strcmp(chanuser_row[0], "500")) owner_count++;
             if(chanmatch && match(chanmatch, chanuser_row[0])) continue;
@@ -146,6 +162,9 @@ static void neonserv_cmd_myaccess_async1(struct ClientSocket *client, struct Cli
             content[3] = chanuser_row[2];
             table_add(table, content);
         }
+    } else {
+        table = table_init(4, 1, 0);
+        table_add(table, content);
     }
     //send the table
     char **table_lines = table_end(table);