From 2110f3dad7244154097b57da1ed09210d2f0d863 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 8 Jan 2020 02:14:41 -0500 Subject: [PATCH] fix #705 --- irc/channel.go | 2 ++ irc/channelreg.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/irc/channel.go b/irc/channel.go index 25afdd72..11518219 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -119,6 +119,7 @@ func (channel *Channel) applyRegInfo(chanReg RegisteredChannel) { channel.name = chanReg.Name channel.createdTime = chanReg.RegisteredAt channel.key = chanReg.Key + channel.userLimit = chanReg.UserLimit for _, mode := range chanReg.Modes { channel.flags.SetMode(mode, true) @@ -150,6 +151,7 @@ func (channel *Channel) ExportRegistration(includeFlags uint) (info RegisteredCh if includeFlags&IncludeModes != 0 { info.Key = channel.key info.Modes = channel.flags.AllModes() + info.UserLimit = channel.userLimit } if includeFlags&IncludeLists != 0 { diff --git a/irc/channelreg.go b/irc/channelreg.go index e0ea9b25..1258cd97 100644 --- a/irc/channelreg.go +++ b/irc/channelreg.go @@ -32,6 +32,7 @@ const ( keyChannelPassword = "channel.key %s" keyChannelModes = "channel.modes %s" keyChannelAccountToUMode = "channel.accounttoumode %s" + keyChannelUserLimit = "channel.userlimit %s" keyChannelPurged = "channel.purged %s" ) @@ -51,6 +52,7 @@ var ( keyChannelPassword, keyChannelModes, keyChannelAccountToUMode, + keyChannelUserLimit, } ) @@ -88,6 +90,8 @@ type RegisteredChannel struct { Modes []modes.Mode // Key represents the channel key / password 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 map[string]modes.Mode // 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) password, _ := tx.Get(fmt.Sprintf(keyChannelPassword, channelKey)) modeString, _ := tx.Get(fmt.Sprintf(keyChannelModes, channelKey)) + userLimitString, _ := tx.Get(fmt.Sprintf(keyChannelUserLimit, channelKey)) banlistString, _ := tx.Get(fmt.Sprintf(keyChannelBanlist, channelKey)) exceptlistString, _ := tx.Get(fmt.Sprintf(keyChannelExceptlist, 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) } + userLimit, _ := strconv.Atoi(userLimitString) + var banlist map[string]MaskInfo _ = json.Unmarshal([]byte(banlistString), &banlist) var exceptlist map[string]MaskInfo @@ -226,6 +233,7 @@ func (reg *ChannelRegistry) LoadChannel(nameCasefolded string) (info RegisteredC Excepts: exceptlist, Invites: invitelist, AccountToUMode: accountToUMode, + UserLimit: int(userLimit), } return nil }) @@ -336,6 +344,7 @@ func (reg *ChannelRegistry) saveChannel(tx *buntdb.Tx, channelInfo RegisteredCha modeStrings[i] = string(mode) } 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 {