- Added tileset and map CRC check in the network lobby

- numerous bugfixes
This commit is contained in:
Mark Vejvoda 2011-01-09 04:49:21 +00:00
parent 2e60d3e0a8
commit 1c78fca0fb
28 changed files with 440 additions and 249 deletions

View File

@ -34,7 +34,7 @@ enum FlagTypes1 {
};
class GameSettings{
class GameSettings {
private:
string description;
string map;
@ -69,8 +69,11 @@ private:
uint32 flagTypes1;
public:
int32 mapCRC;
int32 tilesetCRC;
int32 techCRC;
public:
GameSettings() {
thisFactionIndex = 0;
@ -92,6 +95,10 @@ public:
}
flagTypes1 = ft1_none;
mapCRC = 0;
tilesetCRC = 0;
techCRC = 0;
}
// default copy constructor will do fine, and will maintain itself ;)
@ -147,6 +154,10 @@ public:
PathFinderType getPathFinderType() const { return pathFinderType; }
uint32 getFlagTypes1() const { return flagTypes1;}
int32 getMapCRC() const { return mapCRC; }
int32 getTilesetCRC() const { return tilesetCRC; }
int32 getTechCRC() const { return techCRC; }
//set
void setDescription(const string& description) {this->description= description;}
void setMap(const string& map) {this->map= map;}
@ -177,8 +188,13 @@ public:
void setNetworkFramePeriod(int value) {this->networkFramePeriod = value; }
void setNetworkPauseGameForLaggedClients(bool value) {this->networkPauseGameForLaggedClients = value; }
void setPathFinderType(PathFinderType value) {this->pathFinderType = value; }
void setFlagTypes1(uint32 value) {this->flagTypes1 = value; }
void setMapCRC(int32 value) { mapCRC = value; }
void setTilesetCRC(int32 value) { tilesetCRC = value; }
void setTechCRC(int32 value) { techCRC = value; }
string toString() const {
string result = "";
@ -214,6 +230,9 @@ public:
result += "networkPauseGameForLaggedClients = " + intToStr(networkPauseGameForLaggedClients) + "\n";
result += "pathFinderType = " + intToStr(pathFinderType) + "\n";
result += "flagTypes1 = " + intToStr(flagTypes1) + "\n";
result += "mapCRC = " + intToStr(mapCRC) + "\n";
result += "tilesetCRC = " + intToStr(tilesetCRC) + "\n";
result += "techCRC = " + intToStr(techCRC) + "\n";
return result;
}

View File

@ -119,6 +119,12 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
labelInfo.setText("");
labelInfo.setFont(CoreData::getInstance().getMenuFontBig());
timerLabelFlash = time(NULL);
labelDataSynchInfo.registerGraphicComponent(containerName,"labelDataSynchInfo");
labelDataSynchInfo.init(30, networkHeadPos-60);
labelDataSynchInfo.setText("");
labelDataSynchInfo.setFont(CoreData::getInstance().getMenuFontBig());
//create
buttonDisconnect.registerGraphicComponent(containerName,"buttonDisconnect");
buttonDisconnect.init(450, 180, 125);
@ -720,6 +726,17 @@ void MenuStateConnectedGame::render() {
renderer.renderLabel(&labelStatus);
renderer.renderLabel(&labelInfo);
if(difftime(time(NULL),timerLabelFlash) < 1) {
renderer.renderLabel(&labelDataSynchInfo,&RED);
}
else {
renderer.renderLabel(&labelDataSynchInfo,&WHITE);
if(difftime(time(NULL),timerLabelFlash) > 2) {
timerLabelFlash = time(NULL);
}
}
renderer.renderLabel(&labelMap);
renderer.renderLabel(&labelFogOfWar);
renderer.renderLabel(&labelAllowObservers);
@ -845,12 +862,85 @@ void MenuStateConnectedGame::update() {
if(clientInterface->getAllowDownloadDataSynch() == false) {
string label = lang.get("ConnectedToServer");
if(!clientInterface->getServerName().empty()) {
if(clientInterface->getServerName().empty() == false) {
label = label + " " + clientInterface->getServerName();
}
label = label + ", " + clientInterface->getVersionString();
if(clientInterface->getAllowGameDataSynchCheck() == false) {
Config &config = Config::getInstance();
const GameSettings *gameSettings = clientInterface->getGameSettings();
int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL);
// Test data synch
//tilesetCRC++;
//int32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/*", ".xml", NULL);
Checksum checksum;
string file = Map::getMapPath(gameSettings->getMap(),"",false);
checksum.addFile(file);
int32 mapCRC = checksum.getSum();
bool dataSynchMismatch = (mapCRC != gameSettings->getMapCRC() || tilesetCRC != gameSettings->getTilesetCRC());
//printf("\nmapCRC [%d] gameSettings->getMapCRC() [%d] tilesetCRC [%d] gameSettings->getTilesetCRC() [%d]\n",mapCRC,gameSettings->getMapCRC(),tilesetCRC,gameSettings->getTilesetCRC());
if(dataSynchMismatch == true) {
string labelSynch = "Game data synch mismatch for:";
if(mapCRC != gameSettings->getMapCRC()) {
labelSynch = labelSynch + " map";
if(updateDataSynchDetailText == true &&
lastMapDataSynchError != "map CRC mismatch, " + listBoxMap.getSelectedItem()) {
lastMapDataSynchError = "map CRC mismatch, " + listBoxMap.getSelectedItem();
clientInterface->sendTextMessage(lastMapDataSynchError,-1,true);
}
}
if(tilesetCRC != gameSettings->getTilesetCRC()) {
labelSynch = labelSynch + " tileset";
if(updateDataSynchDetailText == true &&
lastTileDataSynchError != "tileset CRC mismatch, " + listBoxTileset.getSelectedItem()) {
lastTileDataSynchError = "tileset CRC mismatch, " + listBoxTileset.getSelectedItem();
clientInterface->sendTextMessage(lastTileDataSynchError,-1,true);
}
}
/*
if(clientInterface->getNetworkGameDataSynchCheckOkTech() == false) {
labelSynch = labelSynch + " techtree";
if(updateDataSynchDetailText == true) {
string report = clientInterface->getNetworkGameDataSynchCheckTechMismatchReport();
if(lastTechtreeDataSynchError != "techtree CRC mismatch" + report) {
lastTechtreeDataSynchError = "techtree CRC mismatch" + report;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] report: %s\n",__FILE__,__FUNCTION__,__LINE__,report.c_str());
clientInterface->sendTextMessage("techtree CRC mismatch",-1,true);
vector<string> reportLineTokens;
Tokenize(report,reportLineTokens,"\n");
for(int reportLine = 0; reportLine < reportLineTokens.size(); ++reportLine) {
clientInterface->sendTextMessage(reportLineTokens[reportLine],-1,true);
}
}
}
}
*/
//if(clientInterface->getReceivedDataSynchCheck() == true) {
updateDataSynchDetailText = false;
//}
labelDataSynchInfo.setText(labelSynch);
}
else {
labelDataSynchInfo.setText("");
}
}
if(clientInterface->getAllowGameDataSynchCheck() == true &&
clientInterface->getNetworkGameDataSynchCheckOk() == false) {
label = label + " -synch mismatch for:";
@ -984,7 +1074,6 @@ void MenuStateConnectedGame::update() {
//process network messages
if(clientInterface != NULL && clientInterface->isConnected()) {
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
if(chrono.getMillis() > 0) chrono.start();
@ -1233,7 +1322,6 @@ void MenuStateConnectedGame::update() {
//update lobby
clientInterface= NetworkManager::getInstance().getClientInterface();
if(clientInterface != NULL && clientInterface->isConnected()) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] clientInterface = %p\n",__FILE__,__FUNCTION__,__LINE__,clientInterface);
clientInterface->updateLobby();
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
@ -1243,16 +1331,12 @@ void MenuStateConnectedGame::update() {
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
if(chrono.getMillis() > 0) chrono.start();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
clientInterface= NetworkManager::getInstance().getClientInterface();
if(clientInterface != NULL && clientInterface->isConnected()) {
if( initialSettingsReceivedFromServer == true &&
clientInterface->getIntroDone() == true &&
(switchSetupRequestFlagType & ssrft_NetworkPlayerName) == ssrft_NetworkPlayerName) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] getHumanPlayerName() = [%s], clientInterface->getGameSettings()->getThisFactionIndex() = %d\n",__FILE__,__FUNCTION__,__LINE__,getHumanPlayerName().c_str(),clientInterface->getGameSettings()->getThisFactionIndex());
//needToSetChangedGameSettings = false;
//lastSetChangedGameSettings = time(NULL);
clientInterface->sendSwitchSetupRequest("",clientInterface->getPlayerIndex(),-1,-1,getHumanPlayerName(),switchSetupRequestFlagType);
switchSetupRequestFlagType=ssrft_None;

View File

@ -97,6 +97,9 @@ private:
GraphicLabel *activeInputLabel;
time_t timerLabelFlash;
GraphicLabel labelDataSynchInfo;
MapInfo mapInfo;
bool needToSetChangedGameSettings;

View File

@ -2111,16 +2111,19 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
gameSettings->setFactionCount(factionCount);
Config &config = Config::getInstance();
//gameSettings->setEnableServerControlledAI(listBoxEnableServerControlledAI.getSelectedItemIndex() == 0);
gameSettings->setEnableServerControlledAI(config.getBool("ServerControlledAI","true"));
//gameSettings->setNetworkFramePeriod((listBoxNetworkFramePeriod.getSelectedItemIndex()+1)*10);
gameSettings->setNetworkFramePeriod(config.getInt("NetworkSendFrameCount","20"));
gameSettings->setNetworkPauseGameForLaggedClients(((listBoxNetworkPauseGameForLaggedClients.getSelectedItemIndex() != 0)));
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTileset() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTileset().c_str());
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str());
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str());
int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL);
gameSettings->setTilesetCRC(tilesetCRC);
//int32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/*", ".xml", NULL);
Checksum checksum;
string file = Map::getMapPath(gameSettings->getMap(),"",false);
checksum.addFile(file);
int32 mapCRC = checksum.getSum();
gameSettings->setMapCRC(mapCRC);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
}

View File

@ -37,62 +37,48 @@ namespace Glest{ namespace Game{
// class NetworkMessage
// =====================================================
bool NetworkMessage::peek(Socket* socket, void* data, int dataSize)
{
bool NetworkMessage::peek(Socket* socket, void* data, int dataSize) {
if(socket != NULL) {
int ipeekdatalen = socket->getDataToRead();
if(ipeekdatalen >= dataSize)
{
if(socket->peek(data, dataSize)!=dataSize)
{
if(socket != NULL && socket->getSocketId() > 0)
{
if(ipeekdatalen >= dataSize) {
if(socket->peek(data, dataSize)!=dataSize) {
if(socket != NULL && socket->getSocketId() > 0) {
throw runtime_error("Error peeking NetworkMessage");
}
else
{
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__);
}
}
else
{
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize);
}
return true;
}
else
{
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
}
}
return false;
}
bool NetworkMessage::receive(Socket* socket, void* data, int dataSize)
{
bool NetworkMessage::receive(Socket* socket, void* data, int dataSize) {
if(socket != NULL) {
int ipeekdatalen = socket->getDataToRead();
if(ipeekdatalen >= dataSize)
{
if(socket->receive(data, dataSize)!=dataSize)
{
if(socket != NULL && socket->getSocketId() > 0)
{
if(ipeekdatalen >= dataSize) {
if(socket->receive(data, dataSize)!=dataSize) {
if(socket != NULL && socket->getSocketId() > 0) {
throw runtime_error("Error receiving NetworkMessage");
}
else
{
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__);
}
}
else
{
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize);
}
return true;
}
else
{
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
}
}
@ -189,11 +175,11 @@ void NetworkMessagePing::send(Socket* socket) const{
// class NetworkMessageReady
// =====================================================
NetworkMessageReady::NetworkMessageReady(){
NetworkMessageReady::NetworkMessageReady() {
data.messageType= nmtReady;
}
NetworkMessageReady::NetworkMessageReady(int32 checksum){
NetworkMessageReady::NetworkMessageReady(int32 checksum) {
data.messageType= nmtReady;
data.checksum= checksum;
}
@ -202,7 +188,7 @@ bool NetworkMessageReady::receive(Socket* socket){
return NetworkMessage::receive(socket, &data, sizeof(data));
}
void NetworkMessageReady::send(Socket* socket) const{
void NetworkMessageReady::send(Socket* socket) const {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtReady\n",__FILE__,__FUNCTION__,__LINE__);
assert(data.messageType==nmtReady);
NetworkMessage::send(socket, &data, sizeof(data));
@ -212,13 +198,17 @@ void NetworkMessageReady::send(Socket* socket) const{
// class NetworkMessageLaunch
// =====================================================
NetworkMessageLaunch::NetworkMessageLaunch(){
NetworkMessageLaunch::NetworkMessageLaunch() {
data.messageType=-1;
}
NetworkMessageLaunch::NetworkMessageLaunch(const GameSettings *gameSettings,int8 messageType){
NetworkMessageLaunch::NetworkMessageLaunch(const GameSettings *gameSettings,int8 messageType) {
data.messageType=messageType;
data.mapCRC = gameSettings->getMapCRC();
data.tilesetCRC = gameSettings->getTilesetCRC();
data.techCRC = gameSettings->getTechCRC();
data.description= gameSettings->getDescription();
data.map= gameSettings->getMap();
data.tileset= gameSettings->getTileset();
@ -237,7 +227,7 @@ NetworkMessageLaunch::NetworkMessageLaunch(const GameSettings *gameSettings,int8
data.pathFinderType = gameSettings->getPathFinderType();
data.flagTypes1 = gameSettings->getFlagTypes1();
for(int i= 0; i<data.factionCount; ++i){
for(int i= 0; i<data.factionCount; ++i) {
data.factionTypeNames[i]= gameSettings->getFactionTypeName(i);
data.networkPlayerNames[i]= gameSettings->getNetworkPlayerName(i);
data.factionControls[i]= gameSettings->getFactionControl(i);
@ -247,7 +237,7 @@ NetworkMessageLaunch::NetworkMessageLaunch(const GameSettings *gameSettings,int8
}
}
void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const{
void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const {
gameSettings->setDescription(data.description.getString());
gameSettings->setMap(data.map.getString());
gameSettings->setTileset(data.tileset.getString());
@ -267,7 +257,11 @@ void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const{
gameSettings->setPathFinderType(static_cast<PathFinderType>(data.pathFinderType));
gameSettings->setFlagTypes1(data.flagTypes1);
for(int i= 0; i<data.factionCount; ++i){
gameSettings->setMapCRC(data.mapCRC);
gameSettings->setTilesetCRC(data.tilesetCRC);
gameSettings->setTechCRC(data.techCRC);
for(int i= 0; i<data.factionCount; ++i) {
gameSettings->setFactionTypeName(i, data.factionTypeNames[i].getString());
gameSettings->setNetworkPlayerName(i,data.networkPlayerNames[i].getString());
gameSettings->setFactionControl(i, static_cast<ControlType>(data.factionControls[i]));
@ -277,7 +271,7 @@ void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const{
}
}
bool NetworkMessageLaunch::receive(Socket* socket){
bool NetworkMessageLaunch::receive(Socket* socket) {
bool result = NetworkMessage::receive(socket, &data, sizeof(data));
data.description.nullTerminate();
data.map.nullTerminate();

View File

@ -181,7 +181,7 @@ public:
// =====================================================
#pragma pack(push, 1)
class NetworkMessageLaunch: public NetworkMessage{
class NetworkMessageLaunch: public NetworkMessage {
private:
static const int maxStringSize= 256;
static const int maxSmallStringSize= 60;
@ -195,6 +195,9 @@ private:
NetworkString<maxSmallStringSize> tech;
NetworkString<maxSmallStringSize> factionTypeNames[GameConstants::maxPlayers]; //faction names
NetworkString<maxSmallStringSize> networkPlayerNames[GameConstants::maxPlayers]; //networkPlayerNames
int32 mapCRC;
int32 tilesetCRC;
int32 techCRC;
int8 factionControls[GameConstants::maxPlayers];
int8 resourceMultiplierIndex[GameConstants::maxPlayers];
@ -226,6 +229,10 @@ public:
void buildGameSettings(GameSettings *gameSettings) const;
int getMessageType() const { return data.messageType; }
int getMapCRC() const { return data.mapCRC; }
int getTilesetCRC() const { return data.tilesetCRC; }
int getTechCRC() const { return data.techCRC; }
virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const;
};
@ -240,7 +247,7 @@ public:
//const int32 commandListHeaderSize = 6;
#pragma pack(push, 1)
class NetworkMessageCommandList: public NetworkMessage{
class NetworkMessageCommandList: public NetworkMessage {
private:
static const int maxCommandCount = 2496; // can be as large as 65535

View File

@ -3,16 +3,16 @@
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "faction_type.h"
#include "logger.h"
#include "util.h"
#include "util.h"
#include "xml_parser.h"
#include "tech_tree.h"
#include "resource.h"
@ -27,7 +27,7 @@ using namespace Shared::Xml;
namespace Glest{ namespace Game{
// ======================================================
// Class FactionType
// Class FactionType
// ======================================================
FactionType::FactionType(){
@ -36,7 +36,7 @@ FactionType::FactionType(){
}
//load a faction, given a directory
void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum){
void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum,Checksum *techtreeChecksum) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -59,7 +59,7 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
for(int i=0; i<unitTypes.size(); ++i) {
string str= dir + "/units/" + unitFilenames[i];
unitTypes[i].preLoad(str);
SDL_PumpEvents();
}
@ -79,7 +79,7 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
try{
for(int i = 0; i < unitTypes.size(); ++i) {
string str= dir + "/units/" + unitTypes[i].getName();
unitTypes[i].load(i, str, techTree, this, checksum);
unitTypes[i].load(i, str, techTree, this, checksum,techtreeChecksum);
SDL_PumpEvents();
}
@ -93,7 +93,7 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
try{
for(int i = 0; i < upgradeTypes.size(); ++i) {
string str= dir + "/upgrades/" + upgradeTypes[i].getName();
upgradeTypes[i].load(str, techTree, this, checksum);
upgradeTypes[i].load(str, techTree, this, checksum,techtreeChecksum);
SDL_PumpEvents();
}
@ -105,7 +105,8 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
//open xml file
string path= dir+"/"+name+".xml";
checksum->addFile(path);
checksum->addFile(path);
techtreeChecksum->addFile(path);
XmlTree xmlTree;
xmlTree.load(path);
@ -494,9 +495,9 @@ std::vector<std::string> FactionType::validateFactionTypeUpgradeTypes() {
return results;
}
// ==================== get ====================
// ==================== get ====================
const UnitType *FactionType::getUnitType(const string &name) const{
const UnitType *FactionType::getUnitType(const string &name) const{
for(int i=0; i<unitTypes.size();i++){
if(unitTypes[i].getName()==name){
return &unitTypes[i];
@ -511,7 +512,7 @@ const UnitType *FactionType::getUnitType(const string &name) const{
throw runtime_error("Unit not found: "+name);
}
const UpgradeType *FactionType::getUpgradeType(const string &name) const{
const UpgradeType *FactionType::getUpgradeType(const string &name) const{
for(int i=0; i<upgradeTypes.size();i++){
if(upgradeTypes[i].getName()==name){
return &upgradeTypes[i];

View File

@ -3,9 +3,9 @@
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
@ -30,7 +30,7 @@ namespace Glest{ namespace Game{
class FactionType{
private:
typedef pair<const UnitType*, int> PairPUnitTypeInt;
typedef vector<UnitType> UnitTypes;
typedef vector<UnitType> UnitTypes;
typedef vector<UpgradeType> UpgradeTypes;
typedef vector<PairPUnitTypeInt> StartingUnits;
typedef vector<Resource> Resources;
@ -47,7 +47,7 @@ private:
public:
//init
FactionType();
void load(const string &dir, const TechTree *techTree, Checksum* checksum);
void load(const string &dir, const TechTree *techTree, Checksum* checksum,Checksum *techtreeChecksum);
~FactionType();
//get
@ -60,9 +60,9 @@ public:
int getStartingUnitCount() const {return startingUnits.size();}
const UnitType *getStartingUnit(int i) const {return startingUnits[i].first;}
int getStartingUnitAmount(int i) const {return startingUnits[i].second;}
const UnitType *getUnitType(const string &name) const;
const UpgradeType *getUpgradeType(const string &name) const;
const UnitType *getUnitType(const string &name) const;
const UpgradeType *getUpgradeType(const string &name) const;
int getStartingResourceAmount(const ResourceType *resourceType) const;
FactionPersonalityType getPersonalityType() const { return personalityType;}

View File

@ -38,7 +38,7 @@ ResourceType::ResourceType() {
model = NULL;
}
void ResourceType::load(const string &dir, Checksum* checksum){
void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtreeChecksum) {
string path, str;
Renderer &renderer= Renderer::getInstance();
@ -51,7 +51,8 @@ void ResourceType::load(const string &dir, Checksum* checksum){
Logger::getInstance().add("Resource type: "+ formatString(name), true);
path= dir+"/"+name+".xml";
checksum->addFile(path);
checksum->addFile(path);
techtreeChecksum->addFile(path);
//tree
XmlTree xmlTree;

View File

@ -48,7 +48,7 @@ private:
public:
ResourceType();
void load(const string &dir, Checksum* checksum);
void load(const string &dir, Checksum* checksum,Checksum *techtreeChecksum);
//get
int getClass() const {return resourceClass;}

View File

@ -31,17 +31,19 @@ namespace Glest{ namespace Game{
// class TechTree
// =====================================================
void TechTree::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum) {
Checksum TechTree::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum) {
Checksum techtreeChecksum;
for(int idx = 0; idx < pathList.size(); idx++) {
string path = pathList[idx] + "/" + techName;
if(isdir(path.c_str()) == true) {
load(path, factions, checksum);
load(path, factions, checksum, &techtreeChecksum);
break;
}
}
return techtreeChecksum;
}
void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum) {
void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum, Checksum *techtreeChecksum) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string str;
@ -59,7 +61,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
for(int i=0; i<filenames.size(); ++i){
str=dir+"/resources/"+filenames[i];
resourceTypes[i].load(str, checksum);
resourceTypes[i].load(str, checksum, &checksumValue);
SDL_PumpEvents();
}
@ -82,7 +84,8 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
XmlTree xmlTree;
string path= dir+"/"+lastDir(dir)+".xml";
checksum->addFile(path);
checksum->addFile(path);
checksumValue.addFile(path);
xmlTree.load(path);
const XmlNode *techTreeNode= xmlTree.getRootNode();
@ -133,7 +136,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
//SDL_PumpEvents();
//load factions
str= dir+"/factions/*.";
str = dir + "/factions/*.";
try{
factionTypes.resize(factions.size());
@ -147,7 +150,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
logger.setState(szBuf);
str=dir+"/factions/" + factionName;
factionTypes[i++].load(str, this, checksum);
factionTypes[i++].load(str, this, checksum,&checksumValue);
// give CPU time to update other things to avoid apperance of hanging
sleep(0);
@ -157,12 +160,16 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw runtime_error("Error loading Faction Types: "+ dir + "\n" + e.what());
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
if(techtreeChecksum != NULL) {
*techtreeChecksum = checksumValue;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
TechTree::~TechTree(){
TechTree::~TechTree() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("Tech tree", true);
}

View File

@ -42,11 +42,13 @@ private:
ArmorTypes armorTypes;
AttackTypes attackTypes;
DamageMultiplierTable damageMultiplierTable;
Checksum checksumValue;
public:
void loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum);
void load(const string &dir, set<string> &factions, Checksum* checksum);
Checksum loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum);
void load(const string &dir, set<string> &factions, Checksum* checksum,Checksum *techtreeChecksum);
~TechTree();
Checksum * getChecksumValue() { return &checksumValue; }
//get
int getResourceTypeCount() const {return resourceTypes.size();}

View File

@ -101,7 +101,7 @@ void UnitType::preLoad(const string &dir){
name= lastDir(dir);
}
void UnitType::load(int id,const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){
void UnitType::load(int id,const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum,Checksum* techtreeChecksum) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -114,7 +114,8 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
Logger::getInstance().add("Unit type: " + formatString(name), true);
//file load
checksum->addFile(path);
checksum->addFile(path);
techtreeChecksum->addFile(path);
XmlTree xmlTree;
xmlTree.load(path);
@ -146,7 +147,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
if(parametersNode->hasChild("max-unit-count")){
maxUnitCount= parametersNode->getChild("max-unit-count")->getAttribute("value")->getIntValue();
}
//armor
armor= parametersNode->getChild("armor")->getAttribute("value")->getIntValue();
@ -679,7 +680,7 @@ string UnitType::getReqDesc() const{
return ProducibleType::getReqDesc();
else
return ProducibleType::getReqDesc()+"\nLimits: "+resultTxt;
}
}
std::string UnitType::toString() const {
std::string result = "";
@ -690,7 +691,7 @@ std::string UnitType::toString() const {
result += " maxEp = " + intToStr(maxEp);
result += " epRegeneration = " + intToStr(epRegeneration);
result += " maxUnitCount = " + intToStr(getMaxUnitCount());
for(int i = 0; i < fieldCount; i++) {
result += " fields index = " + intToStr(i) + " value = " + intToStr(fields[i]);

View File

@ -89,8 +89,8 @@ private:
int maxEp;
int epRegeneration;
int maxUnitCount;
///@todo remove fields, multiple fields are not supported by the engine
bool fields[fieldCount]; //fields: land, sea or air
Field field;
@ -134,7 +134,7 @@ public:
UnitType();
virtual ~UnitType();
void preLoad(const string &dir);
void load(int id, const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum);
void load(int id, const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum, Checksum* techtreeChecksum);
//get
int getId() const {return id;}
@ -205,7 +205,7 @@ public:
//other
virtual string getReqDesc() const;
std::string toString() const;
private:

View File

@ -3,9 +3,9 @@
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
@ -14,7 +14,7 @@
#include <algorithm>
#include <cassert>
#include "unit_type.h"
#include "unit_type.h"
#include "util.h"
#include "logger.h"
#include "lang.h"
@ -35,29 +35,30 @@ namespace Glest{ namespace Game{
// class UpgradeType
// =====================================================
// ==================== get ====================
// ==================== get ====================
bool UpgradeType::isAffected(const UnitType *unitType) const{
return find(effects.begin(), effects.end(), unitType)!=effects.end();
}
// ==================== misc ====================
// ==================== misc ====================
void UpgradeType::preLoad(const string &dir){
name=lastDir(dir);
}
void UpgradeType::load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){
void UpgradeType::load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum, Checksum* techtreeChecksum) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string path;
Logger::getInstance().add("Upgrade type: "+ formatString(name), true);
path=dir+"/"+name+".xml";
path = dir + "/" + name + ".xml";
try{
checksum->addFile(path);
checksum->addFile(path);
techtreeChecksum->addFile(path);
XmlTree xmlTree;
xmlTree.load(path);
@ -76,7 +77,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
//upgrade time
const XmlNode *upgradeTimeNode= upgradeNode->getChild("time");
productionTime= upgradeTimeNode->getAttribute("value")->getIntValue();
//unit requirements
const XmlNode *unitRequirementsNode= upgradeNode->getChild("unit-requirements");
for(int i=0; i<unitRequirementsNode->getChildCount(); ++i){
@ -120,7 +121,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue();
moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue();
prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue();
}
catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
@ -131,7 +132,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
}
string UpgradeType::getReqDesc() const{
string str;
int i;
Lang &lang= Lang::getInstance();
@ -141,9 +142,9 @@ string UpgradeType::getReqDesc() const{
str+= "\n"+ lang.get("Upgrades")+":\n";
for(i=0; i<getEffectCount(); ++i){
str+= getEffect(i)->getName()+"\n";
}
}
}
if(maxHp!=0){
str+= lang.get("Hp")+" +"+intToStr(maxHp);
}
@ -157,7 +158,7 @@ string UpgradeType::getReqDesc() const{
str+= lang.get("AttackStrenght")+" +"+intToStr(attackStrength)+"\n";
}
if(attackRange!=0){
str+= lang.get("AttackDistance")+" +"+intToStr(attackRange)+"\n";
str+= lang.get("AttackDistance")+" +"+intToStr(attackRange)+"\n";
}
if(armor!=0){
str+= lang.get("Armor")+" +"+intToStr(armor)+"\n";
@ -175,7 +176,7 @@ string UpgradeType::getReqDesc() const{
// ===============================
// class TotalUpgrade
// class TotalUpgrade
// ===============================
TotalUpgrade::TotalUpgrade(){

View File

@ -3,9 +3,9 @@
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
@ -27,7 +27,7 @@ class FactionType;
class UnitType;
// ===============================
// class UpgradeTypeBase
// class UpgradeTypeBase
// ===============================
class UpgradeTypeBase{
@ -39,7 +39,7 @@ protected:
int attackStrength;
int attackRange;
int moveSpeed;
int prodSpeed;
int prodSpeed;
public:
int getMaxHp() const {return maxHp;}
@ -68,28 +68,28 @@ public:
};
// ===============================
// class UpgradeType
// class UpgradeType
// ===============================
class UpgradeType: public UpgradeTypeBase, public ProducibleType{
private:
vector<const UnitType*> effects;
vector<const UnitType*> effects;
public:
void preLoad(const string &dir);
void load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum);
void load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum, Checksum* techtreeChecksum);
//get all
int getEffectCount() const {return effects.size();}
const UnitType * getEffect(int i) const {return effects[i];}
bool isAffected(const UnitType *unitType) const;
bool isAffected(const UnitType *unitType) const;
//other methods
virtual string getReqDesc() const;
};
// ===============================
// class TotalUpgrade
// class TotalUpgrade
// ===============================
class TotalUpgrade: public UpgradeTypeBase{
@ -97,7 +97,7 @@ public:
TotalUpgrade();
void reset();
void sum(const UpgradeType *ut);
void sum(const UpgradeType *ut);
void incLevel(const UnitType *ut);
};

View File

@ -155,7 +155,9 @@ Vec2i Map::getStartLocation(int locationIndex) const {
return startLocations[locationIndex];
}
void Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
Checksum mapChecksum;
struct MapFileHeader{
int32 version;
int32 maxPlayers;
@ -169,9 +171,10 @@ void Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
};
try{
FILE *f= fopen(path.c_str(), "rb");
if(f!=NULL){
FILE *f = fopen(path.c_str(), "rb");
if(f != NULL) {
mapChecksum.addFile(path);
checksumValue.addFile(path);
//read header
MapFileHeader header;
size_t readBytes = fread(&header, sizeof(MapFileHeader), 1, f);
@ -196,22 +199,21 @@ void Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
//start locations
startLocations= new Vec2i[maxPlayers];
for(int i=0; i<maxPlayers; ++i) {
int x, y;
for(int i=0; i < maxPlayers; ++i) {
int x=0, y=0;
readBytes = fread(&x, sizeof(int32), 1, f);
readBytes = fread(&y, sizeof(int32), 1, f);
startLocations[i]= Vec2i(x, y)*cellScale;
}
//cells
cells= new Cell[getCellArraySize()];
surfaceCells= new SurfaceCell[getSurfaceCellArraySize()];
//read heightmap
for(int j=0; j<surfaceH; ++j){
for(int i=0; i<surfaceW; ++i){
float32 alt;
for(int j = 0; j < surfaceH; ++j) {
for(int i = 0; i < surfaceW; ++i) {
float32 alt=0;
readBytes = fread(&alt, sizeof(float32), 1, f);
SurfaceCell *sc= getSurfaceCell(i, j);
sc->setVertex(Vec3f(i*mapScale, alt / heightFactor, j*mapScale));
@ -219,30 +221,30 @@ void Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
}
//read surfaces
for(int j=0; j<surfaceH; ++j){
for(int i=0; i<surfaceW; ++i){
int8 surf;
for(int j = 0; j < surfaceH; ++j) {
for(int i = 0; i < surfaceW; ++i) {
int8 surf=0;
readBytes = fread(&surf, sizeof(int8), 1, f);
getSurfaceCell(i, j)->setSurfaceType(surf-1);
}
}
//read objects and resources
for(int j=0; j<h; j+= cellScale){
for(int i=0; i<w; i+= cellScale){
for(int j = 0; j < h; j += cellScale) {
for(int i = 0; i < w; i += cellScale) {
int8 objNumber;
int8 objNumber=0;
readBytes = fread(&objNumber, sizeof(int8), 1, f);
SurfaceCell *sc= getSurfaceCell(toSurfCoords(Vec2i(i, j)));
if(objNumber==0){
if(objNumber == 0) {
sc->setObject(NULL);
}
else if(objNumber <= Tileset::objCount){
else if(objNumber <= Tileset::objCount) {
Object *o= new Object(tileset->getObjectType(objNumber-1), sc->getVertex(),Vec2i(i, j));
sc->setObject(o);
for(int k=0; k<techTree->getResourceTypeCount(); ++k){
for(int k = 0; k < techTree->getResourceTypeCount(); ++k) {
const ResourceType *rt= techTree->getResourceType(k);
if(rt->getClass()==rcTileset && rt->getTilesetObject()==objNumber){
if(rt->getClass() == rcTileset && rt->getTilesetObject() == objNumber){
o->setResource(rt, Vec2i(i, j));
}
}
@ -265,6 +267,8 @@ void Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw runtime_error("Error loading map: "+ path+ "\n"+ e.what());
}
return mapChecksum;
}
void Map::init() {

View File

@ -45,7 +45,7 @@ class GameSettings;
/// A map cell that holds info about units present on it
// =====================================================
class Cell{
class Cell {
private:
Unit *units[fieldCount]; //units on this cell
Unit *unitsWithEmptyCellMap[fieldCount]; //units with an empty cellmap on this cell
@ -76,7 +76,7 @@ public:
// A heightmap cell, each surface cell is composed by more than one Cell
// =====================================================
class SurfaceCell{
class SurfaceCell {
private:
//geometry
Vec3f vertex;
@ -147,7 +147,7 @@ public:
/// Represents the game map (and loads it from a gbm file)
// =====================================================
class Map{
class Map {
public:
static const int cellScale; //number of cells per surfaceCell
static const int mapScale; //horizontal scale of surface
@ -163,7 +163,8 @@ private:
int maxPlayers;
Cell *cells;
SurfaceCell *surfaceCells;
Vec2i *startLocations;
Vec2i *startLocations;
Checksum checksumValue;
private:
Map(Map&);
@ -171,10 +172,11 @@ private:
public:
Map();
~Map();
~Map();
Checksum * getChecksumValue() { return &checksumValue; }
void init();
void load(const string &path, TechTree *techTree, Tileset *tileset);
Checksum load(const string &path, TechTree *techTree, Tileset *tileset);
//get
Cell *getCell(int x, int y) const;

View File

@ -30,14 +30,18 @@ namespace Glest{ namespace Game{
// class Scenario
// =====================================================
Scenario::~Scenario(){
Scenario::~Scenario() {
}
void Scenario::load(const string &path){
try{
Checksum Scenario::load(const string &path) {
Checksum scenarioChecksum;
try {
scenarioChecksum.addFile(path);
checksumValue.addFile(path);
string name= cutLastExt(lastDir(path));
Logger::getInstance().add("Scenario: "+formatString(name), true);
Logger::getInstance().add("Scenario: " + formatString(name), true);
//parse xml
XmlTree xmlTree;
@ -52,10 +56,12 @@ void Scenario::load(const string &path){
}
}
//Exception handling (conversions and so on);
catch(const exception &e){
catch(const exception &e) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw runtime_error("Error: " + path + "\n" + e.what());
}
}
return scenarioChecksum;
}
int Scenario::getScenarioPathIndex(const vector<string> dirList, const string &scenarioName) {
@ -85,7 +91,7 @@ string Scenario::getScenarioPath(const vector<string> dirList, const string &sce
scenarioFile = "";
}
}
return scenarioFile;
}

View File

@ -14,22 +14,24 @@
#include <string>
#include <vector>
#include "xml_parser.h"
#include "xml_parser.h"
#include "checksum.h"
#include "leak_dumper.h"
using std::string;
using std::vector;
using std::pair;
using Shared::Xml::XmlNode;
using Shared::Xml::XmlNode;
using namespace Shared::Util;
namespace Glest{ namespace Game{
namespace Glest { namespace Game {
// =====================================================
// class Script
// =====================================================
class Script{
class Script {
private:
string name;
string code;
@ -45,16 +47,18 @@ public:
// class Scenario
// =====================================================
class Scenario{
class Scenario {
private:
typedef pair<string, string> NameScriptPair;
typedef vector<Script> Scripts;
Scripts scripts;
Scripts scripts;
Checksum checksumValue;
public:
~Scenario();
void load(const string &path);
Checksum load(const string &path);
Checksum * getChecksumValue() { return &checksumValue; }
int getScriptCount() const {return scripts.size();}
const Script* getScript(int i) const {return &scripts[i];}

View File

@ -90,18 +90,20 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
// class Tileset
// =====================================================
void Tileset::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) {
Checksum Tileset::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) {
Checksum tilesetChecksum;
for(int idx = 0; idx < pathList.size(); idx++) {
const string path = pathList[idx] + "/" + tilesetName;
if(isdir(path.c_str()) == true) {
load(path, checksum);
load(path, checksum, &tilesetChecksum);
break;
}
}
}
return tilesetChecksum;
}
void Tileset::load(const string &dir, Checksum *checksum){
void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
random.init(time(NULL));
@ -109,9 +111,11 @@ void Tileset::load(const string &dir, Checksum *checksum){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string name= lastDir(dir);
string path= dir+"/"+name+".xml";
string path= dir + "/" + name + ".xml";
checksum->addFile(path);
checksum->addFile(path);
tilesetChecksum->addFile(path);
checksumValue.addFile(path);
try {
Logger::getInstance().add("Tileset: "+formatString(name), true);
@ -262,7 +266,7 @@ void Tileset::load(const string &dir, Checksum *checksum){
}
}
Tileset::~Tileset(){
Tileset::~Tileset() {
Logger::getInstance().add("Tileset", true);
}

View File

@ -126,12 +126,14 @@ private:
Vec3f moonLightColor;
Weather weather;
AmbientSounds ambientSounds;
AmbientSounds ambientSounds;
Checksum checksumValue;
public:
~Tileset();
void loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum);
void load(const string &dir, Checksum *checksum);
Checksum loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum);
void load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum);
Checksum * getChecksumValue() { return &checksumValue; }
//get
const SurfaceAtlas *getSurfaceAtlas() const {return &surfaceAtlas;}

View File

@ -181,39 +181,40 @@ void World::init(Game *game, bool createUnits){
}
//load tileset
void World::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) {
Checksum World::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) {
Checksum tilsetChecksum;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
tileset.loadTileset(pathList, tilesetName, checksum);
tilsetChecksum = tileset.loadTileset(pathList, tilesetName, checksum);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
timeFlow.init(&tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return tilsetChecksum;
}
void World::loadTileset(const string &dir, Checksum *checksum){
Checksum World::loadTileset(const string &dir, Checksum *checksum) {
Checksum tilesetChecksum;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
tileset.load(dir, checksum);
tileset.load(dir, checksum, &tilesetChecksum);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
timeFlow.init(&tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return tilesetChecksum;
}
//load tech
void World::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum *checksum){
Checksum World::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum *checksum) {
Checksum techtreeChecksum;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
/*
std::map<string,TechTree *> &techCache = Shared::PlatformCommon::CacheManager::getCachedItem< std::map<string,TechTree *> >("techCache");
if(techCache.find(techName) != techCache.end()) {
techTree = new TechTree();
*techTree = *techCache[techName];
return;
}
*/
techTree = new TechTree();
techTree->loadTech(pathList, techName, factions, checksum);
//techCache[techName] = techTree;
techtreeChecksum = techTree->loadTech(pathList, techName, factions, checksum);
return techtreeChecksum;
}
std::vector<std::string> World::validateFactionTypes() {
@ -225,20 +226,25 @@ std::vector<std::string> World::validateResourceTypes() {
}
//load map
void World::loadMap(const string &path, Checksum *checksum){
Checksum World::loadMap(const string &path, Checksum *checksum) {
Checksum mapChecksum;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
checksum->addFile(path);
map.load(path, techTree, &tileset);
mapChecksum = map.load(path, techTree, &tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return mapChecksum;
}
//load map
void World::loadScenario(const string &path, Checksum *checksum){
Checksum World::loadScenario(const string &path, Checksum *checksum) {
Checksum scenarioChecksum;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
checksum->addFile(path);
scenario.load(path);
scenarioChecksum = scenario.load(path);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return scenarioChecksum;
}
// ==================== misc ====================

View File

@ -168,11 +168,11 @@ public:
//init & load
void init(Game *game, bool createUnits);
void loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum);
void loadTileset(const string &dir, Checksum* checksum);
void loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum);
void loadMap(const string &path, Checksum* checksum);
void loadScenario(const string &path, Checksum* checksum);
Checksum loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum);
Checksum loadTileset(const string &dir, Checksum* checksum);
Checksum loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum);
Checksum loadMap(const string &path, Checksum* checksum);
Checksum loadScenario(const string &path, Checksum* checksum);
//misc
void update();

View File

@ -42,7 +42,7 @@ void ftpInit(ftpFindExternalFTPServerIpType cb1, ftpAddUPNPPortForwardType cb2,
int ftpCreateAccount(const char* name, const char* passw, const char* root, int accRights);
int ftpStart(int portNumber);
int ftpShutdown(void);
void ftpExecute(void);
int ftpExecute(void);
int ftpState(void);
#ifdef __cplusplus

View File

@ -137,21 +137,22 @@ int ftpState(void)
* all received control-strings are dispatched to the command-module.
* Note, the function blocks if there is nothing to do.
*/
void ftpExecute(void)
{
int n;
int socksRdy;
ftpSession_S *pSession;
int sessionId;
int activeJobs;
int ftpExecute(void)
{
int processedWork=0;
int n=0;
int socksRdy=0;
ftpSession_S *pSession=NULL;
int sessionId=0;
int activeJobs=0;
activeJobs = ftpGetActiveTransCnt(); // are there any active transmitions?
for(n = 0; (activeJobs > 0) && (n < MAX_CONNECTIONS); n++)
{
pSession = ftpGetSession(n);
if(pSession->activeTrans.op) // has this session an active transmition?
{
{
processedWork = 1;
ftpExecTransmission(n); // do the job
activeJobs--;
}
@ -162,7 +163,8 @@ void ftpExecute(void)
//else
// socksRdy = ftpSelect(FALSE);
if(socksRdy > 0)
{
{
processedWork = 1;
if(ftpTestSocket(server)) // server listner-socket signaled?
{
socket_t clientSocket;
@ -222,7 +224,9 @@ if(VERBOSE_MODE_ENABLED) printf("Connection refused; Session limit reached.\n");
}
}
}
}
}
return processedWork;
}

View File

@ -128,8 +128,10 @@ void FTPServerThread::execute() {
*/
ftpStart(portNumber);
while(this->getQuitStatus() == false) {
ftpExecute();
//sleep(25);
int processedWork = ftpExecute();
if(processedWork == 0) {
sleep(25);
}
}
ftpShutdown();

View File

@ -1016,6 +1016,8 @@ int Socket::getDataToRead(bool wantImmediateReply) {
int Socket::send(const void *data, int dataSize) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
const int MAX_SEND_WAIT_SECONDS = 3;
int bytesSent= 0;
if(isSocketValid() == true) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1048,12 +1050,11 @@ int Socket::send(const void *data, int dataSize) {
int attemptCount = 0;
time_t tStartTimer = time(NULL);
while((bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
(difftime(time(NULL),tStartTimer) <= 5)) {
(difftime(time(NULL),tStartTimer) <= MAX_SEND_WAIT_SECONDS)) {
attemptCount++;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount);
{
//if(Socket::isWritable(true) == true) {
if(isConnected() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d, sock = %d, dataSize = %d, data = %p\n",__FILE__,__FUNCTION__,__LINE__,attemptCount,sock,dataSize,data);
MutexSafeWrapper safeMutex(&dataSynchAccessor);
@ -1063,7 +1064,15 @@ int Socket::send(const void *data, int dataSize) {
bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL);
#endif
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesSent);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
}
else {
int iErr = getLastSocketError();
disconnectSocket();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] DISCONNECTED SOCKET error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,bytesSent,getLastSocketErrorFormattedText(&iErr).c_str());
break;
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount);
}
@ -1077,12 +1086,11 @@ int Socket::send(const void *data, int dataSize) {
time_t tStartTimer = time(NULL);
while(((bytesSent > 0 && totalBytesSent < dataSize) ||
(bytesSent < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN)) &&
(difftime(time(NULL),tStartTimer) <= 5)) {
(difftime(time(NULL),tStartTimer) <= MAX_SEND_WAIT_SECONDS)) {
attemptCount++;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d, totalBytesSent = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount,totalBytesSent);
{
//if(bytesSent > 0 || Socket::isWritable(true) == true) {
if(isConnected() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d, sock = %d, dataSize = %d, data = %p\n",__FILE__,__FUNCTION__,__LINE__,attemptCount,sock,dataSize,data);
MutexSafeWrapper safeMutex(&dataSynchAccessor);
@ -1097,6 +1105,14 @@ int Socket::send(const void *data, int dataSize) {
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] retry send returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
}
else {
int iErr = getLastSocketError();
disconnectSocket();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesSent,getLastSocketErrorFormattedText(&iErr).c_str());
break;
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] attemptCount = %d\n",__FILE__,__FUNCTION__,__LINE__,attemptCount);
}
@ -1115,17 +1131,18 @@ int Socket::send(const void *data, int dataSize) {
int iErr = getLastSocketError();
disconnectSocket();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] DISCONNECTED SOCKET error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,bytesSent,getLastSocketErrorFormattedText(&iErr).c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesSent,getLastSocketErrorFormattedText(&iErr).c_str());
//throwException(szBuf);
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] sock = %d, bytesSent = %d\n",__FILE__,__FUNCTION__,sock,bytesSent);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sock = %d, bytesSent = %d\n",__FILE__,__FUNCTION__,__LINE__,sock,bytesSent);
return static_cast<int>(bytesSent);
}
int Socket::receive(void *data, int dataSize)
{
int Socket::receive(void *data, int dataSize) {
const int MAX_RECV_WAIT_SECONDS = 3;
ssize_t bytesReceived = 0;
if(isSocketValid() == true) {
@ -1141,12 +1158,19 @@ int Socket::receive(void *data, int dataSize)
time_t tStartTimer = time(NULL);
while((bytesReceived < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
(difftime(time(NULL),tStartTimer) <= 5)) {
if(Socket::isReadable() == true) {
(difftime(time(NULL),tStartTimer) <= MAX_RECV_WAIT_SECONDS)) {
if(isConnected() == false) {
int iErr = getLastSocketError();
disconnectSocket();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while receiving socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,getLastSocketErrorFormattedText(&iErr).c_str());
break;
}
else if(Socket::isReadable() == true) {
MutexSafeWrapper safeMutex(&dataSynchAccessor);
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 EAGAIN during receive, trying again returned: %d\n",__FILE__,__FUNCTION__,bytesReceived);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during receive, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived);
}
}
}
@ -1155,20 +1179,22 @@ int Socket::receive(void *data, int dataSize)
int iErr = getLastSocketError();
disconnectSocket();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] DISCONNECTED SOCKET error while receiving socket data, bytesReceived = %d, error = %s\n",__FILE__,__FUNCTION__,bytesReceived,getLastSocketErrorFormattedText(&iErr).c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while receiving socket data, bytesReceived = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,getLastSocketErrorFormattedText(&iErr).c_str());
//throwException(szBuf);
}
return static_cast<int>(bytesReceived);
}
int Socket::peek(void *data, int dataSize){
int Socket::peek(void *data, int dataSize) {
const int MAX_PEEK_WAIT_SECONDS = 3;
ssize_t err = 0;
if(isSocketValid() == true) {
MutexSafeWrapper safeMutex(&dataSynchAccessor);
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
}
if(err < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR PEEKING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR PEEKING SOCKET DATA error while sending socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str());
//throwException(szBuf);
disconnectSocket();
@ -1178,8 +1204,15 @@ int Socket::peek(void *data, int dataSize){
time_t tStartTimer = time(NULL);
while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
(difftime(time(NULL),tStartTimer) <= 5)) {
if(Socket::isReadable() == true) {
(difftime(time(NULL),tStartTimer) <= MAX_PEEK_WAIT_SECONDS)) {
if(isConnected() == false) {
int iErr = getLastSocketError();
disconnectSocket();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText(&iErr).c_str());
break;
}
else if(Socket::isReadable() == true) {
MutexSafeWrapper safeMutex(&dataSynchAccessor);
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
@ -1239,12 +1272,12 @@ bool Socket::isReadable() {
i= select((int)sock + 1, &set, NULL, NULL, &tv);
}
if(i < 0) {
if(difftime(time(NULL),lastDebugEvent) >= 1) {
lastDebugEvent = time(NULL);
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
// lastDebugEvent = time(NULL);
//throwException("Error selecting socket");
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,i,getLastSocketErrorFormattedText().c_str());
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,i,getLastSocketErrorFormattedText().c_str());
//}
}
bool result = (i == 1);
return result;
@ -1262,7 +1295,7 @@ bool Socket::isWritable(bool waitOnDelayedResponse) {
FD_SET(sock, &set);
time_t maxElapsedCheck = time(NULL);
const int MAX_CHECK_WAIT_SECONDS = 5;
const int MAX_CHECK_WAIT_SECONDS = 2;
bool result = false;
do {
@ -1278,9 +1311,9 @@ bool Socket::isWritable(bool waitOnDelayedResponse) {
}
if(i < 0 ) {
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
lastDebugEvent = time(NULL);
// lastDebugEvent = time(NULL);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str());
//}
waitOnDelayedResponse = false;
@ -1288,8 +1321,8 @@ bool Socket::isWritable(bool waitOnDelayedResponse) {
}
else if(i == 0) {
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
lastDebugEvent = time(NULL);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] TIMEOUT while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str());
// lastDebugEvent = time(NULL);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] TIMEOUT while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str());
//}
if(waitOnDelayedResponse == false) {
@ -1301,6 +1334,8 @@ bool Socket::isWritable(bool waitOnDelayedResponse) {
result = true;
break;
}
if(isSocketValid() == false) return false;
} while(waitOnDelayedResponse == true && result == false);
//return (i == 1 && FD_ISSET(sock, &set));
@ -1837,10 +1872,9 @@ Socket *ServerSocket::accept() {
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
safeMutex.ReleaseLock();
if(isSocketValid(&newSock) == false)
{
if(isSocketValid(&newSock) == false) {
char szBuf[1024]="";
sprintf(szBuf, "In [%s::%s] Error accepting socket connection sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,newSock,getLastSocketErrorFormattedText().c_str());
sprintf(szBuf, "In [%s::%s Line: %d] Error accepting socket connection sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,sock,newSock,getLastSocketErrorFormattedText().c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
if(getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN)