multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.36k stars 416 forks source link

Network trouble when calling warpPedIntoVehicle on resourceStart #475

Open ArranTuna opened 5 years ago

ArranTuna commented 5 years ago

This issue was created by @Jusonex

Describe the bug

The code posted below leads to a network trouble. I did not test it completely, but I guess the desync is caused as follows:

  1. The following snippet from CStaticFunctionDefinitions::CreateVehicle(server) causes the vehicle to only spawn immediately if the resource has already been started:

    // Only sync if the resource has fully started
    if ( pResource->HasStarted() )
    {
        CEntityAddPacket Packet;
        Packet.Add ( pVehicle );
        m_pPlayerManager->BroadcastOnlyJoined ( Packet );
    }
  2. warpPedIntoVehicle warps the player into the vehicle that exists on the server, but not yet on the client. This causes a desync and therefore network trouble

I think a fix would require pretty much effort (i.e. queueing), but this situation happens practically never (probably mainly for debugging purposes). Therefore I think adding the same condition (CResource::HasStarted) to warpPedIntoVehicle plus a short warning message would be the most sensible way (ofc only if nobody finds a short(er) solution).

To Reproduce

addEventHandler("onResourceStart", resourceRoot,
    function()
        local vehicle = createVehicle(411, 0, 0, 5)
        warpPedIntoVehicle(getRandomPlayer(), vehicle)
    end
)

Expected behavior No desync.

MTA Client (please complete the following information): 1.5.5-release-13192

MTA Server (please complete the following information): 1.5.5-release-13192

Additional context From https://bugs.mtasa.com/view.php?id=7855

Zangomangu commented 3 years ago

This issue just screwed me over for hours, because I thought I broke something.

Therefore I think adding the same condition (CResource::HasStarted) to warpPedIntoVehicle plus a short warning message would be the most sensible way (ofc only if nobody finds a short(er) solution).

I think this is a good solution. Nobody wants network trouble and a frozen game.

lopezloo commented 1 year ago
  1. The following snippet from CStaticFunctionDefinitions::CreateVehicle(server) causes the vehicle to only spawn immediately if the resource has already been started:

But isn't onResourceStart called after resource is fully started? If not, why not?

Zangomangu commented 1 year ago

It's not started on the client at that point. onResourceStart is called before the resource is broadcast to clients, probably because it's cancellable.

So we just need to add this check, and a warning like the issue poster suggests

if (pResource->IsClientSynced())