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

Implement rh_get_client_connect_time() native (#259)

* Implement `rh_get_client_connect_time()` native
This commit is contained in:
Federico Matías 2023-03-31 14:44:20 -03:00 committed by GitHub
parent ac3d641406
commit 7be36cc307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

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

View File

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