commit - 672a1679639d597cf1c4336687ac78dcc24a9559
commit + c74115f25c8ea3f67c75120c0a1398975bac03ad
blob - 45bf615c29d604b453807e2a1e6c2b07c8c3f02c
blob + c5f65fe8051f9dbca27c2f26f073c731112ced08
--- src/ngircd/channel.c
+++ src/ngircd/channel.c
const char *Reason )
{
CHANNEL *chan;
- char *ptr, *target_modes;
bool can_kick = false;
assert(Peer != NULL);
if(Client_Type(Peer) == CLIENT_USER) {
/* Channel mode 'Q' and user mode 'q' on target: nobody but
* IRC Operators and servers can kick the target user */
- if ((strchr(Channel_Modes(chan), 'Q')
+ if ((Channel_HasMode(chan, 'Q')
|| Client_HasMode(Target, 'q')
|| Client_Type(Target) == CLIENT_SERVICE)
&& !Client_HasMode(Origin, 'o')) {
}
/* Check if client has the rights to kick target */
- ptr = Channel_UserModes(chan, Peer);
- target_modes = Channel_UserModes(chan, Target);
- while(*ptr) {
- /* Owner can kick everyone */
- if ( *ptr == 'q') {
- can_kick = true;
- break;
- }
- /* Admin can't kick owner */
- if ( *ptr == 'a' ) {
- if (!strchr(target_modes, 'q')) {
- can_kick = true;
- break;
- }
- }
- /* Op can't kick owner | admin */
- if ( *ptr == 'o' ) {
- if (!strchr(target_modes, 'q') &&
- !strchr(target_modes, 'a')) {
- can_kick = true;
- break;
- }
- }
- /* Half Op can't kick owner | admin | op */
- if ( *ptr == 'h' ) {
- if (!strchr(target_modes, 'q') &&
- !strchr(target_modes, 'a') &&
- !strchr(target_modes, 'o')) {
- can_kick = true;
- break;
- }
- }
- ptr++;
- }
+
+ /* Owner can kick everyone */
+ if (Channel_UserHasMode(chan, Peer, 'q'))
+ can_kick = true;
+
+ /* Admin can't kick owner */
+ else if (Channel_UserHasMode(chan, Peer, 'a') &&
+ !Channel_UserHasMode(chan, Target, 'q'))
+ can_kick = true;
+
+ /* Op can't kick owner | admin */
+ else if (Channel_UserHasMode(chan, Peer, 'o') &&
+ !Channel_UserHasMode(chan, Target, 'q') &&
+ !Channel_UserHasMode(chan, Target, 'a'))
+ can_kick = true;
+
+ /* Half Op can't kick owner | admin | op */
+ else if (Channel_UserHasMode(chan, Peer, 'h') &&
+ !Channel_UserHasMode(chan, Target, 'q') &&
+ !Channel_UserHasMode(chan, Target, 'a') &&
+ !Channel_UserHasMode(chan, Target, 'o'))
+ can_kick = true;
if(!can_kick) {
IRC_WriteStrClient(Origin, ERR_CHANOPPRIVTOOLOW_MSG,
c = My_Channels;
while(c) {
if (Client) {
- if (!strchr(Channel_Modes(c), 's')
+ if (!Channel_HasMode(c, 's')
|| Channel_IsMemberOf(c, Client))
count++;
} else
} /* Channel_Modes */
+GLOBAL bool
+Channel_HasMode( CHANNEL *Chan, char Mode )
+{
+ assert( Chan != NULL );
+ return strchr( Chan->modes, Mode ) != NULL;
+} /* Channel_HasMode */
+
+
GLOBAL char *
Channel_Key( CHANNEL *Chan )
{
assert( Chan != NULL );
x[0] = Mode; x[1] = '\0';
- if( ! strchr( Chan->modes, x[0] ))
+ if( ! Channel_HasMode( Chan, x[0] ))
{
/* Channel does not have this mode yet, set it */
strlcat( Chan->modes, x, sizeof( Chan->modes ));
return cl2chan->modes;
} /* Channel_UserModes */
+
+
+GLOBAL bool
+Channel_UserHasMode( CHANNEL *Chan, CLIENT *Client, char Mode )
+{
+ return strchr(Channel_UserModes(Chan, Client), Mode) != NULL;
+} /* Channel_UserHasMode */
GLOBAL bool
if (Channel_IsMemberOf(Chan, From)) {
is_member = true;
- if (strchr(Channel_UserModes(Chan, From), 'v'))
- has_voice = true;
- if (strchr(Channel_UserModes(Chan, From), 'h'))
+ if (Channel_UserHasMode(Chan, From, 'v'))
+ has_voice = true;
+ if (Channel_UserHasMode(Chan, From, 'h'))
is_halfop = true;
- if (strchr(Channel_UserModes(Chan, From), 'o'))
+ if (Channel_UserHasMode(Chan, From, 'o'))
is_op = true;
- if (strchr(Channel_UserModes(Chan, From), 'a'))
+ if (Channel_UserHasMode(Chan, From, 'a'))
is_chanadmin = true;
- if (strchr(Channel_UserModes(Chan, From), 'q'))
+ if (Channel_UserHasMode(Chan, From, 'q'))
is_owner = true;
}
* If channel mode n set: non-members cannot send to channel.
* If channel mode m set: need voice.
*/
- if (strchr(Channel_Modes(Chan), 'n') && !is_member)
+ if (Channel_HasMode(Chan, 'n') && !is_member)
return false;
- if (strchr(Channel_Modes(Chan), 'M') && !Client_HasMode(From, 'R')
+ if (Channel_HasMode(Chan, 'M') && !Client_HasMode(From, 'R')
&& !Client_HasMode(From, 'o'))
return false;
if (has_voice || is_halfop || is_op || is_chanadmin || is_owner)
return true;
- if (strchr(Channel_Modes(Chan), 'm'))
+ if (Channel_HasMode(Chan, 'm'))
return false;
if (Lists_Check(&Chan->list_excepts, From))
if (!Can_Send_To_Channel(Chan, From)) {
if (! SendErrors)
return CONNECTED; /* no error, see RFC 2812 */
- if (strchr(Channel_Modes(Chan), 'M'))
+ if (Channel_HasMode(Chan, 'M'))
return IRC_WriteStrClient(From, ERR_NEEDREGGEDNICK_MSG,
Client_ID(From), Channel_Name(Chan));
else
}
/* When channel is empty and is not pre-defined, delete */
- if( ! strchr( Channel_Modes( Chan ), 'P' ))
+ if( ! Channel_HasMode( Chan, 'P' ))
{
if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
}
assert(Client != NULL);
assert(Key != NULL);
- if (!strchr(Chan->modes, 'k'))
+ if (!Channel_HasMode(Chan, 'k'))
return true;
if (*Key == '\0')
return false;
blob - d8607a9cb68cf6c27c2428a6e6d4df4d18bceaaa
blob + 1bc77760942bbebbc2ed55d84d27dcc4f2d99651
--- src/ngircd/channel.h
+++ src/ngircd/channel.h
GLOBAL int Channel_CountForUser PARAMS(( CLIENT *Client ));
GLOBAL const char *Channel_Name PARAMS(( const CHANNEL *Chan ));
-GLOBAL char *Channel_Modes PARAMS(( CHANNEL *Chan ));
GLOBAL char *Channel_Topic PARAMS(( CHANNEL *Chan ));
GLOBAL char *Channel_Key PARAMS(( CHANNEL *Chan ));
GLOBAL unsigned long Channel_MaxUsers PARAMS(( CHANNEL *Chan ));
GLOBAL bool Channel_ModeAdd PARAMS(( CHANNEL *Chan, char Mode ));
GLOBAL bool Channel_ModeDel PARAMS(( CHANNEL *Chan, char Mode ));
+GLOBAL bool Channel_HasMode PARAMS(( CHANNEL *Chan, char Mode ));
+GLOBAL char *Channel_Modes PARAMS(( CHANNEL *Chan ));
GLOBAL bool Channel_UserModeAdd PARAMS(( CHANNEL *Chan, CLIENT *Client, char Mode ));
GLOBAL bool Channel_UserModeDel PARAMS(( CHANNEL *Chan, CLIENT *Client, char Mode ));
+GLOBAL bool Channel_UserHasMode PARAMS(( CHANNEL *Chan, CLIENT *Client, char Mode ));
GLOBAL char *Channel_UserModes PARAMS(( CHANNEL *Chan, CLIENT *Client ));
GLOBAL bool Channel_IsMemberOf PARAMS(( CHANNEL *Chan, CLIENT *Client ));
blob - 07a6e5a530b677684b9f713db5bc31d4cce28f5c
blob + d06caa3161f255f45d891ebea39210bc0282c574
--- src/ngircd/irc-channel.c
+++ src/ngircd/irc-channel.c
const char *key)
{
bool is_invited, is_banned, is_exception;
- const char *channel_modes;
/* Allow IRC operators to overwrite channel limits */
- if (strchr(Client_Modes(Client), 'o'))
+ if (Client_HasMode(Client, 'o'))
return true;
is_banned = Lists_Check(Channel_GetListBans(chan), Client);
return false;
}
- channel_modes = Channel_Modes(chan);
- if (strchr(channel_modes, 'i') && !is_invited) {
+ if (Channel_HasMode(chan, 'i') && !is_invited) {
/* Channel is "invite-only" and client is not on invite list */
IRC_WriteStrClient(Client, ERR_INVITEONLYCHAN_MSG,
Client_ID(Client), channame);
return false;
}
- if (strchr(channel_modes, 'l') &&
+ if (Channel_HasMode(chan, 'l') &&
(Channel_MaxUsers(chan) <= Channel_MemberCount(chan))) {
/* There are more clints joined to this channel than allowed */
IRC_WriteStrClient(Client, ERR_CHANNELISFULL_MSG,
return false;
}
- if (strchr(channel_modes, 'z') && !Conn_UsesSSL(Client_Conn(Client))) {
+ if (Channel_HasMode(chan, 'z') && !Conn_UsesSSL(Client_Conn(Client))) {
/* Only "secure" clients are allowed, but clients doesn't
* use SSL encryption */
IRC_WriteStrClient(Client, ERR_SECURECHANNEL_MSG,
return false;
}
- if (strchr(channel_modes, 'O') && !Client_OperByMe(Client)) {
+ if (Channel_HasMode(chan, 'O') && !Client_OperByMe(Client)) {
/* Only IRC operators are allowed! */
IRC_WriteStrClient(Client, ERR_OPONLYCHANNEL_MSG,
Client_ID(Client), channame);
return false;
}
- if (strchr(channel_modes, 'R') && !strchr(Client_Modes(Client), 'R')) {
+ if (Channel_HasMode(chan, 'R') && !Client_HasMode(Client, 'R')) {
/* Only registered users are allowed! */
IRC_WriteStrClient(Client, ERR_REGONLYCHANNEL_MSG,
Client_ID(Client), channame);
/* If the channel is persistent (+P) and client is an IRC op:
* make client chanop, if not disabled in configuration. */
- if (strchr(Channel_Modes(chan), 'P') && Conf_OperChanPAutoOp
- && strchr(Client_Modes(target), 'o'))
+ if (Channel_HasMode(chan, 'P') && Conf_OperChanPAutoOp
+ && Client_HasMode(target, 'o'))
Channel_UserModeAdd(chan, target, 'o');
} /* join_set_channelmodes */
Channel_Name(chan));
}
- if (strchr(Channel_Modes(chan), 't')) {
+ if (Channel_HasMode(chan, 't')) {
/* Topic Lock. Is the user a channel op or IRC operator? */
if(!topic_power &&
- !strchr(Channel_UserModes(chan, from), 'h') &&
- !strchr(Channel_UserModes(chan, from), 'o') &&
- !strchr(Channel_UserModes(chan, from), 'a') &&
- !strchr(Channel_UserModes(chan, from), 'q'))
+ !Channel_UserHasMode(chan, from, 'h') &&
+ !Channel_UserHasMode(chan, from, 'o') &&
+ !Channel_UserHasMode(chan, from, 'a') &&
+ !Channel_UserHasMode(chan, from, 'q'))
return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
Client_ID(from),
Channel_Name(chan));
/* Check search pattern */
if (MatchCaseInsensitive(pattern, Channel_Name(chan))) {
/* Gotcha! */
- if (!strchr(Channel_Modes(chan), 's')
+ if (!Channel_HasMode(chan, 's')
|| Channel_IsMemberOf(chan, from)
|| (!Conf_MorePrivacy && Client_OperByMe(Client))) {
if ((Conf_MaxListSize > 0)
Channel_SetModes(chan, &Req->argv[1][1]);
if(Req->argc == 5) {
- if(strchr(Channel_Modes(chan), 'k'))
+ if(Channel_HasMode(chan, 'k'))
Channel_SetKey(chan, Req->argv[2]);
- if(strchr(Channel_Modes(chan), 'l'))
+ if(Channel_HasMode(chan, 'l'))
Channel_SetMaxUsers(chan, atol(Req->argv[3]));
} else {
/* Delete modes which we never want to inherit */
blob - 6fb2e31c9470c38703100983821759a5f1e7506c
blob + 5d2ae36ddda7afc217f504368ca143e7f415d6c9
--- src/ngircd/irc-info.c
+++ src/ngircd/irc-info.c
is_member = Channel_IsMemberOf(Chan, Client);
/* Secret channel? */
- if (!is_member && strchr(Channel_Modes(Chan), 's'))
+ if (!is_member && Channel_HasMode(Chan, 's'))
return IRC_WriteStrClient(Client, RPL_ENDOFWHO_MSG,
Client_ID(Client), Channel_Name(Chan));
c = Channel_GetClient(cl2chan);
client_modes = Client_Modes(c);
- is_ircop = strchr(client_modes, 'o') != NULL;
+ is_ircop = Client_HasMode(c, 'o');
if (OnlyOps && !is_ircop)
continue;
- is_visible = strchr(client_modes, 'i') == NULL;
+ is_visible = Client_HasMode(c, 'i');
if (is_member || is_visible) {
strlcpy(flags, who_flags_status(client_modes),
sizeof(flags));
break;
strlcpy(flags, who_flags_status(Client_Modes(c)), sizeof(flags));
- if (strchr(Client_Modes(c), 'o'))
+ if (Client_HasMode(c, 'o'))
strlcat(flags, "*", sizeof(flags));
if (!write_whoreply(Client, c, "*", flags))
cl2chan = Channel_NextChannelOf(c, cl2chan);
/* Secret channel? */
- if (strchr(Channel_Modes(chan), 's')
+ if (Channel_HasMode(chan, 's')
&& !Channel_IsMemberOf(chan, Client))
continue;
while (c) {
if (Client_Type(c) == CLIENT_USER
&& Channel_FirstChannelOf(c) == NULL
- && !strchr(Client_Modes(c), 'i'))
+ && !Client_HasMode(c, 'i'))
{
/* its a user, concatenate ... */
if (rpl[strlen(rpl) - 1] != ':')
return CONNECTED;
/* Secret channel? */
- if (!is_member && strchr(Channel_Modes(Chan), 's'))
+ if (!is_member && Channel_HasMode(Chan, 's'))
return CONNECTED;
snprintf(str, sizeof(str), RPL_NAMREPLY_MSG, Client_ID(Client), "=",
while (cl2chan) {
cl = Channel_GetClient(cl2chan);
- if (strchr(Client_Modes(cl), 'i'))
+ if (Client_HasMode(cl, 'i'))
is_visible = false;
else
is_visible = true;
blob - cebddd22ef551dff43366b06f0ba50e0e38ff577
blob + 0df848f3943ee1a18c685f403898e353784014b2
--- src/ngircd/irc-mode.c
+++ src/ngircd/irc-mode.c
Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
{
char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
- argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
+ argadd[CLIENT_PASS_LEN], *mode_ptr;
bool connected, set, skiponce, retval, use_servermode,
is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
int mode_arg, arg_arg, mode_arg_count = 0;
arg_arg = -1;
if(!is_machine && !is_oper) {
- o_mode_ptr = Channel_UserModes(Channel, Client);
- while( *o_mode_ptr ) {
- if ( *o_mode_ptr == 'q')
- is_owner = true;
- if ( *o_mode_ptr == 'a')
- is_admin = true;
- if ( *o_mode_ptr == 'o')
- is_op = true;
- if ( *o_mode_ptr == 'h')
- is_halfop = true;
- o_mode_ptr++;
- }
+ if (Channel_UserHasMode(Channel, Client, 'q'))
+ is_owner = true;
+ if (Channel_UserHasMode(Channel, Client, 'a'))
+ is_admin = true;
+ if (Channel_UserHasMode(Channel, Client, 'o'))
+ is_op = true;
+ if (Channel_UserHasMode(Channel, Client, 'h'))
+ is_halfop = true;
}
/* Validate modes */
blob - 23fcc71cc14cfe8a352138a433d6a7e1e2a7f82b
blob + 0d471512f6e024581e530344c108751bdbe96332
--- src/ngircd/irc-op.c
+++ src/ngircd/irc-op.c
return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG, Client_ID(Client), Req->argv[1]);
/* Is the channel "invite-disallow"? */
- if (strchr(Channel_Modes(chan), 'V'))
+ if (Channel_HasMode(chan, 'V'))
return IRC_WriteStrClient(from, ERR_NOINVITE_MSG,
Client_ID(from), Channel_Name(chan));
/* Is the channel "invite-only"? */
- if (strchr(Channel_Modes(chan), 'i')) {
+ if (Channel_HasMode(chan, 'i')) {
/* Yes. The user must be channel owner/admin/operator/halfop! */
- if (!strchr(Channel_UserModes(chan, from), 'q') &&
- !strchr(Channel_UserModes(chan, from), 'a') &&
- !strchr(Channel_UserModes(chan, from), 'o') &&
- !strchr(Channel_UserModes(chan, from), 'h'))
+ if (!Channel_UserHasMode(chan, from, 'q') &&
+ !Channel_UserHasMode(chan, from, 'a') &&
+ !Channel_UserHasMode(chan, from, 'o') &&
+ !Channel_UserHasMode(chan, from, 'h'))
return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
Client_ID(from), Channel_Name(chan));
remember = true;
Client_ID(from), Req->argv[0], colon_if_necessary, Req->argv[1]))
return DISCONNECTED;
- if (strchr(Client_Modes(target), 'a') &&
+ if (Client_HasMode(target, 'a') &&
!IRC_WriteStrClient(from, RPL_AWAY_MSG, Client_ID(from),
Client_ID(target), Client_Away(target)))
return DISCONNECTED;
blob - ddef7d021ac3d8b03891062933408df4b0f2cae0
blob + e4f483070c1ae494040820f3ea2fe2b9fb0883fb
--- src/ngircd/irc.c
+++ src/ngircd/irc.c
return DISCONNECTED;
}
if (Client_Type(c) == CLIENT_USER
- && strchr(Client_Modes(c), 'o')) {
+ && Client_HasMode(c, 'o')) {
/* IRC Operator */
if (!IRC_WriteStrClient(from,
RPL_TRACEOPERATOR_MSG,
}
if (SendErrors && (Client_Type(Client) != CLIENT_SERVER)
- && strchr(Client_Modes(cl), 'a')) {
+ && Client_HasMode(cl, 'a')) {
/* Target is away */
if (!IRC_WriteStrClient(from, RPL_AWAY_MSG,
Client_ID(from),
cl = NULL;
- if (strchr(Client_Modes(from), 'o') == NULL) {
+ if (!Client_HasMode(from, 'o')) {
if (!SendErrors)
return true;
return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
blob - f2c61e8a8cb46ea0b7b7649ad73b76c7f9db438a
blob + a43739f18bf4dec9b44183396526c157d408b84b
--- src/ngircd/numeric.c
+++ src/ngircd/numeric.c
strlcat(str, ",", sizeof(str));
/* Prepare user prefix (ChanOp, voiced, ...) */
- if (xop && strchr(Channel_UserModes(Chan, cl), 'q'))
+ if (xop && Channel_UserHasMode(Chan, cl, 'q'))
strlcat(str, "~", sizeof(str));
- if (xop && strchr(Channel_UserModes(Chan, cl), 'a'))
+ if (xop && Channel_UserHasMode(Chan, cl, 'a'))
strlcat(str, "&", sizeof(str));
- if (strchr(Channel_UserModes(Chan, cl), 'o'))
+ if (Channel_UserHasMode(Chan, cl, 'o'))
strlcat(str, "@", sizeof(str));
- if (xop && strchr(Channel_UserModes(Chan, cl), 'h'))
+ if (xop && Channel_UserHasMode(Chan, cl, 'h'))
strlcat(str, "%", sizeof(str));
- if (strchr(Channel_UserModes(Chan, cl), 'v'))
+ if (Channel_UserHasMode(Chan, cl, 'v'))
strlcat(str, "+", sizeof(str));
strlcat(str, Client_ID(cl), sizeof(str));
if (!*modes && !*topic)
return CONNECTED;
- has_k = strchr(modes, 'k') != NULL;
- has_l = strchr(modes, 'l') != NULL;
+ has_k = Channel_HasMode(Chan, 'k');
+ has_l = Channel_HasMode(Chan, 'l');
/* send CHANINFO */
if (!has_k && !has_l) {