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; }
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; }
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; }
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); } }
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,"-------------------------------------------"); }
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; }
virtual void Event ( bz_EventData *eventData ); virtual bool SlashCommand ( int playerID, bz_ApiString, bz_ApiString, bz_APIStringList*); protected: private: }; BZ_PLUGIN(TimeLimit) // variable to save the original -time value float saveTimeLimit = 0; // list to hold the available match durations bz_APIStringList* timeList = bz_newStringList(); // 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()); } // Checks if it's a valid match duration or not bool isValidTime ( float timelimit ) { if ( timeList->size() == 0 ) return true;
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; }
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; }
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; }