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; } }
void LogDetail::listPlayers( action act , bz_PlayerJoinPartEventData_V1 *data ) { bz_APIIntList *playerList = bz_newIntList(); bz_BasePlayerRecord *player = NULL; std::ostringstream msg; char playerStatus; int numPlayers; bz_getPlayerIndexList( playerList ); bz_debugMessage( 4 , "Players:" ); // // Count number of players // numPlayers = 0; for ( unsigned int i = 0; i < playerList->size(); i++ ) { player = bz_getPlayerByIndex( playerList->get(i)); if (player) { if ((player->callsign != "") && (act == join || act == auth || (data && (player->playerID != data->playerID)))) numPlayers++; bz_freePlayerRecord( player ); } } // // Display number of players, callsign, and motto string in the following format: // // PLAYERS (nn) [G]cc:callsign(ee:mottostring) // nn - number of players // G - global auth identifier (+|-| |@) // cc - count of characters in player callsign // callsign - player callsign // ee - count of characters in motto string // mottostring - player motto string // // eg. // PLAYERS (2) [@]7:Thumper(16:[email protected]) [ ]3:xxx() // msg.str(""); msg << "PLAYERS (" << numPlayers << ")"; for ( unsigned int i = 0; i < playerList->size(); i++ ) { player = bz_getPlayerByIndex( playerList->get(i)); if (player) { if ((player->callsign != "") && (act == join || act == auth || (data && (player->playerID != data->playerID)))) { playerStatus = ' '; if (player->globalUser) playerStatus = '+'; if (player->verified) playerStatus = '+'; if (player->admin && !bz_hasPerm(player->playerID, bz_perm_hideAdmin)) playerStatus = '@'; msg << " [" << playerStatus << "]"; msg << player->callsign.size() << ':'; msg << player->callsign.c_str() << "(" << bz_getPlayerMotto(player->playerID) << ")"; } } } bz_debugMessage(0, msg.str().c_str()); bz_deleteIntList(playerList); }
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; }
bool MapChangeCommandHandler::handle ( int playerID, bz_ApiString command, bz_ApiString message, bz_APIStringList *params ) { std::string cmd; tolower(command.c_str(),cmd); std::string param; if ( params && params->size() ) param = params->get(0).c_str(); if ( cmd == "mapnext" ) { if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange")) nextMap(); else bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to change maps"); return true; } else if ( cmd == "mapreset" ) { if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange")) { resetGames(); currentIndex = -1; nextMap(); } else bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to reset map rotation"); return true; } else if ( cmd == "mapcyclemode" ) { if (param.size()) { if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange")) { cycleMode = cycleFromString(param.c_str()); std::string mode = "Map Rotation Mode changed to "; mode += param.c_str(); bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,mode.c_str()); } else bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to set map modes"); } else { std::string mode = "Current Map Rotation Mode:"; mode += cycleToString(cycleMode); bz_sendTextMessage(BZ_SERVER,playerID,mode.c_str()); } return true; } else if ( cmd == "mapendmode" ) { if (param.size()) { if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange")) { startTime = bz_getCurrentTime(); endCond = condFromString(param); std::string mode = "Map End Condition changed to "; mode += param; bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,mode.c_str()); } else bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to set map modes"); } else { std::string mode = "Current End Condtion:"; mode += condToString(endCond); bz_sendTextMessage(BZ_SERVER,playerID,mode.c_str()); } return true; } else if ( cmd == "maplist" ) { bz_sendTextMessage(BZ_SERVER,playerID,"Maps In Rotation"); for (int i = 0; i < (int)gameList.size(); i++ ) bz_sendTextMessage(BZ_SERVER,playerID,gameList[i].mapFile.c_str()); return true; } else if ( cmd == "maplimit" ) { if (endCond == eNoPlayers || endCond == eManual ) { bz_sendTextMessage(BZ_SERVER,playerID,"The currnet mode has no numeric limit"); return true; } if (param.size()) { if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange")) { std::string mode = "Map Change limit changed to "; if (endCond == eTimedGame) { startTime = bz_getCurrentTime(); timeLimit = atof(param.c_str())*60; mode += param.c_str(); mode += "minutes"; } else { scoreCapLimit = atoi(param.c_str()); mode += param.c_str(); if (endCond == eMaxKillScore) mode += " Kills"; else mode += " Caps"; } bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,mode.c_str()); } else { std::string mode = "Map Change limit is "; if (endCond == eTimedGame) mode += format("%f minutes", timeLimit/60.0); else { mode += format("%d", scoreCapLimit); if (endCond == eMaxKillScore) mode += " Kills"; else mode += " Caps"; } bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to set map limits"); } } else { std::string mode = "Current End Condtion:"; mode += condToString(endCond); bz_sendTextMessage(BZ_SERVER,playerID,mode.c_str()); } return true; } return false; }
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; }
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; }
bool fairCTF::SlashCommand (int playerID, bz_ApiString /*command*/, bz_ApiString message, bz_APIStringList * /*params*/) { std::string cs = "UNKNOWN"; bz_BasePlayerRecord* pr = bz_getPlayerByIndex(playerID); if (pr != NULL) { cs = pr->callsign.c_str(); bz_freePlayerRecord (pr); } if (!bz_hasPerm(playerID, "FAIRCTF")) { bz_sendTextMessage(BZ_SERVER, playerID, (cs + ", you do not have permission to use the /ctf command.").c_str()); } else { if (message == "on") { if (!autoMode && allowCTF) { bz_sendTextMessage(BZ_SERVER, playerID, "CTF is already set to \"on\"."); } else { autoMode = false; bz_sendTextMessage (BZ_SERVER, eAdministrators, ("CTF setting has been changed to \"on\" by " + cs + ".").c_str()); if (!allowCTF) { bz_sendTextMessage (BZ_SERVER, BZ_ALLUSERS, ("CTF has been enabled by " + cs + ".").c_str()); allowCTF = true; droptime = 0.0; } } } else if (message == "off") { if (!autoMode && !allowCTF) { bz_sendTextMessage(BZ_SERVER, playerID, "CTF is already set to \"off\"."); } else { autoMode = false; bz_sendTextMessage (BZ_SERVER, eAdministrators, ("CTF setting has been changed to \"off\" by " + cs + ".").c_str()); if (allowCTF) { bz_sendTextMessage (BZ_SERVER, BZ_ALLUSERS, ("CTF has been disabled by " + cs + ".").c_str()); allowCTF = false; SetDropTime(); } } } else if (message == "auto") { if (autoMode) { bz_sendTextMessage(BZ_SERVER, playerID, "CTF is already set to \"auto\"."); } else { autoMode = true; bz_sendTextMessage (BZ_SERVER, eAdministrators, ("CTF setting has been changed to \"auto\" by " + cs + ".").c_str()); UpdateState(eNoTeam); } } else { bz_sendTextMessage (BZ_SERVER, playerID, "Usage: /ctf on|off|auto"); } } return true; }