Skip to content

Commit

Permalink
Merge pull request #9 from Draiget/dev
Browse files Browse the repository at this point in the history
Add Linux support (cross-compilation)
  • Loading branch information
Draiget authored Oct 23, 2020
2 parents b0ffe2b + deeccca commit 551dca7
Show file tree
Hide file tree
Showing 40 changed files with 2,628 additions and 1,173 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/Debug/*
/Release/*
/project.vcxproj.user
/project.vcxproj.filters
/.vs/*
CMakeFiles/
out/
.vs/
Binary file removed .vs/project/v15/.suo
Binary file not shown.
139 changes: 139 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# CMake project for gmsv_rcon2
#
cmake_minimum_required (VERSION 3.8)

project ("gmsv_rcon2" CXX)

#
# Output library path
#
if(NOT "${GMSV_TARGET_PATH}" STREQUAL "")
message("Using output path: ${GMSV_TARGET_PATH}/")
set(LIBRARY_OUTPUT_PATH "${GMSV_TARGET_PATH}/")
endif()

file(GLOB src_files
"src/*.h"
"src/*.cpp"
)

add_library (gmsv_rcon2 SHARED ${src_files})
include_directories (SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/GarrysMod)

#
# Weird Linux naming for GM
#
set_target_properties(gmsv_rcon2
PROPERTIES
SUFFIX ".dll"
PREFIX ""
)

#
# SSDK lookup and includes
#
if("${GMSV_SSDK_PATH}" STREQUAL "")
message(SEND_ERROR "GMSV_SSDK_PATH are not set!")
else()
message("Using SSKD path: ${GMSV_SSDK_PATH}")
include_directories (SYSTEM ${GMSV_SSDK_PATH}/mp/src/public/vphysics)
include_directories (SYSTEM ${GMSV_SSDK_PATH}/mp/src/public/tier0)
include_directories (SYSTEM ${GMSV_SSDK_PATH}/mp/src/public/tier1)
include_directories (SYSTEM ${GMSV_SSDK_PATH}/mp/src/public/tier2)
include_directories (SYSTEM ${GMSV_SSDK_PATH}/mp/src/public/tier3)
include_directories (SYSTEM ${GMSV_SSDK_PATH}/mp/src/common)
include_directories (SYSTEM ${GMSV_SSDK_PATH}/mp/src/public)

if(${GMSV_PLATFORM} MATCHES "LINUX")
target_link_directories(gmsv_rcon2 PRIVATE ${GMSV_SSDK_PATH}/mp/src/lib/public/linux32/)
elseif(${GMSV_PLATFORM} MATCHES "WINDOWS")
target_link_directories(gmsv_rcon2 PRIVATE ${GMSV_SSDK_PATH}/mp/src/lib/public/)
endif()
endif()

#
# Platform auto-detection
#
if("${GMSV_PLATFORM}" STREQUAL "")
message("Target platform is not set, trying to detect it ...")
if (UNIX)
message("Target platform is set to Linux")
set(GMSV_PLATFORM "LINUX")
elseif(WIN32 OR MSVC)
message("Target platform is set to Windows")
set(GMSV_PLATFORM "WINDOWS")
else()
message("Failed to detect platform automatically!")
endif()
endif()

#
# Platform selection
#
if(${GMSV_PLATFORM} MATCHES "LINUX")
message("Target platform is Linux")
add_definitions(-D_PLATFORM_LINUX=1)
set_target_properties(gmsv_rcon2
PROPERTIES
OUTPUT_NAME "gmsv_rcon2_linux"
)

target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/linux32/libtier0.so)
target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/linux32/tier1.a)
target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/linux32/tier2.a)
target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/linux32/tier3.a)
target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/linux32/libvstdlib.so)
elseif(${GMSV_PLATFORM} MATCHES "WINDOWS")
message("Target platform is Windows")
add_definitions(-D_PLATFORM_WINDOWS=1)
set_target_properties(gmsv_rcon2
PROPERTIES
OUTPUT_NAME "gmsv_rcon2_win32"
)

target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/tier0.lib)
target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/tier1.lib)
target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/tier2.lib)
target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/tier3.lib)
target_link_libraries (gmsv_rcon2 ${GMSV_SSDK_PATH}/mp/src/lib/public/vstdlib.lib)
target_link_libraries (gmsv_rcon2 ws2_32.lib)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
if(MSVC)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:\"LIBCMT\" /NODEFAULTLIB:\"LIBCPMT\"")
endif()
else()
message(SEND_ERROR "Target platform is Unknown")
add_definitions(-D_PLATFORM_UKNOWN=1)
endif()

# Gmod Module definition
add_definitions(-DGMMODULE=1)

# Common stuff
set(X86 TRUE)
set(CMAKE_CXX_STANDARD 11)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "-m32")
endif()

#
# Different target configurations
#
if("${GMSV_TARGET}" STREQUAL "")
set(GMSV_TARGET "Release")
endif()
message("Target configurations type - ${GMSV_TARGET}")
if("${GMSV_TARGET}" STREQUAL "Release")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -s -DNDEBUG")
endif()
elseif("${GMSV_TARGET}" STREQUAL "Debug")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DEBUG /Od")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
endif()
158 changes: 158 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"configurations": [
{
"name": "x86-debug-win",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x86" ],
"buildRoot": "${projectDir}\\..\\output\\${name}",
"installRoot": "${projectDir}\\..\\output\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "GMSV_PLATFORM",
"value": "WINDOWS",
"type": "STRING"
},
{
"name": "GMSV_SSDK_PATH",
"value": "B:\\libs\\ssdk2013",
"type": "FILEPATH"
},
{
"name": "GMSV_TARGET_PATH",
"value": "S:\\game\\gmod_dev\\garrysmod\\lua\\bin",
"type": "FILEPATH"
}
]
},
{
"name": "x86-release-win",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [ "msvc_x86" ],
"buildRoot": "${projectDir}\\..\\output\\${name}",
"installRoot": "${projectDir}\\..\\output\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "GMSV_PLATFORM",
"value": "WINDOWS",
"type": "STRING"
},
{
"name": "GMSV_SSDK_PATH",
"value": "B:\\libs\\ssdk2013",
"type": "FILEPATH"
},
{
"name": "GMSV_TARGET_PATH",
"value": "S:\\game\\gmod_dev\\garrysmod\\lua\\bin",
"type": "FILEPATH"
}
]
},
{
"name": "x86-debug-linux",
"generator": "Unix Makefiles",
"remoteMachineName": "${defaultRemoteMachineName}",
"configurationType": "Debug",
"remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
"cmakeExecutable": "cmake",
"remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
"remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
"remoteCopySources": true,
"remoteCopySourcesOutputVerbosity": "Normal",
"remoteCopySourcesConcurrentCopies": "10",
"remoteCopySourcesMethod": "rsync",
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"rsyncCommandArgs": "-t --delete --delete-excluded",
"remoteCopyBuildOutput": false,
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_x86" ],
"addressSanitizerRuntimeFlags": "detect_leaks=0",
"variables": [
{
"name": "GMSV_PLATFORM",
"value": "LINUX",
"type": "STRING"
},
{
"name": "GMSV_TARGET",
"value": "Debug",
"type": "STRING"
},
{
"name": "CMAKE_CXX_COMPILER",
"value": "/usr/bin/g++",
"type": "FILEPATH"
},
{
"name": "GMSV_SSDK_PATH",
"value": "/usr/lib/ssdk-2013",
"type": "FILEPATH"
},
{
"name": "GMSV_TARGET_PATH",
"value": "/game/gmod_test/garrysmod/lua/bin",
"type": "FILEPATH"
}
]
},
{
"name": "x86-release-linux",
"generator": "Unix Makefiles",
"remoteMachineName": "${defaultRemoteMachineName}",
"configurationType": "Release",
"remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
"cmakeExecutable": "cmake",
"remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
"remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
"remoteCopySources": true,
"remoteCopySourcesOutputVerbosity": "Normal",
"remoteCopySourcesConcurrentCopies": "10",
"remoteCopySourcesMethod": "rsync",
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"rsyncCommandArgs": "-t --delete --delete-excluded",
"remoteCopyBuildOutput": false,
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_x86" ],
"addressSanitizerRuntimeFlags": "detect_leaks=0",
"variables": [
{
"name": "GMSV_PLATFORM",
"value": "LINUX",
"type": "STRING"
},
{
"name": "GMSV_TARGET",
"value": "Release",
"type": "STRING"
},
{
"name": "CMAKE_CXX_COMPILER",
"value": "/usr/bin/g++",
"type": "FILEPATH"
},
{
"name": "GMSV_SSDK_PATH",
"value": "/usr/lib/ssdk-2013",
"type": "FILEPATH"
},
{
"name": "GMSV_TARGET_PATH",
"value": "/game/gmod_test/garrysmod/lua/bin",
"type": "FILEPATH"
}
]
}
]
}
52 changes: 44 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
# gmsv_rcon2
Garry's Mod RCON Binary module for controlling RCON authentication directly from Lua

## Supported version:
```
Protocol version 24
Exe version 18.10.17 (garrysmod)
Exe build: 16:45:33 Oct 3 2018 (7270) (4000)
```
Garry's Mod binary module for controlling RCON authentication directly from Lua!

## Supported hooks

#### <a name="on_rcon_write_request"></a> `OnRconWriteRequest (listenerId, requestId, requestType, data, isLanIpAddress, ip, port)`

Main rcon hook **OnRconWriteRequest**, according engine function is - `CServerRemoteAccess::WriteDataRequest`.

On both platforms `::WriteDataRequest` checks for password first time and then process RCON requests. But here's a little difference between platforms. In Linux build each request bein logged with external call of `CServerRemoteAccess::LogCommand` (which is a hook **OnRconLogCommand**), but on Windows this function are force-inlined. Than means, you won't be not able to use `OnRconLogCommand` for Windows game server. Although `::LogCommand` function exists on both platforms, it is not being called on Windows.

#### <a name="on_rcon_check_password"></a> `OnRconCheckPassword (password, listenerId, isLanIpAddress, ip, port)`

Hook for engine function `CServerRemoteAccess::IsPassword`, which is being called in `CServerRemoteAccess::WriteDataRequest` to verity that incoming user password matches server (originally rcon_password console variable). You may not wanted to use **OnRconWriteRequest** but wish to override default password, or make it dynamic over time - so this is an option.

#### <a name="on_rcon_log_command"></a> `OnRconLogCommand (listenerId, msg, isKnownListener, isLanIpAddress, ip, port)`

Hook for engine function `CServerRemoteAccess::LogCommand`, originally it print out messages like `rcon from \"%s\": %s\n`. You can override printing on Linux platform using this hook.
Does not work under Windows, see [OnRconWriteRequest](#on_rcon_write_request).

# Building module
Requirements for manual build:
- SSDK2013
- CMake 3.8+
- GCC (g++)

Build variables:
- **GMSV_SSDK_PATH** - Path to [Valve Source SDK 2013](https://github.com/ValveSoftware/source-sdk-2013)
- **GMSV_PLATFORM** - [Optional] Set build platform (only LINUX or WINDOWS values allowed), by default platform is deteching automatically.
- **GMSV_TARGET** - [Optional] Type of target build, can be Debug or Release (default).

## Linux
First, go to root folder of gmsv_rcon2 files and configure build with follow commands (example):
- `cmake -D GMSV_SSDK_PATH=/usr/lib/ssdk-2013 .`
- `make`

## Windows
You can use Visual Studio 2019 (my version is 16.7.6) to open gmsv_rcon2 root folder, then select `x86-debug-win` configuration and press `Ctrl+Shit+B`.
Another option is to open **x64_x86 Cross Tools Command Prompt for VS 2019** and run following commands (example):
- `cmake -D GMSV_SSDK_PATH=B:\libs\ssdk2013 -A Win32 .`
- `cmake --build .`

# Updates & Issues
Module uses specific patterns for signature scanning and should work after game updates, but still better to test it before updating server.
In case of problems with newer versions or other things, feel free to open an issue.
32 changes: 32 additions & 0 deletions dependencies/GarrysMod/Lua/Interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#ifndef GARRYSMOD_LUA_INTERFACE_H
#define GARRYSMOD_LUA_INTERFACE_H

#include "Types.h"
#include "LuaBase.h"
#include "UserData.h"


#ifdef GMMODULE

struct lua_State
{
unsigned char _ignore_this_common_lua_header_[69];
GarrysMod::Lua::ILuaBase* luabase;
};

#ifdef _WIN32
#define DLL_EXPORT extern "C" __declspec( dllexport )
#else
#define DLL_EXPORT extern "C" __attribute__((visibility("default")))
#endif

#define GMOD_MODULE_OPEN() DLL_EXPORT int gmod13_open( lua_State* state )
#define GMOD_MODULE_CLOSE() DLL_EXPORT int gmod13_close( lua_State* state )

#define LUA state->luabase

#endif

#endif

Loading

0 comments on commit 551dca7

Please sign in to comment.