Documentation ¶
Overview ¶
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Package game implements the Blade II Online game server.
Index ¶
- Constants
- type ActivePlayer
- type B2MatchInstruction
- type Card
- type Cards
- type DisconnectRequest
- type GClient
- type Match
- func (match *Match) BroadCast(message protocol.Message)
- func (match *Match) GetPhase() Phase
- func (match *Match) SendCardData(cards string)
- func (match *Match) SendOpponentData()
- func (match *Match) SendPlayerData()
- func (match *Match) SetMatchResult()
- func (match *Match) SetMatchStart()
- func (match *Match) SetPhase(phase Phase)
- func (match *Match) Tick()
- type MatchState
- type Move
- type Phase
- type Player
- type Server
Constants ¶
const (
// BufferSize is the size of each message queue's buffer.
BufferSize = 2048
)
const ( // SerializedCardsDelimiter is the delimiter for serialized cards objects. SerializedCardsDelimiter string = "." )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivePlayer ¶
type ActivePlayer uint8
ActivePlayer is a uint8 typedef for the active player during a game end check
type B2MatchInstruction ¶
type B2MatchInstruction uint8
B2MatchInstruction is an enum type that represents different different types of match instruction for Blade II Online.
const ( // None is a special case used to indicate that this instruction should result in a noop. None B2MatchInstruction = 0 // Instructions 1 through 11 indicate that a card was selected. The position from which it // should be taken, and where it should end up, is determined by the current board state. CardElliotsOrbalStaff B2MatchInstruction = 1 CardFiesTwinGunswords B2MatchInstruction = 2 CardAlisasOrbalBow B2MatchInstruction = 3 CardJusisSword B2MatchInstruction = 4 CardMachiasOrbalShotgun B2MatchInstruction = 5 CardGaiusSpear B2MatchInstruction = 6 CardLaurasGreatsword B2MatchInstruction = 7 CardBolt B2MatchInstruction = 8 CardMirror B2MatchInstruction = 9 CardBlast B2MatchInstruction = 10 CardForce B2MatchInstruction = 11 // Messages that can be sent to and from the server. InstructionForfeit B2MatchInstruction = 12 InstructionMessage B2MatchInstruction = 13 // Messages that can only be received from the server. InstructionCards B2MatchInstruction = 14 InstructionPlayerData B2MatchInstruction = 15 InstructionOpponentData B2MatchInstruction = 16 InstructionConnectionProgress B2MatchInstruction = 17 InstructionConnectionClosed B2MatchInstruction = 18 // Error messages from the server grouped so we can check for errors by equality (> the lowest value error). InstructionConnectionError B2MatchInstruction = 19 InstructionAuthError B2MatchInstruction = 20 InstructionMatchCheckError B2MatchInstruction = 21 InstructionMatchSetupError B2MatchInstruction = 22 InstructionMatchIllegalMove B2MatchInstruction = 23 InstructionMatchMutualTimeOut B2MatchInstruction = 24 InstructionMatchTimeOut B2MatchInstruction = 25 )
Definitions of server updates. Explicitly numbered so that their numerical value can be seen when hovering them in vscode.
func (B2MatchInstruction) ToCard ¶
func (i B2MatchInstruction) ToCard() (card Card)
ToCard returns this instruction as a card. Invalid cards are returned with the default value of 0 (ElliotsOrbalStaff).
type Card ¶
type Card uint8
Card is a typedef for different Blade II card types.
const ( // Standard cards (basic). ElliotsOrbalStaff Card = 0 FiesTwinGunswords Card = 1 AlisasOrbalBow Card = 2 JusisSword Card = 3 MachiasOrbalShotgun Card = 4 GaiusSpear Card = 5 LaurasGreatsword Card = 6 // Standard cards (effects). Bolt Card = 7 Mirror Card = 8 Blast Card = 9 Force Card = 10 // Bolted Cards (basic). InactiveElliotsOrbalStaff Card = 11 InactiveFiesTwinGunswords Card = 12 InactiveAlisasOrbalBow Card = 13 InactiveJusisSword Card = 14 InactiveMachiasOrbalShotgun Card = 15 InactiveGaiusSpear Card = 16 InactiveLaurasGreatsword Card = 17 // Bolted cards (effects). InactiveBolt Card = 18 InactiveMirror Card = 19 InactiveBlast Card = 20 InactiveForce Card = 21 )
Card enums - explicitly numbered so that their numerical value can be seen when hovering them in vscode.
type Cards ¶
type Cards struct { Player1Deck []Card Player1Hand []Card Player1Field []Card Player1Discard []Card Player2Deck []Card Player2Hand []Card Player2Field []Card Player2Discard []Card }
Cards is a container for all the cards on the field.
func GenerateCards ¶
func GenerateCards() (cards Cards)
GenerateCards generates a new set of cards for a match - has additional checks to ensure that the match is not unwinnable from the first move etc.
func InitializeCards ¶
InitializeCards simulates the first moves of the game until a playable state is reached.
Returns a COPY of the input cards.
func (*Cards) Serialized ¶
Serialized returns the string representation of the DECKS ONLY, as the other data is never required to be sent.
The cards are serialized as hexadecimal numbers, with the following format:
NNNNNNNNNNNNNNN.NNNNNNNNNNNNNNN ¶
Where each "N" is the hexadecimal representation of a card.
type DisconnectRequest ¶
type DisconnectRequest struct { // A pointer to the client to remove. Client *GClient // The reason for removal. Reason protocol.B2Code // An optional to be sent, either to just the player, or both, depending on whether they are // in a match, and the state of the match etc.. Message string }
DisconnectRequest is a wrapper for the information required to remove a client from the game server.
type GClient ¶
type GClient struct { // Database values for this client. DBID uint64 MatchID uint64 PublicID string DisplayName string Avatar uint8 // Whether the server is currently expecting a move update from this client. WaitingForMove bool // contains filtered or unexported fields }
GClient is a container for a websocket connection and its associated user data.
func NewClient ¶
func NewClient(wsconn *websocket.Conn, databaseID uint64, publicID string, displayname string, matchID uint64, avatar uint8, gameServer *Server) *GClient
NewClient creates a and retruns a pointer to a new Client, and starts its message pumps in two seperate go routines.
func (*GClient) Close ¶
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 (*GClient) IsSameConnection ¶
IsSameConnection returns true if the specified client is the same as this one.
func (*GClient) SendMessage ¶
SendMessage adds a message to the outbound queue.
func (*GClient) StartEventLoop ¶
func (client *GClient) StartEventLoop()
StartEventLoop starts the send and receive pumps for the client, with a separate goroutine for each.
type Match ¶
type Match struct { // The Match ID ID uint64 // Pointers to both players. Client1 *GClient Client2 *GClient // Match state State MatchState // A pointer to the game server. Server *Server // contains filtered or unexported fields }
Match is a wrapper for a matches data and client connections etc
func NewMatch ¶
NewMatch creates and returns a pointer to a new match, setting the specified client as player 1.
func (*Match) SendCardData ¶
SendCardData sends starting card data to each client.
func (*Match) SendOpponentData ¶
func (match *Match) SendOpponentData()
SendOpponentData sends each player the opponents data.
func (*Match) SendPlayerData ¶
func (match *Match) SendPlayerData()
SendPlayerData sends each player's (their own) name to the respective client.
func (*Match) SetMatchResult ¶
func (match *Match) SetMatchResult()
SetMatchResult updates the database with the match result, and also updates the match stats for each player via the Blade II Online REST API.
Fails silently but logs errors.
Performed in a goroutine.
func (*Match) SetMatchStart ¶
func (match *Match) SetMatchStart()
SetMatchStart sets the phase + start time for the current match.
Fails silently but logs errors.
Database update is performed in a goroutine to avoid a delay when updating the database.
type MatchState ¶
type MatchState struct { // Winner is the database ID for the winner. A value of zero indicates that there is no player, // or the game ended in a draw. Winner uint64 // Whos turn it currently is. Turn Player // The cards for this match. Cards Cards // Player scores. Player1Score uint16 Player2Score uint16 // Match phase (used by the server to determine whether to, for example, tick the match or not). Phase Phase }
MatchState represents the current state of a match.
type Move ¶
type Move struct { Instruction B2MatchInstruction Payload string }
Move represents a client match data packet.
func MoveFromString ¶
MoveFromString attempts to parse a move from the specified move string Non nil error means something went wrong.
type Player ¶
type Player uint8
Player is a typedef for the two different players
Player enums representing each type of player. PlayerUndecided is an edge case for indicating that there is no player specified, such as when the game just cleared all the cards from the field and is waiting to see when each player draw onto the field.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the game server itself
func NewServer ¶
func NewServer() *Server
NewServer creates and returns a pointer to a new game server.
func (*Server) AddClient ¶
func (gs *Server) AddClient(wsconn *websocket.Conn, dbid uint64, pid string, displayname string, avatar uint8, matchID uint64)
AddClient takes a websocket connection various data, wraps them up and adds them to the game server as a client, to be processed later.
func (*Server) Init ¶
func (gs *Server) Init()
Init initializes the game server including starting the internal loop.