From bb19a9cbf66a30173a3180ea144791664275c9e6 Mon Sep 17 00:00:00 2001 From: Mitchell Monahan Date: Tue, 20 Dec 2016 17:16:49 -0500 Subject: [PATCH] Add OnNpcVehicleDataUpdate --- gtaserver.core/GameServer.cs | 9 ++++++ gtaserver.core/PluginAPI/Events/GameEvents.cs | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/gtaserver.core/GameServer.cs b/gtaserver.core/GameServer.cs index 3a53c5a..f53e5ba 100644 --- a/gtaserver.core/GameServer.cs +++ b/gtaserver.core/GameServer.cs @@ -441,6 +441,10 @@ private void HandleClientIncomingData(Client client, NetIncomingMessage msg) var pedPosData = Util.DeserializeBinary(msg.ReadBytes(len)); if (pedPosData != null) { + var pedPluginResult = GameEvents.PedDataUpdate(client, pedPosData); + if (!pedPluginResult.ContinueServerProc) return; + pedPosData = pedPluginResult.Data; + pedPosData.Id = client.NetConnection.RemoteUniqueIdentifier; pedPosData.Name = client.DisplayName; pedPosData.Latency = client.Latency; @@ -457,8 +461,13 @@ private void HandleClientIncomingData(Client client, NetIncomingMessage msg) { var len = msg.ReadInt32(); var vehData = Util.DeserializeBinary(msg.ReadBytes(len)); + if (vehData != null) { + var pluginVehData = GameEvents.NpcVehicleDataUpdate(client, vehData); + if (!pluginVehData.ContinueServerProc) return; + vehData = pluginVehData.Data; + vehData.Id = client.NetConnection.RemoteUniqueIdentifier; SendToAll(vehData, PacketType.NpcVehPositionData, false, client); } diff --git a/gtaserver.core/PluginAPI/Events/GameEvents.cs b/gtaserver.core/PluginAPI/Events/GameEvents.cs index 6039378..d10471c 100644 --- a/gtaserver.core/PluginAPI/Events/GameEvents.cs +++ b/gtaserver.core/PluginAPI/Events/GameEvents.cs @@ -93,5 +93,33 @@ public static PluginResponse PedDataUpdate(Client c, PedData p) } return result; } + + /// + /// Called on every NPC vehicle update/creation + /// + public static List>> OnNpcVehicleDataUpdate + = new List>>(); + /// + /// Internal method. Triggers OnNpcVehicleDataUpdate + /// + /// Client who sent the update + /// PedData object + /// A PluginResponse, with the ability to rewrite the received data. + public static PluginResponse NpcVehicleDataUpdate(Client c, VehicleData v) + { + var result = new PluginResponse() + { + ContinuePluginProc = true, + ContinueServerProc = true, + Data = v + }; + foreach (var f in OnNpcVehicleDataUpdate) + { + result = f(c, v); + if (!result.ContinuePluginProc) return result; + v = result.Data; + } + return result; + } } }