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

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}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 <stdio.h>
#include <stdlib.h>
#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)
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 <stdio.h>
#include <stdlib.h>
#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)
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)

View File

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

View File

@ -13,13 +13,17 @@
#include "ircclient.h"
#include "util.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
#ifndef LIBIRCCLIENT_PRE1_6
#include <libirc_rfcnumeric.h>
#endif
#endif
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
@ -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<string> &argv, IRCCallbackInterface *callbackObj) : BaseThread() {
this->argv = argv;
this->callbackObj = callbackObj;
@ -467,13 +474,19 @@ IRCThread::IRCThread(const std::vector<string> &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<string> 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<string> IRCThread::GetIRCConnectedNickList(string target, bool waitF
sleep(50);
}
}
#endif
}
MutexSafeWrapper safeMutex(&mutexNickList,string(__FILE__) + "_" + intToStr(__LINE__));
@ -518,7 +539,10 @@ std::vector<string> 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
// <target> ::= <to> [ "," <target> ]
@ -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
}
}