util

package
v0.0.0-...-bce320a Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Config holds the main configuration file
	Config *ConfigurationFile

	// VERSION current version of the build
	VERSION string

	// BUILD_DATE date of the build
	BUILD_DATE string
)
View Source
var (
	// OTBMap holds the main server map parsed using otmap library
	OTBMap = CastroMapInstance{}

	// ServerHouseList holds the main server house list XML list
	ServerHouseList = ServerHouses{
		List: &HouseList{},
	}
)
View Source
var (
	// Template holds all the app templates
	Template Tmpl

	// FuncMap holds the main FuncMap definition
	FuncMap template.FuncMap

	// TemplateHooks holds the hook types available
	TemplateHooks = [...]string{
		"head",
		"beforeContent",
		"afterContent",
		"footer",
		"scriptIncludes",
	}
)
View Source
var Cache *c.Cache

Cache variable that holds the main cache instance of the application

View Source
var (
	// ExtensionStatic holds all extension subtopic static folders
	ExtensionStatic = &StaticList{
		list: map[string]http.FileSystem{},
	}
)
View Source
var LanguageFiles = &LanguageHolder{
	List: map[string]*Language{},
	rw:   sync.RWMutex{},
}

LanguageFiles global language holder

View Source
var (
	// Logger main application logging entry point
	Logger = &ApplicationLogger{}
)
View Source
var MonstersList = []*Monster{}
View Source
var ServerVocationList = ServerVocations{
	List: &VocationList{},
}

ServerVocationList holds all the vocations of the server

SessionStore main application session storage

Functions

func CreateLogFile

func CreateLogFile() (*os.File, time.Time, error)

CreateLogFile creates a log file with the current time

func CreateLogger

func CreateLogger(out io.Writer) *logrus.Logger

CreateLogger creates a new logrus logger with the given output

func EncodeConfig

func EncodeConfig(configFile io.Writer, c *Configuration) error

EncodeConfig encodes the given io writer

func EncodeMap

func EncodeMap(path string) ([]byte, error)

EncodeMap encodes the server map

func GenerateOutfitImage

func GenerateOutfitImage(t, feet, legs, body, head, addons int) ([]byte, error)

GenerateOutfitImage generates an outfit image for the given values

func GetLuaFiles

func GetLuaFiles(dir string) ([]string, error)

GetLuaFiles walks the given path and returns all lua files

func LoadConfig

func LoadConfig(path string) error

LoadConfig loads the configuration file to the given interface pointer

func LoadExternalConfigFiles

func LoadExternalConfigFiles() ([]string, error)

LoadExternalConfigFiles returns a list of external config lua files

func LoadServerMonsters

func LoadServerMonsters(path string) error

LoadServerMonsters loads the server monsters and sets the variable

func LoadVocations

func LoadVocations(file string, list ServerVocations) error

LoadVocations parses the vocations xml file

func Loadi18n

func Loadi18n(path string) error

func RenewLogger

func RenewLogger()

RenewLogger runs a routine to check if the logger needs to be renewed if true a new logger file is created

func SessionCookie

func SessionCookie(v string) *http.Cookie

SessionCookie returns a session cookie pointer

func VerifyCaptcha

func VerifyCaptcha(answer string) (bool, error)

VerifyCaptcha checks if the given captcha answer is valid

Types

type ApplicationLogger

type ApplicationLogger struct {

	// Logger main logger instance of the app
	Logger *logrus.Logger

	// LoggerOutput output file
	LoggerOutput *os.File

	// LastLoggerDay save last day the logger was created
	LastLoggerDay time.Time
	// contains filtered or unexported fields
}

ApplicationLogger struct for application logging to files

type CacheConfig

type CacheConfig struct {
	Default StringDuration
	Purge   StringDuration
}

CacheConfig struct used for the cache configuration options

type CaptchaConfig

type CaptchaConfig struct {
	Enabled bool
	Public  string
	Secret  string
}

CaptchaConfig struct used for the TOML configuration file

type CastroMap

type CastroMap struct {
	Towns     []otmap.Town
	HouseFile string
}

CastroMap struct used to decode and encode tibia maps

func DecodeMap

func DecodeMap(mapData []byte) (*CastroMap, error)

DecodeMap decodes the server map to the given destination

type CastroMapInstance

type CastroMapInstance struct {
	Map *CastroMap
	// contains filtered or unexported fields
}

CastroMapInstance struct used to hold the server map data

func (*CastroMapInstance) Load

func (c *CastroMapInstance) Load(m *CastroMap)

Load sets the map pointer

type ConfigTown

type ConfigTown struct {
	Name string
	ID   uint32
}

ConfigTown struct used to manually populate the server map information

type Configuration

type Configuration struct {
	CheckUpdates bool
	LoadMap      bool
	MapHouseFile string
	Towns        []ConfigTown
	Template     string
	Mode         string
	Port         int
	URL          string
	Datapack     string
	MapWatch     MapWatchConfig
	Security     SecurityConfig
	Plugin       PluginConfig
	Mail         MailConfig
	Captcha      CaptchaConfig
	SSL          SSLConfig
	PayPal       PayPalConfig
	PayGol       PaygolConfig
	Fortumo      FortumoConfig
	Shop         ShopConfig
	Cookies      CookieConfig
	Cache        CacheConfig
	RateLimit    RateLimiterConfig
	Static       StaticConfig
	Custom       map[string]interface{}
}

Configuration struct used for the main Castro config file TOML file

func (Configuration) CSP

func (c Configuration) CSP(nonce string) string

CSP returns a valid Content-Security-Policy header value

func (Configuration) IsDev

func (c Configuration) IsDev() bool

IsDev checks if castro is running on development mode

func (Configuration) IsLog

func (c Configuration) IsLog() bool

IsLog checks if castro is running on log mode

func (Configuration) IsSSL

func (c Configuration) IsSSL() bool

IsSSL returns if the server is behind SSL

type ConfigurationFile

type ConfigurationFile struct {
	Configuration *Configuration
	// contains filtered or unexported fields
}

ConfigurationFile struct used to store a configuration pointer

func (*ConfigurationFile) GetCustomValue

func (c *ConfigurationFile) GetCustomValue(key string) interface{}

GetCustomValue returns a custom config value

func (*ConfigurationFile) SetCustomValue

func (c *ConfigurationFile) SetCustomValue(key string, v interface{})

SetCustomValue sets a config custom value

type ContentSecurityPolicyConfig

type ContentSecurityPolicyConfig struct {
	Default []string
	Enabled bool
	Frame   ContentSecurityPolicyType
	Script  ContentSecurityPolicyType
	Font    ContentSecurityPolicyType
	Image   ContentSecurityPolicyType
	Connect ContentSecurityPolicyType
	Style   ContentSecurityPolicyType
}

ContentSecurityPolicyConfig struct used for CSP headers

type ContentSecurityPolicyType

type ContentSecurityPolicyType struct {
	Default []string
	SRC     []string
}

ContentSecurityPolicyType struct used for CSP fields

type CookieConfig

type CookieConfig struct {
	Name     string
	MaxAge   int
	HashKey  string
	BlockKey string
}

CookieConfig struct used for the cookies configuration options

type FortumoConfig

type FortumoConfig struct {
	Enabled bool
	Service string
	Secret  string
}

FortumoConfig struct used for the fortumo configuration options

type House

type House struct {
	ID     uint32 `xml:"houseid,attr"`
	Name   string `xml:"name,attr"`
	EntryX uint16 `xml:"entryx,attr"`
	EntryY uint16 `xml:"entryy,attr"`
	EntryZ uint16 `xml:"entryz,attr"`
	Size   int    `xml:"size,attr"`
	TownID uint32 `xml:"townid,attr"`
}

House holds all information about a game house

type HouseList

type HouseList struct {
	XMLName xml.Name `xml:"houses"`
	Houses  []*House `xml:"house"`
}

HouseList holds the house array

type Language

type Language struct {
	Name string
	Data map[string]string
}

Language represents a i18n language file

type LanguageHolder

type LanguageHolder struct {
	List map[string]*Language
	// contains filtered or unexported fields
}

func (*LanguageHolder) Get

func (l *LanguageHolder) Get(lang string) (*Language, bool)

Get retrieves the given language

type MailConfig

type MailConfig struct {
	Enabled  bool
	Server   string
	Port     int
	Username string
	Password string
}

MailConfig struct used for the mail configuration options

type MapWatchConfig

type MapWatchConfig struct {
	Enabled bool
	Check   StringDuration
}

MapWatchConfig map watcher goroutine configuration options

type Monster

type Monster struct {
	XMLName      xml.Name            `xml:"monster"`
	Name         string              `xml:"name,attr"`
	Description  string              `xml:"nameDescription,attr"`
	Race         string              `xml:"race,attr"`
	Experience   int                 `xml:"experience,attr"`
	Speed        int                 `xml:"speed,attr"`
	ManaCost     int                 `xml:"manacost,attr"`
	Health       MonsterHealth       `xml:"health"`
	Look         MonsterLook         `xml:"look"`
	TargetChange MonsterTargetChange `xml:"targetchange"`
	Attacks      MonsterAttackList   `xml:"attacks"`
	Defenses     MonsterDefenseList  `xml:"defenses"`
	Voices       MonsterVoiceList    `xml:"voices"`
	Loot         MonsterLootList     `xml:"loot"`
	Elements     MonsterElements     `xml:"elements>element"`
	Immunities   MonsterImmunities   `xml:"immunities>immunity"`
	Flags        MonsterFlagList     `xml:"flags>flag"`
}

Monster defines a server cerature

func LoadMonster

func LoadMonster(path string) (*Monster, error)

LoadMonster loads the given monster xml file

type MonsterAttack

type MonsterAttack struct {
	XMLName    xml.Name           `xml:"attack"`
	Name       string             `xml:"name,attr"`
	Interval   int                `xml:"interval,attr"`
	Range      int                `xml:"range,attr"`
	Min        int                `xml:"min,attr"`
	Max        int                `xml:"max,attr"`
	Target     int                `xml:"target,attr"`
	Attributes []MonsterAttribute `xml:"attribute"`
}

MonsterAttack defines a monster attack

type MonsterAttackList

type MonsterAttackList struct {
	Attacks []MonsterAttack `xml:"attack"`
}

MonsterAttackList defines a list of monster attacks

type MonsterAttribute

type MonsterAttribute struct {
	XMLName xml.Name `xml:"attribute"`
	Key     string   `xml:"key,attr"`
	Value   string   `xml:"value,attr"`
}

MonsterAttribute defines a monster attribute

type MonsterDefense

type MonsterDefense struct {
	Name       string             `xml:"name,attr"`
	Interval   int                `xml:"interval,attr"`
	Chance     int                `xml:"chance,attr"`
	Min        int                `xml:"min,attr"`
	Max        int                `xml:"max,attr"`
	Attributes []MonsterAttribute `xml:"attribute"`
}

MonsterDefense defines a monster defense value

type MonsterDefenseList

type MonsterDefenseList struct {
	Armor    int              `xml:"armor,attr"`
	Defense  int              `xml:"defense,attr"`
	Defenses []MonsterDefense `xml:"defense"`
}

MonsterDefenseList defines a monster defense list

type MonsterElements

type MonsterElements struct {
	Ice      int `xml:"icePercent,attr"`
	Earth    int `xml:"earthPercent,attr"`
	Energy   int `xml:"energyPercent,attr"`
	Fire     int `xml:"firePercent,attr"`
	Holy     int `xml:"holyPercent,attr"`
	Physical int `xml:"physicalPercent,attr"`
	Death    int `xml:"deathPercent,attr"`
}

type MonsterFlagList

type MonsterFlagList struct {
	Summonable       int `xml:"summonable,attr"`
	Attackable       int `xml:"attackable,attr"`
	Hostile          int `xml:"hostile,attr"`
	Illusionable     int `xml:"illusionable,attr"`
	Convinceable     int `xml:"convinceable,attr"`
	Pushable         int `xml:"pushable,attr"`
	CanPushItems     int `xml:"canpushitems,attr"`
	CanPushCreatures int `xml:"canpushcreatures,attr"`
	TargetDistance   int `xml:"targetdistance,attr"`
	StaticAttack     int `xml:"staticattack,attr"`
	RunonHealth      int `xml:"runonhealth,attr"`
	IsBoss           int `xml:"isboss,attr"`
}

type MonsterHealth

type MonsterHealth struct {
	XMLName xml.Name `xml:"health"`
	Now     int      `xml:"now,attr"`
	Max     int      `xml:"max,attr"`
}

MonsterHealth defines the monster health values

type MonsterImmunities

type MonsterImmunities struct {
	Ice      int `xml:"ice,attr"`
	Earth    int `xml:"earth,attr"`
	Energy   int `xml:"energy,attr"`
	Fire     int `xml:"fire,attr"`
	Holy     int `xml:"holy,attr"`
	Physical int `xml:"physical,attr"`
	Death    int `xml:"death,attr"`
	Drown    int `xml:"drown,attr"`
}

type MonsterItem

type MonsterItem struct {
	XMLName  xml.Name `xml:"item"`
	ID       int      `xml:"id,attr"`
	Name     string   `xml:"name,attr"`
	CountMax int      `xml:"countmax,attr"`
	Chance   int      `xml:"chance,attr"`
}

MonsterItem defines a monster lootable item

type MonsterList

type MonsterList struct {
	XMLName  xml.Name             `xml:"monsters"`
	Monsters []monsterListElement `xml:"monster"`
}

MonsterList defines the monsters.xml file

func LoadMonsterList

func LoadMonsterList(path string) (*MonsterList, error)

LoadMonsterList loads the monsters.xml file

type MonsterLook

type MonsterLook struct {
	XMLName xml.Name `xml:"look"`
	Type    int      `xml:"type,attr"`
	Addons  int      `xml:"addons,attr"`
	Head    int      `xml:"head,attr"`
	Body    int      `xml:"body,attr"`
	Legs    int      `xml:"legs,attr"`
	Feet    int      `xml:"feet,attr"`
	Corpse  int      `xml:"corpse,attr"`
}

MonsterLook defines the monster looktype values

type MonsterLootList

type MonsterLootList struct {
	Loot []MonsterItem `xml:"item"`
}

MonsterLootList defines a list of monster lootable items

type MonsterTargetChange

type MonsterTargetChange struct {
	XMLName  xml.Name `xml:"targetchange"`
	Interval int      `xml:"interval,attr"`
	Chance   int      `xml:"chance,attr"`
}

MonsterTargetChange defines the monster targetting change values

type MonsterVoice

type MonsterVoice struct {
	XMLName  xml.Name `xml:"voice"`
	Sentence string   `xml:"sentence,attr"`
	Yell     int      `xml:"yell,attr"`
}

MonsterVoice defines a monster sentence

type MonsterVoiceList

type MonsterVoiceList struct {
	Interval int            `xml:"interval,attr"`
	Chance   int            `xml:"chance,attr"`
	Voices   []MonsterVoice `xml:"voice"`
}

MonsterVoiceList defines a list of monster voices

type PayPalConfig

type PayPalConfig struct {
	Enabled   bool
	PublicKey string
	SecretKey string
	Currency  string
	SandBox   bool
}

PayPalConfig struct used for the paypal configuration options

type PaygolConfig

type PaygolConfig struct {
	Enabled  bool
	Service  int
	Currency string
	Language string
	Secret   string
}

PaygolConfig struct used for the paygol configuration options

type PluginConfig

type PluginConfig struct {
	Enabled bool
	Origin  string
}

PluginConfig struct used for the plugin listener

type RateLimiterConfig

type RateLimiterConfig struct {
	Enabled bool
	Number  int64
	Time    StringDuration
}

RateLimiterConfig struct used for the rate limiting configuration options

type SSLConfig

type SSLConfig struct {
	Enabled bool
	Auto    bool
	Proxy   bool
	Cert    string
	Key     string
}

SSLConfig struct used for the ssl configuration options

type SecurityConfig

type SecurityConfig struct {
	NonceEnabled      bool
	XSS               string
	STS               string
	Frame             string
	ContentType       string
	ReferrerPolicy    string
	CrossDomainPolicy string
	CSP               ContentSecurityPolicyConfig
}

SecurityConfig struct used for the security of the application

type ServerHouses

type ServerHouses struct {
	List *HouseList
	// contains filtered or unexported fields
}

ServerHouses contains the whole house list of the server

func (*ServerHouses) LoadHouses

func (s *ServerHouses) LoadHouses(file string) error

LoadHouses parses the server map houses

type ServerVocations

type ServerVocations struct {
	List *VocationList
}

ServerVocations contains the list of the server vocations

type ShopConfig

type ShopConfig struct {
	Enabled bool
}

ShopConfig struct used for the shop configuration options

type StaticConfig

type StaticConfig struct {
	Enabled   bool
	Directory string
}

StaticConfig struct used for the static asset handler options

type StaticList

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

StaticList struct used to hold static lists

func (*StaticList) FileExists

func (e *StaticList) FileExists(id string) (http.FileSystem, bool)

FileExists checks if the given resource exists

func (*StaticList) Load

func (e *StaticList) Load(d string) error

Load loads all the static resources from the enabled extensions

type StringDuration

type StringDuration struct {
	Duration time.Duration
	String   string
}

StringDuration struct used to convert strings to time duration during config encoding or vice-versa

func NewStringDuration

func NewStringDuration(s string) StringDuration

NewStringDuration returns a new string duration struct

func (StringDuration) MarshalText

func (s StringDuration) MarshalText() ([]byte, error)

MarshalText use toml interface to convert string durations to strings

func (*StringDuration) UnmarshalText

func (s *StringDuration) UnmarshalText(text []byte) error

UnmarshalText use toml interface to convert strings to durations

type Tmpl

type Tmpl struct {
	Tmpl *template.Template
	// contains filtered or unexported fields
}

Tmpl struct that holds an application template wrapper for the Go template used in the lua bindings

var (
	// WidgetTemplate holds all the widget templates
	WidgetTemplate Tmpl

	// Widgets holds all the widget results
	Widgets = WidgetList{
			// contains filtered or unexported fields
	}
)

func NewTemplate

func NewTemplate(name string) Tmpl

NewTemplate creates and returns a new tmpl instance

func (*Tmpl) FuncMap

func (t *Tmpl) FuncMap(f template.FuncMap)

FuncMap returns the template map of functions

func (*Tmpl) LoadExtensionTemplates

func (t *Tmpl) LoadExtensionTemplates(extType string) error

LoadExtensionTemplates parses and loads all extension templates

func (Tmpl) LoadTemplateHooks

func (t Tmpl) LoadTemplateHooks()

func (*Tmpl) LoadTemplates

func (t *Tmpl) LoadTemplates(dir string) error

LoadTemplates parses and loads all template files

func (Tmpl) Render

func (t Tmpl) Render(wr io.Writer, name string, args interface{}) error

Render executes the given template. if the app is running on dev mode all the templates will be reloaded

func (Tmpl) RenderTemplate

func (t Tmpl) RenderTemplate(w http.ResponseWriter, req *http.Request, name string, args map[string]interface{})

RenderTemplate render the given template passing some values and loading all templates if in development mode

func (Tmpl) RenderWidget

func (t Tmpl) RenderWidget(req *http.Request, name string, args map[string]interface{}) (*bytes.Buffer, error)

RenderWidget renders the given widget template

func (Tmpl) TemplateHook

func (t Tmpl) TemplateHook(hookName string) error

type Vocation

type Vocation struct {
	ID          int    `xml:"id,attr"`
	Name        string `xml:"name,attr"`
	Description string `xml:"description,attr"`
	FromVoc     int    `xml:"fromvoc,attr"`
}

Vocation holds all information about a game vocation

type VocationList

type VocationList struct {
	XMLName   xml.Name    `xml:"vocations"`
	Vocations []*Vocation `xml:"vocation"`
}

VocationList golds the XML list of the vocation list

type Widget

type Widget struct {
	Name   string
	Result template.HTML
	// contains filtered or unexported fields
}

Widget is an application sidebar content

func (*Widget) Execute

func (w *Widget) Execute(luaState *glua.LState) error

Execute gets the result of the given widget

func (*Widget) IsCached

func (w *Widget) IsCached() (template.HTML, bool)

IsCached checks if the given widget is cached

type WidgetList

type WidgetList struct {
	List []*Widget
	// contains filtered or unexported fields
}

WidgetList the list of widget application

func (*WidgetList) Load

func (w *WidgetList) Load(path string) error

Load loads all the widgets from the given directory

func (*WidgetList) LoadExtensions

func (w *WidgetList) LoadExtensions() error

LoadExtensions loads all the extension widgets

func (*WidgetList) UnloadExtensionWidget

func (w *WidgetList) UnloadExtensionWidget(widgetName string) error

UnloadExtensionWidget removes a widget extension from the list

Jump to

Keyboard shortcuts

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