Skip to content

Commit

Permalink
Implement rh_get_net_from() native (#221)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
francoromaniello and wopox1337 committed Oct 23, 2021
1 parent 3c9e583 commit efcc395
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
11 changes: 11 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_engine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions reapi/msvc/reapi.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
23 changes: 23 additions & 0 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 }
};
Expand Down
19 changes: 19 additions & 0 deletions reapi/src/reapi_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

2 changes: 2 additions & 0 deletions reapi/src/reapi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);

0 comments on commit efcc395

Please sign in to comment.