This repository contains two HTTP servers designed to execute LUA scripts in DCS World, leveraging tslua-dcs and TypeScriptToLua. While primarily intended for integration with DCS Fiddle, these servers can also be used for other purposes.
- Execute LUA scripts: Easily run LUA scripts in DCS World.
- RESTful API: Interact via POST requests for seamless integration with tools and scripts.
- Swagger Integration: View and test API endpoints with OpenAPI specifications.
Download the latest release from the GitHub repository.
- Add the
dcs-fiddle-main.lua
file to your DCS World%USERPROFILE%\Saved Games\DCS\Scripts\Hooks
folder. - Add the
dcs-fiddle-mission.lua
file to your DCS World%USERPROFILE%\Saved Games\DCS\Scripts
folder.
To enable script execution, update your MissionScripting.lua
file to run the mission server before sanitizing the environment.
The GUI script will automatically run when DCS starts.
Add to the top of the MissionScripting.lua
file content with the following code:
-- MissionScripting.lua
dofile(lfs.writedir()..'Scripts/dcs-fiddle-mission.lua')
-- Initialization script for the Mission lua Environment (SSE)
dofile('Scripts/ScriptingSystem.lua')
...
When DCS starts it will load the dcs-fiddle-main.lua
script, which will start the GUI HTTP server on port 12081
.
curl -X GET --location "http://127.0.0.1:12081/health"
If the server is running, you will receive the following response:
{"_APP_VERSION":"2.9.10.3948","version":"0.1.0","environment":"GUI","status":"OK","_VERSION":"Lua 5.1","_ARCHITECTURE":"x86_64"}
When a mission is loaded, the dcs-fiddle-mission.lua
script will start the Mission HTTP server on port 12080
.
curl -X GET --location "http://127.0.0.1:12080/health"
If the server is running, you will receive the following response:
{"_APP_VERSION":"2.9.10.3948","version":"0.1.0","environment":"MISSION","status":"OK","_VERSION":"Lua 5.1","_ARCHITECTURE":"x86_64"}
-
Health Check:
- Endpoint:
GET /health
- Use this endpoint to check if the server is running.
- Endpoint:
-
Execute LUA Script:
- Endpoint:
POST /loadstring
- Accepts a base64-encoded LUA script in the request body and executes it.
- Endpoint:
Send a POST request to execute a LUA script. The script must be encoded in base64.
Request:
curl -X POST --location "http://127.0.0.1:12081/loadstring" \
-H "Content-Type: text/plain" \
-d 'cmV0dXJuICJVUCI='
Response:
The server returns the result of the LUA script in JSON format:
"Caucasus"
Request:
curl --location --request POST 'http://127.0.0.1:12080/loadstring' \
--header 'Content-Type: text/plain' \
--data-raw 'cmV0dXJuIGNvYWxpdGlvbi5zaWRl'
Response:
{ "NEUTRAL": 0, "BLUE": 2, "RED": 1 }
View the API documentation in a Swagger editor, such as Swagger Petstore, by navigating to:
- Main: https://petstore.swagger.io/?url=http://127.0.0.1:12081/v3/api-docs
- Mission: https://petstore.swagger.io/?url=http://127.0.0.1:12080/v3/api-docs
This project is authored using tslua-dcs, enabling the development of LUA scripts in TypeScript.
To test the project locally without restarting DCS:
- Install the DCS Hot Loader.
- Use the following commands for rapid iteration:
npm run build && npm run deploy
The following package.json
scripts are available for this project:
build
: Cleans thedist
folder and builds both main and mission files.npm run build
build:main
: Builds the main server script usingtsconfig.tstl-main.json
.npm run build:main
build:mission
: Builds the mission script usingtsconfig.tstl-mission.json
.npm run build:mission
deploy
: Deploys both the main server and mission scripts.npm run deploy
deploy:main
: Deploys the main server script.npm run deploy:main
deploy:mission
: Deploys the mission script.npm run deploy:mission
- Server not starting: Ensure all dependencies are installed and the required ports are not in use, ensure the MissionScripting.lua file is correctly configured.
- Script execution errors: Verify that the LUA script is properly encoded in base64 and adheres to DCS scripting requirements.
This project is licensed under the MIT License. See the LICENSE
file for details.