Add basic upstream message handler

git-svn-id: file:///srv/svn/repo/suika/trunk@11 f0ae65fe-ee39-954e-97ec-027ff2717ef4
This commit is contained in:
contact 2020-02-06 15:11:28 +00:00
parent 2ff6caa14d
commit bfc082992f

View File

@ -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()