Documentation ¶
Overview ¶
Package matchnet handles networking for Spy Cards Online.
Index ¶
- Variables
- func NewFakeSignalConn() (*SignalConn, *SignalConn)
- type ConnState
- type ExchangeDataFunc
- type GameConn
- func (gc *GameConn) AwaitMatchReady()
- func (gc *GameConn) BeginTurn(ch chan<- *card.TurnData)
- func (gc *GameConn) ClearRematchStatus()
- func (gc *GameConn) ConnStateExcept(except ...ConnState) ConnState
- func (gc *GameConn) ExchangeInHand(data []byte) []byte
- func (gc *GameConn) FinalizeMatch(verifyInit VerifyInitFunc, verifyTurn VerifyTurnFunc) error
- func (gc *GameConn) LastPing() time.Duration
- func (gc *GameConn) OfferRematch() error
- func (gc *GameConn) OpponentReady() bool
- func (gc *GameConn) RecvCosmeticData() *card.CosmeticData
- func (gc *GameConn) RecvDeck() (card.UnknownDeck, bool)
- func (gc *GameConn) RecvInputs() []byte
- func (gc *GameConn) RecvModifiedCards(revealCard bool) []card.ModifiedCardPosition
- func (gc *GameConn) RecvReady(turnData *card.TurnData, perspective uint8) bool
- func (gc *GameConn) RematchStatus() (connected, recv, sent bool)
- func (gc *GameConn) SendCosmeticData(c card.CosmeticData) error
- func (gc *GameConn) SendDeck(ctx context.Context, deck card.Deck, useEffectBack bool)
- func (gc *GameConn) SendInputs(buf []byte) error
- func (gc *GameConn) SendModifiedCards(m []card.ModifiedCardPosition, revealCard bool) error
- func (gc *GameConn) SendQ() uint64
- func (gc *GameConn) SendReady(turnData *card.TurnData, perspective uint8)
- func (gc *GameConn) SignalClosed() (websocket.StatusCode, string)
- func (gc *GameConn) SimulateNetworkCondition(drop float64, latency, jitter time.Duration)
- func (gc *GameConn) State() (ConnState, LogicalState)
- func (gc *GameConn) UseSignal(ctx context.Context, sc *SignalConn, isHost bool, mode *string, ...) error
- func (gc *GameConn) UseSignalRollback(ctx context.Context, sc *SignalConn) error
- func (gc *GameConn) WaitAcceptRematch() bool
- func (gc *GameConn) WaitRecvDeck() card.UnknownDeck
- func (gc *GameConn) WaitRecvReady(turnData *card.TurnData, perspective uint8)
- type LogicalState
- type RNGSharedType
- type SecureCardGame
- func (scg *SecureCardGame) BeginTurn(exchangeData ExchangeDataFunc) (*card.TurnData, error)
- func (scg *SecureCardGame) ConfirmTurn(exchangeData ExchangeDataFunc) ([]byte, error)
- func (scg *SecureCardGame) Finalize(exchangeData ExchangeDataFunc, ...) error
- func (scg *SecureCardGame) Init(playerNumber uint8, exchangeData ExchangeDataFunc) error
- func (scg *SecureCardGame) InitTurnSeed(turnSeed, localSeed, remoteSeed []byte)
- func (scg *SecureCardGame) PrepareTurn(data []byte) ([]byte, error)
- func (scg *SecureCardGame) PromiseTurn(promise []byte) error
- func (scg *SecureCardGame) Rand(shared RNGSharedType) *rng.RNG
- func (scg *SecureCardGame) Seed(shared RNGSharedType) []byte
- func (scg *SecureCardGame) SetDeck(exchangeData ExchangeDataFunc, deck card.Deck, backs card.UnknownDeck) (card.UnknownDeck, error)
- func (scg *SecureCardGame) Shuffle(shared RNGSharedType, length int, swap func(i, j int))
- func (scg *SecureCardGame) WhenConfirmedTurn(seed2 []byte)
- type SecureCardGameOptions
- type SignalConn
- func (sc *SignalConn) Close() error
- func (sc *SignalConn) HaveSessionID() bool
- func (sc *SignalConn) InitPlayer(ctx context.Context, playerNumber, versionSuffix string) error
- func (sc *SignalConn) SessionID(ctx context.Context) (string, error)
- func (sc *SignalConn) SetSessionID(ctx context.Context, sessionID string) error
- type VerifyInitFunc
- type VerifyTurnFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultICEServers = []webrtc.ICEServer{ {URLs: []string{"stun:stun.stunprotocol.org"}}, {URLs: []string{"stun:stun.sipnet.net"}}, }
DefaultICEServers are the default servers used for interactive connectivity establishment.
Functions ¶
func NewFakeSignalConn ¶
func NewFakeSignalConn() (*SignalConn, *SignalConn)
NewFakeSignalConn creates a mock matchmaking server connection pair.
Types ¶
type ConnState ¶
type ConnState uint64
ConnState is the connection state.
type ExchangeDataFunc ¶
ExchangeDataFunc is a simplified networking API where all messages are sent in both directions simultaneously.
type GameConn ¶
type GameConn struct { SCG *SecureCardGame // contains filtered or unexported fields }
func (*GameConn) AwaitMatchReady ¶
func (gc *GameConn) AwaitMatchReady()
AwaitMatchReady waits until the logical state is StateMatchReady.
func (*GameConn) ClearRematchStatus ¶ added in v0.3.1
func (gc *GameConn) ClearRematchStatus()
func (*GameConn) ConnStateExcept ¶
ConnStateExcept waits until the connection state is not one of the arguments, then returns the connection state.
func (*GameConn) ExchangeInHand ¶ added in v0.2.77
func (*GameConn) FinalizeMatch ¶ added in v0.2.77
func (gc *GameConn) FinalizeMatch(verifyInit VerifyInitFunc, verifyTurn VerifyTurnFunc) error
func (*GameConn) LastPing ¶ added in v0.3.1
LastPing returns the round trip time to the opponent in rollback mode.
func (*GameConn) OfferRematch ¶ added in v0.3.1
func (*GameConn) OpponentReady ¶
func (*GameConn) RecvCosmeticData ¶
func (gc *GameConn) RecvCosmeticData() *card.CosmeticData
func (*GameConn) RecvInputs ¶ added in v0.3.1
RecvInputs returns a pending input packet from the opponent, or nil if no packet has been received since the previous call.
func (*GameConn) RecvModifiedCards ¶ added in v0.2.77
func (gc *GameConn) RecvModifiedCards(revealCard bool) []card.ModifiedCardPosition
func (*GameConn) RematchStatus ¶ added in v0.3.1
func (*GameConn) SendCosmeticData ¶
func (gc *GameConn) SendCosmeticData(c card.CosmeticData) error
func (*GameConn) SendInputs ¶ added in v0.3.1
SendInputs sends an input packet to the opponent. This packet is not guaranteed to arrive.
func (*GameConn) SendModifiedCards ¶ added in v0.2.77
func (gc *GameConn) SendModifiedCards(m []card.ModifiedCardPosition, revealCard bool) error
func (*GameConn) SignalClosed ¶
func (gc *GameConn) SignalClosed() (websocket.StatusCode, string)
SignalClosed returns the status code and reason for the SignalConn closing.
func (*GameConn) SimulateNetworkCondition ¶ added in v0.3.1
func (*GameConn) State ¶
func (gc *GameConn) State() (ConnState, LogicalState)
State returns the network and logical state of the connection.
func (*GameConn) UseSignal ¶
func (gc *GameConn) UseSignal(ctx context.Context, sc *SignalConn, isHost bool, mode *string, cards *card.Set) error
UseSignal negotiates a card game connection using a SingalConn.
func (*GameConn) UseSignalRollback ¶ added in v0.3.12
func (gc *GameConn) UseSignalRollback(ctx context.Context, sc *SignalConn) error
UseSignalRollback negotiates a GGPO-like connection using a SingalConn.
func (*GameConn) WaitAcceptRematch ¶ added in v0.3.1
func (*GameConn) WaitRecvDeck ¶
func (gc *GameConn) WaitRecvDeck() card.UnknownDeck
type LogicalState ¶
type LogicalState uint64
LogicalState is the application logic state.
const ( StateUninitialized LogicalState = iota StateSecureInitializing StateSecureReady StateMatchReady )
Application logic states.
func (LogicalState) String ¶
func (i LogicalState) String() string
type RNGSharedType ¶
type RNGSharedType uint8
RNGSharedType determines which random number generator state is being used.
const ( RNGLocal RNGSharedType = iota RNGRemote )
Constants for RNGSharedType.
func (RNGSharedType) String ¶
func (i RNGSharedType) String() string
type SecureCardGame ¶
type SecureCardGame struct {
// contains filtered or unexported fields
}
SecureCardGame provides secrecy and verifiability to the networked card game.
func NewSecureCardGame ¶
func NewSecureCardGame(opt *SecureCardGameOptions) (*SecureCardGame, error)
NewSecureCardGame creates a SecureCardGame instance.
func (*SecureCardGame) BeginTurn ¶
func (scg *SecureCardGame) BeginTurn(exchangeData ExchangeDataFunc) (*card.TurnData, error)
BeginTurn starts a round of the card game.
func (*SecureCardGame) ConfirmTurn ¶
func (scg *SecureCardGame) ConfirmTurn(exchangeData ExchangeDataFunc) ([]byte, error)
ConfirmTurn finishes the turn and returns the opponent's promised data.
func (*SecureCardGame) Finalize ¶
func (scg *SecureCardGame) Finalize(exchangeData ExchangeDataFunc, verifyDeck func(card.Deck, card.UnknownDeck) error, verifyTurn func(*scgTurn) error) error
Finalize completes and verifies the card game.
func (*SecureCardGame) Init ¶
func (scg *SecureCardGame) Init(playerNumber uint8, exchangeData ExchangeDataFunc) error
Init starts a secure card game session.
func (*SecureCardGame) InitTurnSeed ¶
func (scg *SecureCardGame) InitTurnSeed(turnSeed, localSeed, remoteSeed []byte)
InitTurnSeed initializes the random number generator for a turn.
func (*SecureCardGame) PrepareTurn ¶
func (scg *SecureCardGame) PrepareTurn(data []byte) ([]byte, error)
PrepareTurn computes a promise for the provided data.
func (*SecureCardGame) PromiseTurn ¶
func (scg *SecureCardGame) PromiseTurn(promise []byte) error
PromiseTurn stores the opponent's promised turn data.
func (*SecureCardGame) Rand ¶
func (scg *SecureCardGame) Rand(shared RNGSharedType) *rng.RNG
Rand returns the *rng.RNG for the specified random state type.
func (*SecureCardGame) Seed ¶
func (scg *SecureCardGame) Seed(shared RNGSharedType) []byte
Seed returns the seed for the specified random state type.
func (*SecureCardGame) SetDeck ¶
func (scg *SecureCardGame) SetDeck(exchangeData ExchangeDataFunc, deck card.Deck, backs card.UnknownDeck) (card.UnknownDeck, error)
SetDeck sets the current player's deck and returns the backs of the opponent's cards.
func (*SecureCardGame) Shuffle ¶
func (scg *SecureCardGame) Shuffle(shared RNGSharedType, length int, swap func(i, j int))
Shuffle shuffles an arbitrary set of data.
func (*SecureCardGame) WhenConfirmedTurn ¶
func (scg *SecureCardGame) WhenConfirmedTurn(seed2 []byte)
WhenConfirmedTurn initializes the shared seed for the processing stage of a round of Spy Cards Online.
type SecureCardGameOptions ¶
type SecureCardGameOptions struct { NewHash func() hash.Hash SeedLength int RandLength int ForReplay *[3]uint64 }
SecureCardGameOptions modifies the behavior of SecureCardGame.
type SignalConn ¶
type SignalConn struct {
// contains filtered or unexported fields
}
SignalConn is a connection to the matchmaking server.
func NewSignalConn ¶
func NewSignalConn(ctx context.Context) (*SignalConn, error)
NewSignalConn creates a matchmaking server connection.
func (*SignalConn) Close ¶
func (sc *SignalConn) Close() error
Close terminates the matchmaking server connection.
func (*SignalConn) HaveSessionID ¶
func (sc *SignalConn) HaveSessionID() bool
HaveSessionID returns true if the session ID has been obtained.
func (*SignalConn) InitPlayer ¶
func (sc *SignalConn) InitPlayer(ctx context.Context, playerNumber, versionSuffix string) error
InitPlayer starts the matchmaking process as either Player 1 ("1"), Player 2 ("2"), or Auto Join ("q").
func (*SignalConn) SessionID ¶
func (sc *SignalConn) SessionID(ctx context.Context) (string, error)
SessionID returns the session ID assigned by the matchmaking server.
func (*SignalConn) SetSessionID ¶
func (sc *SignalConn) SetSessionID(ctx context.Context, sessionID string) error
SetSessionID starts the Player 2 matchmaking process using the code from Player 1.