- added support to disable libircclient via cmake:

-DDISABLE_IRCCLIENT=On
This commit is contained in:
Mark Vejvoda 2013-01-08 06:59:53 +00:00
parent 7e2b161a20
commit 6872a873b2
4 changed files with 91 additions and 38 deletions

View File

@ -170,11 +170,14 @@ static void cleanupProcessObjects() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 IRCCLient Cache SHUTDOWN\n"); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 IRCCLient Cache SHUTDOWN\n");
IRCThread * &ircClient = CacheManager::getCachedItem< IRCThread * >(GameConstants::ircClientCacheLookupKey); IRCThread * &ircClient = CacheManager::getCachedItem< IRCThread * >(GameConstants::ircClientCacheLookupKey);
//printf("In main IRCThreadcheck [%p]...\n",ircClient);
if(ircClient != NULL) { if(ircClient != NULL) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 IRCCLient Cache SHUTDOWN\n"); 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__); 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); ircClient->setCallbackObj(NULL);
//printf("In main IRCThreadcheck [%p] signalled quit...\n",ircClient);
ircClient->signalQuit(); ircClient->signalQuit();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
ircClient = NULL; ircClient = NULL;

View File

@ -347,48 +347,55 @@ option(ENABLE_FRIBIDI "Enable FriBIDi support" ON)
INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}platform/sdl ) INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}platform/sdl )
INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}xml/rapidxml ) INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}xml/rapidxml )
IF(NOT WANT_STATIC_LIBS) option(DISABLE_IRCCLIENT "Disable libircclient support" OFF)
MESSAGE(STATUS "*** Searching for libircclient since WANT_STATIC_LIBS is off ...")
FIND_PACKAGE(Ircclient)
ENDIF()
if(NOT IRCCLIENT_FOUND) IF(NOT DISABLE_IRCCLIENT)
MESSAGE(STATUS "*** Using EMBEDDED libircclient since this system does not have it... IRCCLIENT_FOUND [${IRCCLIENT_FOUND}]") 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) if(NOT IRCCLIENT_FOUND)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/libircclient/include) MESSAGE(STATUS "*** Using EMBEDDED libircclient since this system does not have it... IRCCLIENT_FOUND [${IRCCLIENT_FOUND}]")
else()
MESSAGE(STATUS "*** Using SHARED libircclient found in [${IRCCLIENT_INCLUDE_DIR}] IRCCLIENT_FOUND [${IRCCLIENT_FOUND}] IRCCLIENT_LIBRARY [${IRCCLIENT_LIBRARY}]")
INCLUDE_DIRECTORIES(${IRCCLIENT_INCLUDE_DIR}) SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/libircclient/src/libircclient.c)
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${IRCCLIENT_LIBRARY}) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/libircclient/include)
endif() 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}") INCLUDE_DIRECTORIES(${IRCCLIENT_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES "${IRCCLIENT_LIBRARY}") SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${IRCCLIENT_LIBRARY})
include(CheckCXXSourceRuns) endif()
check_cxx_source_runs(" set(CMAKE_REQUIRED_INCLUDES "${IRCCLIENT_INCLUDE_DIR}")
#include <stdio.h> set(CMAKE_REQUIRED_LIBRARIES "${IRCCLIENT_LIBRARY}")
#include <stdlib.h> include(CheckCXXSourceRuns)
#include <libircclient.h>
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) check_cxx_source_runs("
message(STATUS "Found HAS_LIBIRCCLIENT_1_6: ${HAS_LIBIRCCLIENT_1_6}") #include <stdio.h>
ELSE() #include <stdlib.h>
ADD_DEFINITIONS(-DLIBIRCCLIENT_PRE1_6) #include <libircclient.h>
ENDIF() 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) IF(WIN32)
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/posix/socket.cpp) SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/posix/socket.cpp)

View File

@ -81,6 +81,7 @@ protected:
public: public:
IRCThread(const std::vector<string> &argv,IRCCallbackInterface *callbackObj); IRCThread(const std::vector<string> &argv,IRCCallbackInterface *callbackObj);
virtual ~IRCThread();
virtual void execute(); virtual void execute();
virtual void signalQuit(); virtual void signalQuit();
virtual bool shutdownAndWait(); virtual bool shutdownAndWait();

View File

@ -13,13 +13,17 @@
#include "ircclient.h" #include "ircclient.h"
#include "util.h" #include "util.h"
#include "platform_common.h" #include "platform_common.h"
#include <libircclient.h>
#if !defined(DISABLE_IRCCLIENT)
#include <libircclient.h>
// upstream moved some defines into new headers as of 1.6 // upstream moved some defines into new headers as of 1.6
#ifndef LIBIRCCLIENT_PRE1_6 #ifndef LIBIRCCLIENT_PRE1_6
#include <libirc_rfcnumeric.h> #include <libirc_rfcnumeric.h>
#endif #endif
#endif
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
@ -35,6 +39,7 @@ const int IRC_SERVER_PORT = 6667;
//bool IRCThread::debugEnabled = true; //bool IRCThread::debugEnabled = true;
bool IRCThread::debugEnabled = false; bool IRCThread::debugEnabled = false;
#if !defined(DISABLE_IRCCLIENT)
void addlog (const char * fmt, ...) { void addlog (const char * fmt, ...) {
//FILE * fp; //FILE * fp;
char buf[8096]; 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); dump_event (session, buf, origin, params, count);
} }
#endif
IRCThread::IRCThread(const std::vector<string> &argv, IRCCallbackInterface *callbackObj) : BaseThread() { IRCThread::IRCThread(const std::vector<string> &argv, IRCCallbackInterface *callbackObj) : BaseThread() {
this->argv = argv; this->argv = argv;
this->callbackObj = callbackObj; this->callbackObj = callbackObj;
@ -467,13 +474,19 @@ IRCThread::IRCThread(const std::vector<string> &argv, IRCCallbackInterface *call
void IRCThread::signalQuit() { void IRCThread::signalQuit() {
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: signalQuit [%p]\n",ircSession); if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: signalQuit [%p]\n",ircSession);
#if !defined(DISABLE_IRCCLIENT)
if(ircSession != NULL) { if(ircSession != NULL) {
setCallbackObj(NULL); setCallbackObj(NULL);
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: Quitting Channel\n"); if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC: Quitting Channel\n");
irc_cmd_quit(ircSession, "MG Bot is closing!"); irc_cmd_quit(ircSession, "MG Bot is closing!");
BaseThread::signalQuit(); BaseThread::signalQuit();
hasJoinedChannel = false; hasJoinedChannel = false;
} }
#else
BaseThread::signalQuit();
#endif
} }
bool IRCThread::shutdownAndWait() { bool IRCThread::shutdownAndWait() {
@ -486,8 +499,12 @@ bool IRCThread::shutdownAndWait() {
void IRCThread::SendIRCCmdMessage(string target, string msg) { void IRCThread::SendIRCCmdMessage(string target, string msg) {
if(ircSession != NULL && hasJoinedChannel == true) { 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(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()); 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); 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<string> IRCThread::GetIRCConnectedNickList(string target, bool waitF
eventDataDone = false; eventDataDone = false;
if(ircSession != NULL && hasJoinedChannel == true) { 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(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()); 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(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) { if(waitForCompletion == true) {
@ -506,6 +526,7 @@ std::vector<string> IRCThread::GetIRCConnectedNickList(string target, bool waitF
sleep(50); sleep(50);
} }
} }
#endif
} }
MutexSafeWrapper safeMutex(&mutexNickList,string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutex(&mutexNickList,string(__FILE__) + "_" + intToStr(__LINE__));
@ -518,7 +539,10 @@ std::vector<string> IRCThread::GetIRCConnectedNickList(string target, bool waitF
bool IRCThread::isConnected() { bool IRCThread::isConnected() {
bool ret = false; bool ret = false;
if(ircSession != NULL) { if(ircSession != NULL) {
#if !defined(DISABLE_IRCCLIENT)
ret = (irc_is_connected(ircSession) != 0); ret = (irc_is_connected(ircSession) != 0);
#endif
} }
return ret; return ret;
@ -556,6 +580,7 @@ void IRCThread::execute() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"IRC thread is running\n"); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"IRC thread is running\n");
try { try {
#if !defined(DISABLE_IRCCLIENT)
irc_callbacks_t callbacks; irc_callbacks_t callbacks;
ircSession=NULL; 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))); 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"); if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC exiting IRC CLient!\n");
} }
catch(const exception &ex) { catch(const exception &ex) {
@ -662,9 +691,14 @@ void IRCThread::execute() {
} }
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In IRCThread() calling delete ...\n");
delete this; delete this;
} }
IRCThread::~IRCThread() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In ~IRCThread() ...\n");
}
void normalizeNick(char *nick) { void normalizeNick(char *nick) {
// http://tools.ietf.org/html/rfc1459#section-2.3.1 // http://tools.ietf.org/html/rfc1459#section-2.3.1
// <target> ::= <to> [ "," <target> ] // <target> ::= <to> [ "," <target> ]
@ -718,17 +752,21 @@ void IRCThread::connectToHost() {
connectRequired = true; connectRequired = true;
} }
else { else {
#if !defined(DISABLE_IRCCLIENT)
int result = irc_is_connected(ircSession); int result = irc_is_connected(ircSession);
if(result != 1) { if(result != 1) {
connectRequired = true; connectRequired = true;
} }
#endif
} }
if(connectRequired == false) { 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(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))); if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("===> IRC Could not connect: %s\n", irc_strerror (irc_errno(ircSession)));
return; return;
} }
#endif
} }
} }
@ -736,6 +774,7 @@ void IRCThread::joinChannel() {
wantToLeaveChannel = false; wantToLeaveChannel = false;
connectToHost(); connectToHost();
if(ircSession != NULL) { if(ircSession != NULL) {
#if !defined(DISABLE_IRCCLIENT)
IRCThread *ctx = (IRCThread *)irc_get_ctx(ircSession); IRCThread *ctx = (IRCThread *)irc_get_ctx(ircSession);
if(ctx != NULL) { if(ctx != NULL) {
eventData.clear(); eventData.clear();
@ -745,16 +784,19 @@ void IRCThread::joinChannel() {
irc_cmd_join(ircSession, ctx->getChannel().c_str(), 0); irc_cmd_join(ircSession, ctx->getChannel().c_str(), 0);
} }
#endif
} }
} }
void IRCThread::leaveChannel() { void IRCThread::leaveChannel() {
wantToLeaveChannel = true; wantToLeaveChannel = true;
if(ircSession != NULL) { if(ircSession != NULL) {
#if !defined(DISABLE_IRCCLIENT)
IRCThread *ctx = (IRCThread *)irc_get_ctx(ircSession); IRCThread *ctx = (IRCThread *)irc_get_ctx(ircSession);
if(ctx != NULL) { if(ctx != NULL) {
irc_cmd_part(ircSession,ctx->getChannel().c_str()); irc_cmd_part(ircSession,ctx->getChannel().c_str());
} }
#endif
} }
} }