When loading the configuration, verify that the player names are unique. If they are not, use the default ones. (#96)
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -322,6 +323,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fillBuffer();
|
fillBuffer();
|
||||||
|
checkAndCorrectBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +386,37 @@ void ConfigFile::fillBuffer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigFile::checkAndCorrectBuffer()
|
||||||
|
{
|
||||||
|
boost::recursive_mutex::scoped_lock lock(m_configMutex);
|
||||||
|
// For now, only the player names are checked.
|
||||||
|
checkAndCorrectPlayerNames();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigFile::checkAndCorrectPlayerNames()
|
||||||
|
{
|
||||||
|
// Verify that the player names are uniquely set.
|
||||||
|
set<string> playerNames;
|
||||||
|
playerNames.insert(readConfigString("MyName"));
|
||||||
|
for(int i = 1; i <= 9; i++) {
|
||||||
|
ostringstream opponentVar;
|
||||||
|
opponentVar << "Opponent" << i << "Name";
|
||||||
|
playerNames.insert(readConfigString(opponentVar.str()));
|
||||||
|
}
|
||||||
|
if (playerNames.size() < 10 || playerNames.find("") != playerNames.end()) {
|
||||||
|
// The set contains less than 10 players or an empty player name.
|
||||||
|
// Reset to default player names.
|
||||||
|
writeConfigString("MyName", "Human Player");
|
||||||
|
for(int i = 1; i <= 9; i++) {
|
||||||
|
ostringstream opponentVar;
|
||||||
|
ostringstream opponentName;
|
||||||
|
opponentVar << "Opponent" << i << "Name";
|
||||||
|
opponentName << "Player " << i;
|
||||||
|
writeConfigString(opponentVar.str(), opponentName.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigFile::writeBuffer() const
|
void ConfigFile::writeBuffer() const
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -527,7 +560,7 @@ void ConfigFile::updateConfig(ConfigState myConfigState)
|
|||||||
|
|
||||||
//test
|
//test
|
||||||
|
|
||||||
bool contains = noUpdateElemtsList.find(value) != mylist.end();
|
//bool contains = noUpdateElemtsList.find(value) != mylist.end();
|
||||||
|
|
||||||
/////// HIER GEHTS WEITER LOTHAR ;) ///////
|
/////// HIER GEHTS WEITER LOTHAR ;) ///////
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public:
|
|||||||
~ConfigFile();
|
~ConfigFile();
|
||||||
|
|
||||||
void fillBuffer();
|
void fillBuffer();
|
||||||
|
void checkAndCorrectBuffer();
|
||||||
void writeBuffer() const;
|
void writeBuffer() const;
|
||||||
|
|
||||||
void updateConfig(ConfigState);
|
void updateConfig(ConfigState);
|
||||||
@@ -51,6 +52,9 @@ public:
|
|||||||
void writeConfigIntList(std::string varName, std::list<int> varCont);
|
void writeConfigIntList(std::string varName, std::list<int> varCont);
|
||||||
void deleteConfigFile();
|
void deleteConfigFile();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void checkAndCorrectPlayerNames();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
mutable boost::recursive_mutex m_configMutex;
|
mutable boost::recursive_mutex m_configMutex;
|
||||||
|
|||||||
Reference in New Issue
Block a user