Parcourir la source

Merge pull request #1227 from slingamn/issue1225.2

fix #1225
tags/v2.3.0-rc1
Shivaram Lingamneni il y a 3 ans
Parent
révision
55b21fa86c
Aucun compte lié à l'adresse e-mail de l'auteur
5 fichiers modifiés avec 22 ajouts et 24 suppressions
  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 Voir le fichier

1124
 	return
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
 	client.stateMutex.Lock()
1129
 	client.stateMutex.Lock()
1130
 	defer client.stateMutex.Unlock()
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
 	client.nick = nick
1137
 	client.nick = nick
1132
 	client.nickCasefolded = nickCasefolded
1138
 	client.nickCasefolded = nickCasefolded
1133
 	client.skeleton = skeleton
1139
 	client.skeleton = skeleton
1134
 	client.updateNickMaskNoMutex()
1140
 	client.updateNickMaskNoMutex()
1141
+	return true
1135
 }
1142
 }
1136
 
1143
 
1137
 // updateNickMaskNoMutex updates the casefolded nickname and nickmask, not acquiring any mutexes.
1144
 // updateNickMaskNoMutex updates the casefolded nickname and nickmask, not acquiring any mutexes.

+ 3
- 1
irc/client_lookup_set.go Voir le fichier

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

+ 5
- 10
irc/getters.go Voir le fichier

235
 	return client.oper
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
 	// `registered` is only written from the client's own goroutine, but may be
239
 	// `registered` is only written from the client's own goroutine, but may be
246
 	// read from other goroutines; therefore, the client's own goroutine may read
240
 	// read from other goroutines; therefore, the client's own goroutine may read
247
 	// the value without synchronization, but must write it with synchronization,
241
 	// the value without synchronization, but must write it with synchronization,
248
 	// and other goroutines must read it with synchronization
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
 func (client *Client) RawHostname() (result string) {
249
 func (client *Client) RawHostname() (result string) {

+ 5
- 7
irc/nickname.go Voir le fichier

91
 		channel.AddHistoryItem(histItem, details.account)
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
 	return nil
99
 	return nil
102
 }
100
 }
103
 
101
 

+ 0
- 4
irc/server.go Voir le fichier

283
 		c.SetMode(defaultMode, true)
283
 		c.SetMode(defaultMode, true)
284
 	}
284
 	}
285
 
285
 
286
-	// registration has succeeded:
287
-	c.SetRegistered()
288
-
289
 	// count new user in statistics
286
 	// count new user in statistics
290
 	server.stats.Register(c.HasMode(modes.Invisible))
287
 	server.stats.Register(c.HasMode(modes.Invisible))
291
-	server.monitorManager.AlertAbout(c.Nick(), c.NickCasefolded(), true)
292
 
288
 
293
 	server.playRegistrationBurst(session)
289
 	server.playRegistrationBurst(session)
294
 	return false
290
 	return false

Chargement…
Annuler
Enregistrer