3
0
mirror of https://github.com/ergochat/ergo.git synced 2025-01-03 00:22:34 +01:00

Send 477 ERR_NEEDREGGEDNICK when an unregistered user messages a +R user.

Fixes #1064.
This commit is contained in:
Alex Jaspersen 2021-03-03 19:36:29 -08:00
parent 1762a168e8
commit 23164054f6

View File

@ -2142,15 +2142,15 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
rb.Add(nil, server.name, ERR_NEEDREGGEDNICK, client.Nick(), tnick, client.t("Direct messages from unregistered users are temporarily restricted"))
return
}
// restrict messages appropriately when +R is set
if details.account == "" && user.HasMode(modes.RegisteredOnly) {
rb.Add(nil, server.name, ERR_NEEDREGGEDNICK, client.Nick(), tnick, client.t("You must be registered to send a direct message to this user"))
return
}
nickMaskString := details.nickMask
accountName := details.accountName
var deliverySessions []*Session
// restrict messages appropriately when +R is set
// intentionally make the sending user think the message went through fine
allowedPlusR := details.account != "" || !user.HasMode(modes.RegisteredOnly)
if allowedPlusR {
deliverySessions = append(deliverySessions, user.Sessions()...)
}
deliverySessions = append(deliverySessions, user.Sessions()...)
// all sessions of the sender, except the originating session, get a copy as well:
if client != user {
for _, session := range client.Sessions() {
@ -2183,10 +2183,6 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
}
}
if !allowedPlusR {
return
}
config := server.Config()
if !config.History.Enabled {
return