Compare commits
1
Commits
d90962c960
..
next
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d31fd529e2 |
@@ -92,9 +92,10 @@ func (c *Conn) handleNick(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.mu.Lock()
|
// Take the nick the session holds, not newNick: another
|
||||||
c.nick = newNick
|
// client of the session may have changed it again since
|
||||||
c.mu.Unlock()
|
// ChangeNick stored newNick.
|
||||||
|
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,6 +313,22 @@ 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,22 +234,13 @@ 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. It
|
// may have taken that nick after another user gave it up.
|
||||||
// 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.mu.Lock()
|
c.loadSessionNick(ctx)
|
||||||
|
|
||||||
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