action-engine-js 1.0.0

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 (93) hide show
  1. package/LICENSE +45 -0
  2. package/README.md +348 -0
  3. package/actionengine/3rdparty/goblin/goblin.js +9609 -0
  4. package/actionengine/3rdparty/goblin/goblin.min.js +5 -0
  5. package/actionengine/camera/actioncamera.js +90 -0
  6. package/actionengine/camera/cameracollisionhandler.js +69 -0
  7. package/actionengine/character/actioncharacter.js +360 -0
  8. package/actionengine/character/actioncharacter3D.js +61 -0
  9. package/actionengine/core/app.js +430 -0
  10. package/actionengine/debug/basedebugpanel.js +858 -0
  11. package/actionengine/display/canvasmanager.js +75 -0
  12. package/actionengine/display/gl/programmanager.js +570 -0
  13. package/actionengine/display/gl/shaders/lineshader.js +118 -0
  14. package/actionengine/display/gl/shaders/objectshader.js +1756 -0
  15. package/actionengine/display/gl/shaders/particleshader.js +43 -0
  16. package/actionengine/display/gl/shaders/shadowshader.js +319 -0
  17. package/actionengine/display/gl/shaders/spriteshader.js +100 -0
  18. package/actionengine/display/gl/shaders/watershader.js +67 -0
  19. package/actionengine/display/graphics/actionmodel3D.js +191 -0
  20. package/actionengine/display/graphics/actionsprite3D.js +230 -0
  21. package/actionengine/display/graphics/lighting/actiondirectionalshadowlight.js +864 -0
  22. package/actionengine/display/graphics/lighting/actionlight.js +211 -0
  23. package/actionengine/display/graphics/lighting/actionomnidirectionalshadowlight.js +862 -0
  24. package/actionengine/display/graphics/lighting/lightingconstants.js +263 -0
  25. package/actionengine/display/graphics/lighting/lightmanager.js +789 -0
  26. package/actionengine/display/graphics/renderableobject.js +44 -0
  27. package/actionengine/display/graphics/renderers/actionrenderer2D.js +341 -0
  28. package/actionengine/display/graphics/renderers/actionrenderer3D/actionrenderer3D.js +655 -0
  29. package/actionengine/display/graphics/renderers/actionrenderer3D/canvasmanager3D.js +82 -0
  30. package/actionengine/display/graphics/renderers/actionrenderer3D/debugrenderer3D.js +493 -0
  31. package/actionengine/display/graphics/renderers/actionrenderer3D/objectrenderer3D.js +790 -0
  32. package/actionengine/display/graphics/renderers/actionrenderer3D/spriteRenderer3D.js +266 -0
  33. package/actionengine/display/graphics/renderers/actionrenderer3D/sunrenderer3D.js +140 -0
  34. package/actionengine/display/graphics/renderers/actionrenderer3D/waterrenderer3D.js +173 -0
  35. package/actionengine/display/graphics/renderers/actionrenderer3D/weatherrenderer3D.js +87 -0
  36. package/actionengine/display/graphics/texture/proceduraltexture.js +192 -0
  37. package/actionengine/display/graphics/texture/texturemanager.js +242 -0
  38. package/actionengine/display/graphics/texture/textureregistry.js +177 -0
  39. package/actionengine/input/actionscrollablearea.js +1405 -0
  40. package/actionengine/input/inputhandler.js +1647 -0
  41. package/actionengine/math/geometry/geometrybuilder.js +161 -0
  42. package/actionengine/math/geometry/glbexporter.js +364 -0
  43. package/actionengine/math/geometry/glbloader.js +722 -0
  44. package/actionengine/math/geometry/modelcodegenerator.js +97 -0
  45. package/actionengine/math/geometry/triangle.js +33 -0
  46. package/actionengine/math/geometry/triangleutils.js +34 -0
  47. package/actionengine/math/mathutils.js +25 -0
  48. package/actionengine/math/matrix4.js +785 -0
  49. package/actionengine/math/physics/actionphysics.js +108 -0
  50. package/actionengine/math/physics/actionphysicsobject3D.js +164 -0
  51. package/actionengine/math/physics/actionphysicsworld3D.js +238 -0
  52. package/actionengine/math/physics/actionraycast.js +129 -0
  53. package/actionengine/math/physics/shapes/actionphysicsbox3D.js +158 -0
  54. package/actionengine/math/physics/shapes/actionphysicscapsule3D.js +200 -0
  55. package/actionengine/math/physics/shapes/actionphysicscompoundshape3D.js +147 -0
  56. package/actionengine/math/physics/shapes/actionphysicscone3D.js +126 -0
  57. package/actionengine/math/physics/shapes/actionphysicsconvexshape3D.js +72 -0
  58. package/actionengine/math/physics/shapes/actionphysicscylinder3D.js +117 -0
  59. package/actionengine/math/physics/shapes/actionphysicsmesh3D.js +74 -0
  60. package/actionengine/math/physics/shapes/actionphysicsplane3D.js +100 -0
  61. package/actionengine/math/physics/shapes/actionphysicssphere3D.js +95 -0
  62. package/actionengine/math/quaternion.js +61 -0
  63. package/actionengine/math/vector2.js +277 -0
  64. package/actionengine/math/vector3.js +318 -0
  65. package/actionengine/math/viewfrustum.js +136 -0
  66. package/actionengine/network/ACTIONNETREADME.md +810 -0
  67. package/actionengine/network/client/ActionNetManager.js +802 -0
  68. package/actionengine/network/client/ActionNetManagerGUI.js +1709 -0
  69. package/actionengine/network/client/ActionNetManagerP2P.js +1537 -0
  70. package/actionengine/network/client/SyncSystem.js +422 -0
  71. package/actionengine/network/p2p/ActionNetPeer.js +142 -0
  72. package/actionengine/network/p2p/ActionNetTrackerClient.js +623 -0
  73. package/actionengine/network/p2p/DataConnection.js +282 -0
  74. package/actionengine/network/p2p/README.md +510 -0
  75. package/actionengine/network/p2p/example.html +502 -0
  76. package/actionengine/network/server/ActionNetServer.js +577 -0
  77. package/actionengine/network/server/ActionNetServerSSL.js +579 -0
  78. package/actionengine/network/server/ActionNetServerUtils.js +458 -0
  79. package/actionengine/network/server/SERVERREADME.md +314 -0
  80. package/actionengine/network/server/package-lock.json +35 -0
  81. package/actionengine/network/server/package.json +13 -0
  82. package/actionengine/network/server/start.bat +27 -0
  83. package/actionengine/network/server/start.sh +25 -0
  84. package/actionengine/network/server/startwss.bat +27 -0
  85. package/actionengine/sound/audiomanager.js +1589 -0
  86. package/actionengine/sound/soundfont/ACTIONSOUNDFONT_README.md +205 -0
  87. package/actionengine/sound/soundfont/actionparser.js +718 -0
  88. package/actionengine/sound/soundfont/actionreverb.js +252 -0
  89. package/actionengine/sound/soundfont/actionsoundfont.js +543 -0
  90. package/actionengine/sound/soundfont/sf2playerlicence.txt +29 -0
  91. package/actionengine/sound/soundfont/soundfont.js +2 -0
  92. package/dist/action-engine.min.js +328 -0
  93. package/package.json +35 -0
@@ -0,0 +1,314 @@
1
+ # ActionNet Multiplayer Game Server
2
+
3
+ A generic, game-agnostic WebSocket server for real-time multiplayer games built with ActionNetServerUtils.
4
+
5
+ ## Features
6
+
7
+ - **Generic Message Relay**: Server doesn't interpret game messages - it just routes them between clients in the same room
8
+ - **Room/Lobby System**: Create or join named rooms for multiplayer sessions
9
+ - **Host Management**: First player to join a room becomes the host; room closes if host leaves
10
+ - **Automatic Display Names**: Handles username collisions with unique display names (e.g., "Player", "Player (1)", "Player (2)")
11
+ - **Configurable Room Size**: Set maximum players per room or allow unlimited players
12
+ - **Connection Management**: Handles connects, disconnects, room joins/leaves, username changes
13
+ - **Ping/Pong Support**: Built-in heartbeat system for connection health monitoring
14
+
15
+ ## Quick Start
16
+
17
+ The start scripts automatically install dependencies if needed!
18
+
19
+ ### Start the Server
20
+
21
+ **Windows:**
22
+ ```bash
23
+ start.bat
24
+ ```
25
+
26
+ **Mac/Linux:**
27
+ ```bash
28
+ chmod +x start.sh
29
+ ./start.sh
30
+ ```
31
+
32
+ **Or manually:**
33
+ ```bash
34
+ node ActionNetServer.js
35
+ ```
36
+
37
+ **Custom port and max players:**
38
+ ```bash
39
+ node ActionNetServer.js 8000 4
40
+ ```
41
+
42
+ ## Default Configuration
43
+
44
+ - **Port**: 8000
45
+ - **WebSocket URL**: `ws://localhost:8000`
46
+ - **Max Players per Room**: Unlimited (-1)
47
+ - **Debug Mode**: Enabled
48
+
49
+ Edit the `CONFIG` object in `ActionNetServer.js` to change defaults:
50
+
51
+ ```javascript
52
+ const CONFIG = {
53
+ port: 8000, // Server port
54
+ debug: true, // Enable debug logging
55
+ maxPlayersPerRoom: -1 // -1 = unlimited, or set a number like 2, 4, 8, etc.
56
+ };
57
+ ```
58
+
59
+ ## How It Works
60
+
61
+ ### Connection Flow
62
+
63
+ 1. **Client connects** → Added to lobby
64
+ 2. **Client sends `connect` message** → Server registers client with unique display name
65
+ 3. **Client sends `joinRoom` message** → Client moves from lobby to room
66
+ - First client to join becomes the **host**
67
+ - Room is created automatically if it doesn't exist
68
+ 4. **Client sends game messages** → Server relays to all other clients in the same room
69
+ 5. **Client disconnects or leaves** → If they were the host, room closes and all players return to lobby
70
+
71
+ ### Host System
72
+
73
+ - **First person to join a room becomes the host**
74
+ - Host status is tracked in client info (`isHost: true`)
75
+ - **When host leaves/disconnects**: Room is closed and all remaining players are returned to lobby
76
+ - Non-host players leaving doesn't affect the room
77
+
78
+ ### Display Name Generation
79
+
80
+ - Clients provide a `username` when connecting
81
+ - If multiple clients use the same username, server generates unique **display names**:
82
+ - First: `"Player"`
83
+ - Second: `"Player (1)"`
84
+ - Third: `"Player (2)"`
85
+ - etc.
86
+ - Display names are what clients should show in UI
87
+ - Each client still has a unique `clientId` for internal tracking
88
+
89
+ ## Message Types
90
+
91
+ The server handles these **system messages**:
92
+
93
+ ### Client → Server
94
+
95
+ - `connect` - Register with server (provides username, clientId)
96
+ - `joinRoom` - Join or create a room (provides roomName)
97
+ - `leaveRoom` - Leave current room and return to lobby
98
+ - `changeUsername` - Change your username (generates new display name if needed)
99
+ - `ping` - Heartbeat (server auto-responds with `pong`)
100
+
101
+ ### Server → Client
102
+
103
+ - `connectSuccess` - Connection confirmed
104
+ - `joinSuccess` - Room join confirmed
105
+ - `roomList` - List of available rooms
106
+ - `userList` - List of users in your current room
107
+ - `userJoined` - Someone joined your room
108
+ - `userLeft` - Someone left your room
109
+ - `hostLeft` - Host left, room is closing
110
+ - `system` - System notification message
111
+ - `error` - Error message (e.g., "Room is full")
112
+ - `pong` - Response to ping (includes sequence and timestamp)
113
+
114
+ ### Game Messages
115
+
116
+ **All other message types are game-specific and relayed without interpretation.**
117
+
118
+ The server doesn't care about message content - it just broadcasts them to other clients in the same room.
119
+
120
+ Examples:
121
+ - `playerMove` - Your game's player movement
122
+ - `scoreUpdate` - Your game's scoring
123
+ - `gameStart` - Your game's start signal
124
+ - `chat` - Your game's chat system
125
+ - Anything else your game needs!
126
+
127
+ ## Usage Example
128
+
129
+ ### Your Game Client (JavaScript)
130
+
131
+ ```javascript
132
+ const net = new ActionNetManager({
133
+ url: 'ws://localhost:8000',
134
+ autoConnect: false
135
+ });
136
+
137
+ // Connect with a username
138
+ await net.connectToServer({ username: 'Alice' });
139
+
140
+ // Join a room
141
+ await net.joinRoom('game-room-1');
142
+
143
+ // Send custom game messages
144
+ net.send({
145
+ type: 'playerMove',
146
+ x: 100,
147
+ y: 200
148
+ });
149
+
150
+ // Receive game messages from other players
151
+ net.on('playerMove', (msg) => {
152
+ otherPlayer.position.set(msg.x, msg.y);
153
+ });
154
+ ```
155
+
156
+ ### The server automatically handles:
157
+ - Creating rooms on first join
158
+ - Assigning host to first joiner
159
+ - Relaying your `playerMove` message to other players in the room
160
+ - Cleaning up empty rooms
161
+ - Returning players to lobby when host leaves
162
+
163
+ ## Testing with Multiple Clients
164
+
165
+ 1. Start the server
166
+ 2. Open multiple browser windows/tabs
167
+ 3. Have each client connect and join the same room
168
+ 4. Send messages from one client, see them arrive at others
169
+ 5. Experiment with host leaving to see room closure behavior
170
+
171
+ ## Architecture
172
+
173
+ ### ActionNetServerUtils
174
+
175
+ The server uses `ActionNetServerUtils` for all the heavy lifting:
176
+
177
+ - **Client Tracking**: Maps WebSocket connections to client info
178
+ - **Room Management**: Tracks which clients are in which rooms
179
+ - **Lobby Management**: Tracks clients not in any room
180
+ - **Host Tracking**: Tracks which client is host of each room
181
+ - **Broadcasting**: Utilities for sending to specific clients, rooms, or everyone
182
+ - **Display Names**: Generates unique display names from usernames
183
+
184
+ ### Message Flow
185
+
186
+ ```
187
+ Client A Server Client B
188
+ | | |
189
+ |--playerMove------->| |
190
+ | |----playerMove------->|
191
+ | | |
192
+ |<---playerMove------|<-----playerMove------|
193
+ | | |
194
+ ```
195
+
196
+ Server doesn't modify, validate, or interpret game messages - it's a pure relay.
197
+
198
+ ## Logs
199
+
200
+ The server provides detailed logging:
201
+
202
+ ```
203
+ Player Alice (1) connected to lobby
204
+ Player Alice (1) joined room: game-room-1
205
+ Created new game room: game-room-1
206
+ Player Bob connected to lobby
207
+ Player Bob joined room: game-room-1
208
+ Player Alice (1) left room: game-room-1
209
+ Host left room game-room-1 - closing room and removing all players
210
+ Deleted empty room: game-room-1
211
+ ```
212
+
213
+ ## Troubleshooting
214
+
215
+ ### "EADDRINUSE" Error
216
+
217
+ Port 8000 is already in use. Either:
218
+ - Stop the other process using the port
219
+ - Start the server on a different port: `node ActionNetServer.js 8001`
220
+ - Update your game client URL to match: `url: 'ws://localhost:8001'`
221
+
222
+ ### Clients Can't Connect
223
+
224
+ - Make sure the server is running
225
+ - Check that the client URL matches the server port
226
+ - Check firewall settings if playing over network
227
+ - Look for errors in server console
228
+
229
+ ### Messages Don't Reach Other Clients
230
+
231
+ - Check server logs for errors
232
+ - Make sure both clients are in the same room
233
+ - Verify the client is calling `net.send()` correctly
234
+ - Check that the server is relaying (should see message type in logs if debug is on)
235
+
236
+ ### Room Closes Unexpectedly
237
+
238
+ - The host probably left or disconnected
239
+ - Check server logs for "Host left room" messages
240
+ - Consider implementing host migration in your game if needed
241
+
242
+ ## Production Deployment
243
+
244
+ For production use:
245
+
246
+ 1. **Disable debug mode**: `CONFIG.debug = false`
247
+ 2. **Use a process manager**: PM2, systemd, or similar to keep server running
248
+ 3. **Set up SSL**: Use `wss://` instead of `ws://` for secure WebSocket
249
+ 4. **Configure firewall**: Allow traffic on your chosen port
250
+ 5. **Add rate limiting**: Protect against spam and DDoS
251
+ 6. **Monitor logs**: Set up log rotation and monitoring
252
+ 7. **Set resource limits**: Prevent memory leaks from affecting server
253
+
254
+ ### Example with PM2
255
+
256
+ ```bash
257
+ npm install -g pm2
258
+ pm2 start ActionNetServer.js --name "game-server"
259
+ pm2 logs game-server
260
+ pm2 stop game-server
261
+ ```
262
+
263
+ ## Extending the Server
264
+
265
+ The server is designed to be customized for your game's needs:
266
+
267
+ ### Add Custom Message Validation
268
+
269
+ ```javascript
270
+ function relayGameMessage(ws, message) {
271
+ const client = utils.getClient(ws);
272
+ if (!client || !client.roomName) return;
273
+
274
+ // Add your validation here
275
+ if (message.type === 'playerMove') {
276
+ if (!message.x || !message.y) {
277
+ utils.sendToClient(ws, {
278
+ type: 'error',
279
+ text: 'Invalid move data'
280
+ });
281
+ return;
282
+ }
283
+ }
284
+
285
+ utils.broadcastToRoom(client.roomName, message, ws);
286
+ }
287
+ ```
288
+
289
+ ### Add Game State Management
290
+
291
+ ```javascript
292
+ function initializeGameRoom(roomName) {
293
+ gameRooms.set(roomName, {
294
+ players: new Map(),
295
+ startTime: Date.now(),
296
+ gameStarted: false,
297
+ customGameState: { /* your data */ }
298
+ });
299
+ }
300
+ ```
301
+
302
+ ### Add Matchmaking
303
+
304
+ ```javascript
305
+ function findAvailableRoom() {
306
+ for (const [roomName, room] of gameRooms) {
307
+ const size = utils.getRoomSize(roomName);
308
+ if (size < maxPlayersPerRoom) {
309
+ return roomName;
310
+ }
311
+ }
312
+ return null; // Create new room
313
+ }
314
+ ```
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "actionnet-server",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "actionnet-server",
9
+ "version": "1.0.0",
10
+ "dependencies": {
11
+ "ws": "^8.13.0"
12
+ }
13
+ },
14
+ "node_modules/ws": {
15
+ "version": "8.18.3",
16
+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
17
+ "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
18
+ "engines": {
19
+ "node": ">=10.0.0"
20
+ },
21
+ "peerDependencies": {
22
+ "bufferutil": "^4.0.1",
23
+ "utf-8-validate": ">=5.0.2"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "bufferutil": {
27
+ "optional": true
28
+ },
29
+ "utf-8-validate": {
30
+ "optional": true
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "actionnet-server",
3
+ "version": "1.0.0",
4
+ "description": "Generic ActionNet WebSocket relay server.",
5
+ "main": "ActionNetServer.js",
6
+ "scripts": {
7
+ "start": "node ActionNetServer.js",
8
+ "start:wss": "node ActionNetServerSSL.js"
9
+ },
10
+ "dependencies": {
11
+ "ws": "^8.13.0"
12
+ }
13
+ }
@@ -0,0 +1,27 @@
1
+ @echo off
2
+ echo Multiplayer Game Server Startup
3
+ echo ===================================
4
+ echo.
5
+
6
+ REM Check if Node.js is installed
7
+ node --version >nul 2>&1
8
+ if errorlevel 1 (
9
+ echo ERROR: Node.js is not installed.
10
+ echo Download from: https://nodejs.org/
11
+ pause
12
+ exit /b 1
13
+ )
14
+
15
+ echo Node.js found
16
+
17
+ REM Install dependencies if needed
18
+ if not exist node_modules (
19
+ echo Installing dependencies...
20
+ call npm install
21
+ )
22
+
23
+ echo.
24
+ echo Starting Game server...
25
+ echo.
26
+ node ActionNetServer.js 8000 -1
27
+ pause
@@ -0,0 +1,25 @@
1
+ #!/bin/bash
2
+ echo "Multiplayer Game Server Startup"
3
+ echo "==================================="
4
+ echo ""
5
+
6
+ # Check if Node.js is installed
7
+ if ! command -v node &> /dev/null
8
+ then
9
+ echo "ERROR: Node.js is not installed."
10
+ echo "Download from: https://nodejs.org/"
11
+ exit 1
12
+ fi
13
+
14
+ echo "Node.js found"
15
+
16
+ # Install dependencies if needed
17
+ if [ ! -d "node_modules" ]; then
18
+ echo "Installing dependencies..."
19
+ npm install
20
+ fi
21
+
22
+ echo ""
23
+ echo "Starting Game server..."
24
+ echo ""
25
+ node ActionNetServer.js 8000 -1
@@ -0,0 +1,27 @@
1
+ @echo off
2
+ echo Multiplayer Game Server (SECURE WSS) Startup
3
+ echo ==============================================
4
+ echo.
5
+
6
+ REM Check if Node.js is installed
7
+ node --version >nul 2>&1
8
+ if errorlevel 1 (
9
+ echo ERROR: Node.js is not installed.
10
+ echo Download from: https://nodejs.org/
11
+ pause
12
+ exit /b 1
13
+ )
14
+
15
+ echo Node.js found
16
+
17
+ REM Install dependencies if needed
18
+ if not exist node_modules (
19
+ echo Installing dependencies...
20
+ call npm install
21
+ )
22
+
23
+ echo.
24
+ echo Starting Secure Game server on port 8443...
25
+ echo.
26
+ node ActionNetServerSSL.js 8443 -1
27
+ pause