Update downstream nicks in single-server mode and after NICK

Previously, the downstream nick was never changed, even when the
downstream sent a NICK message or was in single-server mode with a
different nick.

This adds support for updating the downstream nick in the following
cases:
- when a downstream sends NICK
- additionally, in single-server mode:
  - when a downstream connects and its single network is connected
  - when an upstream connects
  - when an upstream sends NICK
This commit is contained in:
delthas 2020-05-01 00:37:42 +02:00 committed by Simon Ser
parent 566986fdd5
commit b3742cc731
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
3 changed files with 28 additions and 0 deletions

View File

@ -620,6 +620,17 @@ func (dc *downstreamConn) updateSupportedCaps() {
}
}
func (dc *downstreamConn) updateNick() {
if uc := dc.upstream(); uc != nil && uc.nick != dc.nick {
dc.SendMessage(&irc.Message{
Prefix: dc.prefix(),
Command: "NICK",
Params: []string{uc.nick},
})
dc.nick = uc.nick
}
}
func sanityCheckServer(addr string) error {
dialer := net.Dialer{Timeout: 30 * time.Second}
conn, err := tls.DialWithDialer(&dialer, "tcp", addr, nil)
@ -777,6 +788,8 @@ func (dc *downstreamConn) welcome() error {
Params: []string{dc.nick, "No MOTD"},
})
dc.updateNick()
dc.forEachUpstream(func(uc *upstreamConn) {
for _, ch := range uc.channels {
if !ch.complete {
@ -935,6 +948,15 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
dc.forEachUpstream(func(uc *upstreamConn) {
uc.SendMessage(msg)
})
if dc.upstream() == nil && dc.nick != nick {
dc.SendMessage(&irc.Message{
Prefix: dc.prefix(),
Command: "NICK",
Params: []string{nick},
})
dc.nick = nick
}
case "JOIN":
var namesStr string
if err := parseMessageParams(msg, &namesStr); err != nil {

View File

@ -656,6 +656,10 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
uc.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(dc.marshalMessage(msg, uc.network))
})
} else {
uc.forEachDownstream(func(dc *downstreamConn) {
dc.updateNick()
})
}
case "JOIN":
if msg.Prefix == nil {

View File

@ -298,6 +298,8 @@ func (u *user) run() {
uc.forEachDownstream(func(dc *downstreamConn) {
dc.updateSupportedCaps()
sendServiceNOTICE(dc, fmt.Sprintf("connected to %s", uc.network.GetName()))
dc.updateNick()
})
uc.network.lastError = nil
case eventUpstreamDisconnected: