- moved version checking into one common method in the util file. Now all network related checks use this common method to determine version compatibility

This commit is contained in:
Mark Vejvoda 2010-10-15 17:27:00 +00:00
parent 1353f61069
commit 59c5fd2581
5 changed files with 30 additions and 19 deletions

View File

@ -116,23 +116,9 @@ ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, const char
selectButton.setText(">");
//printf("glestVersionString [%s] masterServerInfo->getGlestVersion() [%s]\n",glestVersionString.c_str(),masterServerInfo->getGlestVersion().c_str());
if(glestVersionString != masterServerInfo->getGlestVersion()) {
vector<string> tokens;
vector<string> tokensServer;
Tokenize(glestVersionString,tokens,".");
Tokenize(masterServerInfo->getGlestVersion(),tokensServer,".");
// only check the first 3 sections with . to compare makor versions #'s
bool compatibleWithServer = (tokens.size() >= 3 && tokensServer.size() >= 3);
for(int i = 0; compatibleWithServer == true && i < 3; ++i) {
if(tokens[i] != tokensServer[i]) {
compatibleWithServer = false;
}
}
if(compatibleWithServer == false) {
selectButton.setEnabled(false);
selectButton.setEditable(false);
}
}
bool compatible = checkVersionComptability(glestVersionString, masterServerInfo->getGlestVersion());
selectButton.setEnabled(compatible);
selectButton.setEditable(compatible);
GraphicComponent::applyAllCustomProperties(containerName);
}

View File

@ -184,7 +184,9 @@ void ClientInterface::updateLobby() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got NetworkMessageIntro, networkMessageIntro.getGameState() = %d, versionString [%s], sessionKey = %d, playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageIntro.getGameState(),versionString.c_str(),sessionKey,playerIndex);
//check consistency
if(networkMessageIntro.getVersionString() != getNetworkVersionString()) {
bool compatible = checkVersionComptability(networkMessageIntro.getVersionString(), getNetworkVersionString());
if(compatible == false) {
//if(networkMessageIntro.getVersionString() != getNetworkVersionString()) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool versionMatched = false;

View File

@ -368,7 +368,9 @@ void ConnectionSlot::update(bool checkForNewClients) {
}
//check consistency
if(networkMessageIntro.getVersionString() != getNetworkVersionString()) {
bool compatible = checkVersionComptability(getNetworkVersionString(), networkMessageIntro.getVersionString());
if(compatible == false) {
//if(networkMessageIntro.getVersionString() != getNetworkVersionString()) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool versionMatched = false;

View File

@ -180,6 +180,7 @@ int round(float f);
//misc
bool fileExists(const string &path);
bool checkVersionComptability(string clientVersionString, string serverVersionString);
template<typename T>
void deleteValues(T beginIt, T endIt){

View File

@ -542,4 +542,24 @@ bool fileExists(const string &path){
return false;
}
bool checkVersionComptability(string clientVersionString, string serverVersionString) {
bool compatible = (clientVersionString == serverVersionString);
if(compatible == false) {
vector<string> tokens;
vector<string> tokensServer;
Tokenize(clientVersionString,tokens,".");
Tokenize(serverVersionString,tokensServer,".");
// only check the first 3 sections with . to compare makor versions #'s
compatible = (tokens.size() >= 3 && tokensServer.size() >= 3);
for(int i = 0; compatible == true && i < 3; ++i) {
if(tokens[i] != tokensServer[i]) {
compatible = false;
}
}
}
return compatible;
}
}}//end namespace