added full half-op support
[NeonServV5.git] / src / cmd_neonserv_set.c
index 9cb57674d3d0bc770708aae098549a5fd9bf3e60..2b3ddab2f868ff5b19f2a5fdde69cfc164666149 100644 (file)
@@ -1,5 +1,5 @@
-/* cmd_neonserv_set.c - NeonServ v5.1
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* cmd_neonserv_set.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
@@ -31,6 +31,7 @@ static char* neonserv_cmd_set_nodelete(struct ClientSocket *client, struct UserN
 #define NS_VALID_OPTIONS  0x10
 #define NS_VALID_NUMERIC  0x20
 #define NS_VALID_BOOLEAN  0x40
+#define NS_VALID_IF_HALFOP 0x80
 
 #define NS_HAS_OPT  0x100 /* options (SET_OPTION_{NAME}_{VALUE}) */
 #define NS_HAS_HELP 0x200 /* help    (SET_HELP_{NAME}) - only shown if help is requested */
@@ -52,8 +53,10 @@ static const struct {
     {"MODES",           "channel_modes",        NS_VALID_FUNCTION,                  neonserv_cmd_set_modes},
     {"INVITEME",        "channel_getinvite",    NS_VALID_ACCESS,                    NULL},
     {"GIVEOPS",         "channel_getop",        NS_VALID_ACCESS | NS_HAS_HELP,      NULL},
+    {"GIVEHALFOPS",     "channel_gethalfop",    NS_VALID_ACCESS | NS_HAS_HELP | NS_VALID_IF_HALFOP, NULL},
     {"GIVEVOICE",       "channel_getvoice",     NS_VALID_ACCESS | NS_HAS_HELP,      NULL},
     {"ENFOPS",          "channel_canop",        NS_VALID_ACCESS | NS_HAS_HELP,      NULL},
+    {"ENFHALFOPS",      "channel_canhalfop",    NS_VALID_ACCESS | NS_HAS_HELP | NS_VALID_IF_HALFOP, NULL},
     {"ENFVOICE",        "channel_canvoice",     NS_VALID_ACCESS | NS_HAS_HELP,      NULL},
     {"KICK",            "channel_cankick",      NS_VALID_ACCESS | NS_HAS_HELP,      NULL},
     {"BAN",             "channel_canban",       NS_VALID_ACCESS | NS_HAS_HELP,      NULL},
@@ -85,7 +88,7 @@ CMD_BIND(neonserv_cmd_set) {
     int i, j;
     if(argc && !strcmp(argv[0], "defaults")) {
         //reset channel settings
-        int uaccess = getChannelAccess(user, chan, 0);
+        int uaccess = getChannelAccess(user, chan);
         if(uaccess < 500) {
             if(isGodMode(user)) {
                 event->flags |= CMDFLAG_OPLOG;
@@ -125,8 +128,9 @@ CMD_BIND(neonserv_cmd_set) {
         i = 0;
         j = 0;
         char *args = (argc > 1 ? merge_argv(argv, 1, argc) : NULL);
+        int with_halfops = get_int_field("General.have_halfop");
         while(channel_settings[i].setting) {
-            if(!stricmp(channel_settings[i].setting, argv[0])) {
+            if(!stricmp(channel_settings[i].setting, argv[0]) && (!(channel_settings[i].valid & NS_VALID_IF_HALFOP) || with_halfops)) {
                 //setting found
                 if(channel_settings[i].valid & NS_VALID_FUNCTION) {
                     neonserv_cmd_set_function *func = channel_settings[i].parameter;
@@ -150,13 +154,19 @@ CMD_BIND(neonserv_cmd_set) {
         MYSQL_ROW row, defaults;
         struct Table *table;
         char *content[2];
+        int with_halfops = get_int_field("General.have_halfop");
         i = 0;
+        j = 0;
         while(channel_settings[i].setting) {
+            if((channel_settings[i].valid & NS_VALID_IF_HALFOP) && !with_halfops) {
+                j++;
+                continue;
+            }
             if(channel_settings[i].chanfield)
                 querypos += sprintf(query + querypos, ", `%s`", channel_settings[i].chanfield);
             i++;
         }
-        table = table_init(2, i, 0);
+        table = table_init(2, i-j, 0);
         table_set_bold(table, 0, 1);
         printf_mysql_query("SELECT `channel_id` %s FROM `channels` WHERE `channel_name` = 'defaults'", query);
         defaults_res = mysql_use();
@@ -168,6 +178,10 @@ CMD_BIND(neonserv_cmd_set) {
         j = 0;
         reply(getTextBot(), user, "NS_SET_HEADER", chan->name);
         while(channel_settings[i].setting) {
+            if((channel_settings[i].valid & NS_VALID_IF_HALFOP) && !with_halfops) {
+                i++;
+                continue;
+            }
             if(channel_settings[i].chanfield) {
                 j++;
                 org_value = (row[j] ? row[j] : defaults[j]);
@@ -243,7 +257,7 @@ static void neonserv_cmd_set_setting(struct ClientSocket *client, struct UserNod
                 reply(getTextBot(), user, "NS_INVALID_ACCESS", caccess);
                 return;
             }
-            int uaccess = getChannelAccess(user, chan, 0);
+            int uaccess = getChannelAccess(user, chan);
             if(uaccess == 500) uaccess++;
             if(atoi(value) > uaccess) {
                 if(isGodMode(user)) {
@@ -307,7 +321,15 @@ static void neonserv_cmd_set_setting(struct ClientSocket *client, struct UserNod
         printf_mysql_query("UPDATE `channels` SET `%s` = '%s' WHERE `channel_id` = '%d'", channel_settings[setting].chanfield, escape_string(value), chan->channel_id);
         logEvent(event);
     }
-    reply(getTextBot(), user, "\002%s\002 %s", channel_settings[setting].setting, value);
+    if(channel_settings[setting].valid & NS_HAS_OPT) {
+        sprintf(nameBuf, "NS_SET_OPTION_%s_%s", channel_settings[setting].setting, value);
+        char *tmp = get_language_string(user, nameBuf);
+        if(tmp)
+            reply(getTextBot(), user, "\002%s\002 %s - %s", channel_settings[setting].setting, value, tmp);
+        else
+            reply(getTextBot(), user, "\002%s\002 %s", channel_settings[setting].setting, value);
+    } else
+        reply(getTextBot(), user, "\002%s\002 %s", channel_settings[setting].setting, value);
     if(channel_settings[setting].valid & NS_HAS_HELP) {
          sprintf(nameBuf, "NS_SET_HELP_%s", channel_settings[setting].setting);
          reply(getTextBot(), user, "  %s", get_language_string(user, nameBuf));
@@ -319,12 +341,12 @@ static char* neonserv_cmd_set_trigger(struct ClientSocket *client, struct UserNo
     //get current trigger
     MYSQL_RES *res;
     MYSQL_ROW row;
-    printf_mysql_query("SELECT `trigger` FROM `bot_channels` WHERE `chanid` = '%d' AND `botid` = '%d'", chan->channel_id, client->clientid);
+    printf_mysql_query("SELECT `trigger`, `defaulttrigger` FROM `bot_channels` LEFT JOIN `bots` ON `botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botid` = '%d'", chan->channel_id, client->clientid);
     res = mysql_use();
     row = mysql_fetch_row(res);
-    trigger = row[0];
+    trigger = (row[0] ? row[0] : row[1]);
     if(argument) {
-        int uaccess = getChannelAccess(user, chan, 0);
+        int uaccess = getChannelAccess(user, chan);
         if(uaccess < 500) {
             if(isGodMode(user)) {
                 event->flags |= CMDFLAG_OPLOG;