Compare commits
1
Commits
next
..
d90962c960
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d90962c960 |
@@ -92,10 +92,9 @@ func (c *Conn) handleNick(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take the nick the session holds, not newNick: another
|
c.mu.Lock()
|
||||||
// client of the session may have changed it again since
|
c.nick = newNick
|
||||||
// ChangeNick stored newNick.
|
c.mu.Unlock()
|
||||||
c.loadSessionNick(ctx)
|
|
||||||
|
|
||||||
// Echo NICK change to the client on wire.
|
// Echo NICK change to the client on wire.
|
||||||
c.send(FormatMessage(oldMask, "NICK", newNick))
|
c.send(FormatMessage(oldMask, "NICK", newNick))
|
||||||
|
|||||||
@@ -313,22 +313,6 @@ func (c *Conn) currentNick() string {
|
|||||||
return c.nick
|
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.
|
// send writes a formatted IRC line to the connection.
|
||||||
func (c *Conn) send(line string) {
|
func (c *Conn) send(line string) {
|
||||||
c.sendWithin(writeTimeout, line)
|
c.sendWithin(writeTimeout, line)
|
||||||
|
|||||||
@@ -234,13 +234,22 @@ func (c *Conn) deliverPart(msg *db.IRCMessage, text string) {
|
|||||||
// change may be its own session's, made from another client,
|
// change may be its own session's, made from another client,
|
||||||
// so the connection first takes the nick its session holds
|
// so the connection first takes the nick its session holds
|
||||||
// now. It does not go by the line's old nick: the connection
|
// now. It does not go by the line's old nick: the connection
|
||||||
// may have taken that nick after another user gave it up.
|
// 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.
|
||||||
func (c *Conn) deliverNickChange(
|
func (c *Conn) deliverNickChange(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
msg *db.IRCMessage,
|
msg *db.IRCMessage,
|
||||||
newNick string,
|
newNick string,
|
||||||
) {
|
) {
|
||||||
c.loadSessionNick(ctx)
|
c.mu.Lock()
|
||||||
|
|
||||||
|
nick, err := c.database.GetSessionNick(ctx, c.sessionID)
|
||||||
|
if err == nil {
|
||||||
|
c.nick = nick
|
||||||
|
}
|
||||||
|
|
||||||
|
c.mu.Unlock()
|
||||||
|
|
||||||
prefix := msg.From + "!" + msg.From + "@*"
|
prefix := msg.From + "!" + msg.From + "@*"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user