-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26c7155
commit 2afb6aa
Showing
35 changed files
with
2,190 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
build | ||
build | ||
temp | ||
mongo-c-driver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.associations": { | ||
"iostream": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Build | ||
|
||
Prerequisites | ||
``` | ||
cmake 3.24.3 | ||
Visual Studio 17 2022 | ||
``` | ||
|
||
# Build and compile mongo-c-driver | ||
|
||
For Windows: | ||
```powershell | ||
mkdir mongo-c-driver | ||
mkdir temp | ||
cd temp | ||
git clone https://github.com/mongodb/mongo-c-driver.git | ||
cd mongo-c-driver | ||
git checkout 1.17.1 | ||
echo "1.17.1" | tee VERSION_CURRENT | ||
mkdir cmake-build | ||
cd cmake-build | ||
cmake -DCMAKE_INSTALL_PREFIX=out -DCMAKE_PREFIX_PATH=out .. | ||
cmake --build . --config RelWithDebInfo --target install | ||
cd ../../../ | ||
cp -r ./temp/mongo-c-driver/cmake-build/out ./ | ||
mv ./out ./mongo-c-driver | ||
``` | ||
|
||
# Build gmod module | ||
|
||
For Windows | ||
```powershell | ||
mkdir build | ||
cd build | ||
$CMAKE_PREFIX_PATH = (Resolve-Path -Path ../mongo-c-driver).Path | ||
cmake -DCMAKE_GENERATOR_PLATFORM=x64 -A x64 .. | ||
cmake --build . --target ALL_BUILD --config Release | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
# The project name is rather unimportant and you can name it anything you want. | ||
# It just mustn't conflict with the module name that is defined further below. | ||
project(gmod-module-guide LANGUAGES CXX) | ||
|
||
set(CMAKE_CONFIGURATION_TYPES Release Debug) | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
# Load the gmod-module-base project that sets up headers and settings. | ||
add_subdirectory(gmod-headers/include) | ||
|
||
# The library name defined here (in this case, "testmodule") will be the name of the module. | ||
add_library(testmodule SHARED) | ||
|
||
# Add the source files required for the module. | ||
# Again, the file names don't matter and you can even add multiple files by adding more space-delimited filenames after "module.cpp". | ||
target_sources(testmodule PRIVATE module.cpp) | ||
|
||
# Actually apply the headers and settings to our module. | ||
target_link_libraries(testmodule gmod-module-base) | ||
|
||
set_gmod_suffix_prefix(testmodule) | ||
cmake_minimum_required(VERSION 3.10) | ||
project(gmod-module-base LANGUAGES CXX) | ||
|
||
set(CMAKE_CONFIGURATION_TYPES Release Debug) | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
message ("CMAKE_MODULE_PATH \"${CMAKE_MODULE_PATH}\"") | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/debug) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/release) | ||
set(CMAKE_RUNTIME_LIBRARY_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/debug) | ||
set(CMAKE_RUNTIME_LIBRARY_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/release) | ||
|
||
add_subdirectory(include) | ||
add_subdirectory(projects/Basic) | ||
add_subdirectory(projects/HelloWorld) | ||
add_subdirectory(projects/MongoDb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
``` | ||
``` | ||
mkdir build | ||
cd build | ||
cmake ../ | ||
cmake --build . | ||
``` | ||
# Mongodb lua module for Garry's Mod | ||
|
||
Originally based on https://github.com/PolEpie/gmsv_mongodb | ||
|
||
Includes: | ||
* Upgraded mongo-c-driver to 1.17.1 | ||
|
||
# Installation | ||
|
||
Copy the appropiate binary to `garrysmod\lua\bin` | ||
|
||
Fow Windows: | ||
Copy `gmsv_MongoDb_win64.dll` into `garrysmod\lua\bin` | ||
|
||
# Usage | ||
```lua | ||
require('MongoDb') | ||
local connectionString = 'mongodb+srv://<username>:<passwod>@cluster0.123456.mongodb.net' | ||
local dbClient = mongodb.Client(connectionString, 'Harvest') | ||
local database = dbClient:Database('main') | ||
local playersCollection = database:GetCollection('player-connected') | ||
|
||
gameevent.Listen( "player_connect" ) | ||
hook.Add("player_connect", "AnnounceConnection", function( data ) | ||
print( data.name .. " has connected to the server." ) | ||
playersCollection:Insert({ | ||
steamid = data.networkid, | ||
name = data.name, | ||
steamid = data.networkid, | ||
userid = data.userid, | ||
bot = data.bot, | ||
connectedAt = os.date("!%Y-%m-%dT%TZ" , os.time()) | ||
}) | ||
end) | ||
``` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
set(SOURCES | ||
GarrysMod/Lua/Interface.h | ||
GarrysMod/Lua/LuaBase.h | ||
GarrysMod/Lua/SourceCompat.h | ||
GarrysMod/Lua/Types.h | ||
GarrysMod/Lua/UserData.h) | ||
|
||
add_library(gmod-module-base INTERFACE) | ||
target_include_directories(gmod-module-base INTERFACE ./) | ||
|
||
function(set_gmod_suffix_prefix library) | ||
SET_TARGET_PROPERTIES(${library} PROPERTIES PREFIX "gmsv_") | ||
|
||
if(APPLE) | ||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") | ||
SET_TARGET_PROPERTIES(${library} PROPERTIES SUFFIX "_osx.dll") | ||
else() | ||
SET_TARGET_PROPERTIES(${library} PROPERTIES SUFFIX "_osx64.dll") | ||
endif() | ||
elseif(UNIX) | ||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") | ||
SET_TARGET_PROPERTIES(${library} PROPERTIES SUFFIX "_linux.dll") | ||
else() | ||
SET_TARGET_PROPERTIES(${library} PROPERTIES SUFFIX "_linux64.dll") | ||
endif() | ||
elseif(WIN32) | ||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") | ||
SET_TARGET_PROPERTIES(${library} PROPERTIES SUFFIX "_win32.dll") | ||
else() | ||
SET_TARGET_PROPERTIES(${library} PROPERTIES SUFFIX "_win64.dll") | ||
endif() | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,75 @@ | ||
|
||
#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 | ||
|
||
#ifndef GARRYSMOD_LUA_INTERFACE_H | ||
#define GARRYSMOD_LUA_INTERFACE_H | ||
|
||
#include "LuaBase.h" | ||
|
||
struct lua_State | ||
{ | ||
#if defined( _WIN32 ) && !defined( _M_X64 ) | ||
// Win32 | ||
unsigned char _ignore_this_common_lua_header_[48 + 22]; | ||
#elif defined( _WIN32 ) && defined( _M_X64 ) | ||
// Win64 | ||
unsigned char _ignore_this_common_lua_header_[92 + 22]; | ||
#elif defined( __linux__ ) && !defined( __x86_64__ ) | ||
// Linux32 | ||
unsigned char _ignore_this_common_lua_header_[48 + 22]; | ||
#elif defined( __linux__ ) && defined( __x86_64__ ) | ||
// Linux64 | ||
unsigned char _ignore_this_common_lua_header_[92 + 22]; | ||
#elif defined ( __APPLE__ ) && !defined( __x86_64__ ) | ||
// macOS32 | ||
unsigned char _ignore_this_common_lua_header_[48 + 22]; | ||
#elif defined ( __APPLE__ ) && defined( __x86_64__ ) | ||
// macOS64 | ||
unsigned char _ignore_this_common_lua_header_[92 + 22]; | ||
#else | ||
#error agh | ||
#endif | ||
|
||
GarrysMod::Lua::ILuaBase* luabase; | ||
}; | ||
|
||
#ifndef GMOD | ||
#ifdef _WIN32 | ||
#define DLL_EXPORT extern "C" __declspec( dllexport ) | ||
#else | ||
#define DLL_EXPORT extern "C" __attribute__((visibility("default"))) | ||
#endif | ||
|
||
#ifdef GMOD_ALLOW_DEPRECATED | ||
// Stop using this and use LUA_FUNCTION! | ||
#define LUA ( state->luabase ) | ||
|
||
#define GMOD_MODULE_OPEN() DLL_EXPORT int gmod13_open( lua_State* state ) | ||
#define GMOD_MODULE_CLOSE() DLL_EXPORT int gmod13_close( lua_State* state ) | ||
#else | ||
#define GMOD_MODULE_OPEN() \ | ||
int gmod13_open__Imp( GarrysMod::Lua::ILuaBase* LUA ); \ | ||
DLL_EXPORT int gmod13_open( lua_State* L ) \ | ||
{ \ | ||
return gmod13_open__Imp( L->luabase ); \ | ||
} \ | ||
int gmod13_open__Imp( GarrysMod::Lua::ILuaBase* LUA ) | ||
|
||
#define GMOD_MODULE_CLOSE() \ | ||
int gmod13_close__Imp( GarrysMod::Lua::ILuaBase* LUA ); \ | ||
DLL_EXPORT int gmod13_close( lua_State* L ) \ | ||
{ \ | ||
return gmod13_close__Imp( L->luabase ); \ | ||
} \ | ||
int gmod13_close__Imp( GarrysMod::Lua::ILuaBase* LUA ) | ||
|
||
#define LUA_FUNCTION( FUNC ) \ | ||
int FUNC##__Imp( GarrysMod::Lua::ILuaBase* LUA ); \ | ||
int FUNC( lua_State* L ) \ | ||
{ \ | ||
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \ | ||
LUA->SetState(L); \ | ||
return FUNC##__Imp( LUA ); \ | ||
} \ | ||
int FUNC##__Imp( GarrysMod::Lua::ILuaBase* LUA ) | ||
#endif | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.