Fix hardcoded file paths.

This commit is contained in:
A. Svensson 2016-04-22 11:15:18 +02:00
parent 166215a6f4
commit 549c5b3599
3 changed files with 20 additions and 9 deletions

View File

@ -11,6 +11,7 @@ type Instance struct {
// Settings required by the user. // Settings required by the user.
Debug bool Debug bool
DB *DB DB *DB
PrivServersFile string
// Internal stuff // Internal stuff
addr string addr string

View File

@ -7,8 +7,6 @@ import (
var updatedservers []string var updatedservers []string
const SERVERS_CONFIG = "./servers.json" // TODO
type RawServerData struct { type RawServerData struct {
Title string Title string
Game_url string Game_url string
@ -22,7 +20,7 @@ func (i *Instance) UpdateServers() {
tx := i.DB.NewTransaction() tx := i.DB.NewTransaction()
config, err := LoadConfig(SERVERS_CONFIG) config, err := LoadConfig(i.PrivServersFile)
if !log_error(err) { if !log_error(err) {
if i.Debug { if i.Debug {
fmt.Println("\nPolling servers...") fmt.Println("\nPolling servers...")

16
ss13.go
View File

@ -36,6 +36,16 @@ func main() {
Usage: "Time (in minutes) between each update in daemon mode", Usage: "Time (in minutes) between each update in daemon mode",
Value: 15, Value: 15,
}, },
cli.StringFlag{
Name: "private-servers",
Usage: "JSON file with a list of private servers to poll",
Value: "./servers.json",
},
cli.StringFlag{
Name: "database",
Usage: "Database file",
Value: "./ss13.db",
},
} }
app.Commands = []cli.Command{ app.Commands = []cli.Command{
{ {
@ -60,7 +70,8 @@ func run_server(c *cli.Context) {
instance := &ss13.Instance{ instance := &ss13.Instance{
Debug: c.GlobalBool("debug"), Debug: c.GlobalBool("debug"),
DB: ss13.OpenSqliteDB("new.db"), // TODO DB: ss13.OpenSqliteDB(c.GlobalString("database")),
PrivServersFile: c.GlobalString("private-servers"),
} }
instance.Init() instance.Init()
instance.Serve(c.GlobalString("addr")) instance.Serve(c.GlobalString("addr"))
@ -78,7 +89,8 @@ func update_stats(c *cli.Context) {
instance := &ss13.Instance{ instance := &ss13.Instance{
Debug: c.GlobalBool("debug"), Debug: c.GlobalBool("debug"),
DB: ss13.OpenSqliteDB("new.db"), // TODO DB: ss13.OpenSqliteDB(c.GlobalString("database")),
PrivServersFile: c.GlobalString("private-servers"),
} }
instance.Init() instance.Init()