diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index a6a201d0..d18708a5 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -170,11 +170,14 @@ static void cleanupProcessObjects() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 IRCCLient Cache SHUTDOWN\n"); IRCThread * &ircClient = CacheManager::getCachedItem< IRCThread * >(GameConstants::ircClientCacheLookupKey); + //printf("In main IRCThreadcheck [%p]...\n",ircClient); if(ircClient != NULL) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 IRCCLient Cache SHUTDOWN\n"); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); ircClient->setCallbackObj(NULL); + + //printf("In main IRCThreadcheck [%p] signalled quit...\n",ircClient); ircClient->signalQuit(); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); ircClient = NULL; diff --git a/source/shared_lib/CMakeLists.txt b/source/shared_lib/CMakeLists.txt index 8764dfd9..df3a0fad 100644 --- a/source/shared_lib/CMakeLists.txt +++ b/source/shared_lib/CMakeLists.txt @@ -347,48 +347,55 @@ option(ENABLE_FRIBIDI "Enable FriBIDi support" ON) INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}platform/sdl ) INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}xml/rapidxml ) - IF(NOT WANT_STATIC_LIBS) - MESSAGE(STATUS "*** Searching for libircclient since WANT_STATIC_LIBS is off ...") - FIND_PACKAGE(Ircclient) - ENDIF() + option(DISABLE_IRCCLIENT "Disable libircclient support" OFF) - if(NOT IRCCLIENT_FOUND) - MESSAGE(STATUS "*** Using EMBEDDED libircclient since this system does not have it... IRCCLIENT_FOUND [${IRCCLIENT_FOUND}]") + IF(NOT DISABLE_IRCCLIENT) + IF(NOT WANT_STATIC_LIBS) + MESSAGE(STATUS "*** Searching for libircclient since WANT_STATIC_LIBS is off ...") + FIND_PACKAGE(Ircclient) + ENDIF() - SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/libircclient/src/libircclient.c) - INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/libircclient/include) - else() - MESSAGE(STATUS "*** Using SHARED libircclient found in [${IRCCLIENT_INCLUDE_DIR}] IRCCLIENT_FOUND [${IRCCLIENT_FOUND}] IRCCLIENT_LIBRARY [${IRCCLIENT_LIBRARY}]") + if(NOT IRCCLIENT_FOUND) + MESSAGE(STATUS "*** Using EMBEDDED libircclient since this system does not have it... IRCCLIENT_FOUND [${IRCCLIENT_FOUND}]") - INCLUDE_DIRECTORIES(${IRCCLIENT_INCLUDE_DIR}) - SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${IRCCLIENT_LIBRARY}) - endif() + SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/libircclient/src/libircclient.c) + INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/libircclient/include) + else() + MESSAGE(STATUS "*** Using SHARED libircclient found in [${IRCCLIENT_INCLUDE_DIR}] IRCCLIENT_FOUND [${IRCCLIENT_FOUND}] IRCCLIENT_LIBRARY [${IRCCLIENT_LIBRARY}]") - set(CMAKE_REQUIRED_INCLUDES "${IRCCLIENT_INCLUDE_DIR}") - set(CMAKE_REQUIRED_LIBRARIES "${IRCCLIENT_LIBRARY}") - include(CheckCXXSourceRuns) + INCLUDE_DIRECTORIES(${IRCCLIENT_INCLUDE_DIR}) + SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${IRCCLIENT_LIBRARY}) + endif() - check_cxx_source_runs(" - #include - #include - #include - int main() - { - unsigned int high = 0; - unsigned int low = 0; - irc_get_version(&high,&low); - if( (high == 1 && low >= 6) || (high > 1)) { - return 0; - } - throw 1; - }" - HAS_LIBIRCCLIENT_1_6) + set(CMAKE_REQUIRED_INCLUDES "${IRCCLIENT_INCLUDE_DIR}") + set(CMAKE_REQUIRED_LIBRARIES "${IRCCLIENT_LIBRARY}") + include(CheckCXXSourceRuns) - IF(HAS_LIBIRCCLIENT_1_6) - message(STATUS "Found HAS_LIBIRCCLIENT_1_6: ${HAS_LIBIRCCLIENT_1_6}") - ELSE() - ADD_DEFINITIONS(-DLIBIRCCLIENT_PRE1_6) - ENDIF() + check_cxx_source_runs(" + #include + #include + #include + int main() + { + unsigned int high = 0; + unsigned int low = 0; + irc_get_version(&high,&low); + if( (high == 1 && low >= 6) || (high > 1)) { + return 0; + } + throw 1; + }" + HAS_LIBIRCCLIENT_1_6) + + IF(HAS_LIBIRCCLIENT_1_6) + message(STATUS "Found HAS_LIBIRCCLIENT_1_6: ${HAS_LIBIRCCLIENT_1_6}") + ELSE() + ADD_DEFINITIONS(-DLIBIRCCLIENT_PRE1_6) + ENDIF() + else() + message(STATUS "****WARNING DISABLING libircclient!!") + ADD_DEFINITIONS(-DDISABLE_IRCCLIENT) + endif() IF(WIN32) SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/posix/socket.cpp) diff --git a/source/shared_lib/include/platform/posix/ircclient.h b/source/shared_lib/include/platform/posix/ircclient.h index cbbfff1e..aae0aaab 100644 --- a/source/shared_lib/include/platform/posix/ircclient.h +++ b/source/shared_lib/include/platform/posix/ircclient.h @@ -81,6 +81,7 @@ protected: public: IRCThread(const std::vector &argv,IRCCallbackInterface *callbackObj); + virtual ~IRCThread(); virtual void execute(); virtual void signalQuit(); virtual bool shutdownAndWait(); diff --git a/source/shared_lib/sources/platform/posix/ircclient.cpp b/source/shared_lib/sources/platform/posix/ircclient.cpp index 5e298fe3..51bf1bd4 100644 --- a/source/shared_lib/sources/platform/posix/ircclient.cpp +++ b/source/shared_lib/sources/platform/posix/ircclient.cpp @@ -13,13 +13,17 @@ #include "ircclient.h" #include "util.h" #include "platform_common.h" -#include +#if !defined(DISABLE_IRCCLIENT) + +#include // upstream moved some defines into new headers as of 1.6 #ifndef LIBIRCCLIENT_PRE1_6 #include #endif +#endif + #include #include #include @@ -35,6 +39,7 @@ const int IRC_SERVER_PORT = 6667; //bool IRCThread::debugEnabled = true; bool IRCThread::debugEnabled = false; +#if !defined(DISABLE_IRCCLIENT) void addlog (const char * fmt, ...) { //FILE * fp; char buf[8096]; @@ -452,6 +457,8 @@ void event_numeric(irc_session_t * session, unsigned int event, const char * ori dump_event (session, buf, origin, params, count); } +#endif + IRCThread::IRCThread(const std::vector &argv, IRCCallbackInterface *callbackObj) : BaseThread() { this->argv = argv; this->callbackObj = callbackObj; @@ -467,13 +474,19 @@ IRCThread::IRCThread(const std::vector &argv, IRCCallbackInterface *call void IRCThread::signalQuit() { if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: signalQuit [%p]\n",ircSession); +#if !defined(DISABLE_IRCCLIENT) if(ircSession != NULL) { setCallbackObj(NULL); if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: Quitting Channel\n"); + irc_cmd_quit(ircSession, "MG Bot is closing!"); + BaseThread::signalQuit(); hasJoinedChannel = false; } +#else + BaseThread::signalQuit(); +#endif } bool IRCThread::shutdownAndWait() { @@ -486,8 +499,12 @@ bool IRCThread::shutdownAndWait() { void IRCThread::SendIRCCmdMessage(string target, string msg) { if(ircSession != NULL && hasJoinedChannel == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC command to [%s] cmd [%s]\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),msg.c_str()); + +#if !defined(DISABLE_IRCCLIENT) int ret = irc_cmd_msg (ircSession, target.c_str(), msg.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC command to [%s] cmd [%s] ret = %d\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),msg.c_str(),ret); +#endif } } @@ -495,7 +512,10 @@ std::vector IRCThread::GetIRCConnectedNickList(string target, bool waitF eventDataDone = false; if(ircSession != NULL && hasJoinedChannel == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC nick list command to [%s]\n",__FILE__,__FUNCTION__,__LINE__,target.c_str()); + +#if !defined(DISABLE_IRCCLIENT) int ret = irc_cmd_names (ircSession, target.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC nick list command to [%s] ret = %d\n",__FILE__,__FUNCTION__,__LINE__,target.c_str(),ret); if(waitForCompletion == true) { @@ -506,6 +526,7 @@ std::vector IRCThread::GetIRCConnectedNickList(string target, bool waitF sleep(50); } } +#endif } MutexSafeWrapper safeMutex(&mutexNickList,string(__FILE__) + "_" + intToStr(__LINE__)); @@ -518,7 +539,10 @@ std::vector IRCThread::GetIRCConnectedNickList(string target, bool waitF bool IRCThread::isConnected() { bool ret = false; if(ircSession != NULL) { + +#if !defined(DISABLE_IRCCLIENT) ret = (irc_is_connected(ircSession) != 0); +#endif } return ret; @@ -556,6 +580,7 @@ void IRCThread::execute() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"IRC thread is running\n"); try { +#if !defined(DISABLE_IRCCLIENT) irc_callbacks_t callbacks; ircSession=NULL; @@ -638,7 +663,11 @@ void IRCThread::execute() { if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not run the session: %s\n", irc_strerror (irc_errno(ircSession))); } } - +#else + for(;this->getQuitStatus() == false;) { + sleep(50); + } +#endif if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC exiting IRC CLient!\n"); } catch(const exception &ex) { @@ -662,9 +691,14 @@ void IRCThread::execute() { } safeMutex.ReleaseLock(); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In IRCThread() calling delete ...\n"); delete this; } +IRCThread::~IRCThread() { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In ~IRCThread() ...\n"); +} + void normalizeNick(char *nick) { // http://tools.ietf.org/html/rfc1459#section-2.3.1 // ::= [ "," ] @@ -718,17 +752,21 @@ void IRCThread::connectToHost() { connectRequired = true; } else { +#if !defined(DISABLE_IRCCLIENT) int result = irc_is_connected(ircSession); if(result != 1) { connectRequired = true; } +#endif } if(connectRequired == false) { +#if !defined(DISABLE_IRCCLIENT) if(irc_connect(ircSession, argv[0].c_str(), IRC_SERVER_PORT, 0, this->nick.c_str(), this->username.c_str(), "megaglest")) { if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not connect: %s\n", irc_strerror (irc_errno(ircSession))); return; } +#endif } } @@ -736,6 +774,7 @@ void IRCThread::joinChannel() { wantToLeaveChannel = false; connectToHost(); if(ircSession != NULL) { +#if !defined(DISABLE_IRCCLIENT) IRCThread *ctx = (IRCThread *)irc_get_ctx(ircSession); if(ctx != NULL) { eventData.clear(); @@ -745,16 +784,19 @@ void IRCThread::joinChannel() { irc_cmd_join(ircSession, ctx->getChannel().c_str(), 0); } +#endif } } void IRCThread::leaveChannel() { wantToLeaveChannel = true; if(ircSession != NULL) { +#if !defined(DISABLE_IRCCLIENT) IRCThread *ctx = (IRCThread *)irc_get_ctx(ircSession); if(ctx != NULL) { irc_cmd_part(ircSession,ctx->getChannel().c_str()); } +#endif } }