*** VERSION 5.2.0 ***
[NeonServV5.git] / src / cmd_neonserv_listrank.c
1 /* cmd_neonserv_listrank.c - NeonServ v5.2
2  * Copyright (C) 2011  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17
18 #include "cmd_neonserv.h"
19
20 /*
21 * no arguments
22 */
23
24 CMD_BIND(neonserv_cmd_listrank) {
25     MYSQL_RES *res, *res2;
26     MYSQL_ROW row;
27     struct Table *table;
28     int ranks = 0;
29     printf_mysql_query("SELECT `rank_id`, `rank_name` FROM `support_ranks` ORDER BY `rank_order` ASC");
30     res = mysql_use();
31     table = table_init(3, mysql_num_rows(res) + 1, 0);
32     char *content[3];
33     content[0] = get_language_string(user, "NS_LISTRANK_ID");
34     content[1] = get_language_string(user, "NS_LISTRANK_NAME");
35     content[2] = get_language_string(user, "NS_LISTRANK_ASSIGNED");
36     table_add(table, content);
37     while ((row = mysql_fetch_row(res)) != NULL) {
38         ranks++;
39         content[0] = row[0];
40         content[1] = row[1];
41         printf_mysql_query("SELECT COUNT(*) FROM `users` WHERE `user_rank` = '%s'", row[0]);
42         res2 = mysql_use();
43         row = mysql_fetch_row(res2);
44         content[2] = row[0];
45         table_add(table, content);
46     }
47     //send the table
48     char **table_lines = table_end(table);
49     int i;
50     for(i = 0; i < table->entrys; i++) {
51         reply(getTextBot(), user, table_lines[i]);
52     }
53     if(!ranks)
54         reply(getTextBot(), user, "NS_TABLE_NONE");
55     table_free(table);
56     printf_mysql_query("SELECT COUNT(*) FROM `users` WHERE `user_rank` = '0' AND `user_access` > 0");
57     res2 = mysql_use();
58     row = mysql_fetch_row(res2);
59     reply(getTextBot(), user, "NS_LISTRANK_UNRANKED", atoi(row[0]));
60 }