Skip to content

Commit

Permalink
feat: added CIs, added more documentation, rename main.hpp to main.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Dec 17, 2023
1 parent bdbc3b9 commit 18181e0
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 266 deletions.
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Replace this line with a summary of your changes.

- [ ] My PR is titled using the [convention commits style](https://www.conventionalcommits.org/en/v1.0.0/)
- [ ] I tested my changes before raising the PR.
- [ ] I have not built my pull request using AI, a static analysis tool, or similar, without any human oversight.
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: D++ CI
on:
push:
paths:
- '**Dockerfile'
- '**.cxx'
- '**.cpp'
- '**.h'
- '**.hpp'
- '**.cmake'
- '**ci.yml'
- '**CMakeLists.txt'
pull_request:
paths:
- '**Dockerfile'
- '**.cxx'
- '**.cpp'
- '**.h'
- '**.hpp'
- '**.cmake'
- '**ci.yml'
- '**CMakeLists.txt'
- '!**/docpages/**'

permissions:
contents: read

jobs:
linux:
permissions:
contents: write
name: Linux ${{matrix.cfg.arch}} (${{matrix.cfg.cpp-version}})
runs-on: ${{matrix.cfg.os}}
strategy:
fail-fast: false # Don't fail everything if one fails. We want to test each OS/Compiler individually
matrix:
cfg:
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-13, cpp-version: clang++-13}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-14, cpp-version: clang++-14}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-15, cpp-version: clang++-15}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-13, cpp-version: g++-13}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-12, cpp-version: g++-12}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-11, cpp-version: g++-11}
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit

- name: Checkout FDR
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Install apt packages
run: sudo apt update && sudo apt-get install -y ${{ matrix.cfg.package }} pkg-config libsodium-dev libopus-dev zlib1g-dev rpm

- name: Install DPP
run: wget -O dpp.deb https://dl.dpp.dev/ && sudo dpkg -i dpp.deb

- name: Generate CMake
run: cmake -B build
env:
CXX: ${{matrix.cfg.cpp-version}}

- name: Build Project
run: cmake --build build -j${{ matrix.cfg.concurrency }}
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# IDE stuff
.idea
.vs

# Build directories
_build
build
cmake-build-debug

# Xcode stuff
*.xcworkspace
*.xcuserdatad
*.xcscheme
_build
build

# Apple stuff.
.DS_Store
1 change: 1 addition & 0 deletions include/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
5 changes: 0 additions & 5 deletions include/main.hpp

This file was deleted.

73 changes: 42 additions & 31 deletions include/rcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@
#define HEADER_SIZE 14

enum data_type {
SERVERDATA_AUTH = 3,
SERVERDATA_AUTH_RESPONSE = 2,
SERVERDATA_EXECCOMMAND = 2,
SERVERDATA_RESPONSE_VALUE = 0
/**
* @brief A command packet.
*
* @note The server *may* send a `SERVERDATA_RESPONSE_VALUE` packet if the request was successful.
* However, The server can also not send a packet back if it only processes the packet and does nothing else.
* You should take this into account by either not using the callback or by turning feedback off.
*/
SERVERDATA_EXECCOMMAND = 2,

/**
* @brief An authorisation packet.
*
* The server will send an empty `SERVERDATA_AUTH_RESPONSE` packet if the request was successful.
*/
SERVERDATA_AUTH = 3,
};

struct rcon_packet {
Expand All @@ -35,11 +46,11 @@ struct rcon_queued_request {
};

class rcon {
const std::string address;
const unsigned int port;
const std::string password;
unsigned int sock{0};
bool connected{false};
const std::string address;
const unsigned int port;
const std::string password;
unsigned int sock{0};
bool connected{false};

std::vector<rcon_queued_request> requests_queued{};

Expand All @@ -51,7 +62,7 @@ class rcon {
* @note This is a blocking call (done on purpose). It needs to wait to connect to the RCON server before anything else happens.
* It will timeout after 4 seconds if it can't connect.
*/
rcon(const std::string& addr, const unsigned int _port, const std::string& pass);
rcon(const std::string& addr, const unsigned int _port, const std::string& pass);

/**
* @brief Send data to the connected RCON server. Requests from this function are added to a queue (`requests_queued`) and are handled by a different thread.
Expand All @@ -76,18 +87,18 @@ class rcon {
*
* @returns Data given by the server from the request.
*/
const std::string send_data_sync(const std::string data, const int32_t id, data_type type, bool feedback = true);
const std::string send_data_sync(const std::string data, const int32_t id, data_type type, bool feedback = true);

private:

/**
* @brief Connects to RCON using `address`, `port`, and `password`.
* Those values are pre-filled when constructing this class.
*
* @warning This should only ever be called by the constructor.
* The constructor calls this function once it has filled in the required data and proceeds to login.
*/
bool connect();
/**
* @brief Connects to RCON using `address`, `port`, and `password`.
* Those values are pre-filled when constructing this class.
*
* @warning This should only ever be called by the constructor.
* The constructor calls this function once it has filled in the required data and proceeds to login.
*/
bool connect();

/**
* @brief Form a valid RCON packet.
Expand All @@ -106,22 +117,22 @@ class rcon {
*
* @return Data given by the server.
*/
std::string receive_information(int32_t id);
std::string receive_information(int32_t id);

/**
* @brief Gathers all the packet's content (based on the length returned by `read_packet_length`)
*/
const rcon_packet read_packet();
rcon_packet read_packet();

inline const size_t read_packet_length() {
unsigned char* buffer = new unsigned char[4]{0};
::recv(sock, buffer, 4, 0);
const size_t len = byte32_to_int(buffer);
delete[] buffer;
return len;
}
inline const size_t read_packet_length() {
unsigned char* buffer = new unsigned char[4]{0};
::recv(sock, buffer, 4, 0);
const size_t len = byte32_to_int(buffer);
delete[] buffer;
return len;
}

inline const size_t byte32_to_int(unsigned char* buffer) {
return static_cast<size_t>(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24);
}
inline const size_t byte32_to_int(unsigned char* buffer) {
return static_cast<size_t>(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24);
}
};
Loading

0 comments on commit 18181e0

Please sign in to comment.