Skip to content

Commit 433d9b2

Browse files
feat(lobby): added a new player component parameter to notifysessionstart command to streamline processes (#892)
1 parent 00575fa commit 433d9b2

2 files changed

Lines changed: 15 additions & 26 deletions

File tree

pkg/plugin/lobby/system/lobby.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import (
1919
// The server resolves Preset against lobby.Config.LobbyPresets and
2020
// rejects unknown or empty preset labels. Clients cannot supply
2121
// arbitrary team configuration; the server is the source of truth.
22+
//
23+
// The target game shard is not specified here: it is assigned later by
24+
// an external orchestrator via AssignShardCommand when the session starts.
2225
type CreateLobbyCommand struct {
2326
RequestID string `json:"request_id"` // For matching request/response
2427
// Preset is the label of a server-registered team configuration.
2528
Preset string `json:"preset"`
26-
// GameWorld is the target game shard address for this lobby.
27-
GameWorld cardinal.OtherWorld `json:"game_world"`
2829
// PlayerPassthroughData is custom data for the creating player, forwarded to game shard.
2930
PlayerPassthroughData map[string]any `json:"player_passthrough_data,omitempty"`
3031
// SessionPassthroughData is custom data for the lobby session, forwarded to game shard.
@@ -490,8 +491,9 @@ func (r GetLobbyResult) Name() string {
490491

491492
// NotifySessionStartCommand is sent to game shard when a session starts.
492493
type NotifySessionStartCommand struct {
493-
Lobby component.LobbyComponent `json:"lobby"`
494-
LobbyWorld cardinal.OtherWorld `json:"lobby_world"`
494+
Lobby component.LobbyComponent `json:"lobby"`
495+
LobbyWorld cardinal.OtherWorld `json:"lobby_world"`
496+
Players []component.PlayerComponent `json:"players"`
495497
}
496498

497499
// Name returns the command name.
@@ -1122,7 +1124,6 @@ func processCreateLobbyCommands(
11221124
ID: lobbyID,
11231125
LeaderID: playerID,
11241126
InviteCode: "", // Will be set after generation
1125-
GameWorld: payload.GameWorld,
11261127
Session: component.Session{
11271128
State: component.SessionStateIdle,
11281129
PassthroughData: payload.SessionPassthroughData,
@@ -1868,15 +1869,18 @@ func abortAwaitingAllocation(
18681869
// configured on the lobby. No-op if no game shard is configured.
18691870
func dispatchSessionStart(
18701871
state *LobbySystemState,
1872+
lobbyIndex *component.LobbyIndexComponent,
18711873
config *component.ConfigComponent,
18721874
lobby *component.LobbyComponent,
18731875
lobbyID string,
18741876
) {
18751877
gameWorld := lobby.GameWorld
18761878
lobbyWorld := config.LobbyWorld
1879+
players := gatherLobbyPlayers(state, lobbyIndex, lobby)
18771880
gameWorld.SendCommand(&state.BaseSystemState, NotifySessionStartCommand{
18781881
Lobby: *lobby,
18791882
LobbyWorld: lobbyWorld,
1883+
Players: players,
18801884
})
18811885
state.Logger().Info().
18821886
Str("lobby_id", lobbyID).
@@ -1963,7 +1967,7 @@ func processAssignShardCommands(
19631967
GameWorld: lobby.GameWorld,
19641968
})
19651969

1966-
dispatchSessionStart(state, config, &lobby, payload.LobbyID)
1970+
dispatchSessionStart(state, lobbyIndex, config, &lobby, payload.LobbyID)
19671971

19681972
state.StartSessionResults.Emit(StartSessionResult{
19691973
RequestID: requestID,
@@ -2031,6 +2035,11 @@ func processNotifySessionEndCommands(state *LobbySystemState, lobbyIndex *compon
20312035
playerComp := playerEntity.Player.Get()
20322036
playerComp.IsReady = false
20332037
playerEntity.Player.Set(playerComp)
2038+
2039+
state.PlayerReadyEvents.Emit(PlayerReadyEvent{
2040+
LobbyID: payload.LobbyID,
2041+
Player: playerComp,
2042+
})
20342043
}
20352044

20362045
state.Logger().Info().

pkg/plugin/lobby/system/lobby_internal_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -338,26 +338,6 @@ func TestGameWorld(t *testing.T) {
338338
assert.Equal(t, "game-shard-1", gameWorld.ShardID)
339339
}
340340

341-
func TestCreateLobbyCommand_WithGameWorld(t *testing.T) {
342-
t.Parallel()
343-
344-
cmd := CreateLobbyCommand{
345-
RequestID: "req-123",
346-
Preset: "2v2",
347-
GameWorld: cardinal.OtherWorld{
348-
Region: "us-west",
349-
Organization: "myorg",
350-
Project: "myproject",
351-
ShardID: "game-shard-1",
352-
},
353-
}
354-
355-
assert.Equal(t, "req-123", cmd.RequestID)
356-
assert.Equal(t, "2v2", cmd.Preset)
357-
assert.Equal(t, "game-shard-1", cmd.GameWorld.ShardID)
358-
assert.Equal(t, "lobby_create", cmd.Name())
359-
}
360-
361341
func TestLobbyComponent_WithGameWorld(t *testing.T) {
362342
t.Parallel()
363343

0 commit comments

Comments
 (0)