mirror of
https://github.com/glest/glest-source.git
synced 2025-08-21 15:41:24 +02:00
- added option to disable file transfers for tileset and/or techtrees for published (internet) games
This commit is contained in:
@@ -40,6 +40,7 @@ extern "C" {
|
||||
|
||||
void ftpInit(ftpFindExternalFTPServerIpType cb1, ftpAddUPNPPortForwardType cb2, ftpRemoveUPNPPortForwardType cb3, ftpIsValidClientType cb4);
|
||||
int ftpCreateAccount(const char* name, const char* passw, const char* root, int accRights);
|
||||
int ftpDeleteAccount(const char* name);
|
||||
int ftpStart(int portNumber);
|
||||
int ftpShutdown(void);
|
||||
int ftpExecute(void);
|
||||
|
@@ -39,16 +39,23 @@ protected:
|
||||
int maxPlayers;
|
||||
static FTPClientValidationInterface *ftpValidationIntf;
|
||||
|
||||
bool internetEnabled;
|
||||
bool allowInternetTilesetFileTransfers;
|
||||
bool allowInternetTechtreeFileTransfers;
|
||||
|
||||
public:
|
||||
|
||||
FTPServerThread(std::pair<string,string> mapsPath,
|
||||
std::pair<string,string> tilesetsPath, std::pair<string,string> techtreesPath,
|
||||
bool internetEnabledFlag,
|
||||
bool allowInternetTilesetFileTransfers, bool allowInternetTechtreeFileTransfers,
|
||||
int portNumber,int maxPlayers, FTPClientValidationInterface *ftpValidationIntf);
|
||||
~FTPServerThread();
|
||||
virtual void execute();
|
||||
virtual void signalQuit();
|
||||
virtual bool shutdownAndWait();
|
||||
|
||||
void setInternetEnabled(bool value, bool forceChange=false);
|
||||
static void addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp);
|
||||
static FTPClientValidationInterface * getFtpValidationIntf() { return ftpValidationIntf; }
|
||||
|
||||
|
@@ -48,6 +48,21 @@ typedef struct
|
||||
*/
|
||||
LOCAL ftpUserAccount_S ftpUsers[MAX_USERS];
|
||||
|
||||
|
||||
int ftpDeleteAccount(const char* name)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = ftpFindAccount(name); // check if account already exists
|
||||
if(n > 0)
|
||||
{
|
||||
ftpUsers[n - 1].name[0] = '\0'; // delete account
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates a new user account
|
||||
*
|
||||
|
@@ -48,11 +48,16 @@ int isValidClientType(ip_t clientIp) {
|
||||
|
||||
FTPServerThread::FTPServerThread(std::pair<string,string> mapsPath,
|
||||
std::pair<string,string> tilesetsPath, std::pair<string,string> techtreesPath,
|
||||
bool internetEnabledFlag,
|
||||
bool allowInternetTilesetFileTransfers, bool allowInternetTechtreeFileTransfers,
|
||||
int portNumber, int maxPlayers,
|
||||
FTPClientValidationInterface *ftpValidationIntf) : BaseThread() {
|
||||
this->mapsPath = mapsPath;
|
||||
this->tilesetsPath = tilesetsPath;
|
||||
this->techtreesPath = techtreesPath;
|
||||
setInternetEnabled(internetEnabledFlag,true);
|
||||
this->allowInternetTilesetFileTransfers = allowInternetTilesetFileTransfers;
|
||||
this->allowInternetTechtreeFileTransfers = allowInternetTechtreeFileTransfers;
|
||||
this->portNumber = portNumber;
|
||||
this->maxPlayers = maxPlayers;
|
||||
this->ftpValidationIntf = ftpValidationIntf;
|
||||
@@ -94,6 +99,79 @@ void FTPServerThread::addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Server thread clientIp = %u, ServerIp = %u\n",clientIp,ServerIp);
|
||||
}
|
||||
|
||||
void FTPServerThread::setInternetEnabled(bool value, bool forceChange) {
|
||||
if(forceChange == true || this->internetEnabled != value) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, changing InternetEnabled = %d\n",value);
|
||||
|
||||
this->internetEnabled = value;
|
||||
if(this->internetEnabled == true) {
|
||||
// Setup FTP Users and permissions for tilesets
|
||||
if(this->allowInternetTilesetFileTransfers == true) {
|
||||
if(tilesetsPath.first != "") {
|
||||
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);
|
||||
}
|
||||
if(tilesetsPath.second != "") {
|
||||
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);
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, tilesets users created\n");
|
||||
}
|
||||
else {
|
||||
ftpDeleteAccount("tilesets");
|
||||
ftpDeleteAccount("tilesets_custom");
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, tilesets users deleted\n");
|
||||
}
|
||||
|
||||
if(this->allowInternetTechtreeFileTransfers == true) {
|
||||
// Setup FTP Users and permissions for tilesets
|
||||
if(techtreesPath.first != "") {
|
||||
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);
|
||||
}
|
||||
if(techtreesPath.second != "") {
|
||||
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);
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, techtrees users created\n");
|
||||
}
|
||||
else {
|
||||
ftpDeleteAccount("techtrees");
|
||||
ftpDeleteAccount("techtrees_custom");
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, techtrees users deleted\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(tilesetsPath.first != "") {
|
||||
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);
|
||||
}
|
||||
if(tilesetsPath.second != "") {
|
||||
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);
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, tilesets users created\n");
|
||||
|
||||
// Setup FTP Users and permissions for tilesets
|
||||
if(techtreesPath.first != "") {
|
||||
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);
|
||||
}
|
||||
if(techtreesPath.second != "") {
|
||||
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);
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server thread, techtrees users created\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FTPServerThread::execute() {
|
||||
{
|
||||
RunningStatusSafeWrapper runningStatus(this);
|
||||
@@ -119,26 +197,6 @@ void FTPServerThread::execute() {
|
||||
ftpCreateAccount("maps_custom", "mg_ftp_server", mapsPath.second.c_str(), FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
|
||||
}
|
||||
|
||||
// Setup FTP Users and permissions for tilesets
|
||||
if(tilesetsPath.first != "") {
|
||||
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);
|
||||
}
|
||||
if(tilesetsPath.second != "") {
|
||||
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);
|
||||
}
|
||||
|
||||
// Setup FTP Users and permissions for tilesets
|
||||
if(techtreesPath.first != "") {
|
||||
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);
|
||||
}
|
||||
if(techtreesPath.second != "") {
|
||||
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("anonymous", "", "./", FTP_ACC_RD | FTP_ACC_LS | FTP_ACC_DIR);
|
||||
ftpCreateAccount("nothing", "", "./", 0);
|
||||
|
Reference in New Issue
Block a user