1 /* cmd_neonserv_setrank.c - NeonServ v5.2
2 * Copyright (C) 2011 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"
26 static void neonserv_cmd_setrank_name(struct UserNode *user, int rank_id, char *current, char *value);
27 static void neonserv_cmd_setrank_info(struct UserNode *user, int rank_id, char *current, char *value);
28 static void neonserv_cmd_setrank_access(struct UserNode *user, int rank_id, char *current, char *value);
29 static void neonserv_cmd_setrank_order(struct UserNode *user, int rank_id, char *current, char *value);
31 CMD_BIND(neonserv_cmd_setrank) {
34 printf_mysql_query("SELECT `rank_id`, `rank_name`, `rank_info`, `rank_access`, `rank_order` FROM `support_ranks` WHERE `rank_id` = '%s'", escape_string(argv[0]));
36 if ((row = mysql_fetch_row(res)) == NULL) {
37 reply(getTextBot(), user, "NS_SETRANK_NOT_FOUND", argv[0]);
41 reply(getTextBot(), user, "NS_SETRANK_HEAD", row[0]);
42 reply(getTextBot(), user, "\002NAME \002 %s", row[1]);
43 reply(getTextBot(), user, "\002INFO \002 %s", row[2]);
44 reply(getTextBot(), user, "\002ACCESS \002 %s", row[3]);
45 reply(getTextBot(), user, "\002ORDER \002 %s", row[4]);
49 value = merge_argv(argv, 2, argc);
51 if(!stricmp(argv[1], "name"))
52 neonserv_cmd_setrank_name(user, atoi(row[0]), row[1], value);
53 else if(!stricmp(argv[1], "info"))
54 neonserv_cmd_setrank_info(user, atoi(row[0]), row[2], value);
55 else if(!stricmp(argv[1], "access"))
56 neonserv_cmd_setrank_access(user, atoi(row[0]), row[3], value);
57 else if(!stricmp(argv[1], "order"))
58 neonserv_cmd_setrank_order(user, atoi(row[0]), row[4], value);
60 reply(getTextBot(), user, "NS_SETRANK_UNKNOWN_SETTING", row[1]);
64 static void neonserv_cmd_setrank_name(struct UserNode *user, int rank_id, char *current, char *value) {
65 if(value && stricmp(value, current)) {
68 printf_mysql_query("SELECT `rank_id` FROM `support_ranks` WHERE `rank_name` = '%s'", escape_string(value));
70 if ((row = mysql_fetch_row(res)) != NULL) {
71 reply(getTextBot(), user, "NS_ADDRANK_EXISTS", value);
74 printf_mysql_query("UPDATE `support_ranks` SET `rank_name` = '%s' WHERE `rank_id` = '%d'", escape_string(value), rank_id);
77 reply(getTextBot(), user, "\002NAME\002 %s", current);
80 static void neonserv_cmd_setrank_info(struct UserNode *user, int rank_id, char *current, char *value) {
81 if(value && stricmp(value, current)) {
82 printf_mysql_query("UPDATE `support_ranks` SET `rank_info` = '%s' WHERE `rank_id` = '%d'", escape_string(value), rank_id);
85 reply(getTextBot(), user, "\002INFO\002 %s", current);
88 static void neonserv_cmd_setrank_access(struct UserNode *user, int rank_id, char *current, char *value) {
89 if(value && stricmp(value, current)) {
90 int new_access = atoi(value);
91 if(new_access <= 0 || new_access > 1000) {
92 reply(getTextBot(), user, "NS_INVALID_ACCESS", new_access);
95 printf_mysql_query("UPDATE `users` SET `user_access` = '%d' WHERE `user_rank` = '%d'", new_access, rank_id);
96 printf_mysql_query("UPDATE `support_ranks` SET `rank_access` = '%d' WHERE `rank_id` = '%d'", new_access, rank_id);
99 reply(getTextBot(), user, "\002ACCESS\002 %s", current);
102 static void neonserv_cmd_setrank_order(struct UserNode *user, int rank_id, char *current, char *value) {
103 if(value && stricmp(value, current)) {
104 int new_order = atoi(value);
105 if(new_order <= 0 || new_order > 99) {
106 reply(getTextBot(), user, "NS_SETRANK_ORDER_INVALID", new_order);
109 printf_mysql_query("UPDATE `support_ranks` SET `rank_order` = '%d' WHERE `rank_id` = '%d'", new_order, rank_id);
112 reply(getTextBot(), user, "\002ORDER\002 %s", current);