This commit is contained in:
Shivaram Lingamneni 2020-01-08 02:14:41 -05:00
parent 99c5838949
commit 2110f3dad7
2 changed files with 11 additions and 0 deletions

View File

@ -119,6 +119,7 @@ func (channel *Channel) applyRegInfo(chanReg RegisteredChannel) {
channel.name = chanReg.Name channel.name = chanReg.Name
channel.createdTime = chanReg.RegisteredAt channel.createdTime = chanReg.RegisteredAt
channel.key = chanReg.Key channel.key = chanReg.Key
channel.userLimit = chanReg.UserLimit
for _, mode := range chanReg.Modes { for _, mode := range chanReg.Modes {
channel.flags.SetMode(mode, true) channel.flags.SetMode(mode, true)
@ -150,6 +151,7 @@ func (channel *Channel) ExportRegistration(includeFlags uint) (info RegisteredCh
if includeFlags&IncludeModes != 0 { if includeFlags&IncludeModes != 0 {
info.Key = channel.key info.Key = channel.key
info.Modes = channel.flags.AllModes() info.Modes = channel.flags.AllModes()
info.UserLimit = channel.userLimit
} }
if includeFlags&IncludeLists != 0 { if includeFlags&IncludeLists != 0 {

View File

@ -32,6 +32,7 @@ const (
keyChannelPassword = "channel.key %s" keyChannelPassword = "channel.key %s"
keyChannelModes = "channel.modes %s" keyChannelModes = "channel.modes %s"
keyChannelAccountToUMode = "channel.accounttoumode %s" keyChannelAccountToUMode = "channel.accounttoumode %s"
keyChannelUserLimit = "channel.userlimit %s"
keyChannelPurged = "channel.purged %s" keyChannelPurged = "channel.purged %s"
) )
@ -51,6 +52,7 @@ var (
keyChannelPassword, keyChannelPassword,
keyChannelModes, keyChannelModes,
keyChannelAccountToUMode, keyChannelAccountToUMode,
keyChannelUserLimit,
} }
) )
@ -88,6 +90,8 @@ type RegisteredChannel struct {
Modes []modes.Mode Modes []modes.Mode
// Key represents the channel key / password // Key represents the channel key / password
Key string Key string
// UserLimit is the user limit (0 for no limit)
UserLimit int
// AccountToUMode maps user accounts to their persistent channel modes (e.g., +q, +h) // AccountToUMode maps user accounts to their persistent channel modes (e.g., +q, +h)
AccountToUMode map[string]modes.Mode AccountToUMode map[string]modes.Mode
// Bans represents the bans set on the channel. // Bans represents the bans set on the channel.
@ -194,6 +198,7 @@ func (reg *ChannelRegistry) LoadChannel(nameCasefolded string) (info RegisteredC
topicSetTimeInt, _ := strconv.ParseInt(topicSetTime, 10, 64) topicSetTimeInt, _ := strconv.ParseInt(topicSetTime, 10, 64)
password, _ := tx.Get(fmt.Sprintf(keyChannelPassword, channelKey)) password, _ := tx.Get(fmt.Sprintf(keyChannelPassword, channelKey))
modeString, _ := tx.Get(fmt.Sprintf(keyChannelModes, channelKey)) modeString, _ := tx.Get(fmt.Sprintf(keyChannelModes, channelKey))
userLimitString, _ := tx.Get(fmt.Sprintf(keyChannelUserLimit, channelKey))
banlistString, _ := tx.Get(fmt.Sprintf(keyChannelBanlist, channelKey)) banlistString, _ := tx.Get(fmt.Sprintf(keyChannelBanlist, channelKey))
exceptlistString, _ := tx.Get(fmt.Sprintf(keyChannelExceptlist, channelKey)) exceptlistString, _ := tx.Get(fmt.Sprintf(keyChannelExceptlist, channelKey))
invitelistString, _ := tx.Get(fmt.Sprintf(keyChannelInvitelist, channelKey)) invitelistString, _ := tx.Get(fmt.Sprintf(keyChannelInvitelist, channelKey))
@ -204,6 +209,8 @@ func (reg *ChannelRegistry) LoadChannel(nameCasefolded string) (info RegisteredC
modeSlice[i] = modes.Mode(mode) modeSlice[i] = modes.Mode(mode)
} }
userLimit, _ := strconv.Atoi(userLimitString)
var banlist map[string]MaskInfo var banlist map[string]MaskInfo
_ = json.Unmarshal([]byte(banlistString), &banlist) _ = json.Unmarshal([]byte(banlistString), &banlist)
var exceptlist map[string]MaskInfo var exceptlist map[string]MaskInfo
@ -226,6 +233,7 @@ func (reg *ChannelRegistry) LoadChannel(nameCasefolded string) (info RegisteredC
Excepts: exceptlist, Excepts: exceptlist,
Invites: invitelist, Invites: invitelist,
AccountToUMode: accountToUMode, AccountToUMode: accountToUMode,
UserLimit: int(userLimit),
} }
return nil return nil
}) })
@ -336,6 +344,7 @@ func (reg *ChannelRegistry) saveChannel(tx *buntdb.Tx, channelInfo RegisteredCha
modeStrings[i] = string(mode) modeStrings[i] = string(mode)
} }
tx.Set(fmt.Sprintf(keyChannelModes, channelKey), strings.Join(modeStrings, ""), nil) tx.Set(fmt.Sprintf(keyChannelModes, channelKey), strings.Join(modeStrings, ""), nil)
tx.Set(fmt.Sprintf(keyChannelUserLimit, channelKey), strconv.Itoa(channelInfo.UserLimit), nil)
} }
if includeFlags&IncludeLists != 0 { if includeFlags&IncludeLists != 0 {