server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package server runs the http server with allows users to open websockets to play the game

Index

Constants

View Source
const (
	// HeaderContentType is used to set the document type header on http responses.
	HeaderContentType = "Content-Type"
	// HeaderCacheControl is used to tell browsers how long to cache http responses.
	HeaderCacheControl = "Cache-Control"
	// HeaderLocation is used to tell browsers to request a different document.
	HeaderLocation = "Location"
	// HeaderAcceptEncoding is specified by the browser to tell the server what types of document encoding it can handle.
	HeaderAcceptEncoding = "Accept-Encoding"
	// HeaderContentEncoding is used to tell browsers how the document is encoded.
	HeaderContentEncoding = "Content-Encoding"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Challenge

type Challenge struct {
	Token string
	Key   string
}

Challenge token and key used to get a TLS certificate using the ACME HTTP-01.

type ColorConfig

type ColorConfig struct {
	// The color to paint text on the canvas.
	CanvasPrimary string
	// The color to paint text of tiles when they are bing dragged.
	CanvasDrag string
	// The color to paint tiles on the canvas.
	CanvasTile string
	// The color of log error messages.
	LogError string
	// The color of log warning messages.
	LogWarning string
	// The color of log chat messages between players.
	LogChat string
	// The color of the background of tabs.
	TabBackground string
	// The color of even-numbered columns in tables.
	TableStripe string
	// The color of a button.
	Button string
	// The color of a button when the mouse hovers over it.
	ButtonHover string
	// The color when a button is active (actually a tab).
	ButtonActive string
}

ColorConfig represents the colors on the site.

type Config

type Config struct {
	// HTTPPort is the TCP port for server http requests.  All traffic is redirected to the https port.
	HTTPPort int
	// HTTPSPORT is the TCP port for server https requests.
	HTTPSPort int
	// Tokenizer is used to generate and parse session tokens
	StopDur time.Duration
	// CachenSec is the number of seconds some files are cached
	CacheSec int
	// Version is used to bust caches of files from older server version
	Version string
	// TLSCertPEM is the public HTTPS TLS certificate file data.
	TLSCertPEM string
	// TLSKeyPEM is the private HTTPS TLS key file data.
	TLSKeyPEM string
	// Challenge is used to create ACME certificate.
	Challenge
	// ColorConfig contains the colors to use on the site.
	ColorConfig ColorConfig
	// NoTLSRedirect disables redirection to https from http when true.
	NoTLSRedirect bool
}

Config contains fields which describe the server

func (Config) NewServer

func (cfg Config) NewServer(p Parameters) (*Server, error)

NewServer creates a Server from the Config

type Lobby

type Lobby interface {
	Run(ctx context.Context, wg *sync.WaitGroup)
	AddUser(username string, w http.ResponseWriter, r *http.Request) error
	RemoveUser(username string)
}

Lobby is the place users can create, join, and participate in games.

type Parameters

type Parameters struct {
	Log *log.Logger
	Tokenizer
	UserDao
	Lobby
	StaticFS   fs.FS
	TemplateFS fs.FS
}

Parameters contains the interfaces needed to create a new server

type Server

type Server struct {
	HTTPServer  *http.Server
	HTTPSServer *http.Server

	Config
	// contains filtered or unexported fields
}

Server runs the site

func (*Server) Run

func (s *Server) Run(ctx context.Context) <-chan error

Run the server asynchronously until it receives a shutdown signal. When the HTTP/HTTPS servers stop, errors are logged to the error channel.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop asks the server to shutdown and waits for the shutdown to complete. An error is returned if the server if the context times out.

type Tokenizer

type Tokenizer interface {
	Create(username string, points int) (string, error)
	ReadUsername(tokenString string) (string, error)
}

Tokenizer creates and reads tokens from http traffic.

type UserDao

type UserDao interface {
	Create(ctx context.Context, u user.User) error
	Login(ctx context.Context, u user.User) (*user.User, error)
	UpdatePassword(ctx context.Context, u user.User, newP string) error
	Delete(ctx context.Context, u user.User) error
}

UserDao contains CRUD operations for user-related information.

Directories

Path Synopsis
Package auth contains code to ensure users are authorized to use the server after they have logged in.
Package auth contains code to ensure users are authorized to use the server after they have logged in.
Package game controls the logic to run the game.
Package game controls the logic to run the game.
lobby
Package lobby handles players connecting to games and communication between games and players
Package lobby handles players connecting to games and communication between games and players
player
Package player controls the game for each player
Package player controls the game for each player
socket
Package socket handles communication with a player using a websocket connection
Package socket handles communication with a player using a websocket connection
socket/gorilla
Package gorilla implements a websocket connection by wrapping gorilla/websocket.
Package gorilla implements a websocket connection by wrapping gorilla/websocket.

Jump to

Keyboard shortcuts

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