void leagueOverSeer::loadConfig(const char* cmdLine) //Load the plugin configuration file { PluginConfig config = PluginConfig(cmdLine); std::string section = "leagueOverSeer"; if (config.errors) bz_shutdown(); //Shutdown the server //Extract all the data in the configuration file and assign it to plugin variables rotLeague = toBool(config.item(section, "ROTATIONAL_LEAGUE")); mapchangePath = config.item(section, "MAPCHANGE_PATH"); SQLiteDB = config.item(section, "SQLITE_DB"); LEAGUE_URL = config.item(section, "LEAGUE_OVER_SEER_URL"); DEBUG = atoi((config.item(section, "DEBUG_LEVEL")).c_str()); //Check for errors in the configuration data. If there is an error, shut down the server if (strcmp(LEAGUE_URL.c_str(), "") == 0) { bz_debugMessage(0, "*** DEBUG :: League Over Seer :: No URLs were choosen to report matches or query teams. ***"); bz_shutdown(); } if (DEBUG > 4 || DEBUG < 0) { bz_debugMessage(0, "*** DEBUG :: League Over Seer :: Invalid debug level in the configuration file. ***"); bz_shutdown(); } }
void nextMap ( void ) { bool shutdown = false; // compute the next map, and set the index switch(cycleMode) { case eLoopInf: currentIndex++; if (currentIndex >= (int)gameList.size()) { resetGames(); currentIndex = 0; } break; case eRandomInf: currentIndex = findRandomUnplayedGame(); if ( currentIndex < 0 ) { resetGames(); currentIndex = findRandomUnplayedGame(); } break; case eRandomOnce: currentIndex = findRandomUnplayedGame(); if ( currentIndex < 0 ) { shutdown = true; currentIndex = -1; } break; case eNoLoop: currentIndex++; if (currentIndex >= (int)gameList.size()) { shutdown = true; currentIndex = 0; } break; } sendMapChangeMessage(shutdown); if (shutdown) bz_shutdown(); else bz_restart(); startTime = -1; }
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; }