homegames-common 1.5.1 → 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 +2 -2
- package/game-loader.js +0 -9
- 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,
|
|
@@ -180,7 +180,7 @@ const runGameContainer = async ({
|
|
|
180
180
|
PidsLimit: 64,
|
|
181
181
|
CapDrop: ['ALL'],
|
|
182
182
|
Tmpfs: {
|
|
183
|
-
'/tmp': 'rw,size=
|
|
183
|
+
'/tmp': 'rw,size=160m',
|
|
184
184
|
},
|
|
185
185
|
ExtraHosts: extraHosts,
|
|
186
186
|
},
|
package/game-loader.js
CHANGED
|
@@ -44,22 +44,13 @@ const DEFAULT_SQUISH_VERSION = '135';
|
|
|
44
44
|
const parseSquishVersion = (codePath) => {
|
|
45
45
|
const code = fs.readFileSync(codePath, 'utf-8');
|
|
46
46
|
|
|
47
|
-
console.log('aiaiaiai');
|
|
48
47
|
const { Parser } = require('acorn');
|
|
49
48
|
const parsed = Parser.parse(code, { ecmaVersion: 'latest', sourceType: 'script' });
|
|
50
|
-
console.log('balls and ass');
|
|
51
|
-
console.log(parsed);
|
|
52
|
-
console.log(parsed.body);
|
|
53
|
-
console.log(parsed.body.map(n => n.type));
|
|
54
|
-
console.log(parsed.body.filter(n => n.type === 'ClassDeclaration').superClass);
|
|
55
49
|
|
|
56
50
|
const foundGameClasses = parsed.body.filter(
|
|
57
51
|
n => n.type === 'ClassDeclaration' && n.superClass && (n.superClass.name === 'Game' || n.superClass.name === 'ViewableGame')
|
|
58
52
|
);
|
|
59
53
|
|
|
60
|
-
console.log('found game classes');
|
|
61
|
-
console.log(foundGameClasses);
|
|
62
|
-
|
|
63
54
|
if (foundGameClasses.length !== 1) {
|
|
64
55
|
throw new Error('Unable to parse squish version');
|
|
65
56
|
}
|
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);
|