-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
67 lines (58 loc) · 1.9 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/go-logr/zapr"
lobbyserver "github.com/simple64/simple64-netplay-server/internal/lobbyServer"
"go.uber.org/zap"
)
const (
DefaultBasePort = 45000
DefaultMOTDMessage = "Please consider <a href=\"https://www.patreon.com/loganmc10\">subscribing to the Patreon</a> or " +
"<a href=\"https://github.com/sponsors/loganmc10\">supporting this project on GitHub.</a> Your support is needed in order to keep the netplay service online."
)
func newZap(logPath string) (*zap.Logger, error) {
cfg := zap.NewProductionConfig()
cfg.OutputPaths = []string{"stderr"}
if logPath != "" {
cfg.OutputPaths = append(cfg.OutputPaths, logPath)
}
return cfg.Build() //nolint:wrapcheck
}
func main() {
name := flag.String("name", "local-server", "Server name")
basePort := flag.Int("baseport", DefaultBasePort, "Base port")
disableBroadcast := flag.Bool("disable-broadcast", false, "Disable LAN broadcast")
logPath := flag.String("log-path", "", "Write logs to this file")
motd := flag.String("motd", "", "MOTD message to display to clients")
maxGames := flag.Int("max-games", 10, "Maximum number of concurrent games") //nolint:gomnd,mnd
enableAuth := flag.Bool("enable-auth", false, "Enable client authentication")
flag.Parse()
zapLog, err := newZap(*logPath)
if err != nil {
log.Panic(err)
}
logger := zapr.NewLogger(zapLog)
if *name == "" {
logger.Error(fmt.Errorf("name required"), "server name not set")
os.Exit(1)
}
if *motd == "" {
*motd = DefaultMOTDMessage
}
s := lobbyserver.LobbyServer{
Logger: logger,
Name: *name,
BasePort: *basePort,
DisableBroadcast: *disableBroadcast,
Motd: *motd,
MaxGames: *maxGames,
EnableAuth: *enableAuth,
}
go s.LogServerStats()
if err := s.RunSocketServer(DefaultBasePort); err != nil {
logger.Error(err, "could not run socket server")
}
}