server

package
v0.0.0-...-607b5ed Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

All the chars that MakePin can utilize

Variables

This section is empty.

Functions

func BotHandler

func BotHandler(w http.ResponseWriter, r *http.Request, roomStorage Storage)

func CreateHandler

func CreateHandler(w http.ResponseWriter, r *http.Request, roomStorage Storage)

CreateHandler creates a room. Sends back a path with an id to go to along with leader permissions. Redirects user back to root path with a message if there is an error / problems. BUG: CreateHandler doesn't handle rooms with special character names

func HomeHandler

func HomeHandler(w http.ResponseWriter, r *http.Request)

HomeHandler send the index.html page at root path

func IdExists

func IdExists(rooms Storage, id string) bool

IdExists checks if id exists in Storage variable

func JoinHandler

func JoinHandler(w http.ResponseWriter, r *http.Request, roomStorage Storage)

JoinHandler handles POST requests to join a game. Redirects users back to root with a message if there is an error. Sends back a path with an id to go to to if there is no error.

func LobbyHandler

func LobbyHandler(w http.ResponseWriter, r *http.Request, roomStorage Storage)

Handler that serves game file Create and Join Handler will route here Redirects people who reach here by URL back to Join to be stored in context

func MakeId

func MakeId(roomStorage Storage) string

Generates a unique id containing only numbers

func MakePin

func MakePin(room string, roomStorage Storage) string

MakePin Generates a unique PIN with length 5.

func MakeRouter

func MakeRouter() *mux.Router

MakeRouter creates a router that will handle the routes for Chain Reaction.

func WSHandshake

func WSHandshake(w http.ResponseWriter, r *http.Request, roomStorage Storage)

Creates a websocket connection and starts the hub and client goroutines Might be changed to POST if a websocket server and http server are separated. Function couples the server and the websocket together so two servers are not needed Is in charge of stopping hub server

Types

type ReqBody

type ReqBody struct {
	Pin, Room, Players, Username string
}

Valid request information that a user can send It is stored in the context

func DecodeBody

func DecodeBody(data io.ReadCloser) (*ReqBody, error)

Decode Json message from HTTP Request. Prevents strange values.

type Storage

type Storage map[string]*sock.Hub

Storage is the type that stores all Games id is the key with information about it as a value

Jump to

Keyboard shortcuts

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