diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa94d65..c6b2bd8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build +name: Build and Release on: workflow_dispatch: @@ -7,6 +7,7 @@ on: - "*" - "*/*" - "**" + tags: ['v*'] pull_request: branches: - "*" @@ -15,7 +16,7 @@ on: jobs: build-windows-release: - runs-on: windows-2019 + runs-on: windows-latest steps: - uses: actions/checkout@v3 with: @@ -23,27 +24,34 @@ jobs: submodules: recursive fetch-depth: 0 + - name: Check CMake version + run: cmake --version + - name: Setup Python uses: actions/setup-python@v2 - - name: Install CMake - uses: lukka/get-cmake@v.3.23.2 - - name: Install latest conan run: | python -m pip install --upgrade pip pip install conan + - name: Generate build files run: | mkdir build cd build - cmake -DCMAKE_BUILD_TYPE=Release .. -G "Visual Studio 16 2019" -A Win32 + cmake -DCMAKE_BUILD_TYPE=Release .. -G "Visual Studio 17 2022" -A Win32 cmake --build . --config Release + - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: sscanf-win-release - path: build/Release/sscanf.dll + name: windows-build + path: | + build/Release/sscanf.dll + sscanf2.inc + LICENSE + pawn.json + README.md build-linux-release: runs-on: ubuntu-latest @@ -57,14 +65,11 @@ jobs: - name: Install packages run: | sudo apt-get update - sudo apt-get install g++-multilib + sudo apt-get install g++-multilib cmake - name: Setup Python uses: actions/setup-python@v2 - - name: Install CMake - uses: lukka/get-cmake@v.3.23.2 - - name: Install latest conan run: | python -m pip install --upgrade pip @@ -81,13 +86,137 @@ jobs: cd build cmake --build . --config Release - - name: Rename libsscanf.so to sscanf.so + - name: Rename and upload artifacts run: | cd build mv ./libsscanf.so ./sscanf.so - + - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 + with: + name: linux-build + path: | + build/sscanf.so + sscanf2.inc + LICENSE + pawn.json + README.md + + create-release-packages: + runs-on: windows-latest + needs: [build-windows-release, build-linux-release] + + steps: + - name: Download Windows artifacts + uses: actions/download-artifact@v4 + with: + name: windows-build + path: windows-files/ + + - name: Download Linux artifacts + uses: actions/download-artifact@v4 + with: + name: linux-build + path: linux-files/ + + - name: Check files structure + run: | + echo "=== Windows files ===" + Get-ChildItem -Path "windows-files" -Recurse -Force + echo "=== Linux files ===" + Get-ChildItem -Path "linux-files" -Recurse -Force + + - name: Get version + run: | + $version = $env:GITHUB_SHA.Substring(0, 7) + echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "Version: $version" + + - name: Install 7-Zip + run: choco install 7zip -y + + - name: Create Windows package + run: | + $dllPath = "windows-files/build/Release/sscanf.dll" + if (-not (Test-Path $dllPath)) { + Write-Host "Available files:" + Get-ChildItem -Path "windows-files" -Recurse + throw "Windows sscanf.dll not found at: $dllPath" + } + + mkdir windows-package + cd windows-package + + copy "..\$dllPath" amxsscanf.dll + copy ..\windows-files\LICENSE LICENSE + copy ..\windows-files\pawn.json pawn.json + copy ..\windows-files\README.md README.md + copy ..\windows-files\sscanf2.inc .\ + + mkdir components + copy "..\$dllPath" components\sscanf.dll + + mkdir plugins + copy "..\$dllPath" plugins\sscanf.dll + + mkdir pawno + cd pawno + mkdir include + copy ..\..\windows-files\sscanf2.inc include\sscanf2.inc + cd .. + + mkdir qawno + cd qawno + mkdir include + copy ..\..\windows-files\sscanf2.inc include\sscanf2.inc + cd .. + + 7z a -tzip windows-$env:VERSION.zip * + cd .. + + - name: Create Linux package + run: | + $soPath = "linux-files/build/sscanf.so" + if (-not (Test-Path $soPath)) { + Write-Host "Available files:" + Get-ChildItem -Path "linux-files" -Recurse + throw "Linux sscanf.so not found at: $soPath" + } + + mkdir linux-package + cd linux-package + + copy "..\$soPath" amxsscanf.so + copy ..\linux-files\LICENSE LICENSE + copy ..\linux-files\pawn.json pawn.json + copy ..\linux-files\README.md README.md + copy ..\linux-files\sscanf2.inc .\ + + mkdir components + copy "..\$soPath" components\sscanf.so + + mkdir plugins + copy "..\$soPath" plugins\sscanf.so + + mkdir pawno + cd pawno + mkdir include + copy ..\..\linux-files\sscanf2.inc include\sscanf2.inc + cd .. + + mkdir qawno + cd qawno + mkdir include + copy ..\..\linux-files\sscanf2.inc include\sscanf2.inc + cd .. + + 7z a -ttar -so -an * | 7z a -si linux-$env:VERSION.tar.gz + cd .. + + - name: Upload release packages + uses: actions/upload-artifact@v4 with: - name: sscanf-linux-release - path: build/sscanf.so + name: release-packages + path: | + windows-package/*.zip + linux-package/*.gz diff --git a/.gitmodules b/.gitmodules index 3a2d837..0c7f6df 100644 --- a/.gitmodules +++ b/.gitmodules @@ -15,4 +15,4 @@ url = https://github.com/martinmoene/span-lite.git [submodule "subhook"] path = subhook - url = https://github.com/Zeex/subhook.git + url = https://github.com/devbluen/subhook.git diff --git a/README.md b/README.md index 38dc22c..6018cd0 100644 --- a/README.md +++ b/README.md @@ -3225,3 +3225,7 @@ the Initial Developer. All Rights Reserved. * `SSCANF_GetErrorSpecifier` to get the error position in failure cases. * `SSCANF_Debug` to dump a load of useful debugging information. +### Modification sscanf 2.15.1 - 02/09/2025 +* Added hook `SSCANF_SetPlayerName`. +* The letters `u`, `q`, `r` have been updated to account for the case and length of the player/bot name. It works when using `MATCH_NAME_SIMILARITY` = `-1.0` (default). + diff --git a/specifiers.cpp b/specifiers.cpp index a9d28a0..6126c2a 100644 --- a/specifiers.cpp +++ b/specifiers.cpp @@ -290,7 +290,7 @@ bool // there's no point - it's just extra work and we know it's OK. // We set the null before incrementing to ensure it's included // in the output. - SscanfWarning(2, "String buffer overflow."); + //SscanfWarning(2, "String buffer overflow."); // Removed the break - discard the rest of the string. //break; } @@ -330,7 +330,7 @@ bool ++i; if (i == length) { - SscanfWarning(2, "String buffer overflow."); + //SscanfWarning(2, "String buffer overflow."); } else if (i < length) { @@ -365,7 +365,7 @@ bool ++i; if (i == length) { - SscanfWarning(2, "String buffer overflow."); + //SscanfWarning(2, "String buffer overflow."); } else if (i < length) { @@ -448,7 +448,7 @@ bool while (val < g_iTrueMax) { size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && !strincmp(name, string, len)) + if (*conn && diff >= 0 && !strncmp(name, string, len)) { *ret = val; break; @@ -473,16 +473,16 @@ bool } break; case SSCANF_OPTIONS_NONE: - // Original. + // Original while (val < g_iTrueMax) { - size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && !strincmp(name, string, len)) + if (*conn) { - if (diff < best) + size_t name_len = strlen(name); + if (name_len == len && !strncmp(name, string, len)) { *ret = val; - best = diff; + break; } } ++conn; @@ -514,7 +514,7 @@ bool while (val < g_iTrueMax) { size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && !strincmp(name, string, len)) + if (*conn && diff >= 0 && !strncmp(name, string, len)) { if (*ret != g_iInvalid) { @@ -673,7 +673,7 @@ bool while (val < g_iTrueMax) { size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && *npc && !strincmp(name, string, len)) + if (*conn && diff >= 0 && *npc && !strncmp(name, string, len)) { *ret = val; break; @@ -701,16 +701,16 @@ bool } break; case SSCANF_OPTIONS_NONE: - // Original. + // Original while (val < g_iTrueMax) { - size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && *npc && !strincmp(name, string, len)) + if (*conn) { - if (diff < best) + size_t name_len = strlen(name); + if (name_len == len && *npc && !strncmp(name, string, len)) { *ret = val; - best = diff; + break; } } ++conn; @@ -744,7 +744,7 @@ bool while (val < g_iTrueMax) { size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && *npc && !strincmp(name, string, len)) + if (*conn && diff >= 0 && *npc && !strncmp(name, string, len)) { if (*ret != g_iInvalid) { @@ -902,7 +902,7 @@ bool while (val < g_iTrueMax) { size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && !*npc && !strincmp(name, string, len)) + if (*conn && diff >= 0 && !*npc && !strncmp(name, string, len)) { *ret = val; break; @@ -930,16 +930,16 @@ bool } break; case SSCANF_OPTIONS_NONE: - // Original. + // Original while (val < g_iTrueMax) { - size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && !*npc && !strincmp(name, string, len)) + if (*conn) { - if (diff < best) + size_t name_len = strlen(name); + if (name_len == len && !*npc && !strncmp(name, string, len)) { *ret = val; - best = diff; + break; } } ++conn; @@ -973,7 +973,7 @@ bool while (val < g_iTrueMax) { size_t diff = strlen(name) - len; - if (*conn && diff >= 0 && !*npc && !strincmp(name, string, len)) + if (*conn && diff >= 0 && !*npc && !strncmp(name, string, len)) { if (*ret != g_iInvalid) { @@ -1369,7 +1369,7 @@ int // Add a null terminator. if (i >= *length) { - SscanfWarning(2, "String buffer overflow."); + //SscanfWarning(2, "String buffer overflow."); *(*ret + *length - 1) = '\0'; } else @@ -1444,5 +1444,4 @@ int } DoL(input, ret); return GetReturnDefault(input); -} - +} \ No newline at end of file diff --git a/sscanf2.inc b/sscanf2.inc index f6ee62e..57a842e 100644 --- a/sscanf2.inc +++ b/sscanf2.inc @@ -1355,6 +1355,31 @@ forward OnCachedInit(); CHAIN_FORWARD:SSCANF_OnPlayerDisconnect(playerid, reason) = 1; #endif +/** + * sscanf + * + * Called when a player change names. + * + */ +stock SSCANF__SetPlayerName(playerid, const name[]) +{ + new + SSCANF_value = SetPlayerName(playerid, name) + ; + + if (SSCANF_value == 1 && SSCANF_gInit == 1) + { + SSCANF_Join(playerid, name, bool:IsPlayerNPC(playerid)); + } + return SSCANF_value; +} +#if defined _ALS_SetPlayerName + #undef SetPlayerName +#else + #define _ALS_SetPlayerName +#endif +#define SetPlayerName SSCANF__SetPlayerName + // Ensure that these purely internal natives can't be called from outside this // include. #define SSCANF_Init @@ -1405,7 +1430,7 @@ forward OnCachedInit(); #define EXTRN%0new%1; new%1; #if !defined string - #define string: + #define string: #endif #define player:%0;UNFORMAT__(%1) %0;UNFORMAT__(%1) @@ -2081,11 +2106,11 @@ stock SSCANF_Debug() printf(gap); printf(" | Options: |"); printf(gap); - SSCANF_PrintOption(OLD_DEFAULT_NAME); - SSCANF_PrintOption(MATCH_NAME_PARTIAL); - SSCANF_PrintOption(CELLMIN_ON_MATCHES); - SSCANF_PrintOption(SSCANF_QUIET); - SSCANF_PrintOption(OLD_DEFAULT_KUSTOM); + SSCANF_PrintOption(OLD_DEFAULT_NAME); + SSCANF_PrintOption(MATCH_NAME_PARTIAL); + SSCANF_PrintOption(CELLMIN_ON_MATCHES); + SSCANF_PrintOption(SSCANF_QUIET); + SSCANF_PrintOption(OLD_DEFAULT_KUSTOM); printf(" | SSCANF_ALPHA: 0x%02x |", SSCANF_GetOption__(SSCANF_ALPHA)); printf(" | SSCANF_COLOUR_FORMS: 0x%02x |", forms); printf(" | #RGB (0x01): %s |", forms & 0x01 ? on : off); @@ -2095,9 +2120,9 @@ stock SSCANF_Debug() printf(" | {RRGGBB} (0x10): %s |", forms & 0x10 ? on : off); printf(" | 0xRRGGBBAA (0x20): %s |", forms & 0x20 ? on : off); printf(" | RRGGBBAA (0x40): %s |", forms & 0x40 ? on : off); - //SSCANF_PrintOption(SSCANF_COLOUR_FORMS); - SSCANF_PrintOption(SSCANF_ARGB); - SSCANF_PrintOption(MATCH_NAME_FIRST); + //SSCANF_PrintOption(SSCANF_COLOUR_FORMS); + SSCANF_PrintOption(SSCANF_ARGB); + SSCANF_PrintOption(MATCH_NAME_FIRST); if (similarity < 0.0) { printf(" | MATCH_NAME_SIMILARITY: off |"); @@ -2106,9 +2131,9 @@ stock SSCANF_Debug() { printf(" | MATCH_NAME_SIMILARITY: %6.3f |", similarity); } - SSCANF_PrintOption(ERROR_CODE_IN_RET); - SSCANF_PrintOption(WARNINGS_AS_ERRORS); - SSCANF_PrintOption(ERROR_CATEGORY_ONLY); + SSCANF_PrintOption(ERROR_CODE_IN_RET); + SSCANF_PrintOption(WARNINGS_AS_ERRORS); + SSCANF_PrintOption(ERROR_CATEGORY_ONLY); printf(gap); printf(line); printf(gap); @@ -2272,7 +2297,7 @@ stock sscanf(string[], format[], {Float,_}:...) while(changepos < 16 && string[strpos] && string[strpos] != delim) { changestr[changepos++] = string[strpos++]; - } + } changestr[changepos] = '\0'; setarg(paramPos,0,_:floatstr(changestr)); } @@ -2420,4 +2445,3 @@ stock sscanf(string[], format[], {Float,_}:...) while (delim > ' '); return 0; } - diff --git a/subhook b/subhook index 83d4e1e..da73336 160000 --- a/subhook +++ b/subhook @@ -1 +1 @@ -Subproject commit 83d4e1ebef3588fae48b69a7352cc21801cb70bc +Subproject commit da733366779c3858d104ccde499752541fa5db93