diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 0b3fae16e93..55342aa9b30 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -193,7 +193,7 @@ bool CStaticFunctionDefinitions::TriggerServerEvent(const char* szName, CClientE return false; } -bool CStaticFunctionDefinitions::TriggerLatentServerEvent(const char* szName, CClientEntity& CallWithEntity, CLuaArguments& Arguments, int iBandwidth, +uint CStaticFunctionDefinitions::TriggerLatentServerEvent(const char* szName, CClientEntity& CallWithEntity, CLuaArguments& Arguments, int iBandwidth, CLuaMain* pLuaMain, ushort usResourceNetId) { assert(szName); @@ -214,11 +214,11 @@ bool CStaticFunctionDefinitions::TriggerLatentServerEvent(const char* szName, CC return false; } g_pClientGame->GetLatentTransferManager()->AddSendBatchBegin(PACKET_ID_LUA_EVENT, pBitStream); - g_pClientGame->GetLatentTransferManager()->AddSend(0, pBitStream->Version(), iBandwidth, pLuaMain, usResourceNetId); + SSendHandle handle = g_pClientGame->GetLatentTransferManager()->AddSend(0, pBitStream->Version(), iBandwidth, pLuaMain, usResourceNetId); g_pClientGame->GetLatentTransferManager()->AddSendBatchEnd(); g_pNet->DeallocateNetBitStream(pBitStream); - return true; + return handle; } return false; diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index e1f05f1d108..da183c7d0a6 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -33,7 +33,7 @@ class CStaticFunctionDefinitions static bool RemoveEventHandler(CLuaMain& LuaMain, const char* szName, CClientEntity& Entity, const CLuaFunctionRef& iLuaFunction); static bool TriggerEvent(const char* szName, CClientEntity& Entity, const CLuaArguments& Arguments, bool& bWasCancelled); static bool TriggerServerEvent(const char* szName, CClientEntity& CallWithEntity, CLuaArguments& Arguments); - static bool TriggerLatentServerEvent(const char* szName, CClientEntity& CallWithEntity, CLuaArguments& Arguments, int bandwidth, CLuaMain* pLuaMain, + static uint TriggerLatentServerEvent(const char* szName, CClientEntity& CallWithEntity, CLuaArguments& Arguments, int bandwidth, CLuaMain* pLuaMain, ushort usResourceNetId); static bool CancelEvent(bool bCancel); static bool WasEventCancelled(); diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Event.cpp b/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Event.cpp index 183abe241d2..69626fab4d3 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Event.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Event.cpp @@ -323,9 +323,10 @@ int CLuaFunctionDefs::TriggerLatentServerEvent(lua_State* luaVM) } // Trigger it - if (CStaticFunctionDefinitions::TriggerLatentServerEvent(strName, *pCallWithEntity, Arguments, iBandwidth, pLuaMain, usResourceNetId)) + SSendHandle eventID = CStaticFunctionDefinitions::TriggerLatentServerEvent(strName, *pCallWithEntity, Arguments, iBandwidth, pLuaMain, usResourceNetId); + if (eventID >= 0) { - lua_pushboolean(luaVM, true); + lua_pushnumber(luaVM, eventID); return 1; } } diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index 5807a7f3edf..5495746709a 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -4697,7 +4697,10 @@ bool CGame::SendPacket(unsigned char ucPacketID, const NetServerPlayerID& player return g_pNetServer->SendPacket(ucPacketID, playerID, pBitStream, bBroadcast, packetPriority, packetReliability, packetOrdering); } else - GetLatentTransferManager()->AddSend(playerID, pBitStream->Version(), m_iLatentSendsBandwidth, m_pLatentSendsLuaMain, m_usLatentSendsResourceNetId); + { + SSendHandle handle = GetLatentTransferManager()->AddSend(playerID, pBitStream->Version(), m_iLatentSendsBandwidth, m_pLatentSendsLuaMain, m_usLatentSendsResourceNetId); + m_LastSentHandle = handle; + } return true; } diff --git a/Server/mods/deathmatch/logic/CGame.h b/Server/mods/deathmatch/logic/CGame.h index 07c4f227e65..8eff0b65317 100644 --- a/Server/mods/deathmatch/logic/CGame.h +++ b/Server/mods/deathmatch/logic/CGame.h @@ -465,6 +465,7 @@ class CGame NetServerPacketPriority packetPriority, NetServerPacketReliability packetReliability, ePacketOrdering packetOrdering = PACKET_ORDERING_DEFAULT); void SendPacketBatchEnd(); + uint32_t GetLastSentHandle() const noexcept { return m_LastSentHandle; } bool IsBulletSyncActive(); void SendSyncSettings(CPlayer* pPlayer = NULL); @@ -671,6 +672,7 @@ class CGame int m_iLatentSendsBandwidth; CLuaMain* m_pLatentSendsLuaMain; ushort m_usLatentSendsResourceNetId; + uint32_t m_LastSentHandle; CMtaVersion m_strPrevMinClientKickRequirement; CMtaVersion m_strPrevMinClientConnectRequirement; diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 52695b056fc..6b7f1a23044 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -229,7 +229,8 @@ bool CStaticFunctionDefinitions::TriggerClientEvent(const std::vector& return true; } -bool CStaticFunctionDefinitions::TriggerLatentClientEvent(const std::vector& sendList, const char* szName, CElement* pCallWithElement, +uint CStaticFunctionDefinitions::TriggerLatentClientEvent(const std::vector& sendList, const char* szName, + CElement* pCallWithElement, CLuaArguments& Arguments, int iBandwidth, CLuaMain* pLuaMain, ushort usResourceNetId) { assert(szName); @@ -246,7 +247,7 @@ bool CStaticFunctionDefinitions::TriggerLatentClientEvent(const std::vectorEnableLatentSends(false); CPerfStatEventPacketUsage::GetSingleton()->UpdateEventUsageOut(szName, sendList.size()); - return true; + return g_pGame->GetLastSentHandle(); } bool CStaticFunctionDefinitions::CancelEvent(bool bCancel, const char* szReason) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 388f38b4439..8b92d9c9ad2 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -34,8 +34,8 @@ class CStaticFunctionDefinitions static bool RemoveEventHandler(CLuaMain* pLuaMain, const char* szName, CElement* pElement, const CLuaFunctionRef& iLuaFunction); static bool TriggerEvent(const char* szName, CElement* pElement, const CLuaArguments& Arguments, bool& bWasCancelled); static bool TriggerClientEvent(const std::vector& sendList, const char* szName, CElement* pCallWithElement, CLuaArguments& Arguments); - static bool TriggerLatentClientEvent(const std::vector& sendList, const char* szName, CElement* pCallWithElement, CLuaArguments& Arguments, - int iBandwidth, CLuaMain* pLuaMain, ushort usResourceNetId); + static uint TriggerLatentClientEvent(const std::vector& sendList, const char* szName, CElement* pCallWithElement, + CLuaArguments& Arguments, int iBandwidth, CLuaMain* pLuaMain, ushort usResourceNetId); static bool CancelEvent(bool bCancel, const char* szReason); static const char* GetCancelReason(); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Event.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Event.cpp index cef47c2e4cd..3d0ece264ad 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Event.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Event.cpp @@ -310,7 +310,8 @@ int CLuaFunctionDefs::TriggerLatentClientEvent(lua_State* luaVM) markerLatentEvent.SetAndStoreString(SString("Get args (%d,%s)", sendList.size(), *strName)); // Trigger it - if (CStaticFunctionDefinitions::TriggerLatentClientEvent(sendList, strName, pCallWithElement, Arguments, iBandwidth, pLuaMain, usResourceNetId)) + uint handle = CStaticFunctionDefinitions::TriggerLatentClientEvent(sendList, strName, pCallWithElement, Arguments, iBandwidth, pLuaMain, usResourceNetId); + if (handle >= 0) { markerLatentEvent.Set("End"); @@ -318,7 +319,8 @@ int CLuaFunctionDefs::TriggerLatentClientEvent(lua_State* luaVM) if (CPerfStatDebugInfo::GetSingleton()->IsActive("TriggerLatentClientEvent")) CPerfStatDebugInfo::GetSingleton()->AddLine("TriggerLatentClientEvent", markerLatentEvent.GetString()); - lua_pushboolean(luaVM, true); + // Return the handle id + lua_pushnumber(luaVM, handle); return 1; } }