3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

clean up nickname setting logic

This commit is contained in:
Jeremy Latt 2014-02-18 15:36:58 -08:00
parent 86d4cae141
commit 0cd6be8008
2 changed files with 10 additions and 8 deletions

View File

@ -236,12 +236,17 @@ func (client *Client) Friends() ClientSet {
return friends
}
func (client *Client) ChangeNickname(nickname string) {
// Make reply before changing nick.
reply := RplNick(client, nickname)
func (client *Client) SetNickname(nickname string) {
client.nick = nickname
client.server.clients.Add(client)
}
func (client *Client) ChangeNickname(nickname string) {
// Make reply before changing nick to capture original source id.
reply := RplNick(client, nickname)
client.server.clients.Remove(client)
client.nick = nickname
client.server.clients.Add(client)
for friend := range client.Friends() {
friend.Reply(reply)
}

View File

@ -296,8 +296,7 @@ func (m *NickCommand) HandleRegServer(s *Server) {
return
}
client.ChangeNickname(m.nickname)
s.clients.Add(client)
client.SetNickname(m.nickname)
s.tryRegister(client)
}
@ -356,9 +355,7 @@ func (msg *NickCommand) HandleServer(server *Server) {
return
}
server.clients.Remove(client)
client.ChangeNickname(msg.nickname)
server.clients.Add(client)
}
func (m *UserCommand) HandleServer(s *Server) {