commit cede6d5
Hubert Hirtz
·
2021-04-27 07:45:45 +0000 UTC
parent 70a74ca
Split the "feature" map into specific attributes
1 files changed,
+23,
-16
+23,
-16
1@@ -173,7 +173,10 @@ type Session struct {
2
3 availableCaps map[string]string
4 enabledCaps map[string]struct{}
5- features map[string]string // server ISUPPORT advertized features.
6+
7+ // ISUPPORT features
8+ casemap func(string) string
9+ chantypes string
10
11 users map[string]*User // known users.
12 channels map[string]Channel // joined channels.
13@@ -201,7 +204,8 @@ func NewSession(conn net.Conn, params SessionParams) (*Session, error) {
14 auth: params.Auth,
15 availableCaps: map[string]string{},
16 enabledCaps: map[string]struct{}{},
17- features: map[string]string{},
18+ casemap: CasemapRFC1459,
19+ chantypes: "#&",
20 users: map[string]*User{},
21 channels: map[string]Channel{},
22 chBatches: map[string]HistoryEvent{},
23@@ -280,19 +284,11 @@ func (s *Session) NickCf() string {
24 }
25
26 func (s *Session) IsChannel(name string) bool {
27- chantypes, ok := s.features["CHANTYPES"]
28- if !ok {
29- chantypes = "#&"
30- }
31- return strings.IndexAny(name, chantypes) == 0
32+ return strings.IndexAny(name, s.chantypes) == 0
33 }
34
35 func (s *Session) Casemap(name string) string {
36- if s.features["CASEMAPPING"] == "ascii" {
37- return CasemapASCII(name)
38- } else {
39- return CasemapRFC1459(name)
40- }
41+ return s.casemap(name)
42 }
43
44 // Users returns the list of all known nicknames.
45@@ -1073,10 +1069,21 @@ func (s *Session) updateFeatures(features []string) {
46 value = kv[1]
47 }
48
49- if add {
50- s.features[key] = value
51- } else {
52- delete(s.features, key)
53+ if !add {
54+ // TODO support ISUPPORT negations
55+ continue
56+ }
57+
58+ switch key {
59+ case "CASEMAPPING":
60+ switch value {
61+ case "ascii":
62+ s.casemap = CasemapASCII
63+ default:
64+ s.casemap = CasemapRFC1459
65+ }
66+ case "CHANTYPES":
67+ s.chantypes = value
68 }
69 }
70 }