Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] flagid in bz_ePlayerDieEvent may be incorrect #337

Open
Zehra opened this issue Oct 16, 2023 · 3 comments
Open

[Bug] flagid in bz_ePlayerDieEvent may be incorrect #337

Zehra opened this issue Oct 16, 2023 · 3 comments

Comments

@Zehra
Copy link
Contributor

Zehra commented Oct 16, 2023

It is known that a bug occurs, as within one plug-in, the conditions required for specific flags are met, even if the players are not retaining the flags themselves.

According to one report: It seems spawning and not grabbing a flag, will cause the flagid to be incorrect.

In BZFS, the following section of code exists:

if (victim->haveFlag())   // this may not return true in the current protocol since tanks drop flags before death, when that's fixed the else wont' be needed
    {
        int flagid = victim->getFlag();
        if (flagid >= 0)
            dieEvent.flagHeldWhenKilled = flagid;
    }
    else if (victimData->lastHeldFlagID >= 0)
    {
        auto f = FlagInfo::get(victimData->lastHeldFlagID);

        if (f->flag.status != FlagOnGround) // if the last held flag was just a moment ago, they probably died with this.
            dieEvent.flagHeldWhenKilled = victimData->lastHeldFlagID;
    }

In theory it is possible for the flagid to be incorrect in the case of when another player would hold the flag, as the flag in question would be held, even if not by the same player. (The flagid is not reset at the end of the death event either.)

@Zehra
Copy link
Contributor Author

Zehra commented Oct 16, 2023

The following has been tested and reproduced with BZFlag 2.4.26

The following plug-in was for bug reproduction and documentation:
(The license for it is CC0-1.0.)

// deathFlagID.cpp

#include "bzfsAPI.h"

class deathFlagID : public bz_Plugin
{
public:
  const char* Name(){return "deathFlagID";}
  void Init (const char* commandLine) {
    Register(bz_ePlayerDieEvent);
  }
  void Event(bz_EventData *eventData ){
      switch (eventData->eventType) {
        case bz_ePlayerDieEvent: {
          bz_PlayerDieEventData_V2* deathData = (bz_PlayerDieEventData_V2*)eventData;
          bz_sendTextMessagef(BZ_SERVER,BZ_ALLUSERS, "The flagID value of flagHeldWhenKilled is: %d", deathData->flagHeldWhenKilled);
        }break;
        
        default:{ 
        }break;
      }
    }
  void Cleanup (void) {
    Flush();
  }
};

BZ_PLUGIN(deathFlagID)

As for reproduction of the bug, the following steps will reproduce it reliably under the following configuration:
bzfs -loadplugin /path/to/plugin/plugin.so -set _worldSize 200 -g -passwd 1 -mp 0,1,1,0,0,10 -c

  • Join server with two clients.(playerA and playerB.)
  • Spawn both playerA and playerB
  • Kill playerB and notice the flagID.
  • With playerB grab playerB's team flag and drop it.
  • With playerA grab playerB's team flag.
  • Kill playerB with playerA.
  • Note server message of flagID.
  • Spawn playerB again.
  • Kill playerB
  • Note server message.

The following occurred in testing and should be able to be reproduced:
On the first server message, it should be -1 for the values. But this value is not reproduced on the other events, instead the value of the team flag is given in the other messages relating to flagID.

This is despite it being held by another player and the player having been spawned and not given any flag on the other steps. The value of -1 does not occur on the events which state Note server message, even though it should.

@macsforme
Copy link
Member

I've read through this report numerous times, and will attempt to interpret/summarize it.

The API event bz_ePlayerDieEvent reports an incorrect value for flagHeldWhenKilled in certain scenarios. Because tanks drop their flags prior to death, bzfs logic relies on the value of lastHeldFlagID to determine which flag was last held along with a check that the flag status is not FlagOnGround. This logic is incorrect, as the last flag held by the player may have a status other than FlagOnGround (such as being held by another player or still in the air) when the player dies, in which case it is not the correct value for flagHeldWhenKilled.

How did I do?

@Zehra
Copy link
Contributor Author

Zehra commented Nov 2, 2023

@macsforme It's perfectly summarized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants