models

package
v0.0.0-...-2968aeb Latest Latest
Warning

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

Go to latest
Published: May 15, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	// for sake of simplicity define item types using names
	// matching data coming from CPMA Q3 server
	RedArmor     = "RA"
	YellowArmor  = "YA"
	GreenArmor   = "GA"
	MegaHealth   = "MH"
	QuadDamage   = "Quad"
	BattleSuit   = "BattleSuit"
	Regeneration = "Regen"
	Haste        = "Haste"
	Flight       = "Flight"
	Invisibility = "Invis"

	// weapons
	Gauntlet        = "G"
	Machinegun      = "MG"
	Shotgun         = "SG"
	Plasmagun       = "PG"
	GrenadeLauncher = "GL"
	RocketLauncher  = "RL"
	Railgun         = "RG"
	BFG             = "BFG"
	LightningGun    = "LG"
)
View Source
const (
	NoUser = 0
)

Variables

This section is empty.

Functions

func ClaimAliasesByPlayer

func ClaimAliasesByPlayer(store store.DBConn, player uint, aliases []string)

func CreateSchema

func CreateSchema(store store.DBConn) error

func HasPlayer

func HasPlayer(store store.DBConn, name string) bool

func HasPlayerId

func HasPlayerId(store store.DBConn, pid uint) bool

func ItemHasDuration

func ItemHasDuration(itype string) bool

returns true if effects of given item are time bounded

func NewAliasOrCurrent

func NewAliasOrCurrent(store store.DBConn, newalias Alias) uint

create or lookup a matching alias and return its ID

func NewItemStat

func NewItemStat(store store.DBConn, is ItemStat) uint

create new item stat and return its ID

func NewMatch

func NewMatch(store store.DBConn, match Match) uint

create new match and return its ID

func NewMatchInfo

func NewMatchInfo(store store.DB, m *MatchInfo) (uint, string)

load user provided matchinfo into store, returns match ID and hash

func NewPlayer

func NewPlayer(store store.DBConn, name string, passwordhash string) uint

create new player returning its ID

func NewPlayerMatchStat

func NewPlayerMatchStat(store store.DBConn, pms PlayerMatchStat) uint

func NewWeaponStat

func NewWeaponStat(store store.DBConn, ws WeaponStat) uint

create new weapon stat and return its ID

Types

type Alias

type Alias struct {
	gorm.Model

	// alias, ex. 'honeybunny', 'Klesk'
	Alias string

	// player claiming this alias
	PlayerID uint
}

Alias is a nickname used during the match.

func GetAlias

func GetAlias(store store.DBConn, aliasID uint) *Alias

find alias using alias ID

func GetAliases

func GetAliases(store store.DBConn, user uint) []Alias

return alphabetically ordered list of aliases

type DescData

type DescData struct {
	// mapping of short name to long names
	ItemMap map[string]ItemDesc
}

descriptor of items, mainly for presentation purposes

func GetDesc

func GetDesc() *DescData

obtain pointer to item descriptor

type GlobalStats

type GlobalStats struct {
	// total number of frags/kills
	Frags uint
	// total number of suicides
	Suicides uint
	// total number of matches
	Matches uint
	// total number of unique maps
	Maps uint
	// number of rockets launched
	RocketsLaunched uint
	// players
	Players uint
}

func GetGlobalStats

func GetGlobalStats(store store.DB) GlobalStats

type ItemDesc

type ItemDesc struct {
	// short name, ex. RA (red armor), RL (rocket launcher)
	Short string
	// long name - Rocket Launcher
	Name string
}

item (such as rocket launcher, railgun, red armor) descriptor

func GetItemDesc

func GetItemDesc(name string) ItemDesc

obtain description of given item/weapon

type ItemStat

type ItemStat struct {
	gorm.Model

	// item type (RA, YA, GA, MH)
	Type string
	// pickups count
	Pickups uint
	// time held (when applicable, ex. for quad)
	Time time.Duration

	// player's match stats this item is part of
	PlayerMatchStatID uint
}

Per item statistics achieved during the match

func ListItemStats

func ListItemStats(store store.DBConn, pmsID uint) []ItemStat

list weapon statistics for given player match stat ID

func (ItemStat) DurationDesc

func (i ItemStat) DurationDesc() string

func (ItemStat) HasDuration

func (i ItemStat) HasDuration() bool

true if effect of given item is time bounded, such as Quad Damage, Regeneration, Battle Suit

type Match

type Match struct {
	gorm.Model

	// match data hash
	DataHash string `sql:"not null,unique"`
	// when the match was played
	DateTime time.Time
	// duration in seconds
	Duration uint
	// map, ex. q3dm17
	Map string
	// type of match, 1v1, FFA, CTF
	Type string
}

Match data

func FindMatchByHash

func FindMatchByHash(store store.DBConn, hash string) *Match

func ListMatches

func ListMatches(store store.DBConn, params MatchListParams) []Match

func (Match) DurationDesc

func (m Match) DurationDesc() string

func (Match) NiceDateTime

func (m Match) NiceDateTime() string

type MatchInfo

type MatchInfo struct {
	Match Match
	// stats of all players who attended this match
	PlayerData []PlayerDataItem
}

aggregate match info

func GetMatchInfo

func GetMatchInfo(store store.DB, hash string) *MatchInfo

load match data and produce a match info data wrapper, returns nil if match was not found

type MatchListParams

type MatchListParams struct {
	Limit    int
	TimeSort bool
	SortDesc bool
}

type Player

type Player struct {
	gorm.Model

	// user defined name, ex. joe
	Name string

	// password hash
	PasswordHash string
}

Registered players

func GetPlayer

func GetPlayer(store store.DBConn, pid uint) *Player

func ListPlayers

func ListPlayers(store store.DBConn) []Player

type PlayerDataItem

type PlayerDataItem struct {
	// use Alias to access PlayerID
	Alias   Alias
	Weapons []WeaponStat
	Items   []ItemStat
	Stats   PlayerMatchStat
}

aggregate player data from particular match

type PlayerGlobalStats

type PlayerGlobalStats struct {
	Kills         uint
	Deaths        uint
	Suicides      uint
	Matches       uint
	KillsPerMatch float32
	// frags per life
	Efficiency float32
	Wins       uint
	// global weapon stats
	Weapons []WeaponStat
	// global item stats
	Items []ItemStat
}

func GetPlayerGlobaStats

func GetPlayerGlobaStats(store store.DB, player uint) *PlayerGlobalStats

type PlayerMatchStat

type PlayerMatchStat struct {
	gorm.Model

	// score
	Score int
	// kills count
	Kills int
	// number of deaths
	Deaths int
	// self-kills count
	Suicides int
	// net (kills - deaths - suicides)
	Net int
	// damage given in HP
	DamageGiven int
	// damage taken in HP
	DamageTaken int
	// total health taken in HP
	HealthTotal int
	// total armor points
	ArmorTotal int

	// alias used
	AliasID uint

	// match
	MatchID uint
}

Overall statistics achieved by player during a match

func ListPlayerMatchStat

func ListPlayerMatchStat(store store.DBConn, matchID uint) []PlayerMatchStat

type WeaponStat

type WeaponStat struct {
	gorm.Model

	// weapon type
	Type string
	// number of hits
	Hits uint
	// number of shots
	Shots uint
	// number of kills
	Kills uint

	// player's match stats this weapon is part of
	PlayerMatchStatID uint
}

Per weapon statistics achieved during the match

func ListWeaponStats

func ListWeaponStats(store store.DBConn, pmsID uint) []WeaponStat

list weapon statistics for given player match stat ID

func (WeaponStat) Accuracy

func (w WeaponStat) Accuracy() uint

Directories

Path Synopsis
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

Jump to

Keyboard shortcuts

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