posplay

package
v0.0.0-...-30a0ae6 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DEBUG is whether this is a debug build
	DEBUG = true

	// SessionName is the name of the PosPlay session in the session store
	SessionName = "posplay"

	// GameTimezone is the timezone where the game is played
	GameTimezone = "Europe/Lisbon"

	// CSRFfieldName is the name of the form field used for CSRF protection
	CSRFfieldName = "posplay.csrf"

	// CSRFcookieName is the name of the cookie used for CSRF protection
	CSRFcookieName = "_posplay_csrf"

	// PairProcessLongevity sets the timeout for pairing a device with a PosPlay account
	PairProcessLongevity = 30 * time.Second

	// PosPlayVersion is the version of this PosPlay subsystem release
	PosPlayVersion = "vDEBUG"
)
View Source
const (
	// PrivateLBPrivacy is used when users don't want to appear in leaderboards
	PrivateLBPrivacy string = "PRIVATE"
	// PublicLBPrivacy is used when users want to appear in leaderboards
	PublicLBPrivacy string = "PUBLIC"

	// PrivateProfilePrivacy is used when users don't want to show their profile to anyone
	PrivateProfilePrivacy string = "PRIVATE"
	// PlayersOnlyProfilePrivacy is used when users only want to show their profile to other PosPlay players
	PlayersOnlyProfilePrivacy string = "PLAYERS_ONLY"
	// PublicProfilePrivacy is used when users want to show their profile to everyone
	PublicProfilePrivacy string = "PUBLIC"
)
View Source
const (
	// UsernameDiscriminatorNameType is used when users want to appear like gbl08ma#3988
	UsernameDiscriminatorNameType string = "USERNAME_DISCRIM"
	// UsernameNameType is used when users want to appear like gbl08ma
	UsernameNameType string = "USERNAME"
	// NicknameNameType is used when users want to appear as their nickname in the project's guild
	NicknameNameType string = "NICKNAME"
)
View Source
const (
	// NotificationMethodDiscordDM corresponds to sending notifications through Discord DMs
	NotificationMethodDiscordDM string = "DISCORD_DM"

	// NotificationMethodAppNotif corresponds to sending notifications to the paired app
	NotificationMethodAppNotif string = "APP_NOTIF"
)
View Source
const (
	// NotificationTypeAchievementAchieved is used when the user achieved an achievement
	NotificationTypeAchievementAchieved string = "ACHIEVEMENT_ACHIEVED"

	// NotificationTypeGuildEventWon is used when the user won a Discord guild event
	NotificationTypeGuildEventWon string = "GUILD_EVENT_WON"
)

Variables

View Source
var Consts = map[string]reflect.Value{
	"CSRFcookieName":                      reflect.ValueOf(CSRFcookieName),
	"CSRFfieldName":                       reflect.ValueOf(CSRFfieldName),
	"DEBUG":                               reflect.ValueOf(DEBUG),
	"GameTimezone":                        reflect.ValueOf(GameTimezone),
	"NicknameNameType":                    reflect.ValueOf(NicknameNameType),
	"NotificationMethodAppNotif":          reflect.ValueOf(NotificationMethodAppNotif),
	"NotificationMethodDiscordDM":         reflect.ValueOf(NotificationMethodDiscordDM),
	"NotificationTypeAchievementAchieved": reflect.ValueOf(NotificationTypeAchievementAchieved),
	"NotificationTypeGuildEventWon":       reflect.ValueOf(NotificationTypeGuildEventWon),
	"PairProcessLongevity":                reflect.ValueOf(PairProcessLongevity),
	"PlayersOnlyProfilePrivacy":           reflect.ValueOf(PlayersOnlyProfilePrivacy),
	"PosPlayVersion":                      reflect.ValueOf(PosPlayVersion),
	"PrivateLBPrivacy":                    reflect.ValueOf(PrivateLBPrivacy),
	"PrivateProfilePrivacy":               reflect.ValueOf(PrivateProfilePrivacy),
	"PublicLBPrivacy":                     reflect.ValueOf(PublicLBPrivacy),
	"PublicProfilePrivacy":                reflect.ValueOf(PublicProfilePrivacy),
	"SessionName":                         reflect.ValueOf(SessionName),
	"UsernameDiscriminatorNameType":       reflect.ValueOf(UsernameDiscriminatorNameType),
	"UsernameNameType":                    reflect.ValueOf(UsernameNameType),
}
View Source
var Functions = map[string]reflect.Value{
	"BaseURL":                                 reflect.ValueOf(BaseURL),
	"ConfigureRouter":                         reflect.ValueOf(ConfigureRouter),
	"DescriptionForRarity":                    reflect.ValueOf(DescriptionForRarity),
	"DescriptionForXPTransaction":             reflect.ValueOf(DescriptionForXPTransaction),
	"DoXPTransaction":                         reflect.ValueOf(DoXPTransaction),
	"GetSession":                              reflect.ValueOf(GetSession),
	"Initialize":                              reflect.ValueOf(Initialize),
	"MonthStart":                              reflect.ValueOf(MonthStart),
	"NameForNotificationMethod":               reflect.ValueOf(NameForNotificationMethod),
	"NameForNotificationType":                 reflect.ValueOf(NameForNotificationType),
	"NewSession":                              reflect.ValueOf(NewSession),
	"RegisterDiscussionParticipationCallback": reflect.ValueOf(RegisterDiscussionParticipationCallback),
	"RegisterEventWinCallback":                reflect.ValueOf(RegisterEventWinCallback),
	"RegisterReport":                          reflect.ValueOf(RegisterReport),
	"RegisterTripFirstEdit":                   reflect.ValueOf(RegisterTripFirstEdit),
	"RegisterTripSubmission":                  reflect.ValueOf(RegisterTripSubmission),
	"RegisterXPTransaction":                   reflect.ValueOf(RegisterXPTransaction),
	"ReloadAchievements":                      reflect.ValueOf(ReloadAchievements),
	"ReloadTemplates":                         reflect.ValueOf(ReloadTemplates),
	"WeekStart":                               reflect.ValueOf(WeekStart),
}

NotificationDefaults contains defaults for notification settings

View Source
var Types = map[string]reflect.Type{
	"Config":            reflect.TypeOf((*Config)(nil)).Elem(),
	"ConnectionHandler": reflect.TypeOf((*ConnectionHandler)(nil)).Elem(),
	"DiscordEventParticipationAchievementStrategy": reflect.TypeOf((*DiscordEventParticipationAchievementStrategy)(nil)).Elem(),
	"PairConnection":                           reflect.TypeOf((*PairConnection)(nil)).Elem(),
	"PairConnectionExtra":                      reflect.TypeOf((*PairConnectionExtra)(nil)).Elem(),
	"ReachLevelAchievementStrategy":            reflect.TypeOf((*ReachLevelAchievementStrategy)(nil)).Elem(),
	"Session":                                  reflect.TypeOf((*Session)(nil)).Elem(),
	"StubAchievementStrategy":                  reflect.TypeOf((*StubAchievementStrategy)(nil)).Elem(),
	"SubmitAchievementStrategy":                reflect.TypeOf((*SubmitAchievementStrategy)(nil)).Elem(),
	"TripDuringDisturbanceAchievementStrategy": reflect.TypeOf((*TripDuringDisturbanceAchievementStrategy)(nil)).Elem(),
	"VisitStationsAchievementStrategy":         reflect.TypeOf((*VisitStationsAchievementStrategy)(nil)).Elem(),
	"VisitThroughoutLineAchievementStrategy":   reflect.TypeOf((*VisitThroughoutLineAchievementStrategy)(nil)).Elem(),
}
View Source
var Variables = map[string]reflect.Value{
	"NotificationDefaults": reflect.ValueOf(&NotificationDefaults),
	"TheConnectionHandler": reflect.ValueOf(&TheConnectionHandler),
}

Functions

func BaseURL

func BaseURL() string

BaseURL returns the base URL of the website without trailing slash

func ConfigureRouter

func ConfigureRouter(router *mux.Router)

ConfigureRouter configures a router to handle PosPlay paths

func DescriptionForRarity

func DescriptionForRarity(rarity float64) string

DescriptionForRarity returns a human-friendly description of a achievement rarity value (range 0 to 100)

func DescriptionForXPTransaction

func DescriptionForXPTransaction(tx *types.PPXPTransaction) string

DescriptionForXPTransaction returns a human-friendly description of a XP transaction

func DoXPTransaction

func DoXPTransaction(node sqalx.Node, player *types.PPPlayer, when time.Time, value int, txType string, extra map[string]interface{}, attemptMerge bool) error

DoXPTransaction adds a XP transaction to a user, performing the necessary checks and calling the necessary handlers

func Initialize

func Initialize(ppconfig Config) error

Initialize initializes the PosPlay subsystem

func MonthStart

func MonthStart() time.Time

MonthStart returns when the current competition month started

func NameForNotificationMethod

func NameForNotificationMethod(notifMethod string) string

NameForNotificationMethod returns a human-friendly name of a notification method

func NameForNotificationType

func NameForNotificationType(notifType string) string

NameForNotificationType returns a human-friendly name of a notification type

func RegisterDiscussionParticipationCallback

func RegisterDiscussionParticipationCallback(userID string, XPreward int) bool

RegisterDiscussionParticipationCallback gives a user a XP reward for participating in the Discord channels

func RegisterEventWinCallback

func RegisterEventWinCallback(userID, messageID string, XPreward int, eventType string) bool

RegisterEventWinCallback gives a user a XP reward for a Discord event, if he has not received a reward for that event yet

func RegisterReport

func RegisterReport(report types.Report)

RegisterReport schedules a report for analysis

func RegisterTripFirstEdit

func RegisterTripFirstEdit(trip *types.Trip)

RegisterTripFirstEdit schedules a trip resubmission (edit, confirmation) for analysis

func RegisterTripSubmission

func RegisterTripSubmission(trip *types.Trip)

RegisterTripSubmission schedules a trip submission for analysis

func RegisterXPTransaction

func RegisterXPTransaction(tx *types.PPXPTransaction)

RegisterXPTransaction is exclusively meant for use when bootstrapping the achievements system on a database with previous XP transactions

func ReloadAchievements

func ReloadAchievements() error

ReloadAchievements reloads the achievement cache

func ReloadTemplates

func ReloadTemplates() error

ReloadTemplates reloads the templates for the website

func WeekStart

func WeekStart() time.Time

WeekStart returns when the current competition week started

Types

type Config

type Config struct {
	Keybox              *keybox.Keybox
	Log                 *log.Logger
	Store               *sessions.CookieStore
	Node                sqalx.Node
	GitCommit           string
	SendAppNotification func(pair *types.APIPair, msgType string, data map[string]string)
	// contains filtered or unexported fields
}

Config contains runtime PosPlay subsystem configuration

type ConnectionHandler

type ConnectionHandler struct {
	// contains filtered or unexported fields
}

ConnectionHandler implements resource.PairConnectionHandler

var TheConnectionHandler *ConnectionHandler

TheConnectionHandler is the pair connection handler for PosPlay

func (*ConnectionHandler) DisplayName

func (h *ConnectionHandler) DisplayName() string

DisplayName implements resource.PairConnectionHandler

func (*ConnectionHandler) GetConnectionsForPair

func (h *ConnectionHandler) GetConnectionsForPair(node sqalx.Node, pair *types.APIPair) ([]types.PairConnection, error)

GetConnectionsForPair implements resource.PairConnectionHandler

func (*ConnectionHandler) ID

func (h *ConnectionHandler) ID() string

ID implements resource.PairConnectionHandler

func (*ConnectionHandler) TryCreateConnection

func (h *ConnectionHandler) TryCreateConnection(node sqalx.Node, code, deviceName string, pair *types.APIPair) bool

TryCreateConnection implements resource.PairConnectionHandler

type DiscordEventParticipationAchievementStrategy

type DiscordEventParticipationAchievementStrategy struct {
	StubAchievementStrategy
}

DiscordEventParticipationAchievementStrategy is an achievement strategy that rewards users when they participate in a set number of Discord events

func (*DiscordEventParticipationAchievementStrategy) CriteriaHTML

CriteriaHTML implements types.PPAchievementStrategy

func (*DiscordEventParticipationAchievementStrategy) HandleXPTransaction

func (s *DiscordEventParticipationAchievementStrategy) HandleXPTransaction(context *types.PPAchievementContext, transaction *types.PPXPTransaction, actualValueDiff int) error

HandleXPTransaction implements types.PPAchievementStrategy

func (*DiscordEventParticipationAchievementStrategy) ID

ID returns the ID for this PPAchievementStrategy

func (*DiscordEventParticipationAchievementStrategy) Progress

func (s *DiscordEventParticipationAchievementStrategy) Progress(context *types.PPAchievementContext) (current, total int, err error)

Progress implements types.PPAchievementStrategy

func (*DiscordEventParticipationAchievementStrategy) ProgressHTML

ProgressHTML implements types.PPAchievementStrategy

type PairConnection

type PairConnection struct {
	// contains filtered or unexported fields
}

PairConnection implements types.PairConnection

func (*PairConnection) Created

func (c *PairConnection) Created() time.Time

Created returns the creation time of this connection

func (*PairConnection) Extra

func (c *PairConnection) Extra() interface{}

Extra returns the extra bundle for this connection

func (*PairConnection) Pair

func (c *PairConnection) Pair() *types.APIPair

Pair returns the pair of this connection

type PairConnectionExtra

type PairConnectionExtra struct {
	DiscordID     uint64  `msgpack:"discordID" json:"discordID"`
	Username      string  `msgpack:"username" json:"username"`
	AvatarURL     string  `msgpack:"avatarURL" json:"avatarURL"`
	Level         int     `msgpack:"level" json:"level"`
	LevelProgress float64 `msgpack:"levelProgress" json:"levelProgress"`
	XP            int     `msgpack:"xp" json:"xp"`
	XPthisWeek    int     `msgpack:"xpThisWeek" json:"xpThisWeek"`
	Rank          int     `msgpack:"rank" json:"rank"`
	RankThisWeek  int     `msgpack:"rankThisWeek" json:"rankThisWeek"`
}

PairConnectionExtra is the extra info bundle for PairConnections. This is serialized and sent to clients

type ReachLevelAchievementStrategy

type ReachLevelAchievementStrategy struct {
	StubAchievementStrategy
}

ReachLevelAchievementStrategy is an achievement strategy that rewards users when they reach a specified level

func (*ReachLevelAchievementStrategy) CriteriaHTML

CriteriaHTML implements types.PPAchievementStrategy

func (*ReachLevelAchievementStrategy) HandleXPTransaction

func (s *ReachLevelAchievementStrategy) HandleXPTransaction(context *types.PPAchievementContext, transaction *types.PPXPTransaction, actualValueDiff int) error

HandleXPTransaction implements types.PPAchievementStrategy

func (*ReachLevelAchievementStrategy) ID

ID returns the ID for this PPAchievementStrategy

func (*ReachLevelAchievementStrategy) Progress

func (s *ReachLevelAchievementStrategy) Progress(context *types.PPAchievementContext) (current, total int, err error)

Progress implements types.PPAchievementStrategy

func (*ReachLevelAchievementStrategy) ProgressHTML

ProgressHTML implements types.PPAchievementStrategy

type Session

type Session struct {
	DiscordToken   *oauth2.Token
	DiscordInfo    *discordgo.User
	DisplayName    string
	GoToOnboarding bool
}

Session represents a user session in the PosPlay subsystem

func GetSession

func GetSession(r *http.Request, w http.ResponseWriter, doLogin bool) (ppsession *Session, redirected bool, err error)

GetSession retrieves the Session from the specified request, if one exists, and if not, optionally redirects the user to the authentication page

func NewSession

func NewSession(node sqalx.Node, r *http.Request, w http.ResponseWriter, discordToken *oauth2.Token) (*Session, error)

NewSession initializes a new PosPlay session from a Discord OAuth2 token

func (*Session) Logout

func (session *Session) Logout(r *http.Request, w http.ResponseWriter) error

Logout forcefully terminates a session

type StubAchievementStrategy

type StubAchievementStrategy struct{}

StubAchievementStrategy partially implements types.PPAchievementStrategy

func (*StubAchievementStrategy) CriteriaHTML

func (s *StubAchievementStrategy) CriteriaHTML(context *types.PPAchievementContext) string

CriteriaHTML implements types.PPAchievementStrategy context.Player may be nil when calling this function

func (*StubAchievementStrategy) HandleDisturbanceReport

func (s *StubAchievementStrategy) HandleDisturbanceReport(context *types.PPAchievementContext, report *types.LineDisturbanceReport) error

HandleDisturbanceReport implements types.PPAchievementStrategy

func (*StubAchievementStrategy) HandleTrip

func (s *StubAchievementStrategy) HandleTrip(context *types.PPAchievementContext, trip *types.Trip) error

HandleTrip implements types.PPAchievementStrategy

func (*StubAchievementStrategy) HandleTripEdit

func (s *StubAchievementStrategy) HandleTripEdit(context *types.PPAchievementContext, trip *types.Trip) error

HandleTripEdit implements types.PPAchievementStrategy

func (*StubAchievementStrategy) HandleXPTransaction

func (s *StubAchievementStrategy) HandleXPTransaction(context *types.PPAchievementContext, transaction *types.PPXPTransaction, actualValueDiff int) error

HandleXPTransaction implements types.PPAchievementStrategy

func (*StubAchievementStrategy) Progress

func (s *StubAchievementStrategy) Progress(context *types.PPAchievementContext) (current, total int, err error)

Progress implements types.PPAchievementStrategy If total == 0: this achievement has no progress, it's "all or nothing" If total == -1: this achievement is still locked for the user, show a censured version If total < -1: this achievement is still locked for the user, do not show it at all

func (*StubAchievementStrategy) ProgressHTML

func (s *StubAchievementStrategy) ProgressHTML(context *types.PPAchievementContext) string

ProgressHTML implements types.PPAchievementStrategy

type SubmitAchievementStrategy

type SubmitAchievementStrategy struct {
	StubAchievementStrategy
}

SubmitAchievementStrategy is an achievement strategy that rewards users when they submit a trip, trip edit, or disturbance report

func (*SubmitAchievementStrategy) CriteriaHTML

func (s *SubmitAchievementStrategy) CriteriaHTML(context *types.PPAchievementContext) string

CriteriaHTML implements types.PPAchievementStrategy

func (*SubmitAchievementStrategy) HandleDisturbanceReport

func (s *SubmitAchievementStrategy) HandleDisturbanceReport(context *types.PPAchievementContext, report *types.LineDisturbanceReport) error

HandleDisturbanceReport implements types.PPAchievementStrategy

func (*SubmitAchievementStrategy) HandleTrip

func (s *SubmitAchievementStrategy) HandleTrip(context *types.PPAchievementContext, trip *types.Trip) error

HandleTrip implements types.PPAchievementStrategy

func (*SubmitAchievementStrategy) HandleTripEdit

func (s *SubmitAchievementStrategy) HandleTripEdit(context *types.PPAchievementContext, trip *types.Trip) error

HandleTripEdit implements types.PPAchievementStrategy

func (*SubmitAchievementStrategy) ID

ID returns the ID for this PPAchievementStrategy

type TripDuringDisturbanceAchievementStrategy

type TripDuringDisturbanceAchievementStrategy struct {
	StubAchievementStrategy
}

TripDuringDisturbanceAchievementStrategy is an achievement strategy that rewards users when they submit a trip performed during a disturbance

func (*TripDuringDisturbanceAchievementStrategy) CriteriaHTML

CriteriaHTML implements types.PPAchievementStrategy

func (*TripDuringDisturbanceAchievementStrategy) HandleTrip

HandleTrip implements types.PPAchievementStrategy

func (*TripDuringDisturbanceAchievementStrategy) ID

ID returns the ID for this PPAchievementStrategy

func (*TripDuringDisturbanceAchievementStrategy) Progress

func (s *TripDuringDisturbanceAchievementStrategy) Progress(context *types.PPAchievementContext) (current, total int, err error)

Progress implements types.PPAchievementStrategy

type VisitStationsAchievementStrategy

type VisitStationsAchievementStrategy struct {
	StubAchievementStrategy
}

VisitStationsAchievementStrategy is an achievement strategy that rewards users when they visit certain stations

func (*VisitStationsAchievementStrategy) CriteriaHTML

CriteriaHTML implements types.PPAchievementStrategy

func (*VisitStationsAchievementStrategy) HandleTrip

HandleTrip implements types.PPAchievementStrategy

func (*VisitStationsAchievementStrategy) ID

ID returns the ID for this PPAchievementStrategy

func (*VisitStationsAchievementStrategy) Progress

func (s *VisitStationsAchievementStrategy) Progress(context *types.PPAchievementContext) (current, total int, err error)

Progress implements types.PPAchievementStrategy

func (*VisitStationsAchievementStrategy) ProgressHTML

ProgressHTML implements types.PPAchievementStrategy

type VisitThroughoutLineAchievementStrategy

type VisitThroughoutLineAchievementStrategy struct {
	StubAchievementStrategy
}

VisitThroughoutLineAchievementStrategy is an achievement strategy that rewards users when they visit one line from one end to another in a single trip

func (*VisitThroughoutLineAchievementStrategy) CriteriaHTML

CriteriaHTML implements types.PPAchievementStrategy

func (*VisitThroughoutLineAchievementStrategy) HandleTrip

HandleTrip implements types.PPAchievementStrategy

func (*VisitThroughoutLineAchievementStrategy) ID

ID returns the ID for this PPAchievementStrategy

func (*VisitThroughoutLineAchievementStrategy) Progress

func (s *VisitThroughoutLineAchievementStrategy) Progress(context *types.PPAchievementContext) (current, total int, err error)

Progress implements types.PPAchievementStrategy

Jump to

Keyboard shortcuts

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