Browse Source

add CHANSERV UNREGISTER

tags/v0.12.0
Shivaram Lingamneni 6 years ago
parent
commit
31f386f5a9
5 changed files with 115 additions and 54 deletions
  1. 11
    0
      irc/channel.go
  2. 14
    0
      irc/channelreg.go
  3. 45
    5
      irc/chanserv.go
  4. 1
    1
      irc/getters.go
  5. 44
    48
      irc/server.go

+ 11
- 0
irc/channel.go View File

@@ -157,6 +157,17 @@ func (channel *Channel) SetRegistered(founder string) error {
157 157
 	return nil
158 158
 }
159 159
 
160
+// SetUnregistered deletes the channel's registration information.
161
+func (channel *Channel) SetUnregistered() {
162
+	channel.stateMutex.Lock()
163
+	defer channel.stateMutex.Unlock()
164
+
165
+	channel.registeredFounder = ""
166
+	var zeroTime time.Time
167
+	channel.registeredTime = zeroTime
168
+	channel.accountToUMode = make(map[string]modes.Mode)
169
+}
170
+
160 171
 // IsRegistered returns whether the channel is registered.
161 172
 func (channel *Channel) IsRegistered() bool {
162 173
 	channel.stateMutex.RLock()

+ 14
- 0
irc/channelreg.go View File

@@ -201,6 +201,20 @@ func (reg *ChannelRegistry) LoadChannel(nameCasefolded string) (info *Registered
201 201
 	return info
202 202
 }
203 203
 
204
+func (reg *ChannelRegistry) Delete(casefoldedName string, info RegisteredChannel) {
205
+	if !reg.server.ChannelRegistrationEnabled() {
206
+		return
207
+	}
208
+
209
+	reg.Lock()
210
+	defer reg.Unlock()
211
+
212
+	reg.server.store.Update(func(tx *buntdb.Tx) error {
213
+		reg.deleteChannel(tx, casefoldedName, info)
214
+		return nil
215
+	})
216
+}
217
+
204 218
 // Rename handles the persistence part of a channel rename: the channel is
205 219
 // persisted under its new name, and the old name is cleaned up if necessary.
206 220
 func (reg *ChannelRegistry) Rename(channel *Channel, casefoldedOldName string) {

+ 45
- 5
irc/chanserv.go View File

@@ -22,6 +22,10 @@ To see in-depth help for a specific ChanServ command, try:
22 22
 Here are the commands you can use:
23 23
 %s`
24 24
 
25
+func chanregEnabled(server *Server) bool {
26
+	return server.ChannelRegistrationEnabled()
27
+}
28
+
25 29
 var (
26 30
 	chanservCommands = map[string]*serviceCommand{
27 31
 		"op": {
@@ -32,6 +36,7 @@ OP makes the given nickname, or yourself, a channel admin. You can only use
32 36
 this command if you're the founder of the channel.`,
33 37
 			helpShort:    `$bOP$b makes the given user (or yourself) a channel admin.`,
34 38
 			authRequired: true,
39
+			enabled:      chanregEnabled,
35 40
 		},
36 41
 		"register": {
37 42
 			handler: csRegisterHandler,
@@ -42,6 +47,15 @@ given admin privs on it. Modes set on the channel and the topic will also be
42 47
 remembered.`,
43 48
 			helpShort:    `$bREGISTER$b lets you own a given channel.`,
44 49
 			authRequired: true,
50
+			enabled:      chanregEnabled,
51
+		},
52
+		"unregister": {
53
+			handler: csUnregisterHandler,
54
+			help: `Syntax: $bUNREGISTER #channel$b
55
+
56
+UNREGISTER deletes a channel registration, allowing someone else to claim it.`,
57
+			helpShort: `$bUNREGISTER$b deletes a channel registration.`,
58
+			enabled:   chanregEnabled,
45 59
 		},
46 60
 		"amode": {
47 61
 			handler: csAmodeHandler,
@@ -53,6 +67,7 @@ account the +o operator mode every time they join #channel. To list current
53 67
 accounts and modes, use $bAMODE #channel$b. Note that users are always
54 68
 referenced by their registered account names, not their nicknames.`,
55 69
 			helpShort: `$bAMODE$b modifies persistent mode settings for channel members.`,
70
+			enabled:   chanregEnabled,
56 71
 		},
57 72
 	}
58 73
 )
@@ -197,11 +212,6 @@ func csOpHandler(server *Server, client *Client, command, params string, rb *Res
197 212
 }
198 213
 
199 214
 func csRegisterHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
200
-	if !server.channelRegistrationEnabled {
201
-		csNotice(rb, client.t("Channel registration is not enabled"))
202
-		return
203
-	}
204
-
205 215
 	channelName := strings.TrimSpace(params)
206 216
 	if channelName == "" {
207 217
 		csNotice(rb, ircfmt.Unescape(client.t("Syntax: $bREGISTER #channel$b")))
@@ -246,3 +256,33 @@ func csRegisterHandler(server *Server, client *Client, command, params string, r
246 256
 		}
247 257
 	}
248 258
 }
259
+
260
+func csUnregisterHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
261
+	channelName := strings.TrimSpace(params)
262
+	channelKey, err := CasefoldChannel(channelName)
263
+	if channelKey == "" || err != nil {
264
+		csNotice(rb, client.t("Channel name is not valid"))
265
+		return
266
+	}
267
+
268
+	channel := server.channels.Get(channelKey)
269
+	if channel == nil {
270
+		csNotice(rb, client.t("No such channel"))
271
+		return
272
+	}
273
+
274
+	hasPrivs := client.HasRoleCapabs("chanreg")
275
+	if !hasPrivs {
276
+		founder := channel.Founder()
277
+		hasPrivs = founder != "" && founder == client.Account()
278
+	}
279
+	if !hasPrivs {
280
+		csNotice(rb, client.t("Insufficient privileges"))
281
+		return
282
+	}
283
+
284
+	info := channel.ExportRegistration(0)
285
+	channel.SetUnregistered()
286
+	go server.channelRegistry.Delete(channelKey, info)
287
+	csNotice(rb, fmt.Sprintf(client.t("Channel %s is now unregistered"), channelKey))
288
+}

+ 1
- 1
irc/getters.go View File

@@ -62,7 +62,7 @@ func (server *Server) DefaultChannelModes() modes.Modes {
62 62
 func (server *Server) ChannelRegistrationEnabled() bool {
63 63
 	server.configurableStateMutex.RLock()
64 64
 	defer server.configurableStateMutex.RUnlock()
65
-	return server.channelRegistrationEnabled
65
+	return server.config.Channels.Registration.Enabled
66 66
 }
67 67
 
68 68
 func (server *Server) AccountConfig() *AccountConfig {

+ 44
- 48
irc/server.go View File

@@ -87,51 +87,50 @@ type ListenerWrapper struct {
87 87
 
88 88
 // Server is the main Oragono server.
89 89
 type Server struct {
90
-	accounts                   *AccountManager
91
-	batches                    *BatchManager
92
-	channelRegistrationEnabled bool
93
-	channels                   *ChannelManager
94
-	channelRegistry            *ChannelRegistry
95
-	checkIdent                 bool
96
-	clients                    *ClientManager
97
-	config                     *Config
98
-	configFilename             string
99
-	configurableStateMutex     sync.RWMutex // tier 1; generic protection for server state modified by rehash()
100
-	connectionLimiter          *connection_limits.Limiter
101
-	connectionThrottler        *connection_limits.Throttler
102
-	ctime                      time.Time
103
-	defaultChannelModes        modes.Modes
104
-	dlines                     *DLineManager
105
-	loggingRawIO               bool
106
-	isupport                   *isupport.List
107
-	klines                     *KLineManager
108
-	languages                  *languages.Manager
109
-	limits                     Limits
110
-	listeners                  map[string]*ListenerWrapper
111
-	logger                     *logger.Manager
112
-	maxSendQBytes              uint32
113
-	monitorManager             *MonitorManager
114
-	motdLines                  []string
115
-	name                       string
116
-	nameCasefolded             string
117
-	networkName                string
118
-	operators                  map[string]*Oper
119
-	operclasses                map[string]*OperClass
120
-	password                   []byte
121
-	passwords                  *passwd.SaltedManager
122
-	recoverFromErrors          bool
123
-	rehashMutex                sync.Mutex // tier 4
124
-	rehashSignal               chan os.Signal
125
-	pprofServer                *http.Server
126
-	proxyAllowedFrom           []string
127
-	signals                    chan os.Signal
128
-	snomasks                   *SnoManager
129
-	store                      *buntdb.DB
130
-	stsEnabled                 bool
131
-	webirc                     []webircConfig
132
-	whoWas                     *WhoWasList
133
-	stats                      *Stats
134
-	semaphores                 *ServerSemaphores
90
+	accounts               *AccountManager
91
+	batches                *BatchManager
92
+	channels               *ChannelManager
93
+	channelRegistry        *ChannelRegistry
94
+	checkIdent             bool
95
+	clients                *ClientManager
96
+	config                 *Config
97
+	configFilename         string
98
+	configurableStateMutex sync.RWMutex // tier 1; generic protection for server state modified by rehash()
99
+	connectionLimiter      *connection_limits.Limiter
100
+	connectionThrottler    *connection_limits.Throttler
101
+	ctime                  time.Time
102
+	defaultChannelModes    modes.Modes
103
+	dlines                 *DLineManager
104
+	loggingRawIO           bool
105
+	isupport               *isupport.List
106
+	klines                 *KLineManager
107
+	languages              *languages.Manager
108
+	limits                 Limits
109
+	listeners              map[string]*ListenerWrapper
110
+	logger                 *logger.Manager
111
+	maxSendQBytes          uint32
112
+	monitorManager         *MonitorManager
113
+	motdLines              []string
114
+	name                   string
115
+	nameCasefolded         string
116
+	networkName            string
117
+	operators              map[string]*Oper
118
+	operclasses            map[string]*OperClass
119
+	password               []byte
120
+	passwords              *passwd.SaltedManager
121
+	recoverFromErrors      bool
122
+	rehashMutex            sync.Mutex // tier 4
123
+	rehashSignal           chan os.Signal
124
+	pprofServer            *http.Server
125
+	proxyAllowedFrom       []string
126
+	signals                chan os.Signal
127
+	snomasks               *SnoManager
128
+	store                  *buntdb.DB
129
+	stsEnabled             bool
130
+	webirc                 []webircConfig
131
+	whoWas                 *WhoWasList
132
+	stats                  *Stats
133
+	semaphores             *ServerSemaphores
135 134
 }
136 135
 
137 136
 var (
@@ -955,9 +954,6 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
955 954
 	server.operators = opers
956 955
 	server.checkIdent = config.Server.CheckIdent
957 956
 
958
-	// registration
959
-	server.channelRegistrationEnabled = config.Channels.Registration.Enabled
960
-
961 957
 	server.defaultChannelModes = ParseDefaultChannelModes(config)
962 958
 	server.configurableStateMutex.Unlock()
963 959
 

Loading…
Cancel
Save