Fix PING handlers, again

This commit is contained in:
Simon Ser 2020-02-18 20:40:32 +01:00
parent 1141698a92
commit ef2d145d1f
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 2 additions and 37 deletions

View File

@ -195,29 +195,10 @@ func (dc *downstreamConn) handleMessage(msg *irc.Message) error {
case "QUIT": case "QUIT":
return dc.Close() return dc.Close()
case "PING": case "PING":
var from, to string
if len(msg.Params) >= 1 {
from = msg.Params[0]
}
if len(msg.Params) >= 2 {
to = msg.Params[1]
}
if to != "" && to != dc.srv.Hostname {
return ircError{&irc.Message{
Command: irc.ERR_NOSUCHSERVER,
Params: []string{to, "No such server"},
}}
}
params := []string{dc.srv.Hostname}
if from != "" {
params = append(params, from)
}
dc.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
Command: "PONG", Command: "PONG",
Params: params, Params: msg.Params,
}) })
return nil return nil
default: default:

View File

@ -111,25 +111,9 @@ func (uc *upstreamConn) getChannel(name string) (*upstreamChannel, error) {
func (uc *upstreamConn) handleMessage(msg *irc.Message) error { func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
switch msg.Command { switch msg.Command {
case "PING": case "PING":
var from, to string
if len(msg.Params) >= 1 {
from = msg.Params[0]
}
if len(msg.Params) >= 2 {
to = msg.Params[1]
}
if to != "" && to != uc.srv.Hostname {
return fmt.Errorf("invalid PING destination %q", to)
}
params := []string{uc.srv.Hostname}
if from != "" {
params = append(params, from)
}
uc.SendMessage(&irc.Message{ uc.SendMessage(&irc.Message{
Command: "PONG", Command: "PONG",
Params: params, Params: msg.Params,
}) })
return nil return nil
case "MODE": case "MODE":