Skip to content

Commit

Permalink
Merge pull request #5 from flying-dice/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JonathanTurnock authored Jan 18, 2025
2 parents 1a19c55 + 036cacc commit 5b55be2
Show file tree
Hide file tree
Showing 26 changed files with 2,793 additions and 268 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/cargo-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This GitHub Actions workflow is designed to run the Cargo Release process
# whenever there is a push to the 'main' branch or the workflow is manually triggered.

name: Run Cargo Release

on:
push:
branches:
- main # Trigger the workflow on push events to the 'main' branch
workflow_dispatch: # Allow manual triggering of the workflow

jobs:
cargo_release:
name: Run Cargo Release
runs-on: windows-latest # Use the latest Windows runner

steps:
- name: Checkout Repository
uses: actions/checkout@v4 # Checkout the repository using the specified action

- name: Set Up Rust
uses: actions-rs/toolchain@v1 # Set up the Rust toolchain
with:
toolchain: stable # Use the stable Rust toolchain
override: true # Override any existing toolchain configuration

- name: Install Cargo Release
run: cargo install cargo-release # Install the cargo-release tool

- name: Run Cargo Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use the GitHub token for authentication
run: cargo release --execute --no-publish # Run the cargo release command only creating a new tag but not publishing to crates.io
38 changes: 38 additions & 0 deletions .github/workflows/gh-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This GitHub Actions workflow is designed to create a GitHub Release
# whenever a new tag is pushed to the repository or the workflow is manually triggered.

name: Create GitHub Release

on:
push:
tags:
- 'v*' # Trigger the workflow on any tag that matches the pattern 'v*'
workflow_dispatch: # Allow manual triggering of the workflow

jobs:
create_release:
name: Create GitHub Release
runs-on: windows-latest # Use the latest Windows runner

steps:
- name: Checkout Repository
uses: actions/checkout@v4 # Checkout the repository using the specified action

- name: Set Up Rust
uses: actions-rs/toolchain@v1 # Set up the Rust toolchain
with:
toolchain: stable # Use the stable Rust toolchain
override: true # Override any existing toolchain configuration

- name: Build DLL
run: cargo build --release # Build the project in release mode

- name: Create GitHub Release
uses: ncipollo/release-action@v1 # Use the release action to create a GitHub Release
with:
artifacts: target/release/*.dll # Specify the artifacts to include in the release
tag: ${{ github.ref_name }} # Use the tag created by `cargo release`
name: Release ${{ github.ref_name }} # Set the release name to the tag name
body: |
This release was automatically created using cargo-release and GitHub Actions. # Set the release body
token: ${{ secrets.GITHUB_TOKEN }} # Use the GitHub token for authentication
43 changes: 0 additions & 43 deletions .github/workflows/rust.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.idea
.idea
logs
47 changes: 25 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
[package]
name = "json-rpc-server"
version = "0.1.0"
name = "lua-json-rpc"
version = "0.0.1"
edition = "2021"

[dependencies]
mlua = { version = "0.10", features = ["lua51", "module", "async", "serialize"] }
tokio = "1.43.0"
tokio = { version = "1.43.0", features = ["rt", "macros"] }
actix-web = "4.9.0"
actix-ws = "0.3.0"
serde_json = "1.0.135"
serde = { version = "1.0.217", features = ["derive"] }
uuid = { version = "1.12.0", features = ["v4"] }
log = "0.4.25"

[lib]
crate-type = ["cdylib"]

[package.metadata.release]
tag = true
push = false
17 changes: 17 additions & 0 deletions build-dcs.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@echo off

:: Delete the target folder if it exists
if exist target (
rmdir /s /q target
echo Deleted the target folder.
) else (
echo No target folder found, skipping deletion.
)

:: Set environment variables directly
set LUA_LIB_NAME=lua
set LUA_LIB=lua5.1/
set LUA_INC=lua5.1/include

:: Run cargo build with the custom environment variables
cargo build --release
12 changes: 12 additions & 0 deletions dcs/json-rpc_main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local usercallbacks = {}

function usercallbacks.onSimulationFrame()
net.dostring_in("mission", [[a_do_script("__loop()")]])
end

function usercallbacks.onSimulationStop()
log.info("[EXAMPLE] - Stopping JSON-RPC Server...")
net.dostring_in("mission", [[a_do_script("__stop()")]])
end

DCS.setUserCallbacks(usercallbacks)
43 changes: 43 additions & 0 deletions dcs/json-rpc_mission.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package.path = package.path .. ";" .. lfs.writedir() .. "\\Scripts\\?.lua"
package.cpath = package.cpath .. ";" .. lfs.writedir() .. "\\Scripts\\?.dll"

local jsonrpc = require("lua_json_rpc")

local port = 1359

env.info("[EXAMPLE] - Starting JSON-RPC server on port " .. port .. ", ARCH: " .. _ARCHITECTURE .. " VERION: " .. _VERSION)

__stop = jsonrpc.start_server({
host = "0.0.0.0",
port = port,
workers = 2
})

function loop()
jsonrpc.process_rpc(on_rpc)
end

function __loop()
local success, err = pcall(loop)
if not success then
env.error("loop() error: " .. tostring(err), false) -- false to avoid a popup in DCS
end
end

function on_rpc(payload)
if (payload.id == nil) then
return
end

local response = {
id = payload.id,
jsonrpc = "2.0",
}

if (string.match("subtract", payload.method)) then
env.info("Subtracting " .. payload.params[1] .. " - " .. payload.params[2])
response.result = payload.params[1] - payload.params[2]
end

return response
end
Loading

0 comments on commit 5b55be2

Please sign in to comment.