Exemplo n.º 1
0
// create new weapon stat and return its ID
func NewWeaponStat(store store.DBConn, ws WeaponStat) uint {
	db := store.Conn()

	db.Create(&ws)

	return ws.ID
}
Exemplo n.º 2
0
// create new item stat and return its ID
func NewItemStat(store store.DBConn, is ItemStat) uint {
	db := store.Conn()

	db.Create(&is)

	return is.ID
}
Exemplo n.º 3
0
func NewPlayerMatchStat(store store.DBConn, pms PlayerMatchStat) uint {
	db := store.Conn()

	db.Create(&pms)

	return pms.ID
}
Exemplo n.º 4
0
// create or lookup a matching alias and return its ID
func NewAliasOrCurrent(store store.DBConn, newalias Alias) uint {
	db := store.Conn()

	var alias Alias
	db.FirstOrCreate(&alias, newalias)

	return alias.ID
}
Exemplo n.º 5
0
func ListPlayers(store store.DBConn) []Player {
	db := store.Conn()

	var players []Player
	db.Find(&players)

	return players
}
Exemplo n.º 6
0
// create new match and return its ID
func NewMatch(store store.DBConn, match Match) uint {

	db := store.Conn()

	db.Create(&match)

	return match.ID
}
Exemplo n.º 7
0
// return alphabetically ordered list of aliases
func GetAliases(store store.DBConn, user uint) []Alias {
	var aliases []Alias
	store.Conn().
		Model(&Alias{}).
		Where("player_id = ?", user).
		Order("alias").
		Find(&aliases)

	return aliases
}
Exemplo n.º 8
0
// find alias using alias ID
func GetAlias(store store.DBConn, aliasID uint) *Alias {
	db := store.Conn()

	var alias Alias
	nf := db.First(&alias, aliasID).RecordNotFound()
	if nf == true {
		return nil
	}
	return &alias
}
Exemplo n.º 9
0
// list weapon statistics for given player match stat ID
func ListWeaponStats(store store.DBConn, pmsID uint) []WeaponStat {
	db := store.Conn()

	var ws []WeaponStat
	db.Where(&WeaponStat{
		PlayerMatchStatID: pmsID,
	}).Find(&ws)

	return ws
}
Exemplo n.º 10
0
// list weapon statistics for given player match stat ID
func ListItemStats(store store.DBConn, pmsID uint) []ItemStat {
	db := store.Conn()

	var is []ItemStat
	db.Where(&ItemStat{
		PlayerMatchStatID: pmsID,
	}).Find(&is)

	return is
}
Exemplo n.º 11
0
func ListPlayerMatchStat(store store.DBConn, matchID uint) []PlayerMatchStat {
	db := store.Conn()

	// locate all players in this match
	var pls []PlayerMatchStat

	db.Where(&PlayerMatchStat{MatchID: matchID}).
		Find(&pls)

	return pls
}
Exemplo n.º 12
0
// create new player returning its ID
func NewPlayer(store store.DBConn, name string, passwordhash string) uint {
	player := Player{
		Name:         name,
		PasswordHash: passwordhash,
	}

	db := store.Conn()

	db.Create(&player)

	return player.ID
}
Exemplo n.º 13
0
func GetPlayer(store store.DBConn, pid uint) *Player {
	db := store.Conn()

	var player Player

	notfound := db.First(&player, pid).
		RecordNotFound()
	if notfound == true {
		return nil
	}
	return &player
}
Exemplo n.º 14
0
func FindMatchByHash(store store.DBConn, hash string) *Match {

	db := store.Conn()

	var mfound Match
	notfound := db.Where("data_hash = ?", hash).
		Find(&mfound).
		RecordNotFound()
	if notfound == true {
		return nil
	}
	return &mfound
}
Exemplo n.º 15
0
func ClaimAliasesByPlayer(store store.DBConn, player uint, aliases []string) {
	// update aliases set player_id = `player` where aliases in
	// `aliases`?

	db := store.Conn()

	tx := db.Begin()
	for _, a := range aliases {
		tx.Model(&Alias{}).
			Where(&Alias{Alias: a}).
			Update("player_id", player)
	}
	tx.Commit()
}
Exemplo n.º 16
0
func HasPlayer(store store.DBConn, name string) bool {
	db := store.Conn()

	var player Player

	notfound := db.Where(&Player{Name: name}).
		First(&player).
		RecordNotFound()

	if notfound == true {
		return false
	}
	return true
}
Exemplo n.º 17
0
func ListMatches(store store.DBConn, params MatchListParams) []Match {
	db := store.Conn()

	var matches []Match

	if params.Limit != 0 {
		db = db.Limit(params.Limit)
	}

	if params.TimeSort == true {
		ord := "date_time"
		if params.SortDesc == true {
			ord += " desc"
		}
		db = db.Order(ord)
	}

	db.Find(&matches)

	return matches
}
Exemplo n.º 18
0
func CreateSchema(store store.DBConn) error {
	store.Conn().AutoMigrate(schemaModels...)
	return nil
}