Parcourir la source

clean up force-trailing logic

tags/v2.12.0-rc1
Shivaram Lingamneni il y a 11 mois
Parent
révision
60af8ee491
3 fichiers modifiés avec 25 ajouts et 19 suppressions
  1. 15
    15
      irc/client.go
  2. 2
    4
      irc/message_cache.go
  3. 8
    0
      irc/utils/types.go

+ 15
- 15
irc/client.go Voir le fichier

1425
 }
1425
 }
1426
 
1426
 
1427
 var (
1427
 var (
1428
-	// these are all the output commands that MUST have their last param be a trailing.
1429
-	// this is needed because dumb clients like to treat trailing params separately from the
1430
-	// other params in messages.
1431
-	commandsThatMustUseTrailing = map[string]bool{
1432
-		"PRIVMSG": true,
1433
-		"NOTICE":  true,
1434
-
1435
-		RPL_WHOISCHANNELS: true,
1436
-		RPL_USERHOST:      true,
1437
-
1428
+	// in practice, many clients require that the final parameter be a trailing
1429
+	// (prefixed with `:`) even when this is not syntactically necessary.
1430
+	// by default, force the following commands to use a trailing:
1431
+	commandsThatMustUseTrailing = utils.SetLiteral(
1432
+		"PRIVMSG",
1433
+		"NOTICE",
1434
+		RPL_WHOISCHANNELS,
1435
+		RPL_USERHOST,
1438
 		// mirc's handling of RPL_NAMREPLY is broken:
1436
 		// mirc's handling of RPL_NAMREPLY is broken:
1439
 		// https://forums.mirc.com/ubbthreads.php/topics/266939/re-nick-list
1437
 		// https://forums.mirc.com/ubbthreads.php/topics/266939/re-nick-list
1440
-		RPL_NAMREPLY: true,
1441
-	}
1438
+		RPL_NAMREPLY,
1439
+	)
1442
 )
1440
 )
1443
 
1441
 
1442
+func forceTrailing(config *Config, command string) bool {
1443
+	return config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing.Has(command)
1444
+}
1445
+
1444
 // SendRawMessage sends a raw message to the client.
1446
 // SendRawMessage sends a raw message to the client.
1445
 func (session *Session) SendRawMessage(message ircmsg.Message, blocking bool) error {
1447
 func (session *Session) SendRawMessage(message ircmsg.Message, blocking bool) error {
1446
-	// use dumb hack to force the last param to be a trailing param if required
1447
-	config := session.client.server.Config()
1448
-	if config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[message.Command] {
1448
+	if forceTrailing(session.client.server.Config(), message.Command) {
1449
 		message.ForceTrailing()
1449
 		message.ForceTrailing()
1450
 	}
1450
 	}
1451
 
1451
 

+ 2
- 4
irc/message_cache.go Voir le fichier

79
 	m.params = params
79
 	m.params = params
80
 
80
 
81
 	var msg ircmsg.Message
81
 	var msg ircmsg.Message
82
-	config := server.Config()
83
-	if config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[command] {
82
+	if forceTrailing(server.Config(), command) {
84
 		msg.ForceTrailing()
83
 		msg.ForceTrailing()
85
 	}
84
 	}
86
 	msg.Source = nickmask
85
 	msg.Source = nickmask
111
 	m.target = target
110
 	m.target = target
112
 	m.splitMessage = message
111
 	m.splitMessage = message
113
 
112
 
114
-	config := server.Config()
115
-	forceTrailing := config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[command]
113
+	forceTrailing := forceTrailing(server.Config(), command)
116
 
114
 
117
 	if message.Is512() {
115
 	if message.Is512() {
118
 		isTagmsg := command == "TAGMSG"
116
 		isTagmsg := command == "TAGMSG"

+ 8
- 0
irc/utils/types.go Voir le fichier

20
 	delete(s, elem)
20
 	delete(s, elem)
21
 }
21
 }
22
 
22
 
23
+func SetLiteral[T comparable](elems ...T) HashSet[T] {
24
+	result := make(HashSet[T], len(elems))
25
+	for _, elem := range elems {
26
+		result.Add(elem)
27
+	}
28
+	return result
29
+}
30
+
23
 func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
31
 func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
24
 	result = make(map[K]V, len(input))
32
 	result = make(map[K]V, len(input))
25
 	for key, value := range input {
33
 	for key, value := range input {

Chargement…
Annuler
Enregistrer