Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement rh_get_client_connect_time() native #259

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2745,6 +2745,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 @@ -2755,6 +2780,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