-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added initial source code and update readme
- Loading branch information
1 parent
9316dcd
commit 1a2043f
Showing
8 changed files
with
674 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,36 @@ | ||
# csgo-server-scanner | ||
It scan CSGO community servers and send desktop notification when your favorite map is playing. | ||
# CS:GO Server Scanner | ||
|
||
It scan your favorite CS:GO community servers and send desktop notification when your favorite map is playing. | ||
|
||
## Works only on Windows OS. | ||
|
||
On action: | ||
|
||
|
||
![Alt text](ss.png?raw=true "SS") | ||
|
||
______________ | ||
## How to Install | ||
|
||
``` sh | ||
go build -o csgo-server-scanner.exe | ||
./csgo-server-scanner.exe | ||
``` | ||
|
||
Before running, place config.json with your binary path(csgo-server-scanner.exe). Example config at config.json | ||
|
||
``` JSON | ||
{ | ||
"favoriteMap": "de_dust2", | ||
"serverList": [ | ||
{ | ||
"name": "Turkiye Cumhuriyeti", | ||
"host": "185.193.165.212:27015" | ||
}, | ||
{ | ||
"name": "La Casa", | ||
"host": "185.193.165.115:27015" | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
type ServerConfig struct { | ||
Name string `json:"name"` | ||
Host string `json:"host"` | ||
} | ||
|
||
type Config struct { | ||
ServerList []ServerConfig `json:"serverList"` | ||
FavoriteMap string `json:"favoriteMap"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"favoriteMap": "de_dust2", | ||
"serverList": [ | ||
{ | ||
"name": "Turkiye Cumhuriyeti", | ||
"host": "185.193.165.212:27015" | ||
}, | ||
{ | ||
"name": "La Casa", | ||
"host": "185.193.165.115:27015" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module cs_go_favorite_sv | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/fsnotify/fsnotify v1.5.1 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/magiconair/properties v1.8.6 // indirect | ||
github.com/mitchellh/mapstructure v1.4.3 // indirect | ||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect | ||
github.com/pelletier/go-toml v1.9.4 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect | ||
github.com/rumblefrog/go-a2s v1.0.1 // indirect | ||
github.com/spf13/afero v1.8.2 // indirect | ||
github.com/spf13/cast v1.4.1 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/viper v1.11.0 // indirect | ||
github.com/subosito/gotenv v1.2.0 // indirect | ||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
gopkg.in/ini.v1 v1.66.4 // indirect | ||
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/rumblefrog/go-a2s" | ||
"github.com/spf13/viper" | ||
"gopkg.in/toast.v1" | ||
) | ||
|
||
type ServerInfo struct { | ||
ServerName string | ||
CurrentMap string | ||
Players int | ||
MaxPlayers int | ||
PlayersInfo string | ||
SendNotification bool | ||
IsSick bool | ||
} | ||
|
||
var ( | ||
conf *Config | ||
) | ||
|
||
// Desktop notification | ||
func sendFavoriteMapNotification(serverName, serverPlayers, mapName string) { | ||
var ( | ||
err error | ||
path string | ||
) | ||
path, err = os.Getwd() | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
message := "Server Name: " + serverName + "\nPlayers: " + serverPlayers | ||
title := mapName + " is playing now!" | ||
notification := toast.Notification{ | ||
AppID: "CS GO Favorite Server Scanner", | ||
Title: title, | ||
Message: message, | ||
Icon: path + "/ct.png", | ||
} | ||
err = notification.Push() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
func getConf() *Config { | ||
viper.AddConfigPath(".") | ||
viper.SetConfigName("config") | ||
viper.SetConfigType("json") | ||
err := viper.ReadInConfig() | ||
|
||
if err != nil { | ||
log.Panicf("%v", err) | ||
} | ||
|
||
conf := &Config{} | ||
err = viper.Unmarshal(conf) | ||
if err != nil { | ||
log.Panicf("unable to decode into config struct, %v", err) | ||
} | ||
|
||
return conf | ||
} | ||
|
||
func init() { | ||
conf = getConf() | ||
} | ||
|
||
func main() { | ||
serverMap := make(map[string]ServerInfo) | ||
for { | ||
for _, server := range conf.ServerList { | ||
client, err := a2s.NewClient(server.Host) | ||
|
||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
info, err := client.QueryInfo() | ||
client.Close() | ||
|
||
if err != nil { | ||
log.Println(err) | ||
} | ||
log.Println(info.Name, info.Map, info.Players, "/", info.MaxPlayers) | ||
|
||
_, existServer := serverMap[server.Host] | ||
if existServer && info.Map == serverMap[server.Host].CurrentMap { | ||
continue | ||
} | ||
|
||
serverMap[server.Host] = ServerInfo{ | ||
ServerName: info.Name, | ||
CurrentMap: info.Map, | ||
Players: int(info.Players), | ||
MaxPlayers: int(info.MaxPlayers), | ||
} | ||
|
||
if info.Map == conf.FavoriteMap && info.Players > 0 { | ||
log.Println("sending notification...") | ||
serverPlayers := strconv.Itoa(int(info.Players)) + "/" + strconv.Itoa(int(info.MaxPlayers)) | ||
sendFavoriteMapNotification(server.Name, serverPlayers, info.Map) | ||
} | ||
} | ||
time.Sleep(time.Second * 30) | ||
} | ||
|
||
} |