diff --git a/.gitignore b/.gitignore index 0cffcb3..6298cc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -config.json \ No newline at end of file +config.json +dist diff --git a/config.template.json b/config.template.json index ce27e39..839c7f2 100644 --- a/config.template.json +++ b/config.template.json @@ -2,6 +2,7 @@ "Token": "your_bot_token_id", "RoomIDList": ["id_1", "id_2", "id_3"], "RoleToNotify": "@Elysium", + "GameStatus": "current playing game", "Servers": [ { "Name": "Elysium PvP", diff --git a/dist/ServerStatus-linux b/dist/ServerStatus-linux deleted file mode 100755 index fde56eb..0000000 Binary files a/dist/ServerStatus-linux and /dev/null differ diff --git a/dist/ServerStatus-mac b/dist/ServerStatus-mac deleted file mode 100755 index bc4a99a..0000000 Binary files a/dist/ServerStatus-mac and /dev/null differ diff --git a/dist/ServerStatus-windows.exe b/dist/ServerStatus-windows.exe deleted file mode 100755 index 073ac4c..0000000 Binary files a/dist/ServerStatus-windows.exe and /dev/null differ diff --git a/dist/config.json b/dist/config.json deleted file mode 100644 index ce27e39..0000000 --- a/dist/config.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "Token": "your_bot_token_id", - "RoomIDList": ["id_1", "id_2", "id_3"], - "RoleToNotify": "@Elysium", - "Servers": [ - { - "Name": "Elysium PvP", - "Address": "149.202.207.235", - "Port": 8099 - }, - { - "Name": "Zethkur PvP", - "Address": "151.80.103.221", - "Port": 8093 - }, - { - "Name": "Anathema PvP", - "Address": "149.202.211.5", - "Port": 8095 - }, - { - "Name": "Darrowshire PvE", - "Address": "164.132.233.125", - "Port": 8097 - }, - { - "Name": "Elysium Authentication Server", - "Address": "logon.elysium-project.org", - "Port": 3724 - } - ] -} \ No newline at end of file diff --git a/readme.md b/readme.md index 5b4f32a..ce9e22c 100644 --- a/readme.md +++ b/readme.md @@ -1,13 +1,21 @@ ## Server Status -Scans the Elysium servers checking to see if they are up. +Scans a list of servers checking whether the ports are open or not. This bot will send a chat notification when the status of a server changes. +I originally made this bot the check if private World of Warcraft servers were up or not. +This bot is actually much more useful than that and can be used for any type of server. + ## Configuration -- Download or Clone the repository -- Add your bot token and room ID to the config.json in the dist folder -- Execute the correct binary according to your operating system! +- Download the latest release [here](https://github.com/mgerb/ServerStatus/releases) +- Add your bot token as well as other configurations to config.json +- Execute the OS specific binary! + +## Compiling from source + +- Make sure Go and Make are installed +- make all ### How to get the bot token https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token @@ -29,9 +37,3 @@ Anathema PvP is online! Darrowshire PvE is online! Elysium Authentication Server is online! ``` - -## Compiling - -Make sure you have Go installed. - -`make clean all` diff --git a/src/bot/bot.go b/src/bot/bot.go index 48739e7..8da856b 100644 --- a/src/bot/bot.go +++ b/src/bot/bot.go @@ -43,8 +43,6 @@ func Start() { fmt.Println("Bot is now running. Press CTRL-C to exit.") - // Simple way to keep program running until CTRL-C is pressed. - <-make(chan struct{}) return } diff --git a/src/config/config.go b/src/config/config.go index 6ece504..26174a2 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -15,6 +15,7 @@ type configStruct struct { RoomIDList []string `json:"RoomIDList"` RoleToNotify string `json:"RoleToNotify"` Servers []server `json:"Servers"` + GameStatus string `json:"GameStatus"` } type server struct { diff --git a/src/main.go b/src/main.go index 0685c18..839ed0c 100644 --- a/src/main.go +++ b/src/main.go @@ -18,11 +18,15 @@ func main() { //connect bot to account with token bot.Connect(config.Config.Token) - //start side tasks - serverstatus.Start() - + // add handlers bot.AddHandler(serverstatus.MessageHandler) //start websocket to listen for messages bot.Start() + + //start server status task + serverstatus.Start() + + // Simple way to keep program running until CTRL-C is pressed. + <-make(chan struct{}) } diff --git a/src/serverstatus/serverstatus.go b/src/serverstatus/serverstatus.go index b36ec3b..5cb38c3 100644 --- a/src/serverstatus/serverstatus.go +++ b/src/serverstatus/serverstatus.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/anvie/port-scanner" "github.com/bwmarrin/discordgo" + "log" "time" ) @@ -15,11 +16,17 @@ func Start() { config.Config.Servers[i].Online = true } + err := bot.Session.UpdateStatus(0, config.Config.GameStatus) + + if err != nil { + log.Println(err) + } + //start a new go routine - go loop() + go scanServers() } -func loop() { +func scanServers() { //check if server are in config file if len(config.Config.Servers) < 1 { @@ -32,8 +39,8 @@ func loop() { for index, server := range config.Config.Servers { prevServerUp := server.Online //set value to previous server status - elysiumPvP := portscanner.NewPortScanner(server.Address, time.Second*2) - serverUp := elysiumPvP.IsOpen(server.Port) //check if the port is open + serverScanner := portscanner.NewPortScanner(server.Address, time.Second*2) + serverUp := serverScanner.IsOpen(server.Port) //check if the port is open if serverUp && serverUp != prevServerUp { sendMessage(config.Config.RoleToNotify + " " + server.Name + " is now online!")