3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

modes: Add experimental, untested +R user mode to block messages from unregistered users

This commit is contained in:
Daniel Oaks 2017-08-17 17:52:30 +10:00
parent b975c6f182
commit f9ef97b204
3 changed files with 17 additions and 7 deletions

View File

@ -64,6 +64,7 @@ Oragono supports the following user modes:
+a | User is marked as being away. This mode is set with the /AWAY command. +a | User is marked as being away. This mode is set with the /AWAY command.
+i | User is marked as invisible (their channels are hidden from whois replies). +i | User is marked as invisible (their channels are hidden from whois replies).
+o | User is an IRC operator. +o | User is an IRC operator.
+R | User only accepts messages from other registered users.
+s | Server Notice Masks (see help with /HELPOP snomasks). +s | Server Notice Masks (see help with /HELPOP snomasks).
+Z | User is connected via TLS.` +Z | User is connected via TLS.`
snomaskHelpText = `== Server Notice Masks == snomaskHelpText = `== Server Notice Masks ==

View File

@ -101,6 +101,7 @@ const (
LocalOperator Mode = 'O' LocalOperator Mode = 'O'
Operator Mode = 'o' Operator Mode = 'o'
Restricted Mode = 'r' Restricted Mode = 'r'
RegisteredOnly Mode = 'R'
ServerNotice Mode = 's' ServerNotice Mode = 's'
TLS Mode = 'Z' TLS Mode = 'Z'
UserRoleplaying Mode = 'E' UserRoleplaying Mode = 'E'
@ -110,7 +111,7 @@ const (
var ( var (
// SupportedUserModes are the user modes that we actually support (modifying). // SupportedUserModes are the user modes that we actually support (modifying).
SupportedUserModes = Modes{ SupportedUserModes = Modes{
Away, Invisible, Operator, ServerNotice, UserRoleplaying, Away, Invisible, Operator, RegisteredOnly, ServerNotice, UserRoleplaying,
} }
// supportedUserModesString acts as a cache for when we introduce users // supportedUserModesString acts as a cache for when we introduce users
supportedUserModesString = SupportedUserModes.String() supportedUserModesString = SupportedUserModes.String()
@ -127,9 +128,9 @@ const (
Moderated Mode = 'm' // flag Moderated Mode = 'm' // flag
NoOutside Mode = 'n' // flag NoOutside Mode = 'n' // flag
OpOnlyTopic Mode = 't' // flag OpOnlyTopic Mode = 't' // flag
RegisteredOnly Mode = 'r' // flag // RegisteredOnly mode is reused here from umode definition
Secret Mode = 's' // flag Secret Mode = 's' // flag
UserLimit Mode = 'l' // flag arg UserLimit Mode = 'l' // flag arg
) )
var ( var (
@ -281,7 +282,7 @@ func (client *Client) applyUserModeChanges(force bool, changes ModeChanges) Mode
for _, change := range changes { for _, change := range changes {
switch change.mode { switch change.mode {
case Invisible, WallOps, UserRoleplaying, Operator, LocalOperator: case Invisible, WallOps, UserRoleplaying, Operator, LocalOperator, RegisteredOnly:
switch change.op { switch change.op {
case Add: case Add:
if !force && (change.mode == Operator || change.mode == LocalOperator) { if !force && (change.mode == Operator || change.mode == LocalOperator) {

View File

@ -1133,7 +1133,11 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
clientOnlyTags = nil clientOnlyTags = nil
} }
msgid := server.generateMessageID() msgid := server.generateMessageID()
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg) // restrict messages appropriately when +R is set
// intentionally make the sending user think the message went through fine
if !user.flags[RegisteredOnly] || client.registered {
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
}
if client.capabilities[EchoMessage] { if client.capabilities[EchoMessage] {
client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg) client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
} }
@ -1829,7 +1833,11 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
clientOnlyTags = nil clientOnlyTags = nil
} }
msgid := server.generateMessageID() msgid := server.generateMessageID()
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg) // restrict messages appropriately when +R is set
// intentionally make the sending user think the message went through fine
if !user.flags[RegisteredOnly] || client.registered {
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
}
if client.capabilities[EchoMessage] { if client.capabilities[EchoMessage] {
client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg) client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
} }