Skip to content

Commit 1a2043f

Browse files
committed
added initial source code and update readme
1 parent 9316dcd commit 1a2043f

File tree

8 files changed

+674
-2
lines changed

8 files changed

+674
-2
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
1-
# csgo-server-scanner
2-
It scan CSGO community servers and send desktop notification when your favorite map is playing.
1+
# CS:GO Server Scanner
2+
3+
It scan your favorite CS:GO community servers and send desktop notification when your favorite map is playing.
4+
5+
## Works only on Windows OS.
6+
7+
On action:
8+
9+
10+
![Alt text](ss.png?raw=true "SS")
11+
12+
______________
13+
## How to Install
14+
15+
``` sh
16+
go build -o csgo-server-scanner.exe
17+
./csgo-server-scanner.exe
18+
```
19+
20+
Before running, place config.json with your binary path(csgo-server-scanner.exe). Example config at config.json
21+
22+
``` JSON
23+
{
24+
"favoriteMap": "de_dust2",
25+
"serverList": [
26+
{
27+
"name": "Turkiye Cumhuriyeti",
28+
"host": "185.193.165.212:27015"
29+
},
30+
{
31+
"name": "La Casa",
32+
"host": "185.193.165.115:27015"
33+
}
34+
]
35+
}
36+
```

config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
type ServerConfig struct {
4+
Name string `json:"name"`
5+
Host string `json:"host"`
6+
}
7+
8+
type Config struct {
9+
ServerList []ServerConfig `json:"serverList"`
10+
FavoriteMap string `json:"favoriteMap"`
11+
}

config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"favoriteMap": "de_dust2",
3+
"serverList": [
4+
{
5+
"name": "Turkiye Cumhuriyeti",
6+
"host": "185.193.165.212:27015"
7+
},
8+
{
9+
"name": "La Casa",
10+
"host": "185.193.165.115:27015"
11+
}
12+
]
13+
}

ct.png

163 KB
Loading

go.mod

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module cs_go_favorite_sv
2+
3+
go 1.17
4+
5+
require (
6+
github.com/fsnotify/fsnotify v1.5.1 // indirect
7+
github.com/hashicorp/hcl v1.0.0 // indirect
8+
github.com/magiconair/properties v1.8.6 // indirect
9+
github.com/mitchellh/mapstructure v1.4.3 // indirect
10+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
11+
github.com/pelletier/go-toml v1.9.4 // indirect
12+
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
13+
github.com/rumblefrog/go-a2s v1.0.1 // indirect
14+
github.com/spf13/afero v1.8.2 // indirect
15+
github.com/spf13/cast v1.4.1 // indirect
16+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
17+
github.com/spf13/pflag v1.0.5 // indirect
18+
github.com/spf13/viper v1.11.0 // indirect
19+
github.com/subosito/gotenv v1.2.0 // indirect
20+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
21+
golang.org/x/text v0.3.7 // indirect
22+
gopkg.in/ini.v1 v1.66.4 // indirect
23+
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 // indirect
24+
gopkg.in/yaml.v2 v2.4.0 // indirect
25+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
26+
)

go.sum

Lines changed: 474 additions & 0 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"strconv"
7+
"time"
8+
9+
"github.com/rumblefrog/go-a2s"
10+
"github.com/spf13/viper"
11+
"gopkg.in/toast.v1"
12+
)
13+
14+
type ServerInfo struct {
15+
ServerName string
16+
CurrentMap string
17+
Players int
18+
MaxPlayers int
19+
PlayersInfo string
20+
SendNotification bool
21+
IsSick bool
22+
}
23+
24+
var (
25+
conf *Config
26+
)
27+
28+
// Desktop notification
29+
func sendFavoriteMapNotification(serverName, serverPlayers, mapName string) {
30+
var (
31+
err error
32+
path string
33+
)
34+
path, err = os.Getwd()
35+
if err != nil {
36+
log.Println(err)
37+
}
38+
message := "Server Name: " + serverName + "\nPlayers: " + serverPlayers
39+
title := mapName + " is playing now!"
40+
notification := toast.Notification{
41+
AppID: "CS GO Favorite Server Scanner",
42+
Title: title,
43+
Message: message,
44+
Icon: path + "/ct.png",
45+
}
46+
err = notification.Push()
47+
if err != nil {
48+
log.Fatalln(err)
49+
}
50+
}
51+
52+
func getConf() *Config {
53+
viper.AddConfigPath(".")
54+
viper.SetConfigName("config")
55+
viper.SetConfigType("json")
56+
err := viper.ReadInConfig()
57+
58+
if err != nil {
59+
log.Panicf("%v", err)
60+
}
61+
62+
conf := &Config{}
63+
err = viper.Unmarshal(conf)
64+
if err != nil {
65+
log.Panicf("unable to decode into config struct, %v", err)
66+
}
67+
68+
return conf
69+
}
70+
71+
func init() {
72+
conf = getConf()
73+
}
74+
75+
func main() {
76+
serverMap := make(map[string]ServerInfo)
77+
for {
78+
for _, server := range conf.ServerList {
79+
client, err := a2s.NewClient(server.Host)
80+
81+
if err != nil {
82+
log.Println(err)
83+
}
84+
85+
info, err := client.QueryInfo()
86+
client.Close()
87+
88+
if err != nil {
89+
log.Println(err)
90+
}
91+
log.Println(info.Name, info.Map, info.Players, "/", info.MaxPlayers)
92+
93+
_, existServer := serverMap[server.Host]
94+
if existServer && info.Map == serverMap[server.Host].CurrentMap {
95+
continue
96+
}
97+
98+
serverMap[server.Host] = ServerInfo{
99+
ServerName: info.Name,
100+
CurrentMap: info.Map,
101+
Players: int(info.Players),
102+
MaxPlayers: int(info.MaxPlayers),
103+
}
104+
105+
if info.Map == conf.FavoriteMap && info.Players > 0 {
106+
log.Println("sending notification...")
107+
serverPlayers := strconv.Itoa(int(info.Players)) + "/" + strconv.Itoa(int(info.MaxPlayers))
108+
sendFavoriteMapNotification(server.Name, serverPlayers, info.Map)
109+
}
110+
}
111+
time.Sleep(time.Second * 30)
112+
}
113+
114+
}

ss.png

54.5 KB
Loading

0 commit comments

Comments
 (0)