Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jxsl13 committed May 22, 2024
1 parent 5a1fcd4 commit eaa773d
Showing 1 changed file with 21 additions and 35 deletions.
56 changes: 21 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,22 @@ import (
func main() {
// fetch all server infos (that respond within 16 seconds)
// if no servers responded, this list will be empty.
infos := browser.ServerInfos()
infos, err := browser.ServerInfos()
if err != nil {
panic(err)
}
for _, info := range infos {
fmt.Println(info)
}

// fetches the specified server's players, server name, etc.
// if no answer is received within 16 seconds, this function returns
// an error
info, err := browser.GetServerInfo("89.163.148.121", 8305)
infos, err := browser.GetServerInfosOf("89.163.148.121:8305")
if err != nil {
fmt.Println(err)
panic(err)
} else {
fmt.Println(info)
fmt.Println(infos[0])
}
}
```
Expand All @@ -76,22 +79,18 @@ import (
func main() {
addr, err := net.ResolveUDPAddr("udp", "master1.teeworlds.com:8283")
if err != nil {
fmt.Println(err)
return
panic(err)
}

conn, err := net.DialUDP("udp", nil, addr)

if err != nil {
fmt.Println(err)
return
panic(err)
}
defer conn.Close()

err = browser.RequestToken(conn)
if err != nil {
fmt.Println(err)
return
panic(err)
}

conn.SetDeadline(time.Now().Add(5 * time.Second))
Expand All @@ -101,25 +100,22 @@ func main() {

read, err := conn.Read(bufSlice)
if err != nil {
fmt.Println(err)
return
panic(err)
}
bufSlice = bufSlice[:read]
fmt.Printf("read: %d bytes from %s\n", read, conn.RemoteAddr().String())

// create toke from response
token, err := browser.ParseToken(bufSlice)
if err != nil {
fmt.Println(err)
return
panic(err)
}
// reset slice
bufSlice = bufSlice[:1500]

err = browser.Request("serverlist", token, conn)
if err != nil {
fmt.Println(err)
return
panic(err)
}

// timeout after 5 secods
Expand All @@ -133,14 +129,12 @@ func main() {

serverList, err := browser.ParseServerList(bufSlice)
if err != nil {
fmt.Println(err)
return
panic(err)
}

for _, server := range serverList {
fmt.Printf("Server: %s\n", server.String())
}

}

```
Expand All @@ -161,15 +155,12 @@ import (
func main() {
addr, err := net.ResolveUDPAddr("udp", "master1.teeworlds.com:8283")
if err != nil {
fmt.Println(err)
return
panic(err)
}

conn, err := net.DialUDP("udp", nil, addr)

if err != nil {
fmt.Println(err)
return
panic(err)
}
defer conn.Close()

Expand All @@ -179,8 +170,7 @@ func main() {
// send request
written, err := conn.Write(tokenReq)
if err != nil {
fmt.Println(err)
return
panic(err)
}
fmt.Printf("written: %d bytes to %s\n", written, conn.RemoteAddr().String())

Expand All @@ -191,17 +181,15 @@ func main() {

read, err := conn.Read(bufSlice)
if err != nil {
fmt.Println(err)
return
panic(err)
}
bufSlice = bufSlice[:read]
fmt.Printf("read: %d bytes from %s\n", read, conn.RemoteAddr().String())

// create toke from response
token, err := browser.ParseToken(bufSlice)
if err != nil {
fmt.Println(err)
return
panic(err)
}
// reset slice
bufSlice = bufSlice[:1500]
Expand All @@ -212,8 +200,7 @@ func main() {
// Send server list request
written, err = conn.Write(serverListReq)
if err != nil {
fmt.Println(err)
return
panic(err)
}
fmt.Printf("written: %d bytes to %s\n", written, conn.RemoteAddr().String())

Expand All @@ -228,8 +215,7 @@ func main() {

serverList, err := browser.ParseServerList(bufSlice)
if err != nil {
fmt.Println(err)
return
panic(err)
}

for _, server := range serverList {
Expand Down

0 comments on commit eaa773d

Please sign in to comment.