Documentation ¶
Overview ¶
util provides structs and helpers for deciphering OpenTTD game data. Some stuff in here is used by the admin and query packages, but is left in this package in case it's useful to you.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAuthentication = errors.New("authentication failed")
var ErrBadWrite = errors.New("writing to admin port cut short")
var ErrInvalidIncomingPacket = errors.New("received an invalid packet from the server")
var ErrNotConnected = errors.New("not connected to server")
Functions ¶
func DateFormat ¶
DateFormat takes the number of days from the OpenTTD Epoch (the 1st of January 0000) and returns a UTC time object.
Types ¶
type OpenttdCompany ¶
type OpenttdCompany struct { // The company name. Name string `json:"name"` // The year the company was first founded. YearStart uint32 `json:"start_year"` // The value of the company, in credits. Value uint64 `json:"value"` // The amount of disposable cash the company has. Money uint64 `json:"cash"` // The company's current income. Income int64 `json:"income"` // The company's performance index. Maximum score of 1000. Performance uint16 `json:"performance"` // Whether the company has a password set. Passworded bool `json:"is_passworded"` // A count of the vehicles and stations the company has. Vehicles OpenttdTypeCounts `json:"vehicle_count"` Stations OpenttdTypeCounts `json:"station_count"` }
type OpenttdEnvironment ¶
type OpenttdEnvironment uint8
const ( EnvironmentTemperate OpenttdEnvironment = iota EnvironmentArctic EnvironmentTropic EnvironmentToyland )
func (OpenttdEnvironment) String ¶
func (env OpenttdEnvironment) String() string
String returns the string representation of the Environment.
type OpenttdLanguage ¶
type OpenttdLanguage uint8
const ( LanguageAny OpenttdLanguage = iota LanguageEnglish LanguageGerman LanguageFrench LanguageBrazilianPortuguese LanguageBulgarian LanguageChinese LanguageCzech LanguageDanish LanguageDutch LanguageEsperanto LanguageFinnish LanguageHungarian LanguageIcelandic LanguageItalian LanguageJapanese LanguageKorean LanguageLithuanian LanguageNorwegian LanguagePolish LanguagePortuguese LanguageRomanian LanguageRussian LanguageSlovak LanguageSloveninan LanguageSpanish LanguageSwedish LanguageTurkish LanguageUkraninan LanguageAfrikaans LanguageCroatian LanguageCatalan LanguageEstonian LanguageGalican LanguageGreek LanguageLatvian LanguageCount )
func (OpenttdLanguage) String ¶
func (lang OpenttdLanguage) String() string
String returns the string representation of the Language.
func (OpenttdLanguage) Tag ¶
func (lang OpenttdLanguage) Tag() language.Tag
Tag returns a language.Tag corresponding to the given OpenttdLanguage. Important: If a tag is not available (for example, the Any language, or if the language doesn't exist in the text/language library), this will return an empty Tag{}.
type OpenttdNewgrf ¶
type OpenttdServerState ¶
type OpenttdServerState struct { // Status is set to True if the server was parsable, false otherwise. Status bool `json:"status"` // Error contains any parsing errors. Error error `json:"-"` // Host is the queried hostname and port combination. Host string `json:"host"` // Dedicated is set if the server reports itself to be a Dedicated Server (instead of a Listen Server). Dedicated bool `json:"dedicated"` // Name is the server's advertised Hostname. Name string `json:"name"` // Version is the server's currently running Version string. Version string `json:"version"` // NeedPass defines whether the server is private (i.e needs a password) NeedPass bool `json:"need-pass"` // Language is the given Server Language. // If you need the string version of a language, use // gopenttd.GetISOLanguage(OpenttdServerState.Language) or gopenttd.GetLanguage(OpenttdServerState.Language) Language OpenttdLanguage `json:"language"` // Environment is the environment identifier. // If you need the string version of the environment, use // gopenttd.GetEnvironment(OpenttdServerState.Environment) Environment OpenttdEnvironment `json:"environment"` // Map is the name of the map currently running. Note that this will be set to "Random Map" if the map was generated by a seed. Map string `json:"map_name"` // MapHeight and MapWidth are the height and width of the current map in tiles. MapHeight uint16 `json:"map_height"` MapWidth uint16 `json:"map_width"` // DateStart and DateCurrent are time objects relating to the start of the game and the current date. DateStart time.Time `json:"date_start"` DateCurrent time.Time `json:"date_current"` // The following should be self explanatory. NumClients int `json:"clients_active"` MaxClients int `json:"clients_max"` NumSpectators int `json:"spectators_active"` MaxSpectators int `json:"spectators_max"` NumCompanies int `json:"companies_active"` MaxCompanies int `json:"companies_max"` // NewgrfCount is the number of currently active newgrfs. NewgrfCount int `json:"newgrf_count"` // NewgrfActive is a set of OpenttdNewgrf structs corresponding to the currently active Newgrfs. NewgrfActive []OpenttdNewgrf `json:"newgrf_active"` // Companies is a list of active company data, where available. Companies map[uint8]OpenttdCompany `json:"companies"` }
func (*OpenttdServerState) PopulateCompanyState ¶
func (server *OpenttdServerState) PopulateCompanyState(buf *bytes.Buffer)
PopulateCompanyState populates an OpenttdServerState struct with company data.
func (*OpenttdServerState) PopulateServerState ¶
func (server *OpenttdServerState) PopulateServerState(buf *bytes.Buffer)
PopulateServerState populates an OpenttdServerState struct with data parsed from the Info request in the buffer.