Browse Source

clean up force-trailing logic

tags/v2.12.0-rc1
Shivaram Lingamneni 11 months ago
parent
commit
60af8ee491
3 changed files with 25 additions and 19 deletions
  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 View File

@@ -1425,27 +1425,27 @@ func composeMultilineBatch(batchID, fromNickMask, fromAccount string, isBot bool
1425 1425
 }
1426 1426
 
1427 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 1436
 		// mirc's handling of RPL_NAMREPLY is broken:
1439 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 1446
 // SendRawMessage sends a raw message to the client.
1445 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 1449
 		message.ForceTrailing()
1450 1450
 	}
1451 1451
 

+ 2
- 4
irc/message_cache.go View File

@@ -79,8 +79,7 @@ func (m *MessageCache) Initialize(server *Server, serverTime time.Time, msgid st
79 79
 	m.params = params
80 80
 
81 81
 	var msg ircmsg.Message
82
-	config := server.Config()
83
-	if config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[command] {
82
+	if forceTrailing(server.Config(), command) {
84 83
 		msg.ForceTrailing()
85 84
 	}
86 85
 	msg.Source = nickmask
@@ -111,8 +110,7 @@ func (m *MessageCache) InitializeSplitMessage(server *Server, nickmask, accountN
111 110
 	m.target = target
112 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 115
 	if message.Is512() {
118 116
 		isTagmsg := command == "TAGMSG"

+ 8
- 0
irc/utils/types.go View File

@@ -20,6 +20,14 @@ func (s HashSet[T]) Remove(elem T) {
20 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 31
 func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
24 32
 	result = make(map[K]V, len(input))
25 33
 	for key, value := range input {

Loading…
Cancel
Save