1. 프론트엔드 (MultiGameListController)

1-1. 사용자 클릭 → 소켓 이벤트 발송

ts
**// (호스트만 적용) 사용자가 “게임 선택” 버튼을 누르면 호출**
onSelectButtonClick() {
    if (!this.selectedScene) return;

    const roomId = GameState.createdRoomId;
    // GameState.isHost는 true여야 함
    if (GameState.isHost && roomId && window.socket) {
        window.socket.emit("game-event", {
            type: "move-scene",
            payload: { sceneName: this.selectedScene },
            roomId,
        });
    }
}

1-2. 서버로부터 씬 전환 요청 수신 → 씬 로드

ts
// onLoad() 내부에 등록된 게임 이벤트 리스너
this._gameEventHandler = (message: any) => {
    switch (message.type) {
        case "move-scene":
            const sceneName = message.payload?.sceneName;
            if (sceneName) {
                **// 서버에서 “move-scene”을 브로드캐스트(정상적으로 emit수신 후)하면 씬 전환**
                cc.director.loadScene(sceneName);
            }
            break;

        case "host-left":
            // 호스트가 나가면 MainScene으로 복귀
            GameState.resetMultiplay();
            cc.director.loadScene("MainScene");
            break;

        default:
            break;
    }
};
window.socket.on("game-event", this._gameEventHandler);


2. 백엔드 (Socket.IO 서버)

2-1. 클라이언트 연결 및 방 입장

js
io.on("connection", (socket) => {
    **// 클라이언트가 방 입장을 요청했을 때**
    socket.on("join-room", (roomId) => {
        socket.join(roomId);
    });
    // .. game-event, leave-room 등 이벤트 내용…
});

2-2. “move-scene” 이벤트 처리 및 전파

js
socket.on("game-event", async (data) => {
    const { type, payload, roomId } = data;
    if (!roomId) return;

    switch (type) {
        case "move-scene":
       **// payload.sceneName이 반드시 있어야 함(선택한 게임 씬)**
            if (!payload?.sceneName) return;
       **// 1.2초 딜레이(게스트,호스트 수신 타이밍 고려) 후 방 전체에 동일 이벤트 브로드캐스트**
            setTimeout(() => {
                io.to(roomId).emit("game-event", {
                    type: "move-scene",
                    **payload: { sceneName: payload.sceneName }(클라이언트 emit 필수 정보)**
                });
            }, 1200);
            break;

        // … game-event 타입(점수 저장, spawn-mole 등)
    }
});