]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-mode.c
Changed the reply of the MODE command to match the syntax of the original
[ngircd-alex.git] / src / ngircd / irc-mode.c
index c5eeadfb5e87938e29fbb2a6c268529f918c5af1..28e5327e07dc36625d53ad9596b37580290c851c 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-mode.c,v 1.25 2002/12/26 16:48:14 alex Exp $";
+static char UNUSED id[] = "$Id: irc-mode.c,v 1.33 2004/02/29 16:28:44 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -157,7 +157,11 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
                {
                        case 'a':
                                /* Away */
-                               if( Client_Type( Client ) == CLIENT_SERVER ) x[0] = 'a';
+                               if( Client_Type( Client ) == CLIENT_SERVER )
+                               {
+                                       x[0] = 'a';
+                                       Client_SetAway( Client, DEFAULT_AWAY_MSG );
+                               }
                                else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
                                break;
                        case 'i':
@@ -221,12 +225,13 @@ client_exit:
                else
                {
                        /* Send reply to client and inform other servers */
-                       ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s", Client_ID( Target ), the_modes );
+                       ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
                        IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
                }
                Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( Target ), Client_Modes( Target ));
        }
-               
+       
+       IRC_SetPenalty( Client, 1 );    
        return ok;
 } /* Client_Mode */
 
@@ -243,11 +248,42 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
        LONG l;
 
        /* Mode request: let's answer it :-) */
-       if( Req->argc == 1 ) return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), Channel_Modes( Channel ));
+       if( Req->argc == 1 )
+       {
+               /* Member or not? -- That's the question! */
+               if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), Channel_Modes( Channel ));
+
+               /* The sender is a member: generate extended reply */
+               strlcpy( the_modes, Channel_Modes( Channel ), sizeof( the_modes ));
+               mode_ptr = the_modes;
+               strcpy( the_args, "" );
+               while( *mode_ptr )
+               {
+                       switch( *mode_ptr )
+                       {
+                               case 'l':
+                                       snprintf( argadd, sizeof( argadd ), " %ld", Channel_MaxUsers( Channel ));
+                                       strlcat( the_args, argadd, sizeof( the_args ));
+                                       break;
+                               case 'k':
+                                       strlcat( the_args, " ", sizeof( the_args ));
+                                       strlcat( the_args, Channel_Key( Channel ), sizeof( the_args ));
+                                       break;
+                       }
+                       mode_ptr++;
+               }
+               if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
+
+               return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
+       }
 
        /* Is the user allowed to change modes? */
        if( Client_Type( Client ) == CLIENT_USER )
        {
+               /* Is the originating user on that channel? */
+               if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Channel_Name( Channel ));
+
+               /* Is he channel operator? */
                if( strchr( Channel_UserModes( Channel, Origin ), 'o' )) modeok = TRUE;
                else modeok = FALSE;
                if( Conf_OperCanMode )
@@ -392,7 +428,7 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
                                        {
                                                Channel_ModeDel( Channel, 'k' );
                                                Channel_SetKey( Channel, Req->argv[arg_arg] );
-                                               strcpy( argadd, Channel_Key( Channel ));
+                                               strlcpy( argadd, Channel_Key( Channel ), sizeof( argadd ));
                                                x[0] = *mode_ptr;
                                        }
                                        else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
@@ -418,7 +454,7 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
                                                {
                                                        Channel_ModeDel( Channel, 'l' );
                                                        Channel_SetMaxUsers( Channel, l );
-                                                       sprintf( argadd, "%ld", l );
+                                                       snprintf( argadd, sizeof( argadd ), "%ld", l );
                                                        x[0] = *mode_ptr;
                                                }
                                        }
@@ -474,6 +510,13 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
                /* Is there a valid mode change? */
                if( ! x[0] ) continue;
 
+               /* Validate target client */
+               if( client && ( ! Channel_IsMemberOf( Channel, client )))
+               {
+                       if( ! IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( client ), Channel_Name( Channel ))) break;
+                       continue;
+               }
+
                if( set )
                {
                        /* Set mode */
@@ -556,6 +599,7 @@ chan_exit:
                }
        }
 
+       IRC_SetPenalty( Client, 1 );
        return CONNECTED;
 } /* Channel_Mode */
 
@@ -573,13 +617,14 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
        {
                /* AWAY setzen */
                Client_SetAway( Client, Req->argv[0] );
+               Client_ModeAdd( Client, 'a' );
                IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
                return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
        }
        else
        {
                /* AWAY loeschen */
-               Client_SetAway( Client, NULL );
+               Client_ModeDel( Client, 'a' );
                IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
                return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
        }