]> jfr.im git - irc/quakenet/newserv.git/blobdiff - helpmod2/hcommands.c
Merge pull request #51 from retropc/chanserv-live
[irc/quakenet/newserv.git] / helpmod2 / hcommands.c
index ab52d9b23fa48e53bb07216e597588ed2494e5b0..57b9e9a3106d29df6180b13a632aae8abb85b654 100644 (file)
@@ -5,6 +5,8 @@
 #include <sys/types.h>
 #include <dirent.h>
 
+#include "../lib/strlfunc.h"
+
 #include "hcommands.h"
 #include "hcommand.h"
 
@@ -766,30 +768,31 @@ static void helpmod_cmd_welcome (huser *sender, channel* returntype, char* ostr,
     }
     else
     {
-        strcpy(hchan->welcome, ostr);
+        strlcpy(hchan->welcome, ostr, HCHANNEL_WELCOME_LEN);
         helpmod_reply(sender, returntype, "Welcome message for channel %s (%s) is now: %s", hchan->real_channel->index->name->content, hchannel_get_state(hchan, H_WELCOME), hchan->welcome);
     }
 }
 
+static void helpmod_list_aliases(huser *sender, channel *returntype, char *buf, int *p_i, alias_tree node)
+{
+    if (*p_i > 256)
+    {
+        helpmod_reply(sender, returntype, "%s", buf);
+        *p_i = 0;
+    }
+    if (!node)
+        return;
+    sprintf(buf+*p_i,"%.200s ",node->name->content);
+    *p_i+=(1+strlen(node->name->content));
+    helpmod_list_aliases(sender, returntype, buf, p_i, node->left);
+    helpmod_list_aliases(sender, returntype, buf, p_i, node->right);
+}
+
 static void helpmod_cmd_aliases (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
 {
     char buf[512];
     int i = 0;
-    void helpmod_list_aliases(alias_tree node)
-    {
-       if (i > 256)
-       {
-           helpmod_reply(sender, returntype, "%s", buf);
-           i = 0;
-       }
-       if (!node)
-           return;
-        sprintf(buf+i,"%.200s ",node->name->content);
-       i+=(1+strlen(node->name->content));
-        helpmod_list_aliases(node->left);
-       helpmod_list_aliases(node->right);
-    }
-    helpmod_list_aliases(aliases);
+    helpmod_list_aliases(sender, returntype, buf, &i, aliases);
     if (i)
        helpmod_reply(sender, returntype, "%s", buf);
 }
@@ -1079,7 +1082,7 @@ void helpmod_cmd_term (huser *sender, channel* returntype, char* ostr, int argc,
             char *name = argv[1], *description;
             SKIP_WORD; SKIP_WORD;
             description = ostr;
-            htrm = hterm_add(source, name, description);
+            hterm_add(source, name, description);
             helpmod_reply(sender, returntype, "Term %s added succesfully", name);
         }
     }
@@ -1683,7 +1686,7 @@ static void helpmod_cmd_everyoneout (huser *sender, channel* returntype, char* o
        if (huser_get_level((*hchanuser)->husr) < H_TRIAL)
            if (kickmode == HELPMOD_KICKMODE_ALL || (kickmode == HELPMOD_KICKMODE_UNAUTHED && !IsAccount((*hchanuser)->husr->real_user)))
            {
-               helpmod_kick(hchan, (*hchanuser)->husr, reason);
+               helpmod_kick(hchan, (*hchanuser)->husr, "%s", reason);
                continue;
            }
        hchanuser = &(*hchanuser)->next;
@@ -1756,7 +1759,7 @@ static void helpmod_cmd_kick (huser *sender, channel* returntype, char* ostr, in
     }
 
     for (i=0;i<ntargets;i++)
-        helpmod_kick(hchan, targets[i], reason);
+        helpmod_kick(hchan, targets[i], "%s", reason);
 }
 
 static void helpmod_cmd_stats (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
@@ -1886,7 +1889,6 @@ static void helpmod_cmd_stats (huser *sender, channel* returntype, char* ostr, i
 static void helpmod_cmd_chanstats (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
 {
     hchannel *hchan;
-    hstat_channel *channel_stats;
     hstat_channel_entry *stat_entry;
 
     time_t timer = time(NULL);
@@ -1950,8 +1952,6 @@ static void helpmod_cmd_chanstats (huser *sender, channel* returntype, char* ost
             }
         }
 
-    channel_stats = hchan->stats;
-
     if (!days && !weeks)
         return;
 
@@ -2035,12 +2035,14 @@ static void helpmod_cmd_activestaff (huser *sender, channel* returntype, char* o
     switch (listtype)
     {
     case 0:
-        for (i=0;i < arr.arrlen && arr.array[i].prime_time_spent > H_ACTIVE_LIMIT;i++)
-            helpmod_reply(sender, returntype, "#%-2d %-20s %-20s %-20s", i+1,((haccount*)(arr.array[i].owner))->name->content, helpmod_strtime(arr.array[i].prime_time_spent), helpmod_strtime(arr.array[i].time_spent));
+        for (i=0;i < arr.arrlen;i++)
+            if (arr.array[i].prime_time_spent > H_ACTIVE_LIMIT)
+                helpmod_reply(sender, returntype, "#%-2d %-20s %-20s %-20s", i+1,((haccount*)(arr.array[i].owner))->name->content, helpmod_strtime(arr.array[i].prime_time_spent), helpmod_strtime(arr.array[i].time_spent));
         break;
     case 1:
-        for (i=arr.arrlen-1;i >= 0 && arr.array[i].prime_time_spent < H_ACTIVE_LIMIT;i--)
-            helpmod_reply(sender, returntype, "#%-2d %-20s %-20s %-20s", (arr.arrlen - i),((haccount*)(arr.array[i].owner))->name->content, helpmod_strtime(arr.array[i].prime_time_spent), helpmod_strtime(arr.array[i].time_spent));
+        for (i=arr.arrlen-1;i >= 0;i--)
+            if (arr.array[i].prime_time_spent < H_ACTIVE_LIMIT)
+                helpmod_reply(sender, returntype, "#%-2d %-20s %-20s %-20s", (arr.arrlen - i),((haccount*)(arr.array[i].owner))->name->content, helpmod_strtime(arr.array[i].prime_time_spent), helpmod_strtime(arr.array[i].time_spent));
         break;
     }
 
@@ -2155,7 +2157,7 @@ static void helpmod_cmd_mode(huser *sender, channel* returntype, int change, cha
         husr = huser_get(getnickbynick(argv[i]));
         if (husr == NULL)
         {
-            helpmod_reply(sender, returntype, "Cannot change mode: User %s not found", argv[i], hchannel_get_name(hchan));
+            helpmod_reply(sender, returntype, "Cannot change mode: User %s not found", argv[i]);
             continue;
         }
         huserchan = huser_on_channel(husr, hchan);
@@ -2296,7 +2298,7 @@ static void helpmod_cmd_invite (huser *sender, channel *returntype, char* arg, i
             return;
         }
 
-        if (nickbanned(sender->real_user, hchan->real_channel))
+        if (nickbanned(sender->real_user, hchan->real_channel, 0))
         {
             helpmod_reply(sender, returntype, "Cannot invite: You are banned from channel %s", argv[0]);
             return;
@@ -2384,7 +2386,7 @@ static void helpmod_cmd_ticket (huser *sender, channel* returntype, char* ostr,
         helpmod_reply(sender, returntype, "Cannot issue a ticket: User %s is considered improper and not worthy of a ticket", argv[1]);
         return;
     }
-    if (huser_get_level(husr) > H_PEON)
+    if (huser_get_level(husr) > H_FRIEND)
     {
         helpmod_reply(sender, returntype, "Cannot issue a ticket: User %s does not require a ticket", argv[1]);
         return;
@@ -2680,7 +2682,6 @@ static void helpmod_cmd_checkchannel(huser *sender, channel* returntype, char* o
     /* third pass - find status boundaries */
     {
        for (;o_limit < nick_count && numeric_array[o_limit] & CUMODE_OP; o_limit++);
-        v_limit = o_limit;
        for(v_limit = o_limit; (v_limit < nick_count) && numeric_array[v_limit] & CUMODE_VOICE; v_limit++);
     }
 
@@ -3176,7 +3177,7 @@ static void helpmod_cmd_text (huser *sender, channel* returntype, char* ostr, in
        DIR *dir;
        struct dirent *dent;
        char buffer[384], **lines, *start;
-        int nwritten, bufpos = 0, nlines = 0,i;
+        int bufpos = 0, nlines = 0,i;
 
        dir = opendir(HELPMOD_TEXT_DIR);
        assert(dir != NULL);
@@ -3227,18 +3228,17 @@ static void helpmod_cmd_text (huser *sender, channel* returntype, char* ostr, in
                buffer[bufpos] = ' ';
                bufpos++;
            }
-           sprintf(buffer + bufpos, "%s%n", lines[i], &nwritten);
-           bufpos+=nwritten;
+           bufpos+=sprintf(buffer + bufpos, "%s", lines[i]);
 
            if (bufpos > (384 - (HED_FILENAME_LENGTH+1)))
            {
-               helpmod_reply(sender, returntype, buffer);
+               helpmod_reply(sender, returntype, "%s", buffer);
                bufpos = 0;
            }
        }
 
        if (bufpos)
-           helpmod_reply(sender, returntype, buffer);
+           helpmod_reply(sender, returntype, "%s", buffer);
 
        free(start);
         free(lines);
@@ -3301,6 +3301,7 @@ static void helpmod_cmd_text (huser *sender, channel* returntype, char* ostr, in
        if ((in = fopen(fname_buffer, "rt")) != NULL)
        {
            helpmod_reply(sender, returntype, "Can not add text: Text %s already exists", argv[1]);
+            fclose(in);
             return;
        }
        else
@@ -3508,7 +3509,8 @@ static void helpmod_cmd_weekstats (huser *sender, channel* returntype, char* ost
 
     helpmod_reply(sender, returntype, "Weekly statistics for %ss on channel %s", hlevel_name(lvl), hchannel_get_name(hchan));
 
-    for (i=0;i < arr.arrlen && arr.array[i].time_spent > HDEF_m;i++)
+    for (i=0;i < arr.arrlen;i++)
+      if (arr.array[i].time_spent > HDEF_m)
        helpmod_reply(sender, returntype, "%-20s %-20s %-20s",((haccount*)(arr.array[i].owner))->name->content, helpmod_strtime(arr.array[i].prime_time_spent), helpmod_strtime(arr.array[i].time_spent));
 
     free(arr.array);
@@ -3553,9 +3555,9 @@ void helpmod_cmd_status (huser *sender, channel* returntype, char* ostr, int arg
     helpmod_reply(sender, returntype, "Channels          %d", hchannel_count());
     helpmod_reply(sender, returntype, "Accounts          %d", haccount_count(H_ANY));
     helpmod_reply(sender, returntype, "Users             %d", huser_count());
-    helpmod_reply(sender, returntype, "Help entries      %d", helpmod_entry_count(helpmod_base));
+    helpmod_reply(sender, returntype, "Help entries      %ld", helpmod_entry_count(helpmod_base));
     helpmod_reply(sender, returntype, "Bans              %d", hban_count());
-    helpmod_reply(sender, returntype, "Help provided     %d", helpmod_usage);
+    helpmod_reply(sender, returntype, "Help provided     %ld", helpmod_usage);
     helpmod_reply(sender, returntype, "Tickets           %d", hticket_count());
 }
 
@@ -3774,7 +3776,7 @@ void helpmod_command(huser *sender, channel* returntype, char *args)
 {
     int argc = 0, useless_var;
     char args_copy[512];
-    char *parsed_args[H_CMD_MAX_ARGS + 3], *ptr = args_copy;
+    char *parsed_args[H_CMD_MAX_ARGS + 4], *ptr = args_copy;
 
     /* only accept commands from valid sources */
     if (huser_get_level(sender) > H_ADMIN)
@@ -3791,9 +3793,11 @@ void helpmod_command(huser *sender, channel* returntype, char *args)
     if (*args == '-' || *args == '?')
         args++;
 
-    strcpy(args_copy, args);
+    strncpy(args_copy, args, (sizeof(args_copy) - 1));
+    args_copy[sizeof(args_copy) - 1] = '\0';
+
     /* FIX stringituki */
-    while (argc < 10)
+    while (argc < (H_CMD_MAX_ARGS + 4))
     {
         while (isspace(*ptr) && *ptr)
             ptr++;
@@ -3844,6 +3848,10 @@ void helpmod_command(huser *sender, channel* returntype, char *args)
 
        if (hcom == NULL)
        {
+            controlwall(NO_DEVELOPER, NL_ALL_COMMANDS, "(G) From: %s!%s@%s%s%s: %s",
+                        sender->real_user->nick, sender->real_user->ident,
+                        sender->real_user->host->name->content, IsAccount(sender->real_user)?"/":"",
+                        IsAccount(sender->real_user)?sender->real_user->authname:"", args);            
            if ((returntype == NULL) ||
                (sender->account != NULL && !(sender->account->flags & H_NO_CMD_ERROR)))
                helpmod_reply(sender, returntype, "Unknown command '%s', please see showcommands for a list of all commands available to you", parsed_args[0]);