Documentation
¶
Index ¶
- func HeartbeatSystem(state *HeartbeatSystemState)
- func InitSystem(state *InitSystemState)
- func LobbySystem(state *LobbySystemState)
- func SetConfig(config component.ConfigComponent)
- func SetProvider(provider LobbyProvider)
- type CreateLobbyCommand
- type CreateLobbyResult
- type DefaultProvider
- type GenerateInviteCodeCommand
- type GenerateInviteCodeResult
- type GetAllPlayersCommand
- type GetAllPlayersResult
- type GetPlayerCommand
- type GetPlayerResult
- type HeartbeatCommand
- type HeartbeatSystemState
- type InitSystemState
- type InviteCodeGeneratedEvent
- type JoinLobbyCommand
- type JoinLobbyResult
- type JoinTeamCommand
- type JoinTeamResult
- type KickPlayerCommand
- type KickPlayerResult
- type LeaderChangedEvent
- type LeaveLobbyCommand
- type LeaveLobbyResult
- type LobbyCreatedEvent
- type LobbyDeletedEvent
- type LobbyProvider
- type LobbySystemState
- type NotifySessionEndCommand
- type NotifySessionStartCommand
- type PlayerChangedTeamEvent
- type PlayerJoinedEvent
- type PlayerKickedEvent
- type PlayerLeftEvent
- type PlayerPassthroughUpdatedEvent
- type PlayerReadyEvent
- type PlayerTimedOutEvent
- type SessionEndedEvent
- type SessionPassthroughUpdatedEvent
- type SessionStartedEvent
- type SetReadyCommand
- type SetReadyResult
- type StartSessionCommand
- type StartSessionPayload
- type StartSessionResult
- type TeamConfig
- type TransferLeaderCommand
- type TransferLeaderResult
- type UpdatePlayerPassthroughCommand
- type UpdatePlayerPassthroughResult
- type UpdateSessionPassthroughCommand
- type UpdateSessionPassthroughResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HeartbeatSystem ¶
func HeartbeatSystem(state *HeartbeatSystemState)
HeartbeatSystem processes heartbeat commands and removes stale players.
func InitSystem ¶
func InitSystem(state *InitSystemState)
InitSystem creates singleton index entities. Runs once at tick 0.
func SetConfig ¶
func SetConfig(config component.ConfigComponent)
SetConfig stores the configuration for the init system to use.
func SetProvider ¶
func SetProvider(provider LobbyProvider)
SetProvider stores the provider for the system to use.
Types ¶
type CreateLobbyCommand ¶
type CreateLobbyCommand struct {
RequestID string `json:"request_id"` // For matching request/response
// Teams is the initial team configuration for the lobby.
Teams []TeamConfig `json:"teams,omitempty"`
// GameWorld is the target game shard address for this lobby.
GameWorld cardinal.OtherWorld `json:"game_world"`
// PlayerPassthroughData is custom data for the creating player, forwarded to game shard.
PlayerPassthroughData map[string]any `json:"player_passthrough_data,omitempty"`
// SessionPassthroughData is custom data for the lobby session, forwarded to game shard.
SessionPassthroughData map[string]any `json:"session_passthrough_data,omitempty"`
}
CreateLobbyCommand creates a new lobby with the sender as leader.
func (CreateLobbyCommand) Name ¶
func (CreateLobbyCommand) Name() string
Name returns the command name.
type CreateLobbyResult ¶
type CreateLobbyResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
Lobby component.LobbyComponent `json:"lobby,omitempty"`
Player component.PlayerComponent `json:"player,omitempty"`
}
CreateLobbyResult is sent back to the client after CreateLobbyCommand.
func (CreateLobbyResult) Name ¶
func (r CreateLobbyResult) Name() string
Name returns the request-prefixed event name.
type DefaultProvider ¶
type DefaultProvider struct{}
DefaultProvider provides default implementations.
func (DefaultProvider) GenerateInviteCode ¶
func (DefaultProvider) GenerateInviteCode(lobby *component.LobbyComponent) string
GenerateInviteCode generates a 6-character invite code using Hash(LobbyID + Now()).
type GenerateInviteCodeCommand ¶
type GenerateInviteCodeCommand struct {
RequestID string `json:"request_id"` // For matching request/response
}
GenerateInviteCodeCommand generates a new invite code (leader only).
func (GenerateInviteCodeCommand) Name ¶
func (GenerateInviteCodeCommand) Name() string
Name returns the command name.
type GenerateInviteCodeResult ¶
type GenerateInviteCodeResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
InviteCode string `json:"invite_code,omitempty"`
}
GenerateInviteCodeResult is sent back to the client after GenerateInviteCodeCommand.
func (GenerateInviteCodeResult) Name ¶
func (r GenerateInviteCodeResult) Name() string
Name returns the request-prefixed event name.
type GetAllPlayersCommand ¶
type GetAllPlayersCommand struct {
RequestID string `json:"request_id"` // For matching request/response
}
GetAllPlayersCommand fetches all players in the caller's lobby.
func (GetAllPlayersCommand) Name ¶
func (GetAllPlayersCommand) Name() string
Name returns the command name.
type GetAllPlayersResult ¶
type GetAllPlayersResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
Players []component.PlayerComponent `json:"players,omitempty"`
}
GetAllPlayersResult is sent back to the client after GetAllPlayersCommand.
func (GetAllPlayersResult) Name ¶
func (r GetAllPlayersResult) Name() string
Name returns the request-prefixed event name.
type GetPlayerCommand ¶
type GetPlayerCommand struct {
RequestID string `json:"request_id"` // For matching request/response
PlayerID string `json:"player_id"` // Target player ID (empty = self)
}
GetPlayerCommand fetches a specific player's component data.
type GetPlayerResult ¶
type GetPlayerResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
Player component.PlayerComponent `json:"player,omitempty"`
}
GetPlayerResult is sent back to the client after GetPlayerCommand.
func (GetPlayerResult) Name ¶
func (r GetPlayerResult) Name() string
Name returns the request-prefixed event name.
type HeartbeatCommand ¶
type HeartbeatCommand struct {
}
HeartbeatCommand is sent periodically by clients to indicate they're still connected. Players who don't send heartbeats within the timeout period are automatically removed.
type HeartbeatSystemState ¶
type HeartbeatSystemState struct {
cardinal.BaseSystemState
// Commands
HeartbeatCmds cardinal.WithCommand[HeartbeatCommand]
// Entities
Lobbies cardinal.Contains[struct {
Lobby cardinal.Ref[component.LobbyComponent]
}]
Players cardinal.Contains[struct {
Player cardinal.Ref[component.PlayerComponent]
}]
LobbyIndexes cardinal.Contains[struct {
Index cardinal.Ref[component.LobbyIndexComponent]
}]
Configs cardinal.Contains[struct {
Config cardinal.Ref[component.ConfigComponent]
}]
// Events
PlayerTimedOutEvents cardinal.WithEvent[PlayerTimedOutEvent]
LeaderChangedEvents cardinal.WithEvent[LeaderChangedEvent]
LobbyDeletedEvents cardinal.WithEvent[LobbyDeletedEvent]
}
HeartbeatSystemState is the state for the heartbeat system.
type InitSystemState ¶
type InitSystemState struct {
cardinal.BaseSystemState
LobbyIndexes cardinal.Contains[struct {
Index cardinal.Ref[component.LobbyIndexComponent]
}]
Configs cardinal.Contains[struct {
Config cardinal.Ref[component.ConfigComponent]
}]
}
InitSystemState is the state for the init system.
type InviteCodeGeneratedEvent ¶
type InviteCodeGeneratedEvent struct {
LobbyID string `json:"lobby_id"`
InviteCode string `json:"invite_code"`
}
InviteCodeGeneratedEvent is emitted when a new invite code is generated.
func (InviteCodeGeneratedEvent) Name ¶
func (InviteCodeGeneratedEvent) Name() string
Name returns the event name.
type JoinLobbyCommand ¶
type JoinLobbyCommand struct {
RequestID string `json:"request_id"` // For matching request/response
InviteCode string `json:"invite_code"` // Required: invite code to join
TeamName string `json:"team_name,omitempty"` // Optional: team to join by name (joins first available if empty)
// PlayerPassthroughData is custom data for the joining player, forwarded to game shard.
PlayerPassthroughData map[string]any `json:"player_passthrough_data,omitempty"`
}
JoinLobbyCommand joins an existing lobby via invite code.
type JoinLobbyResult ¶
type JoinLobbyResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
Lobby component.LobbyComponent `json:"lobby,omitempty"`
PlayersList []component.PlayerComponent `json:"players_list,omitempty"`
}
JoinLobbyResult is sent back to the client after JoinLobbyCommand.
func (JoinLobbyResult) Name ¶
func (r JoinLobbyResult) Name() string
Name returns the request-prefixed event name.
type JoinTeamCommand ¶
type JoinTeamCommand struct {
RequestID string `json:"request_id"` // For matching request/response
TeamName string `json:"team_name"`
}
JoinTeamCommand moves a player to a different team.
type JoinTeamResult ¶
type JoinTeamResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
Player component.PlayerComponent `json:"player,omitempty"`
}
JoinTeamResult is sent back to the client after JoinTeamCommand.
func (JoinTeamResult) Name ¶
func (r JoinTeamResult) Name() string
Name returns the request-prefixed event name.
type KickPlayerCommand ¶
type KickPlayerCommand struct {
RequestID string `json:"request_id"` // For matching request/response
TargetPlayerID string `json:"target_player_id"`
}
KickPlayerCommand kicks a player from the lobby (leader only).
func (KickPlayerCommand) Name ¶
func (KickPlayerCommand) Name() string
Name returns the command name.
type KickPlayerResult ¶
type KickPlayerResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
}
KickPlayerResult is sent back to the client after KickPlayerCommand.
func (KickPlayerResult) Name ¶
func (r KickPlayerResult) Name() string
Name returns the request-prefixed event name.
type LeaderChangedEvent ¶
type LeaderChangedEvent struct {
LobbyID string `json:"lobby_id"`
OldLeaderID string `json:"old_leader_id"`
NewLeaderID string `json:"new_leader_id"`
}
LeaderChangedEvent is emitted when leadership is transferred.
func (LeaderChangedEvent) Name ¶
func (LeaderChangedEvent) Name() string
Name returns the event name.
type LeaveLobbyCommand ¶
type LeaveLobbyCommand struct {
RequestID string `json:"request_id"` // For matching request/response
}
LeaveLobbyCommand leaves the current lobby.
func (LeaveLobbyCommand) Name ¶
func (LeaveLobbyCommand) Name() string
Name returns the command name.
type LeaveLobbyResult ¶
type LeaveLobbyResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
}
LeaveLobbyResult is sent back to the client after LeaveLobbyCommand.
func (LeaveLobbyResult) Name ¶
func (r LeaveLobbyResult) Name() string
Name returns the request-prefixed event name.
type LobbyCreatedEvent ¶
type LobbyCreatedEvent struct {
LobbyID string `json:"lobby_id"`
LeaderID string `json:"leader_id"`
InviteCode string `json:"invite_code"`
}
LobbyCreatedEvent is emitted when a lobby is created.
type LobbyDeletedEvent ¶
type LobbyDeletedEvent struct {
LobbyID string `json:"lobby_id"`
}
LobbyDeletedEvent is emitted when a lobby is deleted.
type LobbyProvider ¶
type LobbyProvider interface {
// GenerateInviteCode generates a custom invite code for the lobby.
GenerateInviteCode(lobby *component.LobbyComponent) string
}
LobbyProvider defines customizable behavior for the lobby system.
type LobbySystemState ¶
type LobbySystemState struct {
cardinal.BaseSystemState
// Commands
CreateLobbyCmds cardinal.WithCommand[CreateLobbyCommand]
JoinLobbyCmds cardinal.WithCommand[JoinLobbyCommand]
JoinTeamCmds cardinal.WithCommand[JoinTeamCommand]
LeaveLobbyCmds cardinal.WithCommand[LeaveLobbyCommand]
SetReadyCmds cardinal.WithCommand[SetReadyCommand]
KickPlayerCmds cardinal.WithCommand[KickPlayerCommand]
TransferLeaderCmds cardinal.WithCommand[TransferLeaderCommand]
StartSessionCmds cardinal.WithCommand[StartSessionCommand]
NotifySessionEndCmds cardinal.WithCommand[NotifySessionEndCommand]
GenerateInviteCodeCmds cardinal.WithCommand[GenerateInviteCodeCommand]
UpdateSessionPassthroughCmds cardinal.WithCommand[UpdateSessionPassthroughCommand]
UpdatePlayerPassthroughCmds cardinal.WithCommand[UpdatePlayerPassthroughCommand]
GetPlayerCmds cardinal.WithCommand[GetPlayerCommand]
GetAllPlayersCmds cardinal.WithCommand[GetAllPlayersCommand]
// Entities
Lobbies cardinal.Contains[struct {
Lobby cardinal.Ref[component.LobbyComponent]
}]
Players cardinal.Contains[struct {
Player cardinal.Ref[component.PlayerComponent]
}]
LobbyIndexes cardinal.Contains[struct {
Index cardinal.Ref[component.LobbyIndexComponent]
}]
Configs cardinal.Contains[struct {
Config cardinal.Ref[component.ConfigComponent]
}]
// Events (Broadcast)
LobbyCreatedEvents cardinal.WithEvent[LobbyCreatedEvent]
PlayerJoinedEvents cardinal.WithEvent[PlayerJoinedEvent]
PlayerLeftEvents cardinal.WithEvent[PlayerLeftEvent]
PlayerKickedEvents cardinal.WithEvent[PlayerKickedEvent]
PlayerReadyEvents cardinal.WithEvent[PlayerReadyEvent]
PlayerChangedTeamEvents cardinal.WithEvent[PlayerChangedTeamEvent]
LeaderChangedEvents cardinal.WithEvent[LeaderChangedEvent]
SessionStartedEvents cardinal.WithEvent[SessionStartedEvent]
SessionEndedEvents cardinal.WithEvent[SessionEndedEvent]
InviteCodeGeneratedEvents cardinal.WithEvent[InviteCodeGeneratedEvent]
LobbyDeletedEvents cardinal.WithEvent[LobbyDeletedEvent]
SessionPassthroughUpdatedEvents cardinal.WithEvent[SessionPassthroughUpdatedEvent]
PlayerPassthroughUpdatedEvents cardinal.WithEvent[PlayerPassthroughUpdatedEvent]
// CommandResult (request-prefixed responses)
CreateLobbyResults cardinal.WithEvent[CreateLobbyResult]
JoinLobbyResults cardinal.WithEvent[JoinLobbyResult]
JoinTeamResults cardinal.WithEvent[JoinTeamResult]
LeaveLobbyResults cardinal.WithEvent[LeaveLobbyResult]
SetReadyResults cardinal.WithEvent[SetReadyResult]
KickPlayerResults cardinal.WithEvent[KickPlayerResult]
TransferLeaderResults cardinal.WithEvent[TransferLeaderResult]
StartSessionResults cardinal.WithEvent[StartSessionResult]
GenerateInviteCodeResults cardinal.WithEvent[GenerateInviteCodeResult]
UpdateSessionPassthroughResults cardinal.WithEvent[UpdateSessionPassthroughResult]
UpdatePlayerPassthroughResults cardinal.WithEvent[UpdatePlayerPassthroughResult]
GetPlayerResults cardinal.WithEvent[GetPlayerResult]
GetAllPlayersResults cardinal.WithEvent[GetAllPlayersResult]
}
LobbySystemState is the state for the lobby system.
type NotifySessionEndCommand ¶
type NotifySessionEndCommand struct {
LobbyID string `json:"lobby_id"`
}
NotifySessionEndCommand is sent from game shard to lobby when session ends.
func (NotifySessionEndCommand) Name ¶
func (NotifySessionEndCommand) Name() string
Name returns the command name.
type NotifySessionStartCommand ¶
type NotifySessionStartCommand struct {
Lobby component.LobbyComponent `json:"lobby"`
LobbyWorld cardinal.OtherWorld `json:"lobby_world"`
}
NotifySessionStartCommand is sent to game shard when a session starts.
func (NotifySessionStartCommand) Name ¶
func (NotifySessionStartCommand) Name() string
Name returns the command name.
type PlayerChangedTeamEvent ¶
type PlayerChangedTeamEvent struct {
LobbyID string `json:"lobby_id"`
OldTeamName string `json:"old_team_name"`
NewTeamName string `json:"new_team_name"`
Player component.PlayerComponent `json:"player"`
}
PlayerChangedTeamEvent is emitted when a player changes team.
func (PlayerChangedTeamEvent) Name ¶
func (PlayerChangedTeamEvent) Name() string
Name returns the event name.
type PlayerJoinedEvent ¶
type PlayerJoinedEvent struct {
LobbyID string `json:"lobby_id"`
TeamName string `json:"team_name"`
Player component.PlayerComponent `json:"player"`
}
PlayerJoinedEvent is emitted when a player joins a lobby.
type PlayerKickedEvent ¶
type PlayerKickedEvent struct {
LobbyID string `json:"lobby_id"`
PlayerID string `json:"player_id"`
KickerID string `json:"kicker_id"`
}
PlayerKickedEvent is emitted when a player is kicked.
type PlayerLeftEvent ¶
PlayerLeftEvent is emitted when a player leaves a lobby.
type PlayerPassthroughUpdatedEvent ¶
type PlayerPassthroughUpdatedEvent struct {
LobbyID string `json:"lobby_id"`
Player component.PlayerComponent `json:"player"`
}
PlayerPassthroughUpdatedEvent is emitted when a player's passthrough data is updated.
func (PlayerPassthroughUpdatedEvent) Name ¶
func (PlayerPassthroughUpdatedEvent) Name() string
Name returns the event name.
type PlayerReadyEvent ¶
type PlayerReadyEvent struct {
LobbyID string `json:"lobby_id"`
Player component.PlayerComponent `json:"player"`
}
PlayerReadyEvent is emitted when a player changes ready status.
type PlayerTimedOutEvent ¶
type PlayerTimedOutEvent struct {
LobbyID string `json:"lobby_id"`
PlayerID string `json:"player_id"`
}
PlayerTimedOutEvent is emitted when a player is removed due to missed heartbeats.
func (PlayerTimedOutEvent) Name ¶
func (PlayerTimedOutEvent) Name() string
Name returns the event name.
type SessionEndedEvent ¶
type SessionEndedEvent struct {
LobbyID string `json:"lobby_id"`
}
SessionEndedEvent is emitted when a session ends.
type SessionPassthroughUpdatedEvent ¶
type SessionPassthroughUpdatedEvent struct {
LobbyID string `json:"lobby_id"`
PassthroughData map[string]any `json:"passthrough_data"`
}
SessionPassthroughUpdatedEvent is emitted when session passthrough data is updated.
func (SessionPassthroughUpdatedEvent) Name ¶
func (SessionPassthroughUpdatedEvent) Name() string
Name returns the event name.
type SessionStartedEvent ¶
type SessionStartedEvent struct {
LobbyID string `json:"lobby_id"`
}
SessionStartedEvent is emitted when a session starts.
func (SessionStartedEvent) Name ¶
func (SessionStartedEvent) Name() string
Name returns the event name.
type SetReadyCommand ¶
type SetReadyCommand struct {
RequestID string `json:"request_id"` // For matching request/response
IsReady bool `json:"is_ready"`
}
SetReadyCommand sets the player's ready status.
type SetReadyResult ¶
type SetReadyResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
Player component.PlayerComponent `json:"player,omitempty"`
}
SetReadyResult is sent back to the client after SetReadyCommand.
func (SetReadyResult) Name ¶
func (r SetReadyResult) Name() string
Name returns the request-prefixed event name.
type StartSessionCommand ¶
type StartSessionCommand struct {
RequestID string `json:"request_id"` // For matching request/response
}
StartSessionCommand starts the session (leader only).
func (StartSessionCommand) Name ¶
func (StartSessionCommand) Name() string
Name returns the command name.
type StartSessionPayload ¶
type StartSessionPayload = NotifySessionStartCommand
StartSessionPayload is an alias for NotifySessionStartCommand for documentation clarity.
type StartSessionResult ¶
type StartSessionResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
}
StartSessionResult is sent back to the client after StartSessionCommand.
func (StartSessionResult) Name ¶
func (r StartSessionResult) Name() string
Name returns the request-prefixed event name.
type TeamConfig ¶
TeamConfig defines initial team configuration.
type TransferLeaderCommand ¶
type TransferLeaderCommand struct {
RequestID string `json:"request_id"` // For matching request/response
TargetPlayerID string `json:"target_player_id"`
}
TransferLeaderCommand transfers leadership to another player.
func (TransferLeaderCommand) Name ¶
func (TransferLeaderCommand) Name() string
Name returns the command name.
type TransferLeaderResult ¶
type TransferLeaderResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
}
TransferLeaderResult is sent back to the client after TransferLeaderCommand.
func (TransferLeaderResult) Name ¶
func (r TransferLeaderResult) Name() string
Name returns the request-prefixed event name.
type UpdatePlayerPassthroughCommand ¶
type UpdatePlayerPassthroughCommand struct {
RequestID string `json:"request_id"` // For matching request/response
PassthroughData map[string]any `json:"passthrough_data"`
}
UpdatePlayerPassthroughCommand updates the player's own passthrough data.
func (UpdatePlayerPassthroughCommand) Name ¶
func (UpdatePlayerPassthroughCommand) Name() string
Name returns the command name.
type UpdatePlayerPassthroughResult ¶
type UpdatePlayerPassthroughResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
Player component.PlayerComponent `json:"player,omitempty"`
}
UpdatePlayerPassthroughResult is sent back to the client after UpdatePlayerPassthroughCommand.
func (UpdatePlayerPassthroughResult) Name ¶
func (r UpdatePlayerPassthroughResult) Name() string
Name returns the request-prefixed event name.
type UpdateSessionPassthroughCommand ¶
type UpdateSessionPassthroughCommand struct {
RequestID string `json:"request_id"` // For matching request/response
PassthroughData map[string]any `json:"passthrough_data"`
}
UpdateSessionPassthroughCommand updates the session passthrough data (leader only).
func (UpdateSessionPassthroughCommand) Name ¶
func (UpdateSessionPassthroughCommand) Name() string
Name returns the command name.
type UpdateSessionPassthroughResult ¶
type UpdateSessionPassthroughResult struct {
RequestID string `json:"request_id"`
IsSuccess bool `json:"is_success"`
Message string `json:"message"`
}
UpdateSessionPassthroughResult is sent back to the client after UpdateSessionPassthroughCommand.
func (UpdateSessionPassthroughResult) Name ¶
func (r UpdateSessionPassthroughResult) Name() string
Name returns the request-prefixed event name.