homegames-common 1.5.0 → 1.5.2
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.
- package/docker-helper.js +5 -3
- package/game-loader.js +2 -1
- package/game-session-manager.js +3 -2
- package/game-session.js +7 -0
- package/package.json +1 -1
package/docker-helper.js
CHANGED
|
@@ -101,7 +101,7 @@ const runGameContainer = async ({
|
|
|
101
101
|
saveDataPath,
|
|
102
102
|
assetCachePath = null,
|
|
103
103
|
imageName = 'homegames-runner',
|
|
104
|
-
memoryLimit = '
|
|
104
|
+
memoryLimit = '128m',
|
|
105
105
|
cpuLimit = '1',
|
|
106
106
|
gameEntryRelative = null,
|
|
107
107
|
noFrame = false,
|
|
@@ -148,7 +148,9 @@ const runGameContainer = async ({
|
|
|
148
148
|
if (assetCachePath) {
|
|
149
149
|
const resolved = path.resolve(assetCachePath);
|
|
150
150
|
if (!fs.existsSync(resolved)) {
|
|
151
|
-
fs.mkdirSync(resolved, { recursive: true });
|
|
151
|
+
fs.mkdirSync(resolved, { recursive: true, mode: 0o777 });
|
|
152
|
+
} else {
|
|
153
|
+
fs.chmodSync(resolved, 0o777);
|
|
152
154
|
}
|
|
153
155
|
binds.push(`${resolved}:/root/.homegames/asset-cache:rw`);
|
|
154
156
|
}
|
|
@@ -178,7 +180,7 @@ const runGameContainer = async ({
|
|
|
178
180
|
PidsLimit: 64,
|
|
179
181
|
CapDrop: ['ALL'],
|
|
180
182
|
Tmpfs: {
|
|
181
|
-
'/tmp': 'rw,size=
|
|
183
|
+
'/tmp': 'rw,size=160m',
|
|
182
184
|
},
|
|
183
185
|
ExtraHosts: extraHosts,
|
|
184
186
|
},
|
package/game-loader.js
CHANGED
|
@@ -32,6 +32,7 @@ const squishMap = {
|
|
|
32
32
|
'130': 'squish-130',
|
|
33
33
|
'135': 'squish-135',
|
|
34
34
|
'136': 'squish-136',
|
|
35
|
+
'138': 'squish-138',
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
const DEFAULT_SQUISH_VERSION = '135';
|
|
@@ -47,7 +48,7 @@ const parseSquishVersion = (codePath) => {
|
|
|
47
48
|
const parsed = Parser.parse(code, { ecmaVersion: 'latest', sourceType: 'script' });
|
|
48
49
|
|
|
49
50
|
const foundGameClasses = parsed.body.filter(
|
|
50
|
-
n => n.type === 'ClassDeclaration' && n.superClass && n.superClass.name === 'Game'
|
|
51
|
+
n => n.type === 'ClassDeclaration' && n.superClass && (n.superClass.name === 'Game' || n.superClass.name === 'ViewableGame')
|
|
51
52
|
);
|
|
52
53
|
|
|
53
54
|
if (foundGameClasses.length !== 1) {
|
package/game-session-manager.js
CHANGED
|
@@ -313,6 +313,7 @@ class GameSessionManager {
|
|
|
313
313
|
try {
|
|
314
314
|
squishVersion = parseSquishVersion(gamePath);
|
|
315
315
|
} catch (err) {
|
|
316
|
+
console.log(err);
|
|
316
317
|
squishVersion = DEFAULT_SQUISH_VERSION;
|
|
317
318
|
}
|
|
318
319
|
} else if (input.versionId) {
|
|
@@ -360,11 +361,11 @@ class GameSessionManager {
|
|
|
360
361
|
}
|
|
361
362
|
}
|
|
362
363
|
}
|
|
363
|
-
|
|
364
|
+
|
|
364
365
|
const child = fork(this.childServerPath, [], {
|
|
365
366
|
env,
|
|
366
367
|
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
|
|
367
|
-
execArgv: ['--max-old-space-size=
|
|
368
|
+
execArgv: ['--max-old-space-size=64'],
|
|
368
369
|
});
|
|
369
370
|
|
|
370
371
|
child.send(JSON.stringify({
|
package/game-session.js
CHANGED
|
@@ -91,6 +91,7 @@ class GameSession {
|
|
|
91
91
|
this.squisher.addListener(() => this._broadcastState());
|
|
92
92
|
|
|
93
93
|
this.gameMetadata = (typeof game.constructor.metadata === 'function') ? game.constructor.metadata() : {};
|
|
94
|
+
this.maxPlayers = this.gameMetadata.maxPlayers || 64;
|
|
94
95
|
this.aspectRatio = this.gameMetadata.aspectRatio || { x: 16, y: 9 };
|
|
95
96
|
|
|
96
97
|
// Player / spectator maps — values are raw WebSocket objects
|
|
@@ -128,6 +129,12 @@ class GameSession {
|
|
|
128
129
|
// -----------------------------------------------------------------------
|
|
129
130
|
|
|
130
131
|
addPlayer(playerId, ws, playerOpts = {}) {
|
|
132
|
+
// Reject if the game is at capacity
|
|
133
|
+
if (Object.keys(this.players).length >= this.maxPlayers) {
|
|
134
|
+
try { ws.close(); } catch (e) {}
|
|
135
|
+
throw new Error('Game is full');
|
|
136
|
+
}
|
|
137
|
+
|
|
131
138
|
// If this ID is already connected, disconnect the old one first
|
|
132
139
|
if (this.players[playerId]) {
|
|
133
140
|
this.removePlayer(playerId);
|