1 /* cmd_neonserv_listrank.c - NeonServ v5.3
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
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.
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.
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/>.
18 #include "cmd_neonserv.h"
24 CMD_BIND(neonserv_cmd_listrank) {
25 MYSQL_RES *res, *res2;
29 printf_mysql_query("SELECT `rank_id`, `rank_name` FROM `support_ranks` ORDER BY `rank_order` ASC");
31 table = table_init(3, mysql_num_rows(res) + 1, 0);
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 char usersBuf[MAXLEN];
38 int usersPos, userCount;
39 char assignedBuf[MAXLEN];
40 while ((row = mysql_fetch_row(res)) != NULL) {
44 printf_mysql_query("SELECT `user_user`, `user_god` FROM `users` WHERE `user_rank` = '%s'", row[0]);
48 while((row2 = mysql_fetch_row(res2)) != NULL) {
49 usersPos += sprintf(usersBuf+usersPos, (usersPos ? ", %s%s" : "%s%s"), (strcmp(row2[1], "0") ? "@" : ""), row2[0]);
52 sprintf(assignedBuf, (userCount ? "%d (%s)" : "%d"), userCount, usersBuf);
53 content[2] = assignedBuf;
54 table_add(table, content);
57 char **table_lines = table_end(table);
59 for(i = 0; i < table->entrys; i++) {
60 reply(getTextBot(), user, table_lines[i]);
63 reply(getTextBot(), user, "NS_TABLE_NONE");
65 printf_mysql_query("SELECT `user_user` FROM `users` WHERE `user_rank` = '0' AND `user_access` > 0");
69 while((row2 = mysql_fetch_row(res2)) != NULL) {
70 usersPos += sprintf(usersBuf+usersPos, (usersPos ? ", %s%s" : "%s%s"), (strcmp(row2[1], "0") ? "@" : ""), row2[0]);
73 reply(getTextBot(), user, "NS_LISTRANK_UNRANKED", userCount);
75 reply(getTextBot(), user, " %s", usersBuf);