publist

package
v0.0.0-...-0992052 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package publist is used to keep public list of player information. The list is synchronized with read write lock. Data comes from the two servers. The data from the server should be a snapshot(copy) and the Read data is a pointer to the current list and that list is never update, but replaced when updated. This give all the players that read the list a reference to the same list (so no modify!!) until the list is updated and any new reads can give differnt list.

Index

Constants

View Source
const (

	//SMPass the special move pass
	SMPass = -1
	//SMQuit the special move quit
	SMQuit = -2
	//SMNone used to track fails in json or other file serialization
	//It is not a move.
	SMNone = -3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	ID      int
	Name    string
	Invite  chan<- *Invite  `json:"-"`
	DoneCom chan struct{}   `json:"-"` //Used by the player
	Message chan<- *MesData `json:"-"`
	Opp     int
	OppName string
	Watch   *WatchChCl `json:"-"`
}

Data the public list data a combination of tabel and player information.

type GameData

type GameData struct {
	Opp   int
	Watch *WatchChCl
}

GameData is the game information in the game map. Every game have two enteries one for every player.

type Invite

type Invite struct {
	InvitorID   int
	InvitorName string
	ReceiverID  int
	Rejected    bool                   //TODO MAYBE add reason
	Response    chan<- *InviteResponse `json:"-"` //Common for all invitaion
	Retract     chan struct{}          `json:"-"` //Per invite
	DoneComCh   chan struct{}          `json:"-"`
}

Invite the invite data. The invite can be retracted before the receive channel have stoped listening. This make the standard select unreliable. Use a select with default to check if retracted and the receiver must count on receiving retracted responses.

type InviteResponse

type InviteResponse struct {
	Responder int
	Name      string
	GameCh    chan<- *MoveView //nil when decline
}

InviteResponse the response to a invitation. GameCh is nil when decline.

type List

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

List is the structure that maintain the public data.

func New

func New() (list *List)

New create a list.

func (*List) Read

func (list *List) Read() (publist map[string]*Data)

Read get the current public list. The list is a multible used map. So no change.

func (*List) UpdateGames

func (list *List) UpdateGames(newgames map[int]*GameData)

UpdateGames update the public data with game information. newgames is used directly so it must be a copy.

func (*List) UpdatePlayers

func (list *List) UpdatePlayers(newplayers map[int]*PlayerData)

UpdatePlayers update the public data with player information. newplayers is used directly so it must be a copy.

type MesData

type MesData struct {
	Sender  int
	Name    string
	Message string
}

MesData message data.

type MoveBench

type MoveBench struct {
	Mover      int
	Move       bat.Move
	MoveCardix int
	NextMover  int
}

MoveBench the data send to watchers.

type MoveView

type MoveView struct {
	Mover      bool
	Move       bat.Move
	MoveCardix int
	DeltCardix int //This is the return card from deck moves, zero when not used.
	*Turn
	MoveCh chan<- [2]int `json:"-"`
}

MoveView the information send from the table to the players. It should contain all information to animate a player move. Its is non symetrics, each player get his own.

type PlayerData

type PlayerData struct {
	ID      int
	Name    string
	Invite  chan<- *Invite
	DoneCom chan struct{}   //Used by all send to player
	Message chan<- *MesData //never closed
	BootCh  chan struct{}   //For server to boot player
}

PlayerData the public list player information.

type StartGameChCl

type StartGameChCl struct {
	Channel chan *StartGameData
	Close   chan struct{}
}

StartGameChCl the start game channel.

func NewStartGameChCl

func NewStartGameChCl() (sgc *StartGameChCl)

NewStartGameChCl creates a StartGameChCl.

type StartGameData

type StartGameData struct {
	PlayerIds [2]int
	PlayerChs [2]chan<- *MoveView
}

StartGameData is the information need to start a game.

type Turn

type Turn struct {
	MyTurn    bool
	MovesPass bool
	State     int
	Moves     []bat.Move
	MovesHand map[string][]bat.Move
}

Turn a player turn.

func NewTurn

func NewTurn(turn *bat.Turn, playerix int) (disp *Turn)

NewTurn creates a Turn.

func (*Turn) Equal

func (t *Turn) Equal(other *Turn) (equal bool)

Equal compares for equal with another Turn.

type WatchChCl

type WatchChCl struct {
	Channel chan *WatchData
	Close   chan struct{}
}

WatchChCl watch channel and its close channel.

func NewWatchChCl

func NewWatchChCl() (w *WatchChCl)

NewWatchChCl creates a new watch channel.

type WatchData

type WatchData struct {
	ID   int               //This me
	Send chan<- *MoveBench //Send here. Remember to close.
}

WatchData is the information send to a table to start watching a game.

Jump to

Keyboard shortcuts

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