mirror of
				https://github.com/ergochat/ergo.git
				synced 2025-11-03 23:37:22 +01:00 
			
		
		
		
	fixes and refactoring
This commit is contained in:
		
							parent
							
								
									3962ff8643
								
							
						
					
					
						commit
						af056f26a9
					
				@ -144,8 +144,8 @@ server:
 | 
			
		||||
    motd-formatting: true
 | 
			
		||||
 | 
			
		||||
    # relaying using the RELAYMSG command
 | 
			
		||||
    relaying:
 | 
			
		||||
        # is relaying enabled at all?
 | 
			
		||||
    relaymsg:
 | 
			
		||||
        # is relaymsg enabled at all?
 | 
			
		||||
        enabled: true
 | 
			
		||||
 | 
			
		||||
        # which character(s) are reserved for relayed nicks?
 | 
			
		||||
 | 
			
		||||
@ -171,8 +171,8 @@ server:
 | 
			
		||||
    motd-formatting: true
 | 
			
		||||
 | 
			
		||||
    # relaying using the RELAYMSG command
 | 
			
		||||
    relaying:
 | 
			
		||||
        # is relaying enabled at all?
 | 
			
		||||
    relaymsg:
 | 
			
		||||
        # is relaymsg enabled at all?
 | 
			
		||||
        enabled: true
 | 
			
		||||
 | 
			
		||||
        # which character(s) are reserved for relayed nicks?
 | 
			
		||||
 | 
			
		||||
@ -165,12 +165,8 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
 | 
			
		||||
			return "", errNicknameInvalid, false
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if config.Server.Relaying.Enabled {
 | 
			
		||||
			for _, char := range config.Server.Relaying.Separators {
 | 
			
		||||
				if strings.ContainsRune(newCfNick, char) {
 | 
			
		||||
					return "", errNicknameInvalid, false
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		if config.isRelaymsgIdentifier(newNick) {
 | 
			
		||||
			return "", errNicknameInvalid, false
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if restrictedCasefoldedNicks.Has(newCfNick) || restrictedSkeletons.Has(newSkeleton) {
 | 
			
		||||
 | 
			
		||||
@ -502,7 +502,7 @@ type Config struct {
 | 
			
		||||
		MOTD                    string
 | 
			
		||||
		motdLines               []string
 | 
			
		||||
		MOTDFormatting          bool `yaml:"motd-formatting"`
 | 
			
		||||
		Relaying                struct {
 | 
			
		||||
		Relaymsg                struct {
 | 
			
		||||
			Enabled            bool
 | 
			
		||||
			Separators         string
 | 
			
		||||
			AvailableToChanops bool `yaml:"available-to-chanops"`
 | 
			
		||||
@ -1111,13 +1111,13 @@ func LoadConfig(filename string) (config *Config, err error) {
 | 
			
		||||
	}
 | 
			
		||||
	config.Server.capValues[caps.Languages] = config.languageManager.CapValue()
 | 
			
		||||
 | 
			
		||||
	if config.Server.Relaying.Enabled {
 | 
			
		||||
	if config.Server.Relaymsg.Enabled {
 | 
			
		||||
		for _, char := range protocolBreakingNameCharacters {
 | 
			
		||||
			if strings.ContainsRune(config.Server.Relaying.Separators, char) {
 | 
			
		||||
				return nil, fmt.Errorf("Relaying separators cannot include the characters %s", protocolBreakingNameCharacters)
 | 
			
		||||
			if strings.ContainsRune(config.Server.Relaymsg.Separators, char) {
 | 
			
		||||
				return nil, fmt.Errorf("RELAYMSG separators cannot include the characters %s", protocolBreakingNameCharacters)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		config.Server.capValues[caps.Relaymsg] = config.Server.Relaying.Separators
 | 
			
		||||
		config.Server.capValues[caps.Relaymsg] = config.Server.Relaymsg.Separators
 | 
			
		||||
	} else {
 | 
			
		||||
		config.Server.supportedCaps.Disable(caps.Relaymsg)
 | 
			
		||||
	}
 | 
			
		||||
@ -1222,6 +1222,19 @@ func (config *Config) getOutputPath(filename string) string {
 | 
			
		||||
	return filepath.Join(config.Server.OutputPath, filename)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (config *Config) isRelaymsgIdentifier(nick string) bool {
 | 
			
		||||
	if !config.Server.Relaymsg.Enabled {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, char := range config.Server.Relaymsg.Separators {
 | 
			
		||||
		if strings.ContainsRune(nick, char) {
 | 
			
		||||
			return true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setISupport sets up our RPL_ISUPPORT reply.
 | 
			
		||||
func (config *Config) generateISupport() (err error) {
 | 
			
		||||
	maxTargetsString := strconv.Itoa(maxTargets)
 | 
			
		||||
 | 
			
		||||
@ -2015,21 +2015,12 @@ func messageHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		config := server.Config()
 | 
			
		||||
		if config.Server.Relaying.Enabled {
 | 
			
		||||
			var isForRelayClient bool
 | 
			
		||||
			for _, char := range config.Server.Relaying.Separators {
 | 
			
		||||
				if strings.ContainsRune(targetString, char) {
 | 
			
		||||
					isForRelayClient = true
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			if isForRelayClient {
 | 
			
		||||
				if histType == history.Privmsg {
 | 
			
		||||
					rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), targetString, client.t("Relayed users cannot receive private messages"))
 | 
			
		||||
				}
 | 
			
		||||
				// TAGMSG/NOTICEs are intentionally silently dropped
 | 
			
		||||
				continue
 | 
			
		||||
		if config.isRelaymsgIdentifier(targetString) {
 | 
			
		||||
			if histType == history.Privmsg {
 | 
			
		||||
				rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), targetString, client.t("Relayed users cannot receive private messages"))
 | 
			
		||||
			}
 | 
			
		||||
			// TAGMSG/NOTICEs are intentionally silently dropped
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// each target gets distinct msgids
 | 
			
		||||
@ -2443,8 +2434,8 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
 | 
			
		||||
// RELAYMSG <channel> <spoofed nick> :<message>
 | 
			
		||||
func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) (result bool) {
 | 
			
		||||
	config := server.Config()
 | 
			
		||||
	if !config.Server.Relaying.Enabled {
 | 
			
		||||
		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_ENABLED", client.t("Relaying has been disabled"))
 | 
			
		||||
	if !config.Server.Relaymsg.Enabled {
 | 
			
		||||
		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_ENABLED", client.t("RELAYMSG has been disabled"))
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -2454,7 +2445,7 @@ func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	allowedToRelay := client.HasRoleCapabs("relaymsg-anywhere") || (config.Server.Relaying.AvailableToChanops && channel.ClientIsAtLeast(client, modes.ChannelOperator))
 | 
			
		||||
	allowedToRelay := client.HasRoleCapabs("relaymsg-anywhere") || (config.Server.Relaymsg.AvailableToChanops && channel.ClientIsAtLeast(client, modes.ChannelOperator))
 | 
			
		||||
	if !allowedToRelay {
 | 
			
		||||
		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_PRIVED", client.t("You cannot relay messages to this channel"))
 | 
			
		||||
		return false
 | 
			
		||||
@ -2473,8 +2464,8 @@ func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *
 | 
			
		||||
		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "INVALID_NICK", client.t("Invalid nickname"))
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	if !strings.Contains(nick, "/") {
 | 
			
		||||
		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "INVALID_NICK", fmt.Sprintf(client.t("Relayed nicknames MUST contain the relaymsg separator %s"), "/"))
 | 
			
		||||
	if !config.isRelaymsgIdentifier(nick) {
 | 
			
		||||
		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
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -2486,16 +2477,21 @@ func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *
 | 
			
		||||
 | 
			
		||||
	// send msg
 | 
			
		||||
	channelName := channel.Name()
 | 
			
		||||
	relayTags := map[string]string{
 | 
			
		||||
		"relaymsg": client.Nick(),
 | 
			
		||||
	}
 | 
			
		||||
	for _, member := range channel.Members() {
 | 
			
		||||
		for _, session := range member.Sessions() {
 | 
			
		||||
			var tagsToUse map[string]string
 | 
			
		||||
			if session.capabilities.Has(caps.Relaymsg) {
 | 
			
		||||
				tagsToUse = map[string]string{
 | 
			
		||||
					"relaymsg": client.Nick(),
 | 
			
		||||
				}
 | 
			
		||||
				tagsToUse = relayTags
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			session.sendSplitMsgFromClientInternal(false, nick, "", tagsToUse, "PRIVMSG", channelName, message)
 | 
			
		||||
			if session == rb.session {
 | 
			
		||||
				rb.AddSplitMessageFromClient(nick, "*", tagsToUse, "PRIVMSG", channelName, message)
 | 
			
		||||
			} else {
 | 
			
		||||
				session.sendSplitMsgFromClientInternal(false, nick, "*", tagsToUse, "PRIVMSG", channelName, message)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return false
 | 
			
		||||
 | 
			
		||||
@ -82,7 +82,7 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
 | 
			
		||||
				if rb.session == session {
 | 
			
		||||
					rb.AddSplitMessageFromClient(source, "", nil, "PRIVMSG", targetString, splitMessage)
 | 
			
		||||
				} else {
 | 
			
		||||
					session.sendSplitMsgFromClientInternal(false, source, "", nil, "PRIVMSG", targetString, splitMessage)
 | 
			
		||||
					session.sendSplitMsgFromClientInternal(false, source, "*", nil, "PRIVMSG", targetString, splitMessage)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -108,7 +108,7 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
 | 
			
		||||
		cnick := client.Nick()
 | 
			
		||||
		tnick := user.Nick()
 | 
			
		||||
		for _, session := range user.Sessions() {
 | 
			
		||||
			session.sendSplitMsgFromClientInternal(false, source, "", nil, "PRIVMSG", tnick, splitMessage)
 | 
			
		||||
			session.sendSplitMsgFromClientInternal(false, source, "*", nil, "PRIVMSG", tnick, splitMessage)
 | 
			
		||||
		}
 | 
			
		||||
		if away, awayMessage := user.Away(); away {
 | 
			
		||||
			//TODO(dan): possibly implement cooldown of away notifications to users
 | 
			
		||||
 | 
			
		||||
@ -485,9 +485,9 @@ func (server *Server) applyConfig(config *Config) (err error) {
 | 
			
		||||
			return fmt.Errorf("UTF-8 enforcement cannot be changed after launching the server, rehash aborted")
 | 
			
		||||
		} else if oldConfig.Accounts.Multiclient.AlwaysOn != config.Accounts.Multiclient.AlwaysOn {
 | 
			
		||||
			return fmt.Errorf("Default always-on setting cannot be changed after launching the server, rehash aborted")
 | 
			
		||||
		} else if oldConfig.Server.Relaying.Enabled != config.Server.Relaying.Enabled {
 | 
			
		||||
		} else if oldConfig.Server.Relaymsg.Enabled != config.Server.Relaymsg.Enabled {
 | 
			
		||||
			return fmt.Errorf("Cannot enable or disable relaying after launching the server, rehash aborted")
 | 
			
		||||
		} else if oldConfig.Server.Relaying.Separators != config.Server.Relaying.Separators {
 | 
			
		||||
		} else if oldConfig.Server.Relaymsg.Separators != config.Server.Relaymsg.Separators {
 | 
			
		||||
			return fmt.Errorf("Cannot change relaying separators after launching the server, rehash aborted")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user