forked from HFO4/gameboy.live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-cli.go
95 lines (82 loc) · 1.9 KB
/
main-cli.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"bufio"
"encoding/json"
"flag"
"log"
"os"
"github.com/HFO4/gbc-in-cloud/static"
"github.com/HFO4/gbc-in-cloud/stream"
)
var (
h bool
GUIMode bool
FyneMode bool
StreamServerMode bool
StaticServerMode bool
ConfigPath string
ListenPort int
ROMPath string
SoundOn bool
FPS int
Debug bool
)
func init() {
flag.BoolVar(&h, "h", false, "This help")
flag.BoolVar(&StreamServerMode, "s", false, "Start a cloud-gaming server")
flag.BoolVar(&StaticServerMode, "S", false, "Start a static image cloud-gaming server")
flag.BoolVar(&Debug, "d", false, "Use Debugger in GUI mode")
flag.IntVar(&ListenPort, "p", 1989, "Set the `port` for the cloud-gaming server")
flag.StringVar(&ConfigPath, "c", "", "Set the game option list `config` file path")
flag.StringVar(&ROMPath, "r", "", "Set `ROM` file path")
}
func runStaticServer() {
server := static.StaticServer{
Port: ListenPort,
GamePath: ROMPath,
}
server.Run()
}
func runServer() {
if ConfigPath == "" {
log.Fatal("[Error] Game list not specified")
}
// Read config file
configFile, err := os.Open(ConfigPath)
defer configFile.Close()
if err != nil {
log.Fatal("[Error] Failed to read game list config file,", err)
}
stats, statsErr := configFile.Stat()
if statsErr != nil {
log.Fatal(statsErr)
}
var size = stats.Size()
gameListStr := make([]byte, size)
bufReader := bufio.NewReader(configFile)
_, err = bufReader.Read(gameListStr)
streamServer := new(stream.StreamServer)
streamServer.Port = ListenPort
var gameList []stream.GameInfo
err = json.Unmarshal(gameListStr, &gameList)
if err != nil {
log.Fatal("Unable to decode game list config file.")
}
streamServer.GameList = gameList
streamServer.Run()
}
func main() {
flag.Parse()
if h {
flag.Usage()
return
}
if StreamServerMode {
runServer()
return
}
if StaticServerMode {
runStaticServer()
return
}
}