2
0
mirror of https://github.com/rehlds/reapi.git synced 2024-12-28 15:45:31 +03:00

Implement rh_get_net_from() native (#221)

* Implement native rh_get_net_from

* Add ws2_32.lib

* Add ws2_32.lib in release

* newline at end of reapi_utils.cpp

* Update reapi_utils.cpp

* fix end of file

Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>
This commit is contained in:
Franco Romaniello 2021-10-23 12:43:28 +02:00 committed by GitHub
parent 3c9e583260
commit efcc3952b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 2 deletions

View File

@ -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);

View File

@ -366,7 +366,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>reapi.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
@ -420,7 +420,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>reapi.def</ModuleDefinitionFile>
</Link>
<CustomBuildStep>

View File

@ -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 }
};

View File

@ -240,3 +240,22 @@ 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;
}

View File

@ -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, ...);