This repository has been archived by the owner on Dec 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
main.go
executable file
·76 lines (62 loc) · 1.95 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"flag"
"log"
"os"
"path/filepath"
"syscall"
"github.com/judwhite/go-svc/svc"
"github.com/pangliang/MirServer-Go/gameserver"
"github.com/pangliang/MirServer-Go/loginserver"
"github.com/pangliang/MirServer-Go/tools"
)
type program struct {
loginServer *loginserver.LoginServer
gameServer *gameserver.GameServer
}
func main() {
prg := &program{}
if err := svc.Run(prg, syscall.SIGINT, syscall.SIGTERM); err != nil {
log.Fatal(err)
}
}
func (p *program) Init(env svc.Environment) error {
if env.IsWindowsService() {
dir := filepath.Dir(os.Args[0])
return os.Chdir(dir)
}
return nil
}
func (p *program) Start() error {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.SetOutput(os.Stdout)
tools.MigrateDevDB()
loginOpt := &loginserver.Option{}
flagSet := flag.NewFlagSet("loginserver", flag.ExitOnError)
flagSet.BoolVar(&loginOpt.IsTest, "test.v", false, "")
flagSet.StringVar(&loginOpt.Address, "login-address", "0.0.0.0:7000", "<addr>:<port> to listen on for TCP clients")
flagSet.StringVar(&loginOpt.DataSourceName, "dbSource", "./mir2.db", "DataSourceName")
flagSet.StringVar(&loginOpt.DriverName, "dbDriver", "sqlite3", "database DriverName")
flagSet.Parse(os.Args[1:])
p.loginServer = loginserver.New(loginOpt)
p.loginServer.Main()
gameOpt := &gameserver.Option{}
flagSet = flag.NewFlagSet("gameserver", flag.ExitOnError)
flagSet.BoolVar(&gameOpt.IsTest, "test.v", false, "")
flagSet.StringVar(&gameOpt.Address, "game-address", "0.0.0.0:7400", "<addr>:<port> to listen on for TCP clients")
flagSet.StringVar(&gameOpt.DataSourceName, "dbSource", "./mir2.db", "DataSourceName")
flagSet.StringVar(&gameOpt.DriverName, "dbDriver", "sqlite3", "database DriverName")
flagSet.Parse(os.Args[1:])
p.gameServer = gameserver.New(gameOpt)
p.gameServer.Main()
return nil
}
func (p *program) Stop() error {
if p.loginServer != nil {
p.loginServer.Exit()
}
if p.gameServer != nil {
p.gameServer.Exit()
}
return nil
}