Skip to content

Commit

Permalink
Implement rh_get_client_connect_time() native (#259)
Browse files Browse the repository at this point in the history
* Implement `rh_get_client_connect_time()` native
  • Loading branch information
FEDERICOMB96 committed Mar 31, 2023
1 parent ac3d641 commit 7be36cc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_engine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ native rh_drop_client(const index, const message[] = "");
*
*/
native rh_get_net_from(output[], len);

/*
* Returns client's netchan playing time in seconds.
*
* @param index Client index
*
* @return Netchan connection time in seconds or 0 if client index is invalid or client is not connected
*/
native rh_get_client_connect_time(const index);
27 changes: 27 additions & 0 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,31 @@ cell AMX_NATIVE_CALL rh_get_net_from(AMX* amx, cell* params)
return TRUE;
}

/*
* Returns client's netchan playing time in seconds.
*
* @param index Client index
*
* @return Netchan connection time in seconds or 0 if client index is invalid or client is not connected
*
* native rh_get_client_connect_time(const index);
*/
cell AMX_NATIVE_CALL rh_get_client_connect_time(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index };

CHECK_ISPLAYER(arg_index);

client_t *pClient = clientOfIndex(params[arg_index]);
if (unlikely(pClient == nullptr || !(pClient->active | pClient->spawned | pClient->connected)))
{
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]);
return FALSE;
}

return (cell)(g_RehldsFuncs->GetRealTime() - pClient->netchan.connect_time);
}

AMX_NATIVE_INFO Misc_Natives_RH[] =
{
{ "rh_set_mapname", rh_set_mapname },
Expand All @@ -2761,6 +2786,8 @@ AMX_NATIVE_INFO Misc_Natives_RH[] =
{ "rh_drop_client", rh_drop_client },
{ "rh_get_net_from", rh_get_net_from },

{ "rh_get_client_connect_time", rh_get_client_connect_time },

{ nullptr, nullptr }
};

Expand Down

0 comments on commit 7be36cc

Please sign in to comment.