server

package
v0.0.0-...-5a45d91 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2019 License: AGPL-3.0 Imports: 22 Imported by: 1

Documentation

Overview

Package server contains controller and client logic

Index

Constants

View Source
const (
	WsRequestActionSelectCard WsRequestAction = "select"
	WsRequestActionReveal                     = "reveal"
	WsRequestActionReset                      = "reset"
	WsRequestActionDeck                       = "deck"
	WsRequestActionTopic                      = "topic"
	WsRequestActionUsername                   = "username"
)

WsRequestAction constants

View Source
const UsernameMaxLength = 25

UsernameMaxLength is the maximum number of characters allowed in a username

Variables

View Source
var ErrInvalidUsername = errors.New("server: invalid username entered")

ErrInvalidUsername is an error when the username does not match criteria

Functions

This section is empty.

Types

type Client

type Client struct {
	Game *game.Game

	Conn WsConn
	// contains filtered or unexported fields
}

Client represents a user connected via websocket

func NewClient

func NewClient(game *game.Game, conn WsConn, id int, uname string) *Client

NewClient instantiates a new client object.

func (*Client) CloseChannel

func (c *Client) CloseChannel()

CloseChannel will close the send channel

func (*Client) ID

func (c *Client) ID() int

ID returns the ID of the client

func (*Client) Name

func (c *Client) Name() string

Name returns the display name for the user

func (*Client) ReadPump

func (c *Client) ReadPump(s *Server)

ReadPump reads messages sent from the client.

func (*Client) RemoteAddr

func (c *Client) RemoteAddr() string

RemoteAddr returns the remote address (IP + port) of the client

func (*Client) Send

func (c *Client) Send(o interface{})

Send will send an object to the client.

func (*Client) SetName

func (c *Client) SetName(n string) error

SetName sets the name of the player

func (*Client) WritePump

func (c *Client) WritePump(s *Server)

WritePump writes messages to the client. This method should be called in a separate goroutine.

type Server

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

Server is the main object that can be used to return an *http.ServeMux object.

func New

func New(templatesBox, staticBox *rice.Box) *Server

New returns a new *Server object

func (*Server) HandleWsRequest

func (s *Server) HandleWsRequest(c *Client, r *WsRequest)

HandleWsRequest handles requests that came in from a web socket connection via Client

func (*Server) ListenForEvents

func (s *Server) ListenForEvents(done chan bool)

ListenForEvents will listen for various events like when to destroy a game, and when to disconnect the server.

func (*Server) ServeMux

func (s *Server) ServeMux() *http.ServeMux

ServeMux returns a mux that can be used with the listen and server methods in net/http

type WsConn

type WsConn interface {
	Close() error
	ReadJSON(v interface{}) error
	RemoteAddr() net.Addr
	SetPongHandler(func(appDate string) error)
	SetReadDeadline(t time.Time) error
	SetReadLimit(limit int64)
	SetWriteDeadline(t time.Time) error
	WriteJSON(v interface{}) error
	WriteMessage(messageType int, data []byte) error
}

WsConn is an interface which implements a subset of the available methods in *websocket.Conn

type WsRequest

type WsRequest struct {
	Action WsRequestAction `json:"action"`
	Card   int             `json:"card"`
	Deck   string          `json:"deck"`
	Room   string          `json:"room"`
	Token  string          `json:"token"`
	Value  string          `json:"value"`
}

WsRequest is data that was read from a web socket connection

type WsRequestAction

type WsRequestAction string

WsRequestAction is a type for representing a web socket action

Jump to

Keyboard shortcuts

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