package main

import (
	"log/slog"
	"os"
	"slgserver/config"
	"slgserver/net"
	"slgserver/server/gateserver"
	"slgserver/server/gateserver/controller"
)

func getGateServerAddr() string {
	host := config.GetString("gateserver.host", "")
	port := config.GetString("gateserver.port", "8004")
	return host + ":" + port
}

func main() {
	if wd, err := os.Getwd(); err == nil {
		slog.Info("working directory", "dir", wd)
	} else {
		slog.Warn("get working directory failed", "error", err)
	}
	gateserver.Init()
	needSecret := config.GetBool("gateserver.need_secret", false)
	s := net.NewServer(getGateServerAddr(), needSecret)
	s.Router(gateserver.MyRouter)
	s.SetOnBeforeClose(controller.GHandle.OnServerConnClose)
	s.Start()
}
