game

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: GPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetSWJSRoute                    = "GetSWJS"
	GetMainJSRoute                  = "GetMainJS"
	ConfigureRoute                  = "AuthConfigure"
	IndexRoute                      = "Index"
	ListOpenGamesRoute              = "ListOpenGames"
	ListStartedGamesRoute           = "ListStartedGames"
	ListFinishedGamesRoute          = "ListFinishedGames"
	ListMyStagingGamesRoute         = "ListMyStagingGames"
	ListMyStartedGamesRoute         = "ListMyStartedGames"
	ListMyFinishedGamesRoute        = "ListMyFinishedGames"
	ListOtherStagingGamesRoute      = "ListOtherStagingGames"
	ListOtherStartedGamesRoute      = "ListOtherStartedGames"
	ListOtherFinishedGamesRoute     = "ListOtherFinishedGames"
	ListOrdersRoute                 = "ListOrders"
	ListPhasesRoute                 = "ListPhases"
	ListPhaseStatesRoute            = "ListPhaseStates"
	ListGameStatesRoute             = "ListGameStates"
	ListOptionsRoute                = "ListOptions"
	ListChannelsRoute               = "ListChannels"
	ListMessagesRoute               = "ListMessages"
	ListBansRoute                   = "ListBans"
	ListTopRatedPlayersRoute        = "ListTopRatedPlayers"
	ListTopReliablePlayersRoute     = "ListTopReliablePlayers"
	ListTopHatedPlayersRoute        = "ListTopHatedPlayers"
	ListTopHaterPlayersRoute        = "ListTopHaterPlayers"
	ListTopQuickPlayersRoute        = "ListTopQuickPlayers"
	ListFlaggedMessagesRoute        = "ListFlaggedMessages"
	DevResolvePhaseTimeoutRoute     = "DevResolvePhaseTimeout"
	DevUserStatsUpdateRoute         = "DevUserStatsUpdate"
	ReceiveMailRoute                = "ReceiveMail"
	RenderPhaseMapRoute             = "RenderPhaseMap"
	ReRateRoute                     = "ReRate"
	GlobalStatsRoute                = "GlobalStats"
	RssRoute                        = "Rss"
	ResaveRoute                     = "Resave"
	AllocateNationsRoute            = "AllocateNations"
	ReapInactiveWaitingPlayersRoute = "ReapInactiveWaitingPlayersRoute"
	ReScheduleRoute                 = "ReSchedule"
	ReScheduleAllBrokenRoute        = "ReScheduleAllBroken"
)
View Source
const (
	MAX_PHASE_DEADLINE = 30 * 24 * 60
)
View Source
const (
	MAX_STAGING_GAME_INACTIVITY = 30 * 24 * time.Hour
)

Variables

View Source
var (
	MessageFlagResource     *Resource
	FlaggedMessagesResource *Resource
)
View Source
var (
	UpdateUserStatsFunc *DelayFunc

	UserStatsResource *Resource
)
View Source
var (
	AllocationResource *Resource
)
View Source
var BanResource *Resource
View Source
var (
	GameResource *Resource
)
View Source
var GameResultResource = &Resource{
	Load:     loadGameResult,
	FullPath: "/Game/{game_id}/GameResult",
}
View Source
var GameStateResource *Resource
View Source
var MemberResource = &Resource{
	Create:     createMember,
	Delete:     deleteMember,
	Update:     updateMember,
	CreatePath: "/Game/{game_id}/Member",
	FullPath:   "/Game/{game_id}/Member/{user_id}",
}
View Source
var (
	MessageResource *Resource
)
View Source
var OrderResource *Resource
View Source
var (
	PhaseResource *Resource
)
View Source
var PhaseResultResource = &Resource{
	Load:     loadPhaseResult,
	FullPath: "/Game/{game_id}/Phase/{phase_ordinal}/Result",
}
View Source
var PhaseStateResource *Resource

Functions

func Allocate

func Allocate(preferers Preferers, nations godip.Nations) ([]godip.Nation, error)

func BanID

func BanID(ctx context.Context, userIds []string) (*datastore.Key, error)

func ChannelID

func ChannelID(ctx context.Context, gameID *datastore.Key, members Nations) (*datastore.Key, error)

func FlaggedMessagesID

func FlaggedMessagesID(ctx context.Context, gameID *datastore.Key, userId string) (*datastore.Key, error)

func GameResultID

func GameResultID(ctx context.Context, gameID *datastore.Key) *datastore.Key

func GameStateID

func GameStateID(ctx context.Context, gameID *datastore.Key, nation godip.Nation) (*datastore.Key, error)

func OrderID

func OrderID(ctx context.Context, phaseID *datastore.Key, srcProvince godip.Province) (*datastore.Key, error)

func PP

func PP(i interface{}) string

func PhaseID

func PhaseID(ctx context.Context, gameID *datastore.Key, phaseOrdinal int64) (*datastore.Key, error)

func PhaseResultID

func PhaseResultID(ctx context.Context, gameID *datastore.Key, phaseOrdinal int64) (*datastore.Key, error)

func PhaseStateID

func PhaseStateID(ctx context.Context, phaseID *datastore.Key, nation godip.Nation) (*datastore.Key, error)

func SeenMarkerID

func SeenMarkerID(ctx context.Context, channelID *datastore.Key, owner godip.Nation) (*datastore.Key, error)

func SetFCMConf

func SetFCMConf(ctx context.Context, fcmConf *FCMConf) error

func SetSendGrid

func SetSendGrid(ctx context.Context, sendGrid *SendGrid) error

func SetupRouter

func SetupRouter(r *mux.Router)

func UpdateGlickosASAP

func UpdateGlickosASAP(ctx context.Context) error

func UpdateUserStatsASAP

func UpdateUserStatsASAP(ctx context.Context, uids []string) error

func UserStatsID

func UserStatsID(ctx context.Context, userId string) *datastore.Key

Types

type Allocation

type Allocation struct {
	Members AllocationMembers `methods:"POST"`
	Variant string            `methods:"POST"`
}

func (*Allocation) Item

func (a *Allocation) Item(r Request) *Item

type AllocationMember

type AllocationMember struct {
	Prefs  godip.Nations `methods:"POST"`
	Result godip.Nation
}

func (AllocationMember) Preferences

func (a AllocationMember) Preferences() godip.Nations

type AllocationMembers

type AllocationMembers []AllocationMember

func (AllocationMembers) Each

func (a AllocationMembers) Each(f func(int, Preferer))

func (AllocationMembers) Len

func (a AllocationMembers) Len() int

type AllocationMethod

type AllocationMethod int
const (
	RandomAllocation AllocationMethod = iota
	PreferenceAllocation
)

type Ban

type Ban struct {
	UserIds  []string `methods:"POST"`
	OwnerIds []string
	Users    []auth.User
}

func (*Ban) ID

func (b *Ban) ID(ctx context.Context) (*datastore.Key, error)

func (*Ban) Item

func (b *Ban) Item(r Request) *Item

func (*Ban) OwnedBy

func (b *Ban) OwnedBy(uid string) bool

func (*Ban) Save

func (b *Ban) Save(ctx context.Context) error

type Bans

type Bans []Ban

func (Bans) Item

func (b Bans) Item(r Request, userId string) *Item

type Bounce

type Bounce struct {
	Province   godip.Province
	BounceList string
}

type Channel

type Channel struct {
	GameID         *datastore.Key
	Members        Nations
	NMessages      int
	NMessagesSince NMessagesSince `datastore:"-"`
}

func (*Channel) CountSince

func (c *Channel) CountSince(ctx context.Context, since time.Time) error

func (*Channel) ID

func (c *Channel) ID(ctx context.Context) (*datastore.Key, error)

func (*Channel) Item

func (c *Channel) Item(r Request) *Item

type Channels

type Channels []Channel

func (Channels) Item

func (c Channels) Item(r Request, gameID *datastore.Key, isMember bool) *Item

type DelayFunc

type DelayFunc struct {
	// contains filtered or unexported fields
}
var (
	FCMSendToTokensFunc *DelayFunc
)

func NewDelayFunc

func NewDelayFunc(queue string, backend interface{}) *DelayFunc

func (*DelayFunc) EnqueueAt

func (d *DelayFunc) EnqueueAt(ctx context.Context, taskETA time.Time, args ...interface{}) error

func (*DelayFunc) EnqueueIn

func (d *DelayFunc) EnqueueIn(ctx context.Context, taskDelay time.Duration, args ...interface{}) error

type Diplicity

type Diplicity struct {
	User *auth.User
}

type Dislodged

type Dislodged struct {
	Province  godip.Province
	Dislodged godip.Unit
}

type Dislodger

type Dislodger struct {
	Province godip.Province
	// The name of this is crap.
	// The Dislodger struct is used so that
	// Province is the actual dislodger, while
	// Dislodger is the province that was dislodged.
	Dislodger godip.Province
}

type FCMConf

type FCMConf struct {
	ServerKey string
}

type FCMData

type FCMData struct {
	DiplicityJSON []byte
}

func NewFCMData

func NewFCMData(payload interface{}) (*FCMData, error)

type FlaggedMessage

type FlaggedMessage struct {
	GameID         *datastore.Key
	ChannelMembers string
	Sender         godip.Nation
	Body           string
	CreatedAt      time.Time
	AuthorId       string
}

type FlaggedMessages

type FlaggedMessages struct {
	GameID    *datastore.Key
	UserId    string
	Messages  []FlaggedMessage
	CreatedAt time.Time
}

func (*FlaggedMessages) Item

func (f *FlaggedMessages) Item(r Request) *Item

type FlaggedMessagess

type FlaggedMessagess []FlaggedMessages

func (FlaggedMessagess) Item

func (f FlaggedMessagess) Item(r Request, curs *datastore.Cursor, limit int, userId string) *Item

type Game

type Game struct {
	ID *datastore.Key `datastore:"-"`

	Started  bool // Game has started.
	Closed   bool // Game is no longer joinable..
	Finished bool // Game has reached its end.

	Desc                  string           `methods:"POST" datastore:",noindex"`
	Variant               string           `methods:"POST"`
	PhaseLengthMinutes    time.Duration    `methods:"POST"`
	MaxHated              float64          `methods:"POST"`
	MaxHater              float64          `methods:"POST"`
	MinRating             float64          `methods:"POST"`
	MaxRating             float64          `methods:"POST"`
	MinReliability        float64          `methods:"POST"`
	MinQuickness          float64          `methods:"POST"`
	Private               bool             `methods:"POST"`
	NoMerge               bool             `methods:"POST"`
	DisableConferenceChat bool             `methods:"POST"`
	DisableGroupChat      bool             `methods:"POST"`
	DisablePrivateChat    bool             `methods:"POST"`
	NationAllocation      AllocationMethod `methods:"POST"`

	NMembers int
	Members  Members
	StartETA time.Time

	NewestPhaseMeta []PhaseMeta

	ActiveBans         []Ban    `datastore:"-"`
	FailedRequirements []string `datastore:"-"`
	FirstMember        *Member  `datastore:"-" json:",omitempty" methods:"POST"`

	CreatedAt   time.Time
	CreatedAgo  time.Duration `datastore:"-" ticker:"true"`
	StartedAt   time.Time
	StartedAgo  time.Duration `datastore:"-" ticker:"true"`
	FinishedAt  time.Time
	FinishedAgo time.Duration `datastore:"-" ticker:"true"`
}

func (*Game) AbbrNat

func (g *Game) AbbrNat(nat godip.Nation) godip.Nation

func (*Game) AbbrNats

func (g *Game) AbbrNats(nats Nations) Nations

func (*Game) DescFor

func (g *Game) DescFor(nat godip.Nation) string

func (*Game) GetMemberByNation

func (g *Game) GetMemberByNation(nation godip.Nation) (*Member, bool)

func (*Game) GetMemberByUserId

func (g *Game) GetMemberByUserId(userID string) (*Member, bool)

func (*Game) Item

func (g *Game) Item(r Request) *Item

func (*Game) Joinable

func (g *Game) Joinable() bool

func (*Game) Leavable

func (g *Game) Leavable() bool

func (*Game) Redact

func (g *Game) Redact(viewer *auth.User)

func (*Game) Refresh

func (g *Game) Refresh()

func (*Game) Save

func (g *Game) Save(ctx context.Context) error

type GameResult

type GameResult struct {
	GameID            *datastore.Key
	SoloWinnerMember  godip.Nation
	SoloWinnerUser    string
	DIASMembers       []godip.Nation
	DIASUsers         []string
	NMRMembers        []godip.Nation
	NMRUsers          []string
	EliminatedMembers []godip.Nation
	EliminatedUsers   []string
	AllUsers          []string
	Scores            []GameScore
	Rated             bool
	Private           bool
	CreatedAt         time.Time
}

func (*GameResult) AssignScores

func (g *GameResult) AssignScores()

func (*GameResult) ID

func (g *GameResult) ID(ctx context.Context) *datastore.Key

func (*GameResult) Item

func (g *GameResult) Item(r Request) *Item

func (*GameResult) Save

func (g *GameResult) Save(ctx context.Context) error

type GameResults

type GameResults []GameResult

type GameScore

type GameScore struct {
	UserId string
	Member godip.Nation
	SCs    int
	Score  float64
}

type GameState

type GameState struct {
	GameID *datastore.Key
	Nation godip.Nation
	Muted  []godip.Nation `methods:"PUT"`
}

func (*GameState) HasMuted

func (g *GameState) HasMuted(nat godip.Nation) bool

func (*GameState) ID

func (g *GameState) ID(ctx context.Context) (*datastore.Key, error)

func (*GameState) Item

func (p *GameState) Item(r Request) *Item

func (*GameState) Save

func (g *GameState) Save(ctx context.Context) error

type GameStates

type GameStates []GameState

func (GameStates) Item

func (g GameStates) Item(r Request, gameID *datastore.Key) *Item

type Games

type Games []Game

func (Games) Item

func (g Games) Item(r Request, user *auth.User, cursor *datastore.Cursor, limit int, name string, desc []string, route string) *Item

func (Games) Len

func (g Games) Len() int

func (Games) Less

func (g Games) Less(i, j int) bool

func (*Games) RemoveBanned

func (g *Games) RemoveBanned(ctx context.Context, uid string) ([][]Ban, error)

func (*Games) RemoveCustomFiltered

func (g *Games) RemoveCustomFiltered(filters []func(g *Game) bool)

func (*Games) RemoveFiltered

func (g *Games) RemoveFiltered(userStats *UserStats) [][]string

func (Games) Swap

func (g Games) Swap(i, j int)

type Glicko

type Glicko struct {
	GameID          *datastore.Key
	UserId          string
	CreatedAt       time.Time
	Member          godip.Nation
	Rating          float64
	PracticalRating float64
	Deviation       float64
	Volatility      float64
}

func GetGlicko

func GetGlicko(ctx context.Context, userId string) (*Glicko, error)

func (*Glicko) ID

func (g *Glicko) ID(ctx context.Context) (*datastore.Key, error)

type GlobalStats

type GlobalStats struct {
	ActiveGameHistograms                map[string]Histogram
	ActiveGameMemberUserStatsHistograms map[string]Histogram
	ActiveMemberUserStatsHistograms     map[string]Histogram
}

type Histogram

type Histogram struct {
	Data        map[string]int
	Description string
}

type Member

type Member struct {
	User              auth.User
	Nation            godip.Nation
	GameAlias         string `methods:"POST,PUT" datastore:",noindex"`
	NationPreferences string `methods:"POST,PUT" datastore:",noindex"`
	NewestPhaseState  PhaseState
	UnreadMessages    int
}

func (*Member) Item

func (m *Member) Item(r Request) *Item

func (Member) Preferences

func (m Member) Preferences() godip.Nations

func (*Member) Redact

func (m *Member) Redact(viewer *auth.User, isMember bool, started bool)

type Members

type Members []Member

func (Members) Each

func (m Members) Each(f func(int, Preferer))

func (Members) Len

func (m Members) Len() int

type Message

type Message struct {
	ID             *datastore.Key `datastore:"-"`
	GameID         *datastore.Key
	ChannelMembers Nations `methods:"POST"`
	Sender         godip.Nation
	Body           string `methods:"POST" datastore:",noindex"`
	CreatedAt      time.Time
	Age            time.Duration `datastore:"-" ticker:"true"`
}

func (*Message) Item

func (m *Message) Item(r Request) *Item

func (*Message) NotifyRecipients

func (m *Message) NotifyRecipients(ctx context.Context, host string, channel *Channel, game *Game) error

type MessageFlag

type MessageFlag struct {
	GameID         *datastore.Key
	ChannelMembers Nations
	From           time.Time `methods:"POST"`
	To             time.Time `methods:"POST"`
}

func (*MessageFlag) Item

func (m *MessageFlag) Item(r Request) *Item

type Messages

type Messages []Message

func (Messages) Item

func (m Messages) Item(r Request, gameID *datastore.Key, channelMembers Nations) *Item

type NMessagesSince

type NMessagesSince struct {
	Since     time.Time
	NMessages int
}

type Nations

type Nations []godip.Nation

func (*Nations) FromString

func (n *Nations) FromString(s string)

func (Nations) Includes

func (n Nations) Includes(m godip.Nation) bool

func (Nations) Len

func (n Nations) Len() int

func (Nations) Less

func (n Nations) Less(i, j int) bool

func (Nations) String

func (n Nations) String() string

func (Nations) Swap

func (n Nations) Swap(i, j int)

type Order

type Order struct {
	GameID       *datastore.Key
	PhaseOrdinal int64
	Nation       godip.Nation
	Parts        []string `methods:"POST,PUT" separator:" "`
}

func (*Order) ID

func (o *Order) ID(ctx context.Context) (*datastore.Key, error)

func (*Order) Item

func (o *Order) Item(r Request) *Item

func (*Order) Save

func (o *Order) Save(ctx context.Context) error

type Orders

type Orders []Order

func (Orders) Item

func (o Orders) Item(r Request, gameID *datastore.Key, phase *Phase) *Item

type Phase

type Phase struct {
	PhaseMeta
	GameID      *datastore.Key
	Units       []UnitWrapper
	SCs         []SC
	Dislodgeds  []Dislodged
	Dislodgers  []Dislodger
	Bounces     []Bounce
	Resolutions []Resolution
	Host        string
	// Ignore this field completely, it should never be used, and is simply hard to remove.
	Scheme string
}

func NewPhase

func NewPhase(s *state.State, gameID *datastore.Key, phaseOrdinal int64, host string) *Phase

func (*Phase) ID

func (p *Phase) ID(ctx context.Context) (*datastore.Key, error)

func (*Phase) Item

func (p *Phase) Item(r Request) *Item

func (*Phase) Orders

func (p *Phase) Orders(ctx context.Context) (map[godip.Nation]map[godip.Province][]string, error)

func (*Phase) Recalc

func (p *Phase) Recalc() error

func (*Phase) Save

func (p *Phase) Save(ctx context.Context) error

func (*Phase) ScheduleResolution

func (p *Phase) ScheduleResolution(ctx context.Context) error

func (*Phase) State

func (p *Phase) State(ctx context.Context, variant vrt.Variant, orderMap map[godip.Nation]map[godip.Province][]string) (*state.State, error)

type PhaseMeta

type PhaseMeta struct {
	PhaseOrdinal   int64
	Season         godip.Season
	Year           int
	Type           godip.PhaseType
	Resolved       bool
	CreatedAt      time.Time
	CreatedAgo     time.Duration `datastore:"-" ticker:"true"`
	ResolvedAt     time.Time
	ResolvedAgo    time.Duration `datastore:"-" ticker:"true"`
	DeadlineAt     time.Time
	NextDeadlineIn time.Duration `datastore:"-" ticker:"true"`
	UnitsJSON      string        `datastore:",noindex"`
	SCsJSON        string        `datastore:",noindex"`
}

func (*PhaseMeta) Refresh

func (p *PhaseMeta) Refresh()

type PhaseResolver

type PhaseResolver struct {
	Context          context.Context
	Game             *Game
	Phase            *Phase
	PhaseStates      PhaseStates
	TimeoutTriggered bool
	// contains filtered or unexported fields
}

func (*PhaseResolver) Act

func (p *PhaseResolver) Act() error

func (*PhaseResolver) SCCounts

func (p *PhaseResolver) SCCounts(s *state.State) map[godip.Nation]int

type PhaseResult

type PhaseResult struct {
	GameID       *datastore.Key
	PhaseOrdinal int64
	NMRUsers     []string
	ActiveUsers  []string
	ReadyUsers   []string
	AllUsers     []string
	Private      bool
}

func (*PhaseResult) ID

func (p *PhaseResult) ID(ctx context.Context) (*datastore.Key, error)

func (*PhaseResult) Item

func (p *PhaseResult) Item(r Request) *Item

func (*PhaseResult) Save

func (p *PhaseResult) Save(ctx context.Context) error

type PhaseState

type PhaseState struct {
	GameID         *datastore.Key
	PhaseOrdinal   int64
	Nation         godip.Nation
	ReadyToResolve bool `methods:"PUT"`
	WantsDIAS      bool `methods:"PUT"`
	OnProbation    bool
	NoOrders       bool
	Eliminated     bool
	ZippedOptions  []byte `skip:"true"`
	Note           string `datastore:",noindex"`
}

func (*PhaseState) ID

func (p *PhaseState) ID(ctx context.Context) (*datastore.Key, error)

func (*PhaseState) Item

func (p *PhaseState) Item(r Request) *Item

func (*PhaseState) Save

func (p *PhaseState) Save(ctx context.Context) error

type PhaseStates

type PhaseStates []PhaseState

func (PhaseStates) Item

func (p PhaseStates) Item(r Request, phase *Phase) *Item

type Phases

type Phases []Phase

func (Phases) Item

func (p Phases) Item(r Request, gameID *datastore.Key) *Item

func (Phases) Len

func (p Phases) Len() int

func (Phases) Less

func (p Phases) Less(i, j int) bool

func (Phases) Swap

func (p Phases) Swap(i, j int)

type Preferer

type Preferer interface {
	Preferences() godip.Nations
}

type Preferers

type Preferers interface {
	Each(func(int, Preferer))
	Len() int
}

type Resolution

type Resolution struct {
	Province   godip.Province
	Resolution string
}

type SC

type SC struct {
	Province godip.Province
	Owner    godip.Nation
}

type SeenMarker

type SeenMarker struct {
	GameID  *datastore.Key
	Members Nations
	Owner   godip.Nation
	At      time.Time `methods:"POST"`
}

func (*SeenMarker) ID

func (s *SeenMarker) ID(ctx context.Context) (*datastore.Key, error)

type SendGrid

type SendGrid struct {
	APIKey string
}

func GetSendGrid

func GetSendGrid(ctx context.Context) (*SendGrid, error)

type UnitWrapper

type UnitWrapper struct {
	Province godip.Province
	Unit     godip.Unit
}

type UserStats

type UserStats struct {
	UserId string

	UserStatsNumbers

	PrivateStats UserStatsNumbers

	Glicko Glicko
	User   auth.User
}

func (*UserStats) ID

func (u *UserStats) ID(ctx context.Context) *datastore.Key

func (*UserStats) Item

func (u *UserStats) Item(r Request) *Item

func (*UserStats) Redact

func (u *UserStats) Redact()

type UserStatsNumbers

type UserStatsNumbers struct {
	StartedGames  int
	FinishedGames int

	SoloGames       int
	DIASGames       int
	EliminatedGames int
	DroppedGames    int

	NMRPhases    int
	ActivePhases int
	ReadyPhases  int
	Reliability  float64
	Quickness    float64

	OwnedBans  int
	SharedBans int
	Hated      float64
	Hater      float64
}

func (*UserStatsNumbers) Recalculate

func (u *UserStatsNumbers) Recalculate(ctx context.Context, private bool, userId string) error

type UserStatsSlice

type UserStatsSlice []UserStats

func (UserStatsSlice) Item

func (u UserStatsSlice) Item(r Request, cursor *datastore.Cursor, limit int64, name string, desc []string, route string) *Item

Jump to

Keyboard shortcuts

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