Пример #1
0
func launch(isDebug bool) {
	if !util.FileExists(constants.GameFileFullPath) {
		filters.DumpDefaultGames()
	}
	if !isDebug {
		if !util.FileExists(constants.ConfigFilePath) {
			fmt.Printf("Could not read configuration file '%s' in the '%s' directory.\n",
				constants.ConfigFilename, constants.ConfigDirectory)
			fmt.Printf("You must generate the configuration file with: %s --%s\n",
				os.Args[0], configFlag)
			os.Exit(1)
		}
	}
	// Initialize the application-wide configuration
	config.InitConfig()
	// Initialize the application-wide database connections (panic on failure)
	db.InitDBs()

	if !runSilent {
		printStartInfo()
	}

	if config.Config.SteamConfig.AutoQueryMaster {
		autoQueryGame := filters.GetGameByName(
			config.Config.SteamConfig.AutoQueryGame)
		if autoQueryGame == filters.GameUnspecified {
			fmt.Println("Invalid game specified for automatic timed query!")
			fmt.Printf(
				"You may need to delete: '%s' and/or recreate the config with: %s --%s",
				constants.GameFileFullPath, os.Args[0], configFlag)
			os.Exit(1)
		}
		// HTTP server + API + Steam auto-querier
		go web.Start(runSilent)
		filter := filters.NewFilter(autoQueryGame, filters.SrAll, nil)
		stop := make(chan bool, 1)
		go steam.StartMasterRetrieval(stop, filter, 7,
			config.Config.SteamConfig.TimeBetweenMasterQueries)
		<-stop
	} else {
		// HTTP server + API standalone
		web.Start(runSilent)
	}
}
Пример #2
0
func verifyLogPaths(lt constants.LogType) error {
	if err := util.CreateDirectory(constants.LogDirectory); err != nil {
		return err
	}
	if !util.FileExists(getLogPath(lt)) {
		if err := util.CreateEmptyFile(getLogPath(lt), false); err != nil {
			return fmt.Errorf("verifyLogPaths error: %s", err)
		}
	}
	return nil
}
Пример #3
0
func createServerDBtable(dbfile string) error {
	create := `CREATE TABLE servers (
	server_id INTEGER NOT NULL,
	host TEXT NOT NULL,
	game TEXT NOT NULL,
	PRIMARY KEY(server_id)
	)`

	if util.FileExists(dbfile) {
		// already exists, so verify integrity
		db, err := sql.Open("sqlite3", dbfile)
		if err != nil {
			return logger.LogAppErrorf(
				"Unable to open server DB file for verification: %s", err)
		}
		defer db.Close()
		var name string
		err = db.QueryRow(
			"SELECT name from sqlite_master where type='table' and name='servers'").Scan(&name)
		switch {
		case err == sql.ErrNoRows:
			if _, err = db.Exec(create); err != nil {
				return logger.LogAppErrorf("Unable to create servers table in DB: %s", err)
			}
		case err != nil:
			return logger.LogAppErrorf("Server DB table verification error: %s", err)
		}
		return nil
	}

	err := util.CreateEmptyFile(dbfile, true)
	if err != nil {
		return logger.LogAppErrorf("Unable to create server DB: %s", err)
	}

	db, err := sql.Open("sqlite3", dbfile)
	if err != nil {
		return logger.LogAppErrorf(
			"Unable to open server DB file for table creation: %s", err)
	}
	defer db.Close()
	_, err = db.Exec(create)
	if err != nil {
		return logger.LogAppErrorf("Unable to create servers table in servers DB: %s",
			err)
	}
	return nil
}
Пример #4
0
func main() {
	flag.Parse()

	if doConfig {
		if !util.FileExists(constants.GameFileFullPath) {
			filters.DumpDefaultGames()
		}
		config.CreateConfig()
		os.Exit(0)
	}

	if useDebugConfig {
		config.CreateDebugConfig()
		constants.IsDebug = true
		launch(true)
	} else {
		launch(false)
	}
}