steamclient

package
v0.0.0-...-e6a6dc6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Achievements

type Achievements struct {
	Name     string `json:"name"`
	Achieved int    `json:"achieved"`
}

Achievements is the nested struct to hold the "archivements" array returned by the steam API endopint GetUserStatsForGame

type Calculations

type Calculations struct {
	PercentWin      string
	PercentAccuracy string
	PercentHeadshot string
}

Calculations holds additional values to be shown in the templates, that are calculated on-the-fly

type GameArchievements

type GameArchievements struct {
}

GameArchievements holds the players archievement data from the steam API endpoint UserStatsForGame

type GameExtras

type GameExtras struct {

	// SteamID of the player
	SteamID uint64

	// Total KD ratio
	TotalKD string

	// KD ratio of the last match
	LastMatchKD string

	// Total hit ratio
	HitRatio string

	// Total played hours
	PlayedHours string

	// Total Average damage per round
	TotalADR string

	// Last match average damage per round
	LastMatchADR string
}

GameExtras holds data in the same way as the other nested structs. This data is not fetched from an endpoint but calculated based on other values locally

type GameStats

type GameStats struct {
	SteamID                                   uint64
	GILessonCsgoInstrExplainInspect           int
	GILessonBombSitesA                        int
	GILessonBombSitesB                        int
	GILessonCsgoCycleWeaponsKb                int
	GILessonCsgoHostageLeadToHrz              int
	GILessonCsgoInstrExplainBombCarrier       int
	GILessonCsgoInstrExplainBuyarmor          int
	GILessonCsgoInstrExplainBuymenu           int
	GILessonCsgoInstrExplainFollowBomber      int
	GILessonCsgoInstrExplainPickupBomb        int
	GILessonCsgoInstrExplainPlantBomb         int
	GILessonCsgoInstrExplainPreventBombPickup int
	GILessonCsgoInstrExplainReload            int
	GILessonCsgoInstrExplainZoom              int
	GILessonCsgoInstrRescueZone               int
	GILessonDefusePlantedBomb                 int
	GILessonFindPlantedBomb                   int
	GILessonTrExplainPlantBomb                int
	GILessonVersionNumber                     int
	LastMatchContributionScore                int
	LastMatchCtWins                           int
	LastMatchDamage                           int
	LastMatchDeaths                           int
	LastMatchDominations                      int
	LastMatchFavweaponHits                    int
	LastMatchFavweaponID                      int
	LastMatchFavweaponKills                   int
	LastMatchFavweaponShots                   int
	LastMatchGgContributionScore              int
	LastMatchKills                            int
	LastMatchMaxPlayers                       int
	LastMatchMoneySpent                       int
	LastMatchMvps                             int
	LastMatchRevenges                         int
	LastMatchRounds                           int
	LastMatchTWins                            int
	LastMatchWins                             int
	SteamStatMatchwinscomp                    int
	SteamStatSurvivedz                        int
	SteamStatXpearnedgames                    int
	TotalBrokenWindows                        int
	TotalContributionScore                    int
	TotalDamageDone                           int
	TotalDeaths                               int
	TotalDefusedBombs                         int
	TotalDominationOverkills                  int
	TotalDominations                          int
	TotalGgMatchesPlayed                      int
	TotalGgMatchesWon                         int
	TotalGunGameContributionScore             int
	TotalGunGameRoundsPlayed                  int
	TotalGunGameRoundsWon                     int
	TotalHitsAk47                             int
	TotalHitsAug                              int
	TotalHitsAwp                              int
	TotalHitsBizon                            int
	TotalHitsDeagle                           int
	TotalHitsElite                            int
	TotalHitsFamas                            int
	TotalHitsFiveseven                        int
	TotalHitsG3sg1                            int
	TotalHitsGalilar                          int
	TotalHitsGlock                            int
	TotalHitsHkp2000                          int
	TotalHitsM249                             int
	TotalHitsM4a1                             int
	TotalHitsMac10                            int
	TotalHitsMag7                             int
	TotalHitsMp7                              int
	TotalHitsMp9                              int
	TotalHitsNegev                            int
	TotalHitsNova                             int
	TotalHitsP250                             int
	TotalHitsP90                              int
	TotalHitsSawedoff                         int
	TotalHitsScar20                           int
	TotalHitsSg556                            int
	TotalHitsSsg08                            int
	TotalHitsTec9                             int
	TotalHitsUmp45                            int
	TotalHitsXm1014                           int
	TotalKills                                int
	TotalKillsAgainstZoomedSniper             int
	TotalKillsAk47                            int
	TotalKillsAug                             int
	TotalKillsAwp                             int
	TotalKillsBizon                           int
	TotalKillsDeagle                          int
	TotalKillsElite                           int
	TotalKillsEnemyBlinded                    int
	TotalKillsEnemyWeapon                     int
	TotalKillsFamas                           int
	TotalKillsFiveseven                       int
	TotalKillsG3sg1                           int
	TotalKillsGalilar                         int
	TotalKillsGlock                           int
	TotalKillsHeadshot                        int
	TotalKillsHegrenade                       int
	TotalKillsHkp2000                         int
	TotalKillsKnife                           int
	TotalKillsKnifeFight                      int
	TotalKillsM249                            int
	TotalKillsM4a1                            int
	TotalKillsMac10                           int
	TotalKillsMag7                            int
	TotalKillsMolotov                         int
	TotalKillsMp7                             int
	TotalKillsMp9                             int
	TotalKillsNegev                           int
	TotalKillsNova                            int
	TotalKillsP250                            int
	TotalKillsP90                             int
	TotalKillsSawedoff                        int
	TotalKillsScar20                          int
	TotalKillsSg556                           int
	TotalKillsSsg08                           int
	TotalKillsTaser                           int
	TotalKillsTec9                            int
	TotalKillsUmp45                           int
	TotalKillsXm1014                          int
	TotalMatchesPlayed                        int
	TotalMatchesWon                           int
	TotalMatchesWonBaggage                    int
	TotalMatchesWonBank                       int
	TotalMatchesWonLake                       int
	TotalMatchesWonSafehouse                  int
	TotalMatchesWonShoots                     int
	TotalMatchesWonStmarc                     int
	TotalMatchesWonSugarcane                  int
	TotalMatchesWonTrain                      int
	TotalMoneyEarned                          int
	TotalMvps                                 int
	TotalPlantedBombs                         int
	TotalProgressiveMatchesWon                int
	TotalRescuedHostages                      int
	TotalRevenges                             int
	TotalRoundsMapArBaggage                   int
	TotalRoundsMapArMonastery                 int
	TotalRoundsMapArShoots                    int
	TotalRoundsMapCsAssault                   int
	TotalRoundsMapCsItaly                     int
	TotalRoundsMapCsMilitia                   int
	TotalRoundsMapCsOffice                    int
	TotalRoundsMapDeAztec                     int
	TotalRoundsMapDeBank                      int
	TotalRoundsMapDeCbble                     int
	TotalRoundsMapDeDust                      int
	TotalRoundsMapDeDust2                     int
	TotalRoundsMapDeInferno                   int
	TotalRoundsMapDeLake                      int
	TotalRoundsMapDeNuke                      int
	TotalRoundsMapDeSafehouse                 int
	TotalRoundsMapDeHouse                     int
	TotalRoundsMapDeShorttrain                int
	TotalRoundsMapDeStmarc                    int
	TotalRoundsMapDeSugarcane                 int
	TotalRoundsMapDeTrain                     int
	TotalRoundsMapDeVertigo                   int
	TotalRoundsPlayed                         int
	TotalShotsAk47                            int
	TotalShotsAug                             int
	TotalShotsAwp                             int
	TotalShotsBizon                           int
	TotalShotsDeagle                          int
	TotalShotsElite                           int
	TotalShotsFamas                           int
	TotalShotsFired                           int
	TotalShotsFiveseven                       int
	TotalShotsG3sg1                           int
	TotalShotsGalilar                         int
	TotalShotsGlock                           int
	TotalShotsHit                             int
	TotalShotsHkp2000                         int
	TotalShotsM249                            int
	TotalShotsM4a1                            int
	TotalShotsMac10                           int
	TotalShotsMag7                            int
	TotalShotsMp7                             int
	TotalShotsMp9                             int
	TotalShotsNegev                           int
	TotalShotsNova                            int
	TotalShotsP250                            int
	TotalShotsP90                             int
	TotalShotsSawedoff                        int
	TotalShotsScar20                          int
	TotalShotsSg556                           int
	TotalShotsSsg08                           int
	TotalShotsTaser                           int
	TotalShotsTec9                            int
	TotalShotsUmp45                           int
	TotalShotsXm1014                          int
	TotalTRDefusedBombs                       int
	TotalTRPlantedBombs                       int
	TotalTimePlayed                           int
	TotalTrbombMatchesWon                     int
	TotalWeaponsDonated                       int
	TotalWins                                 int
	TotalWinsMapArBaggage                     int
	TotalWinsMapArMonastery                   int
	TotalWinsMapArShoots                      int
	TotalWinsMapCsAssault                     int
	TotalWinsMapCsItaly                       int
	TotalWinsMapCsMilitia                     int
	TotalWinsMapCsOffice                      int
	TotalWinsMapDeAztec                       int
	TotalWinsMapDeBank                        int
	TotalWinsMapDeCbble                       int
	TotalWinsMapDeDust                        int
	TotalWinsMapDeDust2                       int
	TotalWinsMapDeHouse                       int
	TotalWinsMapDeInferno                     int
	TotalWinsMapDeLake                        int
	TotalWinsMapDeNuke                        int
	TotalWinsMapDeSafehouse                   int
	TotalWinsMapDeShorttrain                  int
	TotalWinsMapDeStmarc                      int
	TotalWinsMapDeSugarcane                   int
	TotalWinsMapDeTrain                       int
	TotalWinsMapDeVertigo                     int
	TotalWinsPistolround                      int
}

GameStats holds the players stats data from the steam API endpoint UserStatsForGame

func (GameStats) MapStats

func (gs GameStats) MapStats() []Mapstat

MapStats returns stats for all maps played by a player

func (GameStats) WeaponStats

func (gs GameStats) WeaponStats() []Weaponstat

WeaponStats returns stats for all weapons used by a player

type LastMatch

type LastMatch struct {
	Outcome           string
	FavWeaponIconPath string
	FavWeaponName     string
	FavWeaponAccuracy string
}

LastMatch hold additional stats calculated to be viewed in the templates

type Mapstat

type Mapstat struct {
	Map    string
	Name   string
	Rounds int
	Wins   int
}

Mapstat holds all values for a map to be marshalled into JSON

func (Mapstat) MarshalJSON

func (ms Mapstat) MarshalJSON() ([]byte, error)

MarshalJSON converts a Mapstat struct to json, e.g. for the API

type PlayerHistory

type PlayerHistory struct {

	//SteamID of the player
	SteamID string

	// Data array containing entries to the history with time and values
	Data []PlayerHistoryEntry
}

PlayerHistory holds the players history data from the player_history table. Stats values that need to be saved over time, are added to this table and object.

type PlayerHistoryEntry

type PlayerHistoryEntry struct {

	// SteamID of the player
	SteamID string

	// The time when the entry was saved
	Time time.Time

	// Total kill/death ratio
	TotalKD string

	// Total avarage damage per round
	TotalADR string

	// Last match avarage damage per round
	LastMatchADR string

	// Total kills
	TotalKills string

	// Total kills with headshot
	TotalKillsHeadshot string

	// Total shots hit
	TotalShotsHit string

	// Total shots fired
	TotalShotsFired string

	// Contribution score in last match
	LastMatchContributionScore string

	// Damage dealt in last match
	LastMatchDamage string

	// Death count in last match
	LastMatchDeaths string

	// Kills in last match
	LastMatchKills string

	// Number of round of last match
	LastMatchRounds string

	// Las match kill/death ratio
	LastMatchKD string

	// Total hit ratio
	HitRatio string

	// Platime in the last 2 weeks
	Playtime2Weeks string
}

PlayerHistoryEntry holds on snapshot of the values that are tracked over time. The steamid field is no primary key in this case, since every player will have multiple entries

type PlayerInfo

type PlayerInfo struct {
	PlayerSummary       PlayerSummary
	UserStatsForGame    UserStatsForGame
	RecentlyPlayedGames RecentlyPlayedGames
	PlayerHistory       PlayerHistory
}

PlayerInfo contains the information to be shown of a given player

func (PlayerInfo) Calc

func (pi PlayerInfo) Calc() Calculations

Calc is a helper function to access the dynamically caluclated values from the templates

func (PlayerInfo) LastMatch

func (pi PlayerInfo) LastMatch() LastMatch

LastMatch is a helper function to access the dynamically caluclated values from the templates

type PlayerSummary

type PlayerSummary struct {

	// 64bit SteamID of the user
	SteamID uint64

	// The player's persona name (display name)
	Personaname string

	// The full URL of the player's Steam Community profile.
	Profileurl string

	// The full URL of the player's 32x32px avatar. If the user
	// hasn't configured an avatar, this will be the default ?
	// avatar.
	Avatar string

	// The full URL of the player's 64x64px avatar. If the user
	// hasn't configured an avatar, this will be the default ?
	// avatar.
	Avatarmedium string

	// The full URL of the player's 184x184px avatar. If the
	// user hasn't configured an avatar, this will be the
	// default ? avatar.
	Avatarfull string

	// 0 - Offline
	// 1 - Online
	// 2 - Busy
	// 3 - Away
	// 4 - Snooze
	// 5 - looking to trade
	// 6 - looking to play.
	// The user's current status. If the player's profile is private,
	// this will always be "0", except if the user has set
	// their status to looking to trade or looking to play,
	// because a bug makes those status appear even if the
	// profile is private.
	Personastate string

	// This represents whether the profile is visible or not,
	// and if it is visible, why you are allowed to see it.
	// Note that because this WebAPI does not use
	// authentication, there are only two possible values
	// returned: 1 - the profile is not visible to you
	// (Private, Friends Only, etc), 3 - the profile is
	// "Public", and the data is visible. Mike Blaszczak's post
	// on Steam forums says, "The community visibility state
	// this API returns is different than the privacy state.
	// It's the effective visibility state from the account
	// making the request to the account being viewed given the
	// requesting account's relationship to the viewed
	// account."
	Communityvisibilitystate string

	// If set, indicates the user has a community profile
	// configured (will be set to '1')
	Profilestate string

	// The last time the user was online, in unix time. Only
	// available when you are friends with the requested user
	// (since Feb, 4).
	Lastlogoff string

	// If set, indicates the profile allows public comments.
	Commentpermission string

	// This value will be removed in a future update (see loccityid)
	Cityid string

	// If the user is currently in-game, this will be the name
	// of the game they are playing. This may be the name of a
	// non-Steam game shortcut.
	Gameextrainfo string

	// If the user is currently in-game, this value will be
	// returned and set to the gameid of that game.
	Gameid string

	// The ip and port of the game server the user is currently
	// playing on, if they are playing on-line in a game using
	// Steam matchmaking. Otherwise will be set to "0.0.0.0:0".
	Gameserverip string

	// An internal code indicating the user's city of
	// residence. A future update will provide this data in a
	// more useful way.  steam_location gem/package makes
	// player location data readable for output.
	Loccityid string

	// If set on the user's Steam Community profile, The user's
	// country of residence, 2-character ISO country code
	Loccountrycode string

	// If set on the user's Steam Community profile, The user's state of residence
	Locstatecode string

	// The player's primary group, as configured in their Steam Community profile.
	Primaryclanid string

	// The player's "Real Name", if they have set it.
	Realname string

	// The time the player's account was created.
	Timecreated string
}

PlayerSummary holds the players summary data from the steam API endpoint GetPlayerSummaries

type RecentlyPlayedGames

type RecentlyPlayedGames struct {

	// SteamID of the player
	SteamID string

	// AppID for the game, 730 for CS:GO
	Appid string

	// Name of the game played
	Name string

	// Playtime in the last two weeks
	Playtime2Weeks string

	// Total playtime
	PlaytimeForever string

	// URL to the icon of the game
	ImgIconURL string

	// URL to the logo of the game
	ImgLogoURL string

	// Total playtime on windows
	PlaytimeWindowsForever string

	// Total playtime on mac
	PlaytimeMacForever string

	// Total playtime on linux
	PlaytimeLinuxForever string
}

RecentlyPlayedGames holds the players summary data from the steam API endpoint GetRecentlyPlayedGames

type Stats

type Stats struct {
	Name  string `json:"name"`
	Value int    `json:"value"`
}

Stats is the nested struct to hold the "stats" array returned by the steam API endopint GetUserStatsForGame

type SteamClient

type SteamClient struct {
	Config SteamConfig
}

SteamClient acts as main interface to interact with the steam API and gather data

func NewSteamClient

func NewSteamClient(configPath string) *SteamClient

NewSteamClient returrns a new SteamClient

func (SteamClient) GetAvatarURL

func (sc SteamClient) GetAvatarURL(id uint64) string

GetAvatarURL returns the URL to a players avatar image

func (SteamClient) GetPlayers

func (sc SteamClient) GetPlayers() []PlayerInfo

GetPlayers returns info for all players fetched from the API using the steamIDs in it's config

type SteamConfig

type SteamConfig struct {
	SteamAPIKey     string   `json:"SteamAPIKey"`
	SteamIDs        []string `json:"SteamIDs"`
	HistoryInterval int      `json:"HistoryInterval"`
	UpdateInterval  int      `json:"UpdateInterval"`
	PostgresUser    string   `json:"db_user"`
	PostgresPass    string   `json:"db_pass"`
	PostgresDbName  string   `json:"db_name"`
	PostgresDbHost  string   `json:"db_host"`
}

SteamConfig struct holds the values as read from the configuration file config.json on startup

func NewSteamConfig

func NewSteamConfig(configPath string) (SteamConfig, error)

NewSteamConfig creates a new configuration struct from a path pointing to the json configuration file. It will return an error if the file does not exist

type UserStatsForGame

type UserStatsForGame struct {

	// SteamID of the player
	SteamID uint64

	// Name of the game
	GameName string

	// GamesStats object containing stats for the game
	Stats GameStats

	// GameArchievements object containing archievements for the game
	Archivements GameArchievements

	// GameExtras object containig additional, calculated information
	Extra GameExtras
}

UserStatsForGame holds the players summary data from the steam API endpoint GetUserStatsForGame

type Weaponstat

type Weaponstat struct {
	Weapon common.EquipmentType
	Hits   int
	Shots  int
	Kills  int
}

Weaponstat holds all stat values for a weapon to be marshalled into JSON

func (Weaponstat) MarshalJSON

func (ws Weaponstat) MarshalJSON() ([]byte, error)

MarshalJSON converts a Weaponstat struct to json, e.g. for the API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL