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":
return dc.Close()
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{
Prefix: dc.srv.prefix(),
Command: "PONG",
Params: params,
Params: msg.Params,
})
return nil
default:

View file

@ -111,25 +111,9 @@ func (uc *upstreamConn) getChannel(name string) (*upstreamChannel, error) {
func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
switch msg.Command {
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{
Command: "PONG",
Params: params,
Params: msg.Params,
})
return nil
case "MODE":