@@ -18,9 +18,11 @@ const EXIT_UNAVAILABLE = 78
1818
1919type ServerEngine = 'bevy' | 'hammurabi'
2020
21+ const DEFAULT_ENGINE : ServerEngine = 'bevy'
22+
2123function selectedEngine ( ) : ServerEngine {
2224 const requested = process . env . DCL_SERVER_ENGINE
23- return requested === 'bevy' || requested === 'hammurabi' ? requested : 'hammurabi'
25+ return requested === 'bevy' || requested === 'hammurabi' ? requested : DEFAULT_ENGINE
2426}
2527
2628/**
@@ -52,11 +54,11 @@ function registerProcessCleanup(cleanup: () => void): () => void {
5254/**
5355 * Starts the Multiplayer Server process using npx to install and run in one step
5456 */
55- export function startHammurabiServer (
57+ export function startMultiplayerServer (
5658 components : Pick < CliComponents , 'logger' > ,
5759 workingDir : string ,
5860 realm : string ,
59- engine : ServerEngine = 'hammurabi'
61+ engine : ServerEngine = DEFAULT_ENGINE
6062) : ChildProcess {
6163 const pkg = packageSpec ( engine )
6264
@@ -75,40 +77,40 @@ export function startHammurabiServer(
7577
7678 // If npx-cli.js was found, run it directly via process.execPath (node in regular env,
7779 // Electron Helper with ELECTRON_RUN_AS_NODE=1 in Electron). Otherwise fall back to npx binary.
78- const hammurabiProcess = npxCliJs
80+ const serverProcess = npxCliJs
7981 ? spawn ( process . execPath , [ npxCliJs , ...npxArgs ] , { cwd : workingDir , shell : false , stdio : 'inherit' , env } )
8082 : spawn ( getNpxBin ( ) , npxArgs , { cwd : workingDir , shell : false , stdio : 'inherit' , env } )
8183
82- hammurabiProcess . on ( 'error' , ( error ) => {
84+ serverProcess . on ( 'error' , ( error ) => {
8385 printWarning ( components . logger , `Multiplayer Server process error: ${ error . message } ` )
8486 } )
8587
8688 // Register cleanup handlers
8789 const cleanup = ( ) => {
88- if ( ! hammurabiProcess . killed ) {
89- hammurabiProcess . kill ( 'SIGTERM' )
90+ if ( ! serverProcess . killed ) {
91+ serverProcess . kill ( 'SIGTERM' )
9092 }
9193 }
9294
9395 const removeCleanup = registerProcessCleanup ( cleanup )
9496
95- hammurabiProcess . on ( 'close' , ( code ) => {
97+ serverProcess . on ( 'close' , ( code ) => {
9698 removeCleanup ( )
9799 if ( code !== 0 && code !== null ) {
98100 printWarning ( components . logger , `Multiplayer Server exited with code ${ code } ` )
99101 }
100102 } )
101103
102- return hammurabiProcess
104+ return serverProcess
103105}
104106
105107/**
106108 * Spawns the multiplayer server for the project.
107109 * In the auth-server SDK, all scenes are authoritative multiplayer.
108110 * Uses npx to handle installation and execution in a single step (works in Electron).
109111 *
110- * Which implementation runs is chosen by DCL_SERVER_ENGINE (bevy | hammurabi). When bevy
111- * reports itself unavailable on this machine, hammurabi is started instead.
112+ * Which implementation runs is chosen by DCL_SERVER_ENGINE (bevy | hammurabi), defaulting
113+ * to bevy. When bevy reports itself unavailable on this machine, hammurabi is started instead.
112114 *
113115 * @param components - Preview components including logger
114116 * @param project - The project to start the multiplayer server for
@@ -122,12 +124,14 @@ export function spawnAuthServer(
122124) : ChildProcess | undefined {
123125 const engine = selectedEngine ( )
124126 try {
125- const child = startHammurabiServer ( components , project . workingDirectory , realm , engine )
126- if ( engine === 'bevy' ) {
127+ const child = startMultiplayerServer ( components , project . workingDirectory , realm , engine )
128+ // No fallback when DCL_SERVER_PACKAGE is set: packageSpec would resolve the
129+ // hammurabi retry to the same overridden package that just exited 78.
130+ if ( engine === 'bevy' && ! process . env . DCL_SERVER_PACKAGE ) {
127131 child . on ( 'close' , ( code ) => {
128132 if ( code === EXIT_UNAVAILABLE ) {
129133 printWarning ( components . logger , 'Bevy multiplayer server unavailable here — falling back to hammurabi' )
130- startHammurabiServer ( components , project . workingDirectory , realm , 'hammurabi' )
134+ startMultiplayerServer ( components , project . workingDirectory , realm , 'hammurabi' )
131135 }
132136 } )
133137 }
0 commit comments