Esempio n. 1
0
// CreateDebugConfig creates the configuration file that is used when running the
// applciation in debug mode.
func CreateDebugConfig() {
	cfg := &Cfg{}
	cfg.LogConfig.EnableAppLogging = true
	cfg.LogConfig.EnableSteamLogging = false // even in debug mode; disable
	cfg.LogConfig.EnableWebLogging = true
	cfg.LogConfig.MaximumLogCount = defaultMaxLogCount
	cfg.LogConfig.MaximumLogSize = defaultMaxLogSize
	cfg.SteamConfig.AutoQueryMaster = false
	cfg.SteamConfig.SteamWebAPIKey = "none"
	cfg.SteamConfig.UseWebServerList = defaultUseWebServerList
	cfg.SteamConfig.AutoQueryGame = "QuakeLive"
	cfg.SteamConfig.TimeBetweenMasterQueries = defaultTimeBetweenMasterQueries
	cfg.SteamConfig.MaximumHostsToReceive = defaultMaxHostsToReceive
	cfg.WebConfig.AllowDirectUserQueries = true
	cfg.WebConfig.APIWebPort = defaultAPIWebPort
	cfg.WebConfig.APIWebTimeout = defaultAPIWebTimeout
	cfg.WebConfig.CompressResponses = defaultCompressResponses
	cfg.WebConfig.MaximumHostsPerAPIQuery = defaultMaxHostsPerAPIQuery
	cfg.DebugConfig.EnableDebugMessages = true
	cfg.DebugConfig.EnableServerDump = true
	cfg.DebugConfig.ServerDumpFileAsMasterList = true
	cfg.DebugConfig.ServerDumpFilename = defaultServerDumpFile
	if err := util.WriteJSONConfig(cfg, constants.ConfigDirectory,
		constants.DebugConfigFilePath); err != nil {
		panic(err)
	}
	// Set the configuration which will live throughout the application's lifetime
	Config = cfg
}
Esempio n. 2
0
// CreateTestConfig creates the configuration that is used when running automated
// testing.
func CreateTestConfig() {
	// boolean values intentionally default to false and are omitted unless
	// otherwise specified, which is different from the normal configuration
	cfg := &Cfg{}
	cfg.LogConfig.MaximumLogCount = defaultMaxLogCount
	cfg.LogConfig.MaximumLogSize = defaultMaxLogSize
	cfg.SteamConfig.AutoQueryGame = "QuakeLive"
	cfg.SteamConfig.TimeBetweenMasterQueries = defaultTimeBetweenMasterQueries
	cfg.SteamConfig.MaximumHostsToReceive = defaultMaxHostsToReceive
	cfg.WebConfig.AllowDirectUserQueries = true
	cfg.WebConfig.APIWebPort = 40081
	cfg.WebConfig.APIWebTimeout = defaultAPIWebTimeout
	cfg.WebConfig.CompressResponses = defaultCompressResponses
	cfg.WebConfig.MaximumHostsPerAPIQuery = defaultMaxHostsPerAPIQuery
	cfg.DebugConfig.ServerDumpFileAsMasterList = true
	cfg.DebugConfig.ServerDumpFilename = "test-api-servers.json"
	if err := util.WriteJSONConfig(cfg, constants.TestTempDirectory,
		constants.TestConfigFilePath); err != nil {
		panic(err)
	}
	// Set the configuration which will live throughout the application's lifetime
	Config = cfg
}
Esempio n. 3
0
// DumpDefaultGames writes the default struct containing the default games to disk
// on success, otherwise panics.
func DumpDefaultGames() {
	if err := util.WriteJSONConfig(defaultGames, constants.ConfigDirectory,
		constants.GameFileFullPath); err != nil {
		panic(err)
	}
}
Esempio n. 4
0
// CreateConfig initiates the configuration creation process by collecting user
// input for various configuration values and then writes the configuration file
// to disk if successful, otherwise panics.
func CreateConfig() {
	reader := bufio.NewReader(os.Stdin)
	cfg := &Cfg{
		LogConfig:   CfgLog{},
		SteamConfig: CfgSteam{},
		WebConfig:   CfgWeb{},
		DebugConfig: CfgDebug{},
	}
	color.Set(color.FgHiYellow)
	fmt.Printf(`
%s - configuration file creation
Type a value and press 'ENTER'. Leave a value empty and press 'ENTER' to use the
default value.

`, constants.AppInfo)
	color.Unset()

	// Logging configuration
	// Determine if application, Steam, and/or web API logging should be enabled
	cfg.LogConfig.EnableAppLogging = configureLoggingEnable(reader, constants.LTypeApp)
	cfg.LogConfig.EnableSteamLogging = configureLoggingEnable(reader, constants.LTypeSteam)
	cfg.LogConfig.EnableWebLogging = configureLoggingEnable(reader, constants.LTypeWeb)
	// Configure max log size and max log count if logging is enabled
	if cfg.LogConfig.EnableAppLogging || cfg.LogConfig.EnableSteamLogging ||
		cfg.LogConfig.EnableWebLogging {
		cfg.LogConfig.MaximumLogSize = configureMaxLogSize(reader)
		cfg.LogConfig.MaximumLogCount = configureMaxLogCount(reader)
	} else {
		cfg.LogConfig.MaximumLogSize = defaultMaxLogSize
		cfg.LogConfig.MaximumLogCount = defaultMaxLogCount
	}

	// Steam configuration
	// Query the master server automatically at timed intervals
	cfg.SteamConfig.AutoQueryMaster = configureTimedMasterQuery(reader)
	if cfg.SteamConfig.AutoQueryMaster {
		// The Steam WebAPI key to use to get the web server list
		cfg.SteamConfig.SteamWebAPIKey = configureSteamWebAPIKey(reader)
		// Use the Steam Web Server list since master server was shut down in November 2016
		cfg.SteamConfig.UseWebServerList = defaultUseWebServerList
		// The game to automatically query the master server for at timed intervals
		cfg.SteamConfig.AutoQueryGame = configureTimedQueryGame(reader)
		// Time between Steam Master server queries
		cfg.SteamConfig.TimeBetweenMasterQueries = configureTimeBetweenQueries(reader,
			cfg.SteamConfig.AutoQueryGame)
		// Maximum # of servers to retrieve from Steam Master server
		cfg.SteamConfig.MaximumHostsToReceive = configureMaxServersToRetrieve(reader)
	} else {
		cfg.SteamConfig.AutoQueryGame = filters.GameQuakeLive.Name
		cfg.SteamConfig.TimeBetweenMasterQueries = defaultTimeBetweenMasterQueries
		cfg.SteamConfig.MaximumHostsToReceive = defaultMaxHostsToReceive
	}

	// Web API configuration
	// Direct queries: whether users can query any host (not just those with IDs)
	cfg.WebConfig.AllowDirectUserQueries = configureDirectQueries(reader,
		cfg.SteamConfig.AutoQueryMaster)
	// Maximum number of servers to allow users to query via API
	cfg.WebConfig.MaximumHostsPerAPIQuery = configureMaxHostsPerAPIQuery(reader)
	// Time in seconds before HTTP requests time out
	cfg.WebConfig.APIWebTimeout = configureWebTimeout(reader)
	// Port that API's web server will listen on
	cfg.WebConfig.APIWebPort = configureWebServerPort(reader)
	// Enable or disable gzip compression of responses
	cfg.WebConfig.CompressResponses = configureResponseCompression(reader)

	// Debug configuration (not user-selectable. for debug/development purposes)
	// Print a few "debug" messages to stdout
	cfg.DebugConfig.EnableDebugMessages = defaultEnableDebugMessages
	// Dump the retrieved server information to a JSON file on disk
	cfg.DebugConfig.EnableServerDump = defaultEnableServerDump
	// Use a pre-defined JSON file as disk as the master server list for the API
	cfg.DebugConfig.ServerDumpFileAsMasterList = defaultServerDumpFileAsMasterList
	// Name of the pre-defined JSON file to use as the master server list for API
	cfg.DebugConfig.ServerDumpFilename = defaultServerDumpFile

	if err := util.WriteJSONConfig(cfg, constants.ConfigDirectory,
		constants.ConfigFilePath); err != nil {
		panic(err)
	}
}