libnmdc compatibility fixes (now requires 0.17++)

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
mappu 2018-03-24 13:22:34 +13:00
parent e83e2dc111
commit fa13755311

View File

@ -75,6 +75,7 @@ type Server struct {
upstreamLauncher libnmdc.HubConnectionOptions upstreamLauncher libnmdc.HubConnectionOptions
upstreamCloser chan struct{} upstreamCloser chan struct{}
upstreamEvents chan libnmdc.HubEvent
upstream *libnmdc.HubConnection upstream *libnmdc.HubConnection
verbose bool 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.", motd: "Connected to " + name + ". You /must/ join " + BLESSED_CHANNEL + " to continue.",
upstreamLauncher: libnmdc.HubConnectionOptions{ upstreamLauncher: libnmdc.HubConnectionOptions{
Address: upstream, Address: upstream,
Self: *self, Self: self,
SkipAutoReconnect: true, SkipAutoReconnect: true,
}, },
upstreamEvents: make(chan libnmdc.HubEvent, 0), // unbuffered
upstreamCloser: make(chan struct{}, 1), upstreamCloser: make(chan struct{}, 1),
quirks: DefaultQuirks(), quirks: DefaultQuirks(),
} }
@ -255,7 +257,7 @@ func (s *Server) upstreamWorker() {
s.upstream.Disconnect() s.upstream.Disconnect()
return return
case hubEvent := <-s.upstream.OnEvent: case hubEvent := <-s.upstreamEvents:
switch hubEvent.EventType { switch hubEvent.EventType {
case libnmdc.EVENT_USER_JOINED: case libnmdc.EVENT_USER_JOINED:
s.reply(rplJoin, hubEvent.Nick, BLESSED_CHANNEL) s.reply(rplJoin, hubEvent.Nick, BLESSED_CHANNEL)
@ -537,7 +539,7 @@ func (s *Server) maybeStartUpstream() {
s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL) s.reply(rplJoin, s.clientNick(), BLESSED_CHANNEL)
// Spawn upstream connection // Spawn upstream connection
s.upstream = s.upstreamLauncher.Connect() s.upstream = libnmdc.ConnectAsync(&s.upstreamLauncher, s.upstreamEvents)
go s.upstreamWorker() go s.upstreamWorker()
} else { } else {