From b9a2258bb3bd17f81605f09a7cb039274231e98b Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 10 Apr 2023 11:18:12 +0200 Subject: [PATCH 01/18] Fix various build warnings/errors. --- OneVsOne.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/OneVsOne.cpp b/OneVsOne.cpp index 97a2f6d..513b35c 100644 --- a/OneVsOne.cpp +++ b/OneVsOne.cpp @@ -223,6 +223,7 @@ bool OneVsOne::readConfig(std::string fileName) logFile = config.getValue("logging", "logfile"); } + return true; } bool OneVsOne::isCompat() @@ -242,13 +243,13 @@ bool OneVsOne::isMatch() std::map::iterator it = Players.begin(); - std::string matchType = (*it).second.matchType; + std::string matchTypeP = (*it).second.matchType; - if ( matchType.size() == 0) + if ( matchTypeP.size() == 0) return false; for( ; it != Players.end(); it++ ) { - if ( (*it).second.matchType != matchType ) { + if ( (*it).second.matchType != matchTypeP ) { return false; } } @@ -675,7 +676,7 @@ void OneVsOne::logRecordMatch(std::string mType, int winner, int loser) int duration = (int) (bz_getCurrentTime() - startTime); char scores[200]; - char match_date[20]; + char match_date[100]; std::string reportData; From 88a69059258d69d53594006d5046fdf18eb62ca1 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 10 Apr 2023 17:17:37 +0200 Subject: [PATCH 02/18] Fix compiler errors/warnings. --- UrlHandler.cpp | 44 +++++++++++++++++++++++--------------------- UrlHandler.h | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/UrlHandler.cpp b/UrlHandler.cpp index 799d648..22777f6 100644 --- a/UrlHandler.cpp +++ b/UrlHandler.cpp @@ -13,31 +13,33 @@ bool replace_v2(std::string& s,const char * orig,const char * rep ) void BaseUrlHandler::URLDone ( const char* /*URL*/, const 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); - + if (complete) { + int _playerId = _playerIds[0]; + _playerIds.erase(_playerIds.begin()); + + if ( size > 1 && size < _max_data_size ) { + std::string _data; + _data.append((const 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_sendTextMessage (BZ_SERVER, _playerId,"No valid data was received !"); + 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."); } } - 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."); - } } void BaseUrlHandler::URLError ( const char* /*URL*/, int errorCode, const char * errorString ) @@ -84,7 +86,7 @@ bool BaseUrlHandler::is_valid_status(const std::string& data) return false; } -bool BaseUrlHandler::setNoNoKNotify(bool notify) +void BaseUrlHandler::setNoNoKNotify(bool notify) { noNOKNotify = notify; } diff --git a/UrlHandler.h b/UrlHandler.h index 8ec21bb..6017bbc 100644 --- a/UrlHandler.h +++ b/UrlHandler.h @@ -33,7 +33,7 @@ class BaseUrlHandler : public bz_BaseURLHandler virtual void showData(int playerId); void setPlayerId(int playerId); bool is_valid_status(const std::string& data); - bool setNoNoKNotify(bool notify); + void setNoNoKNotify(bool notify); private: bool noNOKNotify; From f07e624230c7e7398c5e940a7bdeed4ce576e963 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 10 Apr 2023 17:20:28 +0200 Subject: [PATCH 03/18] Switch to build-in INI file parser. --- INIParser.cpp | 206 -------------------------------------------------- INIParser.h | 48 ------------ OneVsOne.cpp | 91 ++++++++++++---------- 3 files changed, 52 insertions(+), 293 deletions(-) delete mode 100644 INIParser.cpp delete mode 100644 INIParser.h diff --git a/INIParser.cpp b/INIParser.cpp deleted file mode 100644 index e22197a..0000000 --- a/INIParser.cpp +++ /dev/null @@ -1,206 +0,0 @@ - -#include "INIParser.h" - -INIParser::INIParser(const char * iniFile) -{ - _iniFile = iniFile; -} - -int INIParser::parse() -{ - - char ch; - char buffer[100]; - int i = 0; - int line = 1; - - std::string section = "__NO_SECTION__"; - std::string name; - parseState = NO_SECTION; - - // open ini file - std::ifstream in(_iniFile.c_str(), std::ios::in | std::ios::binary); - - while ( in.get(ch) ) { - switch (ch) { - case '[' : - if (isStartSection()) - return line; - - if ( i == 0 ) - parseState = START_SECTION; - else - return line; - - break; - case ']' : - if (isStopSection()) - return line; - - if (isStartSection() && i > 0) { - buffer[i] = '\0'; - section = buffer; - //std::cout << "section => " << buffer << std::endl; - i=0; - } else { // else error , empty section [] or ] not the end of start section - return line; - } - - parseState = STOP_SECTION; - break; - case '=' : - - if ( isStartSection() || isDelimiter()) - return line; - - if ( isNoSection() && i == 0 ) - return line; - - if ((isNewline() || isNoSection()) && i > 0) { - buffer[i] = '\0'; - name = buffer; - //std::cout << "key => " << buffer << std::endl; - i=0; - } else if (isNewline() && i == 0) - return line; - - parseState = DELIMITER; - - break; - case '\n' : - - if ( isNewline() && i > 0 ) - return line; - - if ( isNoSection() && i > 0 ) - return line; - - if ( isStartSection() ) - return line; - - if ( isDelimiter() && i > 0 ) { - buffer[i] = '\0'; - sections[section][name] = buffer; - //std::cout << "value => " << buffer << std::endl; - i=0; - } else if ( isDelimiter() && i == 0 ) - return line; - - //if ( parseState != DELIMITER || parseState != STOP_SECTION || parseState != COMMENT ) - // return line; - - parseState = NEWLINE; - line++; - break; - case ';' : - parseState = COMMENT; - break; - case '#' : - parseState = COMMENT; - break; - case ' ' : - break; - default : - - if ( isNewline() || isNoSection() ) { - buffer[i] = ch; - i++; - } - - if ( isDelimiter() ) { - buffer[i] = ch; - i++; - } - - if ( isStartSection() ) { - buffer[i] = ch; - i++; - } - // else error - - break; - } - } - - in.close(); - - return 0; -} - -const std::string INIParser::getValue(const char * section, const char * name) -{ - //Sections::iterator it_s = sections.find(section); - //it_s = sections.find(section); - //Parameters::iterator it_p = it_s->second.find(name); - //return it_p->second; - return sections[section][name]; -} - -Parameters & INIParser::getParameters(const char * section) -{ - //Sections::iterator it_s = sections.find(section); - it_s = sections.find(section); - return it_s->second; -} - -bool INIParser::isSection(const char * section) -{ - return ( sections.count(section) > 0 ); -} - -bool INIParser::isValue(const char * section, const char * name) -{ - if ( isSection(section) > 0 ) - if ( sections[section].count(name) > 0 ) - return true; - - return false; -} - -bool INIParser::isNoSection() -{ - if ( parseState == NO_SECTION ) - return true; - - return false; -} - -bool INIParser::isStartSection() -{ - if ( parseState == START_SECTION ) - return true; - - return false; -} - -bool INIParser::isStopSection() -{ - if ( parseState == STOP_SECTION ) - return true; - - return false; -} - -bool INIParser::isDelimiter() -{ - if ( parseState == DELIMITER ) - return true; - - return false; -} - -bool INIParser::isComment() -{ - if ( parseState == COMMENT ) - return true; - - return false; -} - -bool INIParser::isNewline() -{ - if ( parseState == NEWLINE ) - return true; - - return false; -} diff --git a/INIParser.h b/INIParser.h deleted file mode 100644 index e21749c..0000000 --- a/INIParser.h +++ /dev/null @@ -1,48 +0,0 @@ - -#ifndef __INITPARSER_H__ -#define __INITPARSER_H__ - -#include -#include -#include - -typedef std::map Parameters; -typedef std::map Sections; - -class INIParser -{ - public: - INIParser(const char * iniFile); - ~INIParser() {}; - - int parse(); - Parameters & getParameters(const char * section); - const std::string getValue(const char * section, const char * name); - bool isSection(const char * section); - bool isValue(const char * section, const char * name); - - bool isNoSection(); - bool isStartSection(); - bool isStopSection(); - bool isDelimiter(); - bool isComment(); - bool isNewline(); - - private: - - typedef enum { - NO_SECTION, - START_SECTION, - STOP_SECTION, - DELIMITER, - COMMENT, - NEWLINE - } ParseState; - - std::string _iniFile; - ParseState parseState; - Sections sections; - Sections::iterator it_s; -}; - -#endif diff --git a/OneVsOne.cpp b/OneVsOne.cpp index 513b35c..3b68ac5 100644 --- a/OneVsOne.cpp +++ b/OneVsOne.cpp @@ -9,8 +9,8 @@ #include #include "bzfsAPI.h" +#include "plugin_utils.h" #include "UrlHandler.h" -#include "INIParser.h" #define ONEVSONE "2.0.1" @@ -19,6 +19,7 @@ #define DEBUG_TAG "DEBUG::OneVsOne PLUGIN::" #define DEBUG_LEVEL 2 +typedef std::map Parameters; typedef struct { int losses; @@ -168,59 +169,73 @@ OneVsOne::OneVsOne() bool OneVsOne::readConfig(std::string fileName) { - INIParser config = INIParser(fileName.c_str()); - int status = config.parse(); - if (status > 0 ) { - bz_debugMessage(DEBUG_LEVEL,"OneVsOne plugin loading FAILED"); - bz_debugMessagef(DEBUG_LEVEL,"Error parsing config file at line %d", status); - return false; - } +// std::cout << "!!!! DEBUGGING !!!!!: " << fileName << std::endl; + PluginConfig config = PluginConfig(fileName); + + // std::cout << config.item("general", "max_lives"); + + // std::vector sections = config.getSections(); + + // std::vector::iterator it = sections.begin(); + + // for( ; it != sections.end(); it++ ) { + // std::cout << "DEBUG section: " << *it << std::endl; + // } - if (config.isSection("general") ) { + // std::cout << "FAIL: " << config.item("general", "max_lives").size() << std::endl; + // std::cout << "FAIL: " << config.item("general", "max").size() << std::endl; - if ( config.isValue("general","max_lives") ) - maxLives = atoi(config.getValue("general", "max_lives").c_str()); + // general section + + if ( config.item("general", "max_lives").size() != 0 ) { + maxLives = atoi(config.item("general", "max_lives").c_str()); + } - if ( config.isValue("general","style") ) - gameStyle = config.getValue("general","style"); + if ( config.item("general", "style").size() != 0 ) { + gameStyle = config.item("general","style"); + } - if ( config.isValue("general","compatibility") ) { - if ( config.getValue("general", "compatibility") == "false" ) { + if ( config.item("general", "compatibility") == "false" ) { compatibility = false; } - } - } + + // command section gameTypes.clear(); + std::vector> commands = config.getSectionItems("commands"); + std::vector>::iterator it = commands.begin(); - if (config.isSection("commands") ) - gameTypes = config.getParameters("commands"); + for( ; it != commands.end(); it++ ) { + gameTypes[(*it).first] = (*it).second; + } - if (config.isSection("communication") ) { - if ( config.isValue("communication","httpuri") ) { - httpUri = config.getValue("communication", "httpuri"); - isComm = true; + // communication section - if ( config.isValue("communication", "refresh_interval") ) { - refreshInterval = atoi(config.getValue("communication", "refresh_interval").c_str()); - } + if ( config.item("communication", "style").size() != 0 ) { + httpUri = config.item("communication", "httpuri"); + isComm = true; + } + + if ( config.item("communication", "style").size() != 0 ) { + httpUri = config.item("communication", "httpuri"); + isComm = true; + } - if ( config.isValue("communication","enable_motd") ) { - if ( config.getValue("communication", "enable_motd") == "true" ) { + if ( config.item("communication", "refresh_interval").size() != 0 ) { + refreshInterval = atoi(config.item("communication", "refresh_interval").c_str()); + } + + if ( config.item("communication", "enable_motd") == "true" ) { isMotd = true; } - } - if ( config.getValue("communication", "enable_welcome") == "true" ) { - isWelcome = true; - } - } + if ( config.item("communication", "enable_welcome") == "true" ) { + isWelcome = true; } - if (config.isSection("logging") ) { - if ( config.isValue("logging","logfile") ) - logFile = config.getValue("logging", "logfile"); + if ( config.item("logging", "logfile").size() != 0 ) { + logFile = config.item("logging", "logfile"); } return true; @@ -910,9 +925,7 @@ void OneVsOne::Init ( const char* commandLine ) std::string cmdLine = commandLine; if (cmdLine.size()) - if ( ! readConfig(cmdLine) ) - bz_debugMessage( DEBUG_LEVEL, "OneVsOne reading config file failed .. falling back to defaults" ); - + readConfig(cmdLine); bz_registerCustomSlashCommand ("ovso", this); From 5ef69fa8692d5ba38d95b7a5de86dca49e0c6ee0 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 10 Apr 2023 17:24:02 +0200 Subject: [PATCH 04/18] Update .gitignore file. --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index d71de28..89ce169 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,8 @@ # Misc .ruby-version +.libs +.deps +.vscode +Makefile +Makefile.in From 01fff0276737cbffcfe3d229fc3beda0806acb1b Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 10 Apr 2023 17:28:30 +0200 Subject: [PATCH 05/18] Update Automake config. --- Makefile.am | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index ba24919..aaf732a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,8 +3,6 @@ lib_LTLIBRARIES = OneVsOne.la OneVsOne_la_SOURCES = \ UrlHandler.h \ UrlHandler.cpp \ - INIParser.h \ - INIParser.cpp \ OneVsOne.cpp OneVsOne_la_CPPFLAGS= -I$(top_srcdir)/include -I$(top_srcdir)/plugins/plugin_utils OneVsOne_la_LDFLAGS = -module -avoid-version -shared From f38d9291b474de2d955aa69c7b164eb53dc40f37 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 10 Apr 2023 17:50:18 +0200 Subject: [PATCH 06/18] Fix and apply proper formatting. --- OneVsOne.cpp | 1055 +++++++++++++++++++++++++----------------------- UrlHandler.cpp | 133 +++--- UrlHandler.h | 92 ++--- 3 files changed, 670 insertions(+), 610 deletions(-) diff --git a/OneVsOne.cpp b/OneVsOne.cpp index 3b68ac5..798c0e8 100644 --- a/OneVsOne.cpp +++ b/OneVsOne.cpp @@ -16,119 +16,114 @@ #define MAX_PLAYERS 2 -#define DEBUG_TAG "DEBUG::OneVsOne PLUGIN::" +#define DEBUG_TAG "DEBUG::OneVsOne PLUGIN::" #define DEBUG_LEVEL 2 -typedef std::map Parameters; +typedef std::map Parameters; -typedef struct { - int losses; - std::string callsign; - std::string matchType; +typedef struct +{ + int losses; + std::string callsign; + std::string matchType; } OneVsOnePlayer; /// HELPER STUFF /// template -std::string to_string (const T& t) +std::string to_string(const T &t) { std::stringstream ss; ss << t; return ss.str(); } -bool replace(std::string& s,const char * orig,const char * rep ) +bool replace(std::string &s, const char *orig, const char *rep) { - bool retval=false; - while ( s.find(orig) != std::string::npos ) { - s.replace(s.find(orig),std::string(orig).size(),rep); - retval=true; + bool retval = false; + while (s.find(orig) != std::string::npos) + { + s.replace(s.find(orig), std::string(orig).size(), rep); + retval = true; } return retval; } - class OneVsOne : public bz_Plugin, public bz_CustomSlashCommandHandler { - public: - - OneVsOne(); - ~OneVsOne() {}; - - bool readConfig(std::string fileName); - bool isCompat(); - - Parameters gameTypes; - - virtual const char* Name (){return "One Vs One";} - virtual void Init ( const char* config); - virtual void Cleanup (); - virtual void Event ( bz_EventData *eventData ); - virtual bool SlashCommand ( int playerID, bz_ApiString, bz_ApiString, bz_APIStringList*); - - protected: - - private: - - std::map Players; - bool recording; - bool isMotd; - bool isWelcome; - std::string matchType; - std::string serverName; - std::string gameStyle; - int maxLives; - std::string logFile; - double startTime; - std::string httpUri; - double motdLastRefreshTime; - double refreshInterval; - double welcomeMessageLastRefreshTime; - bool cfgPerm; - std::string cfgPermName; - bool compatibility; - bool isComm; - - // reporting/info handlers - BaseUrlHandler playerInfoHandler; - BaseUrlHandler topScoreHandler; - BaseUrlHandler topZeloHandler; - BaseUrlHandler registerHandler; - BaseUrlHandler reportHandler; - BaseUrlHandler motdHandler; - BaseUrlHandler welcomeMessageHandler; - - // issers - bool isMatch(); - - void logRecordMatch(std::string mType, int winner, int loser); - void registerPlayer(int p, bz_APIStringList*); - void getPlayerInfo(int p, bz_APIStringList*); - void getTopScore(int p, bz_APIStringList*); - void getTopZelo(int p, bz_APIStringList*); - void setMatch(int p, bz_APIStringList*); - void unSetMatchAll(void); - void handleMotd(int p, bz_APIStringList*); - void setLives(int p, bz_APIStringList*); - void showHelp(int p, bz_ApiString action = "all"); - - void printScore(void); - void printBanner(int winner, int loser); - void addPlayer(int playerId, const std::string callsign); - void delPlayer(int playerId); - void setLoss(int playerId); - int getHighestLoss(void); - int getWinner(int playerId); - void saveScores(char * scores); - void showMotdBanner(int playerId, bool force=false); - void showWelcomeMessage(int playerId, bool force=false); - +public: + OneVsOne(); + ~OneVsOne(){}; + + bool readConfig(std::string fileName); + bool isCompat(); + + Parameters gameTypes; + + virtual const char *Name() { return "One Vs One"; } + virtual void Init(const char *config); + virtual void Cleanup(); + virtual void Event(bz_EventData *eventData); + virtual bool SlashCommand(int playerID, bz_ApiString, bz_ApiString, bz_APIStringList *); + +protected: +private: + std::map Players; + bool recording; + bool isMotd; + bool isWelcome; + std::string matchType; + std::string serverName; + std::string gameStyle; + int maxLives; + std::string logFile; + double startTime; + std::string httpUri; + double motdLastRefreshTime; + double refreshInterval; + double welcomeMessageLastRefreshTime; + bool cfgPerm; + std::string cfgPermName; + bool compatibility; + bool isComm; + + // reporting/info handlers + BaseUrlHandler playerInfoHandler; + BaseUrlHandler topScoreHandler; + BaseUrlHandler topZeloHandler; + BaseUrlHandler registerHandler; + BaseUrlHandler reportHandler; + BaseUrlHandler motdHandler; + BaseUrlHandler welcomeMessageHandler; + + // issers + bool isMatch(); + + void logRecordMatch(std::string mType, int winner, int loser); + void registerPlayer(int p, bz_APIStringList *); + void getPlayerInfo(int p, bz_APIStringList *); + void getTopScore(int p, bz_APIStringList *); + void getTopZelo(int p, bz_APIStringList *); + void setMatch(int p, bz_APIStringList *); + void unSetMatchAll(void); + void handleMotd(int p, bz_APIStringList *); + void setLives(int p, bz_APIStringList *); + void showHelp(int p, bz_ApiString action = "all"); + + void printScore(void); + void printBanner(int winner, int loser); + void addPlayer(int playerId, const std::string callsign); + void delPlayer(int playerId); + void setLoss(int playerId); + int getHighestLoss(void); + int getWinner(int playerId); + void saveScores(char *scores); + void showMotdBanner(int playerId, bool force = false); + void showWelcomeMessage(int playerId, bool force = false); }; BZ_PLUGIN(OneVsOne) - - OneVsOne::OneVsOne() { // Initialize the default values @@ -147,7 +142,7 @@ OneVsOne::OneVsOne() httpUri = ""; isMotd = false; isWelcome = false; - // in seconds , default 1 hour + // in seconds , default 1 hour refreshInterval = 3600; // logging @@ -158,47 +153,35 @@ OneVsOne::OneVsOne() motdLastRefreshTime = 0; welcomeMessageLastRefreshTime = 0; startTime = 0; - + motdHandler.setNoNoKNotify(true); - cfgPerm = false; + cfgPerm = false; cfgPermName = "OVSO_CFG"; isComm = false; } - bool OneVsOne::readConfig(std::string fileName) { -// std::cout << "!!!! DEBUGGING !!!!!: " << fileName << std::endl; - PluginConfig config = PluginConfig(fileName); - - // std::cout << config.item("general", "max_lives"); - - // std::vector sections = config.getSections(); - - // std::vector::iterator it = sections.begin(); - - // for( ; it != sections.end(); it++ ) { - // std::cout << "DEBUG section: " << *it << std::endl; - // } - - // std::cout << "FAIL: " << config.item("general", "max_lives").size() << std::endl; - // std::cout << "FAIL: " << config.item("general", "max").size() << std::endl; + PluginConfig config = PluginConfig(fileName); // general section - if ( config.item("general", "max_lives").size() != 0 ) { + if (config.item("general", "max_lives").size() != 0) + { maxLives = atoi(config.item("general", "max_lives").c_str()); } - if ( config.item("general", "style").size() != 0 ) { - gameStyle = config.item("general","style"); + if (config.item("general", "style").size() != 0) + { + gameStyle = config.item("general", "style"); } - if ( config.item("general", "compatibility") == "false" ) { - compatibility = false; - } + if (config.item("general", "compatibility") == "false") + { + compatibility = false; + } // command section @@ -206,36 +189,43 @@ bool OneVsOne::readConfig(std::string fileName) std::vector> commands = config.getSectionItems("commands"); std::vector>::iterator it = commands.begin(); - for( ; it != commands.end(); it++ ) { + for (; it != commands.end(); it++) + { gameTypes[(*it).first] = (*it).second; } // communication section - if ( config.item("communication", "style").size() != 0 ) { + if (config.item("communication", "style").size() != 0) + { httpUri = config.item("communication", "httpuri"); isComm = true; } - if ( config.item("communication", "style").size() != 0 ) { + if (config.item("communication", "style").size() != 0) + { httpUri = config.item("communication", "httpuri"); isComm = true; } - if ( config.item("communication", "refresh_interval").size() != 0 ) { + if (config.item("communication", "refresh_interval").size() != 0) + { refreshInterval = atoi(config.item("communication", "refresh_interval").c_str()); } - if ( config.item("communication", "enable_motd") == "true" ) { - isMotd = true; - } + if (config.item("communication", "enable_motd") == "true") + { + isMotd = true; + } - if ( config.item("communication", "enable_welcome") == "true" ) { - isWelcome = true; + if (config.item("communication", "enable_welcome") == "true") + { + isWelcome = true; } - if ( config.item("logging", "logfile").size() != 0 ) { - logFile = config.item("logging", "logfile"); + if (config.item("logging", "logfile").size() != 0) + { + logFile = config.item("logging", "logfile"); } return true; @@ -253,197 +243,218 @@ bool OneVsOne::isCompat() bool OneVsOne::isMatch() { - if ( Players.size() != MAX_PLAYERS ) + if (Players.size() != MAX_PLAYERS) return false; - std::map::iterator it = Players.begin(); + std::map::iterator it = Players.begin(); std::string matchTypeP = (*it).second.matchType; - if ( matchTypeP.size() == 0) + if (matchTypeP.size() == 0) return false; - for( ; it != Players.end(); it++ ) { - if ( (*it).second.matchType != matchTypeP ) { + for (; it != Players.end(); it++) + { + if ((*it).second.matchType != matchTypeP) + { return false; } } return true; -} +} -void OneVsOne::registerPlayer(int playerID, bz_APIStringList* params) +void OneVsOne::registerPlayer(int playerID, bz_APIStringList *params) { - if ( params->size() == 2 ) { + if (params->size() == 2) + { bz_BasePlayerRecord *playerRecord; - playerRecord = bz_getPlayerByIndex ( playerID ); + playerRecord = bz_getPlayerByIndex(playerID); // check if player is verified - if ( playerRecord->verified) { - std::string registerdata; - registerdata = std::string("action=register&callsign=") + std::string(bz_urlEncode(playerRecord->callsign.c_str())) + - std::string("&bzid=") + std::string(bz_urlEncode(playerRecord->bzID.c_str())) + - std::string("&email=") + std::string(bz_urlEncode(params->get(1).c_str())) + - std::string("&ip=") + std::string(bz_urlEncode(playerRecord->ipAddress.c_str())); + if (playerRecord->verified) + { + std::string registerdata; + registerdata = std::string("action=register&callsign=") + std::string(bz_urlEncode(playerRecord->callsign.c_str())) + + std::string("&bzid=") + std::string(bz_urlEncode(playerRecord->bzID.c_str())) + + std::string("&email=") + std::string(bz_urlEncode(params->get(1).c_str())) + + std::string("&ip=") + std::string(bz_urlEncode(playerRecord->ipAddress.c_str())); registerHandler.setPlayerId(playerID); - - bz_addURLJob(httpUri.c_str(),®isterHandler, registerdata.c_str()); - } else - bz_sendTextMessagef ( BZ_SERVER, playerID,"You must be globally registered and identified to register here" ); - bz_freePlayerRecord ( playerRecord ); - } else + bz_addURLJob(httpUri.c_str(), ®isterHandler, registerdata.c_str()); + } + else + bz_sendTextMessagef(BZ_SERVER, playerID, "You must be globally registered and identified to register here"); + + bz_freePlayerRecord(playerRecord); + } + else showHelp(playerID, params->get(0)); } -void OneVsOne::getPlayerInfo(int playerID, bz_APIStringList* params) +void OneVsOne::getPlayerInfo(int playerID, bz_APIStringList *params) { - if ( params->size() >= 2 ) { + if (params->size() >= 2) + { bz_BasePlayerRecord *playerRecord; - playerRecord = bz_getPlayerByIndex ( playerID ); + playerRecord = bz_getPlayerByIndex(playerID); - std::string playerinfodata = "action=playerinfo"; + std::string playerinfodata = "action=playerinfo"; for (unsigned int i = 1; i < params->size(); i++) playerinfodata.append(std::string("&callsigns[]=") + std::string(bz_urlEncode(params->get(i).c_str()))); playerInfoHandler.setPlayerId(playerID); - - bz_addURLJob(httpUri.c_str(),&playerInfoHandler, playerinfodata.c_str()); - bz_freePlayerRecord ( playerRecord ); - } else + bz_addURLJob(httpUri.c_str(), &playerInfoHandler, playerinfodata.c_str()); + + bz_freePlayerRecord(playerRecord); + } + else showHelp(playerID, params->get(0)); } -void OneVsOne::getTopScore(int playerID, bz_APIStringList* params) +void OneVsOne::getTopScore(int playerID, bz_APIStringList *params) { - if ( params->size() > 2 ) + if (params->size() > 2) showHelp(playerID, params->get(0)); - else { + else + { bz_BasePlayerRecord *playerRecord; std::string items = ""; - playerRecord = bz_getPlayerByIndex ( playerID ); + playerRecord = bz_getPlayerByIndex(playerID); - if ( params->size() == 2 ) + if (params->size() == 2) items = bz_urlEncode(params->get(1).c_str()); - std::string topscoredata = std::string("action=topscore&items=") + items; + std::string topscoredata = std::string("action=topscore&items=") + items; topScoreHandler.setPlayerId(playerID); - - bz_addURLJob(httpUri.c_str(),&topScoreHandler, topscoredata.c_str()); - bz_freePlayerRecord ( playerRecord ); + bz_addURLJob(httpUri.c_str(), &topScoreHandler, topscoredata.c_str()); + + bz_freePlayerRecord(playerRecord); } } -void OneVsOne::getTopZelo(int playerID, bz_APIStringList* params) +void OneVsOne::getTopZelo(int playerID, bz_APIStringList *params) { - if ( params->size() > 2 ) + if (params->size() > 2) showHelp(playerID, params->get(0)); - else { + else + { bz_BasePlayerRecord *playerRecord; std::string items = ""; - playerRecord = bz_getPlayerByIndex ( playerID ); + playerRecord = bz_getPlayerByIndex(playerID); - if ( params->size() == 2 ) + if (params->size() == 2) items = bz_urlEncode(params->get(1).c_str()); - std::string topzelodata = std::string("action=topzelo&items=") + items; + std::string topzelodata = std::string("action=topzelo&items=") + items; topZeloHandler.setPlayerId(playerID); - - bz_addURLJob(httpUri.c_str(),&topZeloHandler, topzelodata.c_str()); - bz_freePlayerRecord ( playerRecord ); + bz_addURLJob(httpUri.c_str(), &topZeloHandler, topzelodata.c_str()); + + bz_freePlayerRecord(playerRecord); } } -void OneVsOne::setMatch(int playerID, bz_APIStringList* params) +void OneVsOne::setMatch(int playerID, bz_APIStringList *params) { Parameters::iterator matchTypeIt; - if ( params->size() == 2 ) { + if (params->size() == 2) + { matchTypeIt = gameTypes.find(params->get(1).c_str()); - if ( matchTypeIt != gameTypes.end()) { + if (matchTypeIt != gameTypes.end()) + { bz_BasePlayerRecord *playerRecord; - playerRecord = bz_getPlayerByIndex( playerID ); + playerRecord = bz_getPlayerByIndex(playerID); - if ( playerRecord->team == eObservers ) { - bz_sendTextMessagef ( BZ_SERVER, playerID,"Observers obviously can't play matches ;)", (*matchTypeIt).first.c_str()); - return; + if (playerRecord->team == eObservers) + { + bz_sendTextMessagef(BZ_SERVER, playerID, "Observers obviously can't play matches ;)", (*matchTypeIt).first.c_str()); + return; } - - if ( ! playerRecord->globalUser ) { - bz_sendTextMessagef ( BZ_SERVER, playerID,"You must be registered and identified to play matches" ); - return; + + if (!playerRecord->globalUser) + { + bz_sendTextMessagef(BZ_SERVER, playerID, "You must be registered and identified to play matches"); + return; } - if ( Players[playerID].losses != 0 ) { - bz_sendTextMessagef ( BZ_SERVER, playerID,"You have to declare the match type BEFORE you start playing" ); - return; + if (Players[playerID].losses != 0) + { + bz_sendTextMessagef(BZ_SERVER, playerID, "You have to declare the match type BEFORE you start playing"); + return; } - if ( ! isMatch() ) { - matchType.clear(); - Players[playerID].matchType = (*matchTypeIt).first; - } else { - bz_sendTextMessagef ( BZ_SERVER, playerID,"There is already a match in progress ... [%s]", (*matchTypeIt).first.c_str()); - return; + if (!isMatch()) + { + matchType.clear(); + Players[playerID].matchType = (*matchTypeIt).first; + } + else + { + bz_sendTextMessagef(BZ_SERVER, playerID, "There is already a match in progress ... [%s]", (*matchTypeIt).first.c_str()); + return; } - bz_sendTextMessagef ( BZ_SERVER, BZ_ALLUSERS,"%s declared to play a match [%s]", playerRecord->callsign.c_str(), (*matchTypeIt).first.c_str()); + bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s declared to play a match [%s]", playerRecord->callsign.c_str(), (*matchTypeIt).first.c_str()); - if ( isMatch () ) { - bz_sendTextMessagef ( BZ_SERVER, BZ_ALLUSERS,"All current players agreed to play a match [%s]", (*matchTypeIt).first.c_str()); - matchType = (*matchTypeIt).first.c_str(); - startTime = bz_getCurrentTime(); - - if ( recording ) - bz_stopRecBuf (); + if (isMatch()) + { + bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "All current players agreed to play a match [%s]", (*matchTypeIt).first.c_str()); + matchType = (*matchTypeIt).first.c_str(); + startTime = bz_getCurrentTime(); + + if (recording) + bz_stopRecBuf(); - recording = bz_startRecBuf (); + recording = bz_startRecBuf(); } - bz_freePlayerRecord ( playerRecord ); + bz_freePlayerRecord(playerRecord); return; } } - // list all availabe types - bz_sendTextMessage( BZ_SERVER, playerID,"Available match types are : "); + // list all availabe types + bz_sendTextMessage(BZ_SERVER, playerID, "Available match types are : "); matchTypeIt = gameTypes.begin(); - for ( ; matchTypeIt != gameTypes.end(); matchTypeIt++ ) - bz_sendTextMessagef( BZ_SERVER, playerID," * %s",(*matchTypeIt).first.c_str()); - + for (; matchTypeIt != gameTypes.end(); matchTypeIt++) + bz_sendTextMessagef(BZ_SERVER, playerID, " * %s", (*matchTypeIt).first.c_str()); } void OneVsOne::unSetMatchAll() { - std::map::iterator it = Players.begin(); + std::map::iterator it = Players.begin(); - for( ; it != Players.end(); it++ ) { - bz_sendTextMessagef ( BZ_SERVER,(*it).first, - "The match is cancelled because the opponent left. Please rejoin." ); + for (; it != Players.end(); it++) + { + bz_sendTextMessagef(BZ_SERVER, (*it).first, + "The match is cancelled because the opponent left. Please rejoin."); (*it).second.matchType.clear(); } -} +} -void OneVsOne::handleMotd(int playerID, bz_APIStringList* params) +void OneVsOne::handleMotd(int playerID, bz_APIStringList *params) { - if ( params->size() == 2 && params->get(1) == "get" ) { - showMotdBanner(playerID, true); + if (params->size() == 2 && params->get(1) == "get") + { + showMotdBanner(playerID, true); } - else if ( params->size() > 2 && params->get(1) == "set" ) { + else if (params->size() > 2 && params->get(1) == "set") + { std::string msg = "action=motd&msg="; msg += std::string(bz_urlEncode(params->get(2).c_str())); @@ -451,194 +462,213 @@ void OneVsOne::handleMotd(int playerID, bz_APIStringList* params) // Dirty hack that converts \n \t \r in the correct control char code // http://en.wikipedia.org/wiki/ASCII#ASCII_control_characters - replace(msg,"%5Cn","%0a"); // \n - replace(msg,"%5Ct","%09"); // \t - replace(msg,"%5Cr","%0d"); // \r + replace(msg, "%5Cn", "%0a"); // \n + replace(msg, "%5Ct", "%09"); // \t + replace(msg, "%5Cr", "%0d"); // \r bz_BasePlayerRecord *playerRecord; playerRecord = bz_getPlayerByIndex(playerID); msg += "&bzid=" + std::string(playerRecord->bzID.c_str()) + "&callsign=" + std::string(bz_urlEncode(playerRecord->callsign.c_str())) + - "&ip=" + std::string(bz_urlEncode(playerRecord->ipAddress.c_str())); + "&ip=" + std::string(bz_urlEncode(playerRecord->ipAddress.c_str())); - bz_freePlayerRecord ( playerRecord ); + bz_freePlayerRecord(playerRecord); motdHandler.setPlayerId(playerID); bz_addURLJob(httpUri.c_str(), &motdHandler, msg.c_str()); motdLastRefreshTime = time(NULL); } - else { + else + { showHelp(playerID, params->get(0)); } - } -void OneVsOne::setLives(int playerID, bz_APIStringList* params) -{ - if ( params->size() == 2 && params->get(1) == "get" ) { - bz_sendTextMessagef ( BZ_SERVER, playerID,"Life count set to %d.", maxLives); +void OneVsOne::setLives(int playerID, bz_APIStringList *params) +{ + if (params->size() == 2 && params->get(1) == "get") + { + bz_sendTextMessagef(BZ_SERVER, playerID, "Life count set to %d.", maxLives); } - else if ( params->size() == 3 && params->get(1) == "set" ) { + else if (params->size() == 3 && params->get(1) == "set") + { int lives = 0; std::istringstream iss(params->get(2).c_str()); - if (( iss >> lives)) { - bz_BasePlayerRecord *playerRecord; - playerRecord = bz_getPlayerByIndex ( playerID ); - - if ( getHighestLoss() < lives && lives > 0 ) { - maxLives=lives; - bz_sendTextMessagef ( BZ_SERVER, BZ_ALLUSERS,"Life count set to %d by %s.", maxLives, playerRecord->callsign.c_str() ); - } else - bz_sendTextMessagef ( BZ_SERVER, playerID,"Life count should be higher then highest player hit count."); - - bz_freePlayerRecord ( playerRecord ); - } else - bz_sendTextMessagef ( BZ_SERVER, playerID,"Life count should be numerical value."); - - } else + if ((iss >> lives)) + { + bz_BasePlayerRecord *playerRecord; + playerRecord = bz_getPlayerByIndex(playerID); + + if (getHighestLoss() < lives && lives > 0) + { + maxLives = lives; + bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Life count set to %d by %s.", maxLives, playerRecord->callsign.c_str()); + } + else + bz_sendTextMessagef(BZ_SERVER, playerID, "Life count should be higher then highest player hit count."); + + bz_freePlayerRecord(playerRecord); + } + else + bz_sendTextMessagef(BZ_SERVER, playerID, "Life count should be numerical value."); + } + else showHelp(playerID, params->get(0)); } void OneVsOne::showHelp(int playerID, bz_ApiString action) { action.tolower(); - + if (action == "help") - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso help []" ); - else if (action == "match") - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso match []" ); - else if (action == "register" && isComm ) - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso register " ); - else if (action == "playerinfo" && isComm ) - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso playerinfo [ ...]" ); - else if (action == "topscore" && isComm ) - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso topscore []" ); - else if (action == "topzelo" && isComm ) - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso topzelo []" ); - else if (action == "motd" && cfgPerm && isComm ) - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso motd | " ); + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso help []"); + else if (action == "match") + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso match []"); + else if (action == "register" && isComm) + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso register "); + else if (action == "playerinfo" && isComm) + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso playerinfo [ ...]"); + else if (action == "topscore" && isComm) + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso topscore []"); + else if (action == "topzelo" && isComm) + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso topzelo []"); + else if (action == "motd" && cfgPerm && isComm) + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso motd | "); else if (action == "lives" && cfgPerm) - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso lives | " ); - else if (action == "reload" && cfgPerm && isComm ) - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso reload " ); - else { - bz_sendTextMessage( BZ_SERVER, playerID,"Usage: /ovso " ); - bz_sendTextMessage( BZ_SERVER, playerID,"" ); - bz_sendTextMessage( BZ_SERVER, playerID,"action:" ); - bz_sendTextMessage( BZ_SERVER, playerID,"" ); - bz_sendTextMessage( BZ_SERVER, playerID," help [] 1vs1 help" ); - bz_sendTextMessage( BZ_SERVER, playerID," match [] start a match of a certain type" ); - - if ( isComm ) { - bz_sendTextMessage( BZ_SERVER, playerID," register 1vs1 league registration" ); - bz_sendTextMessage( BZ_SERVER, playerID," playerinfo [ ...] show 1vs1 info of a player" ); - bz_sendTextMessage( BZ_SERVER, playerID," topscore [] show the monthly player score ranking" ); - bz_sendTextMessage( BZ_SERVER, playerID," topzelo [] show the player zelo ranking" ); - - if ( cfgPerm ) - bz_sendTextMessage( BZ_SERVER, playerID," motd | get/set global message of the day" ); - + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso lives | "); + else if (action == "reload" && cfgPerm && isComm) + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso reload "); + else + { + bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /ovso "); + bz_sendTextMessage(BZ_SERVER, playerID, ""); + bz_sendTextMessage(BZ_SERVER, playerID, "action:"); + bz_sendTextMessage(BZ_SERVER, playerID, ""); + bz_sendTextMessage(BZ_SERVER, playerID, " help [] 1vs1 help"); + bz_sendTextMessage(BZ_SERVER, playerID, " match [] start a match of a certain type"); + + if (isComm) + { + bz_sendTextMessage(BZ_SERVER, playerID, " register 1vs1 league registration"); + bz_sendTextMessage(BZ_SERVER, playerID, " playerinfo [ ...] show 1vs1 info of a player"); + bz_sendTextMessage(BZ_SERVER, playerID, " topscore [] show the monthly player score ranking"); + bz_sendTextMessage(BZ_SERVER, playerID, " topzelo [] show the player zelo ranking"); + + if (cfgPerm) + bz_sendTextMessage(BZ_SERVER, playerID, " motd | get/set global message of the day"); } - if ( cfgPerm ) { - bz_sendTextMessage( BZ_SERVER, playerID," lives | get/set maximum life count" ); - bz_sendTextMessage( BZ_SERVER, playerID," reload reloads the configuration file (not available)" ); + if (cfgPerm) + { + bz_sendTextMessage(BZ_SERVER, playerID, " lives | get/set maximum life count"); + bz_sendTextMessage(BZ_SERVER, playerID, " reload reloads the configuration file (not available)"); } - bz_sendTextMessage( BZ_SERVER, playerID,"" ); + bz_sendTextMessage(BZ_SERVER, playerID, ""); } } -void OneVsOne::printScore ( void ) +void OneVsOne::printScore(void) { - std::map::iterator it = Players.begin(); + std::map::iterator it = Players.begin(); std::string timeMsg; std::string lifeMsg; int hits, lives = 0; - for ( ; it != Players.end(); it++ ) { - hits = (*it).second.losses; - lives = maxLives - (*it).second.losses; + for (; it != Players.end(); it++) + { + hits = (*it).second.losses; + lives = maxLives - (*it).second.losses; - if ( hits == 1 ) - timeMsg = "time"; - else timeMsg = "times"; + if (hits == 1) + timeMsg = "time"; + else + timeMsg = "times"; - if ( lives == 1 ) - lifeMsg = "life"; - else lifeMsg = "lives"; + if (lives == 1) + lifeMsg = "life"; + else + lifeMsg = "lives"; - bz_sendTextMessagef ( BZ_SERVER, BZ_ALLUSERS,"%s got hit %d %s, %d %s left", - (*it).second.callsign.c_str(), hits, timeMsg.c_str(), lives, lifeMsg.c_str()); + bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s got hit %d %s, %d %s left", + (*it).second.callsign.c_str(), hits, timeMsg.c_str(), lives, lifeMsg.c_str()); } } -void OneVsOne::printBanner ( int winner, int loser ) +void OneVsOne::printBanner(int winner, int loser) { // this makes sure that if only 1 player is playing, that player // always gets the 'you lose' banner. - if ( Players.size() == MAX_PLAYERS ) { - bz_sendTextMessagef ( BZ_SERVER, winner," .__ "); - bz_sendTextMessagef ( BZ_SERVER, winner," ___.__. ____ __ __ __ _ _|__| ____ "); - bz_sendTextMessagef ( BZ_SERVER, winner,"< | |/ _ \\| | \\ \\ \\/ \\/ / |/ \\ "); - bz_sendTextMessagef ( BZ_SERVER, winner," \\___ ( <_> ) | / \\ /| | | \\ "); - bz_sendTextMessagef ( BZ_SERVER, winner," / ____|\\____/|____/ \\/\\_/ |__|___| / "); - bz_sendTextMessagef ( BZ_SERVER, winner," \\/ \\/ "); - } - - bz_sendTextMessagef ( BZ_SERVER, loser," .__"); - bz_sendTextMessagef ( BZ_SERVER, loser," ___.__. ____ __ __ | | ____ ______ ____"); - bz_sendTextMessagef ( BZ_SERVER, loser,"< | |/ _ \\| | \\ | | / _ \\/ ___// __ \\ "); - bz_sendTextMessagef ( BZ_SERVER, loser," \\___ ( <_> ) | / | |_( <_> )___ \\\\ ___/"); - bz_sendTextMessagef ( BZ_SERVER, loser," / ____|\\____/|____/ |____/\\____/____ >\\___ >"); - bz_sendTextMessagef ( BZ_SERVER, loser," \\/ \\/ \\/"); + if (Players.size() == MAX_PLAYERS) + { + bz_sendTextMessagef(BZ_SERVER, winner, " .__ "); + bz_sendTextMessagef(BZ_SERVER, winner, " ___.__. ____ __ __ __ _ _|__| ____ "); + bz_sendTextMessagef(BZ_SERVER, winner, "< | |/ _ \\| | \\ \\ \\/ \\/ / |/ \\ "); + bz_sendTextMessagef(BZ_SERVER, winner, " \\___ ( <_> ) | / \\ /| | | \\ "); + bz_sendTextMessagef(BZ_SERVER, winner, " / ____|\\____/|____/ \\/\\_/ |__|___| / "); + bz_sendTextMessagef(BZ_SERVER, winner, " \\/ \\/ "); + } + + bz_sendTextMessagef(BZ_SERVER, loser, " .__"); + bz_sendTextMessagef(BZ_SERVER, loser, " ___.__. ____ __ __ | | ____ ______ ____"); + bz_sendTextMessagef(BZ_SERVER, loser, "< | |/ _ \\| | \\ | | / _ \\/ ___// __ \\ "); + bz_sendTextMessagef(BZ_SERVER, loser, " \\___ ( <_> ) | / | |_( <_> )___ \\\\ ___/"); + bz_sendTextMessagef(BZ_SERVER, loser, " / ____|\\____/|____/ |____/\\____/____ >\\___ >"); + bz_sendTextMessagef(BZ_SERVER, loser, " \\/ \\/ \\/"); } -void OneVsOne::addPlayer ( int playerId, const std::string callsign ) +void OneVsOne::addPlayer(int playerId, const std::string callsign) { Players[playerId].callsign = callsign; - Players[playerId].losses=0; -} + Players[playerId].losses = 0; +} -void OneVsOne::delPlayer(int playerId) -{ +void OneVsOne::delPlayer(int playerId) +{ Players.erase(playerId); } -void OneVsOne::setLoss( int playerId ) +void OneVsOne::setLoss(int playerId) { Players[playerId].losses++; -} +} -int OneVsOne::getHighestLoss(void) +int OneVsOne::getHighestLoss(void) { - int highestLoss=-1; + int highestLoss = -1; - std::map::iterator it = Players.begin(), stop = Players.end(); - for( ; it != stop; it++ ) { - if ( (*it).second.losses > highestLoss ) + std::map::iterator it = Players.begin(), stop = Players.end(); + for (; it != stop; it++) + { + if ((*it).second.losses > highestLoss) highestLoss = (*it).second.losses; } return highestLoss; } -int OneVsOne::getWinner( int playerId ) +int OneVsOne::getWinner(int playerId) { - int winner=-1; + int winner = -1; - if ( Players[playerId].losses == maxLives ) { - if ( Players.size() == 1 ) { - winner=playerId; - } else { - std::map::iterator it = Players.begin(), stop = Players.end(); - for( ; it != stop; it++ ) { - if ( (*it).second.losses != maxLives ) { - winner = (*it).first; - break; - } + if (Players[playerId].losses == maxLives) + { + if (Players.size() == 1) + { + winner = playerId; + } + else + { + std::map::iterator it = Players.begin(), stop = Players.end(); + for (; it != stop; it++) + { + if ((*it).second.losses != maxLives) + { + winner = (*it).first; + break; + } } } } @@ -646,321 +676,348 @@ int OneVsOne::getWinner( int playerId ) return winner; } -void OneVsOne::saveScores(char * scores) +void OneVsOne::saveScores(char *scores) { - // always log the score to bzfs debug channel - bz_debugMessagef ( 2,"%s SCORES :: %s", DEBUG_TAG, scores ); + // always log the score to bzfs debug channel + bz_debugMessagef(2, "%s SCORES :: %s", DEBUG_TAG, scores); // log the score also to a seperate file if configured - if ( logFile != "none" ) { - std::ofstream myfile; + if (logFile != "none") + { + std::ofstream myfile; myfile.open(logFile.c_str(), std::ios::out | std::ios::app | std::ios::binary); myfile << scores; myfile.close(); - } + } } void OneVsOne::showMotdBanner(int playerId, bool force) { // only get the motd from the remote server when the interval has exceeded // else get the cached motd - if ( ((time(NULL) - motdLastRefreshTime) > refreshInterval) || force ) { + if (((time(NULL) - motdLastRefreshTime) > refreshInterval) || force) + { motdHandler.setPlayerId(playerId); bz_addURLJob(httpUri.c_str(), &motdHandler, "action=motd"); motdLastRefreshTime = time(NULL); } - else motdHandler.showData(playerId); + else + motdHandler.showData(playerId); } void OneVsOne::showWelcomeMessage(int playerId, bool force) { // only get the welcome message from the remote server when the interval has exceeded // else get the cached welcome message - if ( ((time(NULL) - welcomeMessageLastRefreshTime) > refreshInterval) || force ) { + if (((time(NULL) - welcomeMessageLastRefreshTime) > refreshInterval) || force) + { welcomeMessageHandler.setPlayerId(playerId); bz_addURLJob(httpUri.c_str(), &welcomeMessageHandler, "action=welcome_msg"); welcomeMessageLastRefreshTime = time(NULL); } - else welcomeMessageHandler.showData(playerId); + else + welcomeMessageHandler.showData(playerId); } void OneVsOne::logRecordMatch(std::string mType, int winner, int loser) { time_t t = time(NULL); - tm * now = gmtime(&t); - int duration = (int) (bz_getCurrentTime() - startTime); - + tm *now = gmtime(&t); + int duration = (int)(bz_getCurrentTime() - startTime); + char scores[200]; char match_date[100]; std::string reportData; // save recording - if ( recording ) { + if (recording) + { char filename[512]; - snprintf( filename,512,"%s[%d]_%s[%d]_%02d%02d%02d_%02d%02d%02d.bzr", - Players[winner].callsign.c_str(),Players[loser].losses,Players[loser].callsign.c_str(), - Players[winner].losses, now->tm_year+1900,now->tm_mon+1,now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec); - bz_saveRecBuf( filename ); + snprintf(filename, 512, "%s[%d]_%s[%d]_%02d%02d%02d_%02d%02d%02d.bzr", + Players[winner].callsign.c_str(), Players[loser].losses, Players[loser].callsign.c_str(), + Players[winner].losses, now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec); + bz_saveRecBuf(filename); bz_stopRecBuf(); - bz_sendTextMessagef ( BZ_SERVER, BZ_ALLUSERS,"Match has been recorded as %s ", filename ); - } + bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Match has been recorded as %s ", filename); + } - 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); + 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); // get bzid's ... dirty bz_BasePlayerRecord *playerRecord; - playerRecord = bz_getPlayerByIndex ( winner ); + playerRecord = bz_getPlayerByIndex(winner); bz_ApiString wbzid = playerRecord->bzID; bz_ApiString wip = playerRecord->ipAddress; - bz_freePlayerRecord ( playerRecord ); + bz_freePlayerRecord(playerRecord); - playerRecord = bz_getPlayerByIndex ( loser ); + playerRecord = bz_getPlayerByIndex(loser); bz_ApiString lbzid = playerRecord->bzID; bz_ApiString lip = playerRecord->ipAddress; - bz_freePlayerRecord ( playerRecord ); + bz_freePlayerRecord(playerRecord); if (bz_getPublic()) serverName = bz_getPublicAddr().c_str(); - // format scores - sprintf( scores,"%s\t%s\t%s\t-\t%s\t%d\t-\t%d\t%s\t-\t%s\t%s\t%d\t%s\t%s\t-\t%s\n", gameTypes[mType].c_str(), match_date, - Players[winner].callsign.c_str(), Players[loser].callsign.c_str(), Players[loser].losses, Players[winner].losses, - wbzid.c_str(), lbzid.c_str(), gameStyle.c_str(), duration, serverName.c_str(),wip.c_str(), lip.c_str()); + // format scores + sprintf(scores, "%s\t%s\t%s\t-\t%s\t%d\t-\t%d\t%s\t-\t%s\t%s\t%d\t%s\t%s\t-\t%s\n", gameTypes[mType].c_str(), match_date, + Players[winner].callsign.c_str(), Players[loser].callsign.c_str(), Players[loser].losses, Players[winner].losses, + wbzid.c_str(), lbzid.c_str(), gameStyle.c_str(), duration, serverName.c_str(), wip.c_str(), lip.c_str()); // save scores to file and bzfs log - saveScores( scores ); + saveScores(scores); // do reporting over http if enabled - if ( isComm ) { - reportData = std::string ("action=report") + std::string("&server=") + std::string(bz_urlEncode(serverName.c_str())) - + std::string("&style=") + std::string(bz_urlEncode(gameStyle.c_str())) + - std::string("&type=") + std::string(bz_urlEncode(gameTypes[mType].c_str())) + - std::string("&date=") + std::string(bz_urlEncode(match_date)) + std::string("&winner=") + - std::string(bz_urlEncode(Players[winner].callsign.c_str())) + std::string("&loser=") + - std::string(bz_urlEncode(Players[loser].callsign.c_str())) + std::string("&winner_score=") + - to_string(Players[loser].losses) + std::string("&loser_score=") + to_string(Players[winner].losses) + - std::string("&wbzid=") + std::string(wbzid.c_str()) + std::string("&lbzid=") + std::string(lbzid.c_str()) + - std::string("&wip=") + std::string(wip.c_str()) + std::string("&lip=") + std::string(lip.c_str() + - std::string("&duration=") + to_string(duration)); + if (isComm) + { + reportData = std::string("action=report") + std::string("&server=") + std::string(bz_urlEncode(serverName.c_str())) + std::string("&style=") + std::string(bz_urlEncode(gameStyle.c_str())) + + std::string("&type=") + std::string(bz_urlEncode(gameTypes[mType].c_str())) + + std::string("&date=") + std::string(bz_urlEncode(match_date)) + std::string("&winner=") + + std::string(bz_urlEncode(Players[winner].callsign.c_str())) + std::string("&loser=") + + std::string(bz_urlEncode(Players[loser].callsign.c_str())) + std::string("&winner_score=") + + to_string(Players[loser].losses) + std::string("&loser_score=") + to_string(Players[winner].losses) + + std::string("&wbzid=") + std::string(wbzid.c_str()) + std::string("&lbzid=") + std::string(lbzid.c_str()) + + std::string("&wip=") + std::string(wip.c_str()) + std::string("&lip=") + std::string(lip.c_str() + std::string("&duration=") + to_string(duration)); reportHandler.setPlayerId(BZ_ALLUSERS); bz_addURLJob(httpUri.c_str(), &reportHandler, reportData.c_str()); } - } -void OneVsOne::Event ( bz_EventData *eventData ) +void OneVsOne::Event(bz_EventData *eventData) { - if (eventData->eventType == bz_ePlayerJoinEvent) { - bz_PlayerJoinPartEventData_V1 *joinData = (bz_PlayerJoinPartEventData_V1*)eventData; + if (eventData->eventType == bz_ePlayerJoinEvent) + { + bz_PlayerJoinPartEventData_V1 *joinData = (bz_PlayerJoinPartEventData_V1 *)eventData; - if ( isWelcome ) + if (isWelcome) showWelcomeMessage(joinData->record->playerID); - if ( isMotd ) + if (isMotd) showMotdBanner(joinData->record->playerID); - + // revoking superkill perms makes sure admin/cops don't abuse it - // when a match is in progress ;) - if ( bz_hasPerm ( joinData->record->playerID, "superkill" )) - bz_revokePerm ( joinData->record->playerID, "superkill" ); + // when a match is in progress ;) + if (bz_hasPerm(joinData->record->playerID, "superkill")) + bz_revokePerm(joinData->record->playerID, "superkill"); if (joinData->record->team != eObservers) - addPlayer(joinData->record->playerID,joinData->record->callsign.c_str()); + addPlayer(joinData->record->playerID, joinData->record->callsign.c_str()); if (joinData->record->team == eObservers && isMatch()) - bz_sendTextMessagef ( BZ_SERVER, joinData->record->playerID,"Match in progress ... [%s]", matchType.c_str()); + bz_sendTextMessagef(BZ_SERVER, joinData->record->playerID, "Match in progress ... [%s]", matchType.c_str()); } - if (eventData->eventType == bz_ePlayerPartEvent) { - bz_PlayerJoinPartEventData_V1 *partData = (bz_PlayerJoinPartEventData_V1*)eventData; + if (eventData->eventType == bz_ePlayerPartEvent) + { + bz_PlayerJoinPartEventData_V1 *partData = (bz_PlayerJoinPartEventData_V1 *)eventData; - if ( partData->record->team != eObservers ) { + if (partData->record->team != eObservers) + { if (isMatch()) - unSetMatchAll(); + unSetMatchAll(); matchType.clear(); - delPlayer ( partData->record->playerID ); + delPlayer(partData->record->playerID); - if ( recording ) - bz_stopRecBuf (); + if (recording) + bz_stopRecBuf(); } } - if (eventData->eventType == bz_ePlayerDieEvent) { + if (eventData->eventType == bz_ePlayerDieEvent) + { - if ( !Players.empty () ) { - bz_PlayerDieEventData_V1 *dieData = (bz_PlayerDieEventData_V1*)eventData; + if (!Players.empty()) + { + bz_PlayerDieEventData_V1 *dieData = (bz_PlayerDieEventData_V1 *)eventData; setLoss(dieData->playerID); printScore(); - if (getWinner(dieData->playerID) != -1) { - int loser=dieData->playerID; - int winner=getWinner(dieData->playerID); + if (getWinner(dieData->playerID) != -1) + { + int loser = dieData->playerID; + int winner = getWinner(dieData->playerID); - bz_gameOver (winner, eNoTeam); + bz_gameOver(winner, eNoTeam); - printBanner(winner, loser); + printBanner(winner, loser); - if (isMatch()) - logRecordMatch(matchType,winner,loser); + if (isMatch()) + logRecordMatch(matchType, winner, loser); - // remove all players from the list - delPlayer ( loser ); - delPlayer ( winner ); + // remove all players from the list + delPlayer(loser); + delPlayer(winner); - // reset matchtype - matchType.clear(); + // reset matchtype + matchType.clear(); } } } - if (eventData->eventType == bz_eSlashCommandEvent) { - bz_SlashCommandEventData_V1 *slashCommandData = (bz_SlashCommandEventData_V1*)eventData; + if (eventData->eventType == bz_eSlashCommandEvent) + { + bz_SlashCommandEventData_V1 *slashCommandData = (bz_SlashCommandEventData_V1 *)eventData; - if (strcasecmp(slashCommandData->message.c_str(),"/superkill") == 0) { - if ( isMatch() ) { - bz_sendTextMessagef ( BZ_SERVER,slashCommandData->from, - "You can't perform /superkill when a match is in progress" ); - } else - bz_superkill(); + if (strcasecmp(slashCommandData->message.c_str(), "/superkill") == 0) + { + if (isMatch()) + { + bz_sendTextMessagef(BZ_SERVER, slashCommandData->from, + "You can't perform /superkill when a match is in progress"); + } + else + bz_superkill(); } } } -bool OneVsOne::SlashCommand ( int playerID, bz_ApiString cmd, bz_ApiString msg, bz_APIStringList* cmdParams ) +bool OneVsOne::SlashCommand(int playerID, bz_ApiString cmd, bz_ApiString msg, bz_APIStringList *cmdParams) { // transfrom to lowercase cmd.tolower(); - //msg.tolower(); - - if ( cmd == "official" ) { - bz_sendTextMessagef ( BZ_SERVER, playerID, - "The '/official' command is DEPRECATED, use '/ovso match official' from now on."); - cmd = "ovso"; - cmdParams->push_back(std::string("match")); - cmdParams->push_back(std::string("official")); + // msg.tolower(); + + if (cmd == "official") + { + bz_sendTextMessagef(BZ_SERVER, playerID, + "The '/official' command is DEPRECATED, use '/ovso match official' from now on."); + cmd = "ovso"; + cmdParams->push_back(std::string("match")); + cmdParams->push_back(std::string("official")); } - cfgPerm = bz_hasPerm(playerID,cfgPermName.c_str()); + cfgPerm = bz_hasPerm(playerID, cfgPermName.c_str()); - if ( cmd == "ovso") { - if ( cmdParams->size() >= 1 ) { + if (cmd == "ovso") + { + if (cmdParams->size() >= 1) + { bz_ApiString action = cmdParams->get(0); action.tolower(); - if ( action == "help") { - if ( cmdParams->size() == 2 ) - showHelp(playerID,cmdParams->get(1)); - else showHelp(playerID); + if (action == "help") + { + if (cmdParams->size() == 2) + showHelp(playerID, cmdParams->get(1)); + else + showHelp(playerID); - return true; - } + return true; + } + + if (action == "register" && isComm) + { + registerPlayer(playerID, cmdParams); + return true; + } + + if (action == "playerinfo" && isComm) + { + bz_APIStringList *p = bz_newStringList(); + p->tokenize(msg.c_str(), " ", 0, true); + getPlayerInfo(playerID, p); + bz_deleteStringList(p); + return true; + } + + if (action == "topscore" && isComm) + { + getTopScore(playerID, cmdParams); + return true; + } + + if (action == "topzelo" && isComm) + { + getTopZelo(playerID, cmdParams); + return true; + } - if ( action == "register" && isComm ) { - registerPlayer(playerID, cmdParams); - return true; + if (action == "match") + { + setMatch(playerID, cmdParams); + return true; } - if ( action == "playerinfo" && isComm ) { - bz_APIStringList *p = bz_newStringList(); - p->tokenize(msg.c_str(), " ", 0, true); - getPlayerInfo(playerID, p); - bz_deleteStringList(p); - return true; - } - - if ( action == "topscore" && isComm ) { - getTopScore(playerID, cmdParams); - return true; + if (action == "motd" && cfgPerm && isComm) + { + bz_APIStringList *m = bz_newStringList(); + m->tokenize(msg.c_str(), " ", 3, false); + handleMotd(playerID, m); + bz_deleteStringList(m); + return true; } - if ( action == "topzelo" && isComm ) { - getTopZelo(playerID, cmdParams); - return true; - } - - if ( action == "match") { - setMatch(playerID, cmdParams); - return true; - } - - if ( action == "motd" && cfgPerm && isComm ) { - bz_APIStringList *m = bz_newStringList(); - m->tokenize(msg.c_str(), " ", 3, false); - handleMotd(playerID, m); - bz_deleteStringList(m); - return true; - } - - if ( action == "lives" && cfgPerm ) { - setLives(playerID, cmdParams); - return true; + if (action == "lives" && cfgPerm) + { + setLives(playerID, cmdParams); + return true; } - if ( action == "reload" && cfgPerm ) { - return true; + if (action == "reload" && cfgPerm) + { + return true; } - } + } showHelp(playerID); - } + } return true; } -void OneVsOne::Init ( const char* commandLine ) +void OneVsOne::Init(const char *commandLine) { std::string cmdLine = commandLine; if (cmdLine.size()) readConfig(cmdLine); - - bz_registerCustomSlashCommand ("ovso", this); - // compatibility stuff - if (isCompat()) { - Parameters::iterator it = gameTypes.find("official"); - if ( it != gameTypes.end() ) - bz_registerCustomSlashCommand ((*it).first.c_str(), this); + bz_registerCustomSlashCommand("ovso", this); + + // compatibility stuff + if (isCompat()) + { + Parameters::iterator it = gameTypes.find("official"); + if (it != gameTypes.end()) + bz_registerCustomSlashCommand((*it).first.c_str(), this); } - + Register(bz_ePlayerJoinEvent); Register(bz_ePlayerPartEvent); Register(bz_ePlayerDieEvent); Register(bz_eSlashCommandEvent); - bz_debugMessage( DEBUG_LEVEL, "OneVsOne plugin loaded" ); - + bz_debugMessage(DEBUG_LEVEL, "OneVsOne plugin loaded"); } -void OneVsOne::Cleanup ( void ) -{ - - // compatibility stuff - if (isCompat()) { +void OneVsOne::Cleanup(void) +{ + + // compatibility stuff + if (isCompat()) + { Parameters::iterator it = gameTypes.find("official"); - if ( it != gameTypes.end() ) - bz_removeCustomSlashCommand ((*it).first.c_str()); + if (it != gameTypes.end()) + bz_removeCustomSlashCommand((*it).first.c_str()); } - bz_removeCustomSlashCommand ("ovso"); + bz_removeCustomSlashCommand("ovso"); Flush(); - bz_debugMessage( DEBUG_LEVEL, "OneVsOne plugin unloaded" ); - + bz_debugMessage(DEBUG_LEVEL, "OneVsOne plugin unloaded"); } // Local Variables: *** diff --git a/UrlHandler.cpp b/UrlHandler.cpp index 22777f6..47e9943 100644 --- a/UrlHandler.cpp +++ b/UrlHandler.cpp @@ -1,72 +1,77 @@ #include "UrlHandler.h" -bool replace_v2(std::string& s,const char * orig,const char * rep ) +bool replace_v2(std::string &s, const char *orig, const char *rep) { - bool retval=false; - while ( s.find(orig) != std::string::npos ) { - s.replace(s.find(orig),std::string(orig).size(),rep); - retval=true; + bool retval = false; + while (s.find(orig) != std::string::npos) + { + s.replace(s.find(orig), std::string(orig).size(), rep); + retval = true; } return retval; } -void BaseUrlHandler::URLDone ( const char* /*URL*/, const void * data, unsigned int size, bool complete ) +void BaseUrlHandler::URLDone(const char * /*URL*/, const void *data, unsigned int size, bool complete) { - if (complete) { + if (complete) + { int _playerId = _playerIds[0]; _playerIds.erase(_playerIds.begin()); - if ( size > 1 && size < _max_data_size ) { - std::string _data; - _data.append((const 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"); + if (size > 1 && size < _max_data_size) + { + std::string _data; + _data.append((const 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_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."); + 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."); } } } -void BaseUrlHandler::URLError ( const char* /*URL*/, int errorCode, const char * errorString ) +void BaseUrlHandler::URLError(const char * /*URL*/, int errorCode, const char *errorString) { int _playerId = _playerIds[0]; _playerIds.erase(_playerIds.begin()); - bz_sendTextMessagef(BZ_SERVER, _playerId,"Action failed with errorcode = %d - %s !!",errorCode, errorString); + bz_sendTextMessagef(BZ_SERVER, _playerId, "Action failed with errorcode = %d - %s !!", errorCode, errorString); } void BaseUrlHandler::showDataOK(int playerId) { - for ( unsigned int i = 1; i < dataList->size(); i++) - bz_sendTextMessagef ( BZ_SERVER, playerId,"%s", dataList->get(i).c_str()); + for (unsigned int i = 1; i < dataList->size(); i++) + bz_sendTextMessagef(BZ_SERVER, playerId, "%s", dataList->get(i).c_str()); } void BaseUrlHandler::showDataNOK(int playerId) { - for ( unsigned int i = 1; i < dataList->size(); i++) - bz_sendTextMessagef ( BZ_SERVER, playerId,"%s", dataList->get(1).c_str()); + for (unsigned int i = 1; i < dataList->size(); i++) + bz_sendTextMessagef(BZ_SERVER, playerId, "%s", dataList->get(1).c_str()); } -void BaseUrlHandler::showData(int playerId) +void BaseUrlHandler::showData(int playerId) { - if (dataList->get(0) == "OK") + if (dataList->get(0) == "OK") showDataOK(playerId); - if (dataList->get(0) == "NOK" && (! noNOKNotify) ) + if (dataList->get(0) == "NOK" && (!noNOKNotify)) showDataNOK(playerId); } @@ -75,12 +80,12 @@ void BaseUrlHandler::setPlayerId(int playerId) _playerIds.push_back(playerId); } -bool BaseUrlHandler::is_valid_status(const std::string& data) +bool BaseUrlHandler::is_valid_status(const std::string &data) { if (data.size() < 2) return false; - if ( data.compare(0,2, "OK") == 0 || data.compare(0,3, "NOK") == 0) + if (data.compare(0, 2, "OK") == 0 || data.compare(0, 3, "NOK") == 0) return true; return false; @@ -88,23 +93,24 @@ bool BaseUrlHandler::is_valid_status(const std::string& data) void BaseUrlHandler::setNoNoKNotify(bool notify) { - noNOKNotify = notify; + noNOKNotify = notify; } void PlayerInfo::showDataOK(int playerId) -{ - for ( unsigned int i = 1; i < dataList->size(); i++) { - bz_APIStringList* playerList = bz_newStringList(); +{ + 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_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); } } @@ -112,39 +118,40 @@ void PlayerInfo::showDataOK(int playerId) void TopScore::showDataOK(int playerId) { - bz_sendTextMessage ( BZ_SERVER, playerId,"Monthly points ranking"); - bz_sendTextMessage ( BZ_SERVER, playerId,"-------------------------------------------"); - bz_sendTextMessagef ( BZ_SERVER, playerId,"%-4s %-32s %5s", "Pos", "Player", "Score"); - bz_sendTextMessagef ( BZ_SERVER, playerId,"%-4s %-32s %5s", "---", "------", "-----"); + bz_sendTextMessage(BZ_SERVER, playerId, "Monthly points ranking"); + bz_sendTextMessage(BZ_SERVER, playerId, "-------------------------------------------"); + bz_sendTextMessagef(BZ_SERVER, playerId, "%-4s %-32s %5s", "Pos", "Player", "Score"); + bz_sendTextMessagef(BZ_SERVER, playerId, "%-4s %-32s %5s", "---", "------", "-----"); - for ( unsigned int i = 1; i < dataList->size(); i++) + for (unsigned int i = 1; i < dataList->size(); i++) { - bz_APIStringList* topScoreList = bz_newStringList(); + bz_APIStringList *topScoreList = bz_newStringList(); topScoreList->tokenize(dataList->get(i).c_str(), "\t", 3, false); - bz_sendTextMessagef ( BZ_SERVER, playerId,"%-4s %-32s %5s", topScoreList->get(0).c_str(), - topScoreList->get(1).c_str(),topScoreList->get(2).c_str()); + bz_sendTextMessagef(BZ_SERVER, playerId, "%-4s %-32s %5s", topScoreList->get(0).c_str(), + topScoreList->get(1).c_str(), topScoreList->get(2).c_str()); bz_deleteStringList(topScoreList); } - bz_sendTextMessage ( BZ_SERVER, playerId,"-------------------------------------------"); + bz_sendTextMessage(BZ_SERVER, playerId, "-------------------------------------------"); } 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", "---", "------", "----"); + 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(); + 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_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,"-------------------------------------------"); + bz_sendTextMessage(BZ_SERVER, playerId, "-------------------------------------------"); } diff --git a/UrlHandler.h b/UrlHandler.h index 6017bbc..756460b 100644 --- a/UrlHandler.h +++ b/UrlHandler.h @@ -6,84 +6,80 @@ #include "bzfsAPI.h" - /*** - * class BaseUrlHandler -***/ + * class BaseUrlHandler + ***/ class BaseUrlHandler : public bz_BaseURLHandler { - public: - BaseUrlHandler() - { - _playerIds.clear(); - // max data size in bytes (1MB) - _max_data_size = 1048576; - - noNOKNotify = false; - dataList = bz_newStringList(); - }; - - ~BaseUrlHandler() { bz_deleteStringList(dataList); }; - - virtual void URLDone ( const char* /*URL*/, const void * data, unsigned int size, bool complete ); - virtual void URLError ( const char* /*URL*/, int /*errorCode*/, const char * /*errorString*/ ); - virtual void showDataOK(int playerId); - virtual void showDataNOK(int playerId); - virtual void showData(int playerId); - void setPlayerId(int playerId); - bool is_valid_status(const std::string& data); - void setNoNoKNotify(bool notify); - - private: - bool noNOKNotify; - - protected: - unsigned int _max_data_size; - std::vector _playerIds; - bz_APIStringList* dataList; +public: + BaseUrlHandler() + { + _playerIds.clear(); + // max data size in bytes (1MB) + _max_data_size = 1048576; + + noNOKNotify = false; + dataList = bz_newStringList(); + }; + + ~BaseUrlHandler() { bz_deleteStringList(dataList); }; + + virtual void URLDone(const char * /*URL*/, const void *data, unsigned int size, bool complete); + virtual void URLError(const char * /*URL*/, int /*errorCode*/, const char * /*errorString*/); + virtual void showDataOK(int playerId); + virtual void showDataNOK(int playerId); + virtual void showData(int playerId); + void setPlayerId(int playerId); + bool is_valid_status(const std::string &data); + void setNoNoKNotify(bool notify); + +private: + bool noNOKNotify; + +protected: + unsigned int _max_data_size; + std::vector _playerIds; + bz_APIStringList *dataList; }; -/*** +/*** * Class PlayerInfo *The PlayerInfo class handles player info queries -***/ + ***/ class PlayerInfo : public BaseUrlHandler { - public: - virtual void showDataOK(int playerId); +public: + virtual void showDataOK(int playerId); }; /*** * Class TopScore * The TopScore class handles the topscore info queries -***/ + ***/ class TopScore : public BaseUrlHandler { - public: - virtual void showDataOK(int playerId); +public: + virtual void showDataOK(int playerId); }; -/*** +/*** * Class TopZelo * The TopZelo class handles the topzelo info queries -***/ + ***/ class TopZelo : public BaseUrlHandler { - public: - virtual void showDataOK(int playerId); +public: + virtual void showDataOK(int playerId); }; class InfoMessage : public BaseUrlHandler { - public: - virtual void done ( const char* /*URL*/, void * data, unsigned int size, bool complete ); +public: + virtual void done(const char * /*URL*/, void *data, unsigned int size, bool complete); }; - #endif - - From 3097bcf11865d309fbe256f6d07e5767d9626396 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 10 Apr 2023 22:58:18 +0200 Subject: [PATCH 07/18] Replace bz_sendTextMessagef with bz_sendTextMessage where suitable. --- OneVsOne.cpp | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/OneVsOne.cpp b/OneVsOne.cpp index 798c0e8..4389102 100644 --- a/OneVsOne.cpp +++ b/OneVsOne.cpp @@ -286,7 +286,7 @@ void OneVsOne::registerPlayer(int playerID, bz_APIStringList *params) bz_addURLJob(httpUri.c_str(), ®isterHandler, registerdata.c_str()); } else - bz_sendTextMessagef(BZ_SERVER, playerID, "You must be globally registered and identified to register here"); + bz_sendTextMessage(BZ_SERVER, playerID, "You must be globally registered and identified to register here"); bz_freePlayerRecord(playerRecord); } @@ -380,19 +380,19 @@ void OneVsOne::setMatch(int playerID, bz_APIStringList *params) if (playerRecord->team == eObservers) { - bz_sendTextMessagef(BZ_SERVER, playerID, "Observers obviously can't play matches ;)", (*matchTypeIt).first.c_str()); + bz_sendTextMessage(BZ_SERVER, playerID, "Observers obviously can't play matches ;-)"); return; } if (!playerRecord->globalUser) { - bz_sendTextMessagef(BZ_SERVER, playerID, "You must be registered and identified to play matches"); + bz_sendTextMessage(BZ_SERVER, playerID, "You must be registered and identified to play matches"); return; } if (Players[playerID].losses != 0) { - bz_sendTextMessagef(BZ_SERVER, playerID, "You have to declare the match type BEFORE you start playing"); + bz_sendTextMessage(BZ_SERVER, playerID, "You have to declare the match type BEFORE you start playing"); return; } @@ -440,8 +440,8 @@ void OneVsOne::unSetMatchAll() for (; it != Players.end(); it++) { - bz_sendTextMessagef(BZ_SERVER, (*it).first, - "The match is cancelled because the opponent left. Please rejoin."); + bz_sendTextMessage(BZ_SERVER, (*it).first, + "The match is cancelled because the opponent left. Please rejoin."); (*it).second.matchType.clear(); } } @@ -506,12 +506,12 @@ void OneVsOne::setLives(int playerID, bz_APIStringList *params) bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "Life count set to %d by %s.", maxLives, playerRecord->callsign.c_str()); } else - bz_sendTextMessagef(BZ_SERVER, playerID, "Life count should be higher then highest player hit count."); + bz_sendTextMessage(BZ_SERVER, playerID, "Life count should be higher then highest player hit count."); bz_freePlayerRecord(playerRecord); } else - bz_sendTextMessagef(BZ_SERVER, playerID, "Life count should be numerical value."); + bz_sendTextMessage(BZ_SERVER, playerID, "Life count should be numerical value."); } else showHelp(playerID, params->get(0)); @@ -603,20 +603,20 @@ void OneVsOne::printBanner(int winner, int loser) if (Players.size() == MAX_PLAYERS) { - bz_sendTextMessagef(BZ_SERVER, winner, " .__ "); - bz_sendTextMessagef(BZ_SERVER, winner, " ___.__. ____ __ __ __ _ _|__| ____ "); - bz_sendTextMessagef(BZ_SERVER, winner, "< | |/ _ \\| | \\ \\ \\/ \\/ / |/ \\ "); - bz_sendTextMessagef(BZ_SERVER, winner, " \\___ ( <_> ) | / \\ /| | | \\ "); - bz_sendTextMessagef(BZ_SERVER, winner, " / ____|\\____/|____/ \\/\\_/ |__|___| / "); - bz_sendTextMessagef(BZ_SERVER, winner, " \\/ \\/ "); + bz_sendTextMessage(BZ_SERVER, winner, " .__ "); + bz_sendTextMessage(BZ_SERVER, winner, " ___.__. ____ __ __ __ _ _|__| ____ "); + bz_sendTextMessage(BZ_SERVER, winner, "< | |/ _ \\| | \\ \\ \\/ \\/ / |/ \\ "); + bz_sendTextMessage(BZ_SERVER, winner, " \\___ ( <_> ) | / \\ /| | | \\ "); + bz_sendTextMessage(BZ_SERVER, winner, " / ____|\\____/|____/ \\/\\_/ |__|___| / "); + bz_sendTextMessage(BZ_SERVER, winner, " \\/ \\/ "); } - bz_sendTextMessagef(BZ_SERVER, loser, " .__"); - bz_sendTextMessagef(BZ_SERVER, loser, " ___.__. ____ __ __ | | ____ ______ ____"); - bz_sendTextMessagef(BZ_SERVER, loser, "< | |/ _ \\| | \\ | | / _ \\/ ___// __ \\ "); - bz_sendTextMessagef(BZ_SERVER, loser, " \\___ ( <_> ) | / | |_( <_> )___ \\\\ ___/"); - bz_sendTextMessagef(BZ_SERVER, loser, " / ____|\\____/|____/ |____/\\____/____ >\\___ >"); - bz_sendTextMessagef(BZ_SERVER, loser, " \\/ \\/ \\/"); + bz_sendTextMessage(BZ_SERVER, loser, " .__"); + bz_sendTextMessage(BZ_SERVER, loser, " ___.__. ____ __ __ | | ____ ______ ____"); + bz_sendTextMessage(BZ_SERVER, loser, "< | |/ _ \\| | \\ | | / _ \\/ ___// __ \\ "); + bz_sendTextMessage(BZ_SERVER, loser, " \\___ ( <_> ) | / | |_( <_> )___ \\\\ ___/"); + bz_sendTextMessage(BZ_SERVER, loser, " / ____|\\____/|____/ |____/\\____/____ >\\___ >"); + bz_sendTextMessage(BZ_SERVER, loser, " \\/ \\/ \\/"); } void OneVsOne::addPlayer(int playerId, const std::string callsign) @@ -876,8 +876,8 @@ void OneVsOne::Event(bz_EventData *eventData) { if (isMatch()) { - bz_sendTextMessagef(BZ_SERVER, slashCommandData->from, - "You can't perform /superkill when a match is in progress"); + bz_sendTextMessage(BZ_SERVER, slashCommandData->from, + "You can't perform /superkill when a match is in progress"); } else bz_superkill(); @@ -893,8 +893,8 @@ bool OneVsOne::SlashCommand(int playerID, bz_ApiString cmd, bz_ApiString msg, bz if (cmd == "official") { - bz_sendTextMessagef(BZ_SERVER, playerID, - "The '/official' command is DEPRECATED, use '/ovso match official' from now on."); + bz_sendTextMessage(BZ_SERVER, playerID, + "The '/official' command is DEPRECATED, use '/ovso match official' from now on."); cmd = "ovso"; cmdParams->push_back(std::string("match")); cmdParams->push_back(std::string("official")); From 0007a3b7ba1ad55502a0d9fad7444fe733af3751 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 10 Apr 2023 23:08:28 +0200 Subject: [PATCH 08/18] Update build instructions. --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 9fa7fb1..12f98db 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,34 @@ The plug-in is compatible with the latest stable BZFLag release (2.4.x). Check out the [BZFlag Wiki article](https://wiki.bzflag.org/Plug-ins#For_versions_on_or_after_2.4.3) on how to build third-party plugins. +Get the latest BZFlag source code from GitHub. + +```bash +$ git clone git@github.com:BZFlag-Dev/bzflag.git +``` + +Clone the latest OneVsOne plugin source code below the BZFlag plugin directory. + +```bash +$ cd bzflag/plugins +$ git clone git@github.com:catay/OneVsOne.git +$ cd .. +``` + +Configure and build BZFlag server and custom plugin. + +```bash +$ ./autogen.sh +$ ./configure --disable-client --enable-custom-plugins=OneVsOne +$ make +``` + +If the build is succesfull the plugin can be found under: + +```bash +$ ls -l plugins/OneVsOne/.libs/OneVsOne.so +``` + ## Plug-in command Line The plug-in takes a ini based configuration file as a parameter. In From c5a7ab0986f6e85d5d91e983ecc93d79908d032a Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Wed, 12 Apr 2023 23:01:56 +0200 Subject: [PATCH 09/18] Fix wrong conditional check and remove redundant code. --- OneVsOne.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/OneVsOne.cpp b/OneVsOne.cpp index 4389102..0f384da 100644 --- a/OneVsOne.cpp +++ b/OneVsOne.cpp @@ -196,13 +196,7 @@ bool OneVsOne::readConfig(std::string fileName) // communication section - if (config.item("communication", "style").size() != 0) - { - httpUri = config.item("communication", "httpuri"); - isComm = true; - } - - if (config.item("communication", "style").size() != 0) + if (config.item("communication", "httpuri").size() != 0) { httpUri = config.item("communication", "httpuri"); isComm = true; From faf643d8ff531907749422d04f4a62a86fe3f9d5 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Sun, 7 May 2023 22:19:09 +0200 Subject: [PATCH 10/18] Rename the 'fancy' patch file so it is not tied to a specific version. Update the README with patch instructions. --- README.md | 7 +++++++ misc/{fancy_bzfs-2.4.15.patch => fancy-2.4.patch} | 0 2 files changed, 7 insertions(+) rename misc/{fancy_bzfs-2.4.15.patch => fancy-2.4.patch} (100%) diff --git a/README.md b/README.md index 12f98db..e3726cc 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,13 @@ $ git clone git@github.com:catay/OneVsOne.git $ cd .. ``` +**Optionally**, apply the 'fancy' patch to the BZFlag source tree. +Make sure you are in the root of the source tree. + +```bash +$ patch -p1 < plugins/OneVsOne/misc/fancy-2.4.patch +``` + Configure and build BZFlag server and custom plugin. ```bash diff --git a/misc/fancy_bzfs-2.4.15.patch b/misc/fancy-2.4.patch similarity index 100% rename from misc/fancy_bzfs-2.4.15.patch rename to misc/fancy-2.4.patch From deff538c7b18f250fdb479b3f6ec9dea44fa1d9f Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Mon, 8 May 2023 23:11:09 +0200 Subject: [PATCH 11/18] Bump version to 2.1.0. --- OneVsOne.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneVsOne.cpp b/OneVsOne.cpp index 0f384da..f167bd0 100644 --- a/OneVsOne.cpp +++ b/OneVsOne.cpp @@ -12,7 +12,7 @@ #include "plugin_utils.h" #include "UrlHandler.h" -#define ONEVSONE "2.0.1" +#define ONEVSONE "2.1.0" #define MAX_PLAYERS 2 From ee034bcac03990ab7e9b1dc8d6b440b218d0fb5a Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Wed, 10 May 2023 22:47:41 +0200 Subject: [PATCH 12/18] Remove license info out of README. --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index e3726cc..72cfda1 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,6 @@ That code is independenlty developed by strayer ([BZBB profile](https://forums. To use the full feature set of the plug-in the league code is mandatory. It is ofcourse always possible to write this from scratch. -## License - -The plug-in is released under the following license: - -GNU LESSER GENERAL PUBLIC LICENSE -Version 2.1, February 1999 - ## Requirements No extra libraries are necessary to get it compiled, it all uses standard stuff. From 79ebe33cece4cd2f0a3cc4d1e44b9e4328dcbe35 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Fri, 19 May 2023 23:51:24 +0200 Subject: [PATCH 13/18] Reorganize example configuration: * Split up configurations per game style. * Add BZFlag server configuration. --- README.md | 11 +++++----- examples/classic/bzfs.conf | 20 ++++++++++++++++++ examples/{classic.ini => classic/ovso.ini} | 0 examples/fancy/bzfs.conf | 21 +++++++++++++++++++ examples/{fancy.ini => fancy/ovso.ini} | 0 examples/hix/bzfs.conf | 24 ++++++++++++++++++++++ examples/{hix.ini => hix/ovso.ini} | 0 7 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 examples/classic/bzfs.conf rename examples/{classic.ini => classic/ovso.ini} (100%) create mode 100644 examples/fancy/bzfs.conf rename examples/{fancy.ini => fancy/ovso.ini} (100%) create mode 100644 examples/hix/bzfs.conf rename examples/{hix.ini => hix/ovso.ini} (100%) diff --git a/README.md b/README.md index 72cfda1..1cc0ce1 100644 --- a/README.md +++ b/README.md @@ -87,14 +87,13 @@ Example: A little more info about the plug-in and the ini configuration file. -Example INI files for different styles can be found in the examples directory. +Example BZFlag server and plugin INI configuration files for different styles can be found in the examples directory. - * [hix style](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/hix.ini) - * [classic style](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/classic.ini) - * [fancy](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/fancy.ini) + * [classic style](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/classic/) + * [fancy](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/fancy/) + * [hix style](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/hix/) -The main purpose of the ini file is to make the plug-in more customizable and -to avoid hardcoded ugliness. +The main purpose of the ini file is to allow custom configuration settings. A INI configuration file has 4 sections which each hold different parameters and values : diff --git a/examples/classic/bzfs.conf b/examples/classic/bzfs.conf new file mode 100644 index 0000000..7efd033 --- /dev/null +++ b/examples/classic/bzfs.conf @@ -0,0 +1,20 @@ +-loadplugin plugins/OneVsOne/.libs/OneVsOne.so,plugins/OneVsOne/examples/classic/ovso.ini +-d -d +-density 5 +-a 45 38 +-printscore +-recdir /path/to/recdir +-ms 2 +-h +r -mp 0,1,1,0,0,50 +-worldsize 250 +-lagwarn 300 +-maxidle 180 +-lagdrop 6 +-p 5155 +-publicaddr :5155 +-publictitle "->>> 1vs1 classic style match server <<<-" +-groupdb /path/to/groupdb.1vs1 +-banfile /path/to/banfile.1vs1 +-reportfile /path/to/report.1vs1 +-set _rejoinTime 0 +-publickey \ No newline at end of file diff --git a/examples/classic.ini b/examples/classic/ovso.ini similarity index 100% rename from examples/classic.ini rename to examples/classic/ovso.ini diff --git a/examples/fancy/bzfs.conf b/examples/fancy/bzfs.conf new file mode 100644 index 0000000..5958a2d --- /dev/null +++ b/examples/fancy/bzfs.conf @@ -0,0 +1,21 @@ +-loadplugin plugins/OneVsOne/.libs/OneVsOne.so,plugins/OneVsOne/examples/fancy/ovso.ini +-d -d +-density 4 +-a 45 38 +-printscore +-recdir /path/to/recdir +-ms 2 +-fancy +-h +r -mp 0,1,1,0,0,10 +-worldsize 250 +-lagwarn 300 +-maxidle 180 +-lagdrop 6 +-p 5156 +-publicaddr :5156 +-publictitle "->>> 1vs1 fancy style match server <<<-" +-groupdb /path/to/groupdb.1vs1 +-banfile /path/to/banfile.1vs1 +-reportfile /path/to/report.1vs1 +-set _rejoinTime 0 +-publickey \ No newline at end of file diff --git a/examples/fancy.ini b/examples/fancy/ovso.ini similarity index 100% rename from examples/fancy.ini rename to examples/fancy/ovso.ini diff --git a/examples/hix/bzfs.conf b/examples/hix/bzfs.conf new file mode 100644 index 0000000..37dc1b3 --- /dev/null +++ b/examples/hix/bzfs.conf @@ -0,0 +1,24 @@ +-loadplugin plugins/OneVsOne/.libs/OneVsOne.so,plugins/OneVsOne/examples/hix/ovso.ini +-d -d +-a 0 0 +-printscore +-recdir /path/to/recdir +-ms 3 +-tk +-j +-fb ++r +-b +-mp 0,1,0,0,1,10 +-lagwarn 300 +-maxidle 180 +-lagdrop 6 +-p 5158 +-publicaddr :5158 +-publictitle "->>> 1vs1 hix style match server <<<-" +-groupdb /path/to/groupdb.1vs1 +-banfile /path/to/banfile.1vs1 +-reportfile /path/to/report.1vs1 +-set _rejoinTime 0 +-publickey +-world misc/maps/hix.bzw \ No newline at end of file diff --git a/examples/hix.ini b/examples/hix/ovso.ini similarity index 100% rename from examples/hix.ini rename to examples/hix/ovso.ini From 4b2b2ca711cfc55356b95788a520aae95f8834db Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Sat, 20 May 2023 01:25:23 +0200 Subject: [PATCH 14/18] Add plugin version command. --- OneVsOne.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/OneVsOne.cpp b/OneVsOne.cpp index f167bd0..5712780 100644 --- a/OneVsOne.cpp +++ b/OneVsOne.cpp @@ -109,6 +109,7 @@ class OneVsOne : public bz_Plugin, public bz_CustomSlashCommandHandler void handleMotd(int p, bz_APIStringList *); void setLives(int p, bz_APIStringList *); void showHelp(int p, bz_ApiString action = "all"); + void showVersion(int p); void printScore(void); void printBanner(int winner, int loser); @@ -511,6 +512,11 @@ void OneVsOne::setLives(int playerID, bz_APIStringList *params) showHelp(playerID, params->get(0)); } +void OneVsOne::showVersion(int playerID) +{ + bz_sendTextMessagef(BZ_SERVER, playerID, "OneVsOne plugin version: %s.", ONEVSONE); +} + void OneVsOne::showHelp(int playerID, bz_ApiString action) { action.tolower(); @@ -539,6 +545,7 @@ void OneVsOne::showHelp(int playerID, bz_ApiString action) bz_sendTextMessage(BZ_SERVER, playerID, ""); bz_sendTextMessage(BZ_SERVER, playerID, "action:"); bz_sendTextMessage(BZ_SERVER, playerID, ""); + bz_sendTextMessage(BZ_SERVER, playerID, " version show plugin version"); bz_sendTextMessage(BZ_SERVER, playerID, " help [] 1vs1 help"); bz_sendTextMessage(BZ_SERVER, playerID, " match [] start a match of a certain type"); @@ -903,6 +910,12 @@ bool OneVsOne::SlashCommand(int playerID, bz_ApiString cmd, bz_ApiString msg, bz bz_ApiString action = cmdParams->get(0); action.tolower(); + if (action == "version") + { + showVersion(playerID); + return true; + } + if (action == "help") { if (cmdParams->size() == 2) From d74dc7e23723e910d61270728b517340e0a0027e Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Sat, 20 May 2023 10:33:55 +0200 Subject: [PATCH 15/18] Update docs. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 1cc0ce1..51a53dc 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,12 @@ reports. The OneVsOne plug-in provides the following in-game commands. Commands with (!) are not avaible in basic mode (without INI file). +Display the plug-in version. + +``` +/ovso version +``` + Lists a brief help section about all the available actions. ``` From 59283d0ae91597d3c1e3e7fdfe5c54c1864db768 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Sat, 20 May 2023 10:44:57 +0200 Subject: [PATCH 16/18] Fix broken links. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 51a53dc..db8ff61 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,9 @@ A little more info about the plug-in and the ini configuration file. Example BZFlag server and plugin INI configuration files for different styles can be found in the examples directory. - * [classic style](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/classic/) - * [fancy](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/fancy/) - * [hix style](https://raw.githubusercontent.com/catay/OneVsOne/master/examples/hix/) + * [classic style](https://github.com/catay/OneVsOne/tree/maint/examples/classic) + * [fancy](https://github.com/catay/OneVsOne/tree/maint/examples/fancy) + * [hix style](https://github.com/catay/OneVsOne/tree/maint/examples/hix) The main purpose of the ini file is to allow custom configuration settings. From a46e6f87386c1a110354842e35cebc929743f5d2 Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Sat, 20 May 2023 10:50:44 +0200 Subject: [PATCH 17/18] Linguistic purism, rename plugin to plug-in. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index db8ff61..45466fb 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ The plug-in is compatible with the latest stable BZFLag release (2.4.x). ## Compilation & Installation Check out the [BZFlag Wiki article](https://wiki.bzflag.org/Plug-ins#For_versions_on_or_after_2.4.3) -on how to build third-party plugins. +on how to build third-party plug-ins. Get the latest BZFlag source code from GitHub. @@ -38,7 +38,7 @@ Get the latest BZFlag source code from GitHub. $ git clone git@github.com:BZFlag-Dev/bzflag.git ``` -Clone the latest OneVsOne plugin source code below the BZFlag plugin directory. +Clone the latest OneVsOne plug-in source code below the BZFlag plugins directory. ```bash $ cd bzflag/plugins @@ -53,7 +53,7 @@ Make sure you are in the root of the source tree. $ patch -p1 < plugins/OneVsOne/misc/fancy-2.4.patch ``` -Configure and build BZFlag server and custom plugin. +Configure and build BZFlag server and custom plug-in. ```bash $ ./autogen.sh @@ -61,7 +61,7 @@ $ ./configure --disable-client --enable-custom-plugins=OneVsOne $ make ``` -If the build is succesfull the plugin can be found under: +If the build is succesfull the plug-in can be found under: ```bash $ ls -l plugins/OneVsOne/.libs/OneVsOne.so @@ -87,7 +87,7 @@ Example: A little more info about the plug-in and the ini configuration file. -Example BZFlag server and plugin INI configuration files for different styles can be found in the examples directory. +Example BZFlag server and plug-in INI configuration files for different styles can be found in the examples directory. * [classic style](https://github.com/catay/OneVsOne/tree/maint/examples/classic) * [fancy](https://github.com/catay/OneVsOne/tree/maint/examples/fancy) @@ -321,7 +321,7 @@ for making this league so attractive. * OneVsOne 2.0.0 (1 Nov 2011) - - Update plugin to make it compatible with the BZFlag 2.4.x API + - Update plug-in to make it compatible with the BZFlag 2.4.x API * OneVsOne 1.0.3 (15 Dec 2009) From fc5dd83a9400c17bb24358344e06cb165fdb686c Mon Sep 17 00:00:00 2001 From: Steven Mertens Date: Sat, 20 May 2023 11:17:56 +0200 Subject: [PATCH 18/18] Update changelog. --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 45466fb..bee9c12 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,25 @@ for making this league so attractive. ## Changelog: +* OneVsOne 2.1.0 (20 May 2023) + + - Fix compiler warnings and errors. + - Switch to BZFlag build-in INI file parser. + - Fix overall formatting of the code. + - Update and cleanup the README. + - Include BZFLag server configurations for different gamestyles. + - Add in-game `/ovso version` command. + +* OneVsOne 2.0.3 (25 May 2019) + + - Add extra build dependencies (Allejo). + +* OneVsOne 2.0.2 (4 June 2018) + + - Convert TXT files to Markdown. + - Integrate plug-in build with BZFlag plug-in build system. + - Update build and install instructions. + * OneVsOne 2.0.1 (6 Jul 2013) - fixed bzfsAPI incompatibility due to changes upstream - Thanks ahs3 for