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."); } }
virtual bool SlashCommand ( int playerID, bz_ApiString /*command*/, bz_ApiString /*message*/, bz_APIStringList* /*params*/ ) { bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerID); if (!player) return true; if ( !player->admin ) { bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permission to run /killall"); bz_freePlayerRecord(player); return true; } std::string msg = player->callsign.c_str(); msg += " has killed everyone"; bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,msg.c_str()); bz_APIIntList *playerList = bz_newIntList(); bz_getPlayerIndexList ( playerList ); for ( unsigned int i = 0; i < playerList->size(); i++ ) bz_killPlayer(playerList->get(i),false); bz_freePlayerRecord(player); bz_deleteIntList(playerList); return true; }
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; } } }
void RogueGenoHandler::Event (bz_EventData *eventData) { switch (eventData->eventType) { default: // no clue break; // wait for a tank death and start checking for genocide and rogues case bz_ePlayerDieEvent: { bz_PlayerDieEventData_V1 *dieData = (bz_PlayerDieEventData_V1*)eventData; //if its not a genocide kill, dont care if (dieData->flagKilledWith != "G") break; // if the tank killed was not a rogue, let the server/client do the normal killing if (dieData->team != eRogueTeam) break; // option to disallow rogues getting points for shooting themselves if (!allowSuicide && dieData->killerID == dieData->playerID) break; // if the tank killed was a rogue, kill all rogues. bz_APIIntList *playerList = bz_newIntList(); bz_getPlayerIndexList(playerList); for (unsigned int i = 0; i < playerList->size(); i++) { int targetID = (*playerList)[i]; bz_BasePlayerRecord *playRec = bz_getPlayerByIndex (targetID); if (!playRec) continue; // the sucker is a spawned rogue, kill him. This generates another death event, // so if you kill another rogue with geno while you are a rogue you end up dead too. // and you get both messages (victim and be careful) if (playRec->spawned && playRec->team == eRogueTeam) { bz_killPlayer(targetID, false, dieData->killerID, "G"); bz_sendTextMessage(BZ_SERVER, targetID, "You were a victim of Rogue Genocide"); // oops, I ended up killing myself (directly or indirectly) with Genocide! if (targetID == dieData->killerID) bz_sendTextMessage(BZ_SERVER, targetID, "You should be more careful with Genocide!"); } bz_freePlayerRecord(playRec); } bz_deleteIntList(playerList); } break; } }
void KeepAwayPlayerPaused( bz_EventData *eventData ) { if (eventData->eventType != bz_ePlayerPausedEvent || !keepaway.enabled || keepaway.flagToKeep == "") return; bz_PlayerPausedEventData_V1 *PauseData = (bz_PlayerPausedEventData_V1*)eventData; bz_BasePlayerRecord *player = bz_getPlayerByIndex(PauseData->playerID); if (player) { const char* flagHeld = bz_getPlayerFlag(player->playerID); if (flagHeld) { if (flagHeld == keepaway.flagToKeep) { bz_removePlayerFlag (player->playerID); bz_sendTextMessage (BZ_SERVER, PauseData->playerID, "Flag removed - cannot pause while holding flag."); keepaway.id = -1; keepaway.team = eNoTeam; keepaway.toldFlagFree = false; } } } bz_freePlayerRecord(player); return; }
void killAllHunters(std::string messagepass) { 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 != eRabbitTeam) { bz_killPlayer(player->playerID, true, BZ_SERVER); bz_sendTextMessage(BZ_SERVER, player->playerID, messagepass.c_str()); if (rrzoneinfo.soundEnabled) bz_sendPlayCustomLocalSound(player->playerID,"flag_lost"); } if (player->team == eRabbitTeam && rrzoneinfo.soundEnabled && bz_getTeamCount(eHunterTeam) > 0) bz_sendPlayCustomLocalSound(player->playerID,"flag_won"); bz_freePlayerRecord(player); } } bz_deleteIntList(playerList); return; }
void RegFlag::Event ( bz_EventData *eventData ) { bz_BasePlayerRecord *player = NULL; int playerID = -1; switch (eventData->eventType) { case bz_ePlayerUpdateEvent: playerID = ((bz_PlayerUpdateEventData_V1*)eventData)->playerID; break; case bz_eShotFiredEvent: playerID = ((bz_PlayerUpdateEventData_V1*)eventData)->playerID; break; default: return; } player = bz_getPlayerByIndex(playerID); if (!player) return; if (player->globalUser) { bz_freePlayerRecord(player); return; } bz_freePlayerRecord(player); const char* flagAbrev = bz_getPlayerFlag(playerID); if (!flagAbrev) return; bz_removePlayerFlag(playerID); bz_sendTextMessage(BZ_SERVER,playerID, "Flags are for registered players only"); }
void killmsg::Event ( bz_EventData *eventData ) { if(eventData->eventType==bz_ePlayerDieEvent) { bz_PlayerDieEventData_V1* data = (bz_PlayerDieEventData_V1*)eventData; bz_BasePlayerRecord *playerdata; //create a playerrecord for the dead player. playerdata = bz_getPlayerByIndex(data->playerID); //get data bz_BasePlayerRecord *killerdata; //another playerrecord for the killer killerdata = bz_getPlayerByIndex(data->killerID); //get data if(killerdata&&playerdata) { //now we create a message to send to the killer std::string killermessage = std::string("You killed ") + playerdata->callsign.c_str(); if(data->killerID==data->playerID && killmyself==1) { //This kill is the kill you get after a teamkill... killmyself=0; } else if(data->killerID==data->playerID) { bz_sendTextMessage(BZ_SERVER,data->killerID,"You commited suicide! Don't do that again!"); } else if(killerdata->team==playerdata->team && killerdata->team!=eRogueTeam) { //Here we check whether the kill was a team kill if(triti)killmyself=1; //The plugin gets confused if you get killed after a teamkill std::string tkmessage = std::string("You killed teamate ") + playerdata->callsign.c_str() + std::string("! Don't do that again!") ; bz_sendTextMessage(BZ_SERVER,data->killerID,tkmessage.c_str()); } else { //Send the first message if no TK or suicide bz_sendTextMessage(BZ_SERVER,data->killerID,killermessage.c_str()); } } //free the records here bz_freePlayerRecord(playerdata); bz_freePlayerRecord(killerdata); } }
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,"-------------------------------------------"); }
void sendMapChangeMessage ( bool end ) { std::string message = "Map change!\n"; bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,message.c_str()); if (end) { message = "Good bye!\n"; } else { message = "Please Rejoin!\n"; } bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, message.c_str()); if (!end) { bz_sendJoinServer(BZ_ALLUSERS, bz_getPublicAddr().c_str(), bz_getPublicPort(), eNoTeam, bz_getPublicAddr().c_str(), "Map change"); } }
void fairCTF::SetDropTime() { bz_APIIntList *playerList = bz_newIntList(); bz_getPlayerIndexList(playerList); bool TeamFlagIsCarried = false; // is any tank carrying a team flag? for (unsigned int i = 0; i < playerList->size(); i++) { const char *FlagHeld = bz_getPlayerFlag((*playerList)[i]); if (FlagHeld != NULL && (strcmp(FlagHeld, "R*") == 0 || strcmp(FlagHeld, "G*") == 0 || strcmp(FlagHeld, "B*") == 0 || strcmp(FlagHeld, "P*") == 0)) { TeamFlagIsCarried = true; break; } } bz_deleteIntList(playerList); // announce drop delay only if some tank is carrying a team flag if (TeamFlagIsCarried) { if (drop_delay >= 0) { droptime = bz_getCurrentTime() + (double)drop_delay; if (drop_delay > 1) { bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, bz_format("Currently-held team flags will be dropped in %d seconds.", drop_delay)); } else { bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Currently-held team flags will be dropped in 1 second."); } } else { bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Currently-held team flags will not be dropped."); } } }
bool onePlayer() { int numPlayers = bz_getTeamCount(eRedTeam) + bz_getTeamCount(eGreenTeam) + bz_getTeamCount(eBlueTeam) + bz_getTeamCount(ePurpleTeam) + bz_getTeamCount(eRogueTeam); if (numPlayers <= 1) { if (!koth.onePlayerWarn) bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "King of the Hill disabled: less than 2 players."); koth.onePlayerWarn = true; return true; } else { if (koth.onePlayerWarn) bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "King of the Hill enabled: more than 1 player."); koth.onePlayerWarn = false; return false; } }
void fairCTF::UpdateState(bz_eTeamType teamLeaving) { if (autoMode) { bool fair = isEven(teamLeaving); if (fair && !allowCTF) { allowCTF = true; droptime = 0.0; bz_sendTextMessage (BZ_SERVER, BZ_ALLUSERS, "Team sizes are sufficiently even. CTF play is now enabled."); } else if (!fair && allowCTF) { allowCTF = false; bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Team sizes are uneven. CTF play is now disabled."); SetDropTime(); } } }
std::string getFlag() { if (keepaway.flagToKeepIndex < -1) // this should never happen, but save a crash if something goes nuts return ""; // get next flag; if not free take it from player (if forced flags) for (unsigned int h = 0; h < keepaway.flagsList.size(); h++) // check all specified flags { keepaway.flagToKeepIndex++; // get next one in line if (keepaway.flagToKeepIndex > ((int)keepaway.flagsList.size() - 1)) // go back to start if at end keepaway.flagToKeepIndex = 0; std::string flagCandidate = keepaway.flagsList[keepaway.flagToKeepIndex]; bool flagNotHeld = true; 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) { const char* playerFlag = bz_getPlayerFlag(player->playerID); if (playerFlag) { if (playerFlag == flagCandidate && keepaway.forcedFlags) // take it, if forced flags { bz_removePlayerFlag (player->playerID); bz_sendTextMessage (BZ_SERVER, player->playerID, "Sorry, server needs your flag for Keep Away :/"); } if (playerFlag == flagCandidate && !keepaway.forcedFlags) // look for next free flag in list flagNotHeld = false; } } bz_freePlayerRecord(player); } bz_deleteIntList(playerList); if (flagNotHeld) return flagCandidate; } if (!keepaway.flagsList.empty()) // we should never get here, but if we do keep going return keepaway.flagsList[0]; else return ""; }
inline bool oneTeam(bz_eTeamType leavingPlayerTeam) { int RT = bz_getTeamCount(eRedTeam); int GT = bz_getTeamCount(eGreenTeam); int BT = bz_getTeamCount(eBlueTeam); int PT = bz_getTeamCount(ePurpleTeam); int RGT = bz_getTeamCount(eRogueTeam); if (leavingPlayerTeam == eRedTeam) RT--; if (leavingPlayerTeam == eGreenTeam) GT--; if (leavingPlayerTeam == eBlueTeam) BT--; if (leavingPlayerTeam == ePurpleTeam) PT--; if (leavingPlayerTeam == eRogueTeam) RGT--; int Test1 = (RT * GT) + (RT * BT) + (RT * PT) + (GT * BT) + (GT * PT) + (BT * PT); int Test2 = RT + GT + BT + PT + RGT; if (Test1 < 1 && Test2 < 2) { if (!keepaway.oneTeamWarn) bz_sendTextMessage (BZ_SERVER, BZ_ALLUSERS, "Keep Away disabled: less than 2 teams."); keepaway.oneTeamWarn = true; return true; } else { if (keepaway.oneTeamWarn) bz_sendTextMessage (BZ_SERVER, BZ_ALLUSERS, "Keep Away enabled: more than 1 team."); keepaway.oneTeamWarn = false; return false; } }
void fairCTF::Event(bz_EventData *eventData) { if (eventData->eventType == bz_eAllowFlagGrab) { bz_AllowFlagGrabData_V1* grabData = (bz_AllowFlagGrabData_V1*)eventData; if (!allowCTF) { // Don't allow a team flag grab std::string flagtype = bz_getFlagName(grabData->flagID).c_str(); if (flagtype == "R*" || flagtype == "G*" || flagtype == "B*" || flagtype == "P*") { grabData->allow = false; bz_sendTextMessage (BZ_SERVER, grabData->playerID, "CTF play is currently disabled."); } } } else if (eventData->eventType == bz_ePlayerJoinEvent) { UpdateState(eNoTeam); } else if (eventData->eventType == bz_ePlayerPartEvent) { bz_PlayerJoinPartEventData_V1* partData = (bz_PlayerJoinPartEventData_V1*)eventData; // Need to compensate for that leaving player. UpdateState(partData->record->team); } else if (eventData->eventType == bz_eTickEvent) { if (droptime != 0.0 && bz_getCurrentTime() >= droptime) { // Time to drop any team flags. bz_APIIntList* pl = bz_getPlayerIndexList(); for (unsigned int x = 0; x < pl->size(); x++) { DropTeamFlag(pl->get(x)); } droptime = 0.0; } } else { // Huh? return; } }
void NoRogueGenocide::Event ( bz_EventData * eventData ) { std::string geno = "G"; switch (eventData->eventType) { case bz_eFlagGrabbedEvent: { bz_FlagGrabbedEventData_V1 *grabData = (bz_FlagGrabbedEventData_V1*)eventData; std::string flagType = bz_getFlagName(grabData->flagID).c_str(); // Do nothing if we are on seamless mode if (seamlessMode) return; // Do nothing if the flag isn't Genocide if (flagType != geno) return; // Do nothing if the player is not a rogue if (bz_getPlayerTeam(grabData->playerID) != eRogueTeam) return; if (!silentMode) bz_sendTextMessage(BZ_SERVER, grabData->playerID, "You can't pick up Genocide if you are a rogue!"); bz_removePlayerFlag(grabData->playerID); } break; case bz_eShotFiredEvent: { bz_ShotFiredEventData_V1 *shotData = (bz_ShotFiredEventData_V1*)eventData; std::string shotType = shotData->type.c_str(); // Do nothing if the shot doesn't originate from a geno flag if (shotType != geno) return; // Do nothing if the player is not a rogue if (bz_getPlayerTeam(shotData->playerID) != eRogueTeam) return; // Convert the shot to a regular one shotData->type = ""; shotData->changed = true; } break; default: return; } }
void KOTHPlayerPaused::process(bz_EventData * eventData) { if (eventData->eventType != bz_ePlayerPausedEvent || !koth.enabled) return; bz_PlayerPausedEventData_V1 *PauseData = (bz_PlayerPausedEventData_V1 *) eventData; bz_BasePlayerRecord *player = bz_getPlayerByIndex(PauseData->playerID); if (player) { if (kothzone.pointIn(player->currentState.pos)) { bz_killPlayer(PauseData->playerID, true, BZ_SERVER); bz_sendTextMessage(BZ_SERVER, PauseData->playerID, "Cannot pause while on the Hill."); } } bz_freePlayerRecord(player); return; }
void fairCTF::DropTeamFlag(int playerID) { bz_BasePlayerRecord* droppr = bz_getPlayerByIndex (playerID); if (droppr != NULL) { // Are they carrying a team flag? if (droppr->currentFlag == "Red team flag" || droppr->currentFlag == "Green team flag" || droppr->currentFlag == "Blue team flag" || droppr->currentFlag == "Purple team flag") { bz_removePlayerFlag(playerID); bz_sendTextMessage (BZ_SERVER, playerID, "CTF play is currently disabled."); } bz_freePlayerRecord(droppr); } }
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; }
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; }
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; } }
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; }
inline void KOTHEventHandler::process(bz_EventData * eventData) { if (!koth.enabled) // King of the Hill disabled - we can leave return; if (onePlayer()) // Not enough players - we can leave return; float pos[3] = { 0 }; int playerID = -1; switch (eventData->eventType) { case bz_ePlayerUpdateEvent: pos[0] = ((bz_PlayerUpdateEventData_V1 *) eventData)->state.pos[0]; pos[1] = ((bz_PlayerUpdateEventData_V1 *) eventData)->state.pos[1]; pos[2] = ((bz_PlayerUpdateEventData_V1 *) eventData)->state.pos[2]; playerID = ((bz_PlayerUpdateEventData_V1 *) eventData)->playerID; break; case bz_eShotFiredEvent: pos[0] = ((bz_ShotFiredEventData_V1 *) eventData)->pos[0]; pos[1] = ((bz_ShotFiredEventData_V1 *) eventData)->pos[1]; pos[2] = ((bz_ShotFiredEventData_V1 *) eventData)->pos[2]; playerID = ((bz_ShotFiredEventData_V1 *) eventData)->playerID; break; default: return; } if (!koth.toldHillOpen && koth.id == -1) // Hill is open - inform players { bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Hill is not controlled - take it!"); koth.toldHillOpen = true; } if (kothzone.pointIn(pos)) // player is on Hill { bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerID); if (player) { if (player->playerID != koth.playerJustWon && player->spawned) { if ((koth.id == -1 && player->team != koth.team) || (koth.id == -1 && teamClear(koth.team))) initiatekoth(player->team, player->callsign, player->playerID); double timeStanding = bz_getCurrentTime() - koth.startTime; if (timeStanding >= koth.adjustedTime && koth.id != -1) // time's up - kill 'em { if (koth.teamPlay && koth.team != eRogueTeam) killTeams(koth.team, koth.callsign); else killPlayers(koth.id, koth.callsign); if (!koth.teamPlay || koth.team == eRogueTeam) bz_sendTextMessage(BZ_SERVER, koth.id, "You are King of the Hill! You must leave hill to retake it."); else bz_sendTextMessage(BZ_SERVER, koth.team, "Your team is King of the Hill! Entire team must leave hill to retake it."); koth.playerJustWon = koth.id; koth.id = -1; return; } if (koth.id != -1) sendWarnings(getTeamColor(koth.team), koth.callsign, koth.startTime); } } bz_freePlayerRecord(player); } else { // player is off Hill if (playerID == koth.playerJustWon) koth.playerJustWon = -1; if (playerID == koth.id) { koth.id = -1; koth.team = eNoTeam; } } }
void PlayHistoryTracker::Event(bz_EventData *eventData) { switch (eventData->eventType) { default: break; case bz_ePlayerDieEvent: { bz_PlayerDieEventData_V1 *deathRecord = (bz_PlayerDieEventData_V1*)eventData; // Create variables to store the callsigns std::string victimCallsign = "UNKNOWN"; std::string killerCallsign = "UNKNOWN"; // Get player records for victim and killer bz_BasePlayerRecord *victimData = bz_getPlayerByIndex(deathRecord->playerID); bz_BasePlayerRecord *killerData = bz_getPlayerByIndex(deathRecord->killerID); // If we have valid data, update the callsigns if (victimData) victimCallsign = victimData->callsign.c_str(); if (killerData) killerCallsign = killerData->callsign.c_str(); // Free the player records bz_freePlayerRecord(victimData); bz_freePlayerRecord(killerData); // Handle the victim if (spreeCount.find(deathRecord->playerID) != spreeCount.end()) { // Store a quick reference to their former spree count int spreeTotal = spreeCount[deathRecord->playerID]; std::string message; // Generate an appropriate message, if any if (spreeTotal >= 5 && spreeTotal < 10) message = victimCallsign + std::string("'s rampage was stopped by ") + killerCallsign; else if (spreeTotal >= 10 && spreeTotal < 20) message = victimCallsign + std::string("'s killing spree was halted by ") + killerCallsign; else if (spreeTotal >= 20) message = std::string("The unstoppable reign of ") + victimCallsign + std::string(" was ended by ") + killerCallsign; // If we have a message to send, then send it if (message.size()) bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, message.c_str()); // Since they died, release their spree counter spreeCount[deathRecord->playerID] = 0; } // Handle the killer (if it wasn't also the victim) if (deathRecord->playerID != deathRecord->killerID && spreeCount.find(deathRecord->killerID) != spreeCount.end()) { // Store a quick reference to their newly incremented spree count int spreeTotal = ++spreeCount[deathRecord->playerID]; std::string message; // Generate an appropriate message, if any if (spreeTotal == 5) message = victimCallsign + std::string(" is on a Rampage!"); else if (spreeTotal == 10) message = victimCallsign + std::string(" is on a Killing Spree!"); else if (spreeTotal == 20) message = victimCallsign + std::string(" is Unstoppable!!"); else if (spreeTotal > 20 && spreeTotal%5 == 0) message = victimCallsign + std::string(" continues to rage on"); // If we have a message to send, then send it if (message.size()) bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, message.c_str()); } } break; case bz_ePlayerJoinEvent: { // Initialize the spree counter for the player that just joined spreeCount[((bz_PlayerJoinPartEventData_V1*)eventData)->playerID] = 0; } break; case bz_ePlayerPartEvent: { // Erase the spree counter for the player that just left std::map<int, int >::iterator itr = spreeCount.find(((bz_PlayerJoinPartEventData_V1*)eventData)->playerID); if (itr != spreeCount.end()) spreeCount.erase(itr); } break; } }
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; }
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; } }
void rabbitTimer::Event(bz_EventData *eventData) { if (eventData->eventType == bz_eTickEvent) { bz_TickEventData_V1* tickdata = (bz_TickEventData_V1*)eventData; if (currentRabbit != -1 && tickdata->eventTime >= rabbitDeathTime) { //kill the wabbit! bz_killPlayer(currentRabbit, false, BZ_SERVER); //stopgap. the kill event should do this, really... currentRabbit = -1; rabbitDeathTime = (float)tickdata->eventTime + rabbitKillTimeLimit; bz_sendTextMessage (BZ_SERVER, BZ_ALLUSERS, "Time's up! Selecting new rabbit."); } else if (currentRabbit == -1 && bz_getTeamCount(eHunterTeam) >= 3) //make sure we've got enough people before reactivating the timer { //find the new rabbit bz_APIIntList pl; bz_getPlayerIndexList(&pl); for (unsigned int i = 0; i < pl.size() && currentRabbit == -1; i++) { bz_BasePlayerRecord* pr = bz_getPlayerByIndex(pl.get(i)); if (pr != NULL) { if (pr->team == eRabbitTeam) { currentRabbit = pr->playerID; int limit = (int)rabbitKillTimeLimit; bz_sendTextMessage(BZ_SERVER, currentRabbit, bz_format("You have %d seconds to make a kill!", limit)); } bz_freePlayerRecord(pr); } } } } else if (eventData->eventType == bz_ePlayerDieEvent) { bz_PlayerDieEventData_V1* killdata = (bz_PlayerDieEventData_V1*)eventData; if (killdata->team == eRabbitTeam) { currentRabbit = -1; //we will sort this out on the next tick rabbitDeathTime = (float)killdata->eventTime + rabbitKillTimeLimit; } else if (killdata->killerTeam == eRabbitTeam && currentRabbit != -1) { if (rollOver) { rabbitDeathTime += rabbitKillTimeLimit; int limit = (int)rabbitKillTimeLimit; int timeremaining = (int)(rabbitDeathTime - killdata->eventTime); bz_sendTextMessage(BZ_SERVER, currentRabbit, bz_format("+%d seconds: %d seconds remaining.", limit, timeremaining)); } else { rabbitDeathTime = (float)killdata->eventTime + rabbitKillTimeLimit; int limit = (int)rabbitKillTimeLimit; bz_sendTextMessage(BZ_SERVER, currentRabbit, bz_format("%d seconds remaining.", limit)); } } } else if (eventData->eventType == bz_ePlayerDieEvent) { bz_PlayerJoinPartEventData_V1* partdata = (bz_PlayerJoinPartEventData_V1*)eventData; if (partdata->record->team == eRabbitTeam) //we need to select a new rabbit if the rabbit leaves. { currentRabbit = -1; //we will sort this out on the next tick rabbitDeathTime = (float)partdata->eventTime + rabbitKillTimeLimit; } } }
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; }