浏览代码

fix #1225

tags/v2.3.0-rc1
Shivaram Lingamneni 3 年前
父节点
当前提交
06882a9b89
共有 5 个文件被更改,包括 22 次插入24 次删除
  1. 9
    2
      irc/client.go
  2. 3
    1
      irc/client_lookup_set.go
  3. 5
    10
      irc/getters.go
  4. 5
    7
      irc/nickname.go
  5. 0
    4
      irc/server.go

+ 9
- 2
irc/client.go 查看文件

@@ -1124,14 +1124,21 @@ func (client *Client) SetVHost(vhost string) (updated bool) {
1124 1124
 	return
1125 1125
 }
1126 1126
 
1127
-// updateNick updates `nick` and `nickCasefolded`.
1128
-func (client *Client) updateNick(nick, nickCasefolded, skeleton string) {
1127
+// SetNick gives the client a nickname and marks it as registered, if necessary
1128
+func (client *Client) SetNick(nick, nickCasefolded, skeleton string) (success bool) {
1129 1129
 	client.stateMutex.Lock()
1130 1130
 	defer client.stateMutex.Unlock()
1131
+	if client.destroyed {
1132
+		return false
1133
+	} else if !client.registered {
1134
+		// XXX test this before setting it to avoid annoying the race detector
1135
+		client.registered = true
1136
+	}
1131 1137
 	client.nick = nick
1132 1138
 	client.nickCasefolded = nickCasefolded
1133 1139
 	client.skeleton = skeleton
1134 1140
 	client.updateNickMaskNoMutex()
1141
+	return true
1135 1142
 }
1136 1143
 
1137 1144
 // updateNickMaskNoMutex updates the casefolded nickname and nickmask, not acquiring any mutexes.

+ 3
- 1
irc/client_lookup_set.go 查看文件

@@ -243,10 +243,12 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
243 243
 		return "", errNicknameInUse, false
244 244
 	}
245 245
 
246
+	if changeSuccess := client.SetNick(newNick, newCfNick, newSkeleton); !changeSuccess {
247
+		return "", errClientDestroyed, false
248
+	}
246 249
 	clients.removeInternal(client)
247 250
 	clients.byNick[newCfNick] = client
248 251
 	clients.bySkeleton[newSkeleton] = client
249
-	client.updateNick(newNick, newCfNick, newSkeleton)
250 252
 	return newNick, nil, false
251 253
 }
252 254
 

+ 5
- 10
irc/getters.go 查看文件

@@ -235,20 +235,15 @@ func (client *Client) Oper() *Oper {
235 235
 	return client.oper
236 236
 }
237 237
 
238
-func (client *Client) Registered() bool {
239
-	client.stateMutex.RLock()
240
-	defer client.stateMutex.RUnlock()
241
-	return client.registered
242
-}
243
-
244
-func (client *Client) SetRegistered() {
238
+func (client *Client) Registered() (result bool) {
245 239
 	// `registered` is only written from the client's own goroutine, but may be
246 240
 	// read from other goroutines; therefore, the client's own goroutine may read
247 241
 	// the value without synchronization, but must write it with synchronization,
248 242
 	// and other goroutines must read it with synchronization
249
-	client.stateMutex.Lock()
250
-	client.registered = true
251
-	client.stateMutex.Unlock()
243
+	client.stateMutex.RLock()
244
+	result = client.registered
245
+	client.stateMutex.RUnlock()
246
+	return
252 247
 }
253 248
 
254 249
 func (client *Client) RawHostname() (result string) {

+ 5
- 7
irc/nickname.go 查看文件

@@ -91,13 +91,11 @@ func performNickChange(server *Server, client *Client, target *Client, session *
91 91
 		channel.AddHistoryItem(histItem, details.account)
92 92
 	}
93 93
 
94
-	if target.Registered() {
95
-		newCfnick := target.NickCasefolded()
96
-		if newCfnick != details.nickCasefolded {
97
-			client.server.monitorManager.AlertAbout(details.nick, details.nickCasefolded, false)
98
-			client.server.monitorManager.AlertAbout(assignedNickname, newCfnick, true)
99
-		}
100
-	} // else: these will be deferred to the end of registration (see #572)
94
+	newCfnick := target.NickCasefolded()
95
+	if newCfnick != details.nickCasefolded {
96
+		client.server.monitorManager.AlertAbout(details.nick, details.nickCasefolded, false)
97
+		client.server.monitorManager.AlertAbout(assignedNickname, newCfnick, true)
98
+	}
101 99
 	return nil
102 100
 }
103 101
 

+ 0
- 4
irc/server.go 查看文件

@@ -283,12 +283,8 @@ func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
283 283
 		c.SetMode(defaultMode, true)
284 284
 	}
285 285
 
286
-	// registration has succeeded:
287
-	c.SetRegistered()
288
-
289 286
 	// count new user in statistics
290 287
 	server.stats.Register(c.HasMode(modes.Invisible))
291
-	server.monitorManager.AlertAbout(c.Nick(), c.NickCasefolded(), true)
292 288
 
293 289
 	server.playRegistrationBurst(session)
294 290
 	return false

正在加载...
取消
保存