diff --git a/downstream.go b/downstream.go index 66f4a31..4dd221d 100644 --- a/downstream.go +++ b/downstream.go @@ -195,11 +195,29 @@ func (dc *downstreamConn) handleMessage(msg *irc.Message) error { case "QUIT": return dc.Close() case "PING": - // TODO: handle params + 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: []string{dc.srv.Hostname}, + Params: params, }) return nil default: diff --git a/upstream.go b/upstream.go index 5abff55..f8b9ac2 100644 --- a/upstream.go +++ b/upstream.go @@ -109,10 +109,25 @@ func (uc *upstreamConn) getChannel(name string) (*upstreamChannel, error) { func (uc *upstreamConn) handleMessage(msg *irc.Message) error { switch msg.Command { case "PING": - // TODO: handle params + 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: []string{uc.srv.Hostname}, + Params: params, }) return nil case "MODE":