From a567e9323a6ab74c221e973e4697a5b939905e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Dahlgren?= Date: Sun, 30 Jan 2022 03:41:14 +0100 Subject: [PATCH] Rewrite of extension in Rust --- .github/workflows/ci.yml | 135 +-- .gitignore | 19 +- CMakeLists.txt | 48 - Cargo.lock | 1057 ++++++++++++++++++ Cargo.toml | 5 + README.md | 64 +- aar.json | 2 +- addons/aar/functions/fn_init.sqf | 5 +- addons/aar/functions/fn_sendEvent.sqf | 2 +- addons/aar/functions/fn_sendJson.sqf | 2 +- addons/aar/functions/fn_serializeMission.sqf | 7 +- conanfile.txt | 4 - extension/Cargo.toml | 17 + extension/src/config.rs | 24 + extension/src/lib.rs | 35 + extension/src/mission.rs | 12 + extension/src/organizer.rs | 85 ++ linux32.cmake | 5 - 18 files changed, 1317 insertions(+), 211 deletions(-) delete mode 100644 CMakeLists.txt create mode 100644 Cargo.lock create mode 100644 Cargo.toml delete mode 100644 conanfile.txt create mode 100644 extension/Cargo.toml create mode 100644 extension/src/config.rs create mode 100644 extension/src/lib.rs create mode 100644 extension/src/mission.rs create mode 100644 extension/src/organizer.rs delete mode 100644 linux32.cmake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 771ca71..7bea906 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,17 +4,17 @@ on: [push, pull_request] jobs: sqflint: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2 - uses: arma-actions/sqflint@v1.0 name: Validate with SQFLint mod: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@master + - uses: actions/checkout@v1 - name: HEMTT Build uses: docker://hemtt/hemtt:0.6.1 @@ -28,114 +28,99 @@ jobs: name: 'mod' path: releases/1.0.0/@anrop - extension-linux: - runs-on: ubuntu-18.04 + extensions-linux: + runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2 - - name: Setup Python 3.7 - uses: actions/setup-python@v1 + - name: Install rust + uses: actions-rs/toolchain@v1 with: - python-version: 3.7 + toolchain: stable - - name: Install conan - run: pip install conan==1.24.1 - - - name: Install dependencies + - name: Install x86 dependencies run: | sudo dpkg --add-architecture i386 - sudo apt-get update - sudo apt-get install -y g++-multilib + sudo apt update + sudo apt install -y gcc-multilib libssl-dev:i386 pkg-config:i386 + rustup target add i686-unknown-linux-gnu - - name: Build Linux 32 bit - run: mkdir build-linux32 && cd build-linux32 && cmake -DCMAKE_TOOLCHAIN_FILE=../linux32.cmake -DCMAKE_BUILD_TYPE=Release .. && make && make test + - name: Cargo build x86 + run: cargo build --release --target=i686-unknown-linux-gnu - - name: Build Linux 64 bit - run: mkdir build-linux64 && cd build-linux64 && cmake -DCMAKE_BUILD_TYPE=Release .. && make && make test + - name: Cargo build x86_64 + run: cargo build --release --target=x86_64-unknown-linux-gnu - - name: Upload Linux 32 bit - uses: actions/upload-artifact@v1 - with: - name: libanrop_aar.so - path: build-linux32/lib/libanrop_aar.so + - name: Copy built extensions + run: | + cp target/i686-unknown-linux-gnu/release/libanrop_aar.so anrop_aar.so + cp target/x86_64-unknown-linux-gnu/release/libanrop_aar.so anrop_aar_x64.so - - name: Upload Linux 64 bit - uses: actions/upload-artifact@v1 + - name: Upload Linux extensions + uses: actions/upload-artifact@v2 with: - name: libanrop_aar_x64.so - path: build-linux64/lib/libanrop_aar_x64.so + name: extensions-linux + path: '*.so' - extension-windows: + extensions-windows: runs-on: windows-2019 steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2 - - name: Install conan - run: pip install conan==1.24.1 + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable - - name: Build Windows 32 bit - run: mkdir build-win32 && cd build-win32 && cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 16 2019" -A Win32 .. && cmake --build . --config Release && cmake.exe --build . --target RUN_TESTS --config Release + - name: Install x86 dependencies + run: rustup target add i686-pc-windows-msvc - - name: Build Windows 64 bit - run: mkdir build-win64 && cd build-win64 && cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 16 2019" -A x64 .. && cmake --build . --config Release && cmake --build . --target RUN_TESTS --config Release + - name: Cargo build x86 + working-directory: extension + run: cargo build --release --target=i686-pc-windows-msvc - - name: Upload Windows 32 bit - uses: actions/upload-artifact@v1 - with: - name: anrop_aar.dll - path: build-win32/bin/anrop_aar.dll + - name: Cargo build x86_64 + working-directory: extension + run: cargo build --release --target=x86_64-pc-windows-msvc - - name: Upload Windows 64 bit - uses: actions/upload-artifact@v1 + - name: Copy built extensions + run: | + copy target/i686-pc-windows-msvc/release/anrop_aar.dll anrop_aar.dll + copy target/x86_64-pc-windows-msvc/release/anrop_aar.dll anrop_aar_x64.dll + + - name: Upload Windows extensions + uses: actions/upload-artifact@v2 with: - name: anrop_aar_x64.dll - path: build-win64/bin/anrop_aar_x64.dll + name: extensions-windows + path: '*.dll' package: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 needs: - - extension-linux - - extension-windows + - extensions-linux + - extensions-windows - mod steps: - name: Download mod - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v2 with: name: 'mod' path: '@anrop_aar' - - name: Download Linux 32 bit - uses: actions/download-artifact@v1 - with: - name: libanrop_aar.so - path: '@anrop_aar' - - - name: Download Linux 64 bit - uses: actions/download-artifact@v1 - with: - name: libanrop_aar_x64.so - path: '@anrop_aar' - - - name: Rename Linux extension - run: | - set -e - mv @anrop_aar/libanrop_aar.so @anrop_aar/anrop_aar.so - mv @anrop_aar/libanrop_aar_x64.so @anrop_aar/anrop_aar_x64.so - - - name: Download Windows 32 bit - uses: actions/download-artifact@v1 + - name: Download Linux extensions + uses: actions/download-artifact@v2 with: - name: anrop_aar.dll + name: extensions-linux path: '@anrop_aar' - - name: Download Windows 64 bit - uses: actions/download-artifact@v1 + - name: Download Windows extensions + uses: actions/download-artifact@v2 with: - name: anrop_aar_x64.dll + name: extensions-windows path: '@anrop_aar' - name: Upload built mod - uses: actions/upload-artifact@1.0.0 + uses: actions/upload-artifact@v2 with: name: '@anrop_aar' path: '.' diff --git a/.gitignore b/.gitignore index ba3e977..49bad03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,12 @@ +# Rust +# will have compiled files and executables +debug/ +target/ + +# These are backup files generated by rustfmt +**/*.rs.bk + +# HEMTT addons/*.pbo build/ releases/ - -# CLion -.idea/ - -# CMake -CMakeSettings.json -cmake-build-*/ - -# Visual Studio -.vs/ diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index a4836e9..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -cmake_minimum_required(VERSION 2.8.8) -project(aar-addon CXX) - -# Download automatically, you can also just copy the conan.cmake file -if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") - message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") - file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.14/conan.cmake" - "${CMAKE_BINARY_DIR}/conan.cmake") -endif() - -include(${CMAKE_BINARY_DIR}/conan.cmake) - -if (WIN32) - add_compile_options(-D_WIN32_WINNT=0x0601) - add_compile_options(-DWINVER=0x0601) - - if(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") - set(CONAN_ARCH "x86") - else() - set(CMAKE_SHARED_LIBRARY_SUFFIX "_x64.dll") - set(CONAN_ARCH "x86_64") - endif() -else() - if(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") - set(CMAKE_SHARED_LINK_FLAGS "${CMAKE_SHARED_LINK_FLAGS} -m32") - set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") - set(CONAN_ARCH "x86") - else() - set(CMAKE_SHARED_LIBRARY_SUFFIX "_x64.so") - set(CONAN_ARCH "x86_64") - endif() -endif() - -conan_cmake_run(CONANFILE conanfile.txt - BASIC_SETUP CMAKE_TARGETS - BUILD missing - SETTINGS arch=${CONAN_ARCH} - SETTINGS arch_build=${CONAN_ARCH} -) - -add_subdirectory(src/lib) - -enable_testing() -add_subdirectory(src/test) diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..d5dfd41 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1057 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "anrop-aar" +version = "0.0.0" +dependencies = [ + "arma-rs", + "chrono", + "lazy_static", + "reqwest", + "serde", + "serde_json", +] + +[[package]] +name = "arma-rs" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cfb267bd1db962e7ffa902b0c82ec2e8c1c54ce458afcc2ad28fdd8e2b74646" +dependencies = [ + "arma-rs-proc", + "crossbeam-queue", + "lazy_static", + "libc", + "link_args", + "log", + "regex", +] + +[[package]] +name = "arma-rs-proc" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d5449b8086ffe5d32aa55c0a4fbf30bd474d8ea81125425e69da303b341380b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bumpalo" +version = "3.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cc" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + +[[package]] +name = "core-foundation" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "crossbeam-queue" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b979d76c9fcb84dffc80a73f7290da0f83e4c95773494674cb44b76d13a7a110" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "encoding_rs" +version = "0.8.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" + +[[package]] +name = "futures-io" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" + +[[package]] +name = "futures-sink" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" + +[[package]] +name = "futures-task" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" + +[[package]] +name = "futures-util" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" +dependencies = [ + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "h2" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f1f717ddc7b2ba36df7e871fd88db79326551d3d6f1fc406fbfd28b582ff8e" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" +dependencies = [ + "bytes", + "fnv", + "itoa 1.0.1", +] + +[[package]] +name = "http-body" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa 0.4.7", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "ipnet" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" + +[[package]] +name = "itoa" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" + +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + +[[package]] +name = "js-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74" + +[[package]] +name = "link_args" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c7721e472624c9aaad27a5eb6b7c9c6045c7a396f2efb6dabaec1b640d5e89b" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mio" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "native-tls" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "openssl" +version = "0.10.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project-lite" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" + +[[package]] +name = "proc-macro2" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f242f1488a539a79bac6dbe7c8609ae43b7914b7736210f239a37cccb32525" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + +[[package]] +name = "security-framework" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fed7948b6c68acbb6e20c334f55ad635dc0f75506963de4464289fbd3b051ac" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a57321bf8bc2362081b2599912d2961fe899c0efadf1b4b2f8d48b3e253bb96c" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +dependencies = [ + "itoa 0.4.7", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa 1.0.1", + "ryu", + "serde", +] + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "socket2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]] +name = "tinyvec" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c27a64b625de6d309e8c57716ba93021dccf1b3b5c97edd6d3dd2d2135afc0a" +dependencies = [ + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "winapi", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-bidi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasm-bindgen" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" + +[[package]] +name = "web-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..66e526d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +members = [ + "extension", +] diff --git a/README.md b/README.md index 0207903..31214aa 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,19 @@ # Anrop AAR Addon -[![Build Status](https://travis-ci.org/Anrop/AAR-Addon.svg)](https://travis-ci.org/Anrop/AAR-Addon) - Anrop AAR addon for Arma 3. -This repository handles the game server side of the stats tracking by providing the in-game addon for gathering game related data and the library necessary to provision the data to a backend. +This repository handles the game server side of the stats tracking by providing the in-game addon for gathering game related data and the extension necessary to provision the data to a backend. -The library is written in C++ and depends on Boost C++. -It has been written to support GCC and MSVC. +The extension is written in Rust. ## Building -* Conan is used to download required libraries. -* CMake is used to build all binaries. - -Make sure you have Python 3 and pip installed. - -Install Conan using `pip install conan` before using CMake - -### Linux - -You can build the project using CLion or other CMake compatible IDEs. - -``` -mkdir build -cd build -cmake .. -make -``` - -#### 32 bit - -``` -cmake .. -DCMAKE_TOOLCHAIN_FILE=../linux32.cmake -cmake --build . -``` - -#### 64 bit - -``` -cmake .. -cmake --build . -``` - -### Windows - -You can also build the project using CLion, Visual Studio or other CMake compatible IDEs. - -``` -mkdir build -cd build -``` - -#### 32 bit +Install Rust and Cargo, simplest way is to use [Rustup](https://rustup.rs/). This is used to compile the native extension. -``` -cmake .. -G "Visual Studio 16 2019" -A Win32 -cmake --build . -``` +Install [HEMTT](https://github.com/BrettMayson/HEMTT/releases). This is used to package the mod. -#### 64 bit +Run `cargo build` to compile extension for current platform. -``` -cmake .. -G "Visual Studio 16 2019" -A x64 -cmake --build . -``` +Run `hemtt build` to assemble Arma 3 files into PBOs. ## Config @@ -72,6 +22,6 @@ The file should have the following format: ````json { "authorization": "token authorization", // Optional - "hostname": "api.aar.anrop.se" + "url": "http://api.aar.anrop.se" } ```` diff --git a/aar.json b/aar.json index a83b8a1..65c7014 100644 --- a/aar.json +++ b/aar.json @@ -1,4 +1,4 @@ { "authorization": "token authorization", - "hostname": "api.aar.anrop.se" + "url": "https://api.aar.anrop.se" } diff --git a/addons/aar/functions/fn_init.sqf b/addons/aar/functions/fn_init.sqf index 084376c..da2195d 100644 --- a/addons/aar/functions/fn_init.sqf +++ b/addons/aar/functions/fn_init.sqf @@ -21,7 +21,7 @@ if (!isServer) exitWith { }; // Initialize plugin. Get unique ID from server -private _init = anrop_aar_extension callExtension format["init"]; +(anrop_aar_extension callExtension ["init", []]) select 0; if (_init == "") exitWith { diag_log "[Anrop AAR] extension could not be found"; @@ -34,8 +34,7 @@ if (_init == "ERROR") exitWith { diag_log format ["[Anrop AAR] initialized: %1", _init]; private _mission = call anrop_aar_fnc_serializeMission; -private _missionData = _mission call anrop_aar_fnc_serializeJson; -anrop_aar_id = anrop_aar_extension callExtension format["mission;%1", _missionData]; +anrop_aar_id = anrop_aar_extension callExtension ["mission", _mission]; diag_log format ["[Anrop AAR] mission id: %1", anrop_aar_id]; // Add mission events diff --git a/addons/aar/functions/fn_sendEvent.sqf b/addons/aar/functions/fn_sendEvent.sqf index 8948e26..1f04f87 100644 --- a/addons/aar/functions/fn_sendEvent.sqf +++ b/addons/aar/functions/fn_sendEvent.sqf @@ -1,2 +1,2 @@ private _serialized = _this call anrop_aar_fnc_serializeJson; -anrop_aar_extension callExtension format["event;%1", _serialized]; +anrop_aar_extension callExtension ["event", [_serialized]]; diff --git a/addons/aar/functions/fn_sendJson.sqf b/addons/aar/functions/fn_sendJson.sqf index dc06628..949fb0a 100644 --- a/addons/aar/functions/fn_sendJson.sqf +++ b/addons/aar/functions/fn_sendJson.sqf @@ -1 +1 @@ -anrop_aar_extension callExtension format["event;%1", _this]; +anrop_aar_extension callExtension ["event", [_this]]; diff --git a/addons/aar/functions/fn_serializeMission.sqf b/addons/aar/functions/fn_serializeMission.sqf index c6c3d12..85f3597 100644 --- a/addons/aar/functions/fn_serializeMission.sqf +++ b/addons/aar/functions/fn_serializeMission.sqf @@ -1,6 +1 @@ -params []; - -["object", - ["name", ["string", briefingName]], - ["world", ["string", worldName]] -]; +[briefingName, worldName] diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index 63b6915..0000000 --- a/conanfile.txt +++ /dev/null @@ -1,4 +0,0 @@ -[requires] -boost/1.71.0@conan/stable -catch2/2.11.0 -nlohmann_json/3.7.3 diff --git a/extension/Cargo.toml b/extension/Cargo.toml new file mode 100644 index 0000000..10139bd --- /dev/null +++ b/extension/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "anrop-aar" +version = "0.0.0" +authors = ["Björn Dahlgren "] +edition = "2021" + +[lib] +name = "anrop_aar" +crate-type = ["cdylib"] + +[dependencies] +arma-rs = "1.5" +chrono = "0.4" +lazy_static = "1.4" +reqwest = { version = "0.11", features = ["blocking", "json"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" diff --git a/extension/src/config.rs b/extension/src/config.rs new file mode 100644 index 0000000..85918b4 --- /dev/null +++ b/extension/src/config.rs @@ -0,0 +1,24 @@ +use serde::{Deserialize, Serialize}; +use std::fs; +use std::error::Error; + +#[derive(Clone, Deserialize, Serialize)] +pub struct Config { + pub authorization: String, + pub url: String, +} + +const FILENAME: &str = "aar.json"; + +pub fn empty_config() -> Config { + Config { + authorization: "".to_string(), + url: "".to_string(), + } +} + +pub fn read_config() -> Result> { + let contents = fs::read_to_string(FILENAME)?; + let config: Config = serde_json::from_str(&contents)?; + Ok(config) +} diff --git a/extension/src/lib.rs b/extension/src/lib.rs new file mode 100644 index 0000000..38fd7a6 --- /dev/null +++ b/extension/src/lib.rs @@ -0,0 +1,35 @@ +use arma_rs::{arma, Extension}; + +#[macro_use] +extern crate lazy_static; + +use std::sync::Mutex; + +mod config; +mod mission; +mod organizer; + +lazy_static! { + static ref ORGANIZER: Mutex = Mutex::new(organizer::Organizer::new()); +} + +fn init() -> String { + ORGANIZER.lock().map_or("ERROR".to_string(), |mut o| o.read_config()) +} + +fn event(json_str: String) -> String { + ORGANIZER.lock().map_or("ERROR".to_string(), |mut o| o.event(json_str)) +} + +fn mission(name: String, world: String) -> String { + ORGANIZER.lock().map_or("ERROR".to_string(), |mut o| o.mission(name, world)) +} + +#[arma] +fn extension() -> Extension { + Extension::build() + .command("init", init) + .command("event", event) + .command("mission", mission) + .finish() +} diff --git a/extension/src/mission.rs b/extension/src/mission.rs new file mode 100644 index 0000000..d953c21 --- /dev/null +++ b/extension/src/mission.rs @@ -0,0 +1,12 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize)] +pub struct MissionRequest { + pub name: String, + pub world: String, +} + +#[derive(Deserialize)] +pub struct MissionResponse { + pub id: i64, +} diff --git a/extension/src/organizer.rs b/extension/src/organizer.rs new file mode 100644 index 0000000..b643ae8 --- /dev/null +++ b/extension/src/organizer.rs @@ -0,0 +1,85 @@ +use crate::config::{Config, empty_config, read_config}; +use crate::mission::{MissionRequest, MissionResponse}; +use reqwest::blocking::Client; +use std::collections::HashMap; + +pub struct Organizer { + client: Client, + config: Config, + mission_id: i64, +} + +impl Organizer { + pub fn new() -> Organizer { + Organizer { + client: Client::new(), + config: empty_config(), + mission_id: 0, + } + } + + pub fn event(&mut self, json_str: String) -> String { + match serde_json::from_str::>(&json_str) { + Ok(mut event) => { + event.insert( + "timestamp".to_string(), + serde_json::Value::String(chrono::Utc::now().to_rfc3339().to_string()), + ); + + let path = format!("{}/missions/{}/events", self.config.url, self.mission_id); + + let result = self + .client + .post(&path) + .json(&event) + .send(); + + match result { + Ok(_) => "OK".to_string(), + Err(_) => "ERROR".to_string(), + } + }, + Err(e) => { + println!("{}", e); + "ERROR".to_string() + } + } + } + + pub fn mission(&mut self, name: String, world: String) -> String { + let path = format!("{}/missions", self.config.url); + + let result = self + .client + .post(&path) + .json(&MissionRequest { name, world }) + .send(); + + let response = match result { + Ok(response) => response, + Err(_) => return "-1".to_string(), + }; + + let mission: MissionResponse = match response.json() { + Ok(mission) => mission, + Err(_) => return "-1".to_string(), + }; + + self.mission_id = mission.id; + self.mission_id.to_string() + } + + pub fn read_config(&mut self) -> String { + match read_config() { + Ok(config) => { + let url = config.url.clone(); + self.config = config; + url + }, + Err(e) => { + println!("{}", e); + "ERROR".to_string() + } + } + } +} diff --git a/linux32.cmake b/linux32.cmake deleted file mode 100644 index 33148a4..0000000 --- a/linux32.cmake +++ /dev/null @@ -1,5 +0,0 @@ -set(CMAKE_C_FLAGS_INIT -m32) -set(CMAKE_CXX_FLAGS_INIT -m32) -set(CMAKE_EXE_LINKER_FLAGS_INIT -m32) -set(CMAKE_MODULE_LINKER_FLAGS_INIT -m32) -set(CMAKE_SHARED_LINKER_FLAGS_INIT -m32)