Tino has proposed merging lp:~tino79/widelands-metaserver/ircbridge into lp:widelands-metaserver.
Requested reviews: SirVer (sirver) For more details, see: https://code.launchpad.net/~tino79/widelands-metaserver/ircbridge/+merge/203277 A first draft of a irce bridge. Lets the metaserver connect to a irc channel an mirrors messages between the channel and the metaserver lobby. -- https://code.launchpad.net/~tino79/widelands-metaserver/ircbridge/+merge/203277 Your team Widelands Developers is subscribed to branch lp:widelands-metaserver.
=== added file '.bzrignore' --- .bzrignore 1970-01-01 00:00:00 +0000 +++ .bzrignore 2014-01-27 07:06:57 +0000 @@ -0,0 +1,1 @@ +*.exe === modified file 'wlms/client.go' --- wlms/client.go 2014-01-07 07:38:26 +0000 +++ wlms/client.go 2014-01-27 07:06:57 +0000 @@ -277,6 +277,7 @@ if len(receiver) == 0 { server.BroadcastToConnectedClients("CHAT", client.Name(), message, "public") + server.BroadcastToIRC(client.Name() + " : " + message) } else { recv_client := server.HasClient(receiver) if recv_client != nil { === added file 'wlms/ircbridge.go' --- wlms/ircbridge.go 1970-01-01 00:00:00 +0000 +++ wlms/ircbridge.go 2014-01-27 07:06:57 +0000 @@ -0,0 +1,49 @@ +package main + +import ( + "log" + + "github.com/thoj/go-ircevent" +) + +type IRCBridge struct { + nick, user, channel, server string + connection *irc.Connection +} + +func NewIRCBridge() IRCBridge { + return IRCBridge{ + nick: "WLMetaServer", + user: "WLMetaServer", + channel: "#widelands-test", + server: "irc.freenode.net:7000"} +} + +func (bridge *IRCBridge) connect() { + //Create new connection + bridge.connection = irc.IRC(bridge.nick, bridge.user) + //Set options + bridge.connection.UseTLS = true //default is false + //connection.TLSOptions //set ssl options + //connection.Password = "[server password]" + //Commands + err := bridge.connection.Connect(bridge.server) //Connect to server + if err != nil { + log.Fatal("Can't connect to freenode.") + } + bridge.connection.Join(bridge.channel) +} + +func (bridge *IRCBridge) quit() { + bridge.connection.Quit() +} + +func (bridge *IRCBridge) setCallback(callback func(string, string)) { + bridge.connection.AddCallback("PRIVMSG", func(e *irc.Event) { + callback(e.Nick, e.Message) + }) +} + +func (bridge *IRCBridge) send(m string) { + bridge.connection.Privmsg(bridge.channel, m) +} === modified file 'wlms/server.go' --- wlms/server.go 2014-01-07 06:19:03 +0000 +++ wlms/server.go 2014-01-27 07:06:57 +0000 @@ -28,41 +28,42 @@ gamePingTimeout time.Duration clientForgetTimeout time.Duration gamePingCreator GamePingFactory + ircBridge IRCBridge } type GamePingFactory interface { New(client *Client, timeout time.Duration) *GamePinger } -func (s Server) ClientSendingTimeout() time.Duration { +func (s *Server) ClientSendingTimeout() time.Duration { return s.clientSendingTimeout } func (s *Server) SetClientSendingTimeout(d time.Duration) { s.clientSendingTimeout = d } -func (s Server) PingCycleTime() time.Duration { +func (s *Server) PingCycleTime() time.Duration { return s.pingCycleTime } func (s *Server) SetPingCycleTime(d time.Duration) { s.pingCycleTime = d } -func (s Server) GamePingTimeout() time.Duration { +func (s *Server) GamePingTimeout() time.Duration { return s.gamePingTimeout } func (s *Server) SetGamePingTimeout(v time.Duration) { s.gamePingTimeout = v } -func (s Server) ClientForgetTimeout() time.Duration { +func (s *Server) ClientForgetTimeout() time.Duration { return s.clientForgetTimeout } func (s *Server) SetClientForgetTimeout(v time.Duration) { s.clientForgetTimeout = v } -func (s Server) Motd() string { +func (s *Server) Motd() string { return s.motd } func (s *Server) SetMotd(v string) { @@ -87,6 +88,7 @@ } func (s *Server) AddClient(client *Client) { + s.BroadcastToIRC(client.Name() + " has joined the Metaserver lobby") s.clients.PushBack(client) } @@ -108,6 +110,7 @@ if e.Value.(*Client) == client { log.Printf("Removing client %s.", client.Name()) s.clients.Remove(e) + s.BroadcastToIRC(client.Name() + " has left the Metaserver lobby") } } } @@ -132,7 +135,7 @@ return count } -func (s Server) ForeachActiveClient(callback func(*Client)) { +func (s *Server) ForeachActiveClient(callback func(*Client)) { for e := s.clients.Front(); e != nil; e = e.Next() { client := e.Value.(*Client) if client.State() != CONNECTED { @@ -145,6 +148,7 @@ func (s *Server) AddGame(game *Game) { s.games.PushBack(game) s.BroadcastToConnectedClients("GAMES_UPDATE") + s.BroadcastToIRC("A new game " + game.Name() + " was opened by " + game.Host()) } func (s *Server) RemoveGame(game *Game) { @@ -171,7 +175,7 @@ return s.games.Len() } -func (s Server) ForeachGame(callback func(*Game)) { +func (s *Server) ForeachGame(callback func(*Game)) { for e := s.games.Front(); e != nil; e = e.Next() { callback(e.Value.(*Game)) } @@ -186,6 +190,10 @@ } } +func (s *Server) BroadcastToIRC(message string) { + s.ircBridge.send(message) +} + func RunServer(db UserDb) { ln, err := net.Listen("tcp", ":7395") if err != nil { @@ -207,6 +215,10 @@ CreateServerUsing(C, db).WaitTillShutdown() } +func (s *Server) BroadcastToLobby(nick string, message string) { + s.BroadcastToConnectedClients("CHAT", nick+"(IRC)", message, "public") +} + type RealGamePingFactory struct { server *Server } @@ -258,7 +270,10 @@ pingCycleTime: time.Second * 15, clientSendingTimeout: time.Minute * 2, clientForgetTimeout: time.Minute * 5, + ircBridge: NewIRCBridge(), } + server.ircBridge.connect() + server.ircBridge.setCallback(server.BroadcastToLobby) server.gamePingCreator = RealGamePingFactory{server} go server.mainLoop() return server @@ -280,6 +295,7 @@ s.clients.Remove(e) } close(s.acceptedConnections) + s.ircBridge.quit() s.serverHasShutdown <- true return }
_______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp