- added the first draft of joining games in progress

This commit is contained in:
Mark Vejvoda
2013-02-15 18:25:10 +00:00
parent fb6cff0ed1
commit 9d19ff2b57
26 changed files with 1027 additions and 117 deletions

View File

@@ -25,14 +25,16 @@ using namespace Shared::PlatformCommon;
namespace Shared { namespace PlatformCommon {
const char *FTP_MAPS_CUSTOM_USERNAME = "maps_custom";
const char *FTP_MAPS_USERNAME = "maps";
const char *FTP_TILESETS_CUSTOM_USERNAME = "tilesets_custom";
const char *FTP_TILESETS_USERNAME = "tilesets";
const char *FTP_TECHTREES_CUSTOM_USERNAME = "techtrees_custom";
const char *FTP_TECHTREES_USERNAME = "techtrees";
static const char *FTP_MAPS_CUSTOM_USERNAME = "maps_custom";
static const char *FTP_MAPS_USERNAME = "maps";
static const char *FTP_TILESETS_CUSTOM_USERNAME = "tilesets_custom";
static const char *FTP_TILESETS_USERNAME = "tilesets";
static const char *FTP_TECHTREES_CUSTOM_USERNAME = "techtrees_custom";
static const char *FTP_TECHTREES_USERNAME = "techtrees";
const char *FTP_COMMON_PASSWORD = "mg_ftp_server";
static const char *FTP_TEMPFILES_USERNAME = "temp";
static const char *FTP_COMMON_PASSWORD = "mg_ftp_server";
/*
* This is an example showing how to get a single file from an FTP server.
@@ -237,7 +239,8 @@ FTPClientThread::FTPClientThread(int portNumber, string serverUrl,
string fileArchiveExtension,
string fileArchiveExtractCommand,
string fileArchiveExtractCommandParameters,
int fileArchiveExtractCommandSuccessResult) : BaseThread() {
int fileArchiveExtractCommandSuccessResult,
string tempFilesPath) : BaseThread() {
this->portNumber = portNumber;
this->serverUrl = serverUrl;
this->mapsPath = mapsPath;
@@ -251,6 +254,7 @@ FTPClientThread::FTPClientThread(int portNumber, string serverUrl,
this->fileArchiveExtractCommand = fileArchiveExtractCommand;
this->fileArchiveExtractCommandParameters = fileArchiveExtractCommandParameters;
this->fileArchiveExtractCommandSuccessResult = fileArchiveExtractCommandSuccessResult;
this->tempFilesPath = tempFilesPath;
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d] Using FTP port #: %d, serverUrl [%s]\n",__FILE__,__FUNCTION__,__LINE__,portNumber,serverUrl.c_str());
}
@@ -449,6 +453,16 @@ void FTPClientThread::addFileToRequests(string fileName,string URL) {
}
}
void FTPClientThread::addTempFileToRequests(string fileName,string URL) {
std::pair<string,string> item = make_pair(fileName,URL);
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexTempFileList,mutexOwnerId);
mutexTempFileList.setOwnerId(mutexOwnerId);
if(std::find(tempFileList.begin(),tempFileList.end(),item) == tempFileList.end()) {
tempFileList.push_back(item);
}
}
void FTPClientThread::getTilesetFromServer(pair<string,string> tileSetName) {
bool findArchive = executeShellCommand(
this->fileArchiveExtractCommand,
@@ -840,6 +854,58 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getFileInternalFromServer(p
return result;
}
void FTPClientThread::getTempFileFromServer(pair<string,string> fileName) {
pair<FTP_Client_ResultType,string> result = make_pair(ftp_crt_FAIL,"");
bool findArchive = true;
string ext = extractExtension(fileName.first);
if(("." + ext) == this->fileArchiveExtension) {
findArchive = executeShellCommand(
this->fileArchiveExtractCommand,
this->fileArchiveExtractCommandSuccessResult);
}
if(findArchive == true) {
result = getTempFileInternalFromServer(fileName);
}
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
this->getProgressMutex()->setOwnerId(mutexOwnerId);
if(this->pCBObject != NULL) {
this->pCBObject->FTPClient_CallbackEvent(fileName.first,ftp_cct_TempFile,result,NULL);
}
}
pair<FTP_Client_ResultType,string> FTPClientThread::getTempFileInternalFromServer(pair<string,string> fileName) {
string destFile = fileName.first;
string destFileSaveAs = fileName.first;
string remotePath = fileName.second;
pair<FTP_Client_ResultType,string> result = getFileFromServer(ftp_cct_TempFile,
fileName,remotePath, destFileSaveAs, FTP_TEMPFILES_USERNAME, FTP_COMMON_PASSWORD);
// Extract the archive
if(result.first == ftp_crt_SUCCESS) {
string ext = extractExtension(destFileSaveAs);
if(("." + ext) == fileArchiveExtension) {
string destRootArchiveFolder = extractDirectoryPathFromFile(destFileSaveAs);
string extractCmd = getFullFileArchiveExtractCommand(
this->fileArchiveExtractCommand,
this->fileArchiveExtractCommandParameters,
destRootArchiveFolder,
destFileSaveAs);
if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) {
result.first = ftp_crt_FAIL;
result.second = "failed to extract archive!";
}
}
}
return result;
}
pair<FTP_Client_ResultType,string> FTPClientThread::getFileFromServer(FTP_Client_CallbackType downloadType,
pair<string,string> fileNameTitle,
string remotePath, string destFileSaveAs,
@@ -1104,6 +1170,20 @@ void FTPClientThread::execute() {
safeMutex5.ReleaseLock();
}
static string mutexOwnerId6 = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex6(&mutexTempFileList,mutexOwnerId6);
mutexTempFileList.setOwnerId(mutexOwnerId6);
if(tempFileList.size() > 0) {
pair<string,string> file = tempFileList[0];
tempFileList.erase(tempFileList.begin() + 0);
safeMutex6.ReleaseLock();
getTempFileFromServer(file);
}
else {
safeMutex5.ReleaseLock();
}
if(this->getQuitStatus() == false) {
sleep(25);
}

View File

@@ -26,6 +26,17 @@ using namespace Shared::PlatformCommon;
namespace Shared { namespace PlatformCommon {
static const char *FTP_MAPS_CUSTOM_USERNAME = "maps_custom";
static const char *FTP_MAPS_USERNAME = "maps";
static const char *FTP_TILESETS_CUSTOM_USERNAME = "tilesets_custom";
static const char *FTP_TILESETS_USERNAME = "tilesets";
static const char *FTP_TECHTREES_CUSTOM_USERNAME = "techtrees_custom";
static const char *FTP_TECHTREES_USERNAME = "techtrees";
static const char *FTP_TEMPFILES_USERNAME = "temp";
static const char *FTP_COMMON_PASSWORD = "mg_ftp_server";
static std::map<uint32,uint32> clientToFTPServerList;
FTPClientValidationInterface * FTPServerThread::ftpValidationIntf = NULL;
@@ -62,7 +73,7 @@ FTPServerThread::FTPServerThread(std::pair<string,string> mapsPath,
bool internetEnabledFlag,
bool allowInternetTilesetFileTransfers, bool allowInternetTechtreeFileTransfers,
int portNumber, int maxPlayers,
FTPClientValidationInterface *ftpValidationIntf) : BaseThread() {
FTPClientValidationInterface *ftpValidationIntf, string tempFilesPath) : BaseThread() {
this->mapsPath = mapsPath;
this->tilesetsPath = tilesetsPath;
this->techtreesPath = techtreesPath;
@@ -72,6 +83,7 @@ FTPServerThread::FTPServerThread(std::pair<string,string> mapsPath,
this->portNumber = portNumber;
this->maxPlayers = maxPlayers;
this->ftpValidationIntf = ftpValidationIntf;
this->tempFilesPath = tempFilesPath;
ftpInit(&FindExternalFTPServerIp,&UPNP_Tools::AddUPNPPortForward,&UPNP_Tools::RemoveUPNPPortForward,
&isValidClientType, &isClientAllowedToGetFile);
@@ -131,18 +143,18 @@ void FTPServerThread::setInternetEnabled(bool value, bool forceChange) {
if(this->allowInternetTilesetFileTransfers == true) {
if(tilesetsPath.first != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tilesetsPath #1 [%s]\n",__FILE__,__FUNCTION__,__LINE__,tilesetsPath.first.c_str());
ftpCreateAccount("tilesets", "mg_ftp_server", tilesetsPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_TILESETS_USERNAME, FTP_COMMON_PASSWORD, tilesetsPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(tilesetsPath.second != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tilesetsPath #2 [%s]\n",__FILE__,__FUNCTION__,__LINE__,tilesetsPath.second.c_str());
ftpCreateAccount("tilesets_custom", "mg_ftp_server", tilesetsPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_TILESETS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD, tilesetsPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, tilesets users created\n");
}
else {
ftpDeleteAccount("tilesets");
ftpDeleteAccount("tilesets_custom");
ftpDeleteAccount(FTP_TILESETS_USERNAME);
ftpDeleteAccount(FTP_TILESETS_CUSTOM_USERNAME);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, tilesets users deleted\n");
}
@@ -151,18 +163,18 @@ void FTPServerThread::setInternetEnabled(bool value, bool forceChange) {
// Setup FTP Users and permissions for tilesets
if(techtreesPath.first != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] techtreesPath #1 [%s]\n",__FILE__,__FUNCTION__,__LINE__,techtreesPath.first.c_str());
ftpCreateAccount("techtrees", "mg_ftp_server", techtreesPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_TECHTREES_USERNAME, FTP_COMMON_PASSWORD, techtreesPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(techtreesPath.second != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] techtreesPath #2 [%s]\n",__FILE__,__FUNCTION__,__LINE__,techtreesPath.second.c_str());
ftpCreateAccount("techtrees_custom", "mg_ftp_server", techtreesPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_TECHTREES_CUSTOM_USERNAME, FTP_COMMON_PASSWORD, techtreesPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, techtrees users created\n");
}
else {
ftpDeleteAccount("techtrees");
ftpDeleteAccount("techtrees_custom");
ftpDeleteAccount(FTP_TECHTREES_USERNAME);
ftpDeleteAccount(FTP_TECHTREES_CUSTOM_USERNAME);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, techtrees users deleted\n");
}
@@ -170,11 +182,11 @@ void FTPServerThread::setInternetEnabled(bool value, bool forceChange) {
else {
if(tilesetsPath.first != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tilesetsPath #1 [%s]\n",__FILE__,__FUNCTION__,__LINE__,tilesetsPath.first.c_str());
ftpCreateAccount("tilesets", "mg_ftp_server", tilesetsPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_TILESETS_USERNAME, FTP_COMMON_PASSWORD, tilesetsPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(tilesetsPath.second != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tilesetsPath #2 [%s]\n",__FILE__,__FUNCTION__,__LINE__,tilesetsPath.second.c_str());
ftpCreateAccount("tilesets_custom", "mg_ftp_server", tilesetsPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_TILESETS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD, tilesetsPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, tilesets users created\n");
@@ -182,11 +194,11 @@ void FTPServerThread::setInternetEnabled(bool value, bool forceChange) {
// Setup FTP Users and permissions for tilesets
if(techtreesPath.first != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] techtreesPath #1 [%s]\n",__FILE__,__FUNCTION__,__LINE__,techtreesPath.first.c_str());
ftpCreateAccount("techtrees", "mg_ftp_server", techtreesPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_TECHTREES_USERNAME, FTP_COMMON_PASSWORD, techtreesPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(techtreesPath.second != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] techtreesPath #2 [%s]\n",__FILE__,__FUNCTION__,__LINE__,techtreesPath.second.c_str());
ftpCreateAccount("techtrees_custom", "mg_ftp_server", techtreesPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_TECHTREES_CUSTOM_USERNAME, FTP_COMMON_PASSWORD, techtreesPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, techtrees users created\n");
@@ -212,11 +224,16 @@ void FTPServerThread::execute() {
// Setup FTP Users and permissions for maps
if(mapsPath.first != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] mapsPath #1 [%s]\n",__FILE__,__FUNCTION__,__LINE__,mapsPath.first.c_str());
ftpCreateAccount("maps", "mg_ftp_server", mapsPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_MAPS_USERNAME, FTP_COMMON_PASSWORD, mapsPath.first.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(mapsPath.second != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] mapsPath #2 [%s]\n",__FILE__,__FUNCTION__,__LINE__,mapsPath.second.c_str());
ftpCreateAccount("maps_custom", "mg_ftp_server", mapsPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
ftpCreateAccount(FTP_MAPS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD, mapsPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
if(tempFilesPath != "") {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tempFilesPath [%s]\n",__FILE__,__FUNCTION__,__LINE__,tempFilesPath.c_str());
ftpCreateAccount(FTP_TEMPFILES_USERNAME, FTP_COMMON_PASSWORD, tempFilesPath.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
}
/*

View File

@@ -948,6 +948,8 @@ Socket::~Socket() {
}
void Socket::disconnectSocket() {
//printf("Socket disconnecting\n");
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
if(isSocketValid() == true) {