p2p

package
v0.0.0-...-d63db7d Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(w http.ResponseWriter, status int, v any) error

Types

type APIServer

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

func NewAPIServer

func NewAPIServer(listenAddr string, game *GameState) *APIServer

func (*APIServer) Run

func (s *APIServer) Run()

type AtomicInt

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

func NewAtomicInt

func NewAtomicInt(value int32) *AtomicInt

func (*AtomicInt) Get

func (a *AtomicInt) Get() int32

func (*AtomicInt) Inc

func (a *AtomicInt) Inc()

func (*AtomicInt) Set

func (a *AtomicInt) Set(value int32)

func (*AtomicInt) String

func (a *AtomicInt) String() string

type BroadcastTo

type BroadcastTo struct {
	To      []string
	Payload any
}

type GameState

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

func NewGame

func NewGame(addr string, bc chan BroadcastTo) *GameState

func (*GameState) AddPlayer

func (g *GameState) AddPlayer(from string)

func (*GameState) InitiateShuffleAndDeal

func (g *GameState) InitiateShuffleAndDeal()

func (*GameState) SetPlayerReady

func (g *GameState) SetPlayerReady(addr string)

SetPlayerReady is getting called when we receive a ready message from a player in the network taking a seat on the table.

func (*GameState) SetReady

func (g *GameState) SetReady()

SetReady is being called when we set ourselfs as ready.

func (*GameState) SetStatus

func (g *GameState) SetStatus(s GameStatus)

func (*GameState) ShuffleAndEncrypt

func (g *GameState) ShuffleAndEncrypt(from string, deck [][]byte) error

func (*GameState) TakeAction

func (g *GameState) TakeAction(action PlayerAction, value int) error

type GameStatus

type GameStatus int32
const (
	GameStatusConnected GameStatus = iota
	GameStatusPlayerReady
	GameStatusDealing
	GameStatusPreFlop
	GameStatusFlop
	GameStatusTurn
	GameStatusRiver
)

func (GameStatus) String

func (g GameStatus) String() string

type GameVariant

type GameVariant uint8
const (
	TexasHoldem GameVariant = iota
	Other
)

func (GameVariant) String

func (gv GameVariant) String() string

type Handshake

type Handshake struct {
	Version     string
	GameVariant GameVariant
	GameStatus  GameStatus
	ListenAddr  string
}

type Message

type Message struct {
	Payload any
	From    string
}

func NewMessage

func NewMessage(from string, payload any) *Message

type MessageEncDeck

type MessageEncDeck struct {
	Deck [][]byte
}

type MessagePeerList

type MessagePeerList struct {
	Peers []string
}

type MessagePlayerAction

type MessagePlayerAction struct {
	// CurrentGameStatus is the current status of the sending player his game.
	// this needs to the exact same as ours.
	CurrentGameStatus GameStatus
	// Action is the action that the player is willin to take.
	Action PlayerAction
	// The value of the bet if any
	Value int
}

type MessagePreFlop

type MessagePreFlop struct{}

func (MessagePreFlop) String

func (msg MessagePreFlop) String() string

type MessageReady

type MessageReady struct{}

func (MessageReady) String

func (msg MessageReady) String() string

type MyError

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

func (MyError) Error

func (e MyError) Error() string

type NetAddr

type NetAddr string

func (NetAddr) Network

func (n NetAddr) Network() string

func (NetAddr) String

func (n NetAddr) String() string

type Peer

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

func (*Peer) ReadLoop

func (p *Peer) ReadLoop(msgch chan *Message)

func (*Peer) Send

func (p *Peer) Send(b []byte) error

type Player

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

func NewPlayer

func NewPlayer(addr string) *Player

type PlayerAction

type PlayerAction byte
const (
	PlayerActionNone PlayerAction = iota
	PlayerActionFold
	PlayerActionCheck
	PlayerActionBet
)

func (PlayerAction) String

func (pa PlayerAction) String() string

type PlayersList

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

func NewPlayersList

func NewPlayersList() *PlayersList

func (*PlayersList) Len

func (p *PlayersList) Len() int

func (*PlayersList) Less

func (p *PlayersList) Less(i, j int) bool

func (*PlayersList) List

func (p *PlayersList) List() []string

func (*PlayersList) Swap

func (p *PlayersList) Swap(i, j int)

type Server

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

func NewServer

func NewServer(cfg ServerConfig) *Server

func (*Server) AddPeer

func (s *Server) AddPeer(p *Peer)

func (*Server) Broadcast

func (s *Server) Broadcast(broadcastMsg BroadcastTo) error

func (*Server) Connect

func (s *Server) Connect(addr string) error

TODO(@anthdm): Right now we have some redundent code in registering new peers to the game network. maybe construct a new peer and handshake protocol after registering a plain connection?

func (*Server) Peers

func (s *Server) Peers() []string

func (*Server) SendHandshake

func (s *Server) SendHandshake(p *Peer) error

func (*Server) Start

func (s *Server) Start()

type ServerConfig

type ServerConfig struct {
	Version       string
	ListenAddr    string
	APIListenAddr string
	GameVariant   GameVariant
	MaxPlayers    int
}

type State

type State struct {
}

type TCPTransport

type TCPTransport struct {
	AddPeer chan *Peer
	DelPeer chan *Peer
	// contains filtered or unexported fields
}

func NewTCPTransport

func NewTCPTransport(addr string) *TCPTransport

func (*TCPTransport) ListenAndAccept

func (t *TCPTransport) ListenAndAccept() error

type Table

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

func NewTable

func NewTable(maxSeats int) *Table

func (*Table) AddPlayer

func (t *Table) AddPlayer(addr string) error

NOTE: Adding a player to the table should set the gameStatus to Ready.

func (*Table) AddPlayerOnPosition

func (t *Table) AddPlayerOnPosition(addr string, pos int) error

func (*Table) GetPlayer

func (t *Table) GetPlayer(addr string) (*Player, error)

func (*Table) GetPlayerAfter

func (t *Table) GetPlayerAfter(addr string) (*Player, error)

func (*Table) GetPlayerBefore

func (t *Table) GetPlayerBefore(addr string) (*Player, error)

func (*Table) LenPlayers

func (t *Table) LenPlayers() int

func (*Table) Players

func (t *Table) Players() []*Player

func (*Table) RemovePlayerByAddr

func (t *Table) RemovePlayerByAddr(addr string) error

func (*Table) SetPlayerStatus

func (t *Table) SetPlayerStatus(addr string, s GameStatus)

func (*Table) String

func (t *Table) String() string

Jump to

Keyboard shortcuts

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