Make an IRC listener connection follow its session's nick (closes #184)
check / check (push) Waiting to run
check / check (push) Waiting to run
An IRC listener connection kept its own copy of its nick, so after the session's nick was changed from another client it went on sending under the old nick, which another user could then take. Now, whenever the relay passes on a NICK line and after the connection's own NICK is stored, the connection takes the nick its session holds in the database, read by session ID under the connection's lock. Taking the nick from the database rather than from the line means a connection can never follow another user's rename and send as them. Handlers read the nick under the same lock. Untested: an HTTP API rename landing while the connection's own NICK is being stored; that order cannot be produced reliably. Model: opus-5-5
This commit was merged in pull request #187.
This commit is contained in:
@@ -81,7 +81,7 @@ func (c *Conn) handleNick(
|
||||
}
|
||||
|
||||
oldMask := c.hostmask()
|
||||
oldNick := c.nick
|
||||
oldNick := c.currentNick()
|
||||
|
||||
err := c.svc.ChangeNick(
|
||||
ctx, c.sessionID, c.clientID, oldNick, newNick,
|
||||
@@ -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))
|
||||
@@ -129,7 +130,7 @@ func (c *Conn) handlePrivmsg(
|
||||
|
||||
if strings.HasPrefix(target, "#") {
|
||||
_, err := c.svc.SendChannelMessage(
|
||||
ctx, c.sessionID, c.clientID, c.nick,
|
||||
ctx, c.sessionID, c.clientID, c.currentNick(),
|
||||
msg.Command, target, body, nil,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -137,7 +138,7 @@ func (c *Conn) handlePrivmsg(
|
||||
}
|
||||
} else {
|
||||
result, err := c.svc.SendDirectMessage(
|
||||
ctx, c.sessionID, c.clientID, c.nick,
|
||||
ctx, c.sessionID, c.clientID, c.currentNick(),
|
||||
msg.Command, target, body, nil,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -199,7 +200,7 @@ func (c *Conn) joinChannel(
|
||||
channel, key string,
|
||||
) {
|
||||
result, err := c.svc.JoinChannel(
|
||||
ctx, c.sessionID, c.clientID, c.nick, channel, key,
|
||||
ctx, c.sessionID, c.clientID, c.currentNick(), channel, key,
|
||||
)
|
||||
if err != nil {
|
||||
c.sendIRCError(err)
|
||||
@@ -337,7 +338,7 @@ func (c *Conn) partChannel(
|
||||
channel, reason string,
|
||||
) {
|
||||
err := c.svc.PartChannel(
|
||||
ctx, c.sessionID, c.clientID, c.nick, channel, reason,
|
||||
ctx, c.sessionID, c.clientID, c.currentNick(), channel, reason,
|
||||
)
|
||||
if err != nil {
|
||||
c.sendIRCError(err)
|
||||
@@ -401,7 +402,7 @@ func (c *Conn) handleTopic(
|
||||
newTopic := msg.Params[1]
|
||||
|
||||
err := c.svc.SetTopic(
|
||||
ctx, c.sessionID, c.clientID, c.nick, channel, newTopic,
|
||||
ctx, c.sessionID, c.clientID, c.currentNick(), channel, newTopic,
|
||||
)
|
||||
if err != nil {
|
||||
c.sendIRCError(err)
|
||||
@@ -708,7 +709,7 @@ func (c *Conn) applyChannelModes(
|
||||
c.send(FormatMessage(c.hostmask(), "MODE", params...))
|
||||
|
||||
c.svc.BroadcastMode(
|
||||
ctx, c.clientID, c.nick, channel, chID, modeReply,
|
||||
ctx, c.clientID, c.currentNick(), channel, chID, modeReply,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1185,7 +1186,7 @@ func (c *Conn) handleKick(
|
||||
}
|
||||
|
||||
err := c.svc.KickUser(
|
||||
ctx, c.sessionID, c.clientID, c.nick,
|
||||
ctx, c.sessionID, c.clientID, c.currentNick(),
|
||||
channel, targetNick, reason,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -1225,7 +1226,7 @@ func (c *Conn) handlePassPostReg(
|
||||
return
|
||||
}
|
||||
|
||||
c.sendFromServer("NOTICE", c.nick,
|
||||
c.sendFromServer("NOTICE", c.currentNick(),
|
||||
"Password set. You can reconnect using "+
|
||||
"PASS <password> with your nick.",
|
||||
)
|
||||
@@ -1249,7 +1250,7 @@ func (c *Conn) handleInvite(
|
||||
channel := msg.Params[1]
|
||||
|
||||
targetID, err := c.svc.InviteUser(
|
||||
ctx, c.sessionID, c.nick, targetNick, channel,
|
||||
ctx, c.sessionID, c.currentNick(), targetNick, channel,
|
||||
)
|
||||
if err != nil {
|
||||
c.sendIRCError(err)
|
||||
@@ -1266,7 +1267,7 @@ func (c *Conn) handleInvite(
|
||||
body, _ := json.Marshal([]string{channel}) //nolint:errchkjson
|
||||
|
||||
_, _, _ = c.svc.FanOut( //nolint:dogsled // fire-and-forget broadcast
|
||||
ctx, "INVITE", c.nick, targetNick, targetID, 0,
|
||||
ctx, "INVITE", c.currentNick(), targetNick, targetID, 0,
|
||||
nil, body, nil, []int64{targetID}, 0,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user