├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ ├── change-an-existing-feature.md │ ├── documentation-request.md │ ├── question.md │ ├── request-a-new-feature.md │ └── support-request.md └── workflows │ └── MakeRelease.yaml ├── .gitignore ├── .gitmodules ├── ARRCON ├── ARRCON.cpp ├── ARRCON.ico ├── CMakeLists.txt ├── ExceptionBuilder.hpp ├── config.hpp ├── helpers │ ├── FileLocator.hpp │ ├── bukkit-colors.h │ └── print_input_prompt.h ├── logging.hpp └── net │ ├── rcon.hpp │ └── target_info.hpp ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── README.md └── SECURITY.md /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Issue template for reporting bugs with the ARRCON project. 4 | title: "[BUG] …" 5 | labels: bug 6 | assignees: radj307 7 | 8 | --- 9 | 10 | 14 | 15 | ### \# System Information 16 | 25 | - OS: 26 | - Version: 27 | - Shell (Windows-Only): 28 | 29 | ### \# Bug Description 30 | 36 | 37 | ### \# Reproduction Steps 38 | 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/change-an-existing-feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Change an Existing Feature 3 | about: Suggest changes to an existing ARRCON feature. 4 | title: "[CHANGE] " 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 13 | ### \# Existing Feature Request 14 | - Is this feature related to an existing bug report? 15 | 24 | 25 | - What does this feature currently do? 26 | 29 | 30 | - What should this feature do? 31 | 34 | 35 | - Additional Information 36 | 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation Request 3 | about: Request changes or additions to documentation. 4 | title: "[DOC] " 5 | labels: documentation 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### \# Documentation Request 11 | - What is the documentation for? 12 | 15 | 16 | - Is there existing documentation? 17 | 22 | 23 | - What changes would you want to see? 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question about anything related to the ARRCON project. 4 | title: "[QUESTION] " 5 | labels: question 6 | assignees: radj307 7 | 8 | --- 9 | 10 | ### \# Question 11 | 17 | 18 | 19 | 20 | 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/request-a-new-feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Request a New Feature 3 | about: Suggest new features to add to ARRCON. 4 | title: "[NEW]" 5 | labels: enhancement, new feature request 6 | assignees: '' 7 | 8 | --- 9 | 10 | 13 | ### \# New Feature Request 14 | - Is this feature related to an existing bug report? 15 | 24 | 25 | - What does this feature do? 26 | 29 | 30 | - Are there alternative solutions that already exist? 31 | 35 | 36 | - Description 37 | 41 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/support-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Support Request 3 | about: Report an unsupported game or application. 4 | title: 'Unsupported Title: ' 5 | labels: bug, enhancement, support 6 | assignees: radj307 7 | 8 | --- 9 | 10 | # Support Request 11 | 12 | ## Which Game/Application are you requesting support for? 13 | <!--- Include its name, and if necessary, where I can get a version to test ---> 14 | 15 | ## What is unique to this title that prevents ARRCON from working with it? 16 | <!--- Include any error messages or relevant information. ---> 17 | -------------------------------------------------------------------------------- /.github/workflows/MakeRelease.yaml: -------------------------------------------------------------------------------- 1 | name: Make Release 2 | 3 | on: 4 | push: 5 | tags: [ '[0-9]+.[0-9]+.[0-9]+-?**' ] 6 | 7 | jobs: 8 | build-windows: 9 | runs-on: windows-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v4 13 | with: 14 | submodules: recursive 15 | fetch-depth: 0 16 | 17 | - name: Install Requirements 18 | run: choco install ninja 19 | 20 | - uses: ilammy/msvc-dev-cmd@v1 21 | 22 | - name: CMake Configure 23 | run: cmake -B build -DCMAKE_BUILD_TYPE=Release -G Ninja 24 | 25 | - name: CMake Build 26 | run: cmake --build build --config Release 27 | 28 | - name: Create Archive 29 | run: | 30 | cd build/ARRCON 31 | Compress-Archive ARRCON.exe ARRCON-$(.\ARRCON -vq)-Windows.zip 32 | mv *.zip ../.. 33 | shell: pwsh 34 | 35 | - name: Upload Artifact 36 | uses: actions/upload-artifact@v4 37 | with: 38 | name: build-windows 39 | path: 'ARRCON*.zip' 40 | 41 | 42 | build-linux: 43 | runs-on: ubuntu-latest 44 | 45 | steps: 46 | - uses: actions/checkout@v4 47 | with: 48 | submodules: recursive 49 | fetch-depth: 0 50 | 51 | - name: Install Requirements 52 | run: sudo apt-get install -y gcc-10 cmake ninja-build 53 | 54 | - name: CMake Configure 55 | run: cmake -B build -DCMAKE_BUILD_TYPE=Release -G Ninja 56 | env: 57 | CC: gcc-10 58 | CXX: g++-10 59 | 60 | - name: CMake Build 61 | run: cmake --build build --config Release 62 | 63 | - name: Create Archive 64 | run: | 65 | cd build/ARRCON 66 | zip -T9 ARRCON-$(./ARRCON -vq)-Linux.zip ARRCON 67 | mv *.zip ../.. 68 | 69 | - name: Upload Artifact 70 | uses: actions/upload-artifact@v4 71 | with: 72 | name: build-linux 73 | path: 'ARRCON*.zip' 74 | 75 | 76 | build-macos: 77 | runs-on: macos-latest 78 | 79 | steps: 80 | - uses: actions/checkout@v4 81 | with: 82 | submodules: recursive 83 | fetch-depth: 0 84 | 85 | - name: Install Ninja & LLVM/Clang 16 86 | id: install-deps 87 | run: | 88 | brew install ninja llvm@16 89 | echo "clang_path=$(brew --prefix llvm@16)/bin/clang" >> "$GITHUB_OUTPUT" 90 | 91 | - name: CMake Configure 92 | run: cmake -B build -DCMAKE_BUILD_TYPE=Release -G Ninja 93 | env: 94 | CC: ${{ steps.install-deps.outputs.clang_path }} 95 | CXX: ${{ steps.install-deps.outputs.clang_path }}++ 96 | 97 | - name: CMake Build 98 | run: cmake --build build --config Release 99 | 100 | - name: Create Archive 101 | run: | 102 | cd build/ARRCON 103 | zip -T9 ARRCON-$(./ARRCON -vq)-MacOS.zip ARRCON 104 | mv *.zip ../.. 105 | 106 | - name: Upload Artifact 107 | uses: actions/upload-artifact@v4 108 | with: 109 | name: build-macos 110 | path: 'ARRCON*.zip' 111 | 112 | 113 | make-release: 114 | runs-on: ubuntu-latest 115 | needs: [ build-windows, build-linux, build-macos ] 116 | if: ${{ always() && contains(needs.*.result, 'success') }} 117 | # ^ Run after all other jobs finish & at least one was successful 118 | 119 | steps: 120 | - name: Download Artifacts 121 | uses: actions/download-artifact@v4 122 | 123 | - name: Stage Files 124 | run: mv ./build-*/* ./ 125 | 126 | - name: Create Release 127 | uses: softprops/action-gh-release@v1 128 | with: 129 | draft: true 130 | tag_name: ${{ github.ref_name }} 131 | generate_release_notes: true 132 | fail_on_unmatched_files: true 133 | files: '*.zip' 134 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #Ignore thumbnails created by Windows 3 | Thumbs.db 4 | #Ignore files built by Visual Studio 5 | *.obj 6 | *.exe 7 | *.pdb 8 | *.user 9 | *.aps 10 | *.pch 11 | *.vspscc 12 | *_i.c 13 | *_p.c 14 | *.ncb 15 | *.suo 16 | *.tlb 17 | *.tlh 18 | *.bak 19 | *.cache 20 | *.ilk 21 | *.log 22 | [Bb]in 23 | [Dd]ebug*/ 24 | *.lib 25 | *.sbr 26 | obj/ 27 | [Rr]elease*/ 28 | _ReSharper*/ 29 | [Tt]est[Rr]esult* 30 | .vs/ 31 | #Nuget packages folder 32 | packages/ 33 | out/ 34 | /ARRCON/version.h 35 | /ARRCON/versioninfo.rc 36 | /ARRCON/ARRCON.rc 37 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "307lib"] 2 | path = 307lib 3 | url = https://github.com/radj307/307lib 4 | branch = main 5 | -------------------------------------------------------------------------------- /ARRCON/ARRCON.cpp: -------------------------------------------------------------------------------- 1 | // CMake 2 | #include "version.h" 3 | #include "copyright.h" 4 | 5 | // ARRCON 6 | #include "net/rcon.hpp" 7 | #include "config.hpp" 8 | #include "helpers/print_input_prompt.h" 9 | #include "helpers/bukkit-colors.h" 10 | #include "helpers/FileLocator.hpp" 11 | 12 | // 307lib 13 | #include <opt3.hpp> //< for commandline argument parser & manager 14 | #include <color-sync.hpp> //< for color::sync 15 | #include <envpath.hpp> //< for env::PATH 16 | #include <hasPendingDataSTDIN.h> //< for hasPendingDataSTDIN 17 | #include <str/strconv.hpp> 18 | 19 | // STL 20 | #include <filesystem> //< for std::filesystem 21 | #include <iostream> //< for standard io streams 22 | 23 | // Global defaults 24 | static constexpr char const* const DEFAULT_TARGET_HOST{ "127.0.0.1" }; 25 | static constexpr char const* const DEFAULT_TARGET_PORT{ "27015" }; 26 | 27 | struct print_help { 28 | std::string exeName; 29 | 30 | print_help(const std::string& exeName) : exeName{ exeName } {} 31 | 32 | friend std::ostream& operator<<(std::ostream& os, const print_help& h) 33 | { 34 | return os << h.exeName << " v" << ARRCON_VERSION_EXTENDED << " (" << ARRCON_COPYRIGHT << ")\n" 35 | << " A Robust Remote-CONsole (RCON) client designed for use with the Source RCON Protocol.\n" 36 | << " It is also compatible with similar protocols such as the one used by Minecraft.\n" 37 | << '\n' 38 | << " Report compatibility issues here: https://github.com/radj307/ARRCON/issues/new?template=support-request.md\n" 39 | << '\n' 40 | << "USAGE:" << '\n' 41 | << " " << h.exeName << " [OPTIONS] [COMMANDS]\n" 42 | << '\n' 43 | << " Some arguments take additional inputs, labeled with <angle brackets>." << '\n' 44 | << " Inputs that contain spaces must be enclosed with single (\') or double(\") quotation marks." << '\n' 45 | << '\n' 46 | << "TARGET SPECIFIER OPTIONS:\n" 47 | << " -H, --host <Host> RCON Server IP/Hostname. (Default: \"" << DEFAULT_TARGET_HOST << "\")" << '\n' 48 | << " -P, --port <Port> RCON Server Port. (Default: \"" << DEFAULT_TARGET_PORT << "\")" << '\n' 49 | << " -p, --pass <Pass> RCON Server Password. (Default: \"\")" << '\n' 50 | << " -R, --recall <Name> Recalls saved [Host|Port|Pass] values from the hosts file." << '\n' 51 | << " --save <Name> Saves the specified [Host|Port|Pass] as \"<Name>\" in the hosts file." << '\n' 52 | << " --remove <Name> Removes an entry from the hosts file." << '\n' 53 | << " -l, --list Lists the servers currently saved in the host file." << '\n' 54 | << '\n' 55 | << "OPTIONS:\n" 56 | << " -h, --help Shows this help display, then exits." << '\n' 57 | << " -v, --version Prints the current version number, then exits." << '\n' 58 | << " -q, --quiet Silent/Quiet mode; prevents or minimizes console output. Use \"-qn\" for scripts." << '\n' 59 | << " -i, --interactive Starts an interactive command shell after sending any scripted commands." << '\n' 60 | << " -e, --echo Enables command echo in oneshot mode." << '\n' 61 | << " -w, --wait <ms> Sets the number of milliseconds to wait between sending each queued command. Default: 0" << '\n' 62 | << " -t, --timeout <ms> Sets the number of milliseconds to wait for a response before timing out. Default: 3000" << '\n' 63 | << " -n, --no-color Disables colorized console output." << '\n' 64 | << " -Q, --no-prompt Disables the prompt in interactive mode." << '\n' 65 | << " --no-exit Disables handling the \"exit\" keyword in interactive mode." << '\n' 66 | << " --allow-empty Enables sending empty (whitespace-only) commands to the server in interactive mode." << '\n' 67 | << " --print-env Prints all recognized environment variables, their values, and descriptions." << '\n' 68 | // << " --write-ini (Over)write the INI file with the default configuration values & exit." << '\n' 69 | // << " --update-ini Writes the current configuration values to the INI file, and adds missing keys." << '\n' 70 | // << " -f, --file <file> Load the specified file and run each line as a command." << '\n' 71 | ; 72 | } 73 | }; 74 | 75 | // terminal color synchronizer 76 | color::sync csync{}; 77 | 78 | int main_impl(const int, char**); 79 | 80 | int main(const int argc, char** argv) 81 | { 82 | try { 83 | return main_impl(argc, argv); 84 | } catch (std::exception const& ex) { 85 | std::cerr << csync.get_fatal() << ex.what() << std::endl; 86 | return 1; 87 | } catch (...) { 88 | std::cerr << csync.get_fatal() << "An undefined error occurred!" << std::endl; 89 | return 1; 90 | } 91 | } 92 | 93 | int main_impl(const int argc, char** argv) 94 | { 95 | const opt3::ArgManager args{ argc, argv, 96 | // define capturing args: 97 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, 'H', "host", "hostname"), 98 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, 'P', "port"), 99 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, 'p', "pass", "password"), 100 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, 'S', 'R', "saved", "recall"), 101 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, "save", "save-host"), 102 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, "rm", "remove", "rm-host" "remove-host"), 103 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, 'w', "wait"), 104 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, 't', "timeout"), 105 | opt3::make_template(opt3::CaptureStyle::Required, opt3::ConflictStyle::Conflict, 'f', "file"), 106 | }; 107 | 108 | // get the executable's location & name 109 | const auto& [programPath, programName] { env::PATH().resolve_split(argv[0]) }; 110 | FileLocator locator{ programPath, std::filesystem::path{ programName }.replace_extension() }; 111 | 112 | /// setup the log 113 | // log file stream 114 | std::ofstream logfs{ locator.from_extension(".log") }; 115 | // log manager object 116 | Logger logManager{ logfs.rdbuf() }; 117 | logManager.print_header(); 118 | // write commandline to log 119 | { 120 | const auto argVec{ opt3::vectorize(argc, argv) }; 121 | std::clog 122 | << MessageHeader(LogLevel::Debug) << "Commandline Arguments: \"" 123 | << str::stringify_join(argVec.begin(), argVec.end(), ' ') << '\"' 124 | << std::endl; 125 | } 126 | 127 | try { 128 | // -h|--help 129 | if (args.empty() || args.check_any<opt3::Flag, opt3::Option>('h', "help")) { 130 | std::cout << print_help(programName.generic_string()); 131 | return 0; 132 | } 133 | 134 | // -q|--quiet 135 | const bool quiet{ args.check_any<opt3::Flag, opt3::Option>('q', "quiet") }; 136 | 137 | // -v|--version 138 | if (args.check_any<opt3::Flag, opt3::Option>('v', "version")) { 139 | if (!quiet) std::cout << "ARRCON v"; 140 | std::cout << ARRCON_VERSION_EXTENDED; 141 | if (!quiet) std::cout << std::endl << ARRCON_COPYRIGHT; 142 | std::cout << std::endl; 143 | return 0; 144 | } 145 | 146 | // -n|--no-color 147 | csync.setEnabled(!args.check_any<opt3::Flag, opt3::Option>('n', "no-color")); 148 | 149 | std::string programNameStr{ std::filesystem::path(programName).replace_extension().generic_string() }; 150 | 151 | // --print-env 152 | if (args.check<opt3::Option>("print-env")) { 153 | const auto 154 | config_dir{ env::getvar(programNameStr + "_CONFIG_DIR") }, 155 | hostname{ env::getvar(programNameStr + "_HOST") }, 156 | port{ env::getvar(programNameStr + "_PORT") }, 157 | password{ env::getvar(programNameStr + "_PASS") }; 158 | std::cout << std::boolalpha 159 | << "Environment Variables" << '\n' 160 | << " " << csync(color::yellow) << programNameStr << "_CONFIG_DIR" << csync() << '\n' 161 | << " Is Defined: " << config_dir.has_value() << '\n' 162 | << " Current Value: " << config_dir.value_or("") << '\n' 163 | << " Description:\n" 164 | << " Overrides the config file search location.\n" 165 | << " When this is set, config files in other directories on the search path are ignored.\n" 166 | << '\n' 167 | << " " << csync(color::yellow) << programNameStr << "_HOST" << csync() << '\n' 168 | << " Is Defined: " << hostname.has_value() << '\n' 169 | << " Current Value: " << hostname.value_or("") << '\n' 170 | << " Description:\n" 171 | << " Overrides the target hostname, unless one is specified on the commandline with [-H|--host].\n" 172 | //<< " When this is set, the " << csync(color::yellow) << "sDefaultHost" << csync() << " key in the INI will be ignored.\n" 173 | << '\n' 174 | << " " << csync(color::yellow) << programNameStr << "_PORT" << csync() << '\n' 175 | << " Is Defined: " << port.has_value() << '\n' 176 | << " Current Value: " << port.value_or("") << '\n' 177 | << " Description:\n" 178 | << " Overrides the target port, unless one is specified on the commandline with [-P|--port].\n" 179 | //<< " When this is set, the " << csync(color::yellow) << "sDefaultPort" << csync() << " key in the INI will be ignored.\n" 180 | << '\n' 181 | << " " << csync(color::yellow) << programNameStr << "_PASS" << csync() << '\n' 182 | << " Is Defined: " << password.has_value() << '\n' 183 | << " Description:\n" 184 | << " Overrides the target password, unless one is specified on the commandline with [-p|--pass].\n" 185 | //<< " When this is set, the " << csync(color::yellow) << "sDefaultPass" << csync() << " key in the INI will be ignored.\n" 186 | ; 187 | return 0; 188 | } 189 | 190 | /// determine the target server info & operate on the hosts file 191 | const auto hostsfile_path{ locator.from_extension(".hosts") }; 192 | std::optional<config::SavedHosts> hostsfile; 193 | 194 | // --remove|--rm|--rm-host|--remove-host 195 | if (const auto& arg_removeHost{ args.getv_any<opt3::Option>("rm", "remove", "rm-host", "remove-host") }; arg_removeHost.has_value()) { 196 | if (!std::filesystem::exists(hostsfile_path)) 197 | throw make_exception("The hosts file hasn't been created yet. (Use \"--save\" to create one)"); 198 | 199 | // load the hosts file directly 200 | ini::INI ini(hostsfile_path); 201 | 202 | // remove the specified entry 203 | if (const auto it{ ini.find(arg_removeHost.value()) }; it != ini.end()) 204 | ini.erase(it); 205 | else throw make_exception("The specified saved host \"", arg_removeHost.value(), "\" doesn't exist! (Use \"--list\" to see a list of saved hosts)"); 206 | 207 | // save the hosts file 208 | if (ini.write(hostsfile_path)) { 209 | std::cout 210 | << "Successfully removed \"" << csync(color::yellow) << arg_removeHost.value() << csync() << "\" from the hosts list.\n" 211 | << "Saved hosts file to " << hostsfile_path << '\n' 212 | ; 213 | return 0; 214 | } 215 | else throw make_exception("Failed to save hosts file to ", hostsfile_path, '!'); 216 | } 217 | // --list|--list-hosts 218 | else if (args.check_any<opt3::Flag, opt3::Option>('l', "list", "list-hosts", "list-host")) { 219 | if (!std::filesystem::exists(hostsfile_path)) 220 | throw make_exception("The hosts file hasn't been created yet. (Use \"--save-host\" to create one)"); 221 | 222 | // load the hosts file 223 | if (!hostsfile.has_value()) 224 | hostsfile = config::SavedHosts(hostsfile_path); 225 | 226 | if (hostsfile->empty()) 227 | throw make_exception("The hosts file doesn't have any entries yet. (Use \"--save-host\" to create one)"); 228 | 229 | // if quiet was specified, get the length of the longest saved host name 230 | size_t longestNameLength{}; 231 | if (quiet) { 232 | for (const auto& [name, _] : *hostsfile) { 233 | if (name.size() > longestNameLength) 234 | longestNameLength = name.size(); 235 | } 236 | } 237 | 238 | // print out the hosts list 239 | for (const auto& [name, info] : *hostsfile) { 240 | if (!quiet) { 241 | std::cout 242 | << csync(color::yellow) << name << csync() << '\n' 243 | << " Hostname: \"" << info.host << "\"\n" 244 | << " Port: \"" << info.port << "\"\n" 245 | ; 246 | } 247 | else { 248 | std::cout 249 | << csync(color::yellow) << name << csync() 250 | << indent(longestNameLength + 2, name.size()) 251 | << "( " << info.host << ':' << info.port << " )\n" 252 | ; 253 | } 254 | } 255 | 256 | return 0; 257 | } 258 | 259 | net::rcon::target_info target{ 260 | env::getvar(programNameStr + "_HOST").value_or(DEFAULT_TARGET_HOST), 261 | env::getvar(programNameStr + "_PORT").value_or(DEFAULT_TARGET_PORT), 262 | env::getvar(programNameStr + "_PASS").value_or("") 263 | }; 264 | 265 | // -S|-R|--saved|--recall 266 | if (const auto& arg_saved{ args.getv_any<opt3::Flag, opt3::Option>('S', 'R', "saved", "recall") }; arg_saved.has_value()) { 267 | if (!std::filesystem::exists(hostsfile_path)) 268 | throw make_exception("The hosts file hasn't been created yet. (Use \"--save\" to create one)"); 269 | 270 | // load the hosts file 271 | if (!hostsfile.has_value()) 272 | hostsfile = config::SavedHosts(hostsfile_path); 273 | 274 | // try getting the specified saved target's info 275 | if (const auto savedTarget{ hostsfile->get_host(arg_saved.value()) }; savedTarget.has_value()) { 276 | target = savedTarget.value(); 277 | } 278 | else throw make_exception("The specified saved host \"", arg_saved.value(), "\" doesn't exist! (Use \"--list\" to see a list of saved hosts)"); 279 | 280 | std::clog << MessageHeader(LogLevel::Debug) << "Recalled saved host information for \"" << arg_saved.value() << "\": " << target << std::endl; 281 | } 282 | // -H|--host|--hostname 283 | if (const auto& arg_hostname{ args.getv_any<opt3::Flag, opt3::Option>('H', "host", "hostname") }; arg_hostname.has_value()) 284 | target.host = arg_hostname.value(); 285 | // -P|--port 286 | if (const auto& arg_port{ args.getv_any<opt3::Flag, opt3::Option>('P', "port") }; arg_port.has_value()) 287 | target.port = arg_port.value(); 288 | // -p|--pass|--password 289 | if (const auto& arg_password{ args.getv_any<opt3::Flag, opt3::Option>('p', "pass", "password") }; arg_password.has_value()) 290 | target.pass = arg_password.value(); 291 | 292 | // --save|--save-host 293 | if (const auto& arg_saveHost{ args.getv_any<opt3::Option>("save", "save-host") }; arg_saveHost.has_value()) { 294 | // load the hosts file 295 | if (!hostsfile.has_value()) { 296 | hostsfile = std::filesystem::exists(hostsfile_path) 297 | ? config::SavedHosts(hostsfile_path) 298 | : config::SavedHosts(); 299 | } 300 | 301 | const bool exists{ hostsfile->contains(arg_saveHost.value()) }; 302 | auto& entry{ (*hostsfile)[arg_saveHost.value()] }; 303 | 304 | // break early if no changes will be made 305 | if (exists && entry == target) { 306 | std::cout << "Host \"" << csync(color::yellow) << arg_saveHost.value() << csync() << "\" was already saved with the specified server info.\n"; 307 | return 0; 308 | } 309 | 310 | // set the target 311 | entry = target; 312 | 313 | // create directory structure 314 | if (!std::filesystem::exists(hostsfile_path)) 315 | std::filesystem::create_directories(hostsfile_path.parent_path()); 316 | 317 | // write to disk 318 | ini::INI ini; 319 | hostsfile->export_to(ini); 320 | if (ini.write(hostsfile_path)) { 321 | std::cout 322 | << "Host \"" << csync(color::yellow) << arg_saveHost.value() << csync() << "\" was " << (exists ? "updated" : "created") << " with the specified server info.\n" 323 | << "Saved hosts file to " << hostsfile_path << '\n' 324 | ; 325 | return 0; 326 | } 327 | else throw make_exception("Failed to save hosts file to ", hostsfile_path, '!'); 328 | } 329 | 330 | // initialize the client 331 | net::rcon::RconClient client; 332 | 333 | // connect to the server 334 | client.connect(target.host, target.port); 335 | 336 | // -t|--timeout 337 | client.set_timeout(args.castgetv_any<int, opt3::Flag, opt3::Option>([](auto&& arg) { return str::stoi(std::forward<decltype(arg)>(arg)); }, 't', "timeout").value_or(3000)); 338 | // ^ this needs to be set AFTER connecting 339 | 340 | // authenticate with the server 341 | if (!client.authenticate(target.pass)) { 342 | throw ExceptionBuilder() 343 | .line("Authentication Error: Incorrect Password!") 344 | .line("Target Hostname/IP: ", target.host) 345 | .line("Target Port: ", target.port) 346 | .line("Suggested Solutions:") 347 | .line("1. Verify the password you entered is correct.") 348 | .line("2. Make sure this is the correct target.") 349 | .build(); 350 | } 351 | 352 | /// get commands from STDIN & the commandline 353 | std::vector<std::string> commands; 354 | if (hasPendingDataSTDIN()) { 355 | // get commands from STDIN 356 | for (std::string buf; std::getline(std::cin, buf);) { 357 | commands.emplace_back(buf); 358 | } 359 | } 360 | if (const auto parameters{ args.getv_all<opt3::Parameter>() }; 361 | !parameters.empty()) { 362 | commands.insert(commands.end(), parameters.begin(), parameters.end()); 363 | } 364 | 365 | const bool noPrompt{ args.check_any<opt3::Flag, opt3::Option>('Q', "no-prompt") }; 366 | const bool echoCommands{ args.check_any<opt3::Flag, opt3::Option>('e', "echo") }; 367 | 368 | // Oneshot Mode 369 | if (!commands.empty()) { 370 | // get the command delay, if one was specified 371 | std::chrono::milliseconds commandDelay; 372 | bool useCommandDelay{ false }; 373 | if (const auto waitArg{ args.getv_any<opt3::Flag, opt3::Option>('w', "wait") }; waitArg.has_value()) { 374 | commandDelay = std::chrono::milliseconds{ str::tonumber<uint64_t>(waitArg.value()) }; 375 | useCommandDelay = true; 376 | } 377 | 378 | // oneshot mode 379 | bool fst{ true }; 380 | for (const auto& command : commands) { 381 | // wait for the specified number of milliseconds 382 | if (useCommandDelay) { 383 | if (fst) fst = false; 384 | else std::this_thread::sleep_for(commandDelay); 385 | } 386 | 387 | if (echoCommands) { 388 | if (!noPrompt) // print the shell prompt 389 | print_input_prompt(std::cout, target.host, csync); 390 | // echo the command 391 | std::cout << command << '\n'; 392 | } 393 | 394 | // execute the command and print the result 395 | std::cout << str::trim(client.command(command)) << std::endl; 396 | } 397 | } 398 | 399 | const bool disableExitKeyword{ args.check_any<opt3::Option>("no-exit") }; 400 | const bool allowEmptyCommands{ args.check_any<opt3::Option>("allow-empty") }; 401 | 402 | // Interactive mode 403 | if (commands.empty() || args.check_any<opt3::Flag, opt3::Option>('i', "interactive")) { 404 | if (!noPrompt) { 405 | std::cout << "Authentication Successful.\nUse <Ctrl + C>"; 406 | if (!disableExitKeyword) std::cout << " or type \"exit\""; 407 | std::cout << " to quit.\n"; 408 | } 409 | 410 | // interactive mode input loop 411 | while (true) { 412 | if (!quiet && !noPrompt) // print the shell prompt 413 | print_input_prompt(std::cout, target.host, csync); 414 | 415 | // get user input 416 | std::string str; 417 | std::getline(std::cin, str); 418 | 419 | // check for data remaining in the socket's buffer from previous commands 420 | if (const auto& buffer_size{ client.buffer_size() }; buffer_size > 0) { 421 | std::clog << MessageHeader(LogLevel::Warning) << "The buffer contains " << buffer_size << " unexpected bytes! Dumping the buffer to STDOUT." << std::endl; 422 | 423 | // print the buffered data before continuing 424 | std::cout << str::trim(net::rcon::bytes_to_string(client.flush())) << std::endl; 425 | } 426 | 427 | // validate the input 428 | if (!allowEmptyCommands && str::trim(str).empty()) { 429 | std::cerr << csync(color::cyan) << "[not sent: empty]" << csync() << '\n'; 430 | continue; 431 | } 432 | // check for the exit keyword 433 | else if (!disableExitKeyword && str == "exit") 434 | break; //< exit on keyword input 435 | 436 | // send the command and get the response 437 | str = str::trim(client.command(str)); 438 | 439 | if (str.empty()) { 440 | // response is empty 441 | std::cerr << csync(color::orange) << "[empty response]" << csync() << '\n'; 442 | } 443 | else { 444 | // replace minecraft bukkit color codes with ANSI sequences 445 | str = mc_color::replace_color_codes(str); 446 | 447 | // print the response 448 | std::cout << str << std::endl; 449 | } 450 | } 451 | } 452 | 453 | return 0; 454 | } catch (std::exception const& ex) { 455 | // catch & log exceptions 456 | std::clog << MessageHeader(LogLevel::Fatal) << ex.what() << std::endl; 457 | throw; //< rethrow 458 | } 459 | } 460 | -------------------------------------------------------------------------------- /ARRCON/ARRCON.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/radj307/ARRCON/0859b1b6e21d31573407001ed88d29b86de46fec/ARRCON/ARRCON.ico -------------------------------------------------------------------------------- /ARRCON/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ARRCON/ARRCON 2 | file(GLOB_RECURSE HEADERS 3 | RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" 4 | CONFIGURE_DEPENDS 5 | "*.h*" 6 | ) 7 | file(GLOB_RECURSE SRCS 8 | RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" 9 | CONFIGURE_DEPENDS 10 | "*.c*" 11 | ) 12 | 13 | string(TIMESTAMP _current_year "%Y") 14 | 15 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rc") 16 | if (WIN32) 17 | include(ResourceMaker) 18 | 19 | MAKE_STRINGRC_VERSIONINFO( 20 | _arrcon_stringrc_versioninfo 21 | "${ARRCON_VERSION}" 22 | "Copyright © ${_current_year} by radj307" 23 | "radj307" 24 | "ARRCON" 25 | "Commandline client for communicating with servers using the Source RCON Protocol." 26 | ) 27 | MAKE_STRINGRC_ICON( 28 | _arrcon_stringrc_icon 29 | "${CMAKE_CURRENT_SOURCE_DIR}/ARRCON.ico" 30 | ) 31 | 32 | MAKE_RESOURCE("${CMAKE_CURRENT_BINARY_DIR}/rc/ARRCON.rc" "${_arrcon_stringrc_versioninfo}" "${_arrcon_stringrc_icon}") 33 | endif() 34 | 35 | MAKE_VERSION_HEADER("${CMAKE_CURRENT_BINARY_DIR}/rc/version.h" ARRCON "${ARRCON_VERSION_EXTENDED}") 36 | include(CopyrightMaker) 37 | MAKE_COPYRIGHT_HEADER("${CMAKE_CURRENT_BINARY_DIR}/rc/copyright.h" ARRCON ${_current_year} radj307) 38 | 39 | file(GLOB RESOURCES 40 | CONFIGURE_DEPENDS 41 | "${CMAKE_CURRENT_BINARY_DIR}/rc/*" 42 | ) 43 | 44 | include_directories("/opt/local/include") 45 | 46 | add_executable(ARRCON "${SRCS}" "${RESOURCES}") 47 | 48 | set_property(TARGET ARRCON PROPERTY CXX_STANDARD 20) 49 | set_property(TARGET ARRCON PROPERTY CXX_STANDARD_REQUIRED ON) 50 | 51 | if (MSVC) 52 | target_compile_options(ARRCON PRIVATE "${307lib_compiler_commandline}") 53 | endif() 54 | 55 | target_include_directories(ARRCON PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/rc") 56 | 57 | target_sources(ARRCON PRIVATE "${HEADERS}") 58 | 59 | ## Setup Boost: 60 | # Try to find an existing Boost 1.84.0 package 61 | find_package(Boost 1.84.0 COMPONENTS asio) 62 | # Fallback to FetchContent if not found 63 | if (NOT Boost_FOUND) 64 | message(STATUS "Downloading Boost 1.84.0 via FetchContent") 65 | 66 | include(FetchContent) 67 | FetchContent_Declare( 68 | Boost 69 | GIT_REPOSITORY https://github.com/boostorg/boost.git 70 | GIT_TAG boost-1.84.0 71 | ) 72 | FetchContent_MakeAvailable(Boost) 73 | endif() 74 | 75 | target_link_libraries(ARRCON PRIVATE 76 | TermAPI 77 | filelib 78 | Boost::asio 79 | ) 80 | -------------------------------------------------------------------------------- /ARRCON/ExceptionBuilder.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 307lib::shared 3 | #include <make_exception.hpp> //< for ex::except 4 | #include <indentor.hpp> //< for shared::indent() 5 | 6 | // 307lib::TermAPI 7 | #include <Message.hpp> //< for term::MessageMarginSize 8 | 9 | class ExceptionBuilder { 10 | using this_t = ExceptionBuilder; 11 | 12 | std::stringstream ss; 13 | bool isFirstLine{ true }; 14 | 15 | public: 16 | ExceptionBuilder() {} 17 | 18 | /** 19 | * @brief Builds an exception and returns it. 20 | * @returns ex::except with the previously-specified message. 21 | */ 22 | ex::except build() const 23 | { 24 | return{ ss.str() }; 25 | } 26 | 27 | /** 28 | * @brief Adds a line to the exception message. 29 | * @param ...content - The content of the line. 30 | * @returns *this 31 | */ 32 | this_t& line(auto&&... content) 33 | { 34 | if (!isFirstLine) 35 | ss << std::endl << indent(term::MessageMarginSize); 36 | else isFirstLine = false; 37 | 38 | (ss << ... << std::forward<decltype(content)>(content)); 39 | 40 | return *this; 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /ARRCON/config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "logging.hpp" 3 | #include "net/target_info.hpp" 4 | 5 | // 307lib::filelib 6 | #include <simpleINI.hpp> //< for ini::INI 7 | 8 | // STL 9 | #include <filesystem> //< for std::filesystem::path 10 | #include <map> //< for std::map 11 | 12 | namespace config { 13 | inline constexpr const auto HEADER_APPERANCE{ "appearance" }; 14 | inline constexpr const auto HEADER_TARGET{ "target" }; 15 | inline constexpr const auto HEADER_MISC{ "miscellaneous" }; 16 | 17 | class SavedHosts { 18 | using target_info = net::rcon::target_info; 19 | using map = std::map<std::string, target_info>; 20 | 21 | map hosts; 22 | 23 | public: 24 | SavedHosts() = default; 25 | SavedHosts(ini::INI const& ini) 26 | { 27 | import_from(ini); 28 | } 29 | SavedHosts(std::filesystem::path const& path) : SavedHosts(ini::INI(path)) {} 30 | 31 | auto begin() const { return hosts.begin(); } 32 | auto end() const { return hosts.end(); } 33 | bool empty() const noexcept { return hosts.empty(); } 34 | size_t size() const noexcept { return hosts.size(); } 35 | bool contains(std::string const& name) const { return hosts.contains(name); } 36 | 37 | void import_from(ini::INI const& ini) 38 | { 39 | if (ini.contains("")) { 40 | // warn about global keys 41 | const auto globalKeysCount{ ini.at("").size() }; 42 | std::clog << MessageHeader(LogLevel::Warning) << "Hosts file contains " << globalKeysCount << " key" << (globalKeysCount == 1 ? "" : "s") << " that aren't associated with a saved host!" << std::endl; 43 | } 44 | 45 | // enumerate entries 46 | for (const auto& [entryKey, entryContent] : ini) { 47 | // enumerate key-value pairs 48 | for (const auto& [key, value] : entryContent) { 49 | const std::string keyLower{ str::tolower(key) }; 50 | 51 | if (str::equalsAny<false>(keyLower, "sHost")) { 52 | hosts[entryKey].host = value; 53 | 54 | std::clog << MessageHeader(LogLevel::Trace) << '[' << entryKey << ']' << " Imported hostname \"" << value << '\"' << std::endl; 55 | } 56 | else if (str::equalsAny<false>(keyLower, "sPort")) { 57 | hosts[entryKey].port = value; 58 | 59 | std::clog << MessageHeader(LogLevel::Trace) << '[' << entryKey << ']' << " Imported port \"" << value << '\"' << std::endl; 60 | } 61 | else if (str::equalsAny<false>(keyLower, "sPass")) { 62 | hosts[entryKey].pass = value; 63 | 64 | std::clog << MessageHeader(LogLevel::Trace) << '[' << entryKey << ']' << " Imported password \"" << std::string(value.size(), '*') << '\"' << std::endl; 65 | } 66 | else { 67 | std::clog << MessageHeader(LogLevel::Warning) << '[' << entryKey << ']' << " Skipped unrecognized key \"" << key << "\"" << std::endl; 68 | } 69 | } 70 | } 71 | } 72 | void export_to(ini::INI& ini) const 73 | { 74 | for (const auto& [name, info] : hosts) { 75 | ini[name] = ini::Section{ 76 | std::make_pair("sHost", info.host), 77 | std::make_pair("sPort", info.port), 78 | std::make_pair("sPass", info.pass), 79 | }; 80 | 81 | std::clog << MessageHeader(LogLevel::Trace) << '[' << name << ']' << " was exported successfully." << std::endl; 82 | } 83 | } 84 | 85 | std::optional<target_info> get_host(std::string const& name) const 86 | { 87 | if (const auto& it{ hosts.find(name) }; it != hosts.end()) { 88 | return it->second; 89 | } 90 | else return std::nullopt; 91 | } 92 | 93 | auto& operator[](std::string const& name) 94 | { 95 | return hosts[name]; 96 | } 97 | }; 98 | } 99 | -------------------------------------------------------------------------------- /ARRCON/helpers/FileLocator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 307lib::shared 3 | #include <make_exception.hpp> //< for ex::make_exception 4 | #include <env.hpp> //< for env::getvar 5 | 6 | // STL 7 | #include <filesystem> //< for std::filesystem 8 | 9 | /** 10 | * @class FileLocator 11 | * @brief Used to locate ARRCON's config files. 12 | */ 13 | class FileLocator { 14 | std::filesystem::path program_location; 15 | std::string name_no_ext; 16 | std::filesystem::path env_path; 17 | std::filesystem::path home_path; 18 | 19 | public: 20 | FileLocator(std::filesystem::path const& program_dir, std::string const& program_name_no_extension) : 21 | program_location{ program_dir }, 22 | name_no_ext{ program_name_no_extension }, 23 | env_path{ env::getvar(name_no_ext + "_CONFIG_DIR").value_or("") }, 24 | home_path{ env::get_home() } 25 | { 26 | } 27 | FileLocator(std::filesystem::path const& program_dir, std::filesystem::path const& program_name_no_extension) : 28 | FileLocator(program_dir, program_name_no_extension.generic_string()) 29 | { 30 | } 31 | 32 | /** 33 | * @brief Retrieves the target location of the given file extension appended to the program name. (Excluding extension, if applicable.) 34 | * @param ext The file extension of the target file. 35 | * @returns std::filesystem::path 36 | *\n This is NOT guaranteed to exist! If no valid config file was found, the .config directory in the user's home directory is returned. 37 | */ 38 | std::filesystem::path from_extension(std::string const& ext) const 39 | { 40 | if (ext.empty()) 41 | throw make_exception("Empty extension passed to Locator::from_extension()!"); 42 | 43 | std::string target{ name_no_ext + ((ext.front() != '.') ? ("." + ext) : ext) }; 44 | std::filesystem::path path; 45 | // 1: check the environment 46 | if (!env_path.empty()) { 47 | path = env_path / target; 48 | return path; 49 | } 50 | // 2: check the program directory. (support portable versions by checking this before the user's home dir) 51 | if (path = program_location / target; std::filesystem::exists(path)) 52 | return path; 53 | // 3: user's home directory: 54 | path = home_path / ".config" / name_no_ext / target; 55 | return path; // return even if it doesn't exist 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /ARRCON/helpers/bukkit-colors.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bukkit-colors.hpp 3 | * @author radj307 4 | * @brief Helper functions for minecraft bukkit's color syntax. 5 | */ 6 | #pragma once 7 | // 307lib::TermAPI 8 | #include <Sequence.hpp> //< for ANSI::Sequence 9 | #include <color-values.h> //< for color codes 10 | #include <setcolor.hpp> //< for term::setcolor 11 | 12 | namespace mc_color { 13 | inline bool color_code_to_sequence(char const ch, std::string& sequence) 14 | { 15 | switch (ch) { 16 | case '0': // black 17 | sequence = color::setcolor(color::black); 18 | return true; 19 | case '1': // dark blue 20 | sequence = color::setcolor(color::dark_blue); 21 | return true; 22 | case '2': // dark green 23 | sequence = color::setcolor(color::dark_green); 24 | return true; 25 | case '3': // dark aqua 26 | sequence = color::setcolor(color::dark_cyan); 27 | return true; 28 | case '4': // dark red 29 | sequence = color::setcolor(color::dark_red); 30 | return true; 31 | case '5': // dark purple 32 | sequence = color::setcolor(color::dark_purple); 33 | return true; 34 | case '6': // gold 35 | sequence = color::setcolor(color::gold); 36 | return true; 37 | case '7': // gray 38 | sequence = color::setcolor(color::gray); 39 | return true; 40 | case '8': // dark gray 41 | sequence = color::setcolor(color::dark_gray); 42 | return true; 43 | case '9': // blue 44 | sequence = color::setcolor(color::blue); 45 | return true; 46 | case 'a': // green 47 | sequence = color::setcolor(color::green); 48 | return true; 49 | case 'b': // aqua 50 | sequence = color::setcolor(color::cyan); 51 | return true; 52 | case 'c': // red 53 | sequence = color::setcolor(color::red); 54 | return true; 55 | case 'd': // light purple 56 | sequence = color::setcolor(color::light_purple); 57 | return true; 58 | case 'e': // yellow 59 | sequence = color::setcolor(color::yellow); 60 | return true; 61 | case 'f': // white 62 | sequence = color::setcolor(color::white); 63 | return true; 64 | case 'r': // reset 65 | sequence = color::reset; 66 | return true; 67 | case 'n': // underline 68 | sequence = color::underline; 69 | return true; 70 | case 'l': // bold 71 | sequence = color::bold; 72 | return true; 73 | case 'k': // obfuscated 74 | return true; 75 | case 'm': // strikethrough 76 | return true; 77 | case 'o': // italic 78 | return true; 79 | default: 80 | return{}; 81 | } 82 | return false; 83 | } 84 | 85 | // The ASCII section sign character(s) 86 | #define SECTION_SIGN "§" 87 | 88 | /** 89 | * @brief Replaces Minecraft Bukkit color codes in the specified 90 | * message with the corresponding ANSI escape sequence. 91 | * @param message - The string to replace the bukkit color codes in. 92 | * @returns The converted message string. 93 | */ 94 | inline std::string replace_color_codes(std::string message) 95 | { 96 | for (size_t pos{ message.rfind(SECTION_SIGN) }, lastPos{ std::string::npos }; 97 | pos != std::string::npos; 98 | lastPos = pos, pos = message.rfind(SECTION_SIGN, pos - 1)) { 99 | // We need to check the last pos to prevent previous blank 100 | // replacement sequences from interfering with this one. 101 | // For example, "§§oo" should output "§o", not "" 102 | if (pos + 2 >= message.size() || pos + 2 == lastPos) 103 | continue; 104 | 105 | const auto it{ message.begin() + pos }; 106 | 107 | if (std::string colorSequence; 108 | color_code_to_sequence(*(it + 2), colorSequence)) { 109 | message.replace(it, it + 3, colorSequence); 110 | } 111 | } 112 | 113 | return message; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /ARRCON/helpers/print_input_prompt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 307lib::TermAPI 3 | #include <color-sync.hpp> 4 | 5 | // STL 6 | #include <string> //< for std::string 7 | #include <ostream> //< for std::ostream 8 | 9 | /** 10 | * @brief Pretty-prints an input prompt (ex: "RCON@...>") to the specified output stream. 11 | * @param os The output stream to print to. 12 | * @param hostname The hostname text to show in the prompt. 13 | * @param csync The terminal color synchronizer object to use. 14 | */ 15 | inline void print_input_prompt(std::ostream& os, std::string const& hostname, color::sync& csync) 16 | { 17 | os << csync(color::green) << csync(color::bold) << "RCON@" << hostname << '>' << csync(color::reset_all) << ' '; 18 | } 19 | -------------------------------------------------------------------------------- /ARRCON/logging.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 307lib::shared 3 | #include <strcore.hpp> //< for str::stringify 4 | #include <var.hpp> //< for var::streamable 5 | 6 | // Boost 7 | #include <boost/date_time/posix_time/posix_time.hpp> //< for boost::posix_time 8 | 9 | // STL 10 | #include <cstdint> //< for sized integer types 11 | #include <ostream> //< for std::ostream 12 | 13 | // the margin size for the timestamp 14 | #define LM_TIMESTAMP 17 15 | // the margin size for the message level 16 | #define LM_LEVEL 10 17 | 18 | enum class LogLevel : uint8_t { 19 | /// @brief Situational debugging information. 20 | Trace = 1, 21 | Debug = 2, 22 | Info = 4, 23 | Warning = 8, 24 | Error = 16, 25 | Critical = 32, 26 | Fatal = 64, 27 | }; 28 | 29 | inline std::ostream& operator<<(std::ostream& os, const LogLevel& logLevel) 30 | { 31 | switch (logLevel) { 32 | case LogLevel::Trace: 33 | os << "TRACE"; 34 | break; 35 | case LogLevel::Debug: 36 | os << "DEBUG"; 37 | break; 38 | case LogLevel::Info: 39 | os << "INFO"; 40 | break; 41 | case LogLevel::Warning: 42 | os << "WARN"; 43 | break; 44 | case LogLevel::Error: 45 | os << "ERROR"; 46 | break; 47 | case LogLevel::Critical: 48 | os << "CRITICAL"; 49 | break; 50 | case LogLevel::Fatal: 51 | os << "FATAL"; 52 | break; 53 | default: 54 | throw make_exception(logLevel, " is an invalid value for the LogLevel enum!"); 55 | } 56 | return os; 57 | } 58 | 59 | struct MessageHeader { 60 | LogLevel level; 61 | 62 | friend std::ostream& operator<<(std::ostream& os, const MessageHeader& m) 63 | { 64 | const auto timestamp{ boost::posix_time::to_iso_string(boost::posix_time::second_clock::universal_time()) }; 65 | const auto level{ str::stringify(m.level) }; 66 | return os 67 | << timestamp << indent(LM_TIMESTAMP, timestamp.size()) 68 | << '[' << level << ']' << indent(LM_LEVEL, level.size() + 2); 69 | } 70 | }; 71 | struct BlankHeader { 72 | friend std::ostream& operator<<(std::ostream& os, const BlankHeader& m) 73 | { 74 | return os << indent(LM_TIMESTAMP + LM_LEVEL); 75 | } 76 | }; 77 | 78 | /** 79 | * @class Logger 80 | * @brief Manager object that handles swapping the read buffer of std::clog with another one. 81 | * The read buffer is swapped back in the destructor. 82 | */ 83 | class Logger { 84 | std::streambuf* original_clog_rdbuf; 85 | 86 | public: 87 | Logger(std::streambuf* rdbuf) : original_clog_rdbuf{ std::clog.rdbuf() } 88 | { 89 | // swap clog rdbuf 90 | std::clog.rdbuf(rdbuf); 91 | } 92 | ~Logger() 93 | { 94 | // reset clog rdbuf 95 | std::clog.rdbuf(original_clog_rdbuf); 96 | } 97 | 98 | /** 99 | * @brief Prints a header line that indicates the segments of a log message. 100 | */ 101 | void print_header() const 102 | { 103 | std::clog << "YYYYMMDDTHHMMSS" << indent(LM_TIMESTAMP, 15) << "LEVEL" << indent(LM_LEVEL, 5) << "MESSAGE" << std::endl; 104 | } 105 | }; 106 | -------------------------------------------------------------------------------- /ARRCON/net/rcon.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../logging.hpp" 3 | #include "../ExceptionBuilder.hpp" 4 | 5 | // 307lib::TermAPI 6 | #include <Message.hpp> //< for term::MessageMarginSize 7 | 8 | // Boost::asio 9 | #include <boost/asio.hpp> 10 | 11 | // STL 12 | #include <cstdint> //< for sized integer types 13 | #include <vector> //< for std::vector 14 | #include <string> //< for std::string 15 | #include <iostream> //< for std::clog 16 | 17 | namespace net { 18 | using boost::asio::io_context; 19 | using boost::asio::ip::tcp; 20 | 21 | /** 22 | * @brief Resolves a target endpoint from the specified host and port. 23 | * @param io_context - The io_context to use. 24 | * @param host - The target hostname. 25 | * @param port - The target port number. 26 | * @returns The resolved target when successful; otherwise, std::nullopt. 27 | */ 28 | tcp::resolver::results_type resolve_targets(io_context& io_context, std::string_view host, std::string_view port) 29 | { 30 | return tcp::resolver(io_context).resolve(host, port); 31 | } 32 | 33 | namespace rcon { 34 | enum class PacketType : int32_t { 35 | SERVERDATA_AUTH = 3, 36 | SERVERDATA_AUTH_RESPONSE = 2, 37 | SERVERDATA_EXECCOMMAND = 2, 38 | SERVERDATA_RESPONSE_VALUE = 0, 39 | }; 40 | 41 | inline constexpr const int32_t PACKETID_MIN{ 1 }; 42 | inline constexpr const int32_t PACKETID_MAX{ std::numeric_limits<int32_t>::max() }; 43 | 44 | struct packet_header { 45 | int32_t size{}; 46 | int32_t id{}; 47 | int32_t type{}; 48 | }; 49 | 50 | inline constexpr int32_t get_packet_size(size_t const bodySize) 51 | { 52 | // 4 packet size bytes aren't included vvvvvvv 53 | return (sizeof(packet_header) - sizeof(int32_t)) + bodySize + 2; 54 | } 55 | 56 | /// @brief Minimum possible size of an RCON packet. 57 | inline constexpr const int32_t PACKETSZ_MIN{ sizeof(packet_header) + 2 }; 58 | /// @brief Maximum number of bytes that can be sent in a single packet, before being split between multiple packets. 59 | inline constexpr const int32_t PACKETSZ_MAX_SEND{ 4096 }; 60 | 61 | /** 62 | * @brief Converts the specified vector of bytes to a string by direct copying. 63 | * @param bytes - A vector of bytes to convert to a readable string. 64 | * @returns The string representation of the specified bytes. 65 | */ 66 | inline std::string bytes_to_string(std::vector<uint8_t> const& bytes) 67 | { 68 | std::string s{ bytes.size(), 0, std::allocator<char>() }; 69 | 70 | std::memcpy(const_cast<char*>(s.c_str()), bytes.data(), bytes.size()); 71 | 72 | return s; 73 | } 74 | 75 | /// @brief Source RCON client object. 76 | class RconClient { 77 | using buffer = std::vector<uint8_t>; 78 | 79 | io_context ioContext; 80 | tcp::socket socket; 81 | int32_t currentPacketid{ PACKETID_MIN }; 82 | 83 | /** 84 | * @brief Gets the next pseudo-unique packet ID. 85 | * @returns A pseudo-unique packet ID number. 86 | */ 87 | int32_t get_next_packet_id() 88 | { 89 | if (currentPacketid == PACKETID_MAX) 90 | currentPacketid = PACKETID_MIN; 91 | return currentPacketid++; 92 | } 93 | 94 | /** 95 | * @brief Creates a packet buffer from the specified header and body. 96 | * @param header - The pre-constructed packet header to use. 97 | * @param body - The body string to use. 98 | * @returns A buffer containing the packet's raw bytes. 99 | */ 100 | buffer build_packet(packet_header const& header, std::string const& body) 101 | { 102 | // create a buffer with 2 extra bytes for the packet terminator bytes 103 | buffer buf(sizeof(packet_header) + body.size() + 2, 0, std::allocator<uint8_t>()); 104 | 105 | // copy the buffer header into the buffer 106 | std::memcpy(&buf[0], &header, sizeof(packet_header)); 107 | 108 | // copy the buffer body into the buffer 109 | std::memcpy(&buf[0] + sizeof(packet_header), body.c_str(), body.size()); 110 | 111 | return buf; 112 | } 113 | /// @brief Builds a special blank terminator packet with the specified id. 114 | buffer build_terminator_packet(int32_t const id) 115 | { 116 | return build_packet(packet_header{ get_packet_size(0), id, (int32_t)PacketType::SERVERDATA_RESPONSE_VALUE }, ""); 117 | } 118 | 119 | /** 120 | * @brief Sends a blank message terminator packet to the server. 121 | * @param ec - error_code reference to use for socket errors 122 | * @returns The ID of the terminator packet. 123 | */ 124 | int32_t send_terminator_packet(boost::system::error_code& ec) 125 | { 126 | const int32_t termPacketId{ get_next_packet_id() }; 127 | const buffer termPacket{ build_terminator_packet(termPacketId) }; 128 | 129 | // send the terminator packet to the server 130 | if (boost::asio::write(socket, boost::asio::buffer(termPacket), ec) != termPacket.size()) 131 | return -1; 132 | 133 | return termPacketId; 134 | } 135 | 136 | /** 137 | * @brief Receives a single RCON packet. 138 | * @returns A pair containing the packet header and the packet body. 139 | */ 140 | std::pair<packet_header, buffer> recv() noexcept(false) 141 | { 142 | // error code 143 | boost::system::error_code ec{}; 144 | 145 | // read the packet header 146 | packet_header header{}; 147 | boost::asio::mutable_buffer buf(&header, sizeof(packet_header)); 148 | boost::asio::read(socket, buf, ec); 149 | 150 | // check for errors 151 | if (ec) 152 | throw make_exception("Failed to read packet header due to error: \"", ec.what(), "\"!"); 153 | 154 | // read the packet body 155 | const auto avail{ socket.available() }; 156 | const auto bodySize{ header.size - (sizeof(packet_header) - sizeof(int32_t)) }; 157 | buffer body_buffer{ bodySize, 0, std::allocator<uint8_t>() }; 158 | boost::asio::read(socket, boost::asio::buffer(body_buffer), ec); //< TODO: validate received byte count 159 | 160 | // check for errors 161 | if (ec) 162 | throw make_exception("Failed to read packet body due to error: \"", ec.what(), "\"!"); 163 | 164 | // remove the null terminators from the body buffer 165 | body_buffer.erase(std::remove(body_buffer.begin(), body_buffer.end(), '\0'), body_buffer.end()); 166 | 167 | return std::make_pair(header, body_buffer); 168 | } 169 | 170 | public: 171 | /** 172 | * @brief Creates a new RconClient instance and connects it to the specified endpoint. 173 | * @param host - The hostname of the target endpoint. 174 | * @param port - The port of the target endpoint. 175 | */ 176 | RconClient() : socket{ ioContext } {} 177 | ~RconClient() 178 | { 179 | ioContext.run(); //< wait for async operations to finish 180 | socket.close(); //< close the socket 181 | } 182 | 183 | /// @brief Connects the RCON client to the specified endpoint. 184 | void connect(std::string_view host, std::string_view port) noexcept(false) 185 | { 186 | // resolve DNS 187 | tcp::resolver::results_type targets; 188 | try { 189 | targets = resolve_targets(ioContext, host, port); //< this throws on failure & can't use boost::system::error_code 190 | } catch (std::exception const& ex) { 191 | // rethrow with stacktrace & custom message 192 | throw ExceptionBuilder() 193 | .line("Connection Error: DNS Resolution Failed!") 194 | .line("Target Hostname/IP: ", host) 195 | .line("Target Port: ", port) 196 | .line("Original Exception: ", ex.what()) 197 | .line("Suggested Solutions:") 198 | .line("1. Verify that you're using the correct Hostname/IP & Port.") 199 | .line("2. Verify that the target is online and connected to the internet.") 200 | .build(); 201 | } 202 | 203 | std::clog << MessageHeader(LogLevel::Debug) << "Resolved \"" << host << ':' << port << "\" to " << targets.size() << " endpoint" << (targets.size() == 1 ? "" : "s") << ':' << std::endl; 204 | for (const auto& target : targets) { 205 | std::clog << BlankHeader() << "- \"" << target.endpoint() << '\"' << std::endl; 206 | } 207 | 208 | // connect to the target 209 | boost::system::error_code ec{}; 210 | tcp::endpoint endpoint{ boost::asio::connect(socket, targets, ec) }; 211 | 212 | if (ec) { 213 | // an error occurred 214 | throw ExceptionBuilder() 215 | .line("Connection Error: Failed to establish a connection with the target!") 216 | .line("Target Hostname/IP: ", host) 217 | .line("Target Port: ", port) 218 | .line("Error Code: ", ec.value()) 219 | .line("Error Message: ", ec.message()) 220 | .line("Suggested Solutions:") 221 | .line("1. Verify that you're using the correct IP/hostname & Port.") 222 | .line("2. Verify that port ", port, " is accessible from your network.") 223 | .build(); 224 | } 225 | else std::clog << MessageHeader(LogLevel::Debug) << "Connected to endpoint \"" << endpoint << '\"' << std::endl;; 226 | } 227 | 228 | /** 229 | * @brief Sends a command to the RCON server and returns the response. 230 | * @param command - The command to send to the RCON server. 231 | * @returns The response from the RCON server when successful. 232 | */ 233 | std::string command(std::string const& command) noexcept(false) 234 | { 235 | boost::system::error_code ec{}; 236 | 237 | // build the command packet 238 | const auto packetId{ get_next_packet_id() }; 239 | const buffer packet{ build_packet(packet_header{ get_packet_size(command.size()), packetId, (int32_t)PacketType::SERVERDATA_EXECCOMMAND }, command) }; 240 | 241 | // send the command packet to the server 242 | if (const auto sent_bytes{ boost::asio::write(socket, boost::asio::buffer(packet), ec) }; 243 | sent_bytes != packet.size() || ec) { 244 | // an error occurred: 245 | const auto error_message{ 246 | sent_bytes == packet.size() 247 | ? str::stringify("Sent ", sent_bytes, '/', packet.size(), " bytes of packet #", packetId, " with command \"", command, "\", but an error occurred: ", ec.what()) 248 | : str::stringify("Sent ", sent_bytes, '/', packet.size(), " bytes of packet #", packetId, " with command \"", command, "\" due to error: ", ec.what()) 249 | }; 250 | 251 | std::clog << MessageHeader(LogLevel::Error) << error_message << std::endl; 252 | throw make_exception(error_message); 253 | } 254 | 255 | std::clog << MessageHeader(LogLevel::Debug) << "Sent packet #" << packetId << " with command \"" << command << '\"' << std::endl; 256 | 257 | // send the message terminator packet 258 | const int32_t termPacketId{ send_terminator_packet(ec) }; 259 | 260 | std::stringstream responseBody; 261 | int32_t receivedPackets{ 0 }; 262 | std::pair<packet_header, buffer> response; 263 | 264 | // receive the response 265 | for (response = recv(), receivedPackets = 1; 266 | response.first.id == packetId; 267 | response = recv(), ++receivedPackets) { 268 | responseBody << bytes_to_string(response.second); 269 | } 270 | 271 | std::clog // subtract 1 because of terminator packet vvv 272 | << MessageHeader(LogLevel::Debug) << "Received " << receivedPackets - 1 << " response packet" << (receivedPackets == 1 ? "" : "s") << '.' << std::endl; 273 | 274 | return responseBody.str(); 275 | } 276 | 277 | /** 278 | * @brief Authenticates with the connected RCON server by sending the specified password. 279 | * @param password - The password to send to the server. 280 | * @returns True when successful; otherwise, false. 281 | */ 282 | bool authenticate(std::string_view password) 283 | { 284 | boost::system::error_code ec{}; 285 | 286 | const buffer p{ build_packet(packet_header{ get_packet_size(password.size()), 1, (int32_t)PacketType::SERVERDATA_AUTH }, password.data()) }; 287 | 288 | if (boost::asio::write(socket, boost::asio::buffer(p), ec) != p.size() || ec) { 289 | std::clog << MessageHeader(LogLevel::Error) << "Failed to send authentication packet due to error: " << ec.what() << std::endl; 290 | return false; 291 | } 292 | 293 | // receive response & return success/fail 294 | return recv().first.id != -1; 295 | } 296 | 297 | /// @brief Empties the buffer and returns its contents. 298 | buffer flush() 299 | { 300 | const auto bytes{ socket.available() }; 301 | if (bytes == 0) return {}; 302 | 303 | buffer p{ bytes, 0, std::allocator<uint8_t>() }; 304 | boost::asio::read(socket, boost::asio::buffer(p)); 305 | 306 | std::clog << MessageHeader(LogLevel::Trace) << "Flushed " << bytes << " bytes from the buffer." << std::endl; 307 | 308 | return p; 309 | } 310 | 311 | /** 312 | * @brief Sets the socket timeout duration in milliseconds. 313 | * @param timeout_ms - Number of milliseconds to wait for a response before timing out. 314 | */ 315 | void set_timeout(int timeout_ms) 316 | { 317 | try { 318 | socket.set_option(boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO>{ timeout_ms }); 319 | } catch (std::exception const& ex) { 320 | std::clog << MessageHeader(LogLevel::Error) << "Failed to set socket timeout due to exception: \"" << ex.what() << '\"' << std::endl; 321 | } 322 | } 323 | 324 | /** 325 | * @brief Gets the current size of the socket's data buffer. 326 | * @returns The number of bytes that haven't been read from the buffer yet. 327 | */ 328 | size_t buffer_size() 329 | { 330 | return socket.available(); 331 | } 332 | }; 333 | } 334 | } 335 | -------------------------------------------------------------------------------- /ARRCON/net/target_info.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include <string> //< for std::string 3 | 4 | namespace net::rcon { 5 | struct target_info { 6 | std::string host; 7 | std::string port; 8 | std::string pass; 9 | 10 | friend bool operator==(target_info const& a, target_info const& b) 11 | { 12 | return a.host == b.host && a.port == b.port && a.pass == b.pass; 13 | } 14 | 15 | friend std::ostream& operator<<(std::ostream& os, const target_info& t) 16 | { 17 | return os << t.host << ':' << t.port; 18 | } 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ARRCON/ 2 | cmake_minimum_required (VERSION 3.22) 3 | 4 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/307lib/307modules") 5 | 6 | include(VersionTag) 7 | 8 | set(ENV{ARRCON_VERSION} "0.0.0") 9 | GET_VERSION_TAG("${CMAKE_CURRENT_SOURCE_DIR}" "ARRCON") 10 | 11 | project("ARRCON" VERSION "${ARRCON_VERSION}" LANGUAGES CXX) 12 | 13 | add_subdirectory("307lib") 14 | add_subdirectory("ARRCON") 15 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 4, 3 | "cmakeMinimumRequired": { 4 | "major": 3, 5 | "minor": 22, 6 | "patch": 0 7 | }, 8 | "configurePresets": [ 9 | // Shared 10 | { 11 | "name": "base", 12 | "hidden": true, 13 | "generator": "Ninja", 14 | "binaryDir": "${sourceDir}/out/build/${presetName}", 15 | "warnings": { 16 | "deprecated": true, 17 | "unusedCli": true, 18 | "uninitialized": true 19 | } 20 | }, 21 | 22 | // Windows 23 | { 24 | "name": "win-default", 25 | "inherits": "base", 26 | "hidden": true, 27 | "architecture": { 28 | "value": "x64", 29 | "strategy": "external" 30 | }, 31 | "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } } 32 | }, 33 | { 34 | "name": "win-debug", 35 | "inherits": "win-default", 36 | "cacheVariables": { 37 | "CMAKE_BUILD_TYPE": "Debug" 38 | } 39 | }, 40 | { 41 | "name": "win-release", 42 | "inherits": "win-default", 43 | "cacheVariables": { 44 | "CMAKE_BUILD_TYPE": "Release" 45 | } 46 | }, 47 | 48 | // Linux 49 | { 50 | "name": "linux-default", 51 | "inherits": "base", 52 | "hidden": true, 53 | "vendor": { 54 | "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Linux" ] }, 55 | "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } 56 | } 57 | }, 58 | { 59 | "name": "linux-debug", 60 | "inherits": "linux-default", 61 | "cacheVariables": { 62 | "CMAKE_BUILD_TYPE": "Debug" 63 | } 64 | }, 65 | { 66 | "name": "linux-release", 67 | "inherits": "linux-default", 68 | "cacheVariables": { 69 | "CMAKE_BUILD_TYPE": "Release" 70 | } 71 | }, 72 | 73 | // MacOS 74 | { 75 | "name": "macos-default", 76 | "inherits": "base", 77 | "hidden": true, 78 | "cacheVariables": { 79 | "CMAKE_C_COMPILER": "/opt/local/bin/clang-mp-17", 80 | "CMAKE_CXX_COMPILER": "/opt/local/bin/clang++-mp-17", 81 | // This requires the full path to ninja because visual studio doesn't find it on the PATH when cross compiling: 82 | "CMAKE_MAKE_PROGRAM": "/usr/local/bin/ninja" 83 | }, 84 | "vendor": { 85 | "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "macOS" ] }, 86 | "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } 87 | } 88 | }, 89 | { 90 | "name": "macos-debug", 91 | "inherits": "macos-default", 92 | "cacheVariables": { 93 | "CMAKE_BUILD_TYPE": "Debug" 94 | } 95 | }, 96 | { 97 | "name": "macos-release", 98 | "inherits": "macos-default", 99 | "cacheVariables": { 100 | "CMAKE_BUILD_TYPE": "Release" 101 | } 102 | } 103 | ] 104 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | <one line to give the program's name and a brief idea of what it does.> 635 | Copyright (C) <year> <name of author> 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see <https://www.gnu.org/licenses/>. 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | <program> Copyright (C) <year> <name of author> 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | <https://www.gnu.org/licenses/>. 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | <https://www.gnu.org/licenses/why-not-lgpl.html>. 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | <p align="center"> 2 | <img 3 | src="https://i.imgur.com/BdC2Qz9.png" 4 | alt="ARRCON Banner" 5 | /> 6 | </p> 7 | <p align="center"> 8 | A lightweight cross-platform RCON client compatible with <b>any game using the Source RCON Protocol</b>.<br/> 9 | <p align="center"> 10 | <a href="https://github.com/radj307/ARRCON/releases/latest"><img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/radj307/ARRCON?label=Latest+Version&style=flat"></a> 11 | <nobr/> 12 | <a href="https://github.com/awesome-selfhosted/awesome-selfhosted#games---administrative-utilities--control-panels"><img alt="Mentioned in Awesome-Selfhosted" src="https://awesome.re/mentioned-badge.svg"></a> 13 | <nobr/> 14 | <a href="https://github.com/radj307/ARRCON/releases"><img alt="Downloads" src="https://img.shields.io/github/downloads/radj307/ARRCON/total?label=Downloads&style=flat"></a> 15 | </p> 16 | <p align="center"> 17 | <a href="https://github.com/radj307/ARRCON/actions/workflows/MakeRelease.yaml"><img alt="Release Workflow Status" src="https://img.shields.io/github/actions/workflow/status/radj307/ARRCON/MakeRelease.yaml?label=Build Status&logo=github&style=flat"> 18 | </p> 19 | <p align="center"> 20 | <a href="https://github.com/radj307/ARRCON/releases">Downloads</a>  |  <a href="https://github.com/radj307/ARRCON/wiki">Wiki</a>  |  <a href="https://github.com/radj307/ARRCON/issues">Issues</a> 21 | </p> 22 | 23 | 24 | # Features 25 | - Highly configurable 26 | - **Cross-Platform:** 27 | - Windows 28 | - Linux 29 | - macOS 30 | - **Works for any game using the [Source RCON Protocol](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol)** 31 | - **Handles large packets without issue** 32 | - **Handles multi-packet responses without issue** 33 | - **Supports Minecraft Bukkit's colorized text** 34 | - You can set delays in the INI file or directly on the commandline 35 | - Supports saving a server's connection info so you can connect to it with 1 word 36 | If you've ever used `ssh`'s `config` file, this will be very familiar. *(albeit with more sensible syntax)* 37 | - This can be done in a text editor **or entirely from the commandline** 38 | - Can be used as a one-off from the commandline, or in an interactive console 39 | - Supports piped input using shell operators. 40 | For example; `echo "help" | ARRCON -S myServer` would send the `help` command to the `myServer` host 41 | - Piped commands are sent _after_ any commands explicitly specified on the commandline 42 | - You can write scripts and manually execute them with the `-f`/`--file` options in addition to shell scripts 43 | - Commands are separated by newlines 44 | - Commands from script files are sent _after_ any piped commands 45 | - Line comments can be written using semicolons `;` or pound signs '#' 46 | - Shows an indicator when the server didn't respond to your command 47 | 48 | 49 | # Installation 50 | Get the latest version for your OS from the [releases](https://github.com/radj307/ARRCON/releases) page. 51 | If you're using the [Windows](#windows) or [MacOS](#macos) versions, see the additional information below. 52 | 53 | There is no installation process required, simply extract the archive to a location of your choice, then run it using a terminal emulator. 54 | If you want to be able to run ARRCON from any working directory without specifying its location, you must [add the location to your environment's PATH variable](https://github.com/radj307/ARRCON/wiki/Adding-To-Path). 55 | 56 | 57 | ## Windows 58 | On newer versions of Windows, you may be required to "unblock" the executable before Windows will let you use it. 59 | This is because the executable isn't signed with a Microsoft-approved signing certificate, which costs upwards of [$300/year](https://docs.microsoft.com/en-us/windows-hardware/drivers/dashboard/get-a-code-signing-certificate#step-2-buy-a-new-code-signing-certificate). 60 | To unblock it, ___Right-Click___ on `ARRCON.exe` in the file explorer and click ___Properties___ at the bottom of the right-click menu. 61 | ![](https://i.imgur.com/LKLZPVX.png) 62 | Check the ___unblock___ box, then click ___Apply___. 63 | 64 | ## MacOS 65 | **If you're running macOS 10.9 or later, you must install `gcc` via [HomeBrew](https://brew.sh) or some other package manager!** 66 | If homebrew is installed, you can run this command to install and setup `gcc` automatically: `brew install gcc` 67 | 68 | This is because Apple no longer includes `libstdc++` by default as of macOS 10.9 *(See [#11](https://github.com/radj307/ARRCON/issues/11))*, which is required for ARRCON to run. 69 | 70 | ## Building from Source 71 | See [here](https://github.com/radj307/ARRCON/wiki/Building-from-Source) for a brief guide on building ARRCON from source. 72 | 73 | 74 | # Usage 75 | ARRCON is a CLI _(Command-Line Interface)_ program, which means you need to run it through a terminal. 76 | 77 | __On Windows, you can use `cmd.exe` or `powershell.exe` by R+Clicking on the start menu and selecting "Command Prompt" or "PowerShell".__ 78 | 79 | For more detailed usage instructions, see the [Getting Started](https://github.com/radj307/ARRCON/wiki) page on the wiki. 80 | 81 | To see a list of commands, use `ARRCON -h` or `ARRCON --help` 82 | To see a list of environment variables, their current values, and a description of each, use `ARRCON --print-env` 83 | 84 | 85 | ## Modes 86 | - ___Interactive Shell___ 87 | ![](https://i.imgur.com/4d4Epkb.png) 88 | Opens an interactive console session. You can send commands and view the responses in real-time. 89 | - Used by default when there are no command arguments. 90 | - Connection remains open until you disconnect or kill the process, or if the server closes. 91 | - ___One-Shot___ 92 | ![ARRCON Scripting Support](https://i.imgur.com/oPX47RD.png) 93 | This mode is designed for scripting, it sends commands directly from the commandline in sequential order before exiting. 94 | _(You can also open an interactive shell at the same time with the `-i` / `--interactive` options.)_ 95 | 96 | Supported input methods: 97 | - Commandline Parameters 98 | _These are any arguments that are __not__ short/long-opts and __not captured by__ short/long-opts._ 99 | - Shell Scripts 100 | - Redirected input from STDIN 101 | - Script Files 102 | Splits commands by line, and allows comments using a semicolon `;` or pound sign `#`. 103 | Comments are always considered line comments. 104 | _Use the '`-f`' or '`--file`' options to specify a scriptfile to load._ 105 | 106 | # Contributing 107 | 108 | If you want to add a new feature, fix a bug, or just improve something that annoys you, feel free to submit pull requests and/or issues. 109 | 110 | ## Feedback & Requests 111 | Feel free to leave feedback on the issues tab! 112 | There are a number of premade templates for the following situations: 113 | - [Questions](https://github.com/radj307/ARRCON/issues/new?assignees=radj307&labels=question&template=question.md&title=%5BQUESTION%5D+) 114 | - [Bug Reports](https://github.com/radj307/ARRCON/issues/new?assignees=radj307&labels=bug&template=bug-report.md&title=%5BBUG%5D+%E2%80%A6) 115 | - [Protocol Support Requests](https://github.com/radj307/ARRCON/issues/new?assignees=radj307&labels=bug%2C+enhancement%2C+support&template=support-request.md&title=Unsupported+Title%3A+%3Ctitle%3E) 116 | - __A note on Battleye's RCON protocol:__ 117 | Battleye's RCON protocol requires sending "keep-alive" packets at least every 45 seconds to maintain the connection, which is better suited by a multithreaded GUI application, and as such will not be implemented in ARRCON. 118 | Other protocols or game-specific implementations however, will be considered. 119 | - [Feature Requests](https://github.com/radj307/ARRCON/issues/new?assignees=&labels=enhancement%2C+new+feature+request&template=request-a-new-feature.md&title=%5BNEW%5D) 120 | - [Suggestions](https://github.com/radj307/ARRCON/issues/new?assignees=&labels=&template=change-an-existing-feature.md&title=%5BCHANGE%5D+) 121 | - [Documentation Suggestions or Additions](https://github.com/radj307/ARRCON/issues/new?assignees=&labels=documentation&template=documentation-request.md&title=%5BDOC%5D+) 122 | 123 | ## Pull Requests 124 | Feel free to submit a pull request if you've added a feature or fixed a bug with the project! 125 | Contributions are always welcomed, I'll review it as soon as I see the notification. 126 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Latest version only. 6 | 7 | ## Reporting a Vulnerability 8 | 9 | When possible, open an issue report or even better a pull request. 10 | --------------------------------------------------------------------------------