Skip to content

Commit b733f28

Browse files
author
🎲
committed
feat: add prepend-package.js script for modifying mission build
- update README with new script execution instructions - update build script with prepend-package.js - modify DCS user callbacks for simulation start to not start mission server to late
1 parent 5b05a3a commit b733f28

File tree

6 files changed

+84
-88
lines changed

6 files changed

+84
-88
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/node_modules/
22
/tsconfig.mission.json
3+
/scripts/prepend-package.js

README.md

+18-33
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,34 @@ This repository contains two HTTP servers designed to execute LUA scripts in DCS
1515
- **RESTful API:** Interact via POST requests for seamless integration with tools and scripts.
1616
- **Swagger Integration:** View and test API endpoints with OpenAPI specifications.
1717

18-
## 🔒 Prerequisites
18+
## ⚡️ Installation
1919

20-
To enable script execution, update your `MissionScripting.lua` file to allow access to `require` and `package` modules. Additionally, configure the LuaSocket package path as follows:
20+
[![dropzone](https://dcs-dropzone-registry-viewer.pages.dev/download.svg)](https://dcs-dropzone-registry-viewer.pages.dev/#/dcs-fiddle)
2121

22-
### 🔧 Updating `MissionScripting.lua`
22+
## Manual Installation
2323

24-
Replace your `MissionScripting.lua` file content with the following code:
24+
Download the latest release from the [GitHub repository](https://github.com/flying-dice/dcsfiddle-server/releases).
2525

26-
```lua
27-
-- Initialization script for the Mission lua Environment (SSE)
26+
- Add the `dcs-fiddle-main.lua` file to your DCS World `%USERPROFILE%\Saved Games\DCS\Scripts\Hooks` folder.
27+
- Add the `dcs-fiddle-mission.lua` file to your DCS World `%USERPROFILE%\Saved Games\DCS\Scripts` folder.
2828

29-
dofile('Scripts/ScriptingSystem.lua')
29+
### 🔧 Updating `MissionScripting.lua`
3030

31-
-- Sanitize Mission Scripting environment
32-
-- WARNING: The following configuration makes some functions available, potentially exposing risks.
33-
-- Proceed with caution if using downloaded missions.
34-
35-
local function sanitizeModule(name)
36-
_G[name] = nil
37-
package.loaded[name] = nil
38-
end
39-
40-
do
41-
sanitizeModule('os')
42-
sanitizeModule('io')
43-
sanitizeModule('lfs')
44-
-- _G['require'] = nil
45-
_G['loadlib'] = nil
46-
-- _G['package'] = nil
47-
end
48-
49-
package.path = package.path .. ";.\\LuaSocket\\?.lua"
50-
package.cpath = package.cpath .. ";.\\LuaSocket\\?.dll"
51-
```
31+
To enable script execution, update your `MissionScripting.lua` file to run the mission server before sanitizing the environment.
5232

53-
## ⚡️ Installation
33+
The GUI script will automatically run when DCS starts.
5434

55-
Download the latest release from the [GitHub repository](https://github.com/flying-dice/dcsfiddle-server/releases).
35+
Add to the top of the `MissionScripting.lua` file content with the following code:
5636

57-
- Add the `dcs-fiddle-main.lua` file to your DCS World `%USERPROFILE%\Saved Games\DCS\Scripts\Hooks` folder.
58-
- Add the `dcs-fiddle-mission.lua` file to your DCS World `%USERPROFILE%\Saved Games\DCS\Scripts` folder.
37+
```lua
38+
-- MissionScripting.lua
39+
dofile(lfs.writedir()..'Scripts/dcs-fiddle-mission.lua')
5940

60-
[![dropzone](https://dcs-dropzone-registry-viewer.pages.dev/download.svg)](https://dcs-dropzone-registry-viewer.pages.dev/#/dcs-fiddle)
41+
-- Initialization script for the Mission lua Environment (SSE)
42+
43+
dofile('Scripts/ScriptingSystem.lua')
44+
...
45+
```
6146

6247
## 🚀 Usage
6348

package-lock.json

+34-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
"scripts": {
99
"build": "rimraf dist && npm run build:main && npm run build:mission",
1010
"build:main": "tstl -p tsconfig.tstl-main.json",
11-
"build:mission": "tstl -p tsconfig.tstl-mission.json",
11+
"build:mission": "tstl -p tsconfig.tstl-mission.json && node scripts/prepend-package.js",
1212
"deploy": "npm run deploy:main && npm run deploy:mission",
1313
"deploy:main": "node scripts/deploy-main.js",
1414
"deploy:mission": "node scripts/deploy-mission.js"
1515
},
1616
"dependencies": {
17-
"@flying-dice/tslua-base64": "^0.32.11",
18-
"@flying-dice/tslua-common": "^0.32.11",
19-
"@flying-dice/tslua-dcs-gui-types": "^0.32.11",
20-
"@flying-dice/tslua-dcs-mission-types": "^0.32.11",
21-
"@flying-dice/tslua-http-api": "^0.32.11"
17+
"@flying-dice/tslua-base64": "^0.32.12",
18+
"@flying-dice/tslua-common": "^0.32.12",
19+
"@flying-dice/tslua-dcs-gui-types": "^0.32.12",
20+
"@flying-dice/tslua-dcs-mission-types": "^0.32.12",
21+
"@flying-dice/tslua-http-api": "^0.32.12"
2222
},
2323
"devDependencies": {
2424
"@semantic-release/changelog": "^6.0.3",

scripts/prepend-package.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { readFileSync, writeFileSync } = require("fs");
2+
const { join } = require("path");
3+
4+
const buildPath = join(__dirname, "../dist/dcs-fiddle-mission.lua");
5+
const header = `\
6+
local _path = [[;.\\\\LuaSocket\\\\?.lua]]
7+
local _cpath = [[;.\\\\LuaSocket\\\\?.dll]]
8+
if not string.find(package.path, _path) then
9+
package.path = package.path .. _path
10+
end
11+
if not string.find(package.cpath, _cpath) then
12+
package.cpath = package.cpath .. _cpath
13+
end
14+
15+
`;
16+
17+
const missionScript = readFileSync(
18+
buildPath,
19+
"utf8",
20+
);
21+
writeFileSync(
22+
buildPath,
23+
header + missionScript,
24+
);

src/main/index.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,7 @@ if (__dcs_fiddle_app !== undefined) {
1010
logger.info("Starting app");
1111
__dcs_fiddle_app = app;
1212

13-
DCS?.setUserCallbacks({
14-
onSimulationStart() {
15-
logger.info("Simulation Started");
16-
17-
logger.info("Starting DCS Fiddle Mission Server");
18-
const fiddleFile = `${lfs.writedir()}\\Scripts\\dcs-fiddle-mission.lua`;
19-
const [result] = string.gsub(fiddleFile, "\\", "/");
20-
const fiddleFileCommand = string.format(
21-
`a_do_script("dofile('%s')")`,
22-
result,
23-
);
24-
log.info(`Loading fiddle mission from ${fiddleFileCommand}`);
25-
26-
net.dostring_in("mission", fiddleFileCommand);
27-
},
13+
DCS.setUserCallbacks({
2814
onSimulationFrame() {
2915
__dcs_fiddle_app.acceptNextClient();
3016
},

0 commit comments

Comments
 (0)