-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
39 lines (31 loc) · 834 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/teeworlds-go/protocol/messages7"
"github.com/teeworlds-go/protocol/network7"
"github.com/teeworlds-go/protocol/teeworlds7"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
client := teeworlds7.NewClient()
client.OnChat(func(msg *messages7.SvChat, _ teeworlds7.DefaultAction) error {
if msg.Mode != network7.ChatAll || msg.ClientId < 0 {
// ignore if not from users and not in public chat
return nil
}
// echo user messages
return client.SendChat(msg.Message)
})
err := client.ConnectContext(ctx, "127.0.0.1", 8303)
if err != nil && !errors.Is(err, context.Canceled) {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("graceful shutdown")
}