Skip to content

Commit

Permalink
Merge pull request ergochat#1591 from slingamn/grabbag
Browse files Browse the repository at this point in the history
some small fixes/enhancements
  • Loading branch information
slingamn authored Mar 11, 2021
2 parents de31430 + fe8e655 commit 507d53c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 16 deletions.
6 changes: 6 additions & 0 deletions irc/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,12 @@ func (channel *Channel) isMuted(client *Client) bool {
return muteRe.MatchString(nuh) && !channel.lists[modes.ExceptMask].MatchMute(nuh)
}

func (channel *Channel) relayNickMuted(relayNick string) bool {
relayNUH := fmt.Sprintf("%s!*@*", relayNick)
return channel.lists[modes.BanMask].MatchMute(relayNUH) &&
!channel.lists[modes.ExceptMask].MatchMute(relayNUH)
}

func msgCommandToHistType(command string) (history.ItemType, error) {
switch command {
case "PRIVMSG":
Expand Down
7 changes: 6 additions & 1 deletion irc/chanserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,12 @@ func csTransferHandler(service *ircService, server *Server, client *Client, comm
service.Notice(rb, fmt.Sprintf(client.t("Cancelled pending transfer of channel %s"), chname))
}
} else {
service.Notice(rb, client.t("Could not transfer channel"))
switch err {
case errChannelNotOwnedByAccount:
service.Notice(rb, client.t("You don't own that channel"))
default:
service.Notice(rb, client.t("Could not transfer channel"))
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions irc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,10 @@ func relaymsgHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
rb.Add(nil, server.name, "FAIL", "RELAYMSG", "INVALID_NICK", fmt.Sprintf(client.t("Relayed nicknames MUST contain a relaymsg separator from this set: %s"), config.Server.Relaymsg.Separators))
return false
}
if channel.relayNickMuted(nick) {
rb.Add(nil, server.name, "FAIL", "RELAYMSG", "BANNED", fmt.Sprintf(client.t("%s is banned from relaying to the channel"), nick))
return false
}

channel.AddHistoryItem(history.Item{
Type: history.Privmsg,
Expand Down
25 changes: 18 additions & 7 deletions irc/histserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/oragono/oragono/irc/history"
"github.com/oragono/oragono/irc/modes"
"github.com/oragono/oragono/irc/utils"
)

Expand Down Expand Up @@ -102,21 +103,31 @@ func histservDeleteHandler(service *ircService, server *Server, client *Client,
target, msgid = params[0], params[1]
}

// operators can delete; if individual delete is allowed, a chanop or
// the message author can delete
accountName := "*"
hasPrivs := client.HasRoleCapabs("history")
if !hasPrivs {
accountName = client.AccountName()
if !(server.Config().History.Retention.AllowIndividualDelete && accountName != "*") {
service.Notice(rb, client.t("Insufficient privileges"))
return
isChanop := false
isOper := client.HasRoleCapabs("history")
if !isOper {
if server.Config().History.Retention.AllowIndividualDelete {
channel := server.channels.Get(target)
if channel != nil && channel.ClientIsAtLeast(client, modes.Operator) {
isChanop = true
} else {
accountName = client.AccountName()
}
}
}
if !isOper && !isChanop && accountName == "*" {
service.Notice(rb, client.t("Insufficient privileges"))
return
}

err := server.DeleteMessage(target, msgid, accountName)
if err == nil {
service.Notice(rb, client.t("Successfully deleted message"))
} else {
if hasPrivs {
if isOper {
service.Notice(rb, fmt.Sprintf(client.t("Error deleting message: %v"), err))
} else {
service.Notice(rb, client.t("Could not delete message"))
Expand Down
13 changes: 11 additions & 2 deletions irc/nickserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func displaySetting(service *ircService, settingName string, settings AccountSet
case "always-on":
stored := settings.AlwaysOn
actual := persistenceEnabled(config.Accounts.Multiclient.AlwaysOn, stored)
service.Notice(rb, fmt.Sprintf(client.t("Your stored always-on setting is: %s"), persistentStatusToString(stored)))
service.Notice(rb, fmt.Sprintf(client.t("Your stored always-on setting is: %s"), userPersistentStatusToString(stored)))
if actual {
service.Notice(rb, client.t("Given current server settings, your client is always-on"))
} else {
Expand All @@ -447,7 +447,7 @@ func displaySetting(service *ircService, settingName string, settings AccountSet
stored := settings.AutoAway
alwaysOn := persistenceEnabled(config.Accounts.Multiclient.AlwaysOn, settings.AlwaysOn)
actual := persistenceEnabled(config.Accounts.Multiclient.AutoAway, settings.AutoAway)
service.Notice(rb, fmt.Sprintf(client.t("Your stored auto-away setting is: %s"), persistentStatusToString(stored)))
service.Notice(rb, fmt.Sprintf(client.t("Your stored auto-away setting is: %s"), userPersistentStatusToString(stored)))
if actual && alwaysOn {
service.Notice(rb, client.t("Given current server settings, auto-away is enabled for your client"))
} else if actual && !alwaysOn {
Expand All @@ -465,6 +465,15 @@ func displaySetting(service *ircService, settingName string, settings AccountSet
}
}

func userPersistentStatusToString(status PersistentStatus) string {
// #1544: "mandatory" as a user setting should display as "enabled"
result := persistentStatusToString(status)
if result == "mandatory" {
result = "enabled"
}
return result
}

func nsSetHandler(service *ircService, server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
var account string
if command == "saset" {
Expand Down
20 changes: 14 additions & 6 deletions irc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,8 @@ func (server *Server) Run() {
return

case <-server.rehashSignal:
go func() {
server.logger.Info("server", "Rehashing due to SIGHUP")
server.rehash()
}()
server.logger.Info("server", "Rehashing due to SIGHUP")
go server.rehash()
}
}
}
Expand Down Expand Up @@ -520,14 +518,24 @@ func (client *Client) getWhoisOf(target *Client, hasPrivs bool, rb *ResponseBuff

// rehash reloads the config and applies the changes from the config file.
func (server *Server) rehash() error {
// #1570; this needs its own panic handling because it can be invoked via SIGHUP
defer func() {
if r := recover(); r != nil {
if server.Config().Debug.recoverFromErrors {
server.logger.Error("internal",
fmt.Sprintf("Panic during rehash: %v\n%s", r, debug.Stack()))
} else {
panic(r)
}
}
}()

server.logger.Info("server", "Attempting rehash")

// only let one REHASH go on at a time
server.rehashMutex.Lock()
defer server.rehashMutex.Unlock()

server.logger.Debug("server", "Got rehash lock")

config, err := LoadConfig(server.configFilename)
if err != nil {
server.logger.Error("server", "failed to load config file", err.Error())
Expand Down

0 comments on commit 507d53c

Please sign in to comment.