types

package
v0.0.0-...-b6702c2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2018 License: MPL-2.0 Imports: 4 Imported by: 9

Documentation

Overview

Package types simply provides common structures used throughout the application with very little logic outside of examples and validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Name     string `validate:"required,max=24" json:"name"               bson:"name"`
	Pass     string `validate:"required"        json:"pass"               bson:"pass"`
	Ipv4     string `validate:"required"        json:"ipv4"               bson:"ipv4"`
	Gpci     string `validate:"required,len=40" json:"gpci"               bson:"gpci"`
	Archived bool   `validate:"omitempty"       json:"archived,omitempty" bson:"archived"`
}

Account represents player account information such as password hash

type Admin

type Admin struct {
	ID       bson.ObjectId `validate:"omitempty,required,len=12" json:"_id" bson:"_id"`
	PlayerID bson.ObjectId `validate:"required,len=12" json:"player_id" bson:"player_id"`
	Level    *int32        `validate:"required,max=5" json:"level" bson:"level"`
	Date     time.Time     `validate:"omitempty,required" json:"date,omitempty" bson:"date"`
}

Admin represents a player who has been assigned staff role

func ExampleAdmin

func ExampleAdmin() Admin

ExampleAdmin returns an example object of an admin description

type Ban

type Ban struct {
	ID       bson.ObjectId `validate:"omitempty,required,len=12" json:"_id,omitempty" bson:"_id,omitempty"`
	Of       bson.ObjectId `validate:"required,len=12" json:"of_player_id" bson:"of_player_id"`
	By       bson.ObjectId `validate:"omitempty,len=12" json:"by_player_id,omitempty" bson:"by_player_id,omitempty"`
	Ipv4     uint32        `validate:"required" json:"ipv4" bson:"ipv4"`
	Date     time.Time     `validate:"required" json:"date" bson:"date"`
	Reason   string        `validate:"required" json:"reason" bson:"reason"`
	Position Geo           `validate:"required" json:"position" bson:"position"`
	Duration time.Duration `validate:"required" json:"duration" bson:"duration"`
	Archived bool          `validate:"required" json:"archived" bson:"archived"`
}

Ban contains all the information for a banned player

func ExampleBan

func ExampleBan() Ban

ExampleBan returns an example object of a ban record

type Geo

type Geo struct {
	PosX     float32 `json:"posx,omitempty" bson:"posx,omitempty"`
	PosY     float32 `json:"posy,omitempty" bson:"posy,omitempty"`
	PosZ     float32 `json:"posz,omitempty" bson:"posz,omitempty"`
	RotX     float32 `json:"rotx,omitempty" bson:"rotx,omitempty"`
	RotY     float32 `json:"roty,omitempty" bson:"roty,omitempty"`
	RotZ     float32 `json:"rotz,omitempty" bson:"rotz,omitempty"`
	RotW     float32 `json:"rotw,omitempty" bson:"rotw,omitempty"`
	VelX     float32 `json:"velx,omitempty" bson:"velx,omitempty"`
	VelY     float32 `json:"vely,omitempty" bson:"vely,omitempty"`
	VelZ     float32 `json:"velz,omitempty" bson:"velz,omitempty"`
	Interior int32   `json:"interior,omitempty" bson:"interior,omitempty"`
	World    int32   `json:"world,omitempty" bson:"world,omitempty"`
}

Geo represents a set of geographical data to describe a point in the game world. This can be a player, vehicle, item or anything else. It contains fields that are very commonly grouped together such as interior and velocity.

type Player

type Player struct {
	ID      bson.ObjectId `validate:"omitempty,required" json:"_id"     bson:"_id"`
	Account Account       `validate:"required"           json:"account" bson:"account"`
	Spawn   Geo           `                              json:"spawn"   bson:"spawn"`
}

Player represents a player in the game and all their data

Each field (aside from ID) is an object that corresponds to a package in the gamemode that requires persistent storage for a player. When a new package is added, its data structure must first be added here. The structure at first may just be a `map[string]interface{}` for flexibility, however eventually the schema _should_ be defined in some way.

Because this application is used by both Scavenge and Survive and the Sandbox gamemode, there may be fields here that don't apply to both gamemodes and will be left blank if unused.

func ExamplePlayer

func ExamplePlayer() Player

ExamplePlayer returns an example object of a player

type Report

type Report struct {
	ID       bson.ObjectId `validate:"omitempty,required,len=12" json:"_id,omitempty" bson:"_id,omitempty"`
	Of       bson.ObjectId `validate:"required,len=12" json:"of_player_id" bson:"of_player_id"`
	Reason   string        `validate:"required" json:"reason" bson:"reason"`
	By       bson.ObjectId `validate:"omitempty,len=12" json:"by_player_id,omitempty" bson:"by_player_id,omitempty"`
	Date     time.Time     `validate:"required" json:"date" bson:"date"`
	Read     *bool         `validate:"required" json:"read" bson:"read"`
	Type     string        `validate:"required" json:"type" bson:"type"`
	Position Geo           `validate:"required" json:"position" bson:"position"`
	Metadata string        `validate:"omitempty" json:"metadata,omitempty" bson:"metadata,omitempty"`
	Archived *bool         `validate:"required" json:"archived" bson:"archived"`
}

Report represents a behaviour report made against a player

func ExampleReport

func ExampleReport() Report

ExampleReport returns an example report

type Status

type Status struct {
	Result  interface{} `json:"result"`
	Success bool        `json:"success"`
	Message string      `json:"message,omitempty"`
}

Status is a custom status object returned by all endpoints. This is due to the fact that HTTP status codes do not match the use-case of this service so all endpoints will return either 200 or 500 with this object wrapping any response object with a message and error state.

func ExampleStatus

func ExampleStatus(result interface{}, success bool) Status

ExampleStatus returns an example of Status

func NewStatus

func NewStatus(result interface{}, success bool, message string) Status

NewStatus creates and returns a Status always use this in order to ensure all fields are filled message may be left blank however

func NewStatusValidationError

func NewStatusValidationError(ve validator.ValidationErrors) Status

NewStatusValidationError returns a Status from a set of validation errors

type Storer

type Storer interface {
	// Player account interface
	PlayerCreate(player Player) (id bson.ObjectId, err error)
	PlayerGetByName(name string) (player Player, err error)
	PlayerGetByID(id bson.ObjectId) (player Player, err error)
	PlayerUpdate(id bson.ObjectId, player Player) (err error)
	PlayerRemove(id bson.ObjectId) (err error)

	// Admin interface
	AdminSetLevel(id bson.ObjectId, level int32) (err error)
	AdminGetList() (result []Admin, err error)

	// Report interface
	ReportCreate(report Report) (id bson.ObjectId, err error)
	ReportArchive(id bson.ObjectId, archived bool) (err error)
	ReportGetList(pageSize, page int, archived, noRead bool, by, of bson.ObjectId, from, to *time.Time) (result []Report, err error)
	ReportGet(id bson.ObjectId) (result Report, err error)

	// misc
	DeleteEverythingPermanently() error
}

Storer declares a set of CRUD functions for persisting and accessing data

Jump to

Keyboard shortcuts

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