]> jfr.im git - irc/blitzed-org/bopm.git/commitdiff
opercmd.c:
authorandy <redacted>
Tue, 30 Apr 2002 23:24:38 +0000 (23:24 +0000)
committerandy <redacted>
Tue, 30 Apr 2002 23:24:38 +0000 (23:24 +0000)
Reformatting.
opercmd.h:
Reformatting, moved some global variable declarations to opercmd.c
irc.c:
Needed an extern to get access to LAST_REAP_TIME.

irc.c
opercmd.c
opercmd.h

diff --git a/irc.c b/irc.c
index a9e91cb8c6ac09dfae2349a53be526271639ab88..c615f233d852dadc7d887add12eca5db0d5cd14b 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -78,6 +78,7 @@ static char *get_chan_key(const char *channel);
 static char *check_channel(const char *channel);
 
 extern char *CONFFILE;
+extern time_t LAST_REAP_TIME;
 
 /*
  * Certain variables we don't want to allocate memory for over and over
index 28e24e4eb25549a3efb21499a62a0b4ac2fde018..11a8002505577cfa5089bf3f5663e31ceccae745 100644 (file)
--- a/opercmd.c
+++ b/opercmd.c
@@ -39,129 +39,133 @@ along with this program; if not, write to the Free Software
 #include "config.h"
 #include "extern.h"
 
+static void checkoper(const char *nick, const char *param,
+    const char *target, unsigned int cmd_type);
+static void delete_command(unsigned int index);
+
+struct command cmd_stack[MAXCMD];
+time_t LAST_REAP_TIME;
+
 void do_oper_cmd(const char *nick, const char *cmd, const char *param,
-                const char *target)
+    const char *target)
 {
-   if(strncasecmp(cmd, "CHECK", 5) == 0)
-    {
-      if(!param)
-       {
-         irc_send("PRIVMSG %s :*ring* Hello, cluephone for %s, you need to "
-                 "specify a host or IP address if you want me to do any "
-                 "checking, yo.", target, nick);
-        return;
-       }
-      checkoper(nick, param, target, CMD_CHECK);
-    }
-   else
-    {
-      irc_send("PRIVMSG %s :Sorry, I don't know how to %s, %s.", target,
-              cmd, nick);
-    }
-   return;
+       if (strncasecmp(cmd, "CHECK", 5) == 0) {
+               if (!param) {
+                       irc_send("PRIVMSG %s :*ring* Hello, cluephone for "
+                           "%s, you need to specify a host or IP address "
+                           "if you want me to do any checking, yo.",
+                           target, nick);
+                       return;
+               }
+               checkoper(nick, param, target, CMD_CHECK);
+       } else {
+               irc_send("PRIVMSG %s :Sorry, I don't know how to %s, %s.",
+                   target, cmd, nick);
+       }
+       return;
 }
 
-void checkoper(const char *nick, const char *param, const char *target,
-    unsigned int cmd_type)
+static void checkoper(const char *nick, const char *param,
+    const char *target, unsigned int cmd_type)
 {
-   int i;
-
-   for(i = 0; i < MAXCMD; i++)
-    {
-      if(cmd_stack[i].type == CMD_NONE)
-       {
-         cmd_stack[i].type = cmd_type;
-         cmd_stack[i].param = strdup(param);
-         cmd_stack[i].target = strdup(target);
-         strncpy(cmd_stack[i].nick, nick, NICKMAX);
-        break;
-       }
-    }
-
-   if(i == MAXCMD)
-      irc_send("PRIVMSG %s :Too many queued commands, try later.", target);
-   else
-      irc_send("USERHOST %s", nick);
+       unsigned int i;
+
+       for (i = 0; i < MAXCMD; i++) {
+               if (cmd_stack[i].type == CMD_NONE) {
+                       cmd_stack[i].type = cmd_type;
+                       cmd_stack[i].param = strdup(param);
+                       cmd_stack[i].target = strdup(target);
+                       strncpy(cmd_stack[i].nick, nick, NICKMAX);
+                       break;
+               }
+       }
+
+       if (i == MAXCMD) {
+               irc_send("PRIVMSG %s :Too many queued commands, try later.",
+                   target);
+       } else {
+               irc_send("USERHOST %s", nick);
+       }
 }
 
+/*
+ * Check a userhost to see if it is from an oper, we're looking for the
+ * asterisk (*) between the nick and the ident as below:
+ * :grifferz*=+goats@pc-62-30-219-54-pb.blueyonder.co.uk
+ */
 void check_userhost(const char *userhost)
 {
-   /* check a userhost to see if it is from an oper, we're looking for
-    * the asterisk (*) between the nick and the ident as below:
-    * :grifferz*=+goats@pc-62-30-219-54-pb.blueyonder.co.uk */
-   char *tmp;
-   int c, oper = 0;
+       int c, oper;
+       char *tmp;
+
+       oper = 0;
    
-   tmp = strchr(userhost, '=');
-
-   if(!tmp)
-    {
-      /* looks like they quit, oh well, just ignore it */
-      return;
-    }
-
-   if(*(tmp - 1) == '*')
-    {
-      oper = 1;
-      tmp--;
-    }
-
-   /* null terminate userhost so we have a nickname there now */
-   *tmp = '\0';
-
-   /* go through the command list looking for commands by this person */
-   for(c = 0; c < MAXCMD; c++)
-    {
-      if(!strcasecmp(userhost + 1, cmd_stack[c].nick))
-       {
-         if(oper)
-         {
-            /* do the command */
-           if(cmd_stack[c].type == CMD_CHECK)
-            {
-              do_manual_check(&cmd_stack[c]);
-            }
-         }
-        else
-         {
-           irc_send("PRIVMSG %s :You are not an IRC Operator.  Go away.",
-                    cmd_stack[c].target);
-         }
-
-        delete_command(c);
-       }
-    }
+       tmp = strchr(userhost, '=');
+
+       if (!tmp) {
+               /* Looks like they quit, oh well, just ignore it. */
+               return;
+       }
+
+       if (*(tmp - 1) == '*') {
+               oper = 1;
+               tmp--;
+       }
+
+       /* Null terminate userhost so we have a nickname there now. */
+       *tmp = '\0';
+
+       /* Go through the command list looking for commands by this person */
+       for (c = 0; c < MAXCMD; c++) {
+               if (!strcasecmp(userhost + 1, cmd_stack[c].nick)) {
+                       if (oper) {
+                               /* Do the command. */
+                               if (cmd_stack[c].type == CMD_CHECK) {
+                                       do_manual_check(&cmd_stack[c]);
+                               }
+                       } else {
+                               irc_send("PRIVMSG %s :You are not an IRC "
+                                   "Operator.  Go away.",
+                                   cmd_stack[c].target);
+                       }
+
+                       delete_command(c);
+               }
+       }
 }
 
-/* set a command to CMD_NONE and free all resources it used, so that it
- * can be reused later */
-void delete_command(unsigned int index)
+/*
+ * Set a command to CMD_NONE and free all resources it used, so that it
+ * can be reused later.
+ */
+static void delete_command(unsigned int index)
 {
-   if(cmd_stack[index].type == CMD_NONE)
-      return;
+       if (cmd_stack[index].type == CMD_NONE)
+               return;
    
-   cmd_stack[index].type = CMD_NONE;
-   cmd_stack[index].added = 0;
-   free(cmd_stack[index].param);
-   free(cmd_stack[index].target);
+       cmd_stack[index].type = CMD_NONE;
+       cmd_stack[index].added = 0;
+       free(cmd_stack[index].param);
+       free(cmd_stack[index].target);
 }
 
-/* delete any commands which are more than 2 minutes old, they are almost certainly
- * no longer relevant. */
+/*
+ * Delete any commands which are more than 2 minutes old, they are almost certainly
+ * no longer relevant.
+ */
 void reap_commands(time_t present)
 {
-   int c;
-
-   for(c = 0; c < MAXCMD; c++)
-    {
-      if(cmd_stack[c].type != CMD_NONE &&
-         (present - cmd_stack[c].added >= 120))
-       {
-         irc_send("PRIVMSG %s :Reaping dead command from %s of type %u "
-                 "with param '%s', added %s ago.", cmd_stack[c].nick,
-                 cmd_stack[c].type, cmd_stack[c].param,
-                 dissect_time(present - cmd_stack[c].added));
-        delete_command(c);
-       }
-    }
+       int c;
+
+       for (c = 0; c < MAXCMD; c++) {
+               if (cmd_stack[c].type != CMD_NONE &&
+                   (present - cmd_stack[c].added >= 120)) {
+                       irc_send("PRIVMSG %s :Reaping dead command from "
+                           "%s of type %u with param '%s', added %s ago.",
+                           cmd_stack[c].nick, cmd_stack[c].type,
+                           cmd_stack[c].param,
+                           dissect_time(present - cmd_stack[c].added));
+                       delete_command(c);
+               }
+       }
 }
index e9e43913f4765dec7f5f61b6f72ff5ad5144a940..613e6b7467c54d8d0bce866ff0aa81a6f30bf5fa 100644 (file)
--- a/opercmd.h
+++ b/opercmd.h
@@ -1,44 +1,40 @@
 #ifndef OPERCMD_H
 #define OPERCMD_H
 
-       struct command {
-               /* types defined below */
-               /* THIS MUST BE CMD_NONE FOR AN EMPTY COMMAND! */
-               unsigned int type;
-
-               /* command parameter
-                * <erik> but i cant think of any commands bopm will ever
-                *   have that is multiple parameters
-                */
-               char *param;
+struct command {
+       /* Types defined below. */
+       /* THIS MUST BE CMD_NONE FOR AN EMPTY COMMAND! */
+       unsigned int type;
+
+       /* Command parameter.
+        * <erik> but i cant think of any commands bopm will ever have that is
+        *   multiple parameters
+        */
+       char *param;
        
-               /* who ordered it */    
-               char nick[NICKMAX];
+       /* Who ordered it. */   
+       char nick[NICKMAX];
 
-               /* where the reply is to be sent */
-               char *target;
+       /* Where the reply is to be sent. */
+       char *target;
 
-               /* when it was added, because we might need to remove
-                * it if it does not get executed */
-               time_t added;
-       };
+       /*
+        * When it was added, because we might need to remove it if it does
+        * not get executed.
+        */
+       time_t added;
+};
 
-       /* allow 5 outstanding commands */
-       #define MAXCMD 5
+/* Allow 5 outstanding commands. */
+#define MAXCMD 5
 
-       struct command cmd_stack[MAXCMD];
+/* One for each oper command we support. */
+#define CMD_NONE  0
+#define CMD_CHECK 1
 
-       /* one for each oper command we support */
-       #define CMD_NONE  0
-       #define CMD_CHECK 1
+extern void do_oper_cmd(const char *nick, const char *cmd,
+    const char *param, const char *target);
+extern void check_userhost(const char *userhost);
+extern void reap_commands(time_t present);
 
-       time_t LAST_REAP_TIME;
-
-       void do_oper_cmd(const char *nick, const char *cmd,
-                        const char *param, const char *target);
-       void checkoper(const char *nick, const char *param,
-           const char *target, unsigned int cmd_type);
-       void check_userhost(const char *userhost);
-       void delete_command(unsigned int index);
-       void reap_commands(time_t present);
 #endif