]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-mode.c
Implement the IRC command "SERVLIST"
[ngircd-alex.git] / src / ngircd / irc-mode.c
index d711bf34678c212152b26dd3d49df6b58ddfe0e5..ed70a9bb9d3618519e6ad5f2837cba0a600f7742 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
  *
  * 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
@@ -229,7 +229,9 @@ client_exit:
                        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 ));
+               LogDebug("%s \"%s\": Mode change, now \"%s\".",
+                        Client_TypeText(Target), Client_Mask(Target),
+                        Client_Modes(Target));
        }
        
        IRC_SetPenalty( Client, 1 );    
@@ -280,12 +282,17 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
        /* Handle channel and channel-user modes */
 
        char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
-       bool ok, set, modeok = true, skiponce, use_servermode = false;
+       bool ok, set, modeok = true, skiponce, use_servermode = false, retval;
        int mode_arg, arg_arg;
        CLIENT *client;
        long l;
        size_t len;
 
+       /* Are modes allowed on channel? */
+       if (Channel_Name(Channel)[0] == '+')
+               return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
+                               Client_ID(Client), Channel_Name(Channel));
+
        /* Mode request: let's answer it :-) */
        if (Req->argc <= 1)
                return Channel_Mode_Answer_Request(Origin, Channel);
@@ -519,37 +526,20 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
 
                if (client) {
                        /* Channel-User-Mode */
-                       if (set) {
-                               if (Channel_UserModeAdd(Channel, client, x[0])) {
-                                       strlcat(the_args, " ", sizeof(the_args));
-                                       strlcat(the_args, Client_ID(client), sizeof(the_args));
-                                       strlcat(the_modes, x, sizeof(the_modes));
-                                       Log(LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"",
-                                               Client_Mask(client), Channel_Name(Channel), Channel_UserModes(Channel, client));
-                               }
-                       } else {
-                               if (Channel_UserModeDel(Channel, client, x[0])) {
-                                       strlcat(the_args, " ", sizeof(the_args));
-                                       strlcat(the_args, Client_ID(client), sizeof(the_args));
-                                       strlcat(the_modes, x, sizeof(the_modes));
-                                       Log(LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"",
-                                               Client_Mask(client), Channel_Name(Channel), Channel_UserModes(Channel, client));
-                               }
+                       retval = set ? Channel_UserModeAdd(Channel, client, x[0]) : Channel_UserModeDel(Channel, client, x[0]);
+                       if (retval) {
+                               strlcat(the_args, " ", sizeof(the_args));
+                               strlcat(the_args, Client_ID(client), sizeof(the_args));
+                               strlcat(the_modes, x, sizeof(the_modes));
+                               Log(LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"",
+                                       Client_Mask(client), Channel_Name(Channel), Channel_UserModes(Channel, client));
                        }
                } else {
                        /* Channel-Mode */
-                       if (set) {
-                               if (Channel_ModeAdd( Channel, x[0])) {
-                                       strlcat(the_modes, x, sizeof(the_modes));
-                                       Log(LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name(Channel), Channel_Modes(Channel));
-                               }
-                       } else {
-                               /* Channel-Mode */
-                               if (Channel_ModeDel(Channel, x[0])) {
-                                       strlcat(the_modes, x, sizeof(the_modes));
-                                       Log(LOG_DEBUG, "Channel %s: Mode change, now \"%s\".",
-                                               Channel_Name(Channel), Channel_Modes(Channel));
-                               }
+                       retval = set ? Channel_ModeAdd(Channel, x[0]) : Channel_ModeDel(Channel, x[0]);
+                       if (retval) {
+                               strlcat(the_modes, x, sizeof(the_modes));
+                               Log(LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name(Channel), Channel_Modes(Channel));
                        }
                }
 
@@ -568,7 +558,15 @@ chan_exit:
                        the_modes[len] = '\0';
 
                if (Client_Type(Client) == CLIENT_SERVER) {
-                       /* Forward mode changes to channel users and other servers */
+                       /* MODE requests for local channels from other servers
+                        * are definitely invalid! */
+                       if (Channel_IsLocal(Channel)) {
+                               Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
+                               return CONNECTED;
+                       }
+
+                       /* Forward mode changes to channel users and all the
+                        * other remote servers: */
                        IRC_WriteStrServersPrefix(Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args);
                        IRC_WriteStrChannelPrefix(Client, Channel, Origin, false, "MODE %s %s%s", Channel_Name(Channel), the_modes, the_args);
                } else {
@@ -577,10 +575,14 @@ chan_exit:
                        /* Send reply to client and inform other servers and channel users */
                        ok = IRC_WriteStrClientPrefix(Client, Origin, "MODE %s %s%s",
                                        Channel_Name(Channel), the_modes, the_args);
-                       IRC_WriteStrServersPrefix(Client, Origin, "MODE %s %s%s",
-                                       Channel_Name(Channel), the_modes, the_args);
-                       IRC_WriteStrChannelPrefix(Client, Channel, Origin, false, "MODE %s %s%s",
-                                               Channel_Name(Channel), the_modes, the_args);
+                       /* Only forward requests for non-local channels */
+                       if (!Channel_IsLocal(Channel))
+                               IRC_WriteStrServersPrefix(Client, Origin,
+                                       "MODE %s %s%s", Channel_Name(Channel),
+                                       the_modes, the_args);
+                       IRC_WriteStrChannelPrefix(Client, Channel, Origin,
+                               false, "MODE %s %s%s", Channel_Name(Channel),
+                               the_modes, the_args);
                }
        }