-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a usermode +R (block unauthed user messages) #33
base: u2_10_12_branch
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -490,16 +490,17 @@ static const struct UserMode { | |
unsigned int flag; /**< User mode constant. */ | ||
char c; /**< Character corresponding to the mode. */ | ||
} userModeList[] = { | ||
{ FLAG_OPER, 'o' }, | ||
{ FLAG_LOCOP, 'O' }, | ||
{ FLAG_INVISIBLE, 'i' }, | ||
{ FLAG_WALLOP, 'w' }, | ||
{ FLAG_SERVNOTICE, 's' }, | ||
{ FLAG_DEAF, 'd' }, | ||
{ FLAG_CHSERV, 'k' }, | ||
{ FLAG_DEBUG, 'g' }, | ||
{ FLAG_ACCOUNT, 'r' }, | ||
{ FLAG_HIDDENHOST, 'x' } | ||
{ FLAG_OPER, 'o' }, | ||
{ FLAG_LOCOP, 'O' }, | ||
{ FLAG_INVISIBLE, 'i' }, | ||
{ FLAG_WALLOP, 'w' }, | ||
{ FLAG_SERVNOTICE, 's' }, | ||
{ FLAG_DEAF, 'd' }, | ||
{ FLAG_CHSERV, 'k' }, | ||
{ FLAG_DEBUG, 'g' }, | ||
{ FLAG_ACCOUNT, 'r' }, | ||
{ FLAG_BLOCK_UNAUTH_USERS, 'R' }, | ||
{ FLAG_HIDDENHOST, 'x' } | ||
}; | ||
|
||
/** Length of #userModeList. */ | ||
|
@@ -799,9 +800,13 @@ int whisper(struct Client* source, const char* nick, const char* channel, | |
if (0 == membership || IsZombie(membership)) { | ||
return send_reply(source, ERR_USERNOTINCHANNEL, cli_name(dest), chptr->chname); | ||
} | ||
|
||
if (should_block_unauth_user(source, dest)) | ||
return send_reply_blocked_unauth_user(source, dest); | ||
|
||
if (is_silenced(source, dest)) | ||
return 0; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... although I think this whitespace cleanup is fine. |
||
if (is_notice) | ||
sendcmdto_one(source, CMD_NOTICE, dest, "%C :%s", dest, text); | ||
else | ||
|
@@ -813,6 +818,31 @@ int whisper(struct Client* source, const char* nick, const char* channel, | |
return 0; | ||
} | ||
|
||
/** Return true if the source client isn't authenticated to a registered | ||
* username, and the dest client has mode +R (block unauthed users). | ||
* @param[in] source Client sending the message. | ||
* @param[in] dest Destination of the message. | ||
*/ | ||
int should_block_unauth_user(struct Client *source, struct Client *dest) | ||
{ | ||
// Only block regular users. | ||
if (IsServer(source) || IsChannelService(source)) | ||
return 0; | ||
|
||
return IsBlockUnauthUsers(dest) && !IsAccount(source); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably a little clearer and faster to write this whole function as (with line wrapping where appropriate):
|
||
} | ||
|
||
/** Sends an error message telling the source that the dest doesn't allow | ||
* unauthed users to contact them. | ||
* @param[in] source Client whose message was blocked. | ||
* @param[in] dest Client who rejected the message. | ||
*/ | ||
int send_reply_blocked_unauth_user(struct Client *source, struct Client *dest) | ||
{ | ||
return send_reply(source, SND_EXPLICIT | ERR_NEEDREGGEDNICK, | ||
"%s :You need to be identified to a registered account to contact this user -- you can obtain an account from %s", | ||
cli_name(dest), feature_str(FEAT_URLREG)); | ||
} | ||
|
||
/** Send a user mode change for \a cptr to neighboring servers. | ||
* @param[in] cptr User whose mode is changing. | ||
|
@@ -1056,6 +1086,12 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, | |
else | ||
ClearDeaf(sptr); | ||
break; | ||
case 'R': | ||
if (what == MODE_ADD) | ||
SetBlockUnauthUsers(sptr); | ||
else | ||
ClearBlockUnauthUsers(sptr); | ||
break; | ||
case 'k': | ||
if (what == MODE_ADD) | ||
SetChannelService(sptr); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revise this to not touch whitespace on lines that don't have text changes?