1
0
mirror of https://github.com/mgerb/ServerStatus synced 2026-01-11 03:32:50 +00:00

added current playing game - also refactored some things

This commit is contained in:
2017-04-01 16:19:56 -05:00
parent d2d9b08f8c
commit 93e6c54976
11 changed files with 34 additions and 52 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
config.json config.json
dist

View File

@@ -2,6 +2,7 @@
"Token": "your_bot_token_id", "Token": "your_bot_token_id",
"RoomIDList": ["id_1", "id_2", "id_3"], "RoomIDList": ["id_1", "id_2", "id_3"],
"RoleToNotify": "@Elysium", "RoleToNotify": "@Elysium",
"GameStatus": "current playing game",
"Servers": [ "Servers": [
{ {
"Name": "Elysium PvP", "Name": "Elysium PvP",

Binary file not shown.

BIN
dist/ServerStatus-mac vendored

Binary file not shown.

Binary file not shown.

32
dist/config.json vendored
View File

@@ -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
}
]
}

View File

@@ -1,13 +1,21 @@
## Server Status ## 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. 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 ## Configuration
- Download or Clone the repository - Download the latest release [here](https://github.com/mgerb/ServerStatus/releases)
- Add your bot token and room ID to the config.json in the dist folder - Add your bot token as well as other configurations to config.json
- Execute the correct binary according to your operating system! - Execute the OS specific binary!
## Compiling from source
- Make sure Go and Make are installed
- make all
### How to get the bot token ### How to get the bot token
https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-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! Darrowshire PvE is online!
Elysium Authentication Server is online! Elysium Authentication Server is online!
``` ```
## Compiling
Make sure you have Go installed.
`make clean all`

View File

@@ -43,8 +43,6 @@ func Start() {
fmt.Println("Bot is now running. Press CTRL-C to exit.") 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 return
} }

View File

@@ -15,6 +15,7 @@ type configStruct struct {
RoomIDList []string `json:"RoomIDList"` RoomIDList []string `json:"RoomIDList"`
RoleToNotify string `json:"RoleToNotify"` RoleToNotify string `json:"RoleToNotify"`
Servers []server `json:"Servers"` Servers []server `json:"Servers"`
GameStatus string `json:"GameStatus"`
} }
type server struct { type server struct {

View File

@@ -18,11 +18,15 @@ func main() {
//connect bot to account with token //connect bot to account with token
bot.Connect(config.Config.Token) bot.Connect(config.Config.Token)
//start side tasks // add handlers
serverstatus.Start()
bot.AddHandler(serverstatus.MessageHandler) bot.AddHandler(serverstatus.MessageHandler)
//start websocket to listen for messages //start websocket to listen for messages
bot.Start() bot.Start()
//start server status task
serverstatus.Start()
// Simple way to keep program running until CTRL-C is pressed.
<-make(chan struct{})
} }

View File

@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/anvie/port-scanner" "github.com/anvie/port-scanner"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"log"
"time" "time"
) )
@@ -15,11 +16,17 @@ func Start() {
config.Config.Servers[i].Online = true config.Config.Servers[i].Online = true
} }
//start a new go routine err := bot.Session.UpdateStatus(0, config.Config.GameStatus)
go loop()
if err != nil {
log.Println(err)
} }
func loop() { //start a new go routine
go scanServers()
}
func scanServers() {
//check if server are in config file //check if server are in config file
if len(config.Config.Servers) < 1 { if len(config.Config.Servers) < 1 {
@@ -32,8 +39,8 @@ func loop() {
for index, server := range config.Config.Servers { for index, server := range config.Config.Servers {
prevServerUp := server.Online //set value to previous server status prevServerUp := server.Online //set value to previous server status
elysiumPvP := portscanner.NewPortScanner(server.Address, time.Second*2) serverScanner := portscanner.NewPortScanner(server.Address, time.Second*2)
serverUp := elysiumPvP.IsOpen(server.Port) //check if the port is open serverUp := serverScanner.IsOpen(server.Port) //check if the port is open
if serverUp && serverUp != prevServerUp { if serverUp && serverUp != prevServerUp {
sendMessage(config.Config.RoleToNotify + " " + server.Name + " is now online!") sendMessage(config.Config.RoleToNotify + " " + server.Name + " is now online!")