- added option to disable file transfers for tileset and/or techtrees for published (internet) games

This commit is contained in:
Mark Vejvoda 2011-03-11 12:14:24 +00:00
parent e070cf2cbb
commit 9eb1f60048
11 changed files with 180 additions and 30 deletions

View File

@ -87,7 +87,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
serverInitError = false;
try {
networkManager.init(nrServer);
networkManager.init(nrServer,openNetworkSlots);
}
catch(const std::exception &ex) {
serverInitError = true;
@ -95,7 +95,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!!
//throw runtime_error(szBuf);
showGeneralError=true;
generalErrorToShow = ex.what();
@ -314,10 +314,12 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
listBoxPublishServer.init(50, networkPos, 100);
listBoxPublishServer.pushBackItem(lang.get("Yes"));
listBoxPublishServer.pushBackItem(lang.get("No"));
if(openNetworkSlots)
if(openNetworkSlots) {
listBoxPublishServer.setSelectedItemIndex(0);
else
}
else {
listBoxPublishServer.setSelectedItemIndex(1);
}
// Network Frame Period
//labelNetworkFramePeriod.registerGraphicComponent(containerName,"labelNetworkFramePeriod");
@ -792,6 +794,9 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
needToRepublishToMasterserver = true;
soundRenderer.playFx(coreData.getClickSoundC());
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setPublishEnabled(listBoxPublishServer.getSelectedItemIndex() == 0);
}
else if(listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxNetworkPauseGameForLaggedClients.mouseClick(x, y)){
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@ -1445,6 +1450,9 @@ void MenuStateCustomGame::update() {
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
listBoxPublishServer.setSelectedItemIndex(1);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setPublishEnabled(listBoxPublishServer.getSelectedItemIndex() == 0);
}
else if(showGeneralError) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1734,6 +1742,9 @@ void MenuStateCustomGame::update() {
{
listBoxPublishServer.setSelectedItemIndex(1);
listBoxPublishServer.setEditable(false);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setPublishEnabled(listBoxPublishServer.getSelectedItemIndex() == 0);
//listBoxEnableServerControlledAI.setEditable(false);
}

View File

@ -376,6 +376,28 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
labelFTPServerDataPorts.init(currentColumnStart,currentLine );
labelFTPServerDataPorts.setText(szBuf);
currentLine-=30;
labelEnableFTPServerInternetTilesetXfer.registerGraphicComponent(containerName,"labelEnableFTPServerInternetTilesetXfer");
labelEnableFTPServerInternetTilesetXfer.init(currentLabelStart ,currentLine );
labelEnableFTPServerInternetTilesetXfer.setText(lang.get("EnableFTPServerInternetTilesetXfer"));
checkBoxEnableFTPServerInternetTilesetXfer.registerGraphicComponent(containerName,"checkBoxEnableFTPServerInternetTilesetXfer");
checkBoxEnableFTPServerInternetTilesetXfer.init(currentColumnStart ,currentLine );
checkBoxEnableFTPServerInternetTilesetXfer.setValue(config.getBool("EnableFTPServerInternetTilesetXfer","true"));
currentLine-=30;
labelEnableFTPServerInternetTechtreeXfer.registerGraphicComponent(containerName,"labelEnableFTPServerInternetTechtreeXfer");
labelEnableFTPServerInternetTechtreeXfer.init(currentLabelStart ,currentLine );
labelEnableFTPServerInternetTechtreeXfer.setText(lang.get("EnableFTPServerInternetTechtreeXfer"));
checkBoxEnableFTPServerInternetTechtreeXfer.registerGraphicComponent(containerName,"checkBoxEnableFTPServerInternetTechtreeXfer");
checkBoxEnableFTPServerInternetTechtreeXfer.init(currentColumnStart ,currentLine );
checkBoxEnableFTPServerInternetTechtreeXfer.setValue(config.getBool("EnableFTPServerInternetTechtreeXfer","true"));
currentLine-=30;
// FTP config end
// Privacy flag
@ -546,6 +568,9 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
checkBoxEnableFTP.mouseClick(x, y);
checkBoxEnableFTPServer.mouseClick(x, y);
checkBoxEnableFTPServerInternetTilesetXfer.mouseClick(x, y);
checkBoxEnableFTPServerInternetTechtreeXfer.mouseClick(x, y);
checkBoxEnablePrivacy.mouseClick(x, y);
}
}
@ -580,6 +605,9 @@ void MenuStateOptions::mouseMove(int x, int y, const MouseState *ms){
checkBoxEnableFTP.mouseMove(x, y);
checkBoxEnableFTPServer.mouseMove(x, y);
checkBoxEnableFTPServerInternetTilesetXfer.mouseMove(x, y);
checkBoxEnableFTPServerInternetTechtreeXfer.mouseMove(x, y);
checkBoxEnablePrivacy.mouseMove(x, y);
}
@ -692,6 +720,11 @@ void MenuStateOptions::render(){
renderer.renderLabel(&labelFTPServerDataPortsLabel);
renderer.renderLabel(&labelFTPServerDataPorts);
renderer.renderLabel(&labelEnableFTPServerInternetTilesetXfer);
renderer.renderCheckBox(&checkBoxEnableFTPServerInternetTilesetXfer);
renderer.renderLabel(&labelEnableFTPServerInternetTechtreeXfer);
renderer.renderCheckBox(&checkBoxEnableFTPServerInternetTechtreeXfer);
renderer.renderLabel(&labelEnablePrivacy);
renderer.renderCheckBox(&checkBoxEnablePrivacy);
}
@ -732,6 +765,10 @@ void MenuStateOptions::saveConfig(){
config.setInt("FTPServerPort",config.getInt("MasterServerExternalPort")+1);
config.setBool("EnableFTPXfer", checkBoxEnableFTP.getValue());
config.setBool("EnableFTPServer", checkBoxEnableFTPServer.getValue());
config.setBool("EnableFTPServerInternetTilesetXfer", checkBoxEnableFTPServerInternetTilesetXfer.getValue());
config.setBool("EnableFTPServerInternetTechtreeXfer", checkBoxEnableFTPServerInternetTechtreeXfer.getValue());
config.setBool("PrivacyPlease", checkBoxEnablePrivacy.getValue());
string currentResolution=config.getString("ScreenWidth")+"x"+config.getString("ScreenHeight");

View File

@ -96,6 +96,12 @@ private:
GraphicLabel labelFTPServerDataPortsLabel;
GraphicLabel labelFTPServerDataPorts;
GraphicLabel labelEnableFTPServerInternetTilesetXfer;
GraphicCheckBox checkBoxEnableFTPServerInternetTilesetXfer;
GraphicLabel labelEnableFTPServerInternetTechtreeXfer;
GraphicCheckBox checkBoxEnableFTPServerInternetTechtreeXfer;
GraphicLabel labelEnablePrivacy;
GraphicCheckBox checkBoxEnablePrivacy;

View File

@ -35,7 +35,7 @@ NetworkManager::NetworkManager() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] this->networkRole = %d gameNetworkInterface [%p]\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole,gameNetworkInterface);
}
void NetworkManager::init(NetworkRole networkRole) {
void NetworkManager::init(NetworkRole networkRole, bool publishEnabled) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] this->networkRole = %d, networkRole = %d, gameNetworkInterface [%p]\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole,networkRole,gameNetworkInterface);
assert(gameNetworkInterface==NULL);
@ -44,7 +44,7 @@ void NetworkManager::init(NetworkRole networkRole) {
if(networkRole == nrServer) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] this->networkRole = %d, networkRole = %d, gameNetworkInterface [%p]\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole,networkRole,gameNetworkInterface);
gameNetworkInterface = new ServerInterface();
gameNetworkInterface = new ServerInterface(publishEnabled);
}
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] this->networkRole = %d, networkRole = %d, gameNetworkInterface [%p]\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole,networkRole,gameNetworkInterface);

View File

@ -37,7 +37,7 @@ public:
static NetworkManager &getInstance();
NetworkManager();
void init(NetworkRole networkRole);
void init(NetworkRole networkRole,bool publishEnabled=false);
void end();
void update();

View File

@ -41,7 +41,7 @@ double MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE = 2;
const int MAX_SLOT_THREAD_WAIT_TIME = 3;
const int MASTERSERVER_HEARTBEAT_GAME_STATUS_SECONDS = 30;
ServerInterface::ServerInterface() :GameNetworkInterface() {
ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
nextEventId = 1;
@ -105,13 +105,25 @@ ServerInterface::ServerInterface() :GameNetworkInterface() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
int portNumber = Config::getInstance().getInt("FTPServerPort",intToStr(ServerSocket::getFTPServerPort()).c_str());
ServerSocket::setFTPServerPort(portNumber);
bool allowInternetTilesetFileTransfers = Config::getInstance().getBool("EnableFTPServerInternetTilesetXfer","true");
bool allowInternetTechtreeFileTransfers = Config::getInstance().getBool("EnableFTPServerInternetTechtreeXfer","true");
ftpServer = new FTPServerThread(mapsPath,tilesetsPath,techtreesPath,
portNumber,GameConstants::maxPlayers,this);
publishEnabled,
allowInternetTilesetFileTransfers, allowInternetTechtreeFileTransfers,
portNumber,GameConstants::maxPlayers,this);
ftpServer->start();
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void ServerInterface::setPublishEnabled(bool value) {
if(ftpServer != NULL) {
ftpServer->setInternetEnabled(value);
}
}
ServerInterface::~ServerInterface() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
exitServer = true;

View File

@ -74,7 +74,7 @@ private:
bool inBroadcastMessage;
public:
ServerInterface();
ServerInterface(bool publishEnabled);
virtual ~ServerInterface();
virtual Socket* getSocket() {return &serverSocket;}
@ -157,6 +157,8 @@ public:
needToRepublishToMasterserver = value;
}
void setPublishEnabled(bool value);
public:
Mutex *getServerSynchAccessor() {
return &serverSynchAccessor;
@ -165,6 +167,7 @@ public:
virtual void simpleTask(BaseThread *callingThread);
void addClientToServerIPAddress(uint32 clientIp, uint32 ServerIp);
virtual int isValidClientType(uint32 clientIp);
private:
void broadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1, int lockedSlotIndex = -1);
void broadcastMessageToConnectedClients(const NetworkMessage *networkMessage, int excludeSlot = -1);

View File

@ -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);

View File

@ -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; }

View File

@ -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
*

View File

@ -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);