Skip to content

Commit

Permalink
Add new natives set_netchan/get_netchan (Close rehlds#322), rh_is_ent…
Browse files Browse the repository at this point in the history
…ity_fullpacked and rh_get_realtime

Minor refactoring/cleanup
  • Loading branch information
s1lentq committed Jul 13, 2024
1 parent 439396f commit 472d279
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 73 deletions.
3 changes: 2 additions & 1 deletion reapi/extra/amxmodx/scripting/include/reapi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ enum members_tables_e
mt_csplayerweapon,
mt_gib,
mt_netadr,
mt_csentity
mt_csentity,
mt_netchan
};

#define ReAPIFunc {EngineFunc, GamedllFunc, GamedllFunc_CBaseAnimating, GamedllFunc_CBasePlayer, GamedllFunc_CSGameRules, GamedllFunc_CGrenade, GamedllFunc_CWeaponBox, ReCheckerFunc, GamedllFunc_CBasePlayerWeapon, GamedllFunc_CGib, GamedllFunc_CBaseEntity, GamedllFunc_CBotManager}
Expand Down
46 changes: 38 additions & 8 deletions reapi/extra/amxmodx/scripting/include/reapi_engine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ native set_ucmd(const ucmd, const UCmd:var, any:...);
*/
native any:get_ucmd(const ucmd, const UCmd:var, any:...);

/*
* Sets netchan data.
* Use the net_* NetChan enum
*/
native set_netchan(const index, const NetChan:var, any:...);

/*
* Returns metchan data from an client.
* Use the net_* NetChan enum
*/
native any:get_netchan(const index, const NetChan:var, any:...);

/*
* Sets a NetAdr var.
*
Expand Down Expand Up @@ -184,7 +196,7 @@ native CheckVisibilityInOrigin(const ent, Float:origin[3], CheckVisibilityType:t
/*
* Sets the name of the map.
*
* @param mapname New map name.
* @param mapname New map name.
*
* @noreturn
*/
Expand Down Expand Up @@ -228,19 +240,19 @@ native rh_reset_mapname();
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});

/*
* Forces an userinfo update.
* Forces an userinfo update
*
* @param playerEntIndex Player entity index (starts from 1)
* @param index Client index
*
* @noreturn
*/
native rh_update_user_info(playerEntIndex);
native rh_update_user_info(const index);

/*
* Kicks a client from server with message
*
* @param index Client index
* @param message Message that will be sent to client when it is deleted from server
* @param index Client index
* @param message Message that will be sent to client when it is deleted from server
*
* @noreturn
*
Expand All @@ -261,12 +273,30 @@ native rh_get_net_from(output[], len);
/*
* Returns client's netchan playing time in seconds.
*
* @param index Client index
* @param index Client index
*
* @return Netchan connection time in seconds or 0 if client index is invalid or client is not connected
* @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);

/*
* Checks if a specific entity is fully packed in a given frame for a host client.
*
* @param index Client index for whom we are checking the entity.
* @param entity Entity index to find in the table of entities for the given frame.
* @param frame Frame index where to look. Default is -1, which checks the previous frame.
* @note To check in the current frame, this native should be called at the end of the server frame.
*
* @return Returns true if the entity is fully packed and ready to be sent to all clients in the given frame, otherwise false.
*/
native bool:rh_is_entity_fullpacked(const host, const entity, const frame = -1);

/*
* Get real game time throughout the entire server lifecycle.
*
* @return Real game time
*/
native Float:rh_get_realtime();

enum MessageHook
{
Expand Down
176 changes: 152 additions & 24 deletions reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1191,96 +1191,96 @@ enum UCmd
/*
* Description: -
* Member type: short
* Get params: get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, value);
* Get params: get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, value);
*/
ucmd_lerp_msec = BEGIN_MEMBER_REGION(usercmd),

/*
* Description: -
* Member type: byte
* Get params: get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, value);
* Get params: get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, value);
*/
ucmd_msec,

/*
* Description: -
* Member type: vec3_t
* Get params: get_ucmd(const ucmd, UserCmd:var, Float:output[3]);
* Set params: set_ucmd(const ucmd, UserCmd:var, Float:dest[3]);
* Get params: get_ucmd(const ucmd, UCmd:var, Float:output[3]);
* Set params: set_ucmd(const ucmd, UCmd:var, Float:dest[3]);
*/
ucmd_viewangles,

/*
* Description: -
* Member type: float
* Get params: Float:get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, Float:value);
* Get params: Float:get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, Float:value);
*/
ucmd_forwardmove,

/*
* Description: -
* Member type: float
* Get params: Float:get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, Float:value);
* Get params: Float:get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, Float:value);
*/
ucmd_sidemove,

/*
* Description: -
* Member type: float
* Get params: Float:get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, Float:value);
* Get params: Float:get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, Float:value);
*/
ucmd_upmove,

/*
* Description: -
* Member type: byte
* Get params: get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, value);
* Get params: get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, value);
*/
ucmd_lightlevel,

/*
* Description: -
* Member type: unsigned short
* Get params: get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, value);
* Get params: get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, value);
*/
ucmd_buttons,

/*
* Description: -
* Member type: byte
* Get params: get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, value);
* Get params: get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, value);
*/
ucmd_impulse,

/*
* Description: -
* Member type: byte
* Get params: get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, value);
* Get params: get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, value);
*/
ucmd_weaponselect,

/*
* Description: -
* Member type: int
* Get params: get_ucmd(const ucmd, UserCmd:var);
* Set params: set_ucmd(const ucmd, UserCmd:var, value);
* Get params: get_ucmd(const ucmd, UCmd:var);
* Set params: set_ucmd(const ucmd, UCmd:var, value);
*/
ucmd_impact_index,

/*
* Description: -
* Member type: vec3_t
* Get params: get_ucmd(const ucmd, UserCmd:var, Float:output[3]);
* Set params: set_ucmd(const ucmd, UserCmd:var, Float:dest[3]);
* Get params: get_ucmd(const ucmd, UCmd:var, Float:output[3]);
* Set params: set_ucmd(const ucmd, UCmd:var, Float:dest[3]);
*/
ucmd_impact_position
};
Expand Down Expand Up @@ -1322,6 +1322,134 @@ enum NetAdrVars
netadr_port
};

/**
* enum NetSrc
*/
enum NetSrc
{
NS_CLIENT,
NS_SERVER,
NS_MULTICAST // xxxMO
};

/**
* enum NetChan
*/
enum NetChan
{
/*
* Description: NS_SERVER or NS_CLIENT, depending on channel
* Member type: int
* Get params: NetSrc:get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, NetSrc:value);
*/
net_sock = BEGIN_MEMBER_REGION(netchan),

/*
* Description: Address this channel is talking to
* Member type: NetAdr
* Get params: NetAdr:get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, NetAdr:value);
*/
net_remote_address,

/*
* Description: -
* Member type: int
* Get params: get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, value);
*/
net_player_slot,

/*
* Description: For timeouts. Time last message was received
* Member type: float
* Get params: Float:get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, Float:value);
*/
net_last_received,

/*
* Description: Time when channel was connected
* Member type: float
* Get params: Float:get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, Float:value);
*/
net_connect_time,

/*
* Description: Bandwidth choke. (Bytes per second)
* Member type: float
* Get params: Float:get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, Float:value);
*/
net_rate,

/*
* Description: If rh_get_realtime() > cleartime, free to send next packet.
* Member type: float
* Get params: Float:get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, Float:value);
*/
net_cleartime,

/*
* Description: A sequence number that increases with each incoming bunch of packets.
* Member type: int
* Get params: get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, value);
*/
net_incoming_sequence,

/*
* Description: The number of last outgoing message that has been ack'd.
* Member type: int
* Get params: get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, value);
*/
net_incoming_acknowledged,

/*
* Description: Single bit indicating the state of acknowledgment for the last reliable message.
* Member type: int
* Get params: get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, value);
*/
net_incoming_reliable_acknowledged,

/*
* Description: Single bit, maintained local that toggles between 0 and 1 to track the sequence of reliable messages received
* Member type: int
* Get params: get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, value);
*/
net_incoming_reliable_sequence,

/*
* Description: Message we are sending to remote
* Member type: int
* Get params: get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, value);
*/
net_outgoing_sequence,

/*
* Description: Whether the message contains reliable payload, single bit
* Member type: int
* Get params: get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, value);
*/
net_reliable_sequence,

/*
* Description: Outgoing sequence number of last send that had reliable data
* Member type: int
* Get params: get_netchan(const index, NetChan:var);
* Set params: set_netchan(const index, NetChan:var, value);
*/
net_last_reliable_sequence
};

/**
* Message argument types used with GetMessageArgType()
*/
Expand Down
Loading

0 comments on commit 472d279

Please sign in to comment.