Documentation ¶
Index ¶
- Constants
- Variables
- func EnsurePlayerExists(gameID, id string, db *mgo.Database, logger zap.Logger) error
- func GetDonationRequestsCollection(db *mgo.Database) *mgo.Collection
- func GetDonationWeightForClan(gameID, clanID string, dt time.Time, resetType ResetType, r redis.Conn, ...) (int, error)
- func GetDonationWeightForPlayer(playerID string, from, to int64, db *mgo.Database, logger zap.Logger) (int, error)
- func GetDonationWeightKey(prefix, gameID, clanID string, date time.Time, resetType ResetType) string
- func GetDonationsCollection(db *mgo.Database) *mgo.Collection
- func GetExpirationDate(date time.Time, resetType ResetType, clock Clock) int64
- func GetGamesCollection(db *mgo.Database) *mgo.Collection
- func GetPlayersCollection(db *mgo.Database) *mgo.Collection
- func IncrementDonationWeightForClan(redis redis.Conn, gameID, clanID string, weight int, clock Clock) error
- func IncrementDonationWeightForPlayer(redis redis.Conn, gameID, playerID string, weight int, clock Clock) error
- func UpdateDonationWindowStart(gameID, id string, timestamp int64, db *mgo.Database, logger zap.Logger) error
- type Clock
- type Donation
- type DonationRequest
- func (d *DonationRequest) Create(db *mgo.Database, logger zap.Logger) error
- func (d *DonationRequest) Donate(playerID string, amount, maxWeightPerPlayer int, r redis.Conn, ...) error
- func (d *DonationRequest) GetDonationCount() int
- func (d *DonationRequest) GetDonationCountForPlayer(playerID string) int
- func (d *DonationRequest) GetGame(db *mgo.Database, logger zap.Logger) (*Game, error)
- func (v DonationRequest) MarshalEasyJSON(w *jwriter.Writer)
- func (d *DonationRequest) ToJSON() ([]byte, error)
- func (v *DonationRequest) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (d *DonationRequest) ValidateDonationRequestLimit(game *Game, amount int, logger zap.Logger) error
- func (d *DonationRequest) ValidateDonationRequestLimitPerPlayer(game *Game, player string, amount int, logger zap.Logger) error
- type Game
- type Item
- type M
- type Player
- type RealClock
- type ResetType
Constants ¶
Variables ¶
var NotFoundString = "not found"
NotFoundString is the string returned when an element is not found
Functions ¶
func EnsurePlayerExists ¶
EnsurePlayerExists upserts the player
func GetDonationRequestsCollection ¶
func GetDonationRequestsCollection(db *mgo.Database) *mgo.Collection
GetDonationRequestsCollection to update or query games
func GetDonationWeightForClan ¶
func GetDonationWeightForClan(gameID, clanID string, dt time.Time, resetType ResetType, r redis.Conn, logger zap.Logger) (int, error)
GetDonationWeightForClan returns the donation weight for a clan in a given interval
func GetDonationWeightForPlayer ¶
func GetDonationWeightForPlayer(playerID string, from, to int64, db *mgo.Database, logger zap.Logger) (int, error)
GetDonationWeightForPlayer returns the donation weight for a given player in a given interval
func GetDonationWeightKey ¶
func GetDonationWeightKey(prefix, gameID, clanID string, date time.Time, resetType ResetType) string
GetDonationWeightKey returns the key to be used in redis for the scores
func GetDonationsCollection ¶
func GetDonationsCollection(db *mgo.Database) *mgo.Collection
GetDonationsCollection to update or query games
func GetExpirationDate ¶
GetExpirationDate returns the date to set the expiration in seconds to for the given reset type
func GetGamesCollection ¶
func GetGamesCollection(db *mgo.Database) *mgo.Collection
GetGamesCollection to update or query games
func GetPlayersCollection ¶
func GetPlayersCollection(db *mgo.Database) *mgo.Collection
GetPlayersCollection to update or query games
func IncrementDonationWeightForClan ¶
func IncrementDonationWeightForClan(redis redis.Conn, gameID, clanID string, weight int, clock Clock) error
IncrementDonationWeightForClan should increment the donation weight for a clan for all time periods
Types ¶
type Donation ¶
type Donation struct { ID string `json:"id" bson:"_id,omitempty"` GameID string `json:"gameID" bson:"gameID"` Clan string `json:"clan" bson:"clan"` Player string `json:"player" bson:"player"` DonationRequestID string `json:"donationRequestID" bson:"donationRequestID"` Amount int `json:"amount" bson:"amount"` Weight int `json:"weight" bson:"weight"` CreatedAt int64 `json:"createdAt" bson:"createdAt"` }
Donation represents a specific donation a player made to a request
func GetDonationFromJSON ¶
GetDonationFromJSON unmarshals the donation from the specified JSON
func (Donation) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Donation) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type DonationRequest ¶
type DonationRequest struct { ID string `json:"id" bson:"_id,omitempty"` Item string `json:"item" bson:"item,omitempty"` Player string `json:"player" bson:"player"` Clan string `json:"clan" bson:"clan"` GameID string `json:"gameID" bson:"gameID"` Donations []Donation `json:"donations" bson:""` CreatedAt int64 `json:"createdAt" bson:"createdAt"` UpdatedAt int64 `json:"updatedAt" bson:"updatedAt,omitempty"` FinishedAt int64 `json:"finishedAt" bson:"finishedAt,omitempty"` Clock Clock `json:"-" bson:"-"` }
DonationRequest represents a request for an item donation a player made in a game
func GetDonationRequestByID ¶
func GetDonationRequestByID(id string, db *mgo.Database, logger zap.Logger) (*DonationRequest, error)
GetDonationRequestByID rtrieves the game by its id
func GetDonationRequestFromJSON ¶
func GetDonationRequestFromJSON(data []byte) (*DonationRequest, error)
GetDonationRequestFromJSON unmarshals the donation request from the specified JSON
func NewDonationRequest ¶
func NewDonationRequest(gameID string, item, player, clan string, clock ...Clock) *DonationRequest
NewDonationRequest returns a new instance of DonationRequest
func (*DonationRequest) Donate ¶
func (d *DonationRequest) Donate(playerID string, amount, maxWeightPerPlayer int, r redis.Conn, db *mgo.Database, logger zap.Logger) error
Donate an item in a given Donation Request
func (*DonationRequest) GetDonationCount ¶
func (d *DonationRequest) GetDonationCount() int
GetDonationCount returns the total amount of donations
func (*DonationRequest) GetDonationCountForPlayer ¶
func (d *DonationRequest) GetDonationCountForPlayer(playerID string) int
GetDonationCountForPlayer returns the total amount of donations for a given player ID
func (DonationRequest) MarshalEasyJSON ¶
func (v DonationRequest) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (*DonationRequest) ToJSON ¶
func (d *DonationRequest) ToJSON() ([]byte, error)
ToJSON returns the game as JSON
func (*DonationRequest) UnmarshalEasyJSON ¶
func (v *DonationRequest) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*DonationRequest) ValidateDonationRequestLimit ¶
func (d *DonationRequest) ValidateDonationRequestLimit(game *Game, amount int, logger zap.Logger) error
ValidateDonationRequestLimit ensures that no more than the allowed number of donations has been donated
func (*DonationRequest) ValidateDonationRequestLimitPerPlayer ¶
func (d *DonationRequest) ValidateDonationRequestLimitPerPlayer(game *Game, player string, amount int, logger zap.Logger) error
ValidateDonationRequestLimitPerPlayer ensures that no more than the allowed number of donations has been donated per player
type Game ¶
type Game struct { ID string `json:"id" bson:"_id,omitempty"` Name string `json:"name" bson:"name,omitempty"` // List of items in this game Items map[string]Item `json:"items" bson:""` // Number of hours since player's first donation before the limit of donations reset. // If player donates item A at timestamp X, then their donations limit resets at x + DonationCooldownHours. DonationCooldownHours int `json:"donationCooldownHours" bson:"donationCooldownHours"` // Cooldown a player must wait before doing his next donation request. Defaults to 8hs DonationRequestCooldownHours int `json:"donationRequestCooldownHours" bson:"donationRequestCooldownHours"` UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` }
Game represents each game in UR
func GetGameByID ¶
GetGameByID rtrieves the game by its id
func GetGameFromJSON ¶
GetGameFromJSON unmarshals the game from the specified JSON
func (*Game) AddItem ¶
func (g *Game) AddItem( key string, metadata map[string]interface{}, limitOfItemsInEachDonationRequest, limitOfItemsPerPlayerDonation, weightPerDonation int, db *mgo.Database, logger zap.Logger, ) (*Item, error)
AddItem to this game
func (Game) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Game) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type Item ¶
type Item struct { Key string `json:"item" bson:"key,omitempty"` Metadata map[string]interface{} `json:"metadata" bson:"metadata"` LimitOfItemsInEachDonationRequest int `json:"limitOfItemsInEachDonationRequest" bson:"limitOfItemsInEachDonationRequest"` LimitOfItemsPerPlayerDonation int `json:"limitOfItemsPerPlayerDonation" bson:"limitOfItemsPerPlayerDonation"` //This weight counts for the donation cooldown limits of each player WeightPerDonation int `json:"weightPerDonation" bson:"weightPerDonation"` UpdatedAt int64 `json:"updatedAt" bson:"updatedAt"` }
Item represents one donatable item in a given game
func GetItemFromJSON ¶
GetItemFromJSON unmarshals the item from the specified JSON
func NewItem ¶
func NewItem( key string, metadata map[string]interface{}, weightPerDonation, limitOfItemsPerPlayerDonation, limitOfItemsInEachDonationRequest int, ) *Item
NewItem returns a configured new item
func (Item) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Item) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type Player ¶
type Player struct { GameID string `json:"gameID" bson:"gameID"` ID string `json:"id" bson:"_id,omitempty"` DonationWindowStart int64 `json:"donationWindowStart" bson:"donationWindowStart"` }
Player represents one player in a given game
func GetPlayerByID ¶
GetPlayerByID rtrieves the game by its id
func GetPlayerFromJSON ¶
GetPlayerFromJSON unmarshals the player from the specified JSON
func (Player) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Player) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type RealClock ¶
type RealClock struct{}
RealClock returns the current time as UTC Date
func (*RealClock) GetUTCTime ¶
GetUTCTime returns the current time as UTC Date