diff --git a/server.go b/server.go index df5d0f1..b7d5ac0 100644 --- a/server.go +++ b/server.go @@ -75,6 +75,7 @@ type Server struct { upstreamLauncher libnmdc.HubConnectionOptions upstreamCloser chan struct{} + upstreamEvents chan libnmdc.HubEvent upstream *libnmdc.HubConnection verbose bool @@ -99,9 +100,10 @@ func NewServer(name string, upstream libnmdc.HubAddress, conn net.Conn) *Server motd: "Connected to " + name + ". You /must/ join " + BLESSED_CHANNEL + " to continue.", upstreamLauncher: libnmdc.HubConnectionOptions{ Address: upstream, - Self: *self, + Self: self, SkipAutoReconnect: true, }, + upstreamEvents: make(chan libnmdc.HubEvent, 0), // unbuffered upstreamCloser: make(chan struct{}, 1), quirks: DefaultQuirks(), } @@ -255,7 +257,7 @@ func (s *Server) upstreamWorker() { s.upstream.Disconnect() return - case hubEvent := <-s.upstream.OnEvent: + case hubEvent := <-s.upstreamEvents: switch hubEvent.EventType { case libnmdc.EVENT_USER_JOINED: s.reply(rplJoin, hubEvent.Nick, BLESSED_CHANNEL) @@ -537,7 +539,7 @@ func (s *Server) maybeStartUpstream() { s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL) // Spawn upstream connection - s.upstream = s.upstreamLauncher.Connect() + s.upstream = libnmdc.ConnectAsync(&s.upstreamLauncher, s.upstreamEvents) go s.upstreamWorker() } else {