match

package
v0.2.74 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package match implements game and networking logic for Spy Cards Online.

Index

Constants

This section is empty.

Variables

View Source
var DefaultICEServers = []webrtc.ICEServer{
	{URLs: []string{"stun:stun.stunprotocol.org"}},
	{URLs: []string{"stun:stun.sipnet.net"}},
}

Functions

func CardTest

func CardTest(ctx context.Context) error

func NewFakeSignalConn

func NewFakeSignalConn() (*SignalConn, *SignalConn)

NewFakeSignalConn creates a mock matchmaking server connection pair.

Types

type Card

type Card struct {
	Set  *card.Set
	Def  *card.Def
	Back card.Rank
	// contains filtered or unexported fields
}

Card is an instance of a card in the game.

func (*Card) Render

func (c *Card) Render(cam *gfx.Camera, x, y, z, scale, cursorX, cursorY, aspect, flip float32)

Render draws a card to the screen.

type ExchangeDataFunc

type ExchangeDataFunc func([]byte) ([]byte, error)

ExchangeDataFunc is a simplified networking API where all messages are sent in both directions simultaneously.

type GameConn

type GameConn struct {
	OnWantRelay    func()
	OnVersion      func(string)
	OnReady        func([]byte)
	OnOfferRematch func()
	OnRematch      func()
	OnQuit         func()
	// contains filtered or unexported fields
}

func NewGameConn

func NewGameConn(ctx context.Context) (*GameConn, error)

func (*GameConn) BeginTurn

func (gc *GameConn) BeginTurn() (*struct{}, error)

func (*GameConn) Close

func (gc *GameConn) Close() error

func (*GameConn) ConfirmTurn

func (gc *GameConn) ConfirmTurn() ([]byte, error)

func (*GameConn) FinalizeMatch

func (gc *GameConn) FinalizeMatch(verifyDeck func(card.Deck, card.UnknownDeck) error, verifyTurn func(turn *scgTurn) error) error

func (*GameConn) InitDeck

func (gc *GameConn) InitDeck(deck card.Deck, backs card.UnknownDeck) (card.UnknownDeck, error)

func (*GameConn) InitSecure

func (gc *GameConn) InitSecure(playerNumber uint8) error

func (*GameConn) OnStateChange

func (gc *GameConn) OnStateChange(cb func(webrtc.PeerConnectionState))

func (*GameConn) SendCosmeticData

func (gc *GameConn) SendCosmeticData(cosmetic *card.CosmeticData) error

func (*GameConn) SendCustomCards

func (gc *GameConn) SendCustomCards(customCards string) error

func (*GameConn) SendReady

func (gc *GameConn) SendReady(data []byte) error

func (*GameConn) SendSpoilerGuardData

func (gc *GameConn) SendSpoilerGuardData(guardData string) error

func (*GameConn) SendVersion

func (gc *GameConn) SendVersion(version string) error

func (*GameConn) UseSignalingServer

func (gc *GameConn) UseSignalingServer(sc *SignalConn, playerNumber uint8)

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) (*struct{}, 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) PrepareTurn

func (scg *SecureCardGame) PrepareTurn(data []byte) ([]byte, error)

PrepareTurn computes a promise for the provided data.

func (*SecureCardGame) PrivateShuffle

func (scg *SecureCardGame) PrivateShuffle(cards []*Card, remote bool)

PrivateShuffle shuffles a set of cards.

func (*SecureCardGame) PromiseTurn

func (scg *SecureCardGame) PromiseTurn(promise []byte) error

PromiseTurn stores the opponent's promised turn data.

func (*SecureCardGame) PublicShuffle

func (scg *SecureCardGame) PublicShuffle(cards []*Card)

PublicShuffle shuffles a set of cards where only the backs are known.

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.

type SecureCardGameOptions

type SecureCardGameOptions struct {
	Hash       hash.Hash
	SeedLength int
	RandLength int
	ForReplay  bool
}

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) InitPlayer

func (sc *SignalConn) InitPlayer(playerNumber, versionSuffix string) error

InitPlayer starts the matchmaking process as either Player 1 ("1"), Player 2 ("2"), or Quick 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(sessionID string) error

SetSessionID starts the Player 2 matchmaking process using the code from Player 1.

Jump to

Keyboard shortcuts

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