Skip to content

Commit

Permalink
Plugin: Added GSCLIB_Init() fixing synchronization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Iswenzz committed Jan 27, 2023
1 parent 0c220f7 commit adc413c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16.0)
project(gsclib VERSION 1.2.0 LANGUAGES C)
project(gsclib VERSION 1.5.0 LANGUAGES C)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@
* [Math](https://github.com/Iswenzz/gsclib/blob/master/docs/math.md)

## Instructions
In order to use this library, just download the archived file down below, and extract it to the Call of Duty 4X ``plugins/gsclib`` directory.
In order to use this library, you'll need to compile the binary and place it to the CoD4 ``plugins`` directory.
Then you can simply use ``loadplugin gsclib`` in your ``server.cfg`` or as CLI arguments.

To initialize gsclib library you need to call ``GSCLIB_Init()`` at the start of your mod entry point.

```c
main()
{
GSCLIB_Init();
}
```

## Building (Linux)
_Pre-Requisites:_
1. Edit plugin_handle.h then recompile the server with an empty obj directory:
1. Edit plugin_handler.h then recompile the server with an empty obj directory:
```c
#define MAX_SCRIPTFUNCTIONS 256
```
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class gsclib(ConanFile):
name = "gsclib"
version = "1.3.0"
version = "1.5.0"
license = "LICENCE"
url = "https://github.com/Iswenzz/gsclib"
description = "gsclib acts as a standard library extension for the Call of Duty 4 scripting language."
Expand Down
11 changes: 11 additions & 0 deletions docs/system.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# System

#### ``GSCLIB_Init()``
Initialize gsclib library, this should be called at the start of your mod entry point.

```c
main()
{
GSCLIB_Init();
}
```
<hr>

#### ``System(<command>)``
Execute a system command.

Expand Down
45 changes: 20 additions & 25 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@
#include "utils/player.h"

#define FUNCTION(name, function) Plugin_ScrReplaceFunction(name, function)
#define METHOD(name, function) Plugin_ScrReplaceMethod(name, function)
#define METHOD(name, function) Plugin_ScrReplaceMethod(name, function)

/// <summary>
/// Init gsclib library.
/// </summary>
void Init()
{
Plugin_Printf("[GSCLIB] Initialize\n");

AsyncHandlerRestart();
ShutdownCriticalSections();

MySQL_Working(qfalse);
HTTP_Working(qfalse);
FTP_Working(qfalse);
CURL_Working(qfalse);
}

/// <summary>
/// Plugin initialization.
Expand All @@ -30,6 +46,9 @@ PCL int OnInit()
curl_handler.code = curl_global_init(CURL_GLOBAL_ALL);
mysql_handler.code = mysql_library_init(0, NULL, NULL);

// gsclib
FUNCTION("gsclib_init", &Init);

// data/file
FUNCTION("file_create", &GScr_FILE_Create);
FUNCTION("file_open", &GScr_FILE_Open);
Expand Down Expand Up @@ -211,30 +230,6 @@ PCL int OnInit()
return 0;
}

/// <summary>
/// Pre fast restart callback.
/// </summary>
/// <returns></returns>
PCL void OnPreFastRestart()
{
OnExitLevel();
}

/// <summary>
/// Exit level callback.
/// </summary>
/// <returns></returns>
PCL void OnExitLevel()
{
AsyncHandlerRestart();
ShutdownCriticalSections();

MySQL_Working(qfalse);
HTTP_Working(qfalse);
FTP_Working(qfalse);
CURL_Working(qfalse);
}

/// <summary>
/// Plugin shutdown.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/sys/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void GScr_EnterCriticalSection()
}
if (!section)
{
Plugin_Scr_AddBool(qfalse);
Plugin_Scr_Error(fmt("EnterCriticalSection(): section %s not found.", name));
return;
}
if (!section->locked)
Expand Down
2 changes: 1 addition & 1 deletion src/sys/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define MAXPRINTMSG 1024

#define GSCLIB_VERSION_MAJOR 1
#define GSCLIB_VERSION_MINOR 4
#define GSCLIB_VERSION_MINOR 5

/// <summary>
/// Critical section/mutex struct.
Expand Down

0 comments on commit adc413c

Please sign in to comment.