From 973b546b04be6a38bf74d6201202b03519531bed Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 30 Dec 2010 20:02:30 +0000 Subject: [PATCH] - more bugfixes related to ftp and firewall handling --- source/glest_game/network/server_interface.cpp | 6 ++++++ .../include/platform/posix/miniftpserver.h | 1 + .../sources/platform/posix/miniftpserver.cpp | 4 ++++ source/shared_lib/sources/platform/posix/socket.cpp | 13 ++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 90a20b520..0be06cca8 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -1141,6 +1141,12 @@ bool ServerInterface::launchGame(const GameSettings* gameSettings) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver); } + + if(ftpServer != NULL) { + ftpServer->shutdownAndWait(); + delete ftpServer; + ftpServer = NULL; + } } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/include/platform/posix/miniftpserver.h b/source/shared_lib/include/platform/posix/miniftpserver.h index 582ae4f69..1da0d0287 100644 --- a/source/shared_lib/include/platform/posix/miniftpserver.h +++ b/source/shared_lib/include/platform/posix/miniftpserver.h @@ -38,6 +38,7 @@ protected: public: FTPServerThread(std::pair mapsPath, int portNumber); + ~FTPServerThread(); virtual void execute(); virtual void signalQuit(); virtual bool shutdownAndWait(); diff --git a/source/shared_lib/sources/platform/posix/miniftpserver.cpp b/source/shared_lib/sources/platform/posix/miniftpserver.cpp index ee5ce85e7..68776acfc 100644 --- a/source/shared_lib/sources/platform/posix/miniftpserver.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpserver.cpp @@ -48,6 +48,10 @@ FTPServerThread::FTPServerThread(std::pair mapsPath,int portNumbe ftpFindExternalFTPServerIp = &FindExternalFTPServerIp; } +FTPServerThread::~FTPServerThread() { + ServerSocket::upnp_rem_redirect(ServerSocket::getFTPServerPort()); +} + void FTPServerThread::signalQuit() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server: signalQuit\n"); BaseThread::signalQuit(); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 2a46c243d..b9da65d72 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1427,11 +1427,13 @@ void ClientSocket::connect(const Ip &ip, int port) addr.sin_port= htons(port); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connecting to host [%s] on port = %d\n", ip.getString().c_str(),port); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("Connecting to host [%s] on port = %d\n", ip.getString().c_str(),port); connectedIpAddress = ""; int err= ::connect(sock, reinterpret_cast(&addr), sizeof(addr)); if(err < 0) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 Error connecting socket for IP: %s for Port: %d err = %d error = %s\n",__FILE__,__FUNCTION__,ip.getString().c_str(),port,err,getLastSocketErrorFormattedText().c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] #2 Error connecting socket for IP: %s for Port: %d err = %d error = %s\n",__FILE__,__FUNCTION__,ip.getString().c_str(),port,err,getLastSocketErrorFormattedText().c_str()); if (getLastSocketError() == PLATFORM_SOCKET_INPROGRESS || getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) { @@ -1441,6 +1443,7 @@ void ClientSocket::connect(const Ip &ip, int port) socklen_t lon; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] PLATFORM_SOCKET_INPROGRESS in connect() - selecting\n",__FILE__,__FUNCTION__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] PLATFORM_SOCKET_INPROGRESS in connect() - selecting\n",__FILE__,__FUNCTION__); do { tv.tv_sec = 10; @@ -1456,6 +1459,8 @@ void ClientSocket::connect(const Ip &ip, int port) if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Error connecting %s\n",__FILE__,__FUNCTION__,getLastSocketErrorFormattedText().c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Error connecting %s\n",__FILE__,__FUNCTION__,getLastSocketErrorFormattedText().c_str()); + //throwException(szBuf); break; } @@ -1469,23 +1474,27 @@ void ClientSocket::connect(const Ip &ip, int port) #endif { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Error in getsockopt() %s\n",__FILE__,__FUNCTION__,getLastSocketErrorFormattedText().c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Error in getsockopt() %s\n",__FILE__,__FUNCTION__,getLastSocketErrorFormattedText().c_str()); //throwException(szBuf); break; } // Check the value returned... if(valopt) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Error in delayed connection() %d - [%s]\n",__FILE__,__FUNCTION__,valopt, strerror(valopt)); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Error in delayed connection() %d - [%s]\n",__FILE__,__FUNCTION__,valopt, strerror(valopt)); //throwException(szBuf); break; } errno = 0; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Apparent recovery for connection sock = %d, err = %d\n",__FILE__,__FUNCTION__,sock,err); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Apparent recovery for connection sock = %d, err = %d\n",__FILE__,__FUNCTION__,sock,err); break; } else { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Timeout in select() - Cancelling!\n",__FILE__,__FUNCTION__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Timeout in select() - Cancelling!\n",__FILE__,__FUNCTION__); //throwException(szBuf); disconnectSocket(); @@ -1496,16 +1505,19 @@ void ClientSocket::connect(const Ip &ip, int port) if(err < 0) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Before END sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Before END sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str()); //throwException(szBuf); disconnectSocket(); } else { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Valid recovery for connection sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Valid recovery for connection sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str()); connectedIpAddress = ip.getString(); } } else { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Connected to host [%s] on port = %d sock = %d err = %d", ip.getString().c_str(),port,sock,err); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Connected to host [%s] on port = %d sock = %d err = %d", ip.getString().c_str(),port,sock,err); connectedIpAddress = ip.getString(); } } @@ -1673,7 +1685,6 @@ ServerSocket::~ServerSocket() { ServerSocket::enabledUPNP = false; NETremRedirects(ServerSocket::externalPort); - NETremRedirects(ServerSocket::ftpServerPort); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);