2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-01-29 06:57:55 +03:00

rh_get_key_value/rh_set_key_value moving from misc to common

This commit is contained in:
s1lent 2017-09-25 07:27:49 +07:00
parent b06b1915eb
commit 1a9b80e168
No known key found for this signature in database
GPG Key ID: 0FE401DC73916B5C
5 changed files with 93 additions and 71 deletions

View File

@ -30,10 +30,35 @@ native set_ucmd(const ucmd, const UCmd:var, any:...);
*/ */
native any:get_ucmd(const ucmd, const UCmd:var, any:...); native any:get_ucmd(const ucmd, const UCmd:var, any:...);
/*
* Gets value for key in buffer
*
* @param pbuffer Pointer to buffer
* @param key Key string
* @param value Buffer to copy value to
* @param maxlen Maximum size of the buffer
*
* @return Number of cells written to buffer
* @error If the index is not within the range of 1 to MaxClients or
* the client is not connected, an error will be thrown.
*/
native get_key_value(const pbuffer, const key[], const value[], const maxlen);
/*
* Sets value for key in buffer
*
* @param pbuffer Pointer to buffer
* @param key Key string
* @param value Value to set
*
* @noreturn
*/
native set_key_value(const pbuffer, const key[], const value[]);
/* /*
* Sets the name of the map. * Sets the name of the map.
* *
* @param mapname New map name. * @param mapname New map name.
* *
* @noreturn * @noreturn
* *
@ -43,10 +68,10 @@ native rh_set_mapname(const mapname[]);
/* /*
* Gets the name of the map. * Gets the name of the map.
* *
* @param output Buffer to copy map name to * @param output Buffer to copy map name to
* @param len Maximum buffer size * @param len Maximum buffer size
* @param type MNT_SET will return the name of the current map * @param type MNT_SET will return the name of the current map
* MNT_TRUE will return the original map name independant of the name set with via rh_set_mapname * MNT_TRUE will return the original map name independant of the name set with via rh_set_mapname
* *
* @noreturn * @noreturn
* *
@ -64,18 +89,18 @@ native rh_reset_mapname();
/* /*
* Emits a sound from an entity from the engine. * Emits a sound from an entity from the engine.
* *
* @param entity Entity index or use 0 to emit from worldspawn at the specified position * @param entity Entity index or use 0 to emit from worldspawn at the specified position
* @param recipient Recipient index or use 0 to make all clients hear it * @param recipient Recipient index or use 0 to make all clients hear it
* @param channel Channel to emit from * @param channel Channel to emit from
* @param sample Sound file to emit * @param sample Sound file to emit
* @param vol Volume in percents * @param vol Volume in percents
* @param attn Sound attenuation * @param attn Sound attenuation
* @param flags Emit flags * @param flags Emit flags
* @param pitch Sound pitch * @param pitch Sound pitch
* @param emitFlags Additional Emit2 flags, look at the defines like SND_EMIT2_* * @param emitFlags Additional Emit2 flags, look at the defines like SND_EMIT2_*
* @param origin Specify origin and only on "param" entity worldspawn that is 0 * @param origin Specify origin and only on "param" entity worldspawn that is 0
* *
* @return true if the emission was successfull, false otherwise * @return true if the emission was successfull, false otherwise
* *
*/ */
native bool:rh_emit_sound2(const entity, const recipient, const channel, const sample[], Float:vol = VOL_NORM, Float:attn = ATTN_NORM, const flags = 0, const pitch = PITCH_NORM, emitFlags = 0, const Float:origin[3] = {0.0,0.0,0.0}); native bool:rh_emit_sound2(const entity, const recipient, const channel, const sample[], Float:vol = VOL_NORM, Float:attn = ATTN_NORM, const flags = 0, const pitch = PITCH_NORM, emitFlags = 0, const Float:origin[3] = {0.0,0.0,0.0});
@ -88,28 +113,3 @@ native bool:rh_emit_sound2(const entity, const recipient, const channel, const s
* @noreturn * @noreturn
*/ */
native rh_update_user_info(playerEntIndex); native rh_update_user_info(playerEntIndex);
/*
* Gets value for key in buffer
*
* @param pbuffer Pointer to buffer
* @param key Key string
* @param value Buffer to copy value to
* @param maxlen Maximum size of the buffer
*
* @return Number of cells written to buffer
* @error If the index is not within the range of 1 to MaxClients or
* the client is not connected, an error will be thrown.
*/
native rh_get_key_value(const pbuffer, const key[], value[], maxlen)
/*
* Sets value for key in buffer
*
* @param pbuffer Pointer to buffer
* @param key Key string
* @param value Value to set
*
* @noreturn
*/
native rh_set_key_value(const pbuffer, const key[], const value[])

View File

@ -36,6 +36,7 @@
// Key + value + 2 x slash + NULL // Key + value + 2 x slash + NULL
const int MAX_INFO_STRING = 256; const int MAX_INFO_STRING = 256;
const int MAX_KV_LEN = 127;
typedef struct client_frame_s typedef struct client_frame_s
{ {

View File

@ -111,12 +111,63 @@ cell AMX_NATIVE_CALL amx_get_viewent(AMX *amx, cell *params)
return indexOfEdictAmx(pClient->pViewEntity); return indexOfEdictAmx(pClient->pViewEntity);
} }
/*
* Gets value for key in buffer
*
* @param pbuffer Pointer to buffer
* @param key Key string
* @param value Buffer to copy value to
* @param maxlen Maximum size of the buffer
*
* @return Number of cells written to buffer
* @error If the index is not within the range of 1 to MaxClients or
* the client is not connected, an error will be thrown.
*
* native get_key_value(const pbuffer, const key[], const value[], const maxlen);
*/
cell AMX_NATIVE_CALL amx_get_key_value(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_buffer, arg_key, arg_value, arg_maxlen };
char buffer[MAX_INFO_STRING], key[MAX_KV_LEN];
Q_strlcpy(buffer, getAmxString(amx, params[arg_buffer]));
Q_strlcpy(key, getAmxString(amx, params[arg_key]));
return g_amxxapi.SetAmxString(amx, params[arg_value], g_engfuncs.pfnInfoKeyValue(buffer, key), params[arg_maxlen]);
}
/*
* Sets value for key in buffer
*
* @param pbuffer Pointer to buffer
* @param key Key string
* @param value Value to set
*
* @noreturn
*
* native set_key_value(const pbuffer, const key[], const value[]);
*/
cell AMX_NATIVE_CALL amx_set_key_value(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_buffer, arg_key, arg_value };
char buffer[MAX_INFO_STRING], key[MAX_KV_LEN], value[MAX_KV_LEN];
Q_strlcpy(buffer, getAmxString(amx, params[arg_buffer]));
Q_strlcpy(key, getAmxString(amx, params[arg_key]));
Q_strlcpy(value, getAmxString(amx, params[arg_value]));
g_engfuncs.pfnSetKeyValue(buffer, key, value);
return TRUE;
}
AMX_NATIVE_INFO Natives_Common[] = AMX_NATIVE_INFO Natives_Common[] =
{ {
{ "FClassnameIs", amx_FClassnameIs }, { "FClassnameIs", amx_FClassnameIs },
{ "GetGrenadeType", amx_GetGrenadeType }, { "GetGrenadeType", amx_GetGrenadeType },
{ "engset_view", amx_engset_view }, { "engset_view", amx_engset_view },
{ "get_viewent", amx_get_viewent }, { "get_viewent", amx_get_viewent },
{ "get_key_value", amx_get_key_value },
{ "set_key_value", amx_set_key_value },
{ nullptr, nullptr } { nullptr, nullptr }
}; };

View File

@ -2012,28 +2012,6 @@ cell AMX_NATIVE_CALL rh_update_user_info(AMX *amx, cell *params)
return TRUE; return TRUE;
} }
cell AMX_NATIVE_CALL rh_get_key_value(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_buffer, arg_key, arg_value, arg_maxlen };
char *buffer = getAmxString(amx, params[arg_buffer]);
const char *key = getAmxString(amx, params[arg_key]);
return g_amxxapi.SetAmxString(amx, params[arg_value], g_engfuncs.pfnInfoKeyValue(buffer, key), params[arg_maxlen]);
}
cell AMX_NATIVE_CALL rh_set_key_value(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_buffer, arg_key, arg_value };
char *buffer = getAmxString(amx, params[arg_buffer]);
const char *key = getAmxString(amx, params[arg_key]);
const char *value = getAmxString(amx, params[arg_value]);
g_engfuncs.pfnSetKeyValue(buffer, key, value);
return 1;
}
AMX_NATIVE_INFO Misc_Natives_RH[] = AMX_NATIVE_INFO Misc_Natives_RH[] =
{ {
{ "rh_set_mapname", rh_set_mapname }, { "rh_set_mapname", rh_set_mapname },
@ -2041,8 +2019,6 @@ AMX_NATIVE_INFO Misc_Natives_RH[] =
{ "rh_reset_mapname", rh_reset_mapname }, { "rh_reset_mapname", rh_reset_mapname },
{ "rh_emit_sound2", rh_emit_sound2 }, { "rh_emit_sound2", rh_emit_sound2 },
{ "rh_update_user_info", rh_update_user_info }, { "rh_update_user_info", rh_update_user_info },
{ "rh_get_key_value", rh_get_key_value },
{ "rh_set_key_value", rh_set_key_value },
{ nullptr, nullptr } { nullptr, nullptr }
}; };

View File

@ -1,11 +1,5 @@
#pragma once #pragma once
enum
{
MAX_KV_LEN = 127,
MAX_INFO_STRING = 256
};
enum WpnInfo enum WpnInfo
{ {
WI_ID, WI_ID,