std::vector<std::string> findGroupsWithPerm( const std::string &perm, bool skipLocal )
{
  std::vector<std::string> groupsWithPerms;

  bz_APIStringList* groupList = bz_getGroupList();

  if (groupList)
  {
    for ( unsigned int i = 0; i < groupList->size();i++)
    {
      std::string groupName = groupList->get(i).c_str();

      if (skipLocal && compare_nocase(groupName,"LOCAL.ADMIN") == 0)
	continue;

      bz_APIStringList *groupPerms = bz_getGroupPerms(groupName.c_str());
      if (groupPerms)
      {
	if (permInGroup(perm,groupPerms))
	  groupsWithPerms.push_back(groupName);

	bz_deleteStringList(groupPerms);
      }
    }
    bz_deleteStringList(groupList);
  }
  return groupsWithPerms;
}
Beispiel #2
0
bool SpawnAtBase::MapObject (bz_ApiString object, bz_CustomMapObjectInfo *data)
{
    if (object != "BASESPAWNZONE" || !data)
    {
        return false;
    }

    BaseSpawnZone newZone;
    newZone.handleDefaultOptions(data);

    for (unsigned int i = 0; i < data->data.size(); i++)
    {
        std::string line = data->data.get(i).c_str();

        bz_APIStringList *nubs = bz_newStringList();
        nubs->tokenize(line.c_str(), " ", 0, true);

        if (nubs->size() > 0)
        {
            std::string key = bz_toupper(nubs->get(0).c_str());

            if (key == "COLOR" && nubs->size() == 2)
            {
                newZone.team = (bz_eTeamType)atoi(nubs->get(1).c_str());
            }
        }

        bz_deleteStringList(nubs);
    }

    TeamZones[newZone.team].push_back(newZone);

    return true;
}
Beispiel #3
0
bool KOTHMapHandler::handle(bz_ApiString object, bz_CustomMapObjectInfo * data)
{
  if (object != "KOTH" || !data)
    return false;

  // parse all the chunks
  for (unsigned int i = 0; i < data->data.size(); i++) {
    std::string line = data->data.get(i).c_str();

    bz_APIStringList *nubs = bz_newStringList();
    nubs->tokenize(line.c_str(), " ", 0, true);

    if (nubs->size() > 0) {
      std::string key = bz_toupper(nubs->get(0).c_str());

      if (key == "BBOX" && nubs->size() > 6) {
	kothzone.box = true;
	kothzone.xMin = (float) atof(nubs->get(1).c_str());
	kothzone.xMax = (float) atof(nubs->get(2).c_str());
	kothzone.yMin = (float) atof(nubs->get(3).c_str());
	kothzone.yMax = (float) atof(nubs->get(4).c_str());
	kothzone.zMin = (float) atof(nubs->get(5).c_str());
	kothzone.zMax = (float) atof(nubs->get(6).c_str());
      } else if (key == "CYLINDER" && nubs->size() > 5) {
	kothzone.box = false;
	kothzone.rad = (float) atof(nubs->get(5).c_str());
	kothzone.xMax = (float) atof(nubs->get(1).c_str());
	kothzone.yMax = (float) atof(nubs->get(2).c_str());
	kothzone.zMin = (float) atof(nubs->get(3).c_str());
	kothzone.zMax = (float) atof(nubs->get(4).c_str());
      } else if (key == "TEAMPLAY") {
	koth.teamPlay = true;
      } else if (key == "NOSOUND") {
	koth.soundEnabled = false;
      } else if (key == "AUTOTIME" && nubs->size() == 1) {
	koth.autoTimeOn = true;
      } else if (key == "AUTOTIME" && nubs->size() > 2) {
	double temp1 = (double) atof(nubs->get(1).c_str());
	double temp2 = (double) atof(nubs->get(2).c_str());
	if (temp1 >= 1 && temp1 <= 99)
	  koth.timeMult = temp1 / 100;
	if (temp2 >= 1 && temp2 <= 99)
	  koth.timeMultMin = temp2 / 100;
	koth.autoTimeOn = true;
      } else if (key == "HOLDTIME" && nubs->size() > 1) {
	double temp = (double) atof(nubs->get(1).c_str());
	if (temp >= 1 && temp <= 7200)
	  koth.TTH = temp;
      }
    }
    bz_deleteStringList(nubs);
  }
  bz_setMaxWaitTime(0.5, "KOTH");
  return true;
}
Beispiel #4
0
bool KOTHMapHandler::MapObject ( bz_ApiString object, bz_CustomMapObjectInfo *data )
{
	if (object != "KOTH" || !data)
		return false;

	kothzone.handleDefaultOptions(data);

	// parse all the chunks
	for ( unsigned int i = 0; i < data->data.size(); i++ )
	{
		std::string line = data->data.get(i).c_str();

		bz_APIStringList *nubs = bz_newStringList();
		nubs->tokenize(line.c_str()," ",0,true);

		if ( nubs->size() > 0)
		{
			std::string key = bz_toupper(nubs->get(0).c_str());

			if ( key == "TEAMPLAY")
			{
				koth.teamPlay = true;
			}
			else if ( key == "NOSOUND")
			{
				koth.soundEnabled = false;
			}
			else if ( key == "AUTOTIME" && nubs->size() == 1 )
			{
				koth.autoTimeOn = true;
			}
			else if ( key == "AUTOTIME" && nubs->size() > 2 )
			{
				double temp1 = (double)atof(nubs->get(1).c_str());
				double temp2 = (double)atof(nubs->get(2).c_str());
				if (temp1 >= 1 && temp1 <= 99)
					koth.timeMult = temp1 / 100;
				if (temp2 >= 1 && temp2 <= 99)
					koth.timeMultMin = temp2 / 100;
				koth.autoTimeOn = true;
			}
			else if ( key == "HOLDTIME" && nubs->size() > 1 )
			{
				double temp = (double)atof(nubs->get(1).c_str());
				if (temp >= 1 && temp <= 7200)
					koth.TTH = temp;
			}
		}

		bz_deleteStringList(nubs);
	}
	return true;
}
std::vector<std::string> findGroupsWithPerms( const std::vector<std::string> &perms, bool skipLocal )
{
  std::vector<std::string> groupsWithPerms;

  bz_APIStringList* groupList = bz_getGroupList();

  if (groupList)
  {
    for ( unsigned int i = 0; i < groupList->size();i++)
    {
      std::string groupName = groupList->get(i).c_str();

      if (skipLocal && compare_nocase(groupName,"LOCAL.ADMIN") == 0)
	continue;

      bz_APIStringList *groupPerms = bz_getGroupPerms(groupName.c_str());
      if (groupPerms)
      {
	// see if any of the perms are NOT in this group.
	bool hasOneWithNoPerm = false;
	for (size_t p =0; p < perms.size(); p++)
	{
	  if (!permInGroup(perms[p],groupPerms))
	    hasOneWithNoPerm = true;
	}
	bz_deleteStringList(groupPerms);

	if (!hasOneWithNoPerm)
	  groupsWithPerms.push_back(groupName);
      }
    }
    bz_deleteStringList(groupList);
  }

  return groupsWithPerms;
}
Beispiel #6
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);
  }
}
Beispiel #7
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,"-------------------------------------------");
}
Beispiel #8
0
bool FlagStayZoneHandler::MapObject ( bz_ApiString object, bz_CustomMapObjectInfo *data )
{
	if (object != "FLAGSTAYZONE" || !data)
		return false;

	FlagStayZone newZone;
	newZone.handleDefaultOptions(data);

	// parse all the chunks
	for ( unsigned int i = 0; i < data->data.size(); i++ )
	{
		std::string line = data->data.get(i).c_str();

		bz_APIStringList *nubs = bz_newStringList();
		nubs->tokenize(line.c_str()," ",0,true);

		if ( nubs->size() > 0)
		{
			std::string key = bz_toupper(nubs->get(0).c_str());

			if ( key == "FLAG" && nubs->size() > 1)
			{
				std::string flag = bz_toupper(nubs->get(1).c_str());
				newZone.flagList.push_back(flag);
			}
			else if ( key == "MESSAGE" && nubs->size() > 1 )
			{
				newZone.message = nubs->get(1).c_str();
			}
		}
	  
		bz_deleteStringList(nubs);
	}

	zoneList.push_back(newZone);
	return true;
}
Beispiel #9
0
bool KeepAwayMapHandler::MapObject ( bz_ApiString object, bz_CustomMapObjectInfo *data )
{
	if (object != "KEEPAWAY" || !data)
		return false;

	// parse all the chunks
	for ( unsigned int i = 0; i < data->data.size(); i++ )
	{
		std::string line = data->data.get(i).c_str();

		bz_APIStringList *nubs = bz_newStringList();
		nubs->tokenize(line.c_str()," ",0,true);

		if ( nubs->size() > 0)
		{
			std::string key = bz_toupper(nubs->get(0).c_str());

			if ( key == "TEAMPLAY" && nubs->size() > 0 )
				keepaway.teamPlay = true;

			else if ( key == "AUTOTIME" && nubs->size() > 0 )
				keepaway.autoTimeOn = true;

			else if ( key == "AUTOTIME" && nubs->size() > 2 )
			{
				double temp1 = (double)atof(nubs->get(1).c_str());
				double temp2 = (double)atof(nubs->get(2).c_str());
				if (temp1 >= 1 && temp1 <= 99) // if parameter out of range, keeps default
					keepaway.timeMult = temp1 / 100;
				if (temp2 >= 1 && temp2 <= 99) // if parameter out of range, keeps default
					keepaway.timeMultMin = temp2 / 100;
				keepaway.autoTimeOn = true;
			}

			else if ( key == "NOSOUND" && nubs->size() > 0 )
				keepaway.soundEnabled = false;

			else if ( key == "NOFLAGRESET" && nubs->size() > 0 )
				keepaway.flagResetEnabled = false;

			else if ( key == "HOLDTIME" && nubs->size() > 1 )
			{
				double temp = (double)atof(nubs->get(1).c_str());
				if (temp >= 1 && temp <= 7200) // if parameter out of range, keeps default
					keepaway.TTH = temp;
			}

			else if ( key == "KEEPAWAYFLAGS" && nubs->size() > 1)
			{
				for (unsigned int j = 1; j < nubs->size(); j++)
				{
					std::string flag = nubs->get(j).c_str();
					if (convertFlag(flag) != "")  // must be valid flag type, reject nub otherwise
						keepaway.flagsList.push_back(flag);
				}
			}

			else if ( key == "FORCEDFLAGS" && nubs->size() > 0 )
				keepaway.forcedFlags = true;
		}
		bz_deleteStringList(nubs);
	}

	if (!keepaway.flagsList.empty())
		keepaway.flagToKeepIndex = -1; // this will increment 1 when we get to getFlag() function;
	else
	{
		keepaway.flagToKeep = ""; // map file didn't give us any flags
		keepaway.flagToKeepIndex = 0;
	}

	return true;
}
Beispiel #10
0
  virtual bool SlashCommand ( int playerID, bz_ApiString command, bz_ApiString /*message*/, bz_APIStringList* params )
  {
    if (command == "maplist") {
      std::ifstream confStream(confFile.c_str());
      if (!confStream.fail()) {
        std::string line;

        bz_sendTextMessage(BZ_SERVER,playerID,"Available configurations: ");

        bz_APIStringList* lineList = bz_newStringList();
        while (std::getline(confStream, line))
        {
          lineList->clear();
          lineList->tokenize(line.c_str(), " \t", 2, true);

          if (lineList->size() == 2)
            bz_sendTextMessage(BZ_SERVER,playerID,(std::string(" -  ") + lineList->get(0).c_str()).c_str());
        }
        bz_deleteStringList(lineList);
      }
      return true;
    }

    bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerID);
    if (!player)
      return true;

    if (player->hasPerm("mapchange")) {
      if (!matchInProgress) {
        if (command == "maprandom") {
          std::ifstream confStream(confFile.c_str());
          std::string line;

          std::vector<std::string> mapnames;
          std::vector<std::string> mapfiles;
          bz_APIStringList* lineList = bz_newStringList();
          while (std::getline(confStream, line))
          {
            lineList->clear();
            lineList->tokenize(line.c_str(), " \t", 2, true);

            if (lineList->size() == 2) {
              mapnames.push_back(lineList->get(0).c_str());
              mapfiles.push_back(lineList->get(1).c_str());
            }
          }

          int i = rand() % mapnames.size();
          std::ofstream oputfStream(outputFile.c_str());
          oputfStream << mapfiles[i] << std::endl;
          oputfStream.close();
          bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,(std::string("Server restarting with randomly selected configuration (") + mapnames[i] + "): Requested by " + player->callsign.c_str()).c_str());
          bz_shutdown();

          bz_deleteStringList(lineList);
          bz_freePlayerRecord(player);

          return true;
        }
        if (params->size() != 1) {
          bz_sendTextMessage(BZ_SERVER,playerID,"Usage: /mapchange <confname>");
          bz_freePlayerRecord(player);

          return true;
        }

        bool done = false;
        std::ifstream confStream(confFile.c_str());
        if (!confStream.fail()) {
          std::string line;

          bz_APIStringList* lineList = bz_newStringList();
          while (std::getline(confStream, line))
          {
            lineList->clear();
            lineList->tokenize(line.c_str(), " \t", 2, true);
	    bz_ApiString thisConfName = lineList->get(0); thisConfName.tolower();
	    bz_ApiString requestedConfName = params->get(0); requestedConfName.tolower();
	    if (lineList->size() == 2 && thisConfName == requestedConfName) {
              std::ofstream oputfStream(outputFile.c_str());
              oputfStream << lineList->get(1).c_str() << std::endl;
              oputfStream.close();
              bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,(std::string("Server restarting with configuration ") + lineList->get(0).c_str() + ": Requested by " + player->callsign.c_str()).c_str());
              bz_shutdown();
              done = true;
            }
          }

          bz_deleteStringList(lineList);
        }
        if (!done) bz_sendTextMessage(BZ_SERVER,playerID,"The configuration you selected does not exist");
      }
      else {
        bz_sendTextMessage(BZ_SERVER,playerID,"Sorry, you are not allowed to change configurations when a match is in progress");
        bz_sendTextMessage(BZ_SERVER,playerID,"For this malicious activity, you will be kicked");
        bz_kickUser(playerID, "mapchange during match", true);
      }
    }
    else bz_sendTextMessage(BZ_SERVER,playerID,"Sorry, you are not allowed to change configurations on this server");

    bz_freePlayerRecord(player);

    return true;
  }
Beispiel #11
0
bool RabidRabbitHandler::MapObject(bz_ApiString object, bz_CustomMapObjectInfo *data)
{
  if (object == "RRSOUNDOFF")
    rrzoneinfo.soundEnabled = false;

  if (object == "RRCYCLEONDIE")
    rrzoneinfo.cycleOnDie = true;

  if (object != "RABIDRABBITZONE" || !data)
    return false;

  RabidRabbitZone newZone;

  // parse all the chunks
  for (unsigned int i = 0; i < data->data.size(); i++) {
    std::string line = data->data.get(i).c_str();

    bz_APIStringList *nubs = bz_newStringList();
    nubs->tokenize(line.c_str()," ",0,true);

    if (nubs->size() > 0) {
      std::string key = bz_toupper(nubs->get(0).c_str());

      if (key == "BBOX" && nubs->size() > 6) {
	newZone.box = true;
	newZone.xMin = (float)atof(nubs->get(1).c_str());
	newZone.xMax = (float)atof(nubs->get(2).c_str());
	newZone.yMin = (float)atof(nubs->get(3).c_str());
	newZone.yMax = (float)atof(nubs->get(4).c_str());
	newZone.zMin = (float)atof(nubs->get(5).c_str());
	newZone.zMax = (float)atof(nubs->get(6).c_str());
      } else if (key == "CYLINDER" && nubs->size() > 5) {
	newZone.box = false;
	newZone.rad = (float)atof(nubs->get(5).c_str());
	newZone.xMax =(float)atof(nubs->get(1).c_str());
	newZone.yMax =(float)atof(nubs->get(2).c_str());
	newZone.zMin =(float)atof(nubs->get(3).c_str());
	newZone.zMax =(float)atof(nubs->get(4).c_str());
      } else if (key == "RRZONEWW" && nubs->size() > 10) {
	newZone.WW = nubs->get(1);
	newZone.WWLifetime = (float)atof(nubs->get(2).c_str());
	newZone.WWPosition[0] = (float)atof(nubs->get(3).c_str());
	newZone.WWPosition[1] = (float)atof(nubs->get(4).c_str());
	newZone.WWPosition[2] = (float)atof(nubs->get(5).c_str());
	newZone.WWTilt = (float)atof(nubs->get(6).c_str());
	newZone.WWTilt = (newZone.WWTilt / 360) * (2 * (float)newZone.pi);
	newZone.WWDirection = (float)atof(nubs->get(7).c_str());
	newZone.WWDirection = (newZone.WWDirection / 360) * (2 * (float)newZone.pi);
	newZone.WWShotID = (int)atoi(nubs->get(8).c_str());
	newZone.WWDT = (float)atof(nubs->get(9).c_str());
	newZone.WWRepeat = (float)atof(nubs->get(10).c_str());
      } else if (key == "SERVERMESSAGE" && nubs->size() > 1) {
	newZone.servermessage = nubs->get(1).c_str();
      } else if (key == "ZONEKILLHUNTER") {
	if (nubs->size() > 1)
	  newZone.playermessage = nubs->get(1).c_str();
	newZone.zonekillhunter = true;
      }
    }
    bz_deleteStringList(nubs);
  }

  zoneList.push_back(newZone);
  return true;
}