Exemplo n.º 1
0
void killAllHunters(std::string messagepass)
{
  bz_APIIntList *playerList = bz_newIntList();
  bz_getPlayerIndexList(playerList);


  for (unsigned int i = 0; i < playerList->size(); i++){

    bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

    if (player) {
      if (player->team != eRabbitTeam) {
	bz_killPlayer(player->playerID, true, BZ_SERVER);
	bz_sendTextMessage(BZ_SERVER, player->playerID, messagepass.c_str());
	if (rrzoneinfo.soundEnabled)
	  bz_sendPlayCustomLocalSound(player->playerID,"flag_lost");
      }
      if (player->team == eRabbitTeam &&
	  rrzoneinfo.soundEnabled &&
	  bz_getTeamCount(eHunterTeam) > 0)
	bz_sendPlayCustomLocalSound(player->playerID,"flag_won");

      bz_freePlayerRecord(player);
    }
  }

  bz_deleteIntList(playerList);

  return;
}
Exemplo n.º 2
0
void killPlayers(int safeid, std::string kothcallsign)
{
  bz_APIIntList *playerList = bz_newIntList();
  bz_getPlayerIndexList(playerList);

  for (unsigned int i = 0; i < playerList->size(); i++) {

    bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

    if (player) {

      if (player->playerID != safeid) {
	bz_killPlayer(player->playerID, true, koth.id);
	if (koth.soundEnabled)
	  bz_sendPlayCustomLocalSound(player->playerID, "flag_lost");
      } else if (koth.soundEnabled) {
	bz_sendPlayCustomLocalSound(player->playerID, "flag_won");
      }
    }

    bz_freePlayerRecord(player);
  }

  bz_deleteIntList(playerList);

  bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s IS KING OF THE HILL!", kothcallsign.c_str());

  return;
}
Exemplo n.º 3
0
bool teamClear(bz_eTeamType teamToCheck)
{
  if (teamToCheck == eRogueTeam || teamToCheck == eNoTeam || !koth.teamPlay)
    return true;

  bz_APIIntList *playerList = bz_newIntList();
  bz_getPlayerIndexList(playerList);

  bool isOut = true;

  for (unsigned int i = 0; i < playerList->size(); i++) {

    bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

    if (player) {
      if (player->team == teamToCheck && kothzone.pointIn(player->currentState.pos) && player->spawned)
	isOut = false;
    }

    bz_freePlayerRecord(player);
  }

  bz_deleteIntList(playerList);

  return isOut;
}
Exemplo n.º 4
0
void KillTeam(bz_eTeamType TeamToKill)
{
  bz_APIIntList *playerList = bz_newIntList();
  bz_getPlayerIndexList(playerList);

  for (unsigned int i = 0; i < playerList->size(); i++) {

    bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

    if (player) {

      if (player->team == TeamToKill) {
	bz_killPlayer(player->playerID, true, BZ_SERVER);
	if (tctf.soundEnabled)
	  bz_sendPlayCustomLocalSound(player->playerID, "flag_lost");
      } else if (tctf.soundEnabled) {
	bz_sendPlayCustomLocalSound(player->playerID, "flag_won");
      }
      bz_freePlayerRecord(player);
    }

  }
  bz_deleteIntList(playerList);

  return;
}
Exemplo n.º 5
0
void killTeams(bz_eTeamType safeteam, std::string keepawaycallsign)
{
	bz_APIIntList *playerList = bz_newIntList();
	bz_getPlayerIndexList ( playerList );

	for ( unsigned int i = 0; i < playerList->size(); i++ ){

		bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

			if (player){

				if (player->team != safeteam)
				{
					bz_killPlayer(player->playerID, true, BZ_SERVER);
					if (keepaway.soundEnabled)
						bz_sendPlayCustomLocalSound(player->playerID,"flag_lost");
				}
				else if (keepaway.soundEnabled)
					bz_sendPlayCustomLocalSound(player->playerID,"flag_won");
			}

		bz_freePlayerRecord(player);
	}
	bz_deleteIntList(playerList);

	bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s (%s) Kept the Flag Away!", getTeamColor(safeteam), keepawaycallsign.c_str());

	if (keepaway.flagResetEnabled)
		bz_resetFlags(true);

	return;
}
Exemplo n.º 6
0
  virtual bool SlashCommand ( int playerID, bz_ApiString /*command*/, bz_ApiString /*message*/, bz_APIStringList* /*params*/ )
  {
    bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerID);
    if (!player)
      return true;

    if ( !player->admin )
    {
      bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permission to run /killall");
      bz_freePlayerRecord(player);
      return true;
    }

    std::string msg = player->callsign.c_str();
    msg += " has killed everyone";

    bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,msg.c_str());

    bz_APIIntList *playerList = bz_newIntList();

    bz_getPlayerIndexList ( playerList );

    for ( unsigned int i = 0; i < playerList->size(); i++ )
      bz_killPlayer(playerList->get(i),false);

    bz_freePlayerRecord(player);
    bz_deleteIntList(playerList);

    return true;
  }
Exemplo n.º 7
0
inline void checkKeepAwayHolder()
{
	bz_APIIntList *playerList = bz_newIntList();
	bz_getPlayerIndexList ( playerList );

	for ( unsigned int i = 0; i < playerList->size(); i++ ){

		bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

			if (player)
			{
				const char* flagHeld = bz_getPlayerFlag(player->playerID);
				if (flagHeld)
				{
					if (flagHeld == keepaway.flagToKeep && keepaway.id == -1) // gotta a new one; initiate
					{
						initiatekeepaway(player->team, player->callsign, player->playerID);
						bz_freePlayerRecord(player);
						bz_deleteIntList(playerList);
						return;
					}
					if (flagHeld == keepaway.flagToKeep && keepaway.id == player->playerID) // someone still has it; leave
					{
						bz_freePlayerRecord(player);
						bz_deleteIntList(playerList);
						return;
					}
					if (flagHeld == keepaway.flagToKeep && keepaway.id != player->playerID) // must have stolen it
					{
						initiatekeepaway(player->team, player->callsign, player->playerID);
						bz_freePlayerRecord(player);
						bz_deleteIntList(playerList);
						return;
					}
				}
			}

		bz_freePlayerRecord(player);
	}

	keepaway.id = -1;  // no one has flag
	keepaway.team = eNoTeam;

	bz_deleteIntList(playerList);

	return;
}
Exemplo n.º 8
0
bool leagueOverSeer::isValidPlayerID(int playerID)
{
    bz_APIIntList *playerList = bz_newIntList();
    bz_getPlayerIndexList(playerList);

    for (unsigned int i = 0; i < playerList->size(); i++) //Go through all the players
    {
        if (playerList->get(i) == playerID)
        {
            bz_deleteIntList(playerList);
            return true;
        }
    }

    bz_deleteIntList(playerList);
    return false;
}
Exemplo n.º 9
0
void LogDetail::listPlayers( action act , bz_PlayerJoinPartEventData_V1 *data )
{
  bz_APIIntList *playerList = bz_newIntList();
  bz_BasePlayerRecord *player = NULL;
  std::ostringstream msg;
  char playerStatus;
  int numPlayers;

  bz_getPlayerIndexList( playerList );

  bz_debugMessage( 4 , "Players:" );
  //
  // Count number of players
  //
  numPlayers = 0;
  for ( unsigned int i = 0; i < playerList->size(); i++ ) {
    player = bz_getPlayerByIndex( playerList->get(i));
    if (player) {
      if ((player->callsign != "") && (act == join || act == auth || (data && (player->playerID != data->playerID))))
	numPlayers++;
      bz_freePlayerRecord( player );
    }
  }

  //
  // Display number of players, callsign, and motto string in the following format:
  //
  // PLAYERS (nn) [G]cc:callsign(ee:mottostring)
  // nn - number of players
  // G	- global auth identifier (+|-| |@)
  // cc - count of characters in player callsign
  // callsign - player callsign
  // ee - count of characters in motto string
  // mottostring - player motto string
  //
  // eg.
  // PLAYERS (2) [@]7:Thumper(16:[email protected]) [ ]3:xxx()
  //
  msg.str("");
  msg << "PLAYERS (" << numPlayers << ")";
  for ( unsigned int i = 0; i < playerList->size(); i++ ) {
    player = bz_getPlayerByIndex( playerList->get(i));
    if (player) {
      if ((player->callsign != "") && (act == join || act == auth || (data && (player->playerID != data->playerID)))) {
	playerStatus = ' ';
	if (player->globalUser) playerStatus = '+';
	if (player->verified) playerStatus = '+';
	if (player->admin && !bz_hasPerm(player->playerID, bz_perm_hideAdmin)) playerStatus = '@';
	msg << " [" << playerStatus << "]";
	msg << player->callsign.size() << ':';
	msg << player->callsign.c_str() << "(" << bz_getPlayerMotto(player->playerID) << ")";
      }
    }
  }
  bz_debugMessage(0, msg.str().c_str());

  bz_deleteIntList(playerList);
}
Exemplo n.º 10
0
int leagueOverSeer::isValidCallsign(std::string callsign)
{
    bz_APIIntList *playerList = bz_newIntList();
    bz_getPlayerIndexList(playerList);

    for (unsigned int i = 0; i < playerList->size(); i++) //Go through all the players
    {
        if (strcmp(bz_getPlayerByIndex(playerList->get(i))->callsign.c_str(), callsign.c_str()) == 0)
        {
            int playerID = playerList->get(i);
            bz_deleteIntList(playerList);
            return playerID;
        }
    }

    bz_deleteIntList(playerList);
    return -1;
}
Exemplo n.º 11
0
void initiatekeepaway(bz_eTeamType plyrteam, bz_ApiString plyrcallsign, int plyrID)
{
	keepaway.team = plyrteam;
	keepaway.callsign = plyrcallsign.c_str();

	if (keepaway.callsign.size() > 16)
	{
		std::string tofix = truncate(keepaway.callsign, 16);
		keepaway.callsign = tofix;
	}

	keepaway.id = plyrID;
	keepaway.startTime = bz_getCurrentTime();
	keepaway.TTHminutes = (int)(keepaway.adjustedTime/60 + 0.5);
	keepaway.TTHseconds = 30;
	keepaway.toldFlagFree = false;
	bool multipleof30 = false;

	if ((int)((keepaway.adjustedTime / 30) + 0.5) != (double)(keepaway.adjustedTime / 30))
		multipleof30 = false;
	else
		multipleof30 = true;

	if (!multipleof30)
	{
		if ((!keepaway.teamPlay || keepaway.team == eRogueTeam))
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s has %s flag; %i secs left!", keepaway.callsign.c_str(), keepaway.flagToKeep.c_str(), (int)keepaway.adjustedTime);
		else
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s (%s) has %s flag; %i secs left!", getTeamColor(keepaway.team), keepaway.callsign.c_str(), keepaway.flagToKeep.c_str(), (int)keepaway.adjustedTime);
	}

	if (keepaway.soundEnabled)
	{
		bz_APIIntList *playerList = bz_newIntList();
		bz_getPlayerIndexList ( playerList );

		for ( unsigned int i = 0; i < playerList->size(); i++ )
		{
		bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

			if (player)
			{
				if ((player->team != keepaway.team || player->team == eRogueTeam) && player->playerID != keepaway.id)
					bz_sendPlayCustomLocalSound(player->playerID,"flag_alert");
				else
					bz_sendPlayCustomLocalSound(player->playerID,"teamgrab");
			}

			bz_freePlayerRecord(player);
		}
		bz_deleteIntList(playerList);
	}

	return;
}
Exemplo n.º 12
0
	void buildStateHash(std::string &params)
	{
		int hash = sumString(mapFile);

		int i = 0;
		i += bz_getTeamScore(eRedTeam);
		i += bz_getTeamScore(eGreenTeam);
		i += bz_getTeamScore(eBlueTeam);
		i += bz_getTeamScore(ePurpleTeam);
		i += bz_getTeamWins(eRedTeam);
		i += bz_getTeamWins(eGreenTeam);
		i += bz_getTeamWins(eBlueTeam);
		i += bz_getTeamWins(ePurpleTeam);
		i += bz_getTeamLosses(eRedTeam);
		i += bz_getTeamLosses(eGreenTeam);
		i += bz_getTeamLosses(eBlueTeam);
		i += bz_getTeamLosses(ePurpleTeam);

		hash += (i * 1000);

		i = 0;
		bz_APIIntList *players = bz_newIntList();
		bz_getPlayerIndexList(players);;
		if (players && players->size())
		{
			for (unsigned int p = 0; p < players->size(); p++ )
			{
				bz_BasePlayerRecord	*player = bz_getPlayerByIndex(players->get(p));

				//int playerID = players->get(p);
				if (player)
				{
					std::string BZID = player->bzID.c_str();
					if (BZID.size())
						i += sumString(BZID);
					else
						i += sumString(std::string(player->callsign.c_str()));

					i += sumString("NONE");

					i += player->wins;
					i += player->losses;
					i += player->teamKills;

					bz_freePlayerRecord(player);
				}
			}
		}
		bz_deleteIntList(players);

		hash += (i * 100000);

		params += format("&hash=%d",hash);
	}
Exemplo n.º 13
0
bool anyPlayers ( void )
{
  bool moreThenZero = false;
  bz_APIIntList *players = bz_getPlayerIndexList();
  if ( players->size() )
    moreThenZero = true;

  bz_deleteIntList(players);

  return moreThenZero;
}
Exemplo n.º 14
0
std::string getFlag()
{
	if (keepaway.flagToKeepIndex < -1) // this should never happen, but save a crash if something goes nuts
		return "";

	// get next flag; if not free take it from player (if forced flags)

	for (unsigned int h = 0; h < keepaway.flagsList.size(); h++) // check all specified flags
	{
		keepaway.flagToKeepIndex++; // get next one in line

		if (keepaway.flagToKeepIndex > ((int)keepaway.flagsList.size() - 1)) // go back to start if at end
			keepaway.flagToKeepIndex = 0;

		std::string flagCandidate = keepaway.flagsList[keepaway.flagToKeepIndex];
		bool flagNotHeld = true;

		bz_APIIntList *playerList = bz_newIntList();
		bz_getPlayerIndexList ( playerList );

		for ( unsigned int i = 0; i < playerList->size(); i++ )
		{
		bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

			if (player)
			{
				const char* playerFlag = bz_getPlayerFlag(player->playerID);
				if (playerFlag)
				{
					if (playerFlag == flagCandidate && keepaway.forcedFlags) // take it, if forced flags
					{
						bz_removePlayerFlag (player->playerID);
						bz_sendTextMessage (BZ_SERVER, player->playerID, "Sorry, server needs your flag for Keep Away :/");
					}
					if (playerFlag == flagCandidate && !keepaway.forcedFlags) // look for next free flag in list
						flagNotHeld = false;
				}
			}
			bz_freePlayerRecord(player);
		}

		bz_deleteIntList(playerList);

		if (flagNotHeld)
			return flagCandidate;
	}

	if (!keepaway.flagsList.empty())  // we should never get here, but if we do keep going
		return keepaway.flagsList[0];
	else
		return "";
}
Exemplo n.º 15
0
void RogueGenoHandler::Event (bz_EventData *eventData)
{
    switch (eventData->eventType) {
    default:
        // no clue
        break;

    // wait for a tank death and start checking for genocide and rogues
    case bz_ePlayerDieEvent:
    {
        bz_PlayerDieEventData_V1 *dieData = (bz_PlayerDieEventData_V1*)eventData;
        //if its not a genocide kill, dont care
        if (dieData->flagKilledWith != "G")
            break;
        // if the tank killed was not a rogue, let the server/client do the normal killing
        if (dieData->team != eRogueTeam)
            break;
        // option to disallow rogues getting points for shooting themselves
        if (!allowSuicide && dieData->killerID == dieData->playerID)
            break;

        // if the tank killed was a rogue, kill all rogues.
        bz_APIIntList *playerList = bz_newIntList();

        bz_getPlayerIndexList(playerList);

        for (unsigned int i = 0; i < playerList->size(); i++) {
            int targetID = (*playerList)[i];
            bz_BasePlayerRecord *playRec = bz_getPlayerByIndex (targetID);
            if (!playRec)
                continue;

            // the sucker is a spawned rogue, kill him.  This generates another death event,
            // so if you kill another rogue with geno while you are a rogue you end up dead too.
            // and you get both messages (victim and be careful)
            if (playRec->spawned && playRec->team == eRogueTeam) {
                bz_killPlayer(targetID, false, dieData->killerID, "G");
                bz_sendTextMessage(BZ_SERVER, targetID, "You were a victim of Rogue Genocide");

                // oops, I ended up killing myself (directly or indirectly) with Genocide!
                if (targetID == dieData->killerID)
                    bz_sendTextMessage(BZ_SERVER, targetID, "You should be more careful with Genocide!");
            }

            bz_freePlayerRecord(playRec);
        }
        bz_deleteIntList(playerList);
    }
    break;
    }
}
Exemplo n.º 16
0
void playAlert()
{
	bz_APIIntList *playerList = bz_newIntList();
	bz_getPlayerIndexList ( playerList );

	for ( unsigned int i = 0; i < playerList->size(); i++ )
	{
	bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

		if (player)
			bz_sendPlayCustomLocalSound(player->playerID,"hunt_select");

		bz_freePlayerRecord(player);
	}
	bz_deleteIntList(playerList);

	return;
}
Exemplo n.º 17
0
void fairCTF::SetDropTime()
{  
  bz_APIIntList	*playerList = bz_newIntList();
  bz_getPlayerIndexList(playerList);
  bool TeamFlagIsCarried = false;

  // is any tank carrying a team flag?
  for (unsigned int i = 0; i < playerList->size(); i++)
  {
    const char *FlagHeld = bz_getPlayerFlag((*playerList)[i]);

    if (FlagHeld != NULL && (strcmp(FlagHeld, "R*") == 0 || strcmp(FlagHeld, "G*") == 0 || strcmp(FlagHeld, "B*") == 0 || strcmp(FlagHeld, "P*") == 0))
    {
      TeamFlagIsCarried = true;
      break;
    }
  }

  bz_deleteIntList(playerList);

  // announce drop delay only if some tank is carrying a team flag
  if (TeamFlagIsCarried)
  {
    if (drop_delay >= 0)
    {
      droptime = bz_getCurrentTime() + (double)drop_delay;
      if (drop_delay > 1)
      {
	bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, bz_format("Currently-held team flags will be dropped in %d seconds.", drop_delay));
      }
      else
      {
	bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Currently-held team flags will be dropped in 1 second.");
      }

    }
    else
    {
      bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Currently-held team flags will not be dropped.");
    }   
  }
}
Exemplo n.º 18
0
	void buildHTMLPlayerList ( std::string &params, int skip = -1 )
	{
		bz_APIIntList *players = bz_newIntList();
		bz_getPlayerIndexList(players);;
		if (players && players->size())
		{
			int count = (int)players->size();
			if (skip > 0)
				count--;

			params += format("&playercount=%d", count);
			int index = 0;
			for( unsigned int i = 0; i < players->size(); i++ )
			{
				int playerID = players->get(i);
				if (playerID != skip)
				{
					buildHTMLPlayer(params,playerID,index);
					index ++;
				}
			}
		}
		bz_deleteIntList(players);
	}
Exemplo n.º 19
0
void leagueOverSeer::Event(bz_EventData *eventData)
{
    switch (eventData->eventType)
    {
        case bz_eCaptureEvent: //Someone caps
        {
            bz_CTFCaptureEventData_V1 *capData = (bz_CTFCaptureEventData_V1*)eventData;

            if (officialMatch) //Only keep score if it's official
            {
                if (capData->teamCapping == teamOne) teamOnePoints++;
                else if (capData->teamCapping == teamTwo) teamTwoPoints++;
            }
        }
        break;

        case bz_eGameEndEvent: //A /gameover or a match has ended
        {
            //Clear the bool variables
            funMatch = false;
            matchStartTime = 0;
            matchParticipantsRecorded = false;

            if (doNotReportMatch && officialMatch) //The match was canceled via /gameover or /superkill and we do not want to report these matches
            {
                officialMatch = false; //Match is over
                doNotReportMatch = false; //Reset the variable for next usage
                teamOnePoints = 0;
                teamTwoPoints = 0;
                matchPlayers.clear();
                bz_debugMessage(DEBUG, "DEBUG :: League Over Seer :: Official match was not reported.");
                bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Official match was not reported.");
            }
            else if (officialMatch)
            {
                officialMatch = false; //Match is over
                time_t t = time(NULL); //Get the current time
                tm * now = gmtime(&t);
                char match_date[20];

                sprintf(match_date, "%02d-%02d-%02d %02d:%02d:%02d", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec); //Format the date to -> year-month-day hour:minute:second

                //Convert ints to std::string with std::ostringstream
                std::ostringstream teamOnePointsConversion;
                teamOnePointsConversion << (teamOnePoints);
                std::ostringstream teamTwoPointsConversion;
                teamTwoPointsConversion << (teamTwoPoints);
                std::ostringstream matchTimeConversion;
                matchTimeConversion << (matchDuration/60);

                //Keep references to values for quick reference
                std::string teamOnePointsFinal = teamOnePointsConversion.str();
                std::string teamTwoPointsFinal = teamTwoPointsConversion.str();
                std::string matchTimeFinal = matchTimeConversion.str();

                // Store match data in the logs
                bz_debugMessagef(DEBUG, "Match Data :: League Over Seer Match Report");
                bz_debugMessagef(DEBUG, "Match Data :: -----------------------------");
                bz_debugMessagef(DEBUG, "Match Data :: Match Time      : %s", match_date);
                bz_debugMessagef(DEBUG, "Match Data :: Duration        : %s", matchTimeFinal.c_str());
                bz_debugMessagef(DEBUG, "Match Data :: Team One Score  : %s", teamOnePointsFinal.c_str());
                bz_debugMessagef(DEBUG, "Match Data :: Team Two Score  : %s", teamTwoPointsFinal.c_str());

                // Start building POST data to be sent to the league website
                std::string matchToSend = "query=reportMatch";
                matchToSend += "&teamOneWins=" + std::string(bz_urlEncode(teamOnePointsFinal.c_str()));
                matchToSend += "&teamTwoWins=" + std::string(bz_urlEncode(teamTwoPointsFinal.c_str()));

                matchToSend += "&duration=" + std::string(bz_urlEncode(matchTimeFinal.c_str())) + "&matchTime=" + std::string(bz_urlEncode(match_date));

                if (rotLeague) //Only add this parameter if it's a rotational league such as Open League
                    matchToSend += "&mapPlayed=" + std::string(bz_urlEncode(map.c_str()));

                matchToSend += "&teamOnePlayers=";
                bz_debugMessagef(DEBUG, "Match Data :: Team One Players");

                for (unsigned int i = 0; i < matchPlayers.size(); i++) //Add all the red players to the match report
                {
                    if (matchPlayers.at(i).team == teamOne)
                    {
                        matchToSend += std::string(bz_urlEncode(matchPlayers.at(i).bzid.c_str())) + ",";
                        bz_debugMessagef(DEBUG, "Match Data ::  %s (%s)", matchPlayers.at(i).callsign.c_str(), matchPlayers.at(i).bzid.c_str());
                    }
                }

                matchToSend.erase(matchToSend.size() - 1);
                matchToSend += "&teamTwoPlayers=";
                bz_debugMessagef(DEBUG, "Match Data :: Team Two Players");

                for (unsigned int i = 0; i < matchPlayers.size(); i++) //Add all the red players to the match report
                {
                    if (matchPlayers.at(i).team == teamTwo)
                    {
                        matchToSend += std::string(bz_urlEncode(matchPlayers.at(i).bzid.c_str())) + ",";
                        bz_debugMessagef(DEBUG, "Match Data ::  %s (%s)", matchPlayers.at(i).callsign.c_str(), matchPlayers.at(i).bzid.c_str());
                    }
                }

                matchToSend.erase(matchToSend.size() - 1);

                bz_debugMessagef(DEBUG, "Match Data :: -----------------------------");
                bz_debugMessagef(DEBUG, "Match Data :: End of Match Report");
                bz_debugMessagef(DEBUG, "DEBUG :: League Over Seer :: Reporting match data...");
                bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Reporting match...");

                bz_addURLJob(LEAGUE_URL.c_str(), this, matchToSend.c_str()); //Send the match data to the league website

                //Clear all the structures and scores for next match
                matchPlayers.clear();
                teamOnePoints = 0;
                teamTwoPoints = 0;
            }
            else
                bz_debugMessage(DEBUG, "DEBUG :: League Over Seer :: Fun match was not reported.");
        }
        break;

        case bz_eGameStartEvent: //The countdown has started
        {
            if (officialMatch) //Don't waste memory if the match isn't official
            {
                //Set the team scores to zero just in case
                teamOnePoints = 0;
                teamTwoPoints = 0;
                matchDuration = bz_getTimeLimit();
                matchStartTime = bz_getCurrentTime();
                doNotReportMatch = false;
                matchPlayers.clear();
            }
        }
        break;

        case bz_eGetPlayerMotto: // Change the motto of a player when they join
        {
            bz_GetPlayerMottoData_V2* mottoEvent = (bz_GetPlayerMottoData_V2*)eventData;

            // Prepare the SQL query with the BZID of the player
            sqlite3_bind_text(getPlayerMotto, 1, mottoEvent->record->bzID.c_str(), -1, SQLITE_TRANSIENT);

            if (sqlite3_step(getPlayerMotto) == SQLITE_ROW) // If returns a team name, use it
                mottoEvent->motto = (const char*)sqlite3_column_text(getPlayerMotto, 0);
            else
                mottoEvent->motto = "";

            sqlite3_reset(getPlayerMotto); //Clear the prepared statement so it can be reused
        }

        case bz_ePlayerJoinEvent: //A player joins
        {
            bz_PlayerJoinPartEventData_V1 *joinData = (bz_PlayerJoinPartEventData_V1*)eventData;

            if (!joinData)
                return;

            if ((bz_isCountDownActive() || bz_isCountDownInProgress()) && officialMatch)
                bz_sendTextMessage(BZ_SERVER, joinData->playerID, "*** There is currently an official match in progress, please be respectful. ***");
            else if ((bz_isCountDownActive() || bz_isCountDownInProgress()) && funMatch)
                bz_sendTextMessage(BZ_SERVER, joinData->playerID, "*** There is currently a fun match in progress, please be respectful. ***");

            if (joinData->record->verified)
            {
                // Build the POST data for the URL job
                std::string teamMotto = "query=teamNameQuery";
                teamMotto += "&teamPlayers=" + std::string(joinData->record->bzID.c_str());

                bz_debugMessagef(DEBUG, "DEBUG :: League Over Seer :: Getting motto for %s...", joinData->record->callsign.c_str());

                bz_addURLJob(LEAGUE_URL.c_str(), this, teamMotto.c_str()); //Send the team update request to the league website
            }
        }
        break;

        case bz_eSlashCommandEvent: //Someone uses a slash command
        {
            bz_SlashCommandEventData_V1 *commandData = (bz_SlashCommandEventData_V1*)eventData;
            bz_BasePlayerRecord *playerData = bz_getPlayerByIndex(commandData->from);
            std::string command = commandData->message.c_str(); //Use std::string for quick reference

            if (strncmp("/gameover", commandData->message.c_str(), 9) == 0)
                bz_sendTextMessagef(BZ_SERVER, commandData->from, "** '/gameover' is disabled, please use /finish or /cancel instead **");
            else if (strncmp("/countdown pause", commandData->message.c_str(), 16) == 0)
                bz_sendTextMessagef(BZ_SERVER, commandData->from, "** '/countdown pause' is disabled, please use /pause instead **");
            else if (strncmp("/countdown resume", commandData->message.c_str(), 17 ) == 0)
                bz_sendTextMessagef(BZ_SERVER, commandData->from, "** '/countdown resume' is disabled, please use /resume instead **");
            else if (isdigit(atoi(commandData->message.c_str()) + 12))
                bz_sendTextMessage(BZ_SERVER, commandData->from, "** '/countdown TIME' is disabled, please use /official or /fm instead **");

            bz_freePlayerRecord(playerData);
        }
        break;

        case bz_eTickEvent: //Tick tock tick tock...
        {
            int totaltanks = bz_getTeamCount(eRogueTeam) + bz_getTeamCount(eRedTeam) + bz_getTeamCount(eGreenTeam) + bz_getTeamCount(eBlueTeam) + bz_getTeamCount(ePurpleTeam);

            if (totaltanks == 0)
            {
                //Incase a boolean gets messed up in the plugin, reset all the plugin variables when there are no players (Observers excluded)
                officialMatch = false;
                doNotReportMatch = false;
                funMatch = false;
                teamOnePoints = 0;
                teamTwoPoints = 0;

                //This should never happen but just incase the countdown is going when there are no tanks
                if (bz_isCountDownActive())
                    bz_gameOver(253, eObservers);
            }

            if (matchStartTime > 0 && matchStartTime + matchRollCall < bz_getCurrentTime() && officialMatch && !matchParticipantsRecorded)
            {
                bool invalidateRollCall = false;
                bz_APIIntList *playerList = bz_newIntList();
                bz_getPlayerIndexList(playerList);

                for (unsigned int i = 0; i < playerList->size(); i++)
                {
                    bz_BasePlayerRecord *playerRecord = bz_getPlayerByIndex(playerList->get(i));

                    if (bz_getPlayerTeam(playerList->get(i)) != eObservers) //If player is not an observer
                    {
                        playersInMatch currentPlayer;
                        currentPlayer.team = playerRecord->team; //Add team to structure
                        currentPlayer.callsign = playerRecord->callsign.c_str(); //Add team to structure
                        currentPlayer.bzid = playerRecord->bzID.c_str(); //Add bzid to structure

                        if (std::string(playerRecord->bzID.c_str()).empty())
                            invalidateRollCall = true;

                        matchPlayers.push_back(currentPlayer);
                    }

                    bz_freePlayerRecord(playerRecord);
                }

                bz_deleteIntList(playerList);

                if (invalidateRollCall && matchRollCall < matchDuration)
                {
                    bz_debugMessagef(DEBUG, "DEBUG :: League Over Seer :: Invalid player found on field at %i:%i.", (int)(matchRollCall/60), (int)(fmod(matchRollCall,60.0)));

                    matchParticipantsRecorded = false;
                    matchRollCall += 30;
                    matchPlayers.clear();
                }
                else
                    matchParticipantsRecorded = true;
            }
        }
        break;

        default:
        break;
    }
}
Exemplo n.º 20
0
void RabidRabbitEventHandler::Event(bz_EventData *eventData)
{

  if (eventData->eventType == bz_ePlayerDieEvent)
  {
    bz_PlayerDieEventData_V1 *DieData = (bz_PlayerDieEventData_V1*)eventData;

    if (rrzoneinfo.cycleOnDie && DieData->team == eRabbitTeam) {
      unsigned int i = rrzoneinfo.currentKillZone;
      if (i == (zoneList.size() - 1))
	rrzoneinfo.currentKillZone = 0;
      else
	rrzoneinfo.currentKillZone++;
    }
    return;
  }

  if ((eventData->eventType != bz_eTickEvent) || (zoneList.size() < 2))
    return;

  for (unsigned int i = 0; i < zoneList.size(); i++) {
    if (!zoneList[i].WWFired && rrzoneinfo.currentKillZone == i) {
      bz_fireWorldWep(zoneList[i].WW.c_str(),
		      zoneList[i].WWLifetime,
		      BZ_SERVER,zoneList[i].WWPosition,
		      zoneList[i].WWTilt,
		      zoneList[i].WWDirection,
		      zoneList[i].WWShotID,
		      zoneList[i].WWDT);
      zoneList[i].WWFired = true;
      zoneList[i].WWLastFired = bz_getCurrentTime();
    } else {
      if ((bz_getCurrentTime() - zoneList[i].WWLastFired) > zoneList[i].WWRepeat)
	zoneList[i].WWFired = false;
    }
  }

  bz_APIIntList *playerList = bz_newIntList();
  bz_getPlayerIndexList(playerList);

  for (unsigned int h = 0; h < playerList->size(); h++) {
    bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](h));

    if (player) {

      for (unsigned int i = 0; i < zoneList.size(); i++) {
	if (zoneList[i].pointIn(player->lastKnownState.pos) &&
	    player->spawned && player->team == eRabbitTeam &&
	    rrzoneinfo.currentKillZone != i && !rrzoneinfo.rabbitNotifiedWrongZone) {
	  bz_sendTextMessage(BZ_SERVER,player->playerID,
			     "You are not in the current Rabid Rabbit zone - try another.");
	  rrzoneinfo.rabbitNotifiedWrongZone = true;
	  rrzoneinfo.rabbitNotifiedWrongZoneNum = i;
	}

	if (!zoneList[i].pointIn(player->lastKnownState.pos) &&
	    player->spawned && player->team == eRabbitTeam &&
	    rrzoneinfo.rabbitNotifiedWrongZone &&
	    rrzoneinfo.rabbitNotifiedWrongZoneNum == i)
	  rrzoneinfo.rabbitNotifiedWrongZone = false;

	if (zoneList[i].pointIn(player->lastKnownState.pos) &&
	    player->spawned &&
	    player->team == eRabbitTeam &&
	    rrzoneinfo.currentKillZone == i &&
	    bz_getTeamCount(eHunterTeam) > 0) {
	  killAllHunters(zoneList[i].servermessage);

	  rrzoneinfo.rabbitNotifiedWrongZone = true;
	  rrzoneinfo.rabbitNotifiedWrongZoneNum = i;

	  if (i == (zoneList.size() - 1))
	    rrzoneinfo.currentKillZone = 0;
	  else
	    rrzoneinfo.currentKillZone++;

	  rrzoneinfo.rabbitNotifiedWrongZone = true;
	  rrzoneinfo.rabbitNotifiedWrongZoneNum = i;
	}

	if (zoneList[i].pointIn(player->lastKnownState.pos) &&
	    player->spawned &&
	    player->team != eRabbitTeam &&
	    zoneList[i].zonekillhunter) {
	  bz_killPlayer(player->playerID, true, BZ_SERVER);
	  bz_sendTextMessage (BZ_SERVER, player->playerID, zoneList[i].playermessage.c_str());
	}
      }
      bz_freePlayerRecord(player);
    }
  }

  bz_deleteIntList(playerList);
  return;
}
Exemplo n.º 21
0
void TeamFlagResetHandler::Event ( bz_EventData *eventData )
{
	if (eventData->eventType != bz_eTickEvent)
		return;

	if (tfr.timerOff == true)
		return;

	bz_APIIntList *playerList = bz_newIntList();
	bz_getPlayerIndexList ( playerList );

	// check to see if anyone has picked up a team flag & count players per team

	for ( unsigned int i = 0; i < playerList->size(); i++ ){

		bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i));

		if (player) {

			tfr.flagTouched = bz_getPlayerFlag(player->playerID);

			if (tfr.flagTouched){

				if (strcmp(tfr.flagTouched, "R*") == 0){
					tfr.redLastTouched = bz_getCurrentTime();
					tfr.redFlagWasHeld = true;
				}
				if (strcmp(tfr.flagTouched, "G*") == 0){
					tfr.greenLastTouched = bz_getCurrentTime();
					tfr.greenFlagWasHeld = true;
				}
				if (strcmp(tfr.flagTouched, "B*") == 0){
					tfr.blueLastTouched = bz_getCurrentTime();
					tfr.blueFlagWasHeld = true;
				}
				if (strcmp(tfr.flagTouched, "P*") == 0){
					tfr.purpleLastTouched = bz_getCurrentTime();
					tfr.purpleFlagWasHeld = true;
				}
			}

			bz_freePlayerRecord(player);
		}
	}

	bz_deleteIntList(playerList);

	// if no teamplay, no need to reset flags

	tfr.OKToReset = false;

	if (bz_getTeamCount(eRedTeam) * bz_getTeamCount(eGreenTeam) > 0)
		tfr.OKToReset = true;
	if (bz_getTeamCount(eRedTeam) * bz_getTeamCount(eBlueTeam) > 0)
		tfr.OKToReset = true;
	if (bz_getTeamCount(eRedTeam) * bz_getTeamCount(ePurpleTeam) > 0)
		tfr.OKToReset = true;
	if (bz_getTeamCount(eGreenTeam) * bz_getTeamCount(eBlueTeam) > 0)
		tfr.OKToReset = true;
	if (bz_getTeamCount(eGreenTeam) * bz_getTeamCount(ePurpleTeam) > 0)
		tfr.OKToReset = true;
	if (bz_getTeamCount(eBlueTeam) * bz_getTeamCount(ePurpleTeam) > 0)
		tfr.OKToReset = true;

	if (tfr.OKToReset == false){
		ResetFlagData();
		return;
	}

	// check if time's up on flags and reset (if they were held at least once after last reset)

	if (bz_getCurrentTime() - tfr.redLastTouched > tfr.idleTime && tfr.redFlagWasHeld){
		if (bz_getTeamCount(eRedTeam) > 0){
			resetTeamFlag ("R*");
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Red flag sat idle too long - reset by server.");
		}
		tfr.redFlagWasHeld = false;
		tfr.redLastTouched = bz_getCurrentTime();
	}

	if (bz_getCurrentTime() - tfr.greenLastTouched > tfr.idleTime && tfr.greenFlagWasHeld){
		if (bz_getTeamCount(eGreenTeam) > 0){
			resetTeamFlag ("G*");
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Green flag sat idle too long - reset by server.");
		}
		tfr.greenLastTouched = bz_getCurrentTime();
		tfr.greenFlagWasHeld = false;
	}

	if (bz_getCurrentTime() - tfr.blueLastTouched > tfr.idleTime && tfr.blueFlagWasHeld){
		if (bz_getTeamCount(eBlueTeam) > 0){
			resetTeamFlag ("B*");
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Blue flag sat idle too long - reset by server.");
		}
		tfr.blueLastTouched = bz_getCurrentTime();
		tfr.blueFlagWasHeld = false;
	}

	if (bz_getCurrentTime() - tfr.purpleLastTouched > tfr.idleTime && tfr.purpleFlagWasHeld){
		if (bz_getTeamCount(ePurpleTeam) > 0){
			resetTeamFlag ("P*");
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Purple flag sat idle too long - reset by server.");
		}
		tfr.purpleLastTouched = bz_getCurrentTime();
		tfr.purpleFlagWasHeld = false;
	}
	return;
}