Rework the penalty handling slightly
authorFederico G. Schwindt <fgsch@lodoss.net>
Thu, 7 Nov 2013 16:53:29 +0000 (16:53 +0000)
committerFederico G. Schwindt <fgsch@lodoss.net>
Thu, 7 Nov 2013 16:53:29 +0000 (16:53 +0000)
Increase the penalty for a command before checking its arguments.  This
makes the handling more consistent and allow us to move more penalties to
Handle_Request().

src/ngircd/irc-info.c
src/ngircd/irc-mode.c
src/ngircd/parse.c

index 202f427f967d8cfa3d8606a61765f80c8274b197..f1d02711b35cfba3de103bfa836c366a40ad21c8 100644 (file)
@@ -152,8 +152,6 @@ IRC_WHO_Channel(CLIENT *Client, CHANNEL *Chan, bool OnlyOps)
        assert( Client != NULL );
        assert( Chan != NULL );
 
-       IRC_SetPenalty(Client, 1);
-
        is_member = Channel_IsMemberOf(Chan, Client);
 
        /* Secret channel? */
@@ -1152,7 +1150,6 @@ IRC_WHO(CLIENT *Client, REQUEST *Req)
        }
 
        /* No channel or (valid) mask given */
-       IRC_SetPenalty(Client, 2);
        return IRC_WHO_Mask(Client, NULL, only_ops);
 } /* IRC_WHO */
 
@@ -1175,8 +1172,6 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-       IRC_SetPenalty(Client, 1);
-
        /* Wrong number of parameters? */
        if (Req->argc < 1)
                return IRC_WriteErrClient(Client, ERR_NONICKNAMEGIVEN_MSG,
index 8e76db17084461f8c6c971bbd79b9858cd0c8c3e..a29ed2387fe64b1274c9636ebee70724e9e10fb7 100644 (file)
@@ -357,7 +357,6 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
                         Client_Modes(Target));
        }
 
-       IRC_SetPenalty(Client, 1);
        return ok;
 } /* Client_Mode */
 
@@ -918,7 +917,6 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                }
        }
 
-       IRC_SetPenalty(Client, 1);
        return connected;
 } /* Channel_Mode */
 
index 4235497b35e43d34aedc8f04a93c8df8237c2af4..fdb957c3efe0c52d881ff3cdffd6bf345e98de02 100644 (file)
@@ -86,7 +86,7 @@ static COMMAND My_Commands[] =
        _CMD("LIST", IRC_LIST, CLIENT_USER|CLIENT_SERVER, 0, 2, 2),
        _CMD("LUSERS", IRC_LUSERS, CLIENT_USER|CLIENT_SERVER, 0, 2, 1),
        _CMD("METADATA", IRC_METADATA, CLIENT_SERVER, 3, 3, 0),
-       _CMD("MODE", IRC_MODE, CLIENT_USER|CLIENT_SERVER, 1, -1, 0),
+       _CMD("MODE", IRC_MODE, CLIENT_USER|CLIENT_SERVER, 1, -1, 1),
        _CMD("MOTD", IRC_MOTD, CLIENT_USER|CLIENT_SERVER, 0, 1, 3),
        _CMD("NAMES", IRC_NAMES, CLIENT_USER|CLIENT_SERVER, 0, 2, 1),
        _CMD("NICK", IRC_NICK, CLIENT_ANY, 0, -1, 0),
@@ -119,7 +119,7 @@ static COMMAND My_Commands[] =
        _CMD("WALLOPS", IRC_WALLOPS, CLIENT_USER|CLIENT_SERVER, 1, 1, 0),
        _CMD("WEBIRC", IRC_WEBIRC, CLIENT_UNKNOWN, 4, 4, 0),
        _CMD("WHO", IRC_WHO, CLIENT_USER, 0, 2, 1),
-       _CMD("WHOIS", IRC_WHOIS, CLIENT_USER|CLIENT_SERVER, 0, -1, 0),
+       _CMD("WHOIS", IRC_WHOIS, CLIENT_USER|CLIENT_SERVER, 0, -1, 1),
        _CMD("WHOWAS", IRC_WHOWAS, CLIENT_USER|CLIENT_SERVER, 0, -1, 0),
 
 #ifdef IRCPLUS
@@ -533,14 +533,14 @@ Handle_Request( CONN_ID Idx, REQUEST *Req )
                                                Client_ID(client));
                }
 
+               if (cmd->penalty)
+                       IRC_SetPenalty(client, cmd->penalty);
+
                if (Req->argc < cmd->min_argc ||
                    (cmd->max_argc != -1 && Req->argc > cmd->max_argc))
                        return IRC_WriteErrClient(client, ERR_NEEDMOREPARAMS_MSG,
                                                  Client_ID(client), Req->command);
 
-               if (cmd->penalty)
-                       IRC_SetPenalty(client, cmd->penalty);
-
                /* Command is allowed for this client: call it and count
                 * generated bytes in output */
                Conn_ResetWCounter();