system

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodePassthrough added in v0.14.0

func DecodePassthrough(b []byte) (map[string]any, error)

DecodePassthrough turns a command's opaque JSON passthrough bytes into the map that components and events store and that downstream systems read. Empty input yields (nil, nil). Malformed input yields a non-nil error; passthrough is best-effort forwarded data the lobby does not validate, so callers log the error and proceed with a nil map rather than failing the command.

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 LobbySystem

func LobbySystem(state *LobbySystemState)

LobbySystem processes lobby commands.

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 AssignShardCommand

type AssignShardCommand struct {
	LobbyID   string                 `json:"lobby_id"`
	RequestID string                 `json:"request_id"`
	GameWorld component.ShardAddress `json:"game_world"`
	Reason    string                 `json:"reason,omitempty"`
}

AssignShardCommand is sent by an external orchestrator to complete a session start that is waiting in SessionStateAwaitingAllocation. The lobby writes GameWorld directly onto the lobby component, transitions to SessionStateInSession, and dispatches NotifySessionStartCommand. The orchestrator is responsible for providing a complete GameWorld address (Region, Organization, Project, ShardID).

If GameWorld.ShardID is empty, the assignment is treated as a failure: the lobby returns to SessionStateIdle and a failure StartSessionResult is emitted with Reason as the failure message.

RequestID must equal the lobby's current Session.PendingRequestID (which the orchestrator reads from the LobbyComponent). Mismatched RequestIDs are rejected; this rejects late duplicate or stale commands that arrive after the original pending cycle has already been completed or cancelled.

func (AssignShardCommand) FromProto added in v0.14.0

func (AssignShardCommand) MarshalWire added in v0.15.0

func (c AssignShardCommand) MarshalWire() ([]byte, error)

func (AssignShardCommand) Name

func (AssignShardCommand) Name() string

Name returns the command name.

func (AssignShardCommand) ToProto added in v0.14.0

func (AssignShardCommand) UnmarshalWire added in v0.15.0

func (c AssignShardCommand) UnmarshalWire(data []byte) (any, error)

type CreateLobbyCommand

type CreateLobbyCommand struct {
	RequestID string `json:"request_id"` // For matching request/response
	// Preset is the label of a server-registered team configuration.
	Preset string `json:"preset"`
	// PlayerPassthroughData is opaque JSON for the creating player, forwarded to the game shard.
	PlayerPassthroughData []byte `json:"player_passthrough_data,omitempty"`
	// SessionPassthroughData is opaque JSON for the lobby session, forwarded to the game shard.
	SessionPassthroughData []byte `json:"session_passthrough_data,omitempty"`
}

CreateLobbyCommand creates a new lobby with the sender as leader. The server resolves Preset against lobby.Config.LobbyPresets and rejects unknown or empty preset labels. Clients cannot supply arbitrary team configuration; the server is the source of truth.

The target game shard is not specified here: it is assigned later by an external orchestrator via AssignShardCommand when the session starts.

func (CreateLobbyCommand) FromProto added in v0.14.0

func (CreateLobbyCommand) MarshalWire added in v0.15.0

func (c CreateLobbyCommand) MarshalWire() ([]byte, error)

func (CreateLobbyCommand) Name

func (CreateLobbyCommand) Name() string

Name returns the command name.

func (CreateLobbyCommand) ToProto added in v0.14.0

func (CreateLobbyCommand) UnmarshalWire added in v0.15.0

func (c CreateLobbyCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (CreateLobbyResult) MarshalWire added in v0.15.0

func (c CreateLobbyResult) MarshalWire() ([]byte, error)

func (CreateLobbyResult) Name

func (r CreateLobbyResult) Name() string

Name returns the request-prefixed event name.

func (CreateLobbyResult) ToProto added in v0.15.0

func (CreateLobbyResult) UnmarshalWire added in v0.15.0

func (c CreateLobbyResult) UnmarshalWire(data []byte) (any, error)

type DefaultProvider

type DefaultProvider struct{}

DefaultProvider provides default implementations.

func (DefaultProvider) GenerateInviteCode

func (DefaultProvider) GenerateInviteCode(lobby *component.LobbyComponent, seed int64) string

GenerateInviteCode generates a 6-character invite code from Hash(LobbyID + seed). Pure in (lobby, seed): the caller owns the clock and must vary seed per attempt.

func (DefaultProvider) ValidateJoin

ValidateJoin accepts all joins by default. Games override this to enforce per-game requirements (version, region, level, etc.).

type GenerateInviteCodeCommand

type GenerateInviteCodeCommand struct {
	RequestID string `json:"request_id"` // For matching request/response
}

GenerateInviteCodeCommand generates a new invite code (leader only).

func (GenerateInviteCodeCommand) FromProto added in v0.14.0

func (GenerateInviteCodeCommand) MarshalWire added in v0.15.0

func (c GenerateInviteCodeCommand) MarshalWire() ([]byte, error)

func (GenerateInviteCodeCommand) Name

Name returns the command name.

func (GenerateInviteCodeCommand) ToProto added in v0.14.0

func (GenerateInviteCodeCommand) UnmarshalWire added in v0.15.0

func (c GenerateInviteCodeCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (GenerateInviteCodeResult) MarshalWire added in v0.15.0

func (c GenerateInviteCodeResult) MarshalWire() ([]byte, error)

func (GenerateInviteCodeResult) Name

Name returns the request-prefixed event name.

func (GenerateInviteCodeResult) ToProto added in v0.15.0

func (GenerateInviteCodeResult) UnmarshalWire added in v0.15.0

func (c GenerateInviteCodeResult) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.14.0

func (GetAllPlayersCommand) MarshalWire added in v0.15.0

func (c GetAllPlayersCommand) MarshalWire() ([]byte, error)

func (GetAllPlayersCommand) Name

Name returns the command name.

func (GetAllPlayersCommand) ToProto added in v0.14.0

func (GetAllPlayersCommand) UnmarshalWire added in v0.15.0

func (c GetAllPlayersCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (GetAllPlayersResult) MarshalWire added in v0.15.0

func (c GetAllPlayersResult) MarshalWire() ([]byte, error)

func (GetAllPlayersResult) Name

func (r GetAllPlayersResult) Name() string

Name returns the request-prefixed event name.

func (GetAllPlayersResult) ToProto added in v0.15.0

func (GetAllPlayersResult) UnmarshalWire added in v0.15.0

func (c GetAllPlayersResult) UnmarshalWire(data []byte) (any, error)

type GetLobbyCommand

type GetLobbyCommand struct {
	RequestID string `json:"request_id"` // For matching request/response
}

GetLobbyCommand fetches the caller's current lobby snapshot. Used by reconnecting clients to restore their full view (teams, session state, assigned GameWorld, etc.) in a single round-trip.

func (GetLobbyCommand) FromProto added in v0.14.0

func (GetLobbyCommand) MarshalWire added in v0.15.0

func (c GetLobbyCommand) MarshalWire() ([]byte, error)

func (GetLobbyCommand) Name

func (GetLobbyCommand) Name() string

Name returns the command name.

func (GetLobbyCommand) ToProto added in v0.14.0

func (c GetLobbyCommand) ToProto() *system.GetLobbyCommand

func (GetLobbyCommand) UnmarshalWire added in v0.15.0

func (c GetLobbyCommand) UnmarshalWire(data []byte) (any, error)

type GetLobbyResult

type GetLobbyResult struct {
	RequestID string                   `json:"request_id"`
	IsSuccess bool                     `json:"is_success"`
	Message   string                   `json:"message"`
	Lobby     component.LobbyComponent `json:"lobby,omitempty"`
}

GetLobbyResult is sent back to the client after GetLobbyCommand.

func (GetLobbyResult) FromProto added in v0.15.0

func (GetLobbyResult) MarshalWire added in v0.15.0

func (c GetLobbyResult) MarshalWire() ([]byte, error)

func (GetLobbyResult) Name

func (r GetLobbyResult) Name() string

Name returns the request-prefixed event name.

func (GetLobbyResult) ToProto added in v0.15.0

func (c GetLobbyResult) ToProto() *system.GetLobbyResult

func (GetLobbyResult) UnmarshalWire added in v0.15.0

func (c GetLobbyResult) UnmarshalWire(data []byte) (any, error)

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.

func (GetPlayerCommand) FromProto added in v0.14.0

func (GetPlayerCommand) MarshalWire added in v0.15.0

func (c GetPlayerCommand) MarshalWire() ([]byte, error)

func (GetPlayerCommand) Name

func (GetPlayerCommand) Name() string

Name returns the command name.

func (GetPlayerCommand) ToProto added in v0.14.0

func (GetPlayerCommand) UnmarshalWire added in v0.15.0

func (c GetPlayerCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (GetPlayerResult) MarshalWire added in v0.15.0

func (c GetPlayerResult) MarshalWire() ([]byte, error)

func (GetPlayerResult) Name

func (r GetPlayerResult) Name() string

Name returns the request-prefixed event name.

func (GetPlayerResult) ToProto added in v0.15.0

func (c GetPlayerResult) ToProto() *system.GetPlayerResult

func (GetPlayerResult) UnmarshalWire added in v0.15.0

func (c GetPlayerResult) UnmarshalWire(data []byte) (any, error)

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.

func (HeartbeatCommand) FromProto added in v0.14.0

func (HeartbeatCommand) MarshalWire added in v0.15.0

func (c HeartbeatCommand) MarshalWire() ([]byte, error)

func (HeartbeatCommand) Name

func (HeartbeatCommand) Name() string

Name returns the command name.

func (HeartbeatCommand) ToProto added in v0.14.0

func (HeartbeatCommand) UnmarshalWire added in v0.15.0

func (c HeartbeatCommand) UnmarshalWire(data []byte) (any, error)

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]
	StartSessionResults  cardinal.WithEvent[StartSessionResult]
}

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) FromProto added in v0.15.0

func (InviteCodeGeneratedEvent) MarshalWire added in v0.15.0

func (c InviteCodeGeneratedEvent) MarshalWire() ([]byte, error)

func (InviteCodeGeneratedEvent) Name

Name returns the event name.

func (InviteCodeGeneratedEvent) ToProto added in v0.15.0

func (InviteCodeGeneratedEvent) UnmarshalWire added in v0.15.0

func (c InviteCodeGeneratedEvent) UnmarshalWire(data []byte) (any, error)

type JoinLobbyCommand

type JoinLobbyCommand struct {
	RequestID  string `json:"request_id"`        // For matching request/response
	InviteCode string `json:"invite_code"`       // Required: invite code to join
	TeamID     string `json:"team_id,omitempty"` // Optional: team to join by ID (joins first available if empty)
	// PlayerPassthroughData is opaque JSON for the joining player, forwarded to the game shard.
	PlayerPassthroughData []byte `json:"player_passthrough_data,omitempty"`
}

JoinLobbyCommand joins an existing lobby via invite code.

func (JoinLobbyCommand) FromProto added in v0.14.0

func (JoinLobbyCommand) MarshalWire added in v0.15.0

func (c JoinLobbyCommand) MarshalWire() ([]byte, error)

func (JoinLobbyCommand) Name

func (JoinLobbyCommand) Name() string

Name returns the command name.

func (JoinLobbyCommand) ToProto added in v0.14.0

func (JoinLobbyCommand) UnmarshalWire added in v0.15.0

func (c JoinLobbyCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (JoinLobbyResult) MarshalWire added in v0.15.0

func (c JoinLobbyResult) MarshalWire() ([]byte, error)

func (JoinLobbyResult) Name

func (r JoinLobbyResult) Name() string

Name returns the request-prefixed event name.

func (JoinLobbyResult) ToProto added in v0.15.0

func (c JoinLobbyResult) ToProto() *system.JoinLobbyResult

func (JoinLobbyResult) UnmarshalWire added in v0.15.0

func (c JoinLobbyResult) UnmarshalWire(data []byte) (any, error)

type JoinTeamCommand

type JoinTeamCommand struct {
	RequestID string `json:"request_id"` // For matching request/response
	TeamID    string `json:"team_id"`
}

JoinTeamCommand moves a player to a different team.

func (JoinTeamCommand) FromProto added in v0.14.0

func (JoinTeamCommand) MarshalWire added in v0.15.0

func (c JoinTeamCommand) MarshalWire() ([]byte, error)

func (JoinTeamCommand) Name

func (JoinTeamCommand) Name() string

Name returns the command name.

func (JoinTeamCommand) ToProto added in v0.14.0

func (c JoinTeamCommand) ToProto() *system.JoinTeamCommand

func (JoinTeamCommand) UnmarshalWire added in v0.15.0

func (c JoinTeamCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (JoinTeamResult) MarshalWire added in v0.15.0

func (c JoinTeamResult) MarshalWire() ([]byte, error)

func (JoinTeamResult) Name

func (r JoinTeamResult) Name() string

Name returns the request-prefixed event name.

func (JoinTeamResult) ToProto added in v0.15.0

func (c JoinTeamResult) ToProto() *system.JoinTeamResult

func (JoinTeamResult) UnmarshalWire added in v0.15.0

func (c JoinTeamResult) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.14.0

func (KickPlayerCommand) MarshalWire added in v0.15.0

func (c KickPlayerCommand) MarshalWire() ([]byte, error)

func (KickPlayerCommand) Name

func (KickPlayerCommand) Name() string

Name returns the command name.

func (KickPlayerCommand) ToProto added in v0.14.0

func (KickPlayerCommand) UnmarshalWire added in v0.15.0

func (c KickPlayerCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (KickPlayerResult) MarshalWire added in v0.15.0

func (c KickPlayerResult) MarshalWire() ([]byte, error)

func (KickPlayerResult) Name

func (r KickPlayerResult) Name() string

Name returns the request-prefixed event name.

func (KickPlayerResult) ToProto added in v0.15.0

func (KickPlayerResult) UnmarshalWire added in v0.15.0

func (c KickPlayerResult) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (LeaderChangedEvent) MarshalWire added in v0.15.0

func (c LeaderChangedEvent) MarshalWire() ([]byte, error)

func (LeaderChangedEvent) Name

func (LeaderChangedEvent) Name() string

Name returns the event name.

func (LeaderChangedEvent) ToProto added in v0.15.0

func (LeaderChangedEvent) UnmarshalWire added in v0.15.0

func (c LeaderChangedEvent) UnmarshalWire(data []byte) (any, error)

type LeaveLobbyCommand

type LeaveLobbyCommand struct {
	RequestID string `json:"request_id"` // For matching request/response
}

LeaveLobbyCommand leaves the current lobby.

func (LeaveLobbyCommand) FromProto added in v0.14.0

func (LeaveLobbyCommand) MarshalWire added in v0.15.0

func (c LeaveLobbyCommand) MarshalWire() ([]byte, error)

func (LeaveLobbyCommand) Name

func (LeaveLobbyCommand) Name() string

Name returns the command name.

func (LeaveLobbyCommand) ToProto added in v0.14.0

func (LeaveLobbyCommand) UnmarshalWire added in v0.15.0

func (c LeaveLobbyCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (LeaveLobbyResult) MarshalWire added in v0.15.0

func (c LeaveLobbyResult) MarshalWire() ([]byte, error)

func (LeaveLobbyResult) Name

func (r LeaveLobbyResult) Name() string

Name returns the request-prefixed event name.

func (LeaveLobbyResult) ToProto added in v0.15.0

func (LeaveLobbyResult) UnmarshalWire added in v0.15.0

func (c LeaveLobbyResult) UnmarshalWire(data []byte) (any, error)

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.

func (LobbyCreatedEvent) FromProto added in v0.15.0

func (LobbyCreatedEvent) MarshalWire added in v0.15.0

func (c LobbyCreatedEvent) MarshalWire() ([]byte, error)

func (LobbyCreatedEvent) Name

func (LobbyCreatedEvent) Name() string

Name returns the event name.

func (LobbyCreatedEvent) ToProto added in v0.15.0

func (LobbyCreatedEvent) UnmarshalWire added in v0.15.0

func (c LobbyCreatedEvent) UnmarshalWire(data []byte) (any, error)

type LobbyDeletedEvent

type LobbyDeletedEvent struct {
	LobbyID string `json:"lobby_id"`
}

LobbyDeletedEvent is emitted when a lobby is deleted.

func (LobbyDeletedEvent) FromProto added in v0.15.0

func (LobbyDeletedEvent) MarshalWire added in v0.15.0

func (c LobbyDeletedEvent) MarshalWire() ([]byte, error)

func (LobbyDeletedEvent) Name

func (LobbyDeletedEvent) Name() string

Name returns the event name.

func (LobbyDeletedEvent) ToProto added in v0.15.0

func (LobbyDeletedEvent) UnmarshalWire added in v0.15.0

func (c LobbyDeletedEvent) UnmarshalWire(data []byte) (any, error)

type LobbyProvider

type LobbyProvider interface {
	// GenerateInviteCode generates a custom invite code for the lobby.
	//
	// seed is the only source of variation between calls for the same lobby, and
	// the caller must vary it per attempt: generateInviteCodeWithRetry retries on
	// collision and depends on each attempt yielding a different code.
	// Implementations should be pure in (lobby, seed).
	GenerateInviteCode(lobby *component.LobbyComponent, seed int64) string

	// ValidateJoin runs game-specific guards on a JoinLobbyCommand after
	// the generic guards (already-in-lobby, invalid code, in-session)
	// pass and before team selection. Return ok=false with a non-empty
	// reason to reject the join; the plugin emits a JoinLobbyResult
	// failure carrying that reason. Return ok=true to allow.
	ValidateJoin(lobby *component.LobbyComponent, cmd JoinLobbyCommand) (ok bool, reason 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]
	AssignShardCmds              cardinal.WithCommand[AssignShardCommand]
	GenerateInviteCodeCmds       cardinal.WithCommand[GenerateInviteCodeCommand]
	UpdateSessionPassthroughCmds cardinal.WithCommand[UpdateSessionPassthroughCommand]
	UpdatePlayerPassthroughCmds  cardinal.WithCommand[UpdatePlayerPassthroughCommand]
	GetPlayerCmds                cardinal.WithCommand[GetPlayerCommand]
	GetAllPlayersCmds            cardinal.WithCommand[GetAllPlayersCommand]
	GetLobbyCmds                 cardinal.WithCommand[GetLobbyCommand]

	// 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]
	SessionAwaitingAllocationEvents cardinal.WithEvent[SessionAwaitingAllocationEvent]
	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]
	GetLobbyResults                 cardinal.WithEvent[GetLobbyResult]
}

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) FromProto added in v0.14.0

func (NotifySessionEndCommand) MarshalWire added in v0.15.0

func (c NotifySessionEndCommand) MarshalWire() ([]byte, error)

func (NotifySessionEndCommand) Name

Name returns the command name.

func (NotifySessionEndCommand) ToProto added in v0.14.0

func (NotifySessionEndCommand) UnmarshalWire added in v0.15.0

func (c NotifySessionEndCommand) UnmarshalWire(data []byte) (any, error)

type NotifySessionStartCommand

type NotifySessionStartCommand struct {
	LobbyID    string                 `json:"lobby_id"`
	LobbyWorld component.ShardAddress `json:"lobby_world"`
}

NotifySessionStartCommand is sent to game shard when a session starts. NotifySessionStartCommand tells the game shard a session is starting. It's a wire DTO: it carries only what the receiver needs (the lobby id and this lobby shard's address to reply to), not the live LobbyComponent/PlayerComponent — those are domain types and never go on the wire.

func (NotifySessionStartCommand) FromProto added in v0.14.0

func (NotifySessionStartCommand) MarshalWire added in v0.15.0

func (c NotifySessionStartCommand) MarshalWire() ([]byte, error)

func (NotifySessionStartCommand) Name

Name returns the command name.

func (NotifySessionStartCommand) ToProto added in v0.14.0

func (NotifySessionStartCommand) UnmarshalWire added in v0.15.0

func (c NotifySessionStartCommand) UnmarshalWire(data []byte) (any, error)

type PlayerChangedTeamEvent

type PlayerChangedTeamEvent struct {
	LobbyID   string                    `json:"lobby_id"`
	OldTeamID string                    `json:"old_team_id"`
	NewTeamID string                    `json:"new_team_id"`
	Player    component.PlayerComponent `json:"player"`
}

PlayerChangedTeamEvent is emitted when a player changes team.

func (PlayerChangedTeamEvent) FromProto added in v0.15.0

func (PlayerChangedTeamEvent) MarshalWire added in v0.15.0

func (c PlayerChangedTeamEvent) MarshalWire() ([]byte, error)

func (PlayerChangedTeamEvent) Name

Name returns the event name.

func (PlayerChangedTeamEvent) ToProto added in v0.15.0

func (PlayerChangedTeamEvent) UnmarshalWire added in v0.15.0

func (c PlayerChangedTeamEvent) UnmarshalWire(data []byte) (any, error)

type PlayerJoinedEvent

type PlayerJoinedEvent struct {
	LobbyID string                    `json:"lobby_id"`
	TeamID  string                    `json:"team_id"`
	Player  component.PlayerComponent `json:"player"`
}

PlayerJoinedEvent is emitted when a player joins a lobby.

func (PlayerJoinedEvent) FromProto added in v0.15.0

func (PlayerJoinedEvent) MarshalWire added in v0.15.0

func (c PlayerJoinedEvent) MarshalWire() ([]byte, error)

func (PlayerJoinedEvent) Name

func (PlayerJoinedEvent) Name() string

Name returns the event name.

func (PlayerJoinedEvent) ToProto added in v0.15.0

func (PlayerJoinedEvent) UnmarshalWire added in v0.15.0

func (c PlayerJoinedEvent) UnmarshalWire(data []byte) (any, error)

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.

func (PlayerKickedEvent) FromProto added in v0.15.0

func (PlayerKickedEvent) MarshalWire added in v0.15.0

func (c PlayerKickedEvent) MarshalWire() ([]byte, error)

func (PlayerKickedEvent) Name

func (PlayerKickedEvent) Name() string

Name returns the event name.

func (PlayerKickedEvent) ToProto added in v0.15.0

func (PlayerKickedEvent) UnmarshalWire added in v0.15.0

func (c PlayerKickedEvent) UnmarshalWire(data []byte) (any, error)

type PlayerLeftEvent

type PlayerLeftEvent struct {
	LobbyID  string `json:"lobby_id"`
	PlayerID string `json:"player_id"`
}

PlayerLeftEvent is emitted when a player leaves a lobby.

func (PlayerLeftEvent) FromProto added in v0.15.0

func (PlayerLeftEvent) MarshalWire added in v0.15.0

func (c PlayerLeftEvent) MarshalWire() ([]byte, error)

func (PlayerLeftEvent) Name

func (PlayerLeftEvent) Name() string

Name returns the event name.

func (PlayerLeftEvent) ToProto added in v0.15.0

func (c PlayerLeftEvent) ToProto() *system.PlayerLeftEvent

func (PlayerLeftEvent) UnmarshalWire added in v0.15.0

func (c PlayerLeftEvent) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (PlayerPassthroughUpdatedEvent) MarshalWire added in v0.15.0

func (c PlayerPassthroughUpdatedEvent) MarshalWire() ([]byte, error)

func (PlayerPassthroughUpdatedEvent) Name

Name returns the event name.

func (PlayerPassthroughUpdatedEvent) ToProto added in v0.15.0

func (PlayerPassthroughUpdatedEvent) UnmarshalWire added in v0.15.0

func (c PlayerPassthroughUpdatedEvent) UnmarshalWire(data []byte) (any, error)

type PlayerReadyEvent

type PlayerReadyEvent struct {
	LobbyID string                    `json:"lobby_id"`
	Player  component.PlayerComponent `json:"player"`
}

PlayerReadyEvent is emitted when a player changes ready status.

func (PlayerReadyEvent) FromProto added in v0.15.0

func (PlayerReadyEvent) MarshalWire added in v0.15.0

func (c PlayerReadyEvent) MarshalWire() ([]byte, error)

func (PlayerReadyEvent) Name

func (PlayerReadyEvent) Name() string

Name returns the event name.

func (PlayerReadyEvent) ToProto added in v0.15.0

func (PlayerReadyEvent) UnmarshalWire added in v0.15.0

func (c PlayerReadyEvent) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (PlayerTimedOutEvent) MarshalWire added in v0.15.0

func (c PlayerTimedOutEvent) MarshalWire() ([]byte, error)

func (PlayerTimedOutEvent) Name

func (PlayerTimedOutEvent) Name() string

Name returns the event name.

func (PlayerTimedOutEvent) ToProto added in v0.15.0

func (PlayerTimedOutEvent) UnmarshalWire added in v0.15.0

func (c PlayerTimedOutEvent) UnmarshalWire(data []byte) (any, error)

type SessionAwaitingAllocationEvent

type SessionAwaitingAllocationEvent struct {
	LobbyID string `json:"lobby_id"`
}

SessionAwaitingAllocationEvent is emitted when a session is awaiting shard assignment. External orchestrators listen for this event and respond with an AssignShardCommand to complete the session start.

func (SessionAwaitingAllocationEvent) FromProto added in v0.15.0

func (SessionAwaitingAllocationEvent) MarshalWire added in v0.15.0

func (c SessionAwaitingAllocationEvent) MarshalWire() ([]byte, error)

func (SessionAwaitingAllocationEvent) Name

Name returns the event name.

func (SessionAwaitingAllocationEvent) ToProto added in v0.15.0

func (SessionAwaitingAllocationEvent) UnmarshalWire added in v0.15.0

func (c SessionAwaitingAllocationEvent) UnmarshalWire(data []byte) (any, error)

type SessionEndedEvent

type SessionEndedEvent struct {
	LobbyID string `json:"lobby_id"`
}

SessionEndedEvent is emitted when a session ends.

func (SessionEndedEvent) FromProto added in v0.15.0

func (SessionEndedEvent) MarshalWire added in v0.15.0

func (c SessionEndedEvent) MarshalWire() ([]byte, error)

func (SessionEndedEvent) Name

func (SessionEndedEvent) Name() string

Name returns the event name.

func (SessionEndedEvent) ToProto added in v0.15.0

func (SessionEndedEvent) UnmarshalWire added in v0.15.0

func (c SessionEndedEvent) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (SessionPassthroughUpdatedEvent) MarshalWire added in v0.15.0

func (c SessionPassthroughUpdatedEvent) MarshalWire() ([]byte, error)

func (SessionPassthroughUpdatedEvent) Name

Name returns the event name.

func (SessionPassthroughUpdatedEvent) ToProto added in v0.15.0

func (SessionPassthroughUpdatedEvent) UnmarshalWire added in v0.15.0

func (c SessionPassthroughUpdatedEvent) UnmarshalWire(data []byte) (any, error)

type SessionStartedEvent

type SessionStartedEvent struct {
	LobbyID   string                 `json:"lobby_id"`
	GameWorld component.ShardAddress `json:"game_world"`
}

SessionStartedEvent is emitted when a session starts. Carries the assigned game shard address so every player in the lobby (not just the session starter) learns which gameplay shard to connect to without a follow-up query.

func (SessionStartedEvent) FromProto added in v0.15.0

func (SessionStartedEvent) MarshalWire added in v0.15.0

func (c SessionStartedEvent) MarshalWire() ([]byte, error)

func (SessionStartedEvent) Name

func (SessionStartedEvent) Name() string

Name returns the event name.

func (SessionStartedEvent) ToProto added in v0.15.0

func (SessionStartedEvent) UnmarshalWire added in v0.15.0

func (c SessionStartedEvent) UnmarshalWire(data []byte) (any, error)

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.

func (SetReadyCommand) FromProto added in v0.14.0

func (SetReadyCommand) MarshalWire added in v0.15.0

func (c SetReadyCommand) MarshalWire() ([]byte, error)

func (SetReadyCommand) Name

func (SetReadyCommand) Name() string

Name returns the command name.

func (SetReadyCommand) ToProto added in v0.14.0

func (c SetReadyCommand) ToProto() *system.SetReadyCommand

func (SetReadyCommand) UnmarshalWire added in v0.15.0

func (c SetReadyCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (SetReadyResult) MarshalWire added in v0.15.0

func (c SetReadyResult) MarshalWire() ([]byte, error)

func (SetReadyResult) Name

func (r SetReadyResult) Name() string

Name returns the request-prefixed event name.

func (SetReadyResult) ToProto added in v0.15.0

func (c SetReadyResult) ToProto() *system.SetReadyResult

func (SetReadyResult) UnmarshalWire added in v0.15.0

func (c SetReadyResult) UnmarshalWire(data []byte) (any, error)

type StartSessionCommand

type StartSessionCommand struct {
	RequestID string `json:"request_id"` // For matching request/response
}

StartSessionCommand starts the session (leader only). The corresponding StartSessionResult is emitted asynchronously, typically several ticks after this command is accepted, once an orchestrator responds with AssignShardCommand. Clients must not set short timeouts on StartSessionResult.

func (StartSessionCommand) FromProto added in v0.14.0

func (StartSessionCommand) MarshalWire added in v0.15.0

func (c StartSessionCommand) MarshalWire() ([]byte, error)

func (StartSessionCommand) Name

func (StartSessionCommand) Name() string

Name returns the command name.

func (StartSessionCommand) ToProto added in v0.14.0

func (StartSessionCommand) UnmarshalWire added in v0.15.0

func (c StartSessionCommand) UnmarshalWire(data []byte) (any, error)

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"`
	GameWorld component.ShardAddress `json:"game_world,omitempty"`
}

StartSessionResult is sent back to the client after StartSessionCommand. Emitted asynchronously — may arrive several ticks after the command, once the orchestrator assigns a game shard via AssignShardCommand. On success, GameWorld holds the assigned shard address so the client can connect without an extra query. Zero-valued on failure.

func (StartSessionResult) FromProto added in v0.15.0

func (StartSessionResult) MarshalWire added in v0.15.0

func (c StartSessionResult) MarshalWire() ([]byte, error)

func (StartSessionResult) Name

func (r StartSessionResult) Name() string

Name returns the request-prefixed event name.

func (StartSessionResult) ToProto added in v0.15.0

func (StartSessionResult) UnmarshalWire added in v0.15.0

func (c StartSessionResult) UnmarshalWire(data []byte) (any, error)

type TeamConfig

type TeamConfig = component.TeamConfig

TeamConfig is an alias for component.TeamConfig to preserve the existing external type path (lobby.TeamConfig).

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) FromProto added in v0.14.0

func (TransferLeaderCommand) MarshalWire added in v0.15.0

func (c TransferLeaderCommand) MarshalWire() ([]byte, error)

func (TransferLeaderCommand) Name

Name returns the command name.

func (TransferLeaderCommand) ToProto added in v0.14.0

func (TransferLeaderCommand) UnmarshalWire added in v0.15.0

func (c TransferLeaderCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (TransferLeaderResult) MarshalWire added in v0.15.0

func (c TransferLeaderResult) MarshalWire() ([]byte, error)

func (TransferLeaderResult) Name

func (r TransferLeaderResult) Name() string

Name returns the request-prefixed event name.

func (TransferLeaderResult) ToProto added in v0.15.0

func (TransferLeaderResult) UnmarshalWire added in v0.15.0

func (c TransferLeaderResult) UnmarshalWire(data []byte) (any, error)

type UpdatePlayerPassthroughCommand

type UpdatePlayerPassthroughCommand struct {
	RequestID       string `json:"request_id"` // For matching request/response
	PassthroughData []byte `json:"passthrough_data"`
}

UpdatePlayerPassthroughCommand updates the player's own passthrough data.

func (UpdatePlayerPassthroughCommand) FromProto added in v0.14.0

func (UpdatePlayerPassthroughCommand) MarshalWire added in v0.15.0

func (c UpdatePlayerPassthroughCommand) MarshalWire() ([]byte, error)

func (UpdatePlayerPassthroughCommand) Name

Name returns the command name.

func (UpdatePlayerPassthroughCommand) ToProto added in v0.14.0

func (UpdatePlayerPassthroughCommand) UnmarshalWire added in v0.15.0

func (c UpdatePlayerPassthroughCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (UpdatePlayerPassthroughResult) MarshalWire added in v0.15.0

func (c UpdatePlayerPassthroughResult) MarshalWire() ([]byte, error)

func (UpdatePlayerPassthroughResult) Name

Name returns the request-prefixed event name.

func (UpdatePlayerPassthroughResult) ToProto added in v0.15.0

func (UpdatePlayerPassthroughResult) UnmarshalWire added in v0.15.0

func (c UpdatePlayerPassthroughResult) UnmarshalWire(data []byte) (any, error)

type UpdateSessionPassthroughCommand

type UpdateSessionPassthroughCommand struct {
	RequestID       string `json:"request_id"` // For matching request/response
	PassthroughData []byte `json:"passthrough_data"`
}

UpdateSessionPassthroughCommand updates the session passthrough data (leader only).

func (UpdateSessionPassthroughCommand) FromProto added in v0.14.0

func (UpdateSessionPassthroughCommand) MarshalWire added in v0.15.0

func (c UpdateSessionPassthroughCommand) MarshalWire() ([]byte, error)

func (UpdateSessionPassthroughCommand) Name

Name returns the command name.

func (UpdateSessionPassthroughCommand) ToProto added in v0.14.0

func (UpdateSessionPassthroughCommand) UnmarshalWire added in v0.15.0

func (c UpdateSessionPassthroughCommand) UnmarshalWire(data []byte) (any, error)

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) FromProto added in v0.15.0

func (UpdateSessionPassthroughResult) MarshalWire added in v0.15.0

func (c UpdateSessionPassthroughResult) MarshalWire() ([]byte, error)

func (UpdateSessionPassthroughResult) Name

Name returns the request-prefixed event name.

func (UpdateSessionPassthroughResult) ToProto added in v0.15.0

func (UpdateSessionPassthroughResult) UnmarshalWire added in v0.15.0

func (c UpdateSessionPassthroughResult) UnmarshalWire(data []byte) (any, error)

Jump to

Keyboard shortcuts

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