-
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.
- Loading branch information
Showing
10 changed files
with
469 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.22" | ||
- run: go install mvdan.cc/garble@latest | ||
- run: garble -tiny build wowPing.go | ||
- run: ./wowPing |
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 @@ | ||
# wow-server-ping-go | ||
|
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,3 @@ | ||
module github.com/egoroof/wow-server-ping-go | ||
|
||
go 1.22.1 |
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,64 @@ | ||
package ping | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
const REQUEST_COUNT = 4 | ||
const TIMEOUT = 1000 | ||
const SERVER_GROUP = "x1" | ||
|
||
type Params struct { | ||
RequestCount int | ||
Timeout int | ||
ServerGroup string | ||
} | ||
|
||
func parseIntOrDefault(value string, def int) int { | ||
i, err := strconv.Atoi(value) | ||
if err != nil { | ||
return def | ||
} | ||
|
||
return i | ||
} | ||
|
||
// hard coded | ||
func ParseArguments(args []string) Params { | ||
params := Params{ | ||
RequestCount: REQUEST_COUNT, | ||
Timeout: TIMEOUT, | ||
ServerGroup: SERVER_GROUP, | ||
} | ||
for _, arg := range args { | ||
// -n=1 -t=100 -s=Fun | ||
parts := strings.Split(arg, "=") | ||
if len(parts) != 2 || len(parts[0]) < 2 { | ||
continue | ||
} | ||
|
||
param := parts[0][1:] // -n -> n | ||
value := parts[1] | ||
|
||
if param == "n" { | ||
params.RequestCount = parseIntOrDefault(value, REQUEST_COUNT) | ||
} | ||
|
||
if param == "t" { | ||
params.Timeout = parseIntOrDefault(value, TIMEOUT) | ||
} | ||
|
||
if param == "s" { | ||
for _, group := range Servers { | ||
if group.Name == value { | ||
params.ServerGroup = value | ||
break | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
return params | ||
} |
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,37 @@ | ||
package ping | ||
|
||
import ( | ||
"math" | ||
) | ||
|
||
func Avg(values []int) int { | ||
if len(values) == 0 { | ||
return 0 | ||
} | ||
|
||
sum := 0 | ||
for _, elem := range values { | ||
sum += elem | ||
} | ||
|
||
return sum / len(values) | ||
} | ||
|
||
func Jitter(values []int) int { | ||
if len(values) == 0 { | ||
return 0 | ||
} | ||
|
||
min := math.MaxInt | ||
max := 0 | ||
for _, value := range values { | ||
if min > value { | ||
min = value | ||
} | ||
if max < value { | ||
max = value | ||
} | ||
} | ||
|
||
return (max - min) / 2 | ||
} |
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,52 @@ | ||
package ping | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"fmt" | ||
"io" | ||
"net" | ||
"time" | ||
) | ||
|
||
type result struct { | ||
Status string | ||
ResponseDuration time.Duration | ||
} | ||
|
||
func OpenConnection(host string, port, timeout int) (result, error) { | ||
address := fmt.Sprintf("%v:%v", host, port) | ||
conn, err := net.DialTimeout("tcp", address, time.Millisecond*time.Duration(timeout)) | ||
connectTime := time.Now() | ||
if err != nil { | ||
return result{}, err | ||
} | ||
defer conn.Close() | ||
|
||
buf := make([]byte, 4) | ||
conn.SetDeadline(connectTime.Add(time.Millisecond * time.Duration(timeout))) | ||
_, err = conn.Read(buf) | ||
responseTime := time.Now() | ||
if err != nil && err != io.EOF { | ||
return result{}, err | ||
} | ||
|
||
var opcode uint16 | ||
reader := bytes.NewReader(buf[2:4]) | ||
err = binary.Read(reader, binary.LittleEndian, &opcode) | ||
if err != nil { | ||
return result{}, err | ||
} | ||
|
||
responseDuration := responseTime.Sub(connectTime).Round(time.Millisecond) | ||
|
||
status := "fail" | ||
if opcode == SMSG_AUTH_CHALLENGE { | ||
status = "success" | ||
} | ||
|
||
return result{ | ||
Status: status, | ||
ResponseDuration: responseDuration, | ||
}, nil | ||
} |
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,4 @@ | ||
package ping | ||
|
||
// https://wowdev.wiki/Opcodes | ||
const SMSG_AUTH_CHALLENGE = 0x1ec |
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,165 @@ | ||
package ping | ||
|
||
type server struct { | ||
Name string | ||
Host string | ||
Port int | ||
} | ||
|
||
type serverGroup struct { | ||
Name string | ||
List []server | ||
} | ||
|
||
var Servers = []serverGroup{ | ||
{ | ||
Name: "local", | ||
List: []server{ | ||
{ | ||
Name: "local", | ||
Host: "127.0.0.1", | ||
Port: 8085, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "x1", | ||
List: []server{ | ||
{ | ||
Name: "WoW Circle 3.3.5a x1", | ||
Host: "212.41.28.25", | ||
Port: 11294, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x1 [DE]", | ||
Host: "194.247.187.187", | ||
Port: 11294, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x1 [FIN]", | ||
Host: "193.84.2.209", | ||
Port: 11294, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x1 [NL]", | ||
Host: "31.207.45.133", | ||
Port: 11294, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x1 [MSK]", | ||
Host: "45.138.163.171", | ||
Port: 11294, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x1 [NSK]", | ||
Host: "79.141.77.15", | ||
Port: 11294, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "x5", | ||
List: []server{ | ||
{ | ||
Name: "WoW Circle 3.3.5a x5", | ||
Host: "212.41.28.25", | ||
Port: 10540, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x5 [DE]", | ||
Host: "194.247.187.187", | ||
Port: 10540, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x5 [FIN]", | ||
Host: "193.84.2.209", | ||
Port: 10540, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x5 [NL]", | ||
Host: "31.207.45.133", | ||
Port: 10540, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x5 [MSK]", | ||
Host: "45.138.163.171", | ||
Port: 10540, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x5 [NSK]", | ||
Host: "79.141.77.15", | ||
Port: 10540, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "x100", | ||
List: []server{ | ||
{ | ||
Name: "WoW Circle 3.3.5a x100", | ||
Host: "212.41.28.25", | ||
Port: 12742, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x100 [DE]", | ||
Host: "194.247.187.187", | ||
Port: 12742, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x100 [FIN]", | ||
Host: "193.84.2.209", | ||
Port: 12742, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x100 [NL]", | ||
Host: "31.207.45.133", | ||
Port: 12742, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x100 [MSK]", | ||
Host: "45.138.163.171", | ||
Port: 12742, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a x100 [NSK]", | ||
Host: "79.141.77.15", | ||
Port: 12742, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "Fun", | ||
List: []server{ | ||
{ | ||
Name: "WoW Circle 3.3.5a Fun", | ||
Host: "87.228.3.124", | ||
Port: 12373, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a Fun [DE]", | ||
Host: "194.247.187.187", | ||
Port: 12373, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a Fun [FIN]", | ||
Host: "193.84.2.209", | ||
Port: 12373, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a Fun [NL]", | ||
Host: "31.207.45.133", | ||
Port: 12373, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a Fun [MSK]", | ||
Host: "45.138.163.171", | ||
Port: 12373, | ||
}, | ||
{ | ||
Name: "WoW Circle 3.3.5a Fun [NSK]", | ||
Host: "79.141.77.15", | ||
Port: 12373, | ||
}, | ||
}, | ||
}, | ||
} |
Oops, something went wrong.