/*
* 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
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 );
/* 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);
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));
}
}
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 {
/* 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);
}
}