Procházet zdrojové kódy

Merge pull request #1343 from slingamn/chanmodes

add +u and +U to CHANMODES token
tags/v2.4.0-rc1
Shivaram Lingamneni před 3 roky
rodič
revize
50dc265e4d
Žádný účet není propojen s e-mailovou adresou tvůrce revize
5 změnil soubory, kde provedl 45 přidání a 1 odebrání
  1. 11
    0
      DEVELOPING.md
  2. 1
    1
      irc/config.go
  3. 20
    0
      irc/modes/modes.go
  4. 10
    0
      irc/modes/modes_test.go
  5. 3
    0
      irc/server.go

+ 11
- 0
DEVELOPING.md Zobrazit soubor

184
 4. Run `crowdin download`
184
 4. Run `crowdin download`
185
 
185
 
186
 This will download a bunch of updated files and put them in the right place
186
 This will download a bunch of updated files and put them in the right place
187
+
188
+
189
+## Adding a mode
190
+
191
+When adding a mode, keep in mind the following places it may need to be referenced:
192
+
193
+1. The mode needs to be defined in the `irc/modes` subpackage
194
+1. It may need to be special-cased in `modes.RplMyInfo()`
195
+1. It may need to be added to the `CHANMODES` ISUPPORT token
196
+1. It may need special handling in `ApplyUserModeChanges` or `ApplyChannelModeChanges`
197
+1. It may need special persistence handling code

+ 1
- 1
irc/config.go Zobrazit soubor

1287
 	isupport.Add("BOT", "B")
1287
 	isupport.Add("BOT", "B")
1288
 	isupport.Add("CASEMAPPING", "ascii")
1288
 	isupport.Add("CASEMAPPING", "ascii")
1289
 	isupport.Add("CHANLIMIT", fmt.Sprintf("%s:%d", chanTypes, config.Channels.MaxChannelsPerClient))
1289
 	isupport.Add("CHANLIMIT", fmt.Sprintf("%s:%d", chanTypes, config.Channels.MaxChannelsPerClient))
1290
-	isupport.Add("CHANMODES", strings.Join([]string{modes.Modes{modes.BanMask, modes.ExceptMask, modes.InviteMask}.String(), modes.Modes{modes.Key}.String(), modes.Modes{modes.UserLimit}.String(), modes.Modes{modes.InviteOnly, modes.Moderated, modes.NoOutside, modes.OpOnlyTopic, modes.ChanRoleplaying, modes.Secret, modes.NoCTCP, modes.RegisteredOnly, modes.RegisteredOnlySpeak}.String()}, ","))
1290
+	isupport.Add("CHANMODES", chanmodesToken)
1291
 	if config.History.Enabled && config.History.ChathistoryMax > 0 {
1291
 	if config.History.Enabled && config.History.ChathistoryMax > 0 {
1292
 		isupport.Add("draft/CHATHISTORY", strconv.Itoa(config.History.ChathistoryMax))
1292
 		isupport.Add("draft/CHATHISTORY", strconv.Itoa(config.History.ChathistoryMax))
1293
 	}
1293
 	}

+ 20
- 0
irc/modes/modes.go Zobrazit soubor

6
 package modes
6
 package modes
7
 
7
 
8
 import (
8
 import (
9
+	"fmt"
9
 	"sort"
10
 	"sort"
10
 	"strings"
11
 	"strings"
11
 
12
 
450
 
451
 
451
 	return userModes.String(), channelModes.String(), channelParametrizedModes.String()
452
 	return userModes.String(), channelModes.String(), channelParametrizedModes.String()
452
 }
453
 }
454
+
455
+func ChanmodesToken() (result string) {
456
+	// https://modern.ircdocs.horse#chanmodes-parameter
457
+	// type A: listable modes with parameters
458
+	A := Modes{BanMask, ExceptMask, InviteMask}
459
+	// type B: modes with parameters
460
+	B := Modes{Key}
461
+	// type C: modes that take a parameter only when set, never when unset
462
+	C := Modes{UserLimit}
463
+	// type D: modes without parameters
464
+	D := Modes{InviteOnly, Moderated, NoOutside, OpOnlyTopic, ChanRoleplaying, Secret, NoCTCP, RegisteredOnly, RegisteredOnlySpeak, Auditorium, OpModerated}
465
+
466
+	sort.Sort(ByCodepoint(A))
467
+	sort.Sort(ByCodepoint(B))
468
+	sort.Sort(ByCodepoint(C))
469
+	sort.Sort(ByCodepoint(D))
470
+
471
+	return fmt.Sprintf("%s,%s,%s,%s", A.String(), B.String(), C.String(), D.String())
472
+}

+ 10
- 0
irc/modes/modes_test.go Zobrazit soubor

5
 
5
 
6
 import (
6
 import (
7
 	"reflect"
7
 	"reflect"
8
+	"strings"
8
 	"testing"
9
 	"testing"
9
 )
10
 )
10
 
11
 
219
 	}
220
 	}
220
 }
221
 }
221
 
222
 
223
+func TestChanmodesToken(t *testing.T) {
224
+	tok := ChanmodesToken()
225
+	for _, mode := range SupportedChannelModes {
226
+		if strings.IndexRune(tok, rune(mode)) == -1 {
227
+			t.Errorf("+%s not included in ChanmodesToken()", mode)
228
+		}
229
+	}
230
+}
231
+
222
 func TestModeChangesString(t *testing.T) {
232
 func TestModeChangesString(t *testing.T) {
223
 	m := ModeChanges{
233
 	m := ModeChanges{
224
 		ModeChange{Op: Add, Mode: RegisteredOnly},
234
 		ModeChange{Op: Add, Mode: RegisteredOnly},

+ 3
- 0
irc/server.go Zobrazit soubor

39
 	// three final parameters of 004 RPL_MYINFO, enumerating our supported modes
39
 	// three final parameters of 004 RPL_MYINFO, enumerating our supported modes
40
 	rplMyInfo1, rplMyInfo2, rplMyInfo3 = modes.RplMyInfo()
40
 	rplMyInfo1, rplMyInfo2, rplMyInfo3 = modes.RplMyInfo()
41
 
41
 
42
+	// CHANMODES isupport token
43
+	chanmodesToken = modes.ChanmodesToken()
44
+
42
 	// whitelist of caps to serve on the STS-only listener. In particular,
45
 	// whitelist of caps to serve on the STS-only listener. In particular,
43
 	// never advertise SASL, to discourage people from sending their passwords:
46
 	// never advertise SASL, to discourage people from sending their passwords:
44
 	stsOnlyCaps = caps.NewSet(caps.STS, caps.MessageTags, caps.ServerTime, caps.Batch, caps.LabeledResponse, caps.EchoMessage, caps.Nope)
47
 	stsOnlyCaps = caps.NewSet(caps.STS, caps.MessageTags, caps.ServerTime, caps.Batch, caps.LabeledResponse, caps.EchoMessage, caps.Nope)

Načítá se…
Zrušit
Uložit