|
@@ -9,6 +9,8 @@ import (
|
9
|
9
|
"strconv"
|
10
|
10
|
"time"
|
11
|
11
|
|
|
12
|
+ "encoding/json"
|
|
13
|
+
|
12
|
14
|
"github.com/tidwall/buntdb"
|
13
|
15
|
)
|
14
|
16
|
|
|
@@ -20,6 +22,9 @@ const (
|
20
|
22
|
keyChannelTopic = "channel.topic %s"
|
21
|
23
|
keyChannelTopicSetBy = "channel.topic.setby %s"
|
22
|
24
|
keyChannelTopicSetTime = "channel.topic.settime %s"
|
|
25
|
+ keyChannelBanlist = "channel.banlist %s"
|
|
26
|
+ keyChannelExceptlist = "channel.exceptlist %s"
|
|
27
|
+ keyChannelInvitelist = "channel.invitelist %s"
|
23
|
28
|
)
|
24
|
29
|
|
25
|
30
|
var (
|
|
@@ -40,6 +45,12 @@ type RegisteredChannel struct {
|
40
|
45
|
TopicSetBy string
|
41
|
46
|
// TopicSetTime represents the time the topic was set.
|
42
|
47
|
TopicSetTime time.Time
|
|
48
|
+ // Banlist represents the bans set on the channel.
|
|
49
|
+ Banlist []string
|
|
50
|
+ // Exceptlist represents the exceptions set on the channel.
|
|
51
|
+ Exceptlist []string
|
|
52
|
+ // Invitelist represents the invite exceptions set on the channel.
|
|
53
|
+ Invitelist []string
|
43
|
54
|
}
|
44
|
55
|
|
45
|
56
|
// loadChannelNoMutex loads a channel from the store.
|
|
@@ -63,6 +74,16 @@ func (server *Server) loadChannelNoMutex(tx *buntdb.Tx, channelKey string) *Regi
|
63
|
74
|
topicSetBy, _ := tx.Get(fmt.Sprintf(keyChannelTopicSetBy, channelKey))
|
64
|
75
|
topicSetTime, _ := tx.Get(fmt.Sprintf(keyChannelTopicSetTime, channelKey))
|
65
|
76
|
topicSetTimeInt, _ := strconv.ParseInt(topicSetTime, 10, 64)
|
|
77
|
+ banlistString, _ := tx.Get(fmt.Sprintf(keyChannelBanlist, channelKey))
|
|
78
|
+ exceptlistString, _ := tx.Get(fmt.Sprintf(keyChannelExceptlist, channelKey))
|
|
79
|
+ invitelistString, _ := tx.Get(fmt.Sprintf(keyChannelInvitelist, channelKey))
|
|
80
|
+
|
|
81
|
+ var banlist []string
|
|
82
|
+ _ = json.Unmarshal([]byte(banlistString), &banlist)
|
|
83
|
+ var exceptlist []string
|
|
84
|
+ _ = json.Unmarshal([]byte(exceptlistString), &exceptlist)
|
|
85
|
+ var invitelist []string
|
|
86
|
+ _ = json.Unmarshal([]byte(invitelistString), &invitelist)
|
66
|
87
|
|
67
|
88
|
chanInfo := RegisteredChannel{
|
68
|
89
|
Name: name,
|
|
@@ -71,6 +92,9 @@ func (server *Server) loadChannelNoMutex(tx *buntdb.Tx, channelKey string) *Regi
|
71
|
92
|
Topic: topic,
|
72
|
93
|
TopicSetBy: topicSetBy,
|
73
|
94
|
TopicSetTime: time.Unix(topicSetTimeInt, 0),
|
|
95
|
+ Banlist: banlist,
|
|
96
|
+ Exceptlist: exceptlist,
|
|
97
|
+ Invitelist: invitelist,
|
74
|
98
|
}
|
75
|
99
|
server.registeredChannels[channelKey] = &chanInfo
|
76
|
100
|
|
|
@@ -86,5 +110,13 @@ func (server *Server) saveChannelNoMutex(tx *buntdb.Tx, channelKey string, chann
|
86
|
110
|
tx.Set(fmt.Sprintf(keyChannelTopic, channelKey), channelInfo.Topic, nil)
|
87
|
111
|
tx.Set(fmt.Sprintf(keyChannelTopicSetBy, channelKey), channelInfo.TopicSetBy, nil)
|
88
|
112
|
tx.Set(fmt.Sprintf(keyChannelTopicSetTime, channelKey), strconv.FormatInt(channelInfo.TopicSetTime.Unix(), 10), nil)
|
|
113
|
+
|
|
114
|
+ banlistString, _ := json.Marshal(channelInfo.Banlist)
|
|
115
|
+ tx.Set(fmt.Sprintf(keyChannelBanlist, channelKey), string(banlistString), nil)
|
|
116
|
+ exceptlistString, _ := json.Marshal(channelInfo.Exceptlist)
|
|
117
|
+ tx.Set(fmt.Sprintf(keyChannelExceptlist, channelKey), string(exceptlistString), nil)
|
|
118
|
+ invitelistString, _ := json.Marshal(channelInfo.Invitelist)
|
|
119
|
+ tx.Set(fmt.Sprintf(keyChannelInvitelist, channelKey), string(invitelistString), nil)
|
|
120
|
+
|
89
|
121
|
server.registeredChannels[channelKey] = &channelInfo
|
90
|
122
|
}
|