Merge branch 'develop' of github-softcoder-megaglest:MegaGlest/megaglest-source into develop

This commit is contained in:
SoftCoder 2016-10-31 13:57:11 -07:00
commit 2162ca460a
9 changed files with 156 additions and 105 deletions

View File

@ -108,7 +108,7 @@ private:
int factionCount;
int teams[GameConstants::maxPlayers];
int startLocationIndex[GameConstants::maxPlayers];
int mapFilterIndex;
int mapFilter;
int fallbackCpuMultiplier;
bool defaultUnits;
@ -147,7 +147,7 @@ public:
defaultUnits=false;
defaultResources=false;
defaultVictoryConditions=false;
mapFilterIndex = 0;
mapFilter = 0;
factionCount = 0;
thisFactionIndex = 0;
fogOfWar = true;
@ -373,7 +373,7 @@ public:
return -1;
}
int getMapFilterIndex() const {return mapFilterIndex;}
int getMapFilter() const {return mapFilter;}
bool getDefaultUnits() const {return defaultUnits;}
bool getDefaultResources() const {return defaultResources;}
@ -516,7 +516,7 @@ public:
this->startLocationIndex[factionIndex]= startLocationIndex;
}
void setMapFilterIndex(int mapFilterIndex) {this->mapFilterIndex=mapFilterIndex;}
void setMapFilter(int mapFilter) {this->mapFilter=mapFilter;}
void setDefaultUnits(bool defaultUnits) {this->defaultUnits= defaultUnits;}
void setDefaultResources(bool defaultResources) {this->defaultResources= defaultResources;}
@ -561,7 +561,7 @@ public:
result += "Game ID = " + gameUUID + "\n";
result += "gameName = " + gameName + "\n";
result += "description = " + description + "\n";
result += "mapFilterIndex = " + intToStr(mapFilterIndex) + "\n";
result += "mapFilterIndex = " + intToStr(mapFilter) + "\n";
result += "map = " + map + "\n";
result += "tileset = " + tileset + "\n";
result += "tech = " + tech + "\n";
@ -700,7 +700,7 @@ public:
}
// int mapFilterIndex;
gameSettingsNode->addAttribute("mapFilterIndex",intToStr(mapFilterIndex), mapTagReplacements);
gameSettingsNode->addAttribute("mapFilterIndex",intToStr(mapFilter), mapTagReplacements);
//
//
// bool defaultUnits;
@ -847,7 +847,7 @@ public:
}
// int mapFilterIndex;
mapFilterIndex = gameSettingsNode->getAttribute("mapFilterIndex")->getIntValue();
mapFilter = gameSettingsNode->getAttribute("mapFilterIndex")->getIntValue();
//
//
// bool defaultUnits;

View File

@ -1462,7 +1462,7 @@ void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSe
#endif
saveGameFile << "Description=" << gameSettings->getDescription() << std::endl;
saveGameFile << "MapFilterIndex=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getMapFilterIndex()) << std::endl;
saveGameFile << "MapFilterIndex=" << Shared::PlatformByteOrder::toCommonEndian(gameSettings->getMapFilter()) << std::endl;
saveGameFile << "Map=" << gameSettings->getMap() << std::endl;
saveGameFile << "Tileset=" << gameSettings->getTileset() << std::endl;
saveGameFile << "TechTree=" << gameSettings->getTech() << std::endl;
@ -1533,7 +1533,7 @@ bool CoreData::loadGameSettingsFromFile(std::string fileName, GameSettings *game
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str());
gameSettings->setMapFilterIndex(properties.getInt("MapFilterIndex","0"));
gameSettings->setMapFilter(properties.getInt("MapFilterIndex","0"));
gameSettings->setDescription(properties.getString("Description"));
gameSettings->setMap(properties.getString("Map"));
gameSettings->setTileset(properties.getString("Tileset"));

View File

@ -288,6 +288,22 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
// Network Frame Period
xoffset=65;
//map listBox
xoffset=65;
// MapFilter
labelMapFilter.registerGraphicComponent(containerName,"labelMapFilter");
labelMapFilter.init(xoffset+325, mapHeadPos);
labelMapFilter.setText(lang.getString("MapFilter"));
listBoxMapFilter.registerGraphicComponent(containerName,"listBoxMapFilter");
listBoxMapFilter.init(xoffset+325, mapPos, 80);
listBoxMapFilter.pushBackItem("-");
for(int i=1; i<GameConstants::maxPlayers+1; ++i){
listBoxMapFilter.pushBackItem(intToStr(i));
}
listBoxMapFilter.setSelectedItemIndex(0);
// put them all in a set, to weed out duplicates (gbm & mgm with same name)
// will also ensure they are alphabetically listed (rather than how the OS provides them)
listBoxMap.registerGraphicComponent(containerName,"listBoxMap");
@ -705,6 +721,8 @@ void MenuStateConnectedGame::reloadUI() {
labelMap.setText(lang.getString("Map"));
labelMapFilter.setText(lang.getString("MapFilter"));
labelTileset.setText(lang.getString("Tileset"));
labelTechTree.setText(lang.getString("TechTree"));
@ -1760,6 +1778,7 @@ void MenuStateConnectedGame::broadCastGameSettingsToHeadlessServer(bool forceNow
//printf("Client sending map [%s] admin key [%d]\n",gameSettings.getMap().c_str(),gameSettings.getMasterserver_admin());
printf("sending Settings map filter=%d\n",displayedGamesettings.getMapFilter());
clientInterface->broadcastGameSetup(&displayedGamesettings);
noReceiveTimer=time(NULL);
}
@ -1799,6 +1818,7 @@ void MenuStateConnectedGame::updateResourceMultiplier(const int index) {
void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButton,string advanceToItemStartingWith) {
try {
int oldListBoxMapfilterIndex=listBoxMapFilter.getSelectedItemIndex();
if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@ -1864,6 +1884,19 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
}
else if(listBoxMapFilter.mouseClick(x, y)){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
switchToNextMapGroup(listBoxMapFilter.getSelectedItemIndex()-oldListBoxMapfilterIndex);
if(loadMapInfo(Config::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true) == true) {
labelMapInfo.setText(mapInfo.desc);
}
else {
labelMapInfo.setText("???");
}
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
}
else if(listBoxTechTree.mouseClick(x, y,advanceToItemStartingWith)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
reloadFactions(false,"");
@ -2007,12 +2040,37 @@ void MenuStateConnectedGame::PlayNow(bool saveGame) {
}
}
string MenuStateConnectedGame::getCurrentMapFile() {
int mapIndex=listBoxMap.getSelectedItemIndex();
if(mapIndex < 0) {
return "";
void MenuStateConnectedGame::switchToNextMapGroup(const int direction){
int i=listBoxMapFilter.getSelectedItemIndex();
// if there are no maps for the current selection we switch to next selection
while(formattedPlayerSortedMaps[i].empty()){
i=i+direction;
if(i>GameConstants::maxPlayers){
i=0;
}
if(i<0){
i=GameConstants::maxPlayers;
}
}
return mapFiles[mapIndex];
switchToMapGroup(i);
}
void MenuStateConnectedGame::switchToMapGroup(int filterIndex){
int i = filterIndex;
listBoxMapFilter.setSelectedItemIndex(i);
listBoxMap.setItems(formattedPlayerSortedMaps[i]);
listBoxMap.setSelectedItemIndex(0);
printf("switching map group to filter=%d mapgroup has %d maps. map=%s \n",i,
(int)formattedPlayerSortedMaps[i].size(),formattedPlayerSortedMaps[i][0].c_str());
}
string MenuStateConnectedGame::getCurrentMapFile(){
int i=listBoxMapFilter.getSelectedItemIndex();
int mapIndex=listBoxMap.getSelectedItemIndex();
if(playerSortedMaps[i].empty() == false) {
return playerSortedMaps[i].at(mapIndex);
}
return "";
}
void MenuStateConnectedGame::reloadFactions(bool keepExistingSelectedItem, string scenario) {
@ -2121,6 +2179,7 @@ void MenuStateConnectedGame::loadGameSettings(GameSettings *gameSettings) {
if(listBoxMap.getSelectedItemIndex() >= 0 && listBoxMap.getSelectedItemIndex() < (int)mapFiles.size()) {
gameSettings->setDescription(formatString(getCurrentMapFile()));
gameSettings->setMap(getCurrentMapFile());
gameSettings->setMapFilter(listBoxMapFilter.getSelectedItemIndex());
}
else {
Lang &lang= Lang::getInstance();
@ -2477,6 +2536,7 @@ void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms) {
listBoxFogOfWar.mouseMove(x, y);
checkBoxAllowObservers.mouseMove(x, y);
listBoxTileset.mouseMove(x, y);
listBoxMapFilter.mouseMove(x, y);
listBoxTechTree.mouseMove(x, y);
listBoxPlayerStatus.mouseMove(x,y);
@ -2710,6 +2770,7 @@ void MenuStateConnectedGame::render() {
}
renderer.renderLabel(&labelMap);
renderer.renderLabel(&labelMapFilter);
renderer.renderLabel(&labelFogOfWar);
renderer.renderLabel(&labelAllowObservers);
renderer.renderLabel(&labelFallbackCpuMultiplier);
@ -2721,6 +2782,7 @@ void MenuStateConnectedGame::render() {
renderer.renderLabel(&labelMapInfo);
renderer.renderListBox(&listBoxMap);
renderer.renderListBox(&listBoxMapFilter);
renderer.renderListBox(&listBoxFogOfWar);
renderer.renderCheckBox(&checkBoxAllowObservers);
renderer.renderListBox(&listBoxTileset);
@ -4658,7 +4720,7 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings,
ClientInterface *clientInterface = networkManager.getClientInterface();
updateDataSynchDetailText = true;
vector<string> maps,tilesets,techtree;
vector<string> tilesets,techtree;
if(gameSettings == NULL) {
throw megaglest_runtime_error("gameSettings == NULL");
@ -4700,12 +4762,17 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings,
}
}
if( isHeadlessAdmin() && listBoxMapFilter.getSelectedItemIndex()!=gameSettings->getMapFilter()){
switchToMapGroup(gameSettings->getMapFilter());
// printf("Switching to Map filter group %d \n",gameSettings->getMapFilter());
}
string scenarioDir = Scenario::getScenarioDir(dirList, gameSettings->getScenario());
setupMapList(gameSettings->getScenario());
setupTechList(gameSettings->getScenario());
setupTilesetList(gameSettings->getScenario());
//listBoxMap.setItems(formattedPlayerSortedMaps[gameSettings.getMapFilterIndex()]);
//printf("A gameSettings->getTileset() [%s]\n",gameSettings->getTileset().c_str());
if ( getMissingTilesetFromFTPServerInProgress == false
@ -4871,24 +4938,18 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings,
if(getMissingMapFromFTPServerInProgress == false &&
gameSettings->getMap() != "") {
gameSettings->getMap() != "" && gameSettings->getMapFilter()==listBoxMapFilter.getSelectedItemIndex())
{
// map
bool missingMap=false;
string mapFile = gameSettings->getMap();
mapFile = formatString(mapFile);
maps = formattedMapFiles;
if(currentMap != gameSettings->getMap()) {// load the setup again
currentMap = gameSettings->getMap();
}
bool mapLoaded = loadMapInfo(Config::getMapPath(currentMap,scenarioDir,false), &mapInfo, true);
if(mapLoaded == true) {
if(find(maps.begin(),maps.end(),formatString(gameSettings->getMap())) == maps.end()) {
maps.push_back(formatString(gameSettings->getMap()));
}
}
else {
if(mapLoaded == false) {
// try to get the map via ftp
if(ftpClientThread != NULL && (getMissingMapFromFTPServer != currentMap ||
difftime(time(NULL),getMissingMapFromFTPServerLastPrompted) > REPROMPT_DOWNLOAD_SECONDS)) {
@ -4915,14 +4976,12 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings,
showFTPMessageBox(szBuf, lang.getString("Question"), false);
}
}
maps.push_back(Lang::getInstance().getString("DataMissing","",true));
formattedPlayerSortedMaps[gameSettings->getMapFilter()].push_back(Lang::getInstance().getString("DataMissing","",true));
mapFile = Lang::getInstance().getString("DataMissing","",true);
missingMap=true;
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d] listBoxMap.getSelectedItemIndex() = %d, mapFiles.size() = " MG_SIZE_T_SPECIFIER ", maps.size() = " MG_SIZE_T_SPECIFIER ", getCurrentMapFile() [%s] mapFile [%s]\n",
extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,listBoxMap.getSelectedItemIndex(),mapFiles.size(),maps.size(),getCurrentMapFile().c_str(),mapFile.c_str());
if( isHeadlessAdmin() && !missingMap && mapFile!=listBoxMap.getSelectedItem()){
//console.addLine("Headless server does not have map, switching to next one");
if(isfirstSwitchingMapMessage){
@ -4931,8 +4990,9 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings,
console.addLine(Lang::getInstance().getString("HeadlessServerDoesNotHaveMap","",true));
}
}
listBoxMap.setItems(maps);
//listBoxMap.setItems(maps);
//printf("Setting map from game settings map:%s , settingsfilter=%d , boxfilter=%d \n",gameSettings->getMap().c_str(),gameSettings->getMapFilter(),listBoxMapFilter.getSelectedItemIndex());
listBoxMap.setSelectedItem(mapFile);
labelMapInfo.setText(mapInfo.desc);
}

View File

@ -92,6 +92,9 @@ private:
GraphicListBox listBoxPlayerStatus;
GraphicLabel labelPlayerStatus[GameConstants::maxPlayers];
GraphicLabel labelMapFilter;
GraphicListBox listBoxMapFilter;
GraphicLabel labelAllowObservers;
GraphicCheckBox checkBoxAllowObservers;
@ -292,6 +295,8 @@ private:
void cleanupMapPreviewTexture();
void mouseClickAdmin(int x, int y, MouseButton mouseButton,string advanceToItemStartingWith);
void switchToNextMapGroup(const int direction);
void switchToMapGroup(int filterIndex);
string getCurrentMapFile();
void loadGameSettings(GameSettings *gameSettings);
void reloadFactions(bool keepExistingSelectedItem,string scenario);

View File

@ -2557,6 +2557,7 @@ void MenuStateCustomGame::update() {
//printf("#2 custom menu got map [%s]\n",settings->getMap().c_str());
setupUIFromGameSettings(*settings);
printf("received Settings map filter=%d\n",settings->getMapFilter());
GameSettings gameSettings;
loadGameSettings(&gameSettings);
@ -3490,7 +3491,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
//printf("scenarioInfo.name [%s] [%s] [%s]\n",scenarioInfo.name.c_str(),listBoxMap.getSelectedItem().c_str(),getCurrentMapFile().c_str());
gameSettings->setMapFilterIndex(listBoxMapFilter.getSelectedItemIndex());
gameSettings->setMapFilter(listBoxMapFilter.getSelectedItemIndex());
gameSettings->setDescription(formatString(getCurrentMapFile()));
gameSettings->setMap(getCurrentMapFile());
if(tilesetFiles.empty() == false) {
@ -4036,13 +4037,14 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin
listBoxMap.setSelectedItem(formatString(scenarioInfo.mapName));
}
else {
if(gameSettings.getMapFilterIndex() == 0) {
printf("gameSettings.getMapFilter()=%d \n",gameSettings.getMapFilter());
if(gameSettings.getMapFilter() == 0) {
listBoxMapFilter.setSelectedItemIndex(0);
}
else {
listBoxMapFilter.setSelectedItem(intToStr(gameSettings.getMapFilterIndex()));
listBoxMapFilter.setSelectedItem(intToStr(gameSettings.getMapFilter()));
}
listBoxMap.setItems(formattedPlayerSortedMaps[gameSettings.getMapFilterIndex()]);
listBoxMap.setItems(formattedPlayerSortedMaps[gameSettings.getMapFilter()]);
}
//printf("gameSettings.getMap() [%s] [%s]\n",gameSettings.getMap().c_str(),listBoxMap.getSelectedItem().c_str());
@ -4994,13 +4996,12 @@ int MenuStateCustomGame::setupMapList(string scenario) {
string scenarioDir = Scenario::getScenarioDir(dirList, scenario);
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
// sort map list non case sensitive
std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive);
if(scenario != "") {
vector<string> allMaps2 = MapPreview::findAllValidMaps(config.getPathListForType(ptMaps,""),"",false,true,&invalidMapList);
copy(allMaps2.begin(), allMaps2.end(), std::inserter(allMaps, allMaps.begin()));
std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive);
}
// sort map list non case sensitive
std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive);
if (allMaps.empty()) {
throw megaglest_runtime_error("No maps were found!");
@ -5014,11 +5015,12 @@ int MenuStateCustomGame::setupMapList(string scenario) {
formattedPlayerSortedMaps[i].clear();
}
// at index=0 fill in the whole list
copy(mapFiles.begin(), mapFiles.end(), std::back_inserter(playerSortedMaps[0]));
copy(playerSortedMaps[0].begin(), playerSortedMaps[0].end(), std::back_inserter(formattedPlayerSortedMaps[0]));
std::for_each(formattedPlayerSortedMaps[0].begin(), formattedPlayerSortedMaps[0].end(), FormatString());
//printf("#5\n");
// fill playerSortedMaps and formattedPlayerSortedMaps according to map player count
for(int i= 0; i < (int)mapFiles.size(); i++){// fetch info and put map in right list
loadMapInfo(Config::getMapPath(mapFiles.at(i), scenarioDir, false), &mapInfo, false);

View File

@ -732,6 +732,7 @@ NetworkMessageLaunch::NetworkMessageLaunch(const GameSettings *gameSettings,int8
this->messageType = messageType;
compressedLength = 0;
data.mapFilter = gameSettings->getMapFilter();
data.mapCRC = gameSettings->getMapCRC();
data.tilesetCRC = gameSettings->getTilesetCRC();
data.techCRC = gameSettings->getTechCRC();
@ -812,6 +813,7 @@ void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const {
gameSettings->setFlagTypes1(data.flagTypes1);
gameSettings->setMapCRC(data.mapCRC);
gameSettings->setMapFilter(data.mapFilter);
gameSettings->setTilesetCRC(data.tilesetCRC);
gameSettings->setTechCRC(data.techCRC);
@ -894,6 +896,7 @@ unsigned int NetworkMessageLaunch::getPackedSize() {
packedData.flagTypes1 = 0;
packedData.fogOfWar = 0;
packedData.mapCRC = 0;
packedData.mapFilter = 0;
packedData.masterserver_admin = 0;
packedData.masterserver_admin_factionIndex = 0;
messageType = 0;
@ -953,6 +956,7 @@ unsigned int NetworkMessageLaunch::getPackedSize() {
packedData.networkPlayerLanguages[6].getBuffer(),
packedData.networkPlayerLanguages[7].getBuffer(),
packedData.mapCRC,
packedData.mapFilter,
packedData.tilesetCRC,
packedData.techCRC,
packedData.factionNameList[0].getBuffer(),
@ -1107,6 +1111,7 @@ void NetworkMessageLaunch::unpackMessage(unsigned char *buf) {
data.networkPlayerLanguages[5].getBuffer(),
data.networkPlayerLanguages[6].getBuffer(),
data.networkPlayerLanguages[7].getBuffer(),
&data.mapFilter,
&data.mapCRC,
&data.tilesetCRC,
&data.techCRC,
@ -1261,6 +1266,7 @@ unsigned char * NetworkMessageLaunch::packMessage() {
data.networkPlayerLanguages[5].getBuffer(),
data.networkPlayerLanguages[6].getBuffer(),
data.networkPlayerLanguages[7].getBuffer(),
data.mapFilter,
data.mapCRC,
data.tilesetCRC,
data.techCRC,
@ -1568,6 +1574,7 @@ void NetworkMessageLaunch::toEndian() {
data.teams[i] = Shared::PlatformByteOrder::toCommonEndian(data.teams[i]);
data.startLocationIndex[i] = Shared::PlatformByteOrder::toCommonEndian(data.startLocationIndex[i]);
}
data.mapFilter = Shared::PlatformByteOrder::toCommonEndian(data.mapFilter);
data.mapCRC = Shared::PlatformByteOrder::toCommonEndian(data.mapCRC);
data.tilesetCRC = Shared::PlatformByteOrder::toCommonEndian(data.tilesetCRC);
data.techCRC = Shared::PlatformByteOrder::toCommonEndian(data.techCRC);
@ -1607,6 +1614,7 @@ void NetworkMessageLaunch::fromEndian() {
data.teams[i] = Shared::PlatformByteOrder::fromCommonEndian(data.teams[i]);
data.startLocationIndex[i] = Shared::PlatformByteOrder::fromCommonEndian(data.startLocationIndex[i]);
}
data.mapFilter = Shared::PlatformByteOrder::fromCommonEndian(data.mapFilter);
data.mapCRC = Shared::PlatformByteOrder::fromCommonEndian(data.mapCRC);
data.tilesetCRC = Shared::PlatformByteOrder::fromCommonEndian(data.tilesetCRC);
data.techCRC = Shared::PlatformByteOrder::fromCommonEndian(data.techCRC);

View File

@ -330,6 +330,7 @@ private:
NetworkString<maxSmallStringSize> networkPlayerLanguages[GameConstants::maxPlayers];
uint32 mapCRC;
int8 mapFilter;
uint32 tilesetCRC;
uint32 techCRC;
NetworkString<maxSmallStringSize> factionNameList[maxFactionCRCCount];

View File

@ -143,11 +143,29 @@ ServerInterface::ServerInterface(bool publishEnabled, ClientLagCallbackInterface
//throw megaglest_runtime_error("No maps were found!");
printf("No maps were found (srv)!\n");
}
std::sort(allMaps.begin(),allMaps.end());
std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive);
vector<string> results;
copy(allMaps.begin(), allMaps.end(), std::back_inserter(results));
mapFiles = results;
//player Sorted maps
////////////////////
for(unsigned int i = 0; i < GameConstants::maxPlayers+1; ++i) {
playerSortedMaps[i].clear();
}
// at index=0 fill in the whole list
copy(mapFiles.begin(), mapFiles.end(), std::back_inserter(playerSortedMaps[0]));
MapInfo mapInfo;
// fill playerSortedMaps according to map player count
for(int i= 0; i < (int)mapFiles.size(); i++){// fetch info and put map in right list
//printf("mapFiles.at(i) %s allMaps.at[i] %s\n",mapFiles[i].c_str(),allMaps.at(i).c_str());
MapPreview::loadMapInfo(Config::getMapPath(mapFiles.at(i)), &mapInfo, "MaxPlayers","Size",true) ;
playerSortedMaps[mapInfo.players].push_back(mapFiles.at(i));
}
///////////////////
results.clear();
findDirs(config.getPathListForType(ptTilesets), results);
if (results.empty()) {
@ -2631,73 +2649,29 @@ void ServerInterface::validateGameSettings(GameSettings *serverGameSettings) {
MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE);
string mapFile = serverGameSettings->getMap();
printf("Trying to set map to [%s]. Current map is [%s]\n",serverGameSettings->getMap().c_str(),gameSettings.getMap().c_str());
if(find(mapFiles.begin(),mapFiles.end(),mapFile) == mapFiles.end()) {
printf("map not found on this server\n");
int currentIndex = -1;
string currentMap = gameSettings.getMap();
for (int mapIndex = 0 ;mapIndex < (int)mapFiles.size(); ++mapIndex) {
string current = mapFiles[mapIndex];
if(current == currentMap) {
currentIndex = mapIndex;
break;
}
//printf("Trying to set map to [%s]. Current map is [%s]\n",serverGameSettings->getMap().c_str(),gameSettings.getMap().c_str());
if(gameSettings.getMapFilter()!=serverGameSettings->getMapFilter()){
if( playerSortedMaps[serverGameSettings->getMapFilter()].size()==0){
serverGameSettings->setMapFilter(0);
}
if(currentIndex == -1) {
serverGameSettings->setMap(gameSettings.getMap());
}
else {
if(mapFile>gameSettings.getMap()){
printf("mapFile>gameSettings [%s] > [%s]\n",mapFile.c_str(),gameSettings.getMap().c_str());
int nextIndex = -1;
for (int mapIndex = 0 ;mapIndex < (int)mapFiles.size(); ++mapIndex) {
string current = mapFiles[mapIndex];
if(current > mapFile) {
nextIndex = mapIndex;
break;
}
}
if(nextIndex > -1) {
serverGameSettings->setMap(mapFiles[nextIndex]);
//printf("switch up\n");
}
else {
//printf("overflow top\n");
serverGameSettings->setMap(mapFiles[0]);
}
}
else {
printf("mapFile<gameSettings [%s] < [%s]\n",mapFile.c_str(),gameSettings.getMap().c_str());
int nextIndex = -1;
for (int mapIndex = (int)mapFiles.size()-1 ;mapIndex >= 0; mapIndex--) {
string current = mapFiles[mapIndex];
if(current < mapFile) {
nextIndex = mapIndex;
break;
}
}
if(nextIndex > -1) {
serverGameSettings->setMap(mapFiles[nextIndex]);
//printf("switch down\n");
}
else {
//printf("overflow bottom\n");
serverGameSettings->setMap(mapFiles[(mapFiles.size()-1)]);
}
}
printf("switching map from [%s] to [%s]\n",mapFile.c_str(),serverGameSettings->getMap().c_str());
}
serverGameSettings->setMapFilterIndex(gameSettings.getMapFilterIndex());
Checksum checksum;
string file = Config::getMapPath(serverGameSettings->getMap(),"",false);
checksum.addFile(file);
serverGameSettings->setMapCRC(checksum.getSum());
}
int playerIndex=serverGameSettings->getMapFilter();
if(find(playerSortedMaps[playerIndex].begin(),playerSortedMaps[playerIndex].end(),mapFile) == playerSortedMaps[playerIndex].end()) {
// switch to closest map
string foundMap = "";
for (int i = 0 ;i < (int)playerSortedMaps[playerIndex].size(); ++i) {
foundMap=playerSortedMaps[playerIndex][i];
if(toLower(foundMap)>toLower(serverGameSettings->getMap())){
break;
}
}
printf("map %s not found on this server. Switching to map %s\n",serverGameSettings->getMap().c_str(),foundMap.c_str());
serverGameSettings->setMap(foundMap);
}
Checksum checksum;
string file = Config::getMapPath(serverGameSettings->getMap(),"",false);
checksum.addFile(file);
serverGameSettings->setMapCRC(checksum.getSum());
string tilesetFile = serverGameSettings->getTileset();
if(find(tilesetFiles.begin(),tilesetFiles.end(),tilesetFile) == tilesetFiles.end()) {
@ -2725,7 +2699,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
if(find(mapFiles.begin(),mapFiles.end(),mapFile) == mapFiles.end()) {
printf("Reverting map from [%s] to [%s]\n",serverGameSettings->getMap().c_str(),gameSettings.getMap().c_str());
serverGameSettings->setMapFilterIndex(gameSettings.getMapFilterIndex());
serverGameSettings->setMapFilter(gameSettings.getMapFilter());
serverGameSettings->setMap(gameSettings.getMap());
serverGameSettings->setMapCRC(gameSettings.getMapCRC());
}

View File

@ -87,6 +87,7 @@ private:
bool masterserverAdminRequestLaunch;
vector<string> mapFiles;
vector<string> playerSortedMaps[GameConstants::maxPlayers+1];
vector<string> techTreeFiles;
vector<string> tilesetFiles;