Add basic upstream message handler

This commit is contained in:
Simon Ser 2020-02-06 16:11:28 +01:00
parent 56d793543e
commit c14e26769f
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -179,6 +179,20 @@ type upstreamConn struct {
srv *Server 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 { type Upstream struct {
Addr string Addr string
Nick string Nick string
@ -262,7 +276,10 @@ func (s *Server) connect(upstream *Upstream) error {
} else if err != nil { } else if err != nil {
return fmt.Errorf("failed to read IRC command: %v", err) 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() return netConn.Close()