From b4feeecd4a0c62c0668aa92bc9202bad69141f34 Mon Sep 17 00:00:00 2001 From: mathusummut Date: Thu, 13 Dec 2018 14:45:58 +0100 Subject: [PATCH] Fixed potential networking bugs --- source/glest_game/ai/ai.cpp | 4 ++-- source/glest_game/game/commander.cpp | 4 ++-- source/glest_game/main/battle_end.cpp | 2 +- source/glest_game/type_instances/faction.cpp | 18 ++---------------- source/glest_game/world/scenario.cpp | 2 +- source/glest_game/world/unit_updater.h | 2 -- .../sources/platform/posix/socket.cpp | 4 ++-- 7 files changed, 10 insertions(+), 26 deletions(-) diff --git a/source/glest_game/ai/ai.cpp b/source/glest_game/ai/ai.cpp index 35d36368c..535414822 100644 --- a/source/glest_game/ai/ai.cpp +++ b/source/glest_game/ai/ai.cpp @@ -1163,10 +1163,10 @@ namespace Game { ultraResourceAttack = (aiInterface->getControlType() == ctCpuUltra) && random.randRange(0, 2) == 1; bool - megaResourceAttack = (aiInterface->getControlType() == ctCpuZeta) + zetaResourceAttack = (aiInterface->getControlType() == ctCpuZeta) && random.randRange(0, 1) == 1; - if (megaResourceAttack || ultraResourceAttack) { + if (zetaResourceAttack || ultraResourceAttack) { Map * map = aiInterface->getMap(); diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index cd026f445..1270a0156 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -1347,7 +1347,7 @@ namespace Game { // world->getFaction(factionIndex)->getPersonalityType(),world->getFaction(factionIndex)->getIndex(),world->getFaction(factionIndex)->getControlType(),settings->getNetworkPlayerStatuses(factionIndex)); //printf("#2 nctPlayerStatusChange factionIndex = %d playerStatus = %d\n",factionIndex,playerStatus); - settings->setFactionControl(factionIndex, ctCpuUltra); + settings->setFactionControl(factionIndex, ctCpuZeta); settings->setResourceMultiplierIndex(factionIndex, settings-> getFallbackCpuMultiplier @@ -1356,7 +1356,7 @@ namespace Game { //game->get Faction * faction = this->world->getFaction(factionIndex); - faction->setControlType(ctCpuUltra); + faction->setControlType(ctCpuZeta); if (!world->getGame()->getGameOver() && !this->world->getGame()-> diff --git a/source/glest_game/main/battle_end.cpp b/source/glest_game/main/battle_end.cpp index dad3fd8c7..89a94550d 100644 --- a/source/glest_game/main/battle_end.cpp +++ b/source/glest_game/main/battle_end.cpp @@ -698,7 +698,7 @@ namespace Game { "\nx " + floatToStr(stats.getResourceMultiplier(i), 1); } else if (stats.getPlayerLeftBeforeEnd(i) == true) { controlString += - "\n" + lang.getString("CpuZeta") + "\nx " + + "\nx " + floatToStr(stats.getResourceMultiplier(i), 1); } diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 8216fc317..7d678387c 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -1038,22 +1038,8 @@ namespace Game { return 0; } - bool Faction::getCpuControl(bool enableServerControlledAI, - bool isNetworkGame, NetworkRole role) const { - bool result = false; - if (enableServerControlledAI == false || isNetworkGame == false) { - result = (control == ctCpuEasy || control == ctCpu - || control == ctCpuUltra || control == ctCpuZeta); - } else { - if (isNetworkGame == true) { - if (role == nrServer) { - result = (control == ctCpuEasy || control == ctCpu - || control == ctCpuUltra || control == ctCpuZeta); - } - } - } - - return result; + bool Faction::getCpuControl(bool enableServerControlledAI, bool isNetworkGame, NetworkRole role) const { + return getCpuControl(); } bool Faction::getCpuControl() const { diff --git a/source/glest_game/world/scenario.cpp b/source/glest_game/world/scenario.cpp index fecc72861..a81b19f5c 100644 --- a/source/glest_game/world/scenario.cpp +++ b/source/glest_game/world/scenario.cpp @@ -545,7 +545,7 @@ Please contact the ZetaGlest team for more info."; char szBuf[8096] = ""; snprintf(szBuf, 8096, - "Invalid controller value specified in scenario: [%s] must be one of the following: closed, cpu-easy, cpu, cpu-ultra, cpu-zeta, human", + "Invalid controller value specified in scenario: [%s] must be one of the following: closed, cpu-easy, cpu, cpu-ultra, cpu-mega, human", str.c_str()); throw std::runtime_error(szBuf); } diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index 104871062..4aacae630 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -74,8 +74,6 @@ namespace Game { private: static const int maxResSearchRadius = 10; static const int harvestDistance = 5; - static const int ultraResourceFactor = 3; - static const int megaResourceFactor = 4; private: const GameCamera *gameCamera; diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 1074143f2..51caa7fb1 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -2118,7 +2118,7 @@ namespace Shared { memset((char*) &bcaddr, 0, sizeof(bcaddr)); bcaddr.sin_family = AF_INET; bcaddr.sin_addr.s_addr = htonl(INADDR_ANY); - bcaddr.sin_port = port; + bcaddr.sin_port = htons(port); int val = 1; #ifndef WIN32 @@ -2985,7 +2985,7 @@ namespace Shared { if (SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork, "UDP Socket broadcast using IP [%s]\n", ipSubnetMaskList[idx].c_str()); bcLocal[idx].sin_addr.s_addr = inet_addr(ipSubnetMaskList[idx].c_str()); //htonl( INADDR_BROADCAST ); } - bcLocal[idx].sin_port = port; // We are letting the OS fill in the port number for the local machine. + bcLocal[idx].sin_port = htons(port); // We are letting the OS fill in the port number for the local machine. #ifdef WIN32 bcfd[idx] = INVALID_SOCKET; #else