From c14e26769f78d0db70ba6a03c98fb9c63fb3a78b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 6 Feb 2020 16:11:28 +0100 Subject: [PATCH] Add basic upstream message handler --- server.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index cab6afd..bb32586 100644 --- a/server.go +++ b/server.go @@ -179,6 +179,20 @@ type upstreamConn struct { srv *Server } +func (c *upstreamConn) handleMessage(msg *irc.Message) error { + switch msg.Command { + case "PING": + // TODO: handle params + return c.irc.WriteMessage(&irc.Message{ + Command: "PONG", + Params: []string{c.srv.Hostname}, + }) + default: + c.srv.Logger.Printf("Unhandled upstream message: %v", msg) + return nil + } +} + type Upstream struct { Addr string Nick string @@ -262,7 +276,10 @@ func (s *Server) connect(upstream *Upstream) error { } else if err != nil { return fmt.Errorf("failed to read IRC command: %v", err) } - log.Printf("Upstream message: %v", msg) + + if err := c.handleMessage(msg); err != nil { + return err + } } return netConn.Close()