示例#1
0
void observerChat::Event ( bz_EventData *eventData )
{
  switch (eventData->eventType)
  {
  case bz_eRawChatMessageEvent:
    {
      bz_ChatEventData_V1 *data = (bz_ChatEventData_V1*)eventData;
      int from = data->from;
      bool isObserver = bz_getPlayerTeam(from) == eObservers;
      bool canSpawn = bz_hasPerm(from,bz_perm_spawn);
      const char* duringTheGame = "";

      if (!isObserver && canSpawn) return;
      if (data->to != BZ_ALLUSERS && (isObserver || data->team == eNoTeam)) return;
      if (bz_hasPerm(from,permName) || bz_getAdmin(from)) return;

      std::string variableValue = makelower(bz_getBZDBString(variableName).c_str());
      if (variableValue == "off" || variableValue == "disable" || variableValue == "disabled" || variableValue == "no") return;
      else if (!(variableValue == "on" || variableValue == "always" || variableValue == "alwayson" || variableValue == "enable" || variableValue == "enabled" || variableValue == "yes")) {
        if (!bz_isCountDownActive()) return;
        duringTheGame = " during the game";
      }

      bz_sendTextMessagef(BZ_SERVER,from,"You are not allowed to send global messages%s.",duringTheGame);
      bz_sendTextMessagef(BZ_SERVER,from,"Please use observer chat only.");
      data->message = "";
    }
    break;
  default:
    break;
  }
}
示例#2
0
void sendWarnings(const char *teamcolor, std::string playercallsign, double kothstartedtime)
{
  double TimeElapsed = bz_getCurrentTime() - kothstartedtime;
  double TimeRemaining = koth.adjustedTime - TimeElapsed;
  int toTens = int ((TimeRemaining + 5) / 10) * 10;

  if ((TimeRemaining / 60) < koth.TTHminutes && koth.adjustedTime > 59) {
    if (!koth.teamPlay || koth.team == eRogueTeam)
      bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s will be King in %i secs!", playercallsign.c_str(), toTens);
    else
      bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s (%s) will be King in %i secs!", teamcolor, playercallsign.c_str(), toTens);

    koth.TTHminutes--;
  }

  if (koth.adjustedTime < koth.TTHseconds) {
    koth.TTHseconds = koth.TTHseconds - 10;
    return;
  }

  if (TimeRemaining < koth.TTHseconds) {
    if (!koth.teamPlay || koth.team == eRogueTeam)
      bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s will be King in %i secs!", playercallsign.c_str(), koth.TTHseconds);
    else
      bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s (%s) will be King in %i secs!", teamcolor, playercallsign.c_str(),
			  koth.TTHseconds);

    koth.TTHseconds = koth.TTHseconds - 10;
  }
  return;
}
示例#3
0
void sendWarnings(const char* teamcolor, std::string playercallsign, double keepawaystartedtime)
{
	double TimeElapsed = bz_getCurrentTime() - keepawaystartedtime;
	double TimeRemaining = keepaway.adjustedTime - TimeElapsed;
	int toTens = int((TimeRemaining + 5) / 10) * 10;

	if ((TimeRemaining/60) < keepaway.TTHminutes && keepaway.adjustedTime > 59 && TimeRemaining >= 1)
	{
		if (!keepaway.teamPlay || keepaway.team == eRogueTeam)
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s has %s flag; %i secs left!", playercallsign.c_str(), keepaway.flagToKeep.c_str(), toTens);
		else
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s (%s) has %s flag; %i secs left!", teamcolor, playercallsign.c_str(), keepaway.flagToKeep.c_str(), toTens);

		keepaway.TTHminutes--;
	}

	if (keepaway.adjustedTime < keepaway.TTHseconds)
	{
		keepaway.TTHseconds = keepaway.TTHseconds - 10;
		return;
	}

	if (TimeRemaining < keepaway.TTHseconds && TimeRemaining >= 1)
	{
		if (!keepaway.teamPlay || keepaway.team == eRogueTeam)
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s has %s flag; %i secs left!", playercallsign.c_str(), keepaway.flagToKeep.c_str(), keepaway.TTHseconds);
		else
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s (%s) has %s flag; %i secs left!", teamcolor, playercallsign.c_str(), keepaway.flagToKeep.c_str(), keepaway.TTHseconds);

		keepaway.TTHseconds = keepaway.TTHseconds - 10;
	}
	return;
}
    virtual void done ( const char* /*URL*/, void * data, unsigned int size, bool complete )
    {
        char *str = (char*)malloc(size+1);
        int k1=0;
        memcpy(str,data,size);
        str[size] = 0;

        page += str;
        free(str);
        if (!complete)
            return;
        std::vector<std::string> tokens = TextUtils::tokenize(page,std::string("\n"),0,false);
        page="";


        if (tokens[0]==std::string("firstdeclare")) {
            k1=2;
            if (tokens[1]!=std::string("NOTEAM"))  {
                k1=3;
                isofficialrequested=true;
                TeamA=tokens[2];
            }
        }

        if (tokens[0]==std::string("challenger")) {
            k1=2;
            if (tokens[1]!=std::string("NOTEAM"))  {
                k1=6;
                if ( tokens[4] == tokens[5] ) {
                    k1=10;
                    bz_sendTextMessagef(BZ_SERVER,BZ_ALLUSERS,"%s is not allowed to play an official match versus itself !",tokens[4].c_str());
                } else {
                    official=true;
                    TeamA=tokens[4];
                    TeamB=tokens[5];
                    std::vector<std::string> teamAplayers = TextUtils::tokenize(tokens[2],std::string("\t"),0,false);
                    std::vector<std::string> teamBplayers = TextUtils::tokenize(tokens[3],std::string("\t"),0,false);
                    MapPlayersData.clear();
                    for (int k=0;k<teamAplayers.size();k++) MapPlayersData.insert ( std::pair<std::string,trackplayer>(tolower(teamAplayers[k]),true) );
                    for (int k=0;k<teamBplayers.size();k++) MapPlayersData.insert ( std::pair<std::string,trackplayer>(tolower(teamBplayers[k]),false) );

                }
            }
        }


        if (tokens[0]==std::string("entermatch")) {
            k1=1;
        }

        if (tokens[0]==std::string("ladder")) {
            k1=2;
            int playerid;
            std::istringstream iss( tokens[1] );
            iss >>  playerid;
            for (int k=k1;k<tokens.size();k++) bz_sendTextMessagef(BZ_SERVER,playerid,"%s",tokens[k].c_str());
            k1=0;
        }
void CustomFlagSample::Event(bz_EventData *eventData)
{
  switch (eventData->eventType) {

  default: {
    // no, sir, we didn't ask for THIS!!
    bz_debugMessage(1, "customflagsample: received event with unrequested eventType!");
    return;
  }

  case bz_eFlagTransferredEvent: {
    bz_FlagTransferredEventData_V1* fte = (bz_FlagTransferredEventData_V1*)eventData;
    if (strcmp(fte->flagType, "CF") == 0)
	bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Custom Flag transferred!");
    break;
  }

  case bz_eFlagGrabbedEvent: {
    bz_FlagGrabbedEventData_V1* fge = (bz_FlagGrabbedEventData_V1*)eventData;
    if (strcmp(fge->flagType, "CF") == 0)
      bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Custom Flag grabbed!");
    break;
  }

  case bz_eFlagDroppedEvent: {
    bz_FlagDroppedEventData_V1* fde = (bz_FlagDroppedEventData_V1*)eventData;
    if (strcmp(fde->flagType, "CF") == 0)
      bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Custom Flag dropped!");
    break;
  }

  case bz_eShotFiredEvent: {
    bz_ShotFiredEventData_V1* sfed = (bz_ShotFiredEventData_V1*)eventData;
    int p = sfed->playerID;
    bz_BasePlayerRecord *playerRecord = bz_getPlayerByIndex(p);
    if (!playerRecord) break;
    if (playerRecord->currentFlag == "Custom Flag (+CF)")
    {
	bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Shot fired by %s with Custom Flag!", playerRecord->callsign.c_str());
	// this user must be cool, add 10 to their score
	bz_BasePlayerRecord* player = bz_getPlayerByIndex(p);
	bz_setPlayerWins(p, player->wins+10);
    }
    break;
  }

  case bz_ePlayerDieEvent: {
    bz_PlayerDieEventData_V1* deed = (bz_PlayerDieEventData_V1*)eventData;
    bz_ApiString flag = deed->flagKilledWith;
    int p = deed->playerID;
    bz_BasePlayerRecord *playerRecord = bz_getPlayerByIndex(p);
    if (flag == "CF")
      bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Player %s killed by a player with Custom Flag!", playerRecord->callsign.c_str());
    break;
  }

  }
}
示例#6
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;
}
示例#7
0
void TCTFFlagCapped::process(bz_EventData * eventData)
{
  if (eventData->eventType != bz_eCaptureEvent)
    return;

  // if timed CTF turned off, get outta here:

  if (!tctf.enabled || !tctf.timerRunning)
    return;

  bz_CTFCaptureEventData_V1 *CapData = (bz_CTFCaptureEventData_V1 *) eventData;

  // if team caps, reset their timer and notify their team

  if (CapData->teamCapping == eRedTeam) {
    tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5);
    bz_sendTextMessagef(BZ_SERVER, eRedTeam,
			"CTF timer is reset to %i minutes for the red team.", tctf.adjTime);
    tctf.redLastTime = bz_getCurrentTime();
    tctf.redLastWarn = bz_getCurrentTime();
    return;
  }
  if (CapData->teamCapping == eGreenTeam) {
    tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5);
    bz_sendTextMessagef(BZ_SERVER, eGreenTeam,
			"CTF timer is reset to %i minutes for the green team.", tctf.adjTime);
    tctf.greenLastTime = bz_getCurrentTime();
    tctf.greenLastWarn = bz_getCurrentTime();
    return;
  }
  if (CapData->teamCapping == eBlueTeam) {
    tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5);
    bz_sendTextMessagef(BZ_SERVER, eBlueTeam,
			"CTF timer is reset to %i minutes for the blue team.", tctf.adjTime);
    tctf.blueLastTime = bz_getCurrentTime();
    tctf.blueLastWarn = bz_getCurrentTime();
    return;
  }
  if (CapData->teamCapping == ePurpleTeam) {
    tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5);
    bz_sendTextMessagef(BZ_SERVER, ePurpleTeam,
			"CTF timer is reset to %i minutes for the purple team.", tctf.adjTime);
    tctf.purpleLastTime = bz_getCurrentTime();
    tctf.purpleLastWarn = bz_getCurrentTime();
    return;
  }

  return;
}
示例#8
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;
}
示例#9
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;
}
示例#10
0
void BaseUrlHandler::URLDone ( const char* /*URL*/, void * data, unsigned int size, bool complete )
{
  int _playerId = _playerIds[0];
  _playerIds.erase(_playerIds.begin());

  if ( size > 1 && size < _max_data_size ) {
    std::string _data; 
    _data.append((char*)data, size);

    if (is_valid_status(_data))	{
      replace_v2(_data,"\r\n","\n");
      replace_v2(_data,"\r","\n");
      replace_v2(_data,"\n\n","\n \n");
      //dataList->tokenize(_data.c_str(), "\r\n");
      dataList->tokenize(_data.c_str(), "\n");
      showData(_playerId);

    }
    else {
      bz_sendTextMessage (BZ_SERVER, _playerId,"No valid data was received !");
      bz_sendTextMessage (BZ_SERVER, _playerId,"This points to a bug or misuse. Please contact the server admin.");
    }
  }
  else {
    bz_sendTextMessagef (BZ_SERVER, _playerId,"The received data size (%d) exceede the limit (%d)", size, _max_data_size);
    bz_sendTextMessage (BZ_SERVER, _playerId,"This points to a bug or misuse. Please contact the server admin.");
  }
}
示例#11
0
void TCTFPlayerUpdates ( bz_EventData *eventData )
{
    if (eventData->eventType != bz_ePlayerUpdateEvent)
        return;

    // no CTF if teams not balanced, drop team flags asap:

    if (!tctf.fairCTF)
    {

        int playerID = ((bz_PlayerUpdateEventData_V1*)eventData)->playerID;
        const char* FlagHeld = bz_getPlayerFlag(playerID);

        if (FlagHeld != NULL)
        {

            if (strcmp(FlagHeld, "R*") == 0 || strcmp(FlagHeld, "G*") == 0 || strcmp(FlagHeld, "B*") == 0
                    || strcmp(FlagHeld, "P*") == 0 )
            {
                bz_removePlayerFlag ( playerID );
                bz_sendTextMessagef (BZ_SERVER, playerID, "Capture The Flag disabled - teams are not evenly balanced.");
            }
        }

    }

    return;
}
示例#12
0
void TopZelo::showDataOK(int playerId)
{
  bz_sendTextMessage ( BZ_SERVER, playerId,"Zelo score ranking");
  bz_sendTextMessage ( BZ_SERVER, playerId,"-------------------------------------------");
  bz_sendTextMessagef ( BZ_SERVER, playerId,"%-4s %-32s %4s", "Pos", "Player", "Zelo");
  bz_sendTextMessagef ( BZ_SERVER, playerId,"%-4s %-32s %4s", "---", "------", "----");

  for ( unsigned int i = 1; i < dataList->size(); i++) {
    bz_APIStringList* topZeloList = bz_newStringList();
    topZeloList->tokenize(dataList->get(i).c_str(), "\t", 3, false);

    bz_sendTextMessagef ( BZ_SERVER, playerId,"%-4s %-32s %-4s", topZeloList->get(0).c_str(), topZeloList->get(1).c_str(),topZeloList->get(2).c_str());
    bz_deleteStringList(topZeloList);
  }

  bz_sendTextMessage ( BZ_SERVER, playerId,"-------------------------------------------");
}
示例#13
0
void KeepAwayPlayerJoined ( bz_EventData *eventData )
{
	if (eventData->eventType != bz_ePlayerJoinEvent || !keepaway.enabled || keepaway.flagToKeep == "")
		return;

	bz_PlayerJoinPartEventData_V1 *joinData = (bz_PlayerJoinPartEventData_V1*)eventData;

	if (keepaway.flagToKeep == "Initiate") //first time server starts, first player initiates it.
	{
		keepaway.flagToKeep = getFlag();
		keepaway.lastReminder = bz_getCurrentTime();
	}

	autoTime();

	if (oneTeam(eNoTeam)) // don't send message if not enough teams
	{
		keepaway.notEnoughTeams = true;
		return;
	}
	else
		keepaway.notEnoughTeams = false;

	if (keepaway.id == -1 && keepaway.enabled && keepaway.flagToKeep != "")
	{
		bz_sendTextMessagef (BZ_SERVER, joinData->playerID, "Keep Away flag is %s: find it and keep it for %i seconds!", convertFlag(keepaway.flagToKeep).c_str(), (int)keepaway.adjustedTime);
		if (keepaway.soundEnabled)
			bz_sendPlayCustomLocalSound(joinData->playerID,"hunt_select");
	}

	if (keepaway.id != -1 && keepaway.enabled && keepaway.flagToKeep != "" && (joinData->record->team != keepaway.team || joinData->record->team == eRogueTeam))
	{
		bz_sendTextMessagef (BZ_SERVER, joinData->playerID, "%s has Keep Away flag %s - kill him/her before time's up!", keepaway.callsign.c_str(), convertFlag(keepaway.flagToKeep).c_str());
		if (keepaway.soundEnabled)
			bz_sendPlayCustomLocalSound(joinData->playerID,"flag_alert");
	}

	if (keepaway.id != -1 && keepaway.enabled && keepaway.flagToKeep != "" && (joinData->record->team == keepaway.team && joinData->record->team != eRogueTeam))
	{
		bz_sendTextMessagef (BZ_SERVER, joinData->playerID, "%s has Keep Away flag %s - protect him/her until time's up!", keepaway.callsign.c_str(), convertFlag(keepaway.flagToKeep).c_str());
		if (keepaway.soundEnabled)
			bz_sendPlayCustomLocalSound(joinData->playerID,"teamgrab");
	}

	return;
}
示例#14
0
bool Defusal::SlashCommand(int playerID, bz_ApiString command, bz_ApiString /*message*/, bz_APIStringList *params)
{
	bz_BasePlayerRecord *playerdata = bz_getPlayerByIndex(playerID);
	
	if (command == "bomb" && playerdata->currentFlag.c_str()=="Red team flag")
	{	
		bombPlaced = true;
		bombPlacer = playerdata->callsign.c_str();
		bombPlacementTime = bz_getCurrentTime();
		
		bz_removePlayerFlag(playerID); //Take away the flag (bomb), it has been placed
		bz_getFlagPosition(0,bombLocation); //Store the location of the bomb
		
		bz_sendTextMessagef(BZ_SERVER,eBlueTeam,"'%s' has placed the bomb! You have %i minutes to find and defuse it.",bombPlacer.c_str(),detonationTime);
		bz_sendTextMessagef(BZ_SERVER,eRedTeam,"'%s' has placed the bomb! Defend the bomb for %i minutes.",bombPlacer.c_str(),detonationTime);
		bz_sendTextMessagef(BZ_SERVER,eObservers,"'%s' has placed the bomb!",bombPlacer.c_str(),detonationTime);
	}
	
	bz_freePlayerRecord(playerdata);
}
示例#15
0
void leagueOverSeer::URLDone(const char* /*URL*/, const void* data, unsigned int /*size*/, bool /*complete*/) //Everything went fine with the report
{
    std::string siteData = (const char*)(data); //Convert the data to a std::string
    bz_debugMessagef(1, "URL Job Successful! Data returned: %s", siteData.c_str());

    if (strcmp(siteData.substr(0, 6).c_str(), "INSERT") == 0 || strcmp(siteData.substr(0, 6).c_str(), "DELETE") == 0)
        doQuery(siteData);
    else if (strcmp(siteData.c_str(), "<html>") < 0)
    {
        bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s", siteData.c_str());
        bz_debugMessagef(DEBUG, "%s", siteData.c_str());
    }
}
示例#16
0
void PlayerInfo::showDataOK(int playerId)
{ 
  for ( unsigned int i = 1; i < dataList->size(); i++) {
    bz_APIStringList* playerList = bz_newStringList();
    playerList->tokenize(dataList->get(i).c_str(), "\t", 6, false);

    bz_sendTextMessagef ( BZ_SERVER, playerId,"Player info for %s", playerList->get(0).c_str());
    bz_sendTextMessage ( BZ_SERVER, playerId,"-------------------------------------------");
    bz_sendTextMessagef ( BZ_SERVER, playerId,"zelo         : %s", playerList->get(1).c_str());
    bz_sendTextMessagef ( BZ_SERVER, playerId,"score        : %s", playerList->get(5).c_str());
    bz_sendTextMessagef ( BZ_SERVER, playerId,"matches won  : %s", playerList->get(2).c_str());
    bz_sendTextMessagef ( BZ_SERVER, playerId,"matches lost : %s", playerList->get(3).c_str());
    bz_sendTextMessagef ( BZ_SERVER, playerId,"status       : %s", playerList->get(4).c_str());
    bz_sendTextMessage ( BZ_SERVER, playerId,"-------------------------------------------");
    bz_deleteStringList(playerList);
  }
}
示例#17
0
int TeamCheck(bz_eTeamType Team, const char* Color, double LastWarn, double LastTime)
{

    if (bz_getTeamCount(Team) != 0 && tctf.timerRunning)
    {

        tctf.timeElapsed = bz_getCurrentTime() - LastTime;
        tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed;

        if (bz_getCurrentTime() - LastWarn > 60)
        {
            tctf.adjTime = (int)(tctf.timeRemaining / 60);
            bz_sendTextMessagef (BZ_SERVER, Team, "%s Team: less than %i minute(s) left to capture a flag!", Color,
                                 tctf.adjTime + 1);
            return 1; // 1 = reset team's LastWarn
        }
        if (bz_getCurrentTime() - LastWarn > 30 && tctf.timeRemaining < 30)
        {
            bz_sendTextMessagef (BZ_SERVER, Team, "%s Team: less than 30 seconds left to capture a flag!", Color);
            return 1; // 1 = reset team's LastWarn
        }
        if (bz_getCurrentTime() - LastWarn > 10 && tctf.timeRemaining < 20 && tctf.timeRemaining > 10)
        {
            bz_sendTextMessagef (BZ_SERVER, Team, "%s Team: less than 20 seconds left to capture a flag!", Color);
            return 1; // 1 = reset team's LastWarn
        }
        if (bz_getCurrentTime() - LastWarn > 10 && tctf.timeRemaining < 10 && tctf.timeRemaining > 1)
        {
            bz_sendTextMessagef (BZ_SERVER, Team, "%s Team: less than 10 seconds left to capture a flag!", Color);
            return 1; // 1 = reset team's LastWarn
        }

        if (tctf.timeElapsed >= tctf.timeLimit)
        {

            KillTeam(Team);
            bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s team did not capture any other team flags in time.", Color);
            tctf.adjTime = (int)(tctf.timeLimit / 60 + 0.5);
            bz_sendTextMessagef (BZ_SERVER, Team, "CTF timer is reset to %i minutes for the %s team.", tctf.adjTime, Color);
            return 2; // 2 = reset team's LastWarn and LastTime
        }
    }

    return 0; // 0 = no need to reset teams LastWarn or LastTime
}
示例#18
0
bool leagueOverSeer::SlashCommand(int playerID, bz_ApiString command, bz_ApiString /*message*/, bz_APIStringList *params)
{
    int timeToStart = atoi(params->get(0).c_str());
    bz_BasePlayerRecord *playerData = bz_getPlayerByIndex(playerID);

    if (command == "official") //Someone used the /official command
    {
        if (playerData->team == eObservers) //Observers can't start matches
            bz_sendTextMessage(BZ_SERVER, playerID, "Observers are not allowed to start matches.");
        else if ((bz_getTeamCount(eRedTeam) < 2 && bz_getTeamPlayerLimit(eRedTeam) > 0) ||
                (bz_getTeamCount(eGreenTeam) < 2 && bz_getTeamPlayerLimit(eGreenTeam) > 0) ||
                (bz_getTeamCount(eBlueTeam) < 2 && bz_getTeamPlayerLimit(eBlueTeam) > 0) ||
                (bz_getTeamCount(ePurpleTeam) < 2 && bz_getTeamPlayerLimit(ePurpleTeam) > 0)) //An official match cannot be 1v1 or 2v1
            bz_sendTextMessage(BZ_SERVER, playerID, "You may not have an official match with less than 2 players per team.");
        else if (funMatch) //A fun match cannot be declared an official match
            bz_sendTextMessage(BZ_SERVER,playerID,"Fun matches cannot be turned into official matches.");
        else if (!playerData->verified || !bz_hasPerm(playerID,"spawn")) //If they can't spawn, they aren't a league player so they can't start a match
            bz_sendTextMessage(BZ_SERVER,playerID,"Only registered league players may start an official match.");
        else if (bz_isCountDownActive() || bz_isCountDownInProgress()) //A countdown is in progress already
            bz_sendTextMessage(BZ_SERVER,playerID,"There is currently a countdown active, you may not start another.");
        else if (playerData->verified && playerData->team != eObservers && bz_hasPerm(playerID,"spawn") && !bz_isCountDownActive() && !funMatch) //Check the user is not an obs and is a league member
        {
            officialMatch = true; //Notify the plugin that the match is official
            bz_debugMessagef(DEBUG, "DEBUG :: League Over Seer :: Official match started by %s (%s).", playerData->callsign.c_str(), playerData->ipAddress.c_str());
            bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Official match started by %s.", playerData->callsign.c_str());

            if (timeToStart <= 120 && timeToStart > 5)
                bz_startCountdown (timeToStart, bz_getTimeLimit(), "Server"); //Start the countdown with a custom countdown time limit under 2 minutes
            else
                bz_startCountdown (10, bz_getTimeLimit(), "Server"); //Start the countdown for the official match
        }
        else
            bz_sendTextMessage(BZ_SERVER, playerID, "You do not have permission to run the /official command.");

        return true;
    }
    else if (command == "fm") //Someone uses the /fm command
    {
        if (bz_isCountDownActive() || bz_isCountDownInProgress() || funMatch || officialMatch) //There is already a countdown
            bz_sendTextMessage(BZ_SERVER, playerID, "There is currently a countdown active, you may not start another.");
        else if (playerData->team == eObservers) //Observers can't start matches
            bz_sendTextMessage(BZ_SERVER,playerID,"Observers are not allowed to start matches.");
        else if (!playerData->verified || !bz_hasPerm(playerID,"spawn")) //If they can't spawn, they aren't a league player so they can't start a match
            bz_sendTextMessage(BZ_SERVER,playerID,"Only registered league players may start an official match.");
        else if (!bz_isCountDownActive() && playerData->team != eObservers && bz_hasPerm(playerID,"spawn") && playerData->verified && !officialMatch)
        {
            funMatch = true; //It's a fun match

            bz_debugMessagef(DEBUG, "DEBUG :: League Over Seer :: Fun match started by %s (%s).", playerData->callsign.c_str(), playerData->ipAddress.c_str());
            bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Fun match started by %s.", playerData->callsign.c_str());

            if (timeToStart <= 120 && timeToStart > 5)
                bz_startCountdown (timeToStart, bz_getTimeLimit(), "Server"); //Start the countdown with a custom countdown time limit under 2 minutes
            else
                bz_startCountdown (10, bz_getTimeLimit(), "Server"); //Start the countdown for the official match
        }
        else
            bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permission to run the /fm command.");

        return true;
    }
    else if (command == "cancel")
    {
        if (bz_hasPerm(playerID,"spawn") && bz_isCountDownActive())
        {
            if (officialMatch)
            {
                bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Official match ended by %s", playerData->callsign.c_str());
                bz_debugMessagef(DEBUG, "DEBUG :: League Over Seer :: Match ended by %s (%s).", playerData->callsign.c_str(),playerData->ipAddress.c_str());
            }
            else
            {
                bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Fun match ended by %s", playerData->callsign.c_str());
                bz_debugMessagef(DEBUG, "DEBUG :: League Over Seer :: Match ended by %s (%s).", playerData->callsign.c_str(),playerData->ipAddress.c_str());
            }

            //Reset the server. Cleanly ends a match
            officialMatch = false;
            doNotReportMatch = true;
            funMatch = false;
            teamOnePoints = 0;
            teamTwoPoints = 0;

            //End the countdown
            if (bz_isCountDownActive())
                bz_gameOver(253, eObservers);
        }
        else if (!bz_isCountDownActive())
            bz_sendTextMessage(BZ_SERVER, playerID, "There is no match in progress to cancel.");
        else //Not a league player
            bz_sendTextMessage(BZ_SERVER, playerID, "You do not have permission to run the /cancel command.");

        return true;
    }
    else if (command == "finish")
    {
        if (bz_hasPerm(playerID,"spawn") && bz_isCountDownActive() && officialMatch)
        {
            bz_debugMessagef(DEBUG, "DEBUG :: Match Over Seer :: Official match ended early by %s (%s)", playerData->callsign.c_str(), playerData->ipAddress.c_str());
            bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Official match ended early by %s", playerData->callsign.c_str());

            doNotReportMatch = false; //To prevent reporting a canceled match, let plugin know the match was canceled

            //End the countdown
            if (bz_isCountDownActive())
                bz_gameOver(253, eObservers);
        }
        else if (!bz_isCountDownActive())
            bz_sendTextMessage(BZ_SERVER, playerID, "There is no match in progress to end.");
        else if (!officialMatch)
            bz_sendTextMessage(BZ_SERVER, playerID, "You cannot /finish a fun match. Use /cancel instead.");
        else //Not a league player
            bz_sendTextMessage(BZ_SERVER, playerID, "You do not have permission to run the /finish command.");

        return true;
    }
    else if (command == "pause")
    {
        if (bz_isCountDownActive() && bz_hasPerm(playerID,"spawn") && playerData->verified)
            bz_pauseCountdown(playerData->callsign.c_str());
        else if (!bz_isCountDownActive())
            bz_sendTextMessage(BZ_SERVER, playerID, "There is no active match to pause right now.");
        else
            bz_sendTextMessage(BZ_SERVER, playerID, "You are not have permission to run the /pause command.");

        return true;
    }
    else if (command == "resume")
    {
        if (bz_hasPerm(playerID,"spawn") && playerData->verified && bz_isCountDownActive())
            bz_resumeCountdown(playerData->callsign.c_str());
        else if (!bz_isCountDownActive())
            bz_sendTextMessage(BZ_SERVER, playerID, "The current match is not paused.");
        else
            bz_sendTextMessage(BZ_SERVER, playerID, "You are not have permission to run the /resume command.");

        return true;
    }
    else if (command == "spawn")
    {
        if (bz_hasPerm(playerID, "ban"))
        {
            if (params->size() > 0)
            {
                std::string callsignToLookup; //store the callsign we're going to search for

                for (unsigned int i = 0; i < params->size(); i++) //piece together the callsign from the slash command parameters
                {
                    callsignToLookup += params->get(i).c_str();
                    if (i != params->size() - 1) // so we don't stick a whitespace on the end
                        callsignToLookup += " "; // add a whitespace between each chat text parameter
                }

                if (std::string::npos != std::string(params->get(0).c_str()).find("#") && isValidPlayerID(atoi(std::string(params->get(0).c_str()).erase(0, 1).c_str())))
                {
                    bz_grantPerm(atoi(std::string(params->get(0).c_str()).erase(0, 1).c_str()), "spawn");
                    bz_sendTextMessagef(BZ_SERVER, eAdministrators, "%s gave spawn perms to %s", bz_getPlayerByIndex(playerID)->callsign.c_str(), bz_getPlayerByIndex(atoi(std::string(params->get(0).c_str()).substr(0, 1).c_str()))->callsign.c_str());
                }
                else if (isValidCallsign(callsignToLookup) >= 0)
                {
                    bz_grantPerm(isValidCallsign(callsignToLookup), "spawn");
                    bz_sendTextMessagef(BZ_SERVER, eAdministrators, "%s gave spawn perms to %s", bz_getPlayerByIndex(playerID)->callsign.c_str(), bz_getPlayerByIndex(isValidCallsign(callsignToLookup))->callsign.c_str());
                }
                else
                    bz_sendTextMessagef(BZ_SERVER, playerID, "player %s not found", params->get(0).c_str());
            }
            else
                bz_sendTextMessage(BZ_SERVER, playerID, "/spawn <player id or callsign>");
        }
        else if (!playerData->admin)
            bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permission to use the /spawn command.");

        return true;
    }

    bz_freePlayerRecord(playerData);
    return false;
}
示例#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;
    }
}
示例#20
0
bool TCTFCommands::handle(int playerID, bz_ApiString _command, bz_ApiString _message, bz_APIStringList * /*_param*/ )
{
  std::string command = _command.c_str();
  std::string message = _message.c_str();

  bz_BasePlayerRecord *fromPlayer = bz_getPlayerByIndex(playerID);

  if (fromPlayer) {
    if (!fromPlayer->admin) {
      bz_sendTextMessage(BZ_SERVER, playerID,
			 "You must be admin to use the ctfcaptime commands.");
      bz_freePlayerRecord(fromPlayer);
      return true;
    }
    bz_freePlayerRecord(fromPlayer);
  }

  if (command == "tctfon") {
    tctf.enabled = true;
    if (!tctf.timerRunning)
      ResetTeamData();
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Timed CTF is enabled.");
    return true;
  }

  if (command == "tctfoff") {
    tctf.enabled = false;
    tctf.timerRunning = false;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Timed CTF is disabled.");
    return true;
  }

  if (command == "fairctfon") {
    tctf.fairCTFEnabled = true;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Fair CTF is enabled.");
    return true;
  }

  if (command == "fairctfoff") {
    tctf.fairCTFEnabled = false;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Fair CTF is disabled.");
    if (!tctf.timerRunning)
      ResetTeamData();
    return true;
  }

  if (command == "tctfsoundon") {

    tctf.soundEnabled = true;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Timed CTF sound is enabled.");
    return true;
  }

  if (command == "tctfsoundoff") {

    tctf.soundEnabled = false;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Timed CTF sound is disabled.");
    return true;
  }

  if (command == "tctfstatus") {

    if (tctf.enabled && !tctf.timerRunning)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Timed CTF is currently enabled, but not running.");

    if (tctf.enabled && tctf.timerRunning)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Timed CTF is currently enabled, and running");

    if (!tctf.enabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Timed CTF is currently disabled.");

    if (!tctf.fairCTFEnabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Fair CTF is currently disabled");

    if (tctf.fairCTFEnabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Fair CTF is currently enabled");

    if (!tctf.soundEnabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Timed CTF sounds are currently disabled");

    if (tctf.soundEnabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Timed CTF sounds are currently enabled");

    tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5);
    bz_sendTextMessagef(BZ_SERVER, playerID, "CTF capture time is currently set to: %i minutes", tctf.adjTime);
    return true;
  }
  // explicit time command handler:

  if (command == "tctftime") {
    double inputvalue = ConvertToInt(message);

    if (inputvalue > 0) {

      tctf.timeLimit = inputvalue * 60;
      tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5);
      bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "CTF capture time has been set to %i minutes.", tctf.adjTime);

      if (!tctf.enabled)
	bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "(Timed CTF is still disabled)");

      ResetTeamData();
      return true;
    } else {
      bz_sendTextMessagef(BZ_SERVER, playerID, "CTF capture time invalid: must be between 1 and 120 minutes.");
      return true;
    }

    return true;
  }

  return false;
}
示例#21
0
// this is where most of the decisions are made - a little clunky, but seems to work:
void TCTFTickEvents::process(bz_EventData * eventData)
{
  if (eventData->eventType != bz_eTickEvent)
    return;

  // read this function once per tick event.  If fair CTF disabled, make it look fair to rest
  // of code - need to do this to be able to have timed ctf without fair ctf.

  tctf.fairCTF = (TeamsBalanced() || !tctf.fairCTFEnabled);

  // check/notify team balance changes while timed CTF is disabled.
  // if fair ctf is disabled, no need to check/notify about team balance changes:

  if (tctf.fairCTF && !tctf.notifiedCTFOK && !tctf.enabled && tctf.fairCTFEnabled) {

    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS,
			"Capture The Flag enabled - teams are evenly balanced.");
    tctf.notifiedCTFOK = true;
    return;
  }

  if (!tctf.fairCTF && tctf.notifiedCTFOK && !tctf.enabled && tctf.fairCTFEnabled) {

    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS,
			"Capture The Flag disabled - teams are not evenly balanced.");
    tctf.notifiedCTFOK = false;
    return;
  }
  // if no timed CTF, we can leave:

  if (!tctf.enabled)
    return;

  // if this is true, we can leave too:

  if (!tctf.fairCTF && !tctf.timerRunning)
    return;

  // check/notify team balance changes while timed CTF and fair CTF are enabled:

  if (!tctf.fairCTF && tctf.timerRunning && tctf.fairCTFEnabled) {

    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS,
			"Capture The Flag disabled - teams are not evenly balanced.");
    tctf.timerRunning = false;
    ResetTeamData();
    return;
  }
  // no timed ctf with fair CTF disabled and only one team present:

  if (tctf.fairCTF && !tctf.fairCTFEnabled) {

    if (OnlyOneTeamPlaying()) {

      if (tctf.timerRunning)
	bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS,
			    "Timed CTF disabled - not enough teams.");

      tctf.timerRunning = false;
      ResetTeamData();
      return;
    }
  }
  // start timing if we have made it this far:

  if (tctf.fairCTF && !tctf.timerRunning && !OnlyOneTeamPlaying()) {

    tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5);
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS,
			"Timed CTF now in progress - capture a flag in less than %i minute(s)!",
			tctf.adjTime);
    tctf.timerRunning = true;
    ResetTeamData();
    return;
  }
  // everything is a go for timed ctf checks now.
  // check each team's time left, warn and kill if necessary:

  int RedReturn = TeamCheck(eRedTeam, "RED", tctf.redLastWarn, tctf.redLastTime);
  int GreenReturn = TeamCheck(eGreenTeam, "GREEN", tctf.greenLastWarn, tctf.greenLastTime);
  int BlueReturn = TeamCheck(eBlueTeam, "BLUE", tctf.blueLastWarn, tctf.blueLastTime);
  int PurpleReturn = TeamCheck(ePurpleTeam, "PURPLE", tctf.purpleLastWarn, tctf.purpleLastTime);

  if (RedReturn == 1)
    tctf.redLastWarn = bz_getCurrentTime();
  if (RedReturn == 2) {
    tctf.redLastWarn = bz_getCurrentTime();
    tctf.redLastTime = bz_getCurrentTime();
  }
  if (GreenReturn == 1)
    tctf.greenLastWarn = bz_getCurrentTime();
  if (GreenReturn == 2) {
    tctf.greenLastWarn = bz_getCurrentTime();
    tctf.greenLastTime = bz_getCurrentTime();
  }
  if (BlueReturn == 1)
    tctf.blueLastWarn = bz_getCurrentTime();
  if (BlueReturn == 2) {
    tctf.blueLastWarn = bz_getCurrentTime();
    tctf.blueLastTime = bz_getCurrentTime();
  }
  if (PurpleReturn == 1)
    tctf.purpleLastWarn = bz_getCurrentTime();
  if (PurpleReturn == 2) {
    tctf.purpleLastWarn = bz_getCurrentTime();
    tctf.purpleLastTime = bz_getCurrentTime();
  }

  ResetZeroTeams();		// reset team data for teams with no players.

  return;
}
示例#22
0
void TCTFPlayerJoined::process(bz_EventData * eventData)
{
  if (eventData->eventType != bz_ePlayerJoinEvent)
    return;

  bz_PlayerJoinPartEventData_V1 *JoinData = (bz_PlayerJoinPartEventData_V1 *) eventData;

  // if teams are not even, notify joiner no CTF.
  // this should never be true if fair ctf is disabled (see definition of tctf.fairCTF):

  if (!tctf.fairCTF) {
    bz_sendTextMessagef(BZ_SERVER, JoinData->playerID,
			"Capture The Flag disabled - teams are not evenly balanced.");
    return;
  }
  // if timed CTF turned off, but teams now even, let everyone know it's ok to cap.
  // if fair CTF is disabled, no need to notify:

  if (tctf.fairCTF && !tctf.enabled && tctf.fairCTFEnabled) {
    bz_sendTextMessagef(BZ_SERVER, JoinData->playerID,
			"Capture The Flag enabled - teams are evenly balanced.");
    return;
  }
  // if timed CTF turned off, get outta here:

  if (!tctf.enabled)
    return;

  // if teams even, notify joiner how much time is left to CTF for their team:

  if (JoinData->record->team == eRedTeam && tctf.timerRunning) {
    tctf.timeElapsed = bz_getCurrentTime() - tctf.redLastTime;
    tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed;
    tctf.adjTime = (int) (tctf.timeRemaining / 60);
    bz_sendTextMessagef(BZ_SERVER, JoinData->playerID,
			"Timed CTF now in progress - capture a flag in less than %i minute(s)!",
			tctf.adjTime + 1);
    return;
  }

  if (JoinData->record->team == eGreenTeam && tctf.timerRunning) {
    tctf.timeElapsed = bz_getCurrentTime() - tctf.greenLastTime;
    tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed;
    tctf.adjTime = (int) (tctf.timeRemaining / 60);
    bz_sendTextMessagef(BZ_SERVER, JoinData->playerID,
			"Timed CTF now in progress - capture a flag in less than %i minute(s)!",
			tctf.adjTime + 1);
    return;
  }

  if (JoinData->record->team == eBlueTeam && tctf.timerRunning) {
    tctf.timeElapsed = bz_getCurrentTime() - tctf.blueLastTime;
    tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed;
    tctf.adjTime = (int) (tctf.timeRemaining / 60);
    bz_sendTextMessagef(BZ_SERVER, JoinData->playerID,
			"Timed CTF now in progress - capture a flag in less than %i minute(s)!",
			tctf.adjTime + 1);
    return;
  }

  if (JoinData->record->team == ePurpleTeam && tctf.timerRunning) {
    tctf.timeElapsed = bz_getCurrentTime() - tctf.purpleLastTime;
    tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed;
    tctf.adjTime = (int) (tctf.timeRemaining / 60);
    bz_sendTextMessagef(BZ_SERVER, JoinData->playerID,
			"Timed CTF now in progress - capture a flag in less than %i minute(s)!",
			tctf.adjTime + 1);
    return;
  }

  return;
}
示例#23
0
bool KOTHCommands::handle(int playerID, bz_ApiString _command, bz_ApiString _message, bz_APIStringList * /*_param*/ )
{
  std::string command = _command.c_str();
  std::string message = _message.c_str();
  const char *kingmessage = _message.c_str();

  if (command == "kingsay") {
    if (koth.id != -1)
      bz_sendTextMessage(playerID, koth.id, kingmessage);
    else
      bz_sendTextMessage(BZ_SERVER, playerID, "There is no one attempting to be king right now.");

    return true;
  }

  bz_BasePlayerRecord *fromPlayer = bz_getPlayerByIndex(playerID);

  if (fromPlayer) {
    if (!fromPlayer->admin) {
      bz_sendTextMessage(BZ_SERVER, playerID, "You must be admin to use the koth commands.");
      bz_freePlayerRecord(fromPlayer);
      return true;
    }

    bz_freePlayerRecord(fromPlayer);
  }

  if (command == "kothon") {
    koth.enabled = true;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill is enabled.");
    return true;
  }

  if (command == "kothoff") {
    koth.enabled = false;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill is disabled.");
    return true;
  }

  if (command == "kothsoundon") {
    koth.soundEnabled = true;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill sounds are enabled.");
    return true;
  }

  if (command == "kothsoundoff") {
    koth.soundEnabled = false;
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill sounds are disabled.");
    return true;
  }

  if (command == "kothtimemult") {
    double inputvalue = ConvertToNum(message, 1, 99);

    if (inputvalue > 0) {
      koth.timeMult = (inputvalue / 100);
      bz_sendTextMessagef(BZ_SERVER, playerID, "Auto time multiplier set to %i percent.", (int) (koth.timeMult * 100 + 0.5));
    } else {
      bz_sendTextMessagef(BZ_SERVER, playerID, "Auto time multiplier (%i) must be between 1 and 99 percent.",
			  (int) (koth.timeMult * 100 + 0.5));
    }

    autoTime();

    return true;
  }

  if (command == "kothtimemultmin") {
    double inputvalue = ConvertToNum(message, 1, 99);

    if (inputvalue > 0) {
      koth.timeMultMin = (inputvalue / 100);
      bz_sendTextMessagef(BZ_SERVER, playerID, "Auto time multiplier minimum set to %i percent.",
			  (int) (koth.timeMultMin * 100 + 0.5));
    } else {
      bz_sendTextMessagef(BZ_SERVER, playerID, "Auto time multiplier minimum must be between 1 and 99 percent.");
    }

    autoTime();

    return true;
  }

  if (command == "kothstatus") {
    if (koth.enabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "King of the Hill is currently enabled.");

    if (!koth.enabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "King of the Hill is currently disabled.");

    if (koth.soundEnabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "King of the Hill sounds are currently enabled.");

    if (!koth.soundEnabled)
      bz_sendTextMessagef(BZ_SERVER, playerID, "King of the Hill sounds are currently disabled.");

    if (koth.autoTimeOn)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Automatic time adjustment is currently enabled.");

    if (!koth.autoTimeOn)
      bz_sendTextMessagef(BZ_SERVER, playerID, "Automatic time adjustment is currently disabled.");

    bz_sendTextMessagef(BZ_SERVER, playerID, "Time multiplier = %i percent.", (int) (koth.timeMult * 100 + 0.5));

    bz_sendTextMessagef(BZ_SERVER, playerID, "Time multiplier minimum = %i percent.", (int) (koth.timeMultMin * 100 + 0.5));

    int AdjTime = (int) (koth.adjustedTime + 0.5);
    bz_sendTextMessagef(BZ_SERVER, playerID, "King of the Hill hold time is currently set to: %i seconds", AdjTime);
    return true;
  }
  // explicit time command handler:

  if (command == "kothtime") {
    double inputvalue = ConvertToNum(message, 1, 7200);

    if (inputvalue > 0) {
      koth.TTH = inputvalue;
      autoTime();
      int AdjTime = (int) (inputvalue + 0.5);
      bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill hold time has been set to %i seconds.", AdjTime);
    } else {
      bz_sendTextMessagef(BZ_SERVER, playerID, "King of the Hill hold time invalid: must be between 1 and 7200 seconds.");
    }

    autoTime();

    return true;
  }

  if (command == "kothautotimeon") {
    koth.autoTimeOn = true;
    autoTime();
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill automatic time adjustment on.");
    return true;
  }

  if (command == "kothautotimeoff") {
    koth.autoTimeOn = false;
    koth.adjustedTime = koth.TTH;
    autoTime();
    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill automatic time adjustment off.");
    return true;
  }

  return false;
}
示例#24
0
void BountyHunter::Event (bz_EventData *eventData)
{
    switch (eventData->eventType)
    {
        case bz_eFlagDroppedEvent: // This event is called each time a flag is dropped by a player.
        {
            bz_FlagDroppedEventData_V1* flagDropData = (bz_FlagDroppedEventData_V1*)eventData;

            // Get the abbreviation of the flag that was dropped to check if it was a team flag
            std::string flag = bz_getName(flagDropData->flagID).c_str();

            // If the dropped flag is a team flag, keep track of who dropped it and when
            if (flag == "R*" || flag == "G*" || flag == "B*" || flag == "P*")
            {
                lastFlagCarrier = flagDropData->playerID;
                teamFlagDropped = flag;
                flagCarryTime   = bz_getCurrentTime();
            }
        }
        break;

        case bz_ePlayerDieEvent: // This event is called each time a tank is killed.
        {
            bz_PlayerDieEventData_V1* dieData = (bz_PlayerDieEventData_V1*)eventData;
            int victimID = dieData->playerID;
            int killerID = dieData->killerID;

            // If the player did not kill themselves, then calculate the bounty points
            if (victimID != killerID)
            {
                // Increment the consecutive kills of the killer if the player is not the server (player ID 253)
                if (killerID != 253)
                {
                    consecutiveKills[killerID]++;
                }

                // If the person killed had more than 0 kills, calculate the bounty points
                if (consecutiveKills[victimID] > 0)
                {
                    // This value will keep track of how many levels of a rampage a player has gotten where each level
                    // is an increment of 6 kills
                    int rampageMultiplier = consecutiveKills[victimID] / 5;

                    // The rampage multiplier times two will be the amount of bounty points granted
                    int bountyPoints = rampageMultiplier * 2;

                    // Only reward bounty points if it's greater than 0
                    if (bountyPoints > 0)
                    {
                        // Set the player's new points and notify them
                        bz_setPlayerWins(killerID, bz_getPlayerWins(killerID) + bountyPoints);
			bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s earned %i bounty points stopping %s's rampage",
                                bz_getPlayerByIndex(killerID)->callsign.c_str(),
                                bountyPoints,
                                bz_getPlayerByIndex(victimID)->callsign.c_str()
                            );
                    }
                }

                // If the person killed was carrying a team flag less than 3 seconds ago, then reward the killer
                if (lastFlagCarrier == victimID && flagCarryTime + 3 > bz_getCurrentTime())
                {
                    // Store the team color
                    std::string teamColor = "";

                    // Set the respective color judging by the team flag abbreviation
                    if      (teamFlagDropped == "R*") { teamColor = "red"; }
                    else if (teamFlagDropped == "G*") { teamColor = "green"; }
                    else if (teamFlagDropped == "B*") { teamColor = "blue"; }
                    else if (teamFlagDropped == "P*") { teamColor = "purple"; }

                    // Set the player's new points and notify them
                    bz_setPlayerWins(killerID, bz_getPlayerWins(killerID) + 2);
                    bz_sendTextMessagef(BZ_SERVER, killerID, "Shooting the %s team flag carrier has earned you 2 bounty points",
                        teamColor.c_str());
                }
            }

            // Reset the consecutive kills made by the player who just got killed
            consecutiveKills[victimID] = 0;
        }
        break;

        case bz_ePlayerJoinEvent: // This event is called each time a player joins the game
        {
            bz_PlayerJoinPartEventData_V1* joinData = (bz_PlayerJoinPartEventData_V1*)eventData;

            // Set a player's consecutive kills to 0 when they join in case the array has a null value
            consecutiveKills[joinData->playerID] = 0;
        }
        break;

        default: break;
    }
}
示例#25
0
void ReverseGeno::Event (bz_EventData *eventData)
{
    switch (eventData->eventType)
    {
    case bz_eFlagGrabbedEvent: // This event is called each time a flag is grabbed by a player
        {
            bz_FlagGrabbedEventData_V1* flagGrabData = (bz_FlagGrabbedEventData_V1*)eventData;
            if (strcmp(flagGrabData->flagType, "RG") == 0)
            {
                bait = flagGrabData->playerID;
                grabTime = flagGrabData->eventTime;
                messageNumber = 5;
                bz_sendTextMessagef(BZ_SERVER, bait, "FIVE SECONDS TO DIE! Get killed before you DIE!");
            }

            // Data
            // ---
            //    (int)           playerID  - The player that grabbed the flag
            //    (int)           flagID    - The flag ID that was grabbed
            //    (bz_ApiString)  flagType  - The flag abbreviation of the flag that was grabbed
            //    (float[3])      pos       - The position at which the flag was grabbed
            //    (double)        eventTime - This value is the local server time of the event.
        }
        break;


    case bz_ePlayerDieEvent: // This event is called each time a tank is killed.
        {
            bz_PlayerDieEventData_V1* dieData = (bz_PlayerDieEventData_V1*)eventData;
            if (bait != -1 && bait != dieData->killerID && bait == dieData->playerID)
            {
                //bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Bait: %s, Player: %s (%d,%d)", bz_getPlayerCallsign(bait), bz_getPlayerCallsign(dieData->playerID), bait, dieData->playerID);
                if (bz_getPlayerTeam(bait) == bz_getPlayerTeam(dieData->killerID)) {
                    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Fail! %s just committed genocide on their own team!", bz_getPlayerCallsign(bait));
                    //bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Bait: %s, other: %s ", bz_getPlayerTeam(bait), bz_getPlayerTeam(dieData->playerID));
                }
                else {
                    bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Score! %s just baited %s into committing genocide on their own team!", bz_getPlayerCallsign(bait), bz_getPlayerCallsign(dieData->killerID));
                }
                
                genoOtherTeam(dieData->killerTeam, false, dieData->playerID, bait, "RG");
                grabTime = -1;
                bait = -1;
                //bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Bait: %0d, Player: %s (%d,%d)", bait, bz_getPlayerCallsign(dieData->playerID), bait, dieData->playerID);
            }
            else if (bait != -1 && bait == dieData->killerID && bait == dieData->playerID)
            {
                grabTime = -1;
                bait = -1;
            }

            // Data
            // ---
            //   (int)                   playerID       - ID of the player who was killed.
            //   (bz_eTeamType)          team           - The team the killed player was on.
            //   (int)                   killerID       - The owner of the shot that killed the player, or BZ_SERVER for server side kills
            //   (bz_eTeamType)          killerTeam     - The team the owner of the shot was on.
            //   (bz_ApiString)          flagKilledWith - The flag name the owner of the shot had when the shot was fired.
            //   (int)                   shotID         - The shot ID that killed the player, if the player was not killed by a shot, the id will be -1.
            //   (bz_PlayerUpdateState)  state          - The state record for the killed player at the time of the event
            //   (double)                eventTime      - Time of the event on the server.
        }
        break;

    case bz_eTickEvent: // This event is called once for each BZFS main loop
        {
            bz_TickEventData_V1* tickData = (bz_TickEventData_V1*)eventData;
            if (grabTime != -1) {
                double timeSinceGrab = tickData->eventTime - grabTime;
                if (timeSinceGrab >= 5)
                {
                    int player = bait;
                    bait = -1;
                    grabTime = -1;
                    messageNumber = 5;
                    bz_sendTextMessagef(BZ_SERVER, player, "YOU FAILED TO GET KILLED, SO YOU DIE.");
                    bz_killPlayer(player, 0, BZ_SERVER, "RG");
                }
                else if (timeSinceGrab >= 4 && messageNumber > 1)
                {
                    bz_sendTextMessagef(BZ_SERVER, bait, "ONE");
                    messageNumber = 1;
                }
                else if (timeSinceGrab >= 3 && messageNumber > 2)
                {
                    bz_sendTextMessagef(BZ_SERVER, bait, "TWO");
                    messageNumber = 2;
                }
                else if (timeSinceGrab >= 2 && messageNumber > 3)
                {
                    bz_sendTextMessagef(BZ_SERVER, bait, "THREE");
                    messageNumber = 3;
                }
                else if (timeSinceGrab >= 1 && messageNumber > 4)
                {
                    bz_sendTextMessagef(BZ_SERVER, bait, "FOUR");
                    messageNumber = 4;
                }
            }
            
            // Data
            // ---
            //    (double)  eventTime - Local Server time of the event (in seconds)
        }
        break;

    default: break;
    }
}
示例#26
0
// Displays the available match durations
void showMatchDurations(int playerID)
{
   bz_sendTextMessagef (BZ_SERVER, playerID, "Not a valid match duration, valid match durations are : ");
   for (unsigned i=0; i < timeList->size(); i++)
      bz_sendTextMessagef (BZ_SERVER, playerID, "* %s minute(s)",timeList->get(i).c_str());
}
示例#27
0
bool TimeLimit::SlashCommand ( int playerID, bz_ApiString cmd, bz_ApiString, bz_APIStringList* cmdParams )
{

  if (strcasecmp (cmd.c_str(), "timelimit")) {
	return false;
  }

  // Check permissions
  if (! bz_hasPerm(playerID,"TIMELIMIT")) {
	bz_sendTextMessagef (BZ_SERVER, playerID, "You do not have permission to run the timelimit command");
	return true;
  }

  // If the server is not configured for manual countdown the timelimit
  // command can't be used
  if (! bz_isTimeManualStart()) {
    bz_sendTextMessagef (BZ_SERVER, playerID, "This server was not configured for manual clock countdowns");
    return true;
  }

  if (cmdParams->get(0).c_str()[0] == '\0') {
    bz_sendTextMessagef (BZ_SERVER, playerID, "Usage : /timelimit <minutes>|show|reset");
    return true;
  }

  // displaying the current timelimit
  if (strcasecmp(cmdParams->get(0).c_str(),"show") == 0 ) {
    bz_sendTextMessagef (BZ_SERVER, playerID,"Match duration is set to %.0f minute(s)",(bz_getTimeLimit() / 60));
    return true;
  }

  // check if there is already a countdown in progress or if a match is
  // already in progress
  if ( bz_isCountDownInProgress() ) {
    bz_sendTextMessagef (BZ_SERVER, playerID, "There is a countdown already in progress, match duration can't be changed now");
    return true;
  } else if ( bz_isCountDownActive() ) {
    bz_sendTextMessagef (BZ_SERVER, playerID, "A game is already in progress, match duration can't be changed now");
    return true;
    }

  bz_BasePlayerRecord *playerRecord;
  playerRecord = bz_getPlayerByIndex(playerID);

  // resets the timer to the default
  if (strcasecmp(cmdParams->get(0).c_str(),"reset") == 0 ) {
    bz_setTimeLimit(saveTimeLimit);
    bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Match duration reset to %.0f minute(s) by %s",(bz_getTimeLimit() / 60),playerRecord->callsign.c_str());
    return true;
  }

  unsigned i, nonumber=0;

  for (i=0; i < strlen(cmdParams->get(0).c_str()); i++) {
     if (isdigit(cmdParams->get(0).c_str()[i]) == 0) nonumber=1;
  }

  if (nonumber == 0 ) {
    float limit = (float)atof(cmdParams->get(0).c_str());
	// Don't allow timelimit being equal or lower then 0
	if (limit > 0 ) {

	  if (! isValidTime(limit)) {

	showMatchDurations(playerID);
		return true;
      }

      bz_setTimeLimit(limit * 60);
      bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Match duration set to %.0f minute(s) by %s",(bz_getTimeLimit() / 60),playerRecord->callsign.c_str());
    } else {
	  bz_sendTextMessagef (BZ_SERVER, playerID, "Match duration can't be equal or lower then 0");
		  return true;
      }
  } else {
	bz_sendTextMessagef (BZ_SERVER, playerID, "Not a correct value");
	    return true;
    }

  return true;

}
示例#28
0
bool KeepAwayCommands::SlashCommand ( int playerID, bz_ApiString _command, bz_ApiString _message, bz_APIStringList * /*_param*/ )
{
	std::string command = _command.c_str();
	std::string message = _message.c_str();
	const char* keepermessage = _message.c_str();

	if ( command == "kas" )
	{
		if (keepaway.id != -1)
			bz_sendTextMessage (playerID, keepaway.id, keepermessage);
		else
			bz_sendTextMessage(BZ_SERVER, playerID, "There is no one keeping the flag right now.");

		return true;
	}

	if ( command == "kaf" )
	{
		if (keepaway.id == -1)
			bz_sendTextMessagef (BZ_SERVER, playerID, "The Keep Away flag is: %s", convertFlag(keepaway.flagToKeep).c_str());
		else
			bz_sendTextMessagef (BZ_SERVER, playerID, "%s has Keep Away flag: %s", keepaway.callsign.c_str(), convertFlag(keepaway.flagToKeep).c_str());

		return true;
	}

	bz_BasePlayerRecord *fromPlayer = bz_getPlayerByIndex(playerID);

	if (fromPlayer) {
	  if (!fromPlayer->admin) {
	    bz_sendTextMessage(BZ_SERVER, playerID, "You must be admin to use the keepaway commands.");
	    bz_freePlayerRecord(fromPlayer);
	    return true;
	  }

	  bz_freePlayerRecord(fromPlayer);
	}

	if ( command == "kasoundoff" )
	{
		keepaway.soundEnabled = false;
		bz_sendTextMessage (BZ_SERVER, playerID, "Keep Away sounds are disabled.");
		return true;
	}
		if ( command == "kasoundon" )
	{
		keepaway.soundEnabled = true;
		bz_sendTextMessage (BZ_SERVER, playerID, "Keep Away sounds are enabled.");
		return true;
	}

	if ( command == "kaflagresetoff" )
	{
		keepaway.flagResetEnabled = false;
		bz_sendTextMessage (BZ_SERVER, playerID, "Keep Away flag reset is disabled.");
		return true;
	}
		if ( command == "kaflagreseton" )
	{
		keepaway.flagResetEnabled = true;
		bz_sendTextMessage (BZ_SERVER, playerID, "Keep Away flag reset is enabled.");
		return true;
	}

	if ( command == "kaf+" )
	{
		if (!keepaway.forcedFlags)  // this will always create an open spot for getFlag(), if it's needed
			bz_removePlayerFlag (keepaway.id);

		keepaway.id = -1;
		keepaway.team = eNoTeam;
		keepaway.toldFlagFree = false;
		keepaway.flagToKeep = getFlag();
		keepaway.lastReminder = bz_getCurrentTime();

		bz_sendTextMessagef(BZ_SERVER, playerID, "Keep Away flag advanced to: %s", convertFlag(keepaway.flagToKeep).c_str());

		return true;
	}

	if ( command == "kaon")
	{
		keepaway.enabled = true;
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away is enabled.");
		return true;
	}

	if ( command == "kaoff")
	{
		keepaway.enabled = false;
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away is disabled.");
		return true;
	}

	if ( command == "katimemult")
	{
		double inputvalue = ConvertToNum(message, 1, 99);

		if (inputvalue > 0)
		{
			keepaway.timeMult = (inputvalue/100);
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away auto time multiplier set to %i percent.", (int)(keepaway.timeMult*100 + 0.5));
		}
		else
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away auto time multiplier must be between 1 and 99 percent.", (int)(keepaway.timeMult*100 + 0.5));

		autoTime();

		return true;
	}

	if ( command == "katimemultmin")
	{
		double inputvalue = ConvertToNum(message, 1, 99);

		if (inputvalue > 0)
		{
			keepaway.timeMultMin = (inputvalue/100);
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away auto time multiplier minimum set to %i percent.", (int)(keepaway.timeMultMin*100 + 0.5));
		}
		else
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away auto time multiplier minimum must be between 1 and 99 percent.");

		autoTime();

		return true;
	}

	if ( command == "kastatus")
	{
		if (keepaway.enabled)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away is currently enabled.");

		if (!keepaway.enabled)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away is currently disabled.");

		if (keepaway.autoTimeOn)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away automatic time adjustment is currently enabled.");

		if (!keepaway.autoTimeOn)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away automatic time adjustment is currently disabled.");

		bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away time multiplier = %i percent.", (int)(keepaway.timeMult*100 + 0.5));

		bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away time multiplier minimum = %i percent.", (int)(keepaway.timeMultMin*100 + 0.5));

		int AdjTime = (int)(keepaway.adjustedTime + 0.5);
		bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away hold time is currently set to: %i seconds", AdjTime);

		if (keepaway.forcedFlags)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away forced flags is enabled.");

		if (!keepaway.forcedFlags)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away forced flags is disabled.");

		if (keepaway.soundEnabled)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away sounds are enabled.");

		if (!keepaway.soundEnabled)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away sounds are disabled.");

		if (keepaway.flagResetEnabled)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away flag reset is enabled.");

		if (!keepaway.flagResetEnabled)
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away flag reset is disabled.");

		return true;
	}

  // explicit time command handler:

	if ( command == "katime" )
	{
		double inputvalue = ConvertToNum(message, 1, 7200);

		if (inputvalue > 0 )
		{
			keepaway.TTH = inputvalue;
			autoTime();
			int AdjTime = (int)(inputvalue + 0.5);
			bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away hold time has been set to %i seconds.", AdjTime);
		}
		else
			bz_sendTextMessagef (BZ_SERVER, playerID, "Keep Away hold time invalid: must be between 1 and 7200 seconds.");

		autoTime();

		return true;
	}

	if ( command == "kaautotimeon")
	{
		keepaway.autoTimeOn = true;
		autoTime();
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away automatic time adjustment on.");
		return true;
	}

	if ( command == "kaautotimeoff")
	{
		keepaway.autoTimeOn = false;
		keepaway.adjustedTime = keepaway.TTH;
		autoTime();
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away automatic time adjustment off.");
		return true;
	}

	if ( command == "kaffon")
	{
		keepaway.forcedFlags = true;
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Forced flags on.");
		return true;
	}

	if ( command == "kaffoff")
	{
		keepaway.forcedFlags = false;
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Forced flags off.");
		return true;
	}

	return false;
}
示例#29
0
void KeepAwayEventHandler::Event ( bz_EventData *eventData )
{
	if (eventData->eventType == bz_ePlayerDieEvent)
		KeepAwayPlayerDied(eventData);
	else if (eventData->eventType == bz_ePlayerPartEvent)
		KeepAwayPlayerLeft(eventData);
	else if (eventData->eventType == bz_ePlayerJoinEvent)
		KeepAwayPlayerJoined(eventData);
	else if (eventData->eventType == bz_ePlayerPausedEvent)
		KeepAwayPlayerPaused(eventData);

	if (eventData->eventType != bz_ePlayerUpdateEvent || !keepaway.enabled || keepaway.flagToKeep == "")
		return;

	if (keepaway.notEnoughTeams) // Not enough teams - we can leave
		return;

	checkKeepAwayHolder(); // check for someone holding flag

	if (!keepaway.toldFlagFree && keepaway.id == -1) // Flag is free - inform players
	{
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away flag: %s is free; find it and keep it!", convertFlag(keepaway.flagToKeep).c_str());
		keepaway.toldFlagFree = true;

		if ((bz_getCurrentTime() - keepaway.lastReminder) > 2 && keepaway.soundEnabled) // do not play free flag sound alert if player just won/lost (overlapping sounds)
			playAlert();
	}

	if (timeForReminder() && keepaway.id == -1)
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away flag: %s is free; find it and keep it!", convertFlag(keepaway.flagToKeep).c_str());

	if (keepaway.id == -1)  // no one has it, we can leave
		return;

	sendWarnings(getTeamColor(keepaway.team), keepaway.callsign, keepaway.startTime);

	double timeStanding = bz_getCurrentTime() - keepaway.startTime;

	if (timeStanding >= keepaway.adjustedTime) // time's up - kill 'em
	{
		if (keepaway.teamPlay && keepaway.team != eRogueTeam)
		{
			killTeams(keepaway.team, keepaway.callsign);
			bz_sendTextMessage (BZ_SERVER, keepaway.team, "Your team did it!  Go find the next Keep Away flag and keep it!");
		}
		else
		{
			killPlayers(keepaway.id, keepaway.callsign);
			bz_sendTextMessage (BZ_SERVER, keepaway.id, "You did it!  Go find the next Keep Away flag and keep it!");
		}

		if (!keepaway.forcedFlags)  // this will always create an open spot for getFlag(), if it's needed
			bz_removePlayerFlag (keepaway.id);

		keepaway.id = -1;
		keepaway.team = eNoTeam;
		keepaway.toldFlagFree = false;
		keepaway.flagToKeep = getFlag();
		keepaway.lastReminder = bz_getCurrentTime();

		return;
	}
}
示例#30
0
bool flagResetTimerHandler::SlashCommand (int playerID, bz_ApiString _command, bz_ApiString _message, bz_APIStringList *params)
{
    std::string command = _command.c_str();
    std::string message = _message.c_str();
        
    bz_BasePlayerRecord *playerdata;
    playerdata = bz_getPlayerByIndex(playerID);
    
    if(command == "flagresetunused" && (bz_hasPerm(playerID, "flagMaster")||bz_hasPerm(playerID, "FLAGMASTER")))
    {
        if(gameStyle=="ctf")
        {
            for(unsigned int i = getNumTeams(); i < bz_getNumFlags(); i++)
            {
                  if(bz_flagPlayer(i)==-1)
                      bz_resetFlag(i);
            }
        }
        else
        {
            for(unsigned int i = 0; i < bz_getNumFlags(); i++)
            {
                  if(bz_flagPlayer(i)==-1)
                      bz_resetFlag(i);
            }
        }
        
        nextReset = bz_getCurrentTime()+(timeLimitMinutes*60);
        
        return 1;
    }
    else if(command == "frsettime" && (bz_hasPerm(playerID, "flagMaster")||bz_hasPerm(playerID, "FLAGMASTER")))
    {
        double invalue = ConvertToInteger(message);
        
        if (invalue > 0)
        {
            timeLimitMinutes=invalue;
            bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Flag reset time has been set to %i minutes by %s.", timeLimitMinutes,playerdata->callsign.c_str());
            nextReset = bz_getCurrentTime()+(timeLimitMinutes*60);
        }
        else
        {
            bz_sendTextMessagef (BZ_SERVER, playerID, "Flag reset time invalid: must be between 1 and 120 minutes.");
        }

        return 1;
    }
    else if(command == "frcurrenttime")
    {
        bz_sendTextMessagef (BZ_SERVER, playerID, "Current flag reset time is set to: %i minute(s).",timeLimitMinutes);
    }
    else
    {
        bz_sendTextMessage(BZ_SERVER,playerID,"You do not have the permission to run the flag reset commands.");
    }
    
    bz_freePlayerRecord(playerdata);
    
    return 1;
}