Compare commits
1
Commits
d90962c960
..
next
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d31fd529e2 |
@@ -92,9 +92,10 @@ func (c *Conn) handleNick(
|
||||
return
|
||||
}
|
||||
|
||||
c.mu.Lock()
|
||||
c.nick = newNick
|
||||
c.mu.Unlock()
|
||||
// Take the nick the session holds, not newNick: another
|
||||
// client of the session may have changed it again since
|
||||
// ChangeNick stored newNick.
|
||||
c.loadSessionNick(ctx)
|
||||
|
||||
// Echo NICK change to the client on wire.
|
||||
c.send(FormatMessage(oldMask, "NICK", newNick))
|
||||
|
||||
@@ -313,6 +313,22 @@ func (c *Conn) currentNick() string {
|
||||
return c.nick
|
||||
}
|
||||
|
||||
// loadSessionNick sets c.nick to the nick the connection's
|
||||
// session holds in the database, read by session ID. The
|
||||
// connection's own NICK and the relay passing on a NICK line
|
||||
// both call it, and it reads and sets the nick under c.mu, so
|
||||
// whichever runs last leaves the connection on its session's
|
||||
// nick. If the read fails, c.nick is left as it is.
|
||||
func (c *Conn) loadSessionNick(ctx context.Context) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
nick, err := c.database.GetSessionNick(ctx, c.sessionID)
|
||||
if err == nil {
|
||||
c.nick = nick
|
||||
}
|
||||
}
|
||||
|
||||
// send writes a formatted IRC line to the connection.
|
||||
func (c *Conn) send(line string) {
|
||||
c.sendWithin(writeTimeout, line)
|
||||
|
||||
@@ -234,22 +234,13 @@ func (c *Conn) deliverPart(msg *db.IRCMessage, text string) {
|
||||
// change may be its own session's, made from another client,
|
||||
// so the connection first takes the nick its session holds
|
||||
// now. It does not go by the line's old nick: the connection
|
||||
// may have taken that nick after another user gave it up. It
|
||||
// reads the nick under c.mu, so that a NICK sent on the
|
||||
// connection meanwhile is not undone.
|
||||
// may have taken that nick after another user gave it up.
|
||||
func (c *Conn) deliverNickChange(
|
||||
ctx context.Context,
|
||||
msg *db.IRCMessage,
|
||||
newNick string,
|
||||
) {
|
||||
c.mu.Lock()
|
||||
|
||||
nick, err := c.database.GetSessionNick(ctx, c.sessionID)
|
||||
if err == nil {
|
||||
c.nick = nick
|
||||
}
|
||||
|
||||
c.mu.Unlock()
|
||||
c.loadSessionNick(ctx)
|
||||
|
||||
prefix := msg.From + "!" + msg.From + "@*"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user