diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index e104e137404..31588a8b474 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -201,7 +201,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); @@ -222,11 +222,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 0c20cbe9d6b..c0593ec1c33 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -35,7 +35,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 7bdbc0e2aad..ab47128e378 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 84deaf29b2f..e9278d5253d 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -4712,7 +4712,11 @@ 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 9d0ace7b1aa..fb3a4b75f3a 100644 --- a/Server/mods/deathmatch/logic/CGame.h +++ b/Server/mods/deathmatch/logic/CGame.h @@ -457,14 +457,15 @@ class CGame int GetSyncFPS() { return m_iSyncFPS; } void SetSyncFPS(int iSyncFPS) { m_iSyncFPS = iSyncFPS; } - void HandleBackup(); - void HandleCrashDumpEncryption(); - void EnableLatentSends(bool bEnabled, int iBandwidth = 0, CLuaMain* pLuaMain = NULL, ushort usResourceNetId = 0xFFFF); - void SendPacketBatchBegin(unsigned char ucPacketId, NetBitStreamInterface* pBitStream); - bool SendPacket(unsigned char ucPacketID, const NetServerPlayerID& playerID, NetBitStreamInterface* pBitStream, bool bBroadcast, - NetServerPacketPriority packetPriority, NetServerPacketReliability packetReliability, - ePacketOrdering packetOrdering = PACKET_ORDERING_DEFAULT); - void SendPacketBatchEnd(); + void HandleBackup(); + void HandleCrashDumpEncryption(); + void EnableLatentSends(bool bEnabled, int iBandwidth = 0, CLuaMain* pLuaMain = NULL, ushort usResourceNetId = 0xFFFF); + void SendPacketBatchBegin(unsigned char ucPacketId, NetBitStreamInterface* pBitStream); + bool SendPacket(unsigned char ucPacketID, const NetServerPlayerID& playerID, NetBitStreamInterface* pBitStream, bool bBroadcast, + 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 d0ed1f7ebc5..2936d286276 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -229,7 +229,7 @@ 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 +246,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 0b642a1714d..9831b890d67 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -34,7 +34,7 @@ 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, + 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); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Event.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Event.cpp index 6d9d55d634d..d84c31c5eca 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Event.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Event.cpp @@ -310,7 +310,9 @@ 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 +320,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; } }