Documentation ¶
Index ¶
- Variables
- func CreateLogFile() (*os.File, time.Time, error)
- func CreateLogger(out io.Writer) *logrus.Logger
- func EncodeConfig(configFile io.Writer, c *Configuration) error
- func EncodeMap(path string) ([]byte, error)
- func GenerateOutfitImage(t, feet, legs, body, head, addons int) ([]byte, error)
- func GetLuaFiles(dir string) ([]string, error)
- func LoadConfig(path string) error
- func LoadExternalConfigFiles() ([]string, error)
- func LoadServerMonsters(path string) error
- func LoadVocations(file string, list ServerVocations) error
- func Loadi18n(path string) error
- func RenewLogger()
- func SessionCookie(v string) *http.Cookie
- func VerifyCaptcha(answer string) (bool, error)
- type ApplicationLogger
- type CacheConfig
- type CaptchaConfig
- type CastroMap
- type CastroMapInstance
- type ConfigTown
- type Configuration
- type ConfigurationFile
- type ContentSecurityPolicyConfig
- type ContentSecurityPolicyType
- type CookieConfig
- type FortumoConfig
- type House
- type HouseList
- type Language
- type LanguageHolder
- type MailConfig
- type MapWatchConfig
- type Monster
- type MonsterAttack
- type MonsterAttackList
- type MonsterAttribute
- type MonsterDefense
- type MonsterDefenseList
- type MonsterElements
- type MonsterFlagList
- type MonsterHealth
- type MonsterImmunities
- type MonsterItem
- type MonsterList
- type MonsterLook
- type MonsterLootList
- type MonsterTargetChange
- type MonsterVoice
- type MonsterVoiceList
- type PayPalConfig
- type PaygolConfig
- type PluginConfig
- type RateLimiterConfig
- type SSLConfig
- type SecurityConfig
- type ServerHouses
- type ServerVocations
- type ShopConfig
- type StaticConfig
- type StaticList
- type StringDuration
- type Tmpl
- func (t *Tmpl) FuncMap(f template.FuncMap)
- func (t *Tmpl) LoadExtensionTemplates(extType string) error
- func (t Tmpl) LoadTemplateHooks()
- func (t *Tmpl) LoadTemplates(dir string) error
- func (t Tmpl) Render(wr io.Writer, name string, args interface{}) error
- func (t Tmpl) RenderTemplate(w http.ResponseWriter, req *http.Request, name string, ...)
- func (t Tmpl) RenderWidget(req *http.Request, name string, args map[string]interface{}) (*bytes.Buffer, error)
- func (t Tmpl) TemplateHook(hookName string) error
- type Vocation
- type VocationList
- type Widget
- type WidgetList
Constants ¶
This section is empty.
Variables ¶
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 )
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{}, } )
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", } )
var Cache *c.Cache
Cache variable that holds the main cache instance of the application
var ( // ExtensionStatic holds all extension subtopic static folders ExtensionStatic = &StaticList{ list: map[string]http.FileSystem{}, } )
var LanguageFiles = &LanguageHolder{ List: map[string]*Language{}, rw: sync.RWMutex{}, }
LanguageFiles global language holder
var ( // Logger main application logging entry point Logger = &ApplicationLogger{} )
var MonstersList = []*Monster{}
var ServerVocationList = ServerVocations{ List: &VocationList{}, }
ServerVocationList holds all the vocations of the server
var SessionStore *securecookie.SecureCookie
SessionStore main application session storage
Functions ¶
func CreateLogFile ¶
CreateLogFile creates a log file with the current time
func CreateLogger ¶
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 GenerateOutfitImage ¶
GenerateOutfitImage generates an outfit image for the given values
func GetLuaFiles ¶
GetLuaFiles walks the given path and returns all lua files
func LoadConfig ¶
LoadConfig loads the configuration file to the given interface pointer
func LoadExternalConfigFiles ¶
LoadExternalConfigFiles returns a list of external config lua files
func LoadServerMonsters ¶
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 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 ¶
SessionCookie returns a session cookie pointer
func VerifyCaptcha ¶
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 ¶
CaptchaConfig struct used for the TOML configuration file
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 ¶
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 ¶
ContentSecurityPolicyType struct used for CSP fields
type CookieConfig ¶
CookieConfig struct used for the cookies configuration options
type FortumoConfig ¶
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 LanguageHolder ¶
type MailConfig ¶
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 ¶
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 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 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 ¶
PaygolConfig struct used for the paygol configuration options
type PluginConfig ¶
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 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 ¶
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 ¶
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 ¶
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 ¶
NewTemplate creates and returns a new tmpl instance
func (*Tmpl) LoadExtensionTemplates ¶
LoadExtensionTemplates parses and loads all extension templates
func (Tmpl) LoadTemplateHooks ¶
func (t Tmpl) LoadTemplateHooks()
func (*Tmpl) LoadTemplates ¶
LoadTemplates parses and loads all template files
func (Tmpl) Render ¶
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 ¶
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 ¶
Widget is an application sidebar content
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