model

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package model defines common model structures used in many places throughout the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Appeal

type Appeal struct {
	AppealID    int         `db:"appeal_id" json:"appeal_id"`
	BanID       uint64      `db:"ban_id" json:"ban_id"`
	AppealText  string      `db:"appeal_text" json:"appeal_text"`
	AppealState AppealState `db:"appeal_state" json:"appeal_state"`
	Email       string      `db:"email" json:"email"`
	CreatedOn   time.Time   `db:"created_on" json:"created_on"`
	UpdatedOn   time.Time   `db:"updated_on" json:"updated_on"`
}

type AppealState

type AppealState int

AppealState is the current state of a users ban appeal, if any.

const (
	// ASNew is a user has initiated an appeal
	ASNew AppealState = 0
	// ASDenied the appeal was denied
	ASDenied AppealState = 1
)

type BDIds added in v0.1.8

type BDIds struct {
	FileInfo struct {
		Authors     []string `json:"authors"`
		Description string   `json:"description"`
		Title       string   `json:"title"`
		UpdateURL   string   `json:"update_url"`
	} `json:"file_info"`
	Schema  string `json:"$schema"`
	Players []struct {
		Steamid    int64    `json:"steamid"`
		Attributes []string `json:"attributes"`
		LastSeen   struct {
			PlayerName string `json:"player_name"`
			Time       int    `json:"time"`
		} `json:"last_seen"`
	} `json:"players"`
	Version int `json:"version"`
}

type Ban

type Ban struct {
	BanID uint64 `db:"ban_id" json:"ban_id"`
	// SteamID is the steamID of the banned person
	SteamID  steamid.SID64 `db:"steam_id" json:"steam_id"`
	AuthorID steamid.SID64 `db:"author_id" json:"author_id"`
	// Reason defines the overall ban classification
	BanType BanType `db:"ban_type" json:"ban_type"`
	// Reason defines the overall ban classification
	Reason Reason `db:"reason" json:"reason"`
	// ReasonText is returned to the client when kicked trying to join the server
	ReasonText string `db:"reason_text" json:"reason_text"`
	// Note is a supplementary note added by admins that is hidden from normal view
	Note   string `db:"note" json:"note"`
	Source Origin `json:"ban_source" db:"ban_source"`
	// ValidUntil is when the ban will be no longer valid. 0 denotes forever
	ValidUntil time.Time `json:"valid_until" db:"valid_until"`
	CreatedOn  time.Time `db:"created_on" json:"created_on"`
	UpdatedOn  time.Time `db:"updated_on" json:"updated_on"`
}

func NewBan

func NewBan(steamID steamid.SID64, authorID steamid.SID64, duration time.Duration) Ban

func (Ban) String

func (b Ban) String() string

type BanASN added in v0.1.8

type BanASN struct {
	BanASNId   int64
	ASNum      int64
	Origin     Origin
	AuthorID   steamid.SID64
	TargetID   steamid.SID64
	Reason     string
	ValidUntil time.Time
	CreatedOn  time.Time
	UpdatedOn  time.Time
}

func NewBanASN added in v0.1.8

func NewBanASN(asn int64, authorId steamid.SID64, reason string, duration time.Duration) BanASN

type BanNet

type BanNet struct {
	NetID      int64         `db:"net_id"`
	SteamID    steamid.SID64 `db:"steam_id"`
	AuthorID   steamid.SID64 `db:"author_id"`
	CIDR       *net.IPNet    `db:"cidr"`
	Source     Origin        `db:"source"`
	Reason     string        `db:"reason"`
	CreatedOn  time.Time     `db:"created_on" json:"created_on"`
	UpdatedOn  time.Time     `db:"updated_on" json:"updated_on"`
	ValidUntil time.Time     `db:"valid_until"`
}

func NewBanNet

func NewBanNet(cidr string, reason string, duration time.Duration, source Origin) (BanNet, error)

func (BanNet) String

func (b BanNet) String() string

type BanType

type BanType int

BanType defines the state of the ban for a user, 0 being no ban

const (
	// Unknown means the ban state could not be determined, failing-open to allowing players
	// to connect.
	Unknown BanType = -1
	// OK Ban state is clean
	OK BanType = 0
	// NoComm means the player cannot communicate while playing voice + chat
	NoComm BanType = 1
	// Banned means the player cannot join the server at all
	Banned BanType = 2
)

type BannedPerson

type BannedPerson struct {
	Ban                Ban               `json:"ban"`
	Person             Person            `json:"person"`
	HistoryChat        []logparse.SayEvt `json:"history_chat" db:"-"`
	HistoryPersonaName []string          `json:"history_personaname" db:"-"`
	HistoryConnections []string          `json:"history_connections" db:"-"`
	HistoryIP          []PersonIPRecord  `json:"history_ip" db:"-"`
}

func NewBannedPerson

func NewBannedPerson() BannedPerson

type ChatLog

type ChatLog struct {
	Message   string
	CreatedOn time.Time
}

type DemoFile added in v0.1.8

type DemoFile struct {
	DemoID    int64     `json:"demo_id"`
	ServerID  int64     `json:"server_id"`
	Title     string    `json:"title"`
	Data      []byte    `json:"-"` // Dont send mega data to frontend by accident
	CreatedOn time.Time `json:"created_on"`
	Size      int64     `json:"size"`
	Downloads int64     `json:"downloads"`
}

func NewDemoFile added in v0.1.8

func NewDemoFile(serverId int64, title string, rawData []byte) (DemoFile, error)

type Filter added in v0.1.6

type Filter struct {
	WordID    int
	Pattern   *regexp.Regexp
	CreatedOn time.Time
}

func (*Filter) Match added in v0.1.6

func (f *Filter) Match(value string) bool

type IPRecord

type IPRecord struct {
	IPAddr    net.IP    `json:"ip_addr"`
	CreatedOn time.Time `json:"created_on"`
}

type LogQueryOpts added in v0.1.8

type LogQueryOpts struct {
	LogTypes  []logparse.MsgType `json:"log_types"`
	Limit     uint64             `json:"limit"`
	OrderDesc bool               `json:"order_desc"`
	Query     string             `json:"query"`
	SourceID  string             `json:"source_id"`
	TargetID  string             `json:"target_id"`
	Servers   []int              `json:"servers"`
}

func (*LogQueryOpts) ValidRecordType added in v0.1.8

func (lqo *LogQueryOpts) ValidRecordType(t logparse.MsgType) bool

type Origin added in v0.1.8

type Origin int

Origin defines the origin of the ban or action

const (
	// System is an automatic ban triggered by the service
	System Origin = 0
	// Bot is a ban using the discord bot interface
	Bot Origin = 1
	// Web is a ban using the web-ui
	Web Origin = 2
	// InGame is a ban using the sourcemod plugin
	InGame Origin = 3
)

func (Origin) String added in v0.1.8

func (s Origin) String() string

type Person

type Person struct {
	SteamID          steamid.SID64 `db:"steam_id" json:"steam_id"`
	Name             string        `db:"name" json:"name"`
	CreatedOn        time.Time     `db:"created_on" json:"created_on"`
	UpdatedOn        time.Time     `db:"updated_on" json:"updated_on"`
	PermissionLevel  Privilege     `db:"permission_level" json:"permission_level"`
	IsNew            bool          `db:"-" json:"-"`
	DiscordID        string        `db:"discord_id" json:"discord_id"`
	IPAddr           net.IP        `db:"ip_addr" json:"ip_addr"`
	CommunityBanned  bool
	VACBans          int
	GameBans         int
	EconomyBan       string
	DaysSinceLastBan int
	*steamweb.PlayerSummary
}

func NewPerson

func NewPerson(sid64 steamid.SID64) Person

NewPerson allocates a new default person instance

func (*Person) LoggedIn

func (p *Person) LoggedIn() bool

LoggedIn checks for a valid steamID

type PersonIPRecord added in v0.1.6

type PersonIPRecord struct {
	IP          net.IP
	CreatedOn   time.Time
	CityName    string
	CountryName string
	CountryCode string
	ASName      string
	ASNum       int
	ISP         string
	UsageType   string
	Threat      string
	DomainUsed  string
}

PersonIPRecord holds a composite result of the more relevant ip2location results

type PlayerInfo added in v0.1.6

type PlayerInfo struct {
	Player  *extra.Player
	Server  *Server
	SteamID steamid.SID64
	InGame  bool
	Valid   bool
}

func NewPlayerInfo added in v0.1.8

func NewPlayerInfo() PlayerInfo

type Privilege added in v0.1.2

type Privilege uint8
const (
	PGuest         Privilege = 1
	PBanned        Privilege = 2 // Logged in, but is banned
	PAuthenticated Privilege = 10
	PModerator     Privilege = 50
	PAdmin         Privilege = 100
)

type RawLogEvent added in v0.1.8

type RawLogEvent struct {
	LogID     int64             `json:"log_id"`
	Type      logparse.MsgType  `json:"event_type"`
	Event     map[string]string `json:"event"`
	Server    Server            `json:"server"`
	Player1   *Person           `json:"player1"`
	Player2   *Person           `json:"player2"`
	Assister  *Person           `json:"assister"`
	RawEvent  string            `json:"raw_event"`
	CreatedOn time.Time         `json:"created_on"`
}

RawLogEvent represents a full representation of a server log entry including all meta data attached to the log.

func (*RawLogEvent) Unmarshal added in v0.1.8

func (e *RawLogEvent) Unmarshal(output interface{}) error

Unmarshal is just a helper to

type Reason

type Reason int

Reason defined a set of predefined ban reasons TODO make this fully dynamic?

const (
	Custom           Reason = 1
	External         Reason = 2
	Cheating         Reason = 3
	Racism           Reason = 4
	Harassment       Reason = 5
	Exploiting       Reason = 6
	WarningsExceeded Reason = 7
	Spam             Reason = 8
	Language         Reason = 9
)

func (Reason) String

func (r Reason) String() string

type Server

type Server struct {
	// Auto generated id
	ServerID int64 `db:"server_id" json:"server_id"`
	// ServerName is a short reference name for the server eg: us-1
	ServerName     string `db:"short_name" json:"server_name"`
	ServerNameLong string `db:"server_name_long" json:"server_name_long"`
	// Token is the current valid authentication token that the server uses to make authenticated requests
	Token string `db:"token" json:"token"`
	// Address is the ip of the server
	Address string `db:"address" json:"address"`
	// Port is the port of the server
	Port int `db:"port" json:"port"`
	// RCON is the RCON password for the server
	RCON          string `db:"rcon" json:"-"`
	ReservedSlots int    `db:"reserved_slots" json:"reserved_slots"`
	// Password is what the server uses to generate a token to make authenticated calls
	Password   string              `db:"password" json:"password"`
	IsEnabled  bool                `json:"is_enabled"`
	Deleted    bool                `json:"deleted"`
	Region     string              `json:"region"`
	CC         string              `json:"cc"`
	Location   ip2location.LatLong `json:"location"`
	DefaultMap string              `json:"default_map"`
	// TokenCreatedOn is set when changing the token
	TokenCreatedOn time.Time `db:"token_created_on" json:"token_created_on"`
	CreatedOn      time.Time `db:"created_on" json:"created_on"`
	UpdatedOn      time.Time `db:"updated_on" json:"updated_on"`
}

func NewServer added in v0.1.6

func NewServer(name string, address string, port int) Server

func (Server) Addr

func (s Server) Addr() string

func (Server) Slots

func (s Server) Slots(statusSlots int) int

type ServerEvent added in v0.1.8

type ServerEvent struct {
	LogID       int64                `json:"log_id"`
	Server      *Server              `json:"server"`
	EventType   logparse.MsgType     `json:"event_type"`
	Source      *Person              `json:"source"`
	Target      *Person              `json:"target"`
	PlayerClass logparse.PlayerClass `json:"class"`
	Weapon      logparse.Weapon      `json:"weapon"`
	Damage      int                  `json:"damage"`
	Item        logparse.PickupItem  `json:"item"`
	AttackerPOS logparse.Pos         `json:"attacker_pos"`
	VictimPOS   logparse.Pos         `json:"victim_pos"`
	AssisterPOS logparse.Pos         `json:"assister_pos"`
	Extra       string               `json:"extra"`
	CreatedOn   time.Time            `json:"created_on"`
}

ServerEvent is a flat struct encapsulating a parsed log event Fields being present is event dependent, so do not assume everything will be available

type ServerState added in v0.1.8

type ServerState struct {
	NameLong    string
	Name        string
	Host        string
	Enabled     bool
	Region      string
	CountryCode string
	Reserved    int
	A2S         a2s.ServerInfo
	Status      extra.Status
	Players     []extra.Player
	LastUpdate  time.Time
}

type ServerStateCollection added in v0.1.8

type ServerStateCollection map[string]ServerState

TODO move findPlayerBy* methods to here

func (ServerStateCollection) ByName added in v0.1.8

func (c ServerStateCollection) ByName(name string, state *ServerState) bool

func (ServerStateCollection) ByRegion added in v0.1.8

func (c ServerStateCollection) ByRegion() map[string][]ServerState

type Stats

type Stats struct {
	BansTotal     int `json:"bans"`
	BansDay       int `json:"bans_day"`
	BansWeek      int `json:"bans_week"`
	BansMonth     int `json:"bans_month"`
	Bans3Month    int `json:"bans_3month"`
	Bans6Month    int `json:"bans_6month"`
	BansYear      int `json:"bans_year"`
	BansCIDRTotal int `json:"bans_cidr"`
	AppealsOpen   int `json:"appeals_open"`
	AppealsClosed int `json:"appeals_closed"`
	FilteredWords int `json:"filtered_words"`
	ServersAlive  int `json:"servers_alive"`
	ServersTotal  int `json:"servers_total"`
}

Jump to

Keyboard shortcuts

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