From 6be540baa161832839b3bca312da18cf65df7b01 Mon Sep 17 00:00:00 2001 From: Franco Romaniello Date: Thu, 30 Sep 2021 15:40:27 -0300 Subject: [PATCH 1/6] Implement native rh_get_net_from --- .../scripting/include/reapi_engine.inc | 11 +++++++++ reapi/src/natives/natives_misc.cpp | 23 +++++++++++++++++++ reapi/src/reapi_utils.cpp | 18 +++++++++++++++ reapi/src/reapi_utils.h | 2 ++ 4 files changed, 54 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index 8b797c30..d84ad0d8 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -148,3 +148,14 @@ native rh_update_user_info(playerEntIndex); * */ native rh_drop_client(const index, const message[] = ""); + +/* +* - +* +* @param output Buffer to copy the ip address +* @param len Maximum buffer size +* +* @noreturn +* +*/ +native rh_get_net_from(output[], len); \ No newline at end of file diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index a52d6af5..d06a1224 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2723,6 +2723,28 @@ cell AMX_NATIVE_CALL rh_drop_client(AMX *amx, cell *params) return TRUE; } +/* +* - +* +* @param output Buffer to copy the ip address +* @param len Maximum buffer size +* +* @noreturn +* +* native rh_get_net_from(output[], len); +*/ +cell AMX_NATIVE_CALL rh_get_net_from(AMX* amx, cell* params) +{ + enum args_e { arg_count, arg_output, arg_maxlen }; + + cell *dest = getAmxAddr(amx, params[arg_output]); + char *addr = NET_AdrToString(*g_RehldsData->GetNetFrom()); + + setAmxString(dest, addr, params[arg_maxlen]); + + return TRUE; +} + AMX_NATIVE_INFO Misc_Natives_RH[] = { { "rh_set_mapname", rh_set_mapname }, @@ -2731,6 +2753,7 @@ AMX_NATIVE_INFO Misc_Natives_RH[] = { "rh_emit_sound2", rh_emit_sound2 }, { "rh_update_user_info", rh_update_user_info }, { "rh_drop_client", rh_drop_client }, + { "rh_get_net_from", rh_get_net_from }, { nullptr, nullptr } }; diff --git a/reapi/src/reapi_utils.cpp b/reapi/src/reapi_utils.cpp index 77c0693a..be6422de 100644 --- a/reapi/src/reapi_utils.cpp +++ b/reapi/src/reapi_utils.cpp @@ -240,3 +240,21 @@ const char *getATypeStr(AType type) return s_ATypes[type]; } + +char* NET_AdrToString(const netadr_t& a) +{ + static char s[64]; + + Q_memset(s, 0, sizeof(s)); + + if (a.type == NA_LOOPBACK) + Q_snprintf(s, sizeof(s), "loopback"); + else if (a.type == NA_IP) + Q_snprintf(s, sizeof(s), "%i.%i.%i.%i:%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3], ntohs(a.port)); +#ifdef _WIN32 + else // NA_IPX + Q_snprintf(s, sizeof(s), "%02x%02x%02x%02x:%02x%02x%02x%02x%02x%02x:%i", a.ipx[0], a.ipx[1], a.ipx[2], a.ipx[3], a.ipx[4], a.ipx[5], a.ipx[6], a.ipx[7], a.ipx[8], a.ipx[9], ntohs(a.port)); +#endif // _WIN32 + + return s; +} \ No newline at end of file diff --git a/reapi/src/reapi_utils.h b/reapi/src/reapi_utils.h index 86a8adfa..994864c3 100644 --- a/reapi/src/reapi_utils.h +++ b/reapi/src/reapi_utils.h @@ -59,4 +59,6 @@ void RemoveOrDropItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, GiveType typ const char *getATypeStr(AType type); +char *NET_AdrToString(const netadr_t& a); + extern void NORETURN UTIL_SysError(const char *fmt, ...); From b731c464a7e2883ca51e58aa0174097a1f8fc939 Mon Sep 17 00:00:00 2001 From: Franco Romaniello Date: Thu, 30 Sep 2021 15:43:37 -0300 Subject: [PATCH 2/6] Add ws2_32.lib --- reapi/msvc/reapi.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index 0877c6bd..9572292d 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -366,7 +366,7 @@ Windows true - %(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) reapi.def From 9eef1bb6b758e5f73601d6ea1796e106cc5f3461 Mon Sep 17 00:00:00 2001 From: Franco Romaniello Date: Fri, 1 Oct 2021 13:37:35 -0300 Subject: [PATCH 3/6] Add ws2_32.lib in release --- reapi/msvc/reapi.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index 9572292d..5fdef54e 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -420,7 +420,7 @@ true true true - %(AdditionalDependencies) + ws2_32.lib;%(AdditionalDependencies) reapi.def From 6818bda93604b5ad01676b59ab292d268b05a5b3 Mon Sep 17 00:00:00 2001 From: Franco Romaniello Date: Wed, 20 Oct 2021 20:47:17 -0300 Subject: [PATCH 4/6] newline at end of reapi_utils.cpp --- reapi/src/reapi_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reapi/src/reapi_utils.cpp b/reapi/src/reapi_utils.cpp index be6422de..77edd06a 100644 --- a/reapi/src/reapi_utils.cpp +++ b/reapi/src/reapi_utils.cpp @@ -257,4 +257,4 @@ char* NET_AdrToString(const netadr_t& a) #endif // _WIN32 return s; -} \ No newline at end of file +} From ac402f8e7b712748a3803267466dcb052bc75665 Mon Sep 17 00:00:00 2001 From: Franco Romaniello Date: Wed, 20 Oct 2021 20:47:56 -0300 Subject: [PATCH 5/6] Update reapi_utils.cpp --- reapi/src/reapi_utils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/reapi/src/reapi_utils.cpp b/reapi/src/reapi_utils.cpp index 77edd06a..2d30416e 100644 --- a/reapi/src/reapi_utils.cpp +++ b/reapi/src/reapi_utils.cpp @@ -258,3 +258,4 @@ char* NET_AdrToString(const netadr_t& a) return s; } + From 31a7e24663e969c45cf38b13cd993619a1646de1 Mon Sep 17 00:00:00 2001 From: Sergey Shorokhov Date: Sat, 23 Oct 2021 13:41:10 +0300 Subject: [PATCH 6/6] fix end of file --- reapi/extra/amxmodx/scripting/include/reapi_engine.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index d84ad0d8..52c17a5d 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -158,4 +158,4 @@ native rh_drop_client(const index, const message[] = ""); * @noreturn * */ -native rh_get_net_from(output[], len); \ No newline at end of file +native rh_get_net_from(output[], len);