db

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SteamAPIKey Steam Web API Key for accessing Steam API.
	SteamAPIKey = ""
	// DefaultPage Default page where player access root directly.
	DefaultPage string
	// SQLAccess SQL Access Object for MySQL and GORM things
	SQLAccess DBdatas
	// Cnf Configration Data
	Cnf Config
	// Sess Session
	Sess *sessions.Sessions
)

Functions

func GetSteamName

func GetSteamName(steamid uint64) (string, error)

GetSteamName Get steam profile name by steamid64 via Steam web API

func LoginHandler

func LoginHandler(c *gin.Context)

LoginHandler HTTP Handler for /login page.

func LogoutHandler

func LogoutHandler(c *gin.Context)

LogoutHandler HTTP Handler for /logout

Types

type Config

type Config struct {
	SteamAPIKey  string
	DefaultPage  string
	SQLHost      string
	SQLUser      string
	SQLPass      string
	SQLPort      int
	SQLDBName    string
	SQLDebugMode bool
	HOST         string
	Cookie       string
}

Config Configration Struct for config.ini

type DBdatas

type DBdatas struct {
	Host string
	User string
	Pass string
	Db   string
	Port int
	Gorm *gorm.DB
}

DBdatas Struct for MySQL configration and Gorm

func (*DBdatas) GetUserData

func (s *DBdatas) GetUserData(limit int, wherekey string, wherevalue string) ([]UserData, error)

GetUserData Gets UserData array via MySQL(GORM).

type GameServerData

type GameServerData struct {
	ID           int    `gorm:"primary_key;column:id;AUTO_INCREMENT;NOT NULL" json:"id"`
	UserID       int    `gorm:"column:user_id;DEFAULT NULL" json:"user_id"`
	InUse        bool   `gorm:"column:in_use;DEFAULT NULL" json:"in_use"`
	IPString     string `gorm:"column:ip_string;DEFAULT NULL" json:"ip_string"`
	Port         int    `gorm:"column:port;DEFAULT NULL" json:"port"`
	RconPassword string `gorm:"column:rcon_password;DEFAULT NULL" json:"rcon_password"`
	DisplayName  string `gorm:"column:display_name;DEFAULT NULL" json:"display_name"`
	PublicServer bool   `gorm:"column:public_server;DEFAULT NULL" json:"public_server"`
}

GameServerData Struct for game_server table.

func (*GameServerData) CanDelete

func (g *GameServerData) CanDelete(userid int) bool

CanDelete Check if server is deletable for user or not.

func (*GameServerData) CanEdit

func (g *GameServerData) CanEdit(userid int) bool

CanEdit Check if server is editable for user or not.

func (*GameServerData) Create

func (g *GameServerData) Create(userid int, displayname string, ipstring string, port int, rconpassword string, publicserver bool) (*GameServerData, error)

Create Register GameServer into DB.

func (*GameServerData) Delete

func (g *GameServerData) Delete() error

Delete Deletes GameServer information.

func (*GameServerData) Edit

func (g *GameServerData) Edit() (*GameServerData, error)

Edit Edits GameServer information.

func (*GameServerData) GetDisplay

func (g *GameServerData) GetDisplay() string

GetDisplay Returns "DisplayName" if its not empty. otherwise it returns address and port.

func (*GameServerData) GetHostPort

func (g *GameServerData) GetHostPort() string

GetHostPort gets gameserver addr and port. e.g. localhost:27015

func (*GameServerData) SendRcon

func (g *GameServerData) SendRcon(cmd string) (string, error)

SendRcon Sends Remote-Commands to specific IP SRCDS.

func (*GameServerData) TableName

func (g *GameServerData) TableName() string

TableName declairation for GORM

type MapStatsData

type MapStatsData struct {
	ID         int           `gorm:"primary_key" gorm:"column:id"`
	MatchID    int           `gorm:"column:match_id" gorm:"ForeignKey:match_id"`
	MapNumber  int           `gorm:"column:map_number"`
	MapName    string        `gorm:"column:map_name"`
	StartTime  sql.NullTime  `gorm:"column:start_time"`
	EndTime    sql.NullTime  `gorm:"column:end_time"`
	Winner     sql.NullInt32 `gorm:"column:winner"`
	Team1Score int           `gorm:"column:team1_score"`
	Team2Score int           `gorm:"column:team2_score"`

	User UserData `gorm:"ASSOCIATION_FOREIGNKEY:user_id"`
}

MapStatsData MapStatsData struct for map_stats table.

func (*MapStatsData) GetOrCreate

func (m *MapStatsData) GetOrCreate(matchID int, MapNumber int, mapname string) (*MapStatsData, error)

GetOrCreate Get or register mapstats data.

func (*MapStatsData) TableName

func (m *MapStatsData) TableName() string

TableName declairation for GORM

type MatchConfig

type MatchConfig struct {
	MatchID              string `json:"matchid"` // NOT int
	Scrim                bool   `json:"scrim,omitempty"`
	MatchTitle           string `json:"match_title,omitempty"`
	PlayersPerTeam       int    `json:"players_per_team,omitempty"`
	MinPlayersToReady    int    `json:"min_players_to_ready,omitempty"`
	MinSPectatorsToReady int    `json:"min_spectators_to_ready,omitempty"`
	SkipVeto             bool   `json:"skip_veto,omitempty"`
	// bo2_series and maps_to_win are deprecated on get5 plugin side. Use num_maps insted
	// Bo2Series 			   bool   `json:"bo2_series"`
	// MapsToWin 			   int    `json:"maps_to_win"`
	NumMaps                    int    `json:"num_maps,omitempty"`
	VetoFirst                  string `json:"veto_first,omitempty"` // team1 || team2
	SideType                   string `json:"side_type,omitempty"`  // standard and ?
	FavoredTeamPercentageText  string `json:"favored_percentage_text,omitempty"`
	FavoredTeamPercentageTeam1 int    `json:"favored_percentage_team1,omitempty"`
	Spectators                 struct {
		Name    string   `json:"name"`
		Players []string `json:"players"`
	} `json:"spectators"`
	Team1 struct {
		Flag    string   `json:"flag"`
		Name    string   `json:"name"`
		Tag     string   `json:"tag"`
		Players []string `json:"players"`
	} `json:"team1"`
	Team2 struct {
		Flag    string   `json:"flag"`
		Name    string   `json:"name"`
		Tag     string   `json:"tag"`
		Players []string `json:"players"`
	} `json:"team2"`

	Maplist  []string `json:"maplist"`
	MapSides []string `json:"map_sides"`

	Cvars map[string]string `json:"cvars"`
}

MatchConfig Match configration for get5 api, based on https://github.com/splewis/get5/blob/master/configs/get5/example_match.json and https://github.com/splewis/get5/blob/3f793ceb3736d78ba6a92f42631d91cb52f0beb4/scripting/get5/matchconfig.sp#L435

type MatchData

type MatchData struct {
	ID              int           `gorm:"primary_key;column:id" json:"id"`
	UserID          int           `gorm:"column:user_id" json:"user_id"`
	ServerID        int           `gorm:"column:server_id" json:"server_id"`
	Team1ID         int           `gorm:"column:team1_id" json:"team1_id"`
	Team2ID         int           `gorm:"column:team2_id" json:"team2_id"`
	Winner          sql.NullInt32 `gorm:"column:winner" json:"winner"`
	Cancelled       bool          `gorm:"column:cancelled" json:"cancelled"`
	StartTime       sql.NullTime  `gorm:"column:start_time" json:"start_time"`
	EndTime         sql.NullTime  `gorm:"column:end_time" json:"end_time"`
	MaxMaps         int           `gorm:"column:max_maps" json:"max_maps"`
	Title           string        `gorm:"column:title" json:"title"`
	SkipVeto        bool          `gorm:"column:skip_veto" json:"skip_veto"`
	APIKey          string        `gorm:"column:api_key" json:"-"`
	VetoMapPool     string        `gorm:"column:veto_mappool" json:"-"`
	VetoMapPoolJSON []string      `gorm:"-" json:"veto_mappool"`
	Team1Score      int           `gorm:"column:team1_score" json:"team1_score"`
	Team2Score      int           `gorm:"column:team2_score" json:"team2_score"`
	Team1String     string        `gorm:"column:team1_string" json:"team1_string"`
	Team2String     string        `gorm:"column:team2_string" json:"team2_string"`
	Forfeit         bool          `gorm:"column:forfeit" json:"forfeit"`
	PluginVersion   string        `gorm:"column:plugin_version" json:"-"`

	MapStats []MapStatsData `gorm:"ForeignKey:MatchID" json:"-"`
	Server   GameServerData `json:"-"`
}

MatchData Struct for match table.

func (*MatchData) BuildMatchDict

func (m *MatchData) BuildMatchDict() (*MatchConfig, error)

BuildMatchDict Builds match JSON data.

func (*MatchData) Create

func (m *MatchData) Create(userid int, team1id int, team2id int, team1string string, team2string string, maxmaps int, skipveto bool, title string, vetomappool []string, serverid int) (*MatchData, error)

Create Register Match information into DB.

func (*MatchData) Finalized

func (m *MatchData) Finalized() bool

Finalized Returns true if match is finished or cancelled

func (*MatchData) Finished

func (m *MatchData) Finished() bool

Finished Returns true if match is ended and not cancelled

func (*MatchData) Get

func (m *MatchData) Get(id int) (*MatchData, error)

Get Get myself

func (*MatchData) GetCurrentScore

func (m *MatchData) GetCurrentScore(g *gorm.DB) (int, int, error)

GetCurrentScore Returns current match score. returns map-score if match is BO1.

func (*MatchData) GetLoser

func (m *MatchData) GetLoser() (TeamData, error)

GetLoser Get Loser team as "TeamData" struct.

func (*MatchData) GetMapStat

func (m *MatchData) GetMapStat() (*MatchData, error)

GetMapStat Gets each map stat data as "MapStatsData" struct array.

func (*MatchData) GetServer

func (m *MatchData) GetServer() (*GameServerData, error)

GetServer Get match server ID as GameServerData

func (*MatchData) GetStatusString

func (m *MatchData) GetStatusString(ShowWinner bool) (string, error)

GetStatusString Get match status as string.

func (*MatchData) GetTeam1

func (m *MatchData) GetTeam1() (TeamData, error)

GetTeam1 Get Team1 as "TeamData" struct.

func (*MatchData) GetTeam2

func (m *MatchData) GetTeam2() (TeamData, error)

GetTeam2 Get Team2 as "TeamData" struct.

func (*MatchData) GetVSString

func (m *MatchData) GetVSString() (string, error)

GetVSString Get Match VS information as string. for gorazor template

func (*MatchData) GetWinner

func (m *MatchData) GetWinner() (TeamData, error)

GetWinner Get Winner team as "TeamData" struct.

func (*MatchData) Live

func (m *MatchData) Live() bool

Live Retursn true if match is in-progress

func (*MatchData) Pending

func (m *MatchData) Pending() bool

Pending Returns true if match is not started and not cancelled

func (*MatchData) SendToServer

func (m *MatchData) SendToServer() error

SendToServer Send match config to server

func (*MatchData) TableName

func (m *MatchData) TableName() string

TableName declairation for GORM

type MatchPageData

type MatchPageData struct {
	LoggedIn    bool
	AdminAccess bool
	Match       MatchData
}

MatchPageData Struct for /match/{matchID} page.

type MatchesPageData

type MatchesPageData struct {
	LoggedIn   bool
	UserName   string
	UserID     int
	Matches    []MatchData
	AllMatches bool
	MyMatches  bool
	Owner      UserData
}

MatchesPageData Struct for /matches/ page.

type MetricsData

type MetricsData struct {
	RegisteredUsers    int `json:"users"`
	SavedTeams         int `json:"saved_teams"`
	MatchesCreated     int `json:"matches_created"`
	CompletedMatches   int `json:"completed_matches"`
	ServersAdded       int `json:"servers_added"`
	MapsWithStatsSaved int `json:"maps_with_stats"`
	UniquePlayers      int `json:"unique_players"`
}

MetricsData Struct metrics analysys.

func GetMetrics

func GetMetrics() MetricsData

GetMetrics Get Each table's count.

type MetricsDataPage

type MetricsDataPage struct {
	LoggedIn bool
	Data     MetricsData
}

MetricsDataPage Struct for /metrics page.

type MyserversPageData

type MyserversPageData struct {
	Servers  []GameServerData
	LoggedIn bool
}

MyserversPageData Struct for /myservers page.

type PlayerStatsData

type PlayerStatsData struct {
	ID               int    `gorm:"primary_key;column:id"`
	MatchID          int    `gorm:"column:match_id"`
	MapID            int    `gorm:"column:map_id"`
	TeamID           int    `gorm:"column:team_id"`
	SteamID          string `gorm:"column:steam_id;unique"`
	Name             string `gorm:"column:name"`
	Kills            int    `gorm:"column:kills"`
	Deaths           int    `gorm:"column:deaths"`
	Roundsplayed     int    `gorm:"column:roundsplayed"`
	Assists          int    `gorm:"column:assists"`
	FlashbangAssists int    `gorm:"column:flashbang_assists"`
	Teamkills        int    `gorm:"column:teamkills"`
	Suicides         int    `gorm:"column:suicides"`
	HeadshotKills    int    `gorm:"column:headshot_kills"`
	Damage           int    `gorm:"column:damage"`
	BombPlants       int    `gorm:"column:bomb_plants"`
	BombDefuses      int    `gorm:"column:bomb_defuses"`
	V1               int    `gorm:"column:v1"`
	V2               int    `gorm:"column:v2"`
	V3               int    `gorm:"column:v3"`
	V4               int    `gorm:"column:v4"`
	V5               int    `gorm:"column:v5"`
	K1               int    `gorm:"column:k1"`
	K2               int    `gorm:"column:k2"`
	K3               int    `gorm:"column:k3"`
	K4               int    `gorm:"column:k4"`
	K5               int    `gorm:"column:k5"`
	FirstdeathCT     int    `gorm:"column:firstdeath_Ct"`
	FirstdeathT      int    `gorm:"column:firstdeath_t"`
	FirstkillCT      int    `gorm:"column:firstkill_ct"`
	FirstkillT       int    `gorm:"column:firstkill_t"`

	User UserData `gorm:"ASSOCIATION_FOREIGNKEY:user_id"`
}

PlayerStatsData Player stats data struct for player_stats table.

func (*PlayerStatsData) GetADR

func (p *PlayerStatsData) GetADR() float64

GetADR Returns player's ADR(Average Damage per Round).

func (*PlayerStatsData) GetFPR

func (p *PlayerStatsData) GetFPR() float64

GetFPR Returns player's FPR(Frags Per Round).

func (*PlayerStatsData) GetHSP

func (p *PlayerStatsData) GetHSP() float64

GetHSP Returns player's HSP(HeadShot Percentage).

func (*PlayerStatsData) GetKDR

func (p *PlayerStatsData) GetKDR() float64

GetKDR Returns player's KDR(Kill/Deaths Ratio).

func (*PlayerStatsData) GetOrCreate

func (p *PlayerStatsData) GetOrCreate(matchID int, MapNumber int, steamid string) (*PlayerStatsData, error)

GetOrCreate Get or register player stats data into DB.

func (*PlayerStatsData) GetRating

func (p *PlayerStatsData) GetRating() float64

GetRating Get player's rating. Average datas are static tho.

func (*PlayerStatsData) GetSteamURL

func (p *PlayerStatsData) GetSteamURL() string

GetSteamURL get player's Steam community URL by their steamid64.

func (*PlayerStatsData) TableName

func (p *PlayerStatsData) TableName() string

TableName declairation for GORM

type TeamCreatePageData

type TeamCreatePageData struct {
	LoggedIn bool
	Edit     bool
	Content  interface{} // should be template
}

TeamCreatePageData Struct for /team/create page.

type TeamData

type TeamData struct {
	ID          int               `gorm:"primary_key;column:id" json:"id"`
	UserID      int               `gorm:"column:user_id" json:"user_id"`
	Name        string            `gorm:"column:name" json:"name"`
	Tag         string            `gorm:"column:tag" json:"tag"`
	Flag        string            `gorm:"column:flag" json:"flag"`
	AuthsPickle []byte            `gorm:"column:auths" json:"-"`
	Auths       []string          `gorm:"-" json:"auths"` // converts pickle []byte to []string
	Players     []PlayerStatsData `gorm:"-" json:"-"`
	PublicTeam  bool              `gorm:"column:public_team" json:"public_team"`
}

TeamData Struct for team table.

func (*TeamData) CanDelete

func (t *TeamData) CanDelete(userid int) bool

CanDelete Check if server is deletable for user or not.

func (*TeamData) CanEdit

func (t *TeamData) CanEdit(userid int) bool

CanEdit Check if server is editable for user or not.

func (*TeamData) Create

func (t *TeamData) Create(userid int, name string, tag string, flag string, logo string, auths []string, publicteam bool) (*TeamData, error)

Create Register Team information into DB.

func (*TeamData) Delete

func (t *TeamData) Delete() error

Delete Deletes TeamData information.

func (*TeamData) Edit

func (t *TeamData) Edit() (*TeamData, error)

Edit Edits TeamData information.

func (*TeamData) GetNameURLHtml

func (t *TeamData) GetNameURLHtml() string

GetNameURLHtml Get team page and name as a-tag. for gorazor template

func (*TeamData) GetPlayers

func (t *TeamData) GetPlayers() (*[]string, error)

GetPlayers Gets registered player's steamid64.

func (*TeamData) GetRecentMatches

func (t *TeamData) GetRecentMatches(limit int) []*MatchData

GetRecentMatches Gets team match history.

func (*TeamData) GetURL

func (t *TeamData) GetURL() string

GetURL Get URL of team page.

func (*TeamData) GetVSMatchResult

func (t *TeamData) GetVSMatchResult(matchid int) (string, error)

GetVSMatchResult Returns Match result as string for gorazor template.

func (*TeamData) TableName

func (t *TeamData) TableName() string

TableName declairation for GORM

type TeamPageData

type TeamPageData struct {
	LoggedIn   bool
	IsYourTeam bool
	User       UserData
	Team       TeamData
}

TeamPageData Struct for /team/{teamID} page.

type TeamsPageData

type TeamsPageData struct {
	LoggedIn   bool
	User       UserData
	IsYourTeam bool
	Teams      []TeamData
}

TeamsPageData Struct for /teams/{userID} page.

type UserData

type UserData struct {
	ID      int    `gorm:"primary_key;column:id;AUTO_INCREMENT"`
	SteamID string `gorm:"column:steam_id;unique"`
	Name    string `gorm:"column:name"`
	Admin   bool   `gorm:"column:admin"`

	Servers []*GameServerData `gorm:"ForeignKey:UserID"`
	Teams   []*TeamData       `gorm:"ForeignKey:UserID"`
	Matches []*MatchData      `gorm:"ForeignKey:UserID"`
}

UserData Struct for "user" table.

func (*UserData) GetOrCreate

func (u *UserData) GetOrCreate() (*UserData, bool, error)

GetOrCreate Get or Register Userdata by their steamid into DB.

func (*UserData) GetRecentMatches

func (u *UserData) GetRecentMatches(limit int) []*MatchData

GetRecentMatches Gets match history

func (*UserData) GetSteamURL

func (u *UserData) GetSteamURL() string

GetSteamURL Get user's steam page URL by their steamid64

func (*UserData) GetTeams

func (u *UserData) GetTeams(limit int) []*TeamData

GetTeams Get teams which is owened by user

func (*UserData) GetURL

func (u *UserData) GetURL() string

GetURL Get user page URL

func (*UserData) TableName

func (u *UserData) TableName() string

TableName declairation for GORM

type UserMaxResources added in v0.1.2

type UserMaxResources struct {
	Servers uint16
	Teams   uint16
	Matches uint16
}
var (
	// MaxResource  per user
	MaxResource UserMaxResources
)

type UserPageData

type UserPageData struct {
	LoggedIn bool
	User     UserData
}

UserPageData Struct for /user/{userID} page.

Jump to

Keyboard shortcuts

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