rogueserver/pokerogue-server.go

55 lines
1.3 KiB
Go
Raw Normal View History

2023-12-05 10:28:08 -08:00
package main
import (
"flag"
"log"
"net"
"net/http"
2023-12-28 17:01:55 -08:00
"os"
2023-12-05 10:28:08 -08:00
"github.com/Flashfyre/pokerogue-server/api"
"github.com/Flashfyre/pokerogue-server/db"
)
func main() {
2023-12-29 11:30:47 -08:00
debug := flag.Bool("debug", false, "debug mode")
2023-12-28 19:08:50 -08:00
proto := flag.String("proto", "tcp", "protocol for api to use (tcp, unix)")
2023-12-28 19:16:47 -08:00
addr := flag.String("addr", "0.0.0.0", "network address for api to listen on")
2023-12-05 10:28:08 -08:00
dbuser := flag.String("dbuser", "pokerogue", "database username")
dbpass := flag.String("dbpass", "", "database password")
dbproto := flag.String("dbproto", "tcp", "protocol for database connection")
2023-12-28 19:18:57 -08:00
dbaddr := flag.String("dbaddr", "localhost", "database address")
2023-12-28 17:08:58 -08:00
dbname := flag.String("dbname", "pokeroguedb", "database name")
2023-12-05 10:28:08 -08:00
flag.Parse()
err := db.Init(*dbuser, *dbpass, *dbproto, *dbaddr, *dbname)
if err != nil {
log.Fatalf("failed to initialize database: %s", err)
}
2023-12-28 19:08:50 -08:00
if *proto == "unix" {
2023-12-28 19:11:16 -08:00
os.Remove(*addr)
2023-12-28 17:01:55 -08:00
}
2023-12-28 19:11:16 -08:00
listener, err := net.Listen(*proto, *addr)
2023-12-05 10:28:08 -08:00
if err != nil {
log.Fatalf("failed to create net listener: %s", err)
}
2023-12-28 19:08:50 -08:00
if *proto == "unix" {
2023-12-28 19:11:16 -08:00
os.Chmod(*addr, 0777)
2023-12-28 17:06:06 -08:00
}
2024-04-06 15:15:47 -07:00
api.ScheduleStatRefresh()
2024-03-16 18:51:13 -07:00
api.ScheduleDailyRunRefresh()
api.InitDailyRun()
2023-12-29 11:30:47 -08:00
err = http.Serve(listener, &api.Server{Debug: *debug})
2023-12-05 10:28:08 -08:00
if err != nil {
log.Fatalf("failed to create http server or server errored: %s", err)
}
}