Overview
Hooks allow your plugin to intercept and modify network packets between the client and server. Each hook corresponds to a specific YSFlight network command and can be registered for both client-to-server and server-to-client traffic.Registering Hooks
Use theregister_hook() method to register a hook in your plugin’s register() method:
Method Signature
Registers a hook callback with the plugin manager.Parameters:
hook_name(str): Name of the hook to registercallback(function): Function to call when the hook is triggered
Hook Callback Signature
All hook callbacks must follow this signature:Raw packet data for this network command
The player object associated with this packet. Contains:
player.aircraft.id- Aircraft IDplayer.iff- IFF (Identify Friend or Foe) valueplayer.aircraft.last_packet- Last received flight data packetplayer.streamWriterObject- Stream writer for sending data to player
List to append packets that should be sent to the client. Add encoded packets here to send additional data.
List to append packets that should be sent to the server. Add encoded packets here to forward modified data.
Return Value
Your hook callback must return a boolean:True- Forward the original packet to its destinationFalse- Block the original packet (useful when you modify and resend it)
Available Hooks
Client to Server Hooks
These hooks intercept packets sent from the client to the server:on_login
on_login
Triggered when a player logs in.Hook name:
on_loginPacket type: FSNETCMD_LOGONon_logout
on_logout
Triggered when a player logs out.Hook name:
on_logoutPacket type: FSNETCMD_LOGOFFon_join_request
on_join_request
Triggered when a player requests to join the game.Hook name:
on_join_requestPacket type: FSNETCMD_JOINREQUESTExample use cases:- Validate player aircraft
- Enforce server rules
- Log join attempts
on_flight_data
on_flight_data
Triggered continuously when the client sends flight data updates.Hook name:
on_flight_dataPacket type: FSNETCMD_AIRPLANESTATEExample use cases:- Track player positions
- Monitor G-forces
- Implement flight restrictions
on_chat
on_chat
Triggered when a player sends a chat message.Hook name:
on_chatPacket type: FSNETCMD_TEXTMESSAGEExample use cases:- Filter profanity
- Modify messages
- Log chat activity
on_unjoin
on_unjoin
Triggered when a player leaves the aircraft.Hook name:
on_unjoinPacket type: FSNETCMD_UNJOINon_get_damage
on_get_damage
Triggered when a player receives damage.Hook name:
on_get_damagePacket type: FSNETCMD_GETDAMAGEon_missile_launch
on_missile_launch
Triggered when a player launches a missile.Hook name:
on_missile_launchPacket type: FSNETCMD_MISSILELAUNCHon_weapon_config
on_weapon_config
Triggered when weapon configuration changes.Hook name:
on_weapon_configPacket type: FSNETCMD_WEAPONCONFIGon_air_cmd
on_air_cmd
Triggered for air commands.Hook name:
on_air_cmdPacket type: FSNETCMD_AIRCMDon_lockon
on_lockon
Triggered when a player locks onto a target.Hook name:
on_lockonPacket type: FSNETCMD_LOCKONon_smoke_color
on_smoke_color
Triggered when smoke color is changed.Hook name:
on_smoke_colorPacket type: FSNETCMD_SMOKECOLOROther Client Hooks
Other Client Hooks
Additional client-to-server hooks:
on_error- Error packetson_load_field- Field loadingon_add_object- Object additionon_readback- Readback packetson_join_approval- Join approvalon_reject_join_request- Join rejectionon_remove_airplane- Airplane removalon_request_test_airplane- Test airplane requeston_kill_server- Server kill requeston_prepare_simulation- Simulation preparationon_test_packet- Test packetson_remove_ground- Ground object removalon_environment- Environment settingson_sky_color- Sky color changeson_fog_color- Fog color changeson_list- List requests
Server to Client Hooks
These hooks intercept packets sent from the server to the client. Add_server suffix to any client hook name:
on_login_serveron_logout_serveron_join_request_serveron_flight_data_serveron_chat_serveron_unjoin_serveron_get_damage_server- And all other hooks with
_serversuffix
Server hooks are useful for modifying data before it reaches the client, such as implementing radar systems that hide enemy positions.
Common Patterns
Modifying Packets
To modify a packet, decode it, modify the data, encode a new packet, and returnFalse: