Просмотр исходного кода

fixes and refactoring

tags/v2.4.0-rc1
Shivaram Lingamneni 3 лет назад
Родитель
Сommit
af056f26a9
7 измененных файлов: 47 добавлений и 42 удалений
  1. 2
    2
      conventional.yaml
  2. 2
    2
      default.yaml
  3. 2
    6
      irc/client_lookup_set.go
  4. 18
    5
      irc/config.go
  5. 19
    23
      irc/handlers.go
  6. 2
    2
      irc/roleplay.go
  7. 2
    2
      irc/server.go

+ 2
- 2
conventional.yaml Просмотреть файл

@@ -144,8 +144,8 @@ server:
144 144
     motd-formatting: true
145 145
 
146 146
     # relaying using the RELAYMSG command
147
-    relaying:
148
-        # is relaying enabled at all?
147
+    relaymsg:
148
+        # is relaymsg enabled at all?
149 149
         enabled: true
150 150
 
151 151
         # which character(s) are reserved for relayed nicks?

+ 2
- 2
default.yaml Просмотреть файл

@@ -171,8 +171,8 @@ server:
171 171
     motd-formatting: true
172 172
 
173 173
     # relaying using the RELAYMSG command
174
-    relaying:
175
-        # is relaying enabled at all?
174
+    relaymsg:
175
+        # is relaymsg enabled at all?
176 176
         enabled: true
177 177
 
178 178
         # which character(s) are reserved for relayed nicks?

+ 2
- 6
irc/client_lookup_set.go Просмотреть файл

@@ -165,12 +165,8 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
165 165
 			return "", errNicknameInvalid, false
166 166
 		}
167 167
 
168
-		if config.Server.Relaying.Enabled {
169
-			for _, char := range config.Server.Relaying.Separators {
170
-				if strings.ContainsRune(newCfNick, char) {
171
-					return "", errNicknameInvalid, false
172
-				}
173
-			}
168
+		if config.isRelaymsgIdentifier(newNick) {
169
+			return "", errNicknameInvalid, false
174 170
 		}
175 171
 
176 172
 		if restrictedCasefoldedNicks.Has(newCfNick) || restrictedSkeletons.Has(newSkeleton) {

+ 18
- 5
irc/config.go Просмотреть файл

@@ -502,7 +502,7 @@ type Config struct {
502 502
 		MOTD                    string
503 503
 		motdLines               []string
504 504
 		MOTDFormatting          bool `yaml:"motd-formatting"`
505
-		Relaying                struct {
505
+		Relaymsg                struct {
506 506
 			Enabled            bool
507 507
 			Separators         string
508 508
 			AvailableToChanops bool `yaml:"available-to-chanops"`
@@ -1111,13 +1111,13 @@ func LoadConfig(filename string) (config *Config, err error) {
1111 1111
 	}
1112 1112
 	config.Server.capValues[caps.Languages] = config.languageManager.CapValue()
1113 1113
 
1114
-	if config.Server.Relaying.Enabled {
1114
+	if config.Server.Relaymsg.Enabled {
1115 1115
 		for _, char := range protocolBreakingNameCharacters {
1116
-			if strings.ContainsRune(config.Server.Relaying.Separators, char) {
1117
-				return nil, fmt.Errorf("Relaying separators cannot include the characters %s", protocolBreakingNameCharacters)
1116
+			if strings.ContainsRune(config.Server.Relaymsg.Separators, char) {
1117
+				return nil, fmt.Errorf("RELAYMSG separators cannot include the characters %s", protocolBreakingNameCharacters)
1118 1118
 			}
1119 1119
 		}
1120
-		config.Server.capValues[caps.Relaymsg] = config.Server.Relaying.Separators
1120
+		config.Server.capValues[caps.Relaymsg] = config.Server.Relaymsg.Separators
1121 1121
 	} else {
1122 1122
 		config.Server.supportedCaps.Disable(caps.Relaymsg)
1123 1123
 	}
@@ -1222,6 +1222,19 @@ func (config *Config) getOutputPath(filename string) string {
1222 1222
 	return filepath.Join(config.Server.OutputPath, filename)
1223 1223
 }
1224 1224
 
1225
+func (config *Config) isRelaymsgIdentifier(nick string) bool {
1226
+	if !config.Server.Relaymsg.Enabled {
1227
+		return false
1228
+	}
1229
+
1230
+	for _, char := range config.Server.Relaymsg.Separators {
1231
+		if strings.ContainsRune(nick, char) {
1232
+			return true
1233
+		}
1234
+	}
1235
+	return false
1236
+}
1237
+
1225 1238
 // setISupport sets up our RPL_ISUPPORT reply.
1226 1239
 func (config *Config) generateISupport() (err error) {
1227 1240
 	maxTargetsString := strconv.Itoa(maxTargets)

+ 19
- 23
irc/handlers.go Просмотреть файл

@@ -2015,21 +2015,12 @@ func messageHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
2015 2015
 		}
2016 2016
 
2017 2017
 		config := server.Config()
2018
-		if config.Server.Relaying.Enabled {
2019
-			var isForRelayClient bool
2020
-			for _, char := range config.Server.Relaying.Separators {
2021
-				if strings.ContainsRune(targetString, char) {
2022
-					isForRelayClient = true
2023
-					break
2024
-				}
2025
-			}
2026
-			if isForRelayClient {
2027
-				if histType == history.Privmsg {
2028
-					rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), targetString, client.t("Relayed users cannot receive private messages"))
2029
-				}
2030
-				// TAGMSG/NOTICEs are intentionally silently dropped
2031
-				continue
2018
+		if config.isRelaymsgIdentifier(targetString) {
2019
+			if histType == history.Privmsg {
2020
+				rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), targetString, client.t("Relayed users cannot receive private messages"))
2032 2021
 			}
2022
+			// TAGMSG/NOTICEs are intentionally silently dropped
2023
+			continue
2033 2024
 		}
2034 2025
 
2035 2026
 		// each target gets distinct msgids
@@ -2443,8 +2434,8 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2443 2434
 // RELAYMSG <channel> <spoofed nick> :<message>
2444 2435
 func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) (result bool) {
2445 2436
 	config := server.Config()
2446
-	if !config.Server.Relaying.Enabled {
2447
-		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_ENABLED", client.t("Relaying has been disabled"))
2437
+	if !config.Server.Relaymsg.Enabled {
2438
+		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_ENABLED", client.t("RELAYMSG has been disabled"))
2448 2439
 		return false
2449 2440
 	}
2450 2441
 
@@ -2454,7 +2445,7 @@ func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *
2454 2445
 		return false
2455 2446
 	}
2456 2447
 
2457
-	allowedToRelay := client.HasRoleCapabs("relaymsg-anywhere") || (config.Server.Relaying.AvailableToChanops && channel.ClientIsAtLeast(client, modes.ChannelOperator))
2448
+	allowedToRelay := client.HasRoleCapabs("relaymsg-anywhere") || (config.Server.Relaymsg.AvailableToChanops && channel.ClientIsAtLeast(client, modes.ChannelOperator))
2458 2449
 	if !allowedToRelay {
2459 2450
 		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_PRIVED", client.t("You cannot relay messages to this channel"))
2460 2451
 		return false
@@ -2473,8 +2464,8 @@ func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *
2473 2464
 		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "INVALID_NICK", client.t("Invalid nickname"))
2474 2465
 		return false
2475 2466
 	}
2476
-	if !strings.Contains(nick, "/") {
2477
-		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "INVALID_NICK", fmt.Sprintf(client.t("Relayed nicknames MUST contain the relaymsg separator %s"), "/"))
2467
+	if !config.isRelaymsgIdentifier(nick) {
2468
+		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))
2478 2469
 		return false
2479 2470
 	}
2480 2471
 
@@ -2486,16 +2477,21 @@ func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *
2486 2477
 
2487 2478
 	// send msg
2488 2479
 	channelName := channel.Name()
2480
+	relayTags := map[string]string{
2481
+		"relaymsg": client.Nick(),
2482
+	}
2489 2483
 	for _, member := range channel.Members() {
2490 2484
 		for _, session := range member.Sessions() {
2491 2485
 			var tagsToUse map[string]string
2492 2486
 			if session.capabilities.Has(caps.Relaymsg) {
2493
-				tagsToUse = map[string]string{
2494
-					"relaymsg": client.Nick(),
2495
-				}
2487
+				tagsToUse = relayTags
2496 2488
 			}
2497 2489
 
2498
-			session.sendSplitMsgFromClientInternal(false, nick, "", tagsToUse, "PRIVMSG", channelName, message)
2490
+			if session == rb.session {
2491
+				rb.AddSplitMessageFromClient(nick, "*", tagsToUse, "PRIVMSG", channelName, message)
2492
+			} else {
2493
+				session.sendSplitMsgFromClientInternal(false, nick, "*", tagsToUse, "PRIVMSG", channelName, message)
2494
+			}
2499 2495
 		}
2500 2496
 	}
2501 2497
 	return false

+ 2
- 2
irc/roleplay.go Просмотреть файл

@@ -82,7 +82,7 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
82 82
 				if rb.session == session {
83 83
 					rb.AddSplitMessageFromClient(source, "", nil, "PRIVMSG", targetString, splitMessage)
84 84
 				} else {
85
-					session.sendSplitMsgFromClientInternal(false, source, "", nil, "PRIVMSG", targetString, splitMessage)
85
+					session.sendSplitMsgFromClientInternal(false, source, "*", nil, "PRIVMSG", targetString, splitMessage)
86 86
 				}
87 87
 			}
88 88
 		}
@@ -108,7 +108,7 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
108 108
 		cnick := client.Nick()
109 109
 		tnick := user.Nick()
110 110
 		for _, session := range user.Sessions() {
111
-			session.sendSplitMsgFromClientInternal(false, source, "", nil, "PRIVMSG", tnick, splitMessage)
111
+			session.sendSplitMsgFromClientInternal(false, source, "*", nil, "PRIVMSG", tnick, splitMessage)
112 112
 		}
113 113
 		if away, awayMessage := user.Away(); away {
114 114
 			//TODO(dan): possibly implement cooldown of away notifications to users

+ 2
- 2
irc/server.go Просмотреть файл

@@ -485,9 +485,9 @@ func (server *Server) applyConfig(config *Config) (err error) {
485 485
 			return fmt.Errorf("UTF-8 enforcement cannot be changed after launching the server, rehash aborted")
486 486
 		} else if oldConfig.Accounts.Multiclient.AlwaysOn != config.Accounts.Multiclient.AlwaysOn {
487 487
 			return fmt.Errorf("Default always-on setting cannot be changed after launching the server, rehash aborted")
488
-		} else if oldConfig.Server.Relaying.Enabled != config.Server.Relaying.Enabled {
488
+		} else if oldConfig.Server.Relaymsg.Enabled != config.Server.Relaymsg.Enabled {
489 489
 			return fmt.Errorf("Cannot enable or disable relaying after launching the server, rehash aborted")
490
-		} else if oldConfig.Server.Relaying.Separators != config.Server.Relaying.Separators {
490
+		} else if oldConfig.Server.Relaymsg.Separators != config.Server.Relaymsg.Separators {
491 491
 			return fmt.Errorf("Cannot change relaying separators after launching the server, rehash aborted")
492 492
 		}
493 493
 	}

Загрузка…
Отмена
Сохранить