hytopia 0.10.40 → 0.10.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/bin/scripts.js +53 -1
  2. package/package.json +1 -1
  3. package/server.mjs +267 -200
package/bin/scripts.js CHANGED
@@ -41,10 +41,14 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
41
41
  'init-mcp': initMcp,
42
42
  'package': packageProject,
43
43
  'start': start,
44
+ 'update-hosts': () => checkHostsConfiguration(true),
44
45
  'upgrade-cli': () => upgradeCli(process.argv[3] || 'latest'),
45
46
  'upgrade-project': () => upgradeProject(process.argv[3] || 'latest'),
46
47
  'version': displayVersion,
47
48
  };
49
+
50
+ // Check that hosts is properly configured
51
+ checkHostsConfiguration(false);
48
52
 
49
53
  const handler = commandHandlers[command];
50
54
 
@@ -470,7 +474,6 @@ async function packageProject() {
470
474
  // UTILITY FUNCTIONS
471
475
  // ================================================================================
472
476
 
473
- // set priority level for takahiro tickets
474
477
 
475
478
  async function build(devMode = false) {
476
479
  let envFlags = devMode ? '' : '--minify --sourcemap=inline';
@@ -478,6 +481,54 @@ async function build(devMode = false) {
478
481
  execSync(`npx --yes bun build --target=node --env=disable --format=esm ${envFlags} --outfile=index.mjs index.ts`, { stdio: 'inherit' });
479
482
  }
480
483
 
484
+ /**
485
+ * Checks the hosts files and makes sure that dev-local.hytopia.com points to localhost.
486
+ */
487
+ function checkHostsConfiguration(verbose = false) {
488
+ const DOMAIN = 'dev-local.hytopia.com';
489
+ const isWindows = process.platform === 'win32';
490
+ const hostsPath = isWindows
491
+ ? path.join(process.env.SystemRoot || 'C://Windows', 'System32', 'drivers', 'etc', 'hosts')
492
+ : '/etc/hosts';
493
+
494
+ let content = '';
495
+ try {
496
+ content = fs.existsSync(hostsPath) ? fs.readFileSync(hostsPath, 'utf8') : '';
497
+ } catch {
498
+ console.warn(`⚠️ Unable to check hosts configuration. If you can connect to your local server you can ignore this. Otherwise, run 'sudo hytopia update-hosts' to fix this.`);
499
+ return; // no read access; skip silently
500
+ }
501
+
502
+ const managedBegin = '# HYTOPIA DEV-LOCAL BEGIN';
503
+ const managedEnd = '# HYTOPIA DEV-LOCAL END';
504
+
505
+ if (content.includes(managedBegin) && content.includes(managedEnd)) {
506
+ if (verbose) {
507
+ console.log(`✅ Hosts already configured: ${DOMAIN} -> 127.0.0.1, ::1`);
508
+ }
509
+
510
+ return; // already configured by us, skip
511
+ }
512
+
513
+ const EOL = content.includes('\r\n') ? '\r\n' : '\n';
514
+ const block = [
515
+ managedBegin,
516
+ `127.0.0.1 ${DOMAIN}`,
517
+ `::1 ${DOMAIN}`,
518
+ managedEnd,
519
+ ''
520
+ ].join(EOL);
521
+
522
+ const newContent = block + content;
523
+
524
+ try {
525
+ fs.writeFileSync(hostsPath, newContent, { encoding: 'utf8' });
526
+ console.log(`✅ Hosts updated: ${DOMAIN} -> 127.0.0.1, ::1`);
527
+ } catch {
528
+ console.error(`⚠️ Could not modify hosts file (${hostsPath}) to add the dev-local.hytopia.com. Please run 'sudo hytopia update-hosts' to fix this.`);
529
+ }
530
+ }
531
+
481
532
  /**
482
533
  * Parses command-line flags in the format --flag value
483
534
  */
@@ -614,6 +665,7 @@ function displayHelp() {
614
665
  console.log(' init [--template NAME] Initialize a new project');
615
666
  console.log(' init-mcp Setup MCP integrations');
616
667
  console.log(' package Create a zip of the project for uploading to the HYTOPIA create portal.');
668
+ console.log(' update-hosts Update the hosts file to add the dev-local.hytopia.com domain (MUST RUN WITH SUDO: sudo hytopia update-hosts)');
617
669
  console.log(' upgrade-cli Upgrade the HYTOPIA CLI');
618
670
  console.log(' upgrade-project [VERSION] Upgrade project SDK dep (default: latest)');
619
671
  console.log('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hytopia",
3
- "version": "0.10.40",
3
+ "version": "0.10.42",
4
4
  "description": "The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./server.mjs",