frontend

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package frontend provides interactive processing of front end pages and access to the backend game. Note that a 'page' can be anything from a menu of options to choose from to a simple request for a password.

The frontend is responsible for coordinating the display of pages to a user and processing their responses. These pages cover logging into the server, account creation, player creation and other non in-game activities. When the player is in-game the frontend will simply pass any input through to the game backend for processing.

Pages typically have a pair of methods - a display part and a processing part. For example accountDisplay and accountProcess. Sometimes there is only a display part, for example greetingDisplay.

The current state is held in an instance of frontend. With frontend.nextFunc being the next method to call when input is received - usually an xxxProcess method.

Each time input is received Parse will be called. The method in nextFunc will be called to handle the input. nextFunc should then call the next xxxDisplay method to send a response to the input processing and setup nextFunc with the method that will process the next input received. Any buffered response will then be sent back before Parse exits. Parse will then be called again when more input is received.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(log log.Conn, output io.Writer) *frontend

New returns an initialised instance of frontend. The passed log.Conn is used by the instance for per-connection logging. The io.Writer is used to write data back to the client. The instance is also setup with greetingDisplay as the nextFunc to call.

func NewAccount

func NewAccount(f *frontend) (a *account)

NewAccount returns an account with the specified frontend embedded. The returned account can be used for processing the creation of new accounts and players.

func NewGame

func NewGame(f *frontend) (g *game)

NewGame returns a game with the specified frontend embedded. The returned game can be used for processing communication to the actual game.

func NewLogin

func NewLogin(f *frontend) (l *login)

NewLogin returns a login with the specified frontend embedded. The returned login can be used for processing the logging in of accounts.

func NewMenu

func NewMenu(f *frontend) (m *menu)

NewMenu returns a menu with the specified frontend embedded. The returned menu can be used for processing the main menu and it's options.

func Zero added in v0.0.6

func Zero(data []byte)

Zero writes zero bytes into the passed slice

Types

type ClosedError added in v0.0.14

type ClosedError struct{}

ClosedError represents the fact that Close has been called on a frontend instance releasing it's resources and that the instance should be discarded.

func (ClosedError) Error added in v0.0.14

func (ClosedError) Error() string

Error implements the error interface for errors and returns descriptive text for the ClosedError error.

func (ClosedError) Temporary added in v0.0.14

func (ClosedError) Temporary() bool

Temporary always returns true for a frontend.ClosedError. A ClosedError is considered temporary as recovery can be performed by creating a new frontend instance.

Notes

Bugs

  • write should return any errors so that they can be checked. At the moment if there is an error writing the player file the player is still let in and their details not saved for next time they log in.

  • assemblePlayer is very fragile and makes assumptions. For example it assumes jar[0] (the first record) is for the player.

  • Need to add error handling for unexpected/missing fields.

Jump to

Keyboard shortcuts

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