From ed57d7b309ed12ac89c882ec8d47d9b3f9abfbee Mon Sep 17 00:00:00 2001 From: s1lentq Date: Sat, 7 Oct 2023 21:21:32 +0700 Subject: [PATCH] SV_CheckUserInfo: Refer to 'userinfo' argument as a pointer instead of an AMX string buffer Added natives: - set_netadr/get_netaddr - set_key_value_buffer(buffer, "\\name\\ololo") overwrite a entire buffer - get_key_value_buffer(buffer, userinfo, charsmax(userinfo)) get userinfo as AMX string presentation Minor cleanup Bump minor --- .../extra/amxmodx/scripting/include/reapi.inc | 3 +- .../scripting/include/reapi_engine.inc | 42 ++++++++- .../scripting/include/reapi_engine_const.inc | 53 +++++++++-- .../scripting/include/reapi_gamedll_const.inc | 2 +- reapi/src/hook_callback.cpp | 15 ++- reapi/src/hook_callback.h | 7 +- reapi/src/hook_list.cpp | 2 +- reapi/src/member_list.cpp | 9 ++ reapi/src/member_list.h | 8 ++ reapi/src/natives/natives_common.cpp | 83 ++++++++++++++--- reapi/src/natives/natives_members.cpp | 93 +++++++++++++++++++ reapi/src/natives/natives_misc.cpp | 8 +- reapi/src/reapi_utils.cpp | 10 +- reapi/src/reapi_utils.h | 2 +- reapi/version/version.h | 2 +- 15 files changed, 298 insertions(+), 41 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 2b95782d..fdfb9c84 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -79,7 +79,8 @@ enum members_tables_e mt_rebuystruct, mt_mapinfo, mt_csplayerweapon, - mt_gib + mt_gib, + mt_netadr }; #define ReAPIFunc {EngineFunc, GamedllFunc, GamedllFunc_CBaseAnimating, GamedllFunc_CBasePlayer, GamedllFunc_CSGameRules, GamedllFunc_CGrenade, GamedllFunc_CWeaponBox, ReCheckerFunc, GamedllFunc_CBasePlayerWeapon, GamedllFunc_CGib, GamedllFunc_CBaseEntity, GamedllFunc_CBotManager} diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index a98f50b4..f3cedd0a 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -30,6 +30,24 @@ native set_ucmd(const ucmd, const UCmd:var, any:...); */ native any:get_ucmd(const ucmd, const UCmd:var, any:...); +/* +* Sets a NetAdr var. +* +* @param var The specified mvar, look at the enum NetAdrVars +* +* @return 1 on success. +*/ +native set_netadr(const adr, const NetAdrVars:var, any:...); + +/* +* Returns a NetAdr var +* +* @param var The specified mvar, look at the enum NetAdrVars +* +* @return If an integer or boolean or one byte, array or everything else is passed via the 3rd argument and more, look at the argument list for the specified mvar +*/ +native any:get_netadr(const adr, const NetAdrVars:var, any:...); + /* * Gets value for key in buffer * @@ -55,6 +73,28 @@ native get_key_value(const pbuffer, const key[], const value[], const maxlen); */ native set_key_value(const pbuffer, const key[], const value[]); +/* +* Gets an AMXX string buffer from a infobuffer pointer +* +* @param buffer Info string pointer +* @param value String to copy value to +* @param maxlen Maximum size of the output buffer +* +* @return Returns a string buffer on infobuffer pointer +*/ +native get_key_value_buffer(const pbuffer, const output[], const maxlen); + +/* +* Sets value string to entire buffer +* +* @param buffer Pointer to buffer +* @param value Value to set +* @param maxlen Maximum size of the value buffer to set, -1 means copy all characters +* +* @return 1 on success, 0 otherwise +*/ +native set_key_value_buffer(const pbuffer, const value[], const maxlen = -1); + /* * Gets the position of the bone * @@ -156,7 +196,7 @@ native rh_drop_client(const index, const message[] = ""); * @param len Maximum buffer size * * @noreturn -* +* */ native rh_get_net_from(output[], len); diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index 81c4c16b..d1b114e9 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -115,53 +115,53 @@ enum EngineFunc /* * Description: Called when a player's userinfo is being checked. - * Params: (adr, userinfo[], bool:reconnect, reconnectSlot, name[]) + * Params: (adr, buffer, bool:reconnect, reconnectSlot, name[]) * * @note Param adr is unused, guaranteed to return nothing also, don't send anything through it. * @note In order for param name work, hook needs to be registered as Post. */ RH_SV_CheckUserInfo, - + /* * Description: Called when a generic resource is being added to generic precache list. * Return type: int * Params: (const string[]) */ RH_PF_precache_generic_I, - + /* * Description: Called when a model is being added to model precache list. * Return type: int * Params: (const string[]) */ RH_PF_precache_model_I, - + /* * Description: Called when a sound is being added to sound precache list. * Return type: int * Params: (const string[]) */ RH_PF_precache_sound_I, - + /* * Description: Called when an event is being added to event precache list. * Return type: int * Params: (const string[]) */ RH_EV_Precache, - + /* * Description: Called when a resource is being added to resource list. * Params: (ResourceType_t:type, const filename[], size, flags, index) */ RH_SV_AddResource, - + /* * Description: Called when message is being printed to client console. * Params: (const string[]) */ RH_SV_ClientPrintf, - + /* * Description: Called when a command is being sent to server. * Params: (const cmd[], source, id) @@ -1268,3 +1268,40 @@ enum UCmd */ ucmd_impact_position }; + +enum NetAdrType +{ + NA_NULL = 0, + NA_LOOPBACK, + NA_BROADCAST, + NA_IP, + NA_IPX, // Deprecated: GoldSrc + NA_BROADCAST_IPX, // Deprecated: GoldSrc +}; + +enum NetAdrVars +{ + /* + * Description: - + * Member type: NetAdrType + * Get params: get_netadr(const NetAdr:adr, const NetAdrVars:var); + * Set params: set_netadr(const NetAdr:adr, const NetAdrVars:var, const value); + */ + netadr_type = BEGIN_MEMBER_REGION(netadr), + + /* + * Description: - + * Member type: unsigned char [4] + * Get params: get_netadr(const NetAdr:adr, const NetAdrVars:var, dest[], const lenght); // Also returns a iplong value + * Set params: set_netadr(const NetAdr:adr, const NetAdrVars:var, const iplong_value); // Only iplong can to set + */ + netadr_ip, + + /* + * Description: - + * Member type: unsigned short + * Get params: get_netadr(const NetAdr:adr, const NetAdrVars:var); + * Set params: set_netadr(const NetAdr:adr, const NetAdrVars:var, const value); + */ + netadr_port +}; diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 8994cfdf..a4a34e8e 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -475,7 +475,7 @@ enum GamedllFunc RG_ApplyMultiDamage, /* - * Description: Called when player buys an item from buy menu (Nightvision, Kevlar, etc.) + * Description: Called when player buys an item from buy menu (Nightvision, Kevlar, etc.) * Params: (const pPlayer, iSlot) */ RG_BuyItem, diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 36486caa..918c0550 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -150,14 +150,19 @@ bool SV_AllowPhysent(IRehldsHook_SV_AllowPhysent* chain, edict_t* check, edict_t return callForward(RH_SV_AllowPhysent, original, indexOfEdict(check), indexOfEdict(sv_player)); } -int SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name) +BOOL SV_CheckUserInfo_AMXX(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, size_t userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name) { - auto original = [chain](netadr_t *_adr, char *_userinfo, qboolean _bIsReconnecting, int _iReconnectSlot, char *_name) + auto original = [chain](netadr_t *_adr, cell _userinfo, qboolean _bIsReconnecting, int _iReconnectSlot, char *_name) { - return chain->callNext(_adr, _userinfo, _bIsReconnecting, _iReconnectSlot, _name); + return chain->callNext(_adr, (char *)_userinfo, _bIsReconnecting, _iReconnectSlot, _name); }; - return callForward(RH_SV_CheckUserInfo, original, adr, userinfo, bIsReconnecting, iReconnectSlot, name); + return callForward(RH_SV_CheckUserInfo, original, adr, userinfo, bIsReconnecting, iReconnectSlot, name); +} + +BOOL SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name) +{ + return SV_CheckUserInfo_AMXX(chain, adr, (size_t)userinfo, bIsReconnecting, iReconnectSlot, name); } int PF_precache_generic_I(IRehldsHook_PF_precache_generic_I *chain, const char *s) @@ -1614,7 +1619,7 @@ void CSGameRules_Think(IReGameHook_CSGameRules_Think *chain) callVoidForward(RG_CSGameRules_Think, original); } - + BOOL CSGameRules_TeamFull(IReGameHook_CSGameRules_TeamFull *chain, int team_id) { auto original = [chain](int _team_id) diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index cec30399..089299d6 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -338,7 +338,8 @@ void SV_ActivateServer(IRehldsHook_SV_ActivateServer *chain, int runPhysics); void Cvar_DirectSet(IRehldsHook_Cvar_DirectSet *chain, cvar_t *var, const char *value); void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl); void SV_ConnectClient(IRehldsHook_SV_ConnectClient* chain); -int SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo* chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name); +BOOL SV_CheckUserInfo(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, char *userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name); +BOOL SV_CheckUserInfo_AMXX(IRehldsHook_SV_CheckUserInfo *chain, netadr_t *adr, size_t userinfo, qboolean bIsReconnecting, int iReconnectSlot, char *name); struct SV_WriteFullClientUpdate_args_t { @@ -547,14 +548,14 @@ void ClearMultiDamage(IReGameHook_ClearMultiDamage *chain); void AddMultiDamage(IReGameHook_AddMultiDamage *chain, entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType); void ApplyMultiDamage(IReGameHook_ApplyMultiDamage *chain, entvars_t *pevInflictor, entvars_t *pevAttacker); void BuyItem(IReGameHook_BuyItem *chain, CBasePlayer *pPlayer, int iSlot); -void CSGameRules_Think(IReGameHook_CSGameRules_Think *chain); +void CSGameRules_Think(IReGameHook_CSGameRules_Think *chain); BOOL CSGameRules_TeamFull(IReGameHook_CSGameRules_TeamFull *chain, int team_id); BOOL CSGameRules_TeamStacked(IReGameHook_CSGameRules_TeamStacked *chain, int newTeam_id, int curTeam_id); void CSGameRules_PlayerGotWeapon(IReGameHook_CSGameRules_PlayerGotWeapon *chain, CBasePlayer *pPlayer, CBasePlayerItem *pWeapon); void CBotManager_OnEvent(IReGameHook_CBotManager_OnEvent *chain, GameEventType event, CBaseEntity* pEntity, CBaseEntity* pOther); void CBasePlayer_CheckTimeBasedDamage(IReGameHook_CBasePlayer_CheckTimeBasedDamage *chain, CBasePlayer *pthis); edict_t *CBasePlayer_EntSelectSpawnPoint(IReGameHook_CBasePlayer_EntSelectSpawnPoint *chain, CBasePlayer *pthis); -void CBasePlayerWeapon_ItemPostFrame(IReGameHook_CBasePlayerWeapon_ItemPostFrame *chain, CBasePlayerWeapon *pthis); +void CBasePlayerWeapon_ItemPostFrame(IReGameHook_CBasePlayerWeapon_ItemPostFrame *chain, CBasePlayerWeapon *pthis); void CBasePlayerWeapon_KickBack(IReGameHook_CBasePlayerWeapon_KickBack *chain, CBasePlayerWeapon *pthis, float up_base, float lateral_base, float up_modifier, float lateral_modifier, float up_max, float lateral_max, int direction_change); void CBasePlayerWeapon_SendWeaponAnim(IReGameHook_CBasePlayerWeapon_SendWeaponAnim *chain, CBasePlayerWeapon *pthis, int iAnim, int skiplocal); diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 6e77e20a..870c95c1 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -99,7 +99,7 @@ hook_t hooklist_engine[] = { ENG(ED_Alloc), ENG(ED_Free), ENG(Con_Printf), - ENG(SV_CheckUserInfo), + ENG(SV_CheckUserInfo, _AMXX), ENG(PF_precache_generic_I), ENG(PF_precache_model_I), ENG(PF_precache_sound_I), diff --git a/reapi/src/member_list.cpp b/reapi/src/member_list.cpp index becae619..b7777ad6 100644 --- a/reapi/src/member_list.cpp +++ b/reapi/src/member_list.cpp @@ -30,6 +30,7 @@ #define MOVEVAR_MEMBERS(mx) STRUCT_MEMBERS(movevars_t, mx, mv_##mx) #define UCMD_MEMBERS(mx) STRUCT_MEMBERS(usercmd_s, mx, ucmd_##mx) #define PMTRACE_MEMBERS(mx) STRUCT_MEMBERS(pmtrace_s, mx, pmt_##mx) +#define NETADR_MEMBERS(mx) STRUCT_MEMBERS(netadr_t, mx, netadr_##mx) #define CSPL_MEMBERS(mx) CLASS_MEMBERS(CCSPlayer, mx, mx) #define BASEITEM_MEMBERS(mx) CLASS_MEMBERS(CBasePlayerItem, mx, mx) #define BASEWPN_MEMBERS(mx) CLASS_MEMBERS_PREF(CBasePlayerWeapon, mx, m_Weapon_##mx, m_) @@ -111,6 +112,7 @@ inline MType getMemberType(MONSTERSTATE) { return MEMBER_INTEGER; } inline MType getMemberType(ArmorType) { return MEMBER_INTEGER; } inline MType getMemberType(ArmouryItemPack) { return MEMBER_INTEGER; } inline MType getMemberType(InfoMapBuyParam) { return MEMBER_INTEGER; } +inline MType getMemberType(netadrtype_t) { return MEMBER_INTEGER; } inline MType getMemberType(TraceResult) { return MEMBER_TRACERESULT; } @@ -1048,6 +1050,12 @@ member_t memberlist_gib[] = { GIB_MEMBERS(lifeTime), }; +member_t memberlist_netadr[] = { + NETADR_MEMBERS(type), + NETADR_MEMBERS(ip), + NETADR_MEMBERS(port) +}; + #ifdef __GNUC__ #pragma GCC diagnostic pop #endif // #ifdef __GNUC__ @@ -1111,6 +1119,7 @@ member_t *memberlist_t::operator[](size_t members) const CASE(mapinfo) CASE(csplayerweapon) CASE(gib) + CASE(netadr) } #undef CASE diff --git a/reapi/src/member_list.h b/reapi/src/member_list.h index 30c9908d..d54c6aad 100644 --- a/reapi/src/member_list.h +++ b/reapi/src/member_list.h @@ -83,6 +83,7 @@ struct memberlist_t mt_mapinfo, mt_csplayerweapon, mt_gib, + mt_netadr }; }; @@ -735,6 +736,13 @@ enum PMTrace pmt_hitgroup }; +enum NetAdr +{ + netadr_type = BEGIN_MEMBER_REGION(netadr), + netadr_ip, + netadr_port +}; + // CCSPlayer enum CSPlayer_Members { diff --git a/reapi/src/natives/natives_common.cpp b/reapi/src/natives/natives_common.cpp index fff90643..e36c465f 100644 --- a/reapi/src/natives/natives_common.cpp +++ b/reapi/src/natives/natives_common.cpp @@ -113,6 +113,61 @@ cell AMX_NATIVE_CALL amx_get_viewent(AMX *amx, cell *params) return indexOfEdictAmx(pClient->pViewEntity); } +/* +* Sets value string to entire buffer +* +* @param buffer Pointer to buffer +* @param value Value to set +* @param maxlen Maximum size of the value buffer to set, -1 means copy all characters +* +* @return 1 on success, 0 otherwise +* +* native set_key_value_buffer(const pbuffer, const value[], const maxlen = -1); +*/ +cell AMX_NATIVE_CALL amx_set_key_value_buffer(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_buffer, arg_value, arg_maxlen }; + + char *buffer = reinterpret_cast(params[arg_buffer]); + if (!buffer) + { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: Invalid buffer", __FUNCTION__); + return FALSE; + } + + size_t maxlen = (params[arg_maxlen] > 0) ? min(params[arg_maxlen], MAX_INFO_STRING) : MAX_INFO_STRING; + char infobuf[MAX_INFO_STRING]; + const char *value = getAmxString(amx, params[arg_value], infobuf); + size_t len = min(Q_strlen(value) + 1, maxlen); + Q_strnlcpy(buffer, value, len); + return TRUE; +} + +/* +* Gets an AMXX string buffer from a infobuffer pointer +* +* @param buffer Info string pointer +* @param value String to copy value to +* @param maxlen Maximum size of the output buffer +* +* @return Returns a string buffer on infobuffer pointer +* +* native get_key_value_buffer(const pbuffer, const output[], const maxlen); +*/ +cell AMX_NATIVE_CALL amx_get_key_value_buffer(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_buffer, arg_output, arg_maxlen }; + + char *buffer = reinterpret_cast(params[arg_buffer]); + if (!buffer) + { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: Invalid buffer", __FUNCTION__); + return FALSE; + } + + return g_amxxapi.SetAmxString(amx, params[arg_output], buffer, params[arg_maxlen]); +} + /* * Gets value for key in buffer * @@ -480,19 +535,21 @@ cell AMX_NATIVE_CALL amx_SetMoveDone(AMX *amx, cell *params) AMX_NATIVE_INFO Natives_Common[] = { - { "FClassnameIs", amx_FClassnameIs }, - { "GetGrenadeType", amx_GetGrenadeType }, - { "engset_view", amx_engset_view }, - { "get_viewent", amx_get_viewent }, - { "get_key_value", amx_get_key_value }, - { "set_key_value", amx_set_key_value }, - { "GetBonePosition", amx_GetBonePosition }, - { "GetAttachment", amx_GetAttachment }, - { "SetThink", amx_SetThink }, - { "SetTouch", amx_SetTouch }, - { "SetUse", amx_SetUse }, - { "SetBlocked", amx_SetBlocked }, - { "SetMoveDone", amx_SetMoveDone }, + { "FClassnameIs", amx_FClassnameIs }, + { "GetGrenadeType", amx_GetGrenadeType }, + { "engset_view", amx_engset_view }, + { "get_viewent", amx_get_viewent }, + { "get_key_value", amx_get_key_value }, + { "set_key_value", amx_set_key_value }, + { "get_key_value_buffer", amx_get_key_value_buffer }, + { "set_key_value_buffer", amx_set_key_value_buffer }, + { "GetBonePosition", amx_GetBonePosition }, + { "GetAttachment", amx_GetAttachment }, + { "SetThink", amx_SetThink }, + { "SetTouch", amx_SetTouch }, + { "SetUse", amx_SetUse }, + { "SetBlocked", amx_SetBlocked }, + { "SetMoveDone", amx_SetMoveDone }, { nullptr, nullptr } }; diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index a356f8a6..9c2daa12 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -667,6 +667,96 @@ cell AMX_NATIVE_CALL get_pmtrace(AMX *amx, cell *params) return get_member(tr, member, dest, element); } +/* +* Sets a NetAdr var. +* +* @param var The specified mvar, look at the enum NetAdrVars +* +* @return 1 on success. +* +* native set_netadr(const adr, const NetAdrVars:var, any:...); +*/ +cell AMX_NATIVE_CALL set_netadr(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_adr, arg_var, arg_value }; + member_t *member = memberlist[params[arg_var]]; + + if (unlikely(member == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: unknown member id %i", __FUNCTION__, params[arg_var]); + return FALSE; + } + + netadr_t *adr = (netadr_t *)params[arg_adr]; + if (unlikely(adr == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: Invalid network address", __FUNCTION__); + return FALSE; + } + + switch (params[arg_var]) + { + case netadr_type: + adr->type = (netadrtype_t)params[arg_value]; + break; + case netadr_port: + adr->port = ntohs(params[arg_value] & 0xFFFF); // cap short + break; + case netadr_ip: + *(size_t *)adr->ip = htonl(params[arg_value] & 0xFFFFFFFF); // cap int + break; + default: + return FALSE; + } + + return TRUE; +} + +/* +* Returns a NetAdr var +* +* @param var The specified mvar, look at the enum NetAdrVars +* +* @return If an integer or boolean or one byte, array or everything else is passed via the 3rd argument and more, look at the argument list for the specified mvar +* +* native any:get_netadr(const adr, const NetAdrVars:var, any:...); +*/ +cell AMX_NATIVE_CALL get_netadr(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_adr, arg_var, arg_3, arg_4 }; + member_t *member = memberlist[params[arg_var]]; + + if (unlikely(member == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: unknown member id %i", __FUNCTION__, params[arg_var]); + return FALSE; + } + + netadr_t *adr = (netadr_t *)params[arg_adr]; + if (unlikely(adr == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: Invalid network address", __FUNCTION__); + return FALSE; + } + + switch (params[arg_var]) + { + case netadr_type: return adr->type; + case netadr_port: return ntohs(adr->port); + case netadr_ip: + { + if (PARAMS_COUNT == 4) + { + cell *dest = getAmxAddr(amx, params[arg_3]); + size_t length = *getAmxAddr(amx, params[arg_4]); + setAmxString(dest, NET_AdrToString(*adr, true /*no port*/), length); + } + + return htonl(*(size_t *)adr->ip); + } + default: + break; + } + + return FALSE; +} + /* * Sets a RebuyStruct member. * @@ -757,6 +847,9 @@ AMX_NATIVE_INFO ReGameVars_Natives[] = { "set_pmtrace", set_pmtrace }, { "get_pmtrace", get_pmtrace }, + { "set_netadr", set_netadr }, + { "get_netadr", get_netadr }, + { nullptr, nullptr } }; diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index ea276784..15f85ea7 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -1010,7 +1010,7 @@ cell AMX_NATIVE_CALL rg_drop_item(AMX *amx, cell *params) char item[256]; auto pEntity = pPlayer->CSPlayer()->DropPlayerItem(getAmxString(amx, params[arg_item_name], item)); - + if (pEntity) return indexOfPDataAmx(pEntity); @@ -2230,7 +2230,7 @@ cell AMX_NATIVE_CALL rg_get_iteminfo(AMX *amx, cell *params) /** * Sets a parameter of the global CBasePlayerItem::m_ItemInfoArray array -* @note To have effect on client side (i.g. ammo size on HUD) you should +* @note To have effect on client side (i.g. ammo size on HUD) you should * alter this value BEFORE WeaponList message is sent to client, or * force it's alteration by sending again to the specific client. * Hooking WeaponList message with AMXX's register_message is a choice. @@ -2299,7 +2299,7 @@ cell AMX_NATIVE_CALL rg_get_global_iteminfo(AMX *amx, cell *params) } ItemInfo_e type = static_cast(params[arg_type]); - if ((type == ItemInfo_pszAmmo1 || type == ItemInfo_pszAmmo2 || type == ItemInfo_pszName) && PARAMS_COUNT != 4) + if ((type == ItemInfo_pszAmmo1 || type == ItemInfo_pszAmmo2 || type == ItemInfo_pszName) && PARAMS_COUNT != 4) { AMXX_LogError(amx, AMX_ERR_NATIVE, "Bad arg count. Expected %d, got %d.", 4, PARAMS_COUNT); return FALSE; @@ -2861,7 +2861,7 @@ 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()); + const char *addr = NET_AdrToString(*g_RehldsData->GetNetFrom()); setAmxString(dest, addr, params[arg_maxlen]); diff --git a/reapi/src/reapi_utils.cpp b/reapi/src/reapi_utils.cpp index 2a426447..d285b347 100644 --- a/reapi/src/reapi_utils.cpp +++ b/reapi/src/reapi_utils.cpp @@ -262,7 +262,7 @@ const char *getATypeStr(AType type) return s_ATypes[type]; } -char* NET_AdrToString(const netadr_t& a) +const char *NET_AdrToString(const netadr_t &a, bool onlyBase) { static char s[64]; @@ -270,8 +270,14 @@ char* NET_AdrToString(const netadr_t& a) 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)); + { + if (onlyBase) + Q_snprintf(s, sizeof(s), "%i.%i.%i.%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3]); + else + 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)); diff --git a/reapi/src/reapi_utils.h b/reapi/src/reapi_utils.h index 7f261457..bad3c0f0 100644 --- a/reapi/src/reapi_utils.h +++ b/reapi/src/reapi_utils.h @@ -59,6 +59,6 @@ void RemoveOrDropItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, GiveType typ const char *getATypeStr(AType type); -char *NET_AdrToString(const netadr_t& a); +const char *NET_AdrToString(const netadr_t &a, bool onlyBase = false); extern void NORETURN UTIL_SysError(const char *fmt, ...); diff --git a/reapi/version/version.h b/reapi/version/version.h index 554ac429..721f2b48 100644 --- a/reapi/version/version.h +++ b/reapi/version/version.h @@ -6,5 +6,5 @@ #pragma once #define VERSION_MAJOR 5 -#define VERSION_MINOR 23 +#define VERSION_MINOR 24 #define VERSION_MAINTENANCE 0