-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
62 lines (51 loc) · 1.2 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"log"
"nano-game-server/internal"
"net/http"
"os"
"strings"
"github.com/lonng/nano"
"github.com/lonng/nano/component"
"github.com/lonng/nano/serialize/json"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "Rolling Dice"
app.Author = "nano authors"
app.Version = "0.0.1"
app.Copyright = "nano authors reserved"
app.Usage = "rolling dice"
// flags
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "addr",
Value: ":3252",
Usage: "game server address",
},
}
app.Action = serve
app.Run(os.Args)
}
func serve(ctx *cli.Context) error {
components := &component.Components{}
components.Register(internal.NewDiceManager(),
component.WithName("dice"),
component.WithNameFunc(strings.ToLower),
)
// components.Register(logic.NewWorld())
// register all service
options := []nano.Option{
nano.WithIsWebsocket(true),
nano.WithWSPath("game"),
nano.WithComponents(components),
nano.WithSerializer(json.NewSerializer()),
nano.WithCheckOriginFunc(func(_ *http.Request) bool { return true }),
}
//nano.EnableDebug()
log.SetFlags(log.LstdFlags | log.Llongfile)
addr := ctx.String("addr")
nano.Listen(addr, options...)
return nil
}