// Query retrieves the server information for a given set of host to game pairs // and returns it in a format that is presented to the API. It takes a map consisting // of host(s) and their corresponding game names (i.e: k:127.0.0.1:27960, v:"QuakeLive") func Query(hostsgames map[string]string) (*models.APIServerList, error) { hg := make(map[string]filters.Game, len(hostsgames)) needsPlayers := make([]string, len(hostsgames)) needsRules := make([]string, len(hostsgames)) needsInfo := make([]string, len(hostsgames)) for host, game := range hostsgames { fg := filters.GetGameByName(game) hg[host] = fg if !fg.IgnoreRules { needsRules = append(needsRules, host) } if !fg.IgnorePlayers { needsPlayers = append(needsPlayers, host) } if !fg.IgnoreInfo { needsInfo = append(needsInfo, host) } } data := a2sData{ HostsGames: hg, Info: batchInfoQuery(needsInfo), Rules: batchRuleQuery(needsRules), Players: batchPlayerQuery(needsPlayers), } sl, err := buildServerList(data, true) if err != nil { return models.GetDefaultServerList(), logger.LogAppError(err) } return sl, nil }
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) } }
func configureTimedQueryGame(reader *bufio.Reader) string { valid := false var val string games := strings.Join(filters.GetGameNames(), "\n") prompt := fmt.Sprintf(` Choose the game you would like to automatically retrieve servers for at timed intervals. Possible choices are: %s More games can be added via the %s file. %s`, games, constants.GameFileFullPath, promptColor("> [default: NONE]: ")) input := func(r *bufio.Reader) (string, error) { gameval, rserr := r.ReadString('\n') if rserr != nil { return "", fmt.Errorf("Unable to read respone: %s", rserr) } if gameval == newline { return "", fmt.Errorf("[ERROR] Invalid response. Valid responses:\n%s", games) } response := strings.Trim(gameval, newline) if filters.IsValidGame(response) { // format the capitalization return filters.GetGameByName(response).Name, nil } return "", fmt.Errorf("[ERROR] Invalid response. Valid responses: %s", games) } var err error for !valid { fmt.Print(prompt) val, err = input(reader) if err != nil { errorColor(err) } else { valid = true } } return val }