inline bool timeForReminder() { double timeLeft = bz_getCurrentTime() - keepaway.lastReminder; if (timeLeft >= keepaway.reminderPeriod) { keepaway.lastReminder = bz_getCurrentTime(); return true; } return false; }
void ResetFlagData(){ tfr.redLastTouched = bz_getCurrentTime(); tfr.greenLastTouched = bz_getCurrentTime(); tfr.blueLastTouched = bz_getCurrentTime(); tfr.purpleLastTouched = bz_getCurrentTime(); tfr.redFlagWasHeld = false; tfr.greenFlagWasHeld = false; tfr.blueFlagWasHeld = false; tfr.purpleFlagWasHeld = false; }
void ResetZeroTeams() { if (bz_getTeamCount(eRedTeam) == 0) { tctf.redLastTime = bz_getCurrentTime (); tctf.redLastWarn = bz_getCurrentTime (); } if (bz_getTeamCount(eGreenTeam) == 0) { tctf.greenLastTime = bz_getCurrentTime (); tctf.greenLastWarn = bz_getCurrentTime (); } if (bz_getTeamCount(eBlueTeam) == 0) { tctf.blueLastTime = bz_getCurrentTime (); tctf.blueLastWarn = bz_getCurrentTime (); } if (bz_getTeamCount(ePurpleTeam) == 0) { tctf.purpleLastTime = bz_getCurrentTime (); tctf.purpleLastWarn = bz_getCurrentTime (); } return; }
TFR() { idleTime = 300; redLastTouched = bz_getCurrentTime(); greenLastTouched = bz_getCurrentTime(); blueLastTouched = bz_getCurrentTime(); purpleLastTouched = bz_getCurrentTime(); redFlagWasHeld = false; greenFlagWasHeld = false; blueFlagWasHeld = false; purpleFlagWasHeld = false; OKToReset = false; timerOff = false; flagTouched =""; }
BZF_PLUGIN_CALL int bz_Load(const char* /*commandLine*/) { registered = bz_callbackExists("RegisterHTTPDVDir"); if (!registered) { if(server) delete(server); server = new HTTPServer; srand((unsigned int)bz_getCurrentTime()); bz_registerCallBack("RegisterHTTPDVDir",&RegisterVDir); bz_registerCallBack("RemoveHTTPDVDir",&RemoveVDir); bz_registerEvent (bz_eTickEvent,server); bz_registerEvent (bz_eNewNonPlayerConnection,server); serverVersion = bz_getServerVersion(); registered = true; bz_debugMessage(4,"HTTPServer plug-in loaded"); } else { bz_debugMessage(1,"HTTPServer *WARNING* plug-in loaded more then once, this instance will not be used"); } return 0; }
GameInfo::GameInfo(Templateiser &ts) { ts.addKey("MapFile",this); ts.addKey("RedTeamScore",this); ts.addKey("RedTeamWins",this); ts.addKey("RedTeamLosses",this); ts.addKey("GreenTeamScore",this); ts.addKey("GreenTeamWins",this); ts.addKey("GreenTeamLosses",this); ts.addKey("BlueTeamScore",this); ts.addKey("BlueTeamWins",this); ts.addKey("BlueTeamLosses",this); ts.addKey("PurpleTeamScore",this); ts.addKey("PurpleTeamWins",this); ts.addKey("PurpleTeamLosses",this); ts.addKey("KBIn",this); ts.addKey("KBOut",this); bz_registerEvent(bz_eGetWorldEvent,this); bz_registerEvent(bz_eNetDataReceiveEvent,this); bz_registerEvent(bz_eNetDataSendEvent,this); startTime = bz_getCurrentTime(); bytesIn = 0; bytesOut = 0; mapFile = "Unknown"; }
void GameInfo::keyCallback (std::string &data, const std::string &key) { double now = bz_getCurrentTime(); if (key == "mapfile") data += mapFile; else if ( key == "redteamscore") data += format("%d",bz_getTeamScore(eRedTeam)); else if ( key == "redteamwins") data += format("%d",bz_getTeamWins(eRedTeam)); else if ( key == "redteamlosses") data += format("%d",bz_getTeamLosses(eRedTeam)); else if ( key == "greenteamscore") data += format("%d",bz_getTeamScore(eGreenTeam)); else if ( key == "greenteamwins") data += format("%d",bz_getTeamWins(eGreenTeam)); else if ( key == "greenteamlosses") data += format("%d",bz_getTeamLosses(eGreenTeam)); else if ( key == "blueteamscore") data += format("%d",bz_getTeamScore(eBlueTeam)); else if ( key == "blueteamwins") data += format("%d",bz_getTeamWins(eBlueTeam)); else if ( key == "blueteamlosses") data += format("%d",bz_getTeamLosses(eBlueTeam)); else if ( key == "purpleteamscore") data += format("%d",bz_getTeamScore(ePurpleTeam)); else if ( key == "purpleteamwins") data += format("%d",bz_getTeamWins(ePurpleTeam)); else if ( key == "purpleteamlosses") data += format("%d",bz_getTeamLosses(ePurpleTeam)); else if ( key == "kbin") data += format("%f",(double)bytesIn/1024.0); else if ( key == "kbout") data += format("%f",(double)bytesOut/1024.0); }
KeepAway() { id = -1; startTime = 0; team = eNoTeam; callsign = ""; flagsList.clear(); TTH = 120; adjustedTime = 120; timeMult = 0.03; timeMultMin = 0.50; lastReminder = bz_getCurrentTime(); reminderPeriod = 60; enabled = true; toldFlagFree = false; oneTeamWarn = false; autoTimeOn = false; forcedFlags = false; notEnoughTeams = true; soundEnabled = true; teamPlay = false; flagResetEnabled = true; TTHminutes = 0; TTHseconds = 30; flagToKeepIndex = 0; flagToKeep = "Initiate"; }
void autoFlagReset::Init (const char* commandLine) { std::string cl = commandLine; incremental = false; freq = 900.0; nextFlag = 0; nextRunTime = bz_getCurrentTime(); if (nextRunTime < 0.0) { nextRunTime = 0.0; } if (cl.length() > 0) { if (cl.at(cl.length() - 1) == 'i' || cl.at(cl.length() - 1) == 'I') { // Incremental mode. incremental = true; cl = cl.substr(0, cl.length() - 1); } double newfreq = atof(cl.c_str()); if (newfreq > 0.0) { freq = newfreq * 60.0; } } Register(bz_eTickEvent); bz_debugMessage(4,"autoFlagReset plugin loaded"); }
void sendWarnings(const char *teamcolor, std::string playercallsign, double kothstartedtime) { double TimeElapsed = bz_getCurrentTime() - kothstartedtime; double TimeRemaining = koth.adjustedTime - TimeElapsed; int toTens = int ((TimeRemaining + 5) / 10) * 10; if ((TimeRemaining / 60) < koth.TTHminutes && koth.adjustedTime > 59) { if (!koth.teamPlay || koth.team == eRogueTeam) bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s will be King in %i secs!", playercallsign.c_str(), toTens); else bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s (%s) will be King in %i secs!", teamcolor, playercallsign.c_str(), toTens); koth.TTHminutes--; } if (koth.adjustedTime < koth.TTHseconds) { koth.TTHseconds = koth.TTHseconds - 10; return; } if (TimeRemaining < koth.TTHseconds) { if (!koth.teamPlay || koth.team == eRogueTeam) bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s will be King in %i secs!", playercallsign.c_str(), koth.TTHseconds); else bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s (%s) will be King in %i secs!", teamcolor, playercallsign.c_str(), koth.TTHseconds); koth.TTHseconds = koth.TTHseconds - 10; } return; }
void sendWarnings(const char* teamcolor, std::string playercallsign, double keepawaystartedtime) { double TimeElapsed = bz_getCurrentTime() - keepawaystartedtime; double TimeRemaining = keepaway.adjustedTime - TimeElapsed; int toTens = int((TimeRemaining + 5) / 10) * 10; if ((TimeRemaining/60) < keepaway.TTHminutes && keepaway.adjustedTime > 59 && TimeRemaining >= 1) { if (!keepaway.teamPlay || keepaway.team == eRogueTeam) bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s has %s flag; %i secs left!", playercallsign.c_str(), keepaway.flagToKeep.c_str(), toTens); else bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s (%s) has %s flag; %i secs left!", teamcolor, playercallsign.c_str(), keepaway.flagToKeep.c_str(), toTens); keepaway.TTHminutes--; } if (keepaway.adjustedTime < keepaway.TTHseconds) { keepaway.TTHseconds = keepaway.TTHseconds - 10; return; } if (TimeRemaining < keepaway.TTHseconds && TimeRemaining >= 1) { if (!keepaway.teamPlay || keepaway.team == eRogueTeam) bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s has %s flag; %i secs left!", playercallsign.c_str(), keepaway.flagToKeep.c_str(), keepaway.TTHseconds); else bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s (%s) has %s flag; %i secs left!", teamcolor, playercallsign.c_str(), keepaway.flagToKeep.c_str(), keepaway.TTHseconds); keepaway.TTHseconds = keepaway.TTHseconds - 10; } return; }
int TeamCheck(bz_eTeamType Team, const char* Color, double LastWarn, double LastTime) { if (bz_getTeamCount(Team) != 0 && tctf.timerRunning) { tctf.timeElapsed = bz_getCurrentTime() - LastTime; tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed; if (bz_getCurrentTime() - LastWarn > 60) { tctf.adjTime = (int)(tctf.timeRemaining / 60); bz_sendTextMessagef (BZ_SERVER, Team, "%s Team: less than %i minute(s) left to capture a flag!", Color, tctf.adjTime + 1); return 1; // 1 = reset team's LastWarn } if (bz_getCurrentTime() - LastWarn > 30 && tctf.timeRemaining < 30) { bz_sendTextMessagef (BZ_SERVER, Team, "%s Team: less than 30 seconds left to capture a flag!", Color); return 1; // 1 = reset team's LastWarn } if (bz_getCurrentTime() - LastWarn > 10 && tctf.timeRemaining < 20 && tctf.timeRemaining > 10) { bz_sendTextMessagef (BZ_SERVER, Team, "%s Team: less than 20 seconds left to capture a flag!", Color); return 1; // 1 = reset team's LastWarn } if (bz_getCurrentTime() - LastWarn > 10 && tctf.timeRemaining < 10 && tctf.timeRemaining > 1) { bz_sendTextMessagef (BZ_SERVER, Team, "%s Team: less than 10 seconds left to capture a flag!", Color); return 1; // 1 = reset team's LastWarn } if (tctf.timeElapsed >= tctf.timeLimit) { KillTeam(Team); bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s team did not capture any other team flags in time.", Color); tctf.adjTime = (int)(tctf.timeLimit / 60 + 0.5); bz_sendTextMessagef (BZ_SERVER, Team, "CTF timer is reset to %i minutes for the %s team.", tctf.adjTime, Color); return 2; // 2 = reset team's LastWarn and LastTime } } return 0; // 0 = no need to reset teams LastWarn or LastTime }
void ResetTeamData() { tctf.redLastTime = bz_getCurrentTime(); tctf.greenLastTime = bz_getCurrentTime(); tctf.blueLastTime = bz_getCurrentTime(); tctf.purpleLastTime = bz_getCurrentTime(); tctf.redLastWarn = bz_getCurrentTime(); tctf.greenLastWarn = bz_getCurrentTime(); tctf.blueLastWarn = bz_getCurrentTime(); tctf.purpleLastWarn = bz_getCurrentTime(); return; }
void initiatekeepaway(bz_eTeamType plyrteam, bz_ApiString plyrcallsign, int plyrID) { keepaway.team = plyrteam; keepaway.callsign = plyrcallsign.c_str(); if (keepaway.callsign.size() > 16) { std::string tofix = truncate(keepaway.callsign, 16); keepaway.callsign = tofix; } keepaway.id = plyrID; keepaway.startTime = bz_getCurrentTime(); keepaway.TTHminutes = (int)(keepaway.adjustedTime/60 + 0.5); keepaway.TTHseconds = 30; keepaway.toldFlagFree = false; bool multipleof30 = false; if ((int)((keepaway.adjustedTime / 30) + 0.5) != (double)(keepaway.adjustedTime / 30)) multipleof30 = false; else multipleof30 = true; if (!multipleof30) { if ((!keepaway.teamPlay || keepaway.team == eRogueTeam)) bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s has %s flag; %i secs left!", keepaway.callsign.c_str(), keepaway.flagToKeep.c_str(), (int)keepaway.adjustedTime); else bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "%s (%s) has %s flag; %i secs left!", getTeamColor(keepaway.team), keepaway.callsign.c_str(), keepaway.flagToKeep.c_str(), (int)keepaway.adjustedTime); } if (keepaway.soundEnabled) { 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 != keepaway.team || player->team == eRogueTeam) && player->playerID != keepaway.id) bz_sendPlayCustomLocalSound(player->playerID,"flag_alert"); else bz_sendPlayCustomLocalSound(player->playerID,"teamgrab"); } bz_freePlayerRecord(player); } bz_deleteIntList(playerList); } return; }
void flagResetTimerHandler::Event(bz_EventData *eventData) { switch (eventData->eventType) { case bz_eTickEvent: { double timeLimitSeconds = timeLimitMinutes*60; std::string flagname = bz_getName(0).c_str(); if(flagname=="R*" || flagname=="G*" || flagname=="B*" || flagname=="P*") { gameStyle = "ctf"; } if(nextReset<bz_getCurrentTime()) { 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()+timeLimitSeconds; } } break; default:break; } }
void TCTFFlagCapped::process(bz_EventData * eventData) { if (eventData->eventType != bz_eCaptureEvent) return; // if timed CTF turned off, get outta here: if (!tctf.enabled || !tctf.timerRunning) return; bz_CTFCaptureEventData_V1 *CapData = (bz_CTFCaptureEventData_V1 *) eventData; // if team caps, reset their timer and notify their team if (CapData->teamCapping == eRedTeam) { tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5); bz_sendTextMessagef(BZ_SERVER, eRedTeam, "CTF timer is reset to %i minutes for the red team.", tctf.adjTime); tctf.redLastTime = bz_getCurrentTime(); tctf.redLastWarn = bz_getCurrentTime(); return; } if (CapData->teamCapping == eGreenTeam) { tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5); bz_sendTextMessagef(BZ_SERVER, eGreenTeam, "CTF timer is reset to %i minutes for the green team.", tctf.adjTime); tctf.greenLastTime = bz_getCurrentTime(); tctf.greenLastWarn = bz_getCurrentTime(); return; } if (CapData->teamCapping == eBlueTeam) { tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5); bz_sendTextMessagef(BZ_SERVER, eBlueTeam, "CTF timer is reset to %i minutes for the blue team.", tctf.adjTime); tctf.blueLastTime = bz_getCurrentTime(); tctf.blueLastWarn = bz_getCurrentTime(); return; } if (CapData->teamCapping == ePurpleTeam) { tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5); bz_sendTextMessagef(BZ_SERVER, ePurpleTeam, "CTF timer is reset to %i minutes for the purple team.", tctf.adjTime); tctf.purpleLastTime = bz_getCurrentTime(); tctf.purpleLastWarn = bz_getCurrentTime(); return; } return; }
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 KeepAwayPlayerJoined ( bz_EventData *eventData ) { if (eventData->eventType != bz_ePlayerJoinEvent || !keepaway.enabled || keepaway.flagToKeep == "") return; bz_PlayerJoinPartEventData_V1 *joinData = (bz_PlayerJoinPartEventData_V1*)eventData; if (keepaway.flagToKeep == "Initiate") //first time server starts, first player initiates it. { keepaway.flagToKeep = getFlag(); keepaway.lastReminder = bz_getCurrentTime(); } autoTime(); if (oneTeam(eNoTeam)) // don't send message if not enough teams { keepaway.notEnoughTeams = true; return; } else keepaway.notEnoughTeams = false; if (keepaway.id == -1 && keepaway.enabled && keepaway.flagToKeep != "") { bz_sendTextMessagef (BZ_SERVER, joinData->playerID, "Keep Away flag is %s: find it and keep it for %i seconds!", convertFlag(keepaway.flagToKeep).c_str(), (int)keepaway.adjustedTime); if (keepaway.soundEnabled) bz_sendPlayCustomLocalSound(joinData->playerID,"hunt_select"); } if (keepaway.id != -1 && keepaway.enabled && keepaway.flagToKeep != "" && (joinData->record->team != keepaway.team || joinData->record->team == eRogueTeam)) { bz_sendTextMessagef (BZ_SERVER, joinData->playerID, "%s has Keep Away flag %s - kill him/her before time's up!", keepaway.callsign.c_str(), convertFlag(keepaway.flagToKeep).c_str()); if (keepaway.soundEnabled) bz_sendPlayCustomLocalSound(joinData->playerID,"flag_alert"); } if (keepaway.id != -1 && keepaway.enabled && keepaway.flagToKeep != "" && (joinData->record->team == keepaway.team && joinData->record->team != eRogueTeam)) { bz_sendTextMessagef (BZ_SERVER, joinData->playerID, "%s has Keep Away flag %s - protect him/her until time's up!", keepaway.callsign.c_str(), convertFlag(keepaway.flagToKeep).c_str()); if (keepaway.soundEnabled) bz_sendPlayCustomLocalSound(joinData->playerID,"teamgrab"); } return; }
void autoFlagReset::Event(bz_EventData* eventData) { unsigned int nflags = bz_getNumFlags(); if (bz_getCurrentTime() < nextRunTime || nflags <= 0 || eventData->eventType != bz_eTickEvent) { // Nothing to see here. return; } if (incremental) { // Reset one flag. // Limit iteration to one "cycle" of all flags. // Otherwise, this is an infinite loop if all flags are in use. for (unsigned int i = 0; i < nflags; i++) { bool worked = ResetUnusedSuperflag(nextFlag); nextFlag++; if (nextFlag >= nflags) { nextFlag = 0; } if (worked) { break; } } nextRunTime += freq / (double)nflags; } else { // Reset all flags. for (unsigned int i = 0; i < nflags; i++) { // Don't care whether it works or not. ResetUnusedSuperflag(i); } nextRunTime += freq; } }
void BZFSHTTPAuth::flushTasks ( void ) { std::map<int,AuthInfo>::iterator authItr = authedSessions.begin(); double now = bz_getCurrentTime(); while (authedSessions.size() && authItr != authedSessions.end()) { if (sessionTimeout + authItr->second.time < now) { std::map<int,AuthInfo>::iterator t = authItr; t++; authedSessions.erase(authItr); authItr = t; } else authItr++; } }
TCTF() { timeLimit = 300; timeElapsed = 0; timeRemaining = 0; redLastTime = bz_getCurrentTime(); greenLastTime = bz_getCurrentTime(); blueLastTime = bz_getCurrentTime(); purpleLastTime = bz_getCurrentTime(); redLastWarn = bz_getCurrentTime(); greenLastWarn = bz_getCurrentTime(); blueLastWarn = bz_getCurrentTime(); purpleLastWarn = bz_getCurrentTime(); adjTime = 0; timerRunning = false; enabled = true; fairCTFEnabled = true; notifiedCTFOK = false; fairCTF = false; soundEnabled = true; }
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 Defusal::SlashCommand(int playerID, bz_ApiString command, bz_ApiString /*message*/, bz_APIStringList *params) { bz_BasePlayerRecord *playerdata = bz_getPlayerByIndex(playerID); if (command == "bomb" && playerdata->currentFlag.c_str()=="Red team flag") { bombPlaced = true; bombPlacer = playerdata->callsign.c_str(); bombPlacementTime = bz_getCurrentTime(); bz_removePlayerFlag(playerID); //Take away the flag (bomb), it has been placed bz_getFlagPosition(0,bombLocation); //Store the location of the bomb bz_sendTextMessagef(BZ_SERVER,eBlueTeam,"'%s' has placed the bomb! You have %i minutes to find and defuse it.",bombPlacer.c_str(),detonationTime); bz_sendTextMessagef(BZ_SERVER,eRedTeam,"'%s' has placed the bomb! Defend the bomb for %i minutes.",bombPlacer.c_str(),detonationTime); bz_sendTextMessagef(BZ_SERVER,eObservers,"'%s' has placed the bomb!",bombPlacer.c_str(),detonationTime); } bz_freePlayerRecord(playerdata); }
void Templateiser::keyCallback ( std::string &data, const std::string &key ) { if (key == "date") { bz_Time time; bz_getLocaltime(&time); data = format("%d/%d/%d",time.month,time.day,time.year); } else if (key == "time") { bz_Time time; bz_getLocaltime(&time); data = format("%d:%d:%d",time.hour,time.minute,time.second); } else if (key == "hostname") { data = bz_getPublicAddr().c_str(); if (!data.size()) data = format("localhost:%d",bz_getPublicPort()); } else if (key == "pagetime") { data = format("%.3f",bz_getCurrentTime()-startTime); } else if (key == "baseurl") { data =baseURL; } else if (key == "pluginname") { data = pluginName; } }
BZ_GET_PLUGIN_VERSION BZF_PLUGIN_CALL int bz_Load ( const char* commandLine ) { if(!commandLine || !strlen(commandLine)) { bz_debugMessage(0,"mapchange plugin requires a config file as a param and will not load"); return -1; } if(!loadGamesFromFile(commandLine)) { bz_debugMessage(0,"mapchange plugin config file failure, aborting load"); return -1; } bz_debugMessage(4,"mapchange plugin loaded"); if ( anyPlayers() ) startTime = bz_getCurrentTime(); bz_registerEvent ( bz_ePlayerJoinEvent, &handler ); bz_registerEvent ( bz_ePlayerDieEvent, &handler ); bz_registerEvent ( bz_ePlayerPartEvent, &handler ); bz_registerEvent ( bz_eCaptureEvent, &handler ); bz_registerEvent ( bz_eGetWorldEvent, &handler ); bz_registerEvent ( bz_eTickEvent, &handler ); bz_registerEvent ( bz_eListServerUpdateEvent, &handler ); bz_registerCustomSlashCommand ( "mapnext",&slash ); bz_registerCustomSlashCommand ( "mapreset",&slash ); bz_registerCustomSlashCommand ( "mapcyclemode",&slash ); bz_registerCustomSlashCommand ( "mapendmode",&slash ); bz_registerCustomSlashCommand ( "maplist",&slash ); bz_registerCustomSlashCommand ( "maplimit",&slash ); return 0; }
autoFlagReset::autoFlagReset() : bz_Plugin(), incremental(false), freq(900), nextRunTime(bz_getCurrentTime()), nextFlag(0) { }
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; } }
// this is where most of the decisions are made - a little clunky, but seems to work: void TCTFTickEvents::process(bz_EventData * eventData) { if (eventData->eventType != bz_eTickEvent) return; // read this function once per tick event. If fair CTF disabled, make it look fair to rest // of code - need to do this to be able to have timed ctf without fair ctf. tctf.fairCTF = (TeamsBalanced() || !tctf.fairCTFEnabled); // check/notify team balance changes while timed CTF is disabled. // if fair ctf is disabled, no need to check/notify about team balance changes: if (tctf.fairCTF && !tctf.notifiedCTFOK && !tctf.enabled && tctf.fairCTFEnabled) { bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Capture The Flag enabled - teams are evenly balanced."); tctf.notifiedCTFOK = true; return; } if (!tctf.fairCTF && tctf.notifiedCTFOK && !tctf.enabled && tctf.fairCTFEnabled) { bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Capture The Flag disabled - teams are not evenly balanced."); tctf.notifiedCTFOK = false; return; } // if no timed CTF, we can leave: if (!tctf.enabled) return; // if this is true, we can leave too: if (!tctf.fairCTF && !tctf.timerRunning) return; // check/notify team balance changes while timed CTF and fair CTF are enabled: if (!tctf.fairCTF && tctf.timerRunning && tctf.fairCTFEnabled) { bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Capture The Flag disabled - teams are not evenly balanced."); tctf.timerRunning = false; ResetTeamData(); return; } // no timed ctf with fair CTF disabled and only one team present: if (tctf.fairCTF && !tctf.fairCTFEnabled) { if (OnlyOneTeamPlaying()) { if (tctf.timerRunning) bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Timed CTF disabled - not enough teams."); tctf.timerRunning = false; ResetTeamData(); return; } } // start timing if we have made it this far: if (tctf.fairCTF && !tctf.timerRunning && !OnlyOneTeamPlaying()) { tctf.adjTime = (int) (tctf.timeLimit / 60 + 0.5); bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Timed CTF now in progress - capture a flag in less than %i minute(s)!", tctf.adjTime); tctf.timerRunning = true; ResetTeamData(); return; } // everything is a go for timed ctf checks now. // check each team's time left, warn and kill if necessary: int RedReturn = TeamCheck(eRedTeam, "RED", tctf.redLastWarn, tctf.redLastTime); int GreenReturn = TeamCheck(eGreenTeam, "GREEN", tctf.greenLastWarn, tctf.greenLastTime); int BlueReturn = TeamCheck(eBlueTeam, "BLUE", tctf.blueLastWarn, tctf.blueLastTime); int PurpleReturn = TeamCheck(ePurpleTeam, "PURPLE", tctf.purpleLastWarn, tctf.purpleLastTime); if (RedReturn == 1) tctf.redLastWarn = bz_getCurrentTime(); if (RedReturn == 2) { tctf.redLastWarn = bz_getCurrentTime(); tctf.redLastTime = bz_getCurrentTime(); } if (GreenReturn == 1) tctf.greenLastWarn = bz_getCurrentTime(); if (GreenReturn == 2) { tctf.greenLastWarn = bz_getCurrentTime(); tctf.greenLastTime = bz_getCurrentTime(); } if (BlueReturn == 1) tctf.blueLastWarn = bz_getCurrentTime(); if (BlueReturn == 2) { tctf.blueLastWarn = bz_getCurrentTime(); tctf.blueLastTime = bz_getCurrentTime(); } if (PurpleReturn == 1) tctf.purpleLastWarn = bz_getCurrentTime(); if (PurpleReturn == 2) { tctf.purpleLastWarn = bz_getCurrentTime(); tctf.purpleLastTime = bz_getCurrentTime(); } ResetZeroTeams(); // reset team data for teams with no players. return; }
void TCTFPlayerJoined::process(bz_EventData * eventData) { if (eventData->eventType != bz_ePlayerJoinEvent) return; bz_PlayerJoinPartEventData_V1 *JoinData = (bz_PlayerJoinPartEventData_V1 *) eventData; // if teams are not even, notify joiner no CTF. // this should never be true if fair ctf is disabled (see definition of tctf.fairCTF): if (!tctf.fairCTF) { bz_sendTextMessagef(BZ_SERVER, JoinData->playerID, "Capture The Flag disabled - teams are not evenly balanced."); return; } // if timed CTF turned off, but teams now even, let everyone know it's ok to cap. // if fair CTF is disabled, no need to notify: if (tctf.fairCTF && !tctf.enabled && tctf.fairCTFEnabled) { bz_sendTextMessagef(BZ_SERVER, JoinData->playerID, "Capture The Flag enabled - teams are evenly balanced."); return; } // if timed CTF turned off, get outta here: if (!tctf.enabled) return; // if teams even, notify joiner how much time is left to CTF for their team: if (JoinData->record->team == eRedTeam && tctf.timerRunning) { tctf.timeElapsed = bz_getCurrentTime() - tctf.redLastTime; tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed; tctf.adjTime = (int) (tctf.timeRemaining / 60); bz_sendTextMessagef(BZ_SERVER, JoinData->playerID, "Timed CTF now in progress - capture a flag in less than %i minute(s)!", tctf.adjTime + 1); return; } if (JoinData->record->team == eGreenTeam && tctf.timerRunning) { tctf.timeElapsed = bz_getCurrentTime() - tctf.greenLastTime; tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed; tctf.adjTime = (int) (tctf.timeRemaining / 60); bz_sendTextMessagef(BZ_SERVER, JoinData->playerID, "Timed CTF now in progress - capture a flag in less than %i minute(s)!", tctf.adjTime + 1); return; } if (JoinData->record->team == eBlueTeam && tctf.timerRunning) { tctf.timeElapsed = bz_getCurrentTime() - tctf.blueLastTime; tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed; tctf.adjTime = (int) (tctf.timeRemaining / 60); bz_sendTextMessagef(BZ_SERVER, JoinData->playerID, "Timed CTF now in progress - capture a flag in less than %i minute(s)!", tctf.adjTime + 1); return; } if (JoinData->record->team == ePurpleTeam && tctf.timerRunning) { tctf.timeElapsed = bz_getCurrentTime() - tctf.purpleLastTime; tctf.timeRemaining = tctf.timeLimit - tctf.timeElapsed; tctf.adjTime = (int) (tctf.timeRemaining / 60); bz_sendTextMessagef(BZ_SERVER, JoinData->playerID, "Timed CTF now in progress - capture a flag in less than %i minute(s)!", tctf.adjTime + 1); return; } return; }
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; }