clientcomm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

The package serves as an interface to incoming client requests (excluding user requests) and distributes to the updates to the clients based on their login session connection type (such as HTTP, TCP, etc.)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

func SetErrorLogger

func SetErrorLogger(errorLog *log.Logger)

func SetInfoLogger

func SetInfoLogger(infoLog *log.Logger)

Types

type ClientComm

type ClientComm struct {
}

type ClientComm is the interface for the incoming client requests

func (*ClientComm) AcceptRoomInvitation

func (cc *ClientComm) AcceptRoomInvitation(req StdReqInfo) error

AcceptInvitation() accept an invitation to a game session

func (*ClientComm) CreateRoom

func (cc *ClientComm) CreateRoom(userId int, lnSessId int, un string) (int, error)

CreateRoom() create a new game session

func (*ClientComm) DeclineRoomInvitation

func (cc *ClientComm) DeclineRoomInvitation(req StdReqInfo) error

DeclineInvitation() decline an invitation to a room

func (*ClientComm) GetGamesList

func (cc *ClientComm) GetGamesList() []GameInfo

GetGamesList returns the list of game parameters

func (*ClientComm) InviteToRoom

func (cc *ClientComm) InviteToRoom(req StdReqInfo, inviteeId int, inviteeUn string) error

InviteToRoom() invite a player to a specific game session

func (*ClientComm) LeaveRoom

func (cc *ClientComm) LeaveRoom(req StdReqInfo)

LeaveSession() leave an existing game session

func (*ClientComm) RegisterLnSess

func (cc *ClientComm) RegisterLnSess(userId int, lnSessId int, connType string)

RegisterLnSess() add login session details to the connection table

func (*ClientComm) StartGame

func (cc *ClientComm) StartGame(req StdReqInfo, gameId int) error

StartGame() start the game

func (*ClientComm) UnregisterLnSess

func (cc *ClientComm) UnregisterLnSess(userId int, lnSessId int)

UnregisterLnSess() remove login session details from the connection table

type ClientCommLogger

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

type ConnTable

type ConnTable struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ConnTable holds the information associating rooms with login sessions and connection types. The room entries are grouped together by the user

type GameInfo

type GameInfo struct {
	Name       string
	Id         int
	MaxPlayers int
	MinPlayers int
}

Alias for rooms.GameInfo

type GameState

type GameState struct {
	RoomId      int
	LnSessId    int
	Ints        map[string]int
	Strings     map[string]string
	Bools       map[string]bool
	IntSlice    map[string][]int
	StringSlice map[string][]string
	BoolSlice   map[string][]bool
}

An alias for rooms.GameState

type IUpdatesHandler

type IUpdatesHandler interface {
	HandlerType() string
	SendRoomInvitation(userId int, lnSessId int, inv RoomInvitation)
	UpdateRoomInfo(userId int, update RoomInfo)
	UpdateGameState(userId int, gameState GameState)
}

UpdateHandler sends out updates to a user

type LnSessInfo

type LnSessInfo struct {
	LnSessId int
	ConnType string
}

Each login session is associated with a certain connection type (E.g., HTTP, TCP, etc.)

type RoomInfo

type RoomInfo struct {
	// ActiveUsers only holds the usernames; ids are not included
	ActiveUsers []string
	RoomId      int
	GameActive  bool
	LnSessId    int
}

Additional details are added to this type, compared to rooms.RoomInfo

type RoomInvitation

type RoomInvitation struct {
	InvState string
	HostUn   string
	RoomId   int
}

Room invitation types: active - set for new invitations used - set for when an invitation needs to be cleared in the game client (e.g., it was accepted or rejected)

type RoomInvite

type RoomInvite struct {
	InviteeUn string
}

type StdReqInfo

type StdReqInfo struct {
	UserId   int
	LnSessId int
	RoomId   int
}

type UpdateUser

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

func GetUpdateUser

func GetUpdateUser() *UpdateUser

func (*UpdateUser) AddUpdatesHandler

func (iu *UpdateUser) AddUpdatesHandler(uh IUpdatesHandler)

Set the handler for an UpdatesHandler interface. This function should not allow re-assigning the interface handle for the same connection from other modules.

func (*UpdateUser) SendInvitation

func (iu *UpdateUser) SendInvitation(userId int, roomId int, hostUn string)

SendInvitation() send a room invitation to a player. An invitation is sent for each active login session so that it appears in all game clients.

func (*UpdateUser) UpdateGameState

func (iu *UpdateUser) UpdateGameState(userId int, roomId int, gameState igame.GameState)

UpdateGameState() send the new game state to a player.

func (*UpdateUser) UpdateRoomInfo

func (iu *UpdateUser) UpdateRoomInfo(userId int, state boardelicious.RoomInfo)

UpdateRoomInfo() send the new game session state to a player.

Jump to

Keyboard shortcuts

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