matchmaking

package
v0.0.0-...-843b749 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package matchmaking implements the Blade II Online matchmaking server.

Package matchmaking implements the Blade II Online matchmaking server.

Package matchmaking implements the Blade II Online matchmaking server.

Package matchmaking implements the Blade II Online matchmaking server.

Package matchmaking implements the Blade II Online matchmaking server.

Index

Constants

View Source
const (

	// BufferSize is the size of each message queue's buffer.
	BufferSize = 2048
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientPair

type ClientPair struct {

	// Pointer to both clients.
	Client1 *MMClient
	Client2 *MMClient

	// The time at which the ready check began.
	ReadyStart time.Time

	// Whether the pair is currently undergoing a ready check.
	IsReadyChecking bool
}

ClientPair is a light wrapper for a pair of client connections.

func NewPair

func NewPair(client1 *MMClient, client2 *MMClient) *ClientPair

NewPair initializes and returns a pointer to a new client pair.

func (*ClientPair) SendMatchConfirmedMessage

func (pair *ClientPair) SendMatchConfirmedMessage(matchID uint64)

SendMatchConfirmedMessage sends a match confirmation message with match ID to both clients.

func (*ClientPair) SendMatchFoundMessage

func (pair *ClientPair) SendMatchFoundMessage()

SendMatchFoundMessage sends a match found message to both clients.

type DisconnectRequest

type DisconnectRequest struct {

	// A pointer to the client that will be removed.
	Client *MMClient

	// The reason for removal.
	Reason protocol.B2Code

	// An optional message, to be sent to the client before disconnecting.
	Message string
}

DisconnectRequest is a wrapper for the information required to remove a client from the matchmaking queue.

type MMClient

type MMClient struct {

	// Database values for this client.
	DBID     uint64
	PublicID string
	MMR      int

	// Whether the client is ready (for ready checking).
	Ready bool

	// The time at which the client ready confirmation was received (for ready checking).
	ReadyTime time.Time

	// Whether the client is currently waiting for a ready confirmation (for ready checking).
	IsReadyChecking bool

	// Whether the other client is ready (for ready checking).
	AcceptMessageSentToOpponent bool

	// A unique ID used for sorting - Should be set once connected
	ClientID uint64
	// contains filtered or unexported fields
}

MMClient is a container for a websocket connection and its associate player data.

func NewClient

func NewClient(wsconn *websocket.Conn, dbid uint64, pid string, mmr int, queue *Queue) *MMClient

NewClient creates a and retruns a pointer to a new Client, and starts its message pumps in two seperate go routines.

func (*MMClient) Close

func (client *MMClient) Close(message protocol.Message)

Close sends a message to the client, and closes the connection after a delay. The delay is asynchronous, as it is wrapped in a goroutine.

func (*MMClient) SendMessage

func (client *MMClient) SendMessage(message protocol.Message)

SendMessage adds a message to the outbound queue.

func (*MMClient) StartEventLoop

func (client *MMClient) StartEventLoop()

StartEventLoop starts the send and receive pumps for the client, with a separate goroutine for each.

func (*MMClient) Tick

func (client *MMClient) Tick()

Tick processes all the work for this client.

type Queue

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

Queue is a wrapper for the matchmaking queue

func (*Queue) AddClient

func (queue *Queue) AddClient(client *MMClient)

AddClient takes a client and adds it to the matchmaking server to be processed later.

func (*Queue) Broadcast

func (queue *Queue) Broadcast(message protocol.Message)

Broadcast adds a message to the broadcast queue, to be sent to all connected clients.

func (*Queue) Init

func (queue *Queue) Init()

Init initializes the matchmaking server including starting the internal loop.

func (*Queue) MainLoop

func (queue *Queue) MainLoop()

MainLoop is the main logic loop for the queue.

func (*Queue) Remove

func (queue *Queue) Remove(client *MMClient, reason protocol.B2Code, message string)

Remove adds a client to the disconnect queue, to be disconnected next later, along with a reason code and a message.

type Server

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

Server is the matchmaking server itself

func NewServer

func NewServer() *Server

NewServer creates and returns a pointer to a new matchmaking server.

func (*Server) AddClient

func (ms *Server) AddClient(wsconn *websocket.Conn, dbid uint64, pid string, mmr int)

AddClient takes a new client and their various data, wraps them up and adds them to the matchmaking server to be processed later.

func (*Server) Init

func (ms *Server) Init()

Init initializes the matchmaking server including starting the internal loop.

Jump to

Keyboard shortcuts

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