Skip to content

Commit

Permalink
Add documentation & submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
radj307 committed Dec 6, 2021
1 parent 210eac5 commit ea9ce60
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 44 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ _ReSharper*/
#Nuget packages folder
packages/
out/

FileLib/*
sharedlib/*
libunistd/*
TermAPI/*
optlib/*
7 changes: 4 additions & 3 deletions ARRCON/arg-handlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Help.hpp"
#include <ParamsAPI2.hpp>
#include <env.hpp>
#include <make_exception.hpp>

/**
* @brief Retrieve the user's specified connection target.
Expand Down Expand Up @@ -43,7 +44,7 @@ inline void handle_args(const opt::ParamsAPI2& args, const std::string& program_
std::cout << "Successfully wrote to config: \"" << Global.ini_path << '\"' << std::endl;
std::exit(EXIT_SUCCESS);
}
else throw std::exception(("I/O operation failed: \""s + Global.ini_path + "\" couldn't be written to."s).c_str());
else throw make_exception(("I/O operation failed: \""s + Global.ini_path + "\" couldn't be written to."s));
}
// quiet:
if (args.check_any<opt::Option, opt::Flag>('q', "quiet"))
Expand All @@ -59,9 +60,9 @@ inline void handle_args(const opt::ParamsAPI2& args, const std::string& program_
if (std::all_of(arg.value().begin(), arg.value().end(), isdigit)) {
if (const auto t{ std::chrono::milliseconds(std::abs(str::stoll(arg.value()))) }; t <= MAX_DELAY)
Global.command_delay = t;
else throw std::exception(("Cannot set a delay value longer than "s + std::to_string(MAX_DELAY.count()) + " hours!"s).c_str());
else throw make_exception(("Cannot set a delay value longer than "s + std::to_string(MAX_DELAY.count()) + " hours!"s).c_str());
}
else throw std::exception(("Invalid delay value given: \""s + arg.value() + "\", expected an integer."s).c_str());
else throw make_exception(("Invalid delay value given: \""s + arg.value() + "\", expected an integer."s).c_str());
}
// disable colors:
if (const auto arg{ args.typegetv_any<opt::Option, opt::Flag>('n', "no-color") }; arg.has_value())
Expand Down
2 changes: 1 addition & 1 deletion ARRCON/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#pragma once
#include <ColorPalette.hpp>

#include <../libunistd/unistd/sys/socket.h>
#include <sys/socket.h>
#include <chrono>

inline constexpr const auto
Expand Down
22 changes: 13 additions & 9 deletions ARRCON/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#include "mode.hpp"
#include "config.hpp"
#include "arg-handlers.hpp"
#undef __cplusplus
#define __cplusplus 202002L
#include "mode.hpp" ///< RCON client modes
#include "config.hpp" ///< INI functions
#include "arg-handlers.hpp" ///< CLI argument handler

#include <fileio.hpp>
#include <fileio.hpp> ///< file I/O functions

#include <signal.h>
#include <../libunistd/unistd/unistd.h>
#undef read ///< fileio.hpp compat
#undef write ///< fileio.hpp compat
#include <signal.h> ///< signal handling
#include <unistd.h>

// undefine unistd macros for fileio.hpp compat
#undef read
#undef write

/// @brief Emergency stop handler, should be passed to the std::atexit() function to allow a controlled shutdown of the socket.
inline void safeExit(void)
Expand Down Expand Up @@ -87,7 +91,7 @@ inline std::vector<std::string> get_commands(const opt::ParamsAPI2& args, const
return commands;
}

int main(int argc, char** argv, char** envp)
int main(int argc, char** argv)
{
try {
std::cout << sys::term::EnableANSI; // enable ANSI escape sequences on windows
Expand Down
22 changes: 13 additions & 9 deletions ARRCON/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,32 @@

#include <optional>
#include <string>
#include <winsock.h>
#include <sys/socket.h>

/**
* @namespace net
* @brief Contains functions used to interact with sockets.
*/
namespace net {
#ifdef _WIN32
inline void init_WSA(void) noexcept(false)
/**
* @brief Call WSAStartup & initialize the winsock dll.
*\n Only necessary on Windows, as the Linux socket library
* performs the startup & cleanup operations automatically.
*/
inline void init(void) noexcept(false)
{
#ifdef _WIN32
WSADATA wsaData;
int rc{ 0 };
if (rc = WSAStartup(WINSOCK_VERSION, &wsaData); rc != 0 || LOBYTE(wsaData.wVersion) != LOBYTE(WINSOCK_VERSION) || HIBYTE(wsaData.wVersion) != HIBYTE(WINSOCK_VERSION))
throw std::exception("WSAStartup failed with error code " + rc);
#else

#endif
}
#endif

/**
* @brief Close the socket & call WSACleanup.
* @brief Close the socket & call WSACleanup on windows.
* @param sd The socket descriptor to close.
*/
inline void close_socket(const SOCKET& sd)
Expand Down Expand Up @@ -97,9 +103,7 @@ namespace net {
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

#ifdef _WIN32
init_WSA();
#endif
net::init();

int ret = getaddrinfo(host.c_str(), port.c_str(), &hints, &server_info);
if (ret != 0)
Expand All @@ -120,7 +124,7 @@ namespace net {
break; // connection successful, break from loop
}

freeaddrinfo(server_info);
freeaddrinfo(server_info); // release address info memory

if (p == NULL) {
const auto err{ lastError() };
Expand Down
21 changes: 10 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.22)
cmake_minimum_required (VERSION 3.19)

# Set C++ Language Version to 20, or latest on MSVC to fix an MSVC/Windows-specific bug
if(MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29.30129 AND CMAKE_VERSION VERSION_GREATER 3.20.3)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD 23) # MSVC
else()
set(CMAKE_CXX_STANDARD 20)
endif()
# Require C++20 as concepts & other C++20 features are used.
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project ("ARRCON") # Project

project ("ARRCON")

if (MSVC) # Make MSVC use standard __cplusplus macro values
if (MSVC) # MSVC-specific requirements
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")

add_subdirectory(libunistd)
endif()
if (WIN32)
add_subdirectory(libunistd) # replace the unistd library with "libunistd" on windows
target_include_directories(libunistd PUBLIC "libunistd" "libunistd/unistd")
endif()

Expand All @@ -27,7 +26,7 @@ add_subdirectory(TermAPI) # TermAPI library
add_subdirectory(optlib) # cli-opt library
add_subdirectory(FileLib) # cpp-file-parser library

add_subdirectory ("ARRCON") # ARRCON Project Executable
add_subdirectory ("ARRCON") # ARRCON Project Executable

if (MSVC)
target_link_libraries(ARRCON PUBLIC libunistd)
Expand Down
10 changes: 5 additions & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"version": 2,
"configurePresets": [
{
"cmakeExecutable": "X:\\Utilities\\cmake\\bin\\cmake.exe",
"name": "linux-default",
"displayName": "Ninja",
"displayName": "Linux Debug",
"description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.",
"generator": "Visual Studio 17 2022",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cmakeExecutable": "/usr/bin/cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
Expand All @@ -18,12 +18,12 @@
}
},
{
"cmakeExecutable": "X:\\Utilities\\cmake\\bin\\cmake.exe",
"name": "linux-release",
"displayName": "Linux x64 Release",
"displayName": "Linux Release",
"description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cmakeExecutable": "/usr/bin/cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
Expand Down
1 change: 1 addition & 0 deletions FileLib
Submodule FileLib added at 9b703a
1 change: 1 addition & 0 deletions TermAPI
Submodule TermAPI added at f01421
1 change: 1 addition & 0 deletions optlib
Submodule optlib added at 079591
1 change: 1 addition & 0 deletions sharedlib
Submodule sharedlib added at 2226f9

0 comments on commit ea9ce60

Please sign in to comment.