mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 05:13:59 +02:00
- added IRC client to the Internet game menu (still need to update VC++ projects)
This commit is contained in:
@@ -94,23 +94,25 @@ ENDIF()
|
|||||||
|
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
|
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/lib
|
${PROJECT_SOURCE_DIR}/source/win32_deps/lib
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib
|
${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/lib)
|
${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/lib
|
||||||
|
${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/build/lib)
|
||||||
|
|
||||||
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH}
|
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH}
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/include
|
${PROJECT_SOURCE_DIR}/source/win32_deps/include
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/openal-soft-1.12.854/include
|
${PROJECT_SOURCE_DIR}/source/win32_deps/openal-soft-1.12.854/include
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/openal-soft-1.12.854
|
${PROJECT_SOURCE_DIR}/source/win32_deps/openal-soft-1.12.854
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/include
|
${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/include
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/libogg-1.2.1/include
|
${PROJECT_SOURCE_DIR}/source/win32_deps/libogg-1.2.1/include
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/lua-5.1/src
|
${PROJECT_SOURCE_DIR}/source/win32_deps/lua-5.1/src
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/jpeg-8b
|
${PROJECT_SOURCE_DIR}/source/win32_deps/jpeg-8b
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/lpng141
|
${PROJECT_SOURCE_DIR}/source/win32_deps/lpng141
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/zlib-1.2.5
|
${PROJECT_SOURCE_DIR}/source/win32_deps/zlib-1.2.5
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/curl-7.20.1/include
|
${PROJECT_SOURCE_DIR}/source/win32_deps/curl-7.20.1/include
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/SDL-1.2.x/include
|
${PROJECT_SOURCE_DIR}/source/win32_deps/SDL-1.2.x/include
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/include)
|
${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/include)
|
||||||
|
|
||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/lib)
|
||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/lib)
|
||||||
|
@@ -8,13 +8,6 @@ SET(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
|
|||||||
# here is the target environment located
|
# here is the target environment located
|
||||||
SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc ${PROJECT_SOURCE_DIR}/source/win32_deps/lib)
|
SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc ${PROJECT_SOURCE_DIR}/source/win32_deps/lib)
|
||||||
|
|
||||||
# which compilers to use for C and C++
|
|
||||||
#SET(CMAKE_C_COMPILER amd64-mingw32msvc-gcc)
|
|
||||||
#SET(CMAKE_CXX_COMPILER amd64-mingw32msvc-g++)
|
|
||||||
|
|
||||||
# here is the target environment located
|
|
||||||
#SET(CMAKE_FIND_ROOT_PATH /usr/amd64-mingw32msvc ${PROJECT_SOURCE_DIR}/source/win32_deps/lib)
|
|
||||||
|
|
||||||
# adjust the default behaviour of the FIND_XXX() commands:
|
# adjust the default behaviour of the FIND_XXX() commands:
|
||||||
# search headers and libraries in the target environment, search
|
# search headers and libraries in the target environment, search
|
||||||
# programs in the host environment
|
# programs in the host environment
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -53,6 +53,26 @@ ELSE()
|
|||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
# stupid hack because cmake WILL NOT find libircclient for some reason
|
||||||
|
if(WIN32)
|
||||||
|
|
||||||
|
if(EXISTS ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include/libircclient.h)
|
||||||
|
set(LIBIRCCLIENT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include)
|
||||||
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/build/lib)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
else()
|
||||||
|
#CHECK_INCLUDE_FILES(libircclient.h LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
FIND_PATH(LIBIRCCLIENT_INCLUDE_DIR NAME libircclient.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#check_include_files("libircclient/libircclient.h;libircclient/include/libircclient.h" LIBIRCCLIENT_H_)
|
||||||
|
if(NOT LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
message(FATAL_ERROR "missing libircclient : please install it [${LIBIRCCLIENT_INCLUDE_DIR}] [${CMAKE_FIND_ROOT_PATH}]")
|
||||||
|
endif()
|
||||||
|
INCLUDE_DIRECTORIES(${LIBIRCCLIENT_INCLUDE_DIR})
|
||||||
|
#SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ircclient)
|
||||||
|
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
# glest configurator
|
# glest configurator
|
||||||
|
|
||||||
|
@@ -53,6 +53,27 @@ ELSE()
|
|||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
# stupid hack because cmake WILL NOT find libircclient for some reason
|
||||||
|
if(WIN32)
|
||||||
|
|
||||||
|
if(EXISTS ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include/libircclient.h)
|
||||||
|
set(LIBIRCCLIENT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include)
|
||||||
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/build/lib)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
else()
|
||||||
|
#CHECK_INCLUDE_FILES(libircclient.h LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
FIND_PATH(LIBIRCCLIENT_INCLUDE_DIR NAME libircclient.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#check_include_files("libircclient/libircclient.h;libircclient/include/libircclient.h" LIBIRCCLIENT_H_)
|
||||||
|
if(NOT LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
message(FATAL_ERROR "missing libircclient : please install it [${LIBIRCCLIENT_INCLUDE_DIR}] [${CMAKE_FIND_ROOT_PATH}]")
|
||||||
|
endif()
|
||||||
|
INCLUDE_DIRECTORIES(${LIBIRCCLIENT_INCLUDE_DIR})
|
||||||
|
#SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ircclient)
|
||||||
|
|
||||||
|
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
# glest G3d Model Viewer
|
# glest G3d Model Viewer
|
||||||
|
|
||||||
|
@@ -6,7 +6,8 @@ SET(EXTERNAL_LIBS "")
|
|||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
|
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/lib
|
${PROJECT_SOURCE_DIR}/source/win32_deps/lib
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib
|
||||||
|
${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/build/lib)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
|
||||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/openal-soft-1.12.854/include)
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/openal-soft-1.12.854/include)
|
||||||
@@ -24,6 +25,25 @@ IF(WIN32)
|
|||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
# stupid hack because cmake WILL NOT find libircclient for some reason
|
||||||
|
if(WIN32)
|
||||||
|
|
||||||
|
if(EXISTS ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include/libircclient.h)
|
||||||
|
set(LIBIRCCLIENT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include)
|
||||||
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/build/lib)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
CHECK_INCLUDE_FILES(libircclient/libircclient.h LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
#FIND_PATH(LIBIRCCLIENT_INCLUDE_DIR NAME libircclient/libircclient.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#check_include_files("libircclient/libircclient.h;libircclient/include/libircclient.h" LIBIRCCLIENT_H_)
|
||||||
|
if(NOT LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
message(FATAL_ERROR "missing libircclient : please install it [${LIBIRCCLIENT_INCLUDE_DIR}]")
|
||||||
|
endif()
|
||||||
|
INCLUDE_DIRECTORIES(${LIBIRCCLIENT_INCLUDE_DIR})
|
||||||
|
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ircclient)
|
||||||
|
|
||||||
FIND_PACKAGE(SDL REQUIRED)
|
FIND_PACKAGE(SDL REQUIRED)
|
||||||
INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
|
INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
|
||||||
IF(UNIX)
|
IF(UNIX)
|
||||||
@@ -214,7 +234,7 @@ SET_SOURCE_FILES_PROPERTIES(${MG_INCLUDE_FILES} PROPERTIES HEADER_FILE_ONLY 1)
|
|||||||
|
|
||||||
ADD_EXECUTABLE(${TARGET_NAME} ${MG_SOURCE_FILES} ${MG_INCLUDE_FILES})
|
ADD_EXECUTABLE(${TARGET_NAME} ${MG_SOURCE_FILES} ${MG_INCLUDE_FILES})
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
TARGET_LINK_LIBRARIES(${TARGET_NAME} stdc++ gcc odbc32 wsock32 winspool winmm shell32 comctl32 ctl3d32 advapi32 wsock32 opengl32 glu32 ole32 oleaut32 uuid mingw32 ddraw dsound dxguid ws2_32 iphlpapi wsock32 libogg libvorbis libvorbisfile zlib jpeg libpng xerces-c2_8_0 OpenAL32 libcurl winmm gdi32 opengl32 glu32 SDL SDLmain lua5.1 streflop libglest stdc++ moldname mingwex msvcrt user32 kernel32)
|
TARGET_LINK_LIBRARIES(${TARGET_NAME} stdc++ gcc odbc32 wsock32 winspool winmm shell32 comctl32 ctl3d32 advapi32 wsock32 opengl32 glu32 ole32 oleaut32 uuid mingw32 ddraw dsound dxguid ws2_32 iphlpapi wsock32 libogg libvorbis libvorbisfile zlib jpeg libpng xerces-c2_8_0 OpenAL32 libcurl winmm gdi32 opengl32 glu32 SDL SDLmain lua5.1 ircclient streflop libglest stdc++ moldname mingwex msvcrt user32 kernel32)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
IF(NOT WIN32)
|
IF(NOT WIN32)
|
||||||
TARGET_LINK_LIBRARIES(${TARGET_NAME} streflop)
|
TARGET_LINK_LIBRARIES(${TARGET_NAME} streflop)
|
||||||
|
@@ -161,19 +161,25 @@ void MainMenu::keyPress(char c){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::setState(MenuState *state){
|
void MainMenu::setState(MenuState *state){
|
||||||
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
if(oldstate != NULL && oldstate != state) {
|
if(oldstate != NULL && oldstate != state) {
|
||||||
delete oldstate;
|
delete oldstate;
|
||||||
|
|
||||||
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
if(oldstate != this->state) {
|
if(oldstate != this->state) {
|
||||||
oldstate=this->state;
|
oldstate=this->state;
|
||||||
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
oldstate = NULL;
|
oldstate = NULL;
|
||||||
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
oldstate=this->state;
|
oldstate=this->state;
|
||||||
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
this->state= state;
|
this->state= state;
|
||||||
GraphicComponent::resetFade();
|
GraphicComponent::resetFade();
|
||||||
menuBackground.setTargetCamera(state->getCamera());
|
menuBackground.setTargetCamera(state->getCamera());
|
||||||
|
@@ -32,6 +32,10 @@ namespace Glest{ namespace Game{
|
|||||||
|
|
||||||
DisplayMessageFunction MenuStateMasterserver::pCB_DisplayMessage = NULL;
|
DisplayMessageFunction MenuStateMasterserver::pCB_DisplayMessage = NULL;
|
||||||
|
|
||||||
|
static const char *IRC_SERVER = "irc.freenode.net";
|
||||||
|
static const char *IRC_CHANNEL = "#megaglest";
|
||||||
|
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class ServerLine
|
// class ServerLine
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -192,6 +196,8 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
|
|||||||
{
|
{
|
||||||
containerName = "MasterServer";
|
containerName = "MasterServer";
|
||||||
updateFromMasterserverThread = NULL;
|
updateFromMasterserverThread = NULL;
|
||||||
|
ircClient = NULL;
|
||||||
|
lastNickListUpdate = 0;
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
@@ -229,7 +235,7 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
|
|||||||
}
|
}
|
||||||
|
|
||||||
// bottom
|
// bottom
|
||||||
int buttonPos=130;
|
int buttonPos=230;
|
||||||
|
|
||||||
labelChatUrl.registerGraphicComponent(containerName,"labelChatUrl");
|
labelChatUrl.registerGraphicComponent(containerName,"labelChatUrl");
|
||||||
labelChatUrl.init(150,buttonPos-50);
|
labelChatUrl.init(150,buttonPos-50);
|
||||||
@@ -328,6 +334,14 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
|
|||||||
listBoxAutoRefresh.setSelectedItemIndex(1);
|
listBoxAutoRefresh.setSelectedItemIndex(1);
|
||||||
autoRefreshTime=10*listBoxAutoRefresh.getSelectedItemIndex();
|
autoRefreshTime=10*listBoxAutoRefresh.getSelectedItemIndex();
|
||||||
|
|
||||||
|
ircOnlinePeopleLabel.registerGraphicComponent(containerName,"ircOnlinePeopleLabel");
|
||||||
|
ircOnlinePeopleLabel.init(10,startOffset-lineOffset+30);
|
||||||
|
ircOnlinePeopleLabel.setText("IRC People Online:");
|
||||||
|
|
||||||
|
ircOnlinePeopleListLabel.registerGraphicComponent(containerName,"ircOnlinePeopleListLabel");
|
||||||
|
ircOnlinePeopleListLabel.init(90,startOffset-lineOffset+30);
|
||||||
|
ircOnlinePeopleListLabel.setText("n/a");
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
NetworkManager::getInstance().end();
|
NetworkManager::getInstance().end();
|
||||||
@@ -339,6 +353,7 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
|
|||||||
|
|
||||||
GraphicComponent::applyAllCustomProperties(containerName);
|
GraphicComponent::applyAllCustomProperties(containerName);
|
||||||
|
|
||||||
|
chatManager.init(&consoleIRC, -1,true);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
|
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
|
||||||
masterServerThreadInDeletion = false;
|
masterServerThreadInDeletion = false;
|
||||||
@@ -347,12 +362,33 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
|
|||||||
updateFromMasterserverThread->setUniqueID(__FILE__);
|
updateFromMasterserverThread->setUniqueID(__FILE__);
|
||||||
updateFromMasterserverThread->start();
|
updateFromMasterserverThread->start();
|
||||||
|
|
||||||
|
char szIRCNick[80]="";
|
||||||
|
srand(time(NULL));
|
||||||
|
int randomNickId = rand() % 999;
|
||||||
|
|
||||||
|
sprintf(szIRCNick,"MG_%s_%d",Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()).c_str(),randomNickId);
|
||||||
|
ircArgs.push_back(IRC_SERVER);
|
||||||
|
ircArgs.push_back(szIRCNick);
|
||||||
|
ircArgs.push_back(IRC_CHANNEL);
|
||||||
|
ircClient = new IRCThread(ircArgs,this);
|
||||||
|
ircClient->setUniqueID(__FILE__);
|
||||||
|
ircClient->start();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuStateMasterserver::~MenuStateMasterserver() {
|
void MenuStateMasterserver::IRC_CallbackEvent(const char* origin, const char **params, unsigned int count) {
|
||||||
|
//printf ("===> IRC: '%s' said in channel %s: %s\n",origin ? origin : "someone",params[0], params[1] );
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"%s: %s",origin ? origin : "someone",params[1]);
|
||||||
|
consoleIRC.addLine(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuStateMasterserver::cleanup() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
printf("In [%s::%s Line: %d] [%p]\n",__FILE__,__FUNCTION__,__LINE__,ircClient);
|
||||||
|
|
||||||
if(masterServerThreadInDeletion == false) {
|
if(masterServerThreadInDeletion == false) {
|
||||||
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
|
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
|
||||||
if(updateFromMasterserverThread != NULL) {
|
if(updateFromMasterserverThread != NULL) {
|
||||||
@@ -381,10 +417,32 @@ MenuStateMasterserver::~MenuStateMasterserver() {
|
|||||||
|
|
||||||
clearServerLines();
|
clearServerLines();
|
||||||
|
|
||||||
|
printf("Exiting master server menu [%p]\n",ircClient);
|
||||||
|
if(ircClient != NULL) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
ircClient->signalQuit();
|
||||||
|
//if(ircClient->shutdownAndWait() == true) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
//delete ircClient;
|
||||||
|
//}
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
ircClient = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateMasterserver::clearServerLines(){
|
MenuStateMasterserver::~MenuStateMasterserver() {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
printf("In [%s::%s Line: %d] [%p]\n",__FILE__,__FUNCTION__,__LINE__,ircClient);
|
||||||
|
cleanup();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuStateMasterserver::clearServerLines() {
|
||||||
while(!serverLines.empty()){
|
while(!serverLines.empty()){
|
||||||
delete serverLines.back();
|
delete serverLines.back();
|
||||||
serverLines.pop_back();
|
serverLines.pop_back();
|
||||||
@@ -438,6 +496,10 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -465,6 +527,9 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
mainMenu->setState(new MenuStateCustomGame(program, mainMenu,true,true));
|
mainMenu->setState(new MenuStateCustomGame(program, mainMenu,true,true));
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -561,6 +626,8 @@ void MenuStateMasterserver::render(){
|
|||||||
renderer.renderLabel(&externalConnectPort,&titleLabelColor);
|
renderer.renderLabel(&externalConnectPort,&titleLabelColor);
|
||||||
renderer.renderLabel(&selectButton,&titleLabelColor);
|
renderer.renderLabel(&selectButton,&titleLabelColor);
|
||||||
|
|
||||||
|
renderer.renderLabel(&ircOnlinePeopleLabel,&titleLabelColor);
|
||||||
|
renderer.renderLabel(&ircOnlinePeopleListLabel,&titleLabelColor);
|
||||||
|
|
||||||
// render console
|
// render console
|
||||||
renderer.renderConsole(&console,false,false);
|
renderer.renderConsole(&console,false,false);
|
||||||
@@ -568,11 +635,14 @@ void MenuStateMasterserver::render(){
|
|||||||
for(int i=0; i<serverLines.size(); ++i){
|
for(int i=0; i<serverLines.size(); ++i){
|
||||||
serverLines[i]->render();
|
serverLines[i]->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderer.renderChatManager(&chatManager);
|
||||||
|
renderer.renderConsole(&consoleIRC,false,true);
|
||||||
}
|
}
|
||||||
if(program != NULL) program->renderProgramMsgBox();
|
if(program != NULL) program->renderProgramMsgBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateMasterserver::update(){
|
void MenuStateMasterserver::update() {
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
if(autoRefreshTime!=0 && difftime(time(NULL),lastRefreshTimer) >= autoRefreshTime ) {
|
if(autoRefreshTime!=0 && difftime(time(NULL),lastRefreshTimer) >= autoRefreshTime ) {
|
||||||
needUpdateFromServer = true;
|
needUpdateFromServer = true;
|
||||||
@@ -592,6 +662,30 @@ void MenuStateMasterserver::update(){
|
|||||||
|
|
||||||
console.update();
|
console.update();
|
||||||
|
|
||||||
|
//call the chat manager
|
||||||
|
chatManager.updateNetwork();
|
||||||
|
|
||||||
|
//console
|
||||||
|
consoleIRC.update();
|
||||||
|
|
||||||
|
if(ircClient != NULL) {
|
||||||
|
if(difftime(time(NULL),lastNickListUpdate) >= 5) {
|
||||||
|
lastNickListUpdate = time(NULL);
|
||||||
|
std::vector<string> nickList = ircClient->getNickList();
|
||||||
|
string nicks = "";
|
||||||
|
for(int i = 0; i < nickList.size(); ++i) {
|
||||||
|
if(nicks != "") {
|
||||||
|
nicks += " ";
|
||||||
|
}
|
||||||
|
nicks += nickList[i];
|
||||||
|
}
|
||||||
|
ircOnlinePeopleListLabel.setText(nicks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ircOnlinePeopleListLabel.setText("");
|
||||||
|
}
|
||||||
|
|
||||||
if(threadedErrorMsg != "") {
|
if(threadedErrorMsg != "") {
|
||||||
std::string sError = threadedErrorMsg;
|
std::string sError = threadedErrorMsg;
|
||||||
threadedErrorMsg = "";
|
threadedErrorMsg = "";
|
||||||
@@ -815,30 +909,50 @@ void MenuStateMasterserver::showMessageBox(const string &text, const string &hea
|
|||||||
void MenuStateMasterserver::keyDown(char key) {
|
void MenuStateMasterserver::keyDown(char key) {
|
||||||
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
||||||
|
|
||||||
if(key == configKeys.getCharKey("ToggleMusic")) {
|
if(chatManager.getEditEnabled() == true) {
|
||||||
Config &config = Config::getInstance();
|
//printf("keyDown key [%d] chatManager.getText() [%s]\n",key,chatManager.getText().c_str());
|
||||||
Lang &lang= Lang::getInstance();
|
if(key == vkReturn && ircClient != NULL) {
|
||||||
|
ircClient->SendIRCCmdMessage(IRC_CHANNEL, chatManager.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float configVolume = (config.getInt("SoundVolumeMusic") / 100.f);
|
chatManager.keyDown(key);
|
||||||
float currentVolume = CoreData::getInstance().getMenuMusic()->getVolume();
|
if(chatManager.getEditEnabled() == false) {
|
||||||
if(currentVolume > 0) {
|
if(key == configKeys.getCharKey("ToggleMusic")) {
|
||||||
CoreData::getInstance().getMenuMusic()->setVolume(0.f);
|
Config &config = Config::getInstance();
|
||||||
console.addLine(lang.get("GameMusic") + " " + lang.get("Off"));
|
Lang &lang= Lang::getInstance();
|
||||||
}
|
|
||||||
else {
|
float configVolume = (config.getInt("SoundVolumeMusic") / 100.f);
|
||||||
CoreData::getInstance().getMenuMusic()->setVolume(configVolume);
|
float currentVolume = CoreData::getInstance().getMenuMusic()->getVolume();
|
||||||
//If the config says zero, use the default music volume
|
if(currentVolume > 0) {
|
||||||
//gameMusic->setVolume(configVolume ? configVolume : 0.9);
|
CoreData::getInstance().getMenuMusic()->setVolume(0.f);
|
||||||
console.addLine(lang.get("GameMusic"));
|
console.addLine(lang.get("GameMusic") + " " + lang.get("Off"));
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else if(key == configKeys.getCharKey("SaveGUILayout")) {
|
CoreData::getInstance().getMenuMusic()->setVolume(configVolume);
|
||||||
bool saved = GraphicComponent::saveAllCustomProperties(containerName);
|
//If the config says zero, use the default music volume
|
||||||
Lang &lang= Lang::getInstance();
|
//gameMusic->setVolume(configVolume ? configVolume : 0.9);
|
||||||
console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]");
|
console.addLine(lang.get("GameMusic"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if(key == configKeys.getCharKey("SaveGUILayout")) {
|
||||||
|
bool saved = GraphicComponent::saveAllCustomProperties(containerName);
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//CoreData::getInstance().getMenuMusic()->setVolume(strToInt(listBoxVolumeMusic.getSelectedItem())/100.f);
|
void MenuStateMasterserver::keyPress(char c) {
|
||||||
|
chatManager.keyPress(c);
|
||||||
|
}
|
||||||
|
void MenuStateMasterserver::keyUp(char key) {
|
||||||
|
chatManager.keyUp(key);
|
||||||
|
|
||||||
|
if(chatManager.getEditEnabled()) {
|
||||||
|
//send key to the chat manager
|
||||||
|
chatManager.keyUp(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -3,9 +3,9 @@
|
|||||||
//
|
//
|
||||||
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
// by the Free Software Foundation; either version 2 of the
|
// by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version
|
// License, or (at your option) any later version
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
#include "masterserver_info.h"
|
#include "masterserver_info.h"
|
||||||
#include "simple_threads.h"
|
#include "simple_threads.h"
|
||||||
#include "network_interface.h"
|
#include "network_interface.h"
|
||||||
|
#include "ircclient.h"
|
||||||
|
#include "chat_manager.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
@@ -37,14 +39,14 @@ private:
|
|||||||
GraphicLabel glestVersionLabel;
|
GraphicLabel glestVersionLabel;
|
||||||
GraphicLabel platformLabel;
|
GraphicLabel platformLabel;
|
||||||
//GraphicLabel binaryCompileDateLabel;
|
//GraphicLabel binaryCompileDateLabel;
|
||||||
|
|
||||||
//game info:
|
//game info:
|
||||||
GraphicLabel serverTitleLabel;
|
GraphicLabel serverTitleLabel;
|
||||||
GraphicLabel ipAddressLabel;
|
GraphicLabel ipAddressLabel;
|
||||||
|
|
||||||
//game setup info:
|
//game setup info:
|
||||||
GraphicLabel techLabel;
|
GraphicLabel techLabel;
|
||||||
GraphicLabel mapLabel;
|
GraphicLabel mapLabel;
|
||||||
GraphicLabel tilesetLabel;
|
GraphicLabel tilesetLabel;
|
||||||
GraphicLabel activeSlotsLabel;
|
GraphicLabel activeSlotsLabel;
|
||||||
|
|
||||||
@@ -62,16 +64,16 @@ public:
|
|||||||
bool buttonMouseMove(int x, int y);
|
bool buttonMouseMove(int x, int y);
|
||||||
//void setIndex(int value);
|
//void setIndex(int value);
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ===============================
|
// ===============================
|
||||||
// class MenuStateMasterserver
|
// class MenuStateMasterserver
|
||||||
// ===============================
|
// ===============================
|
||||||
typedef vector<ServerLine*> ServerLines;
|
typedef vector<ServerLine*> ServerLines;
|
||||||
typedef vector<MasterServerInfo*> MasterServerInfos;
|
typedef vector<MasterServerInfo*> MasterServerInfos;
|
||||||
|
|
||||||
class MenuStateMasterserver : public MenuState, public SimpleTaskCallbackInterface {
|
class MenuStateMasterserver : public MenuState, public SimpleTaskCallbackInterface, public IRCCallbackInterface {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -83,10 +85,10 @@ private:
|
|||||||
GraphicLabel labelTitle;
|
GraphicLabel labelTitle;
|
||||||
ServerLines serverLines;
|
ServerLines serverLines;
|
||||||
GraphicLabel labelChatUrl;
|
GraphicLabel labelChatUrl;
|
||||||
|
|
||||||
GraphicLabel announcementLabel;
|
GraphicLabel announcementLabel;
|
||||||
GraphicLabel versionInfoLabel;
|
GraphicLabel versionInfoLabel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GraphicLabel glestVersionLabel;
|
GraphicLabel glestVersionLabel;
|
||||||
@@ -106,17 +108,20 @@ private:
|
|||||||
GraphicLabel externalConnectPort;
|
GraphicLabel externalConnectPort;
|
||||||
|
|
||||||
GraphicLabel selectButton;
|
GraphicLabel selectButton;
|
||||||
|
|
||||||
GraphicMessageBox mainMessageBox;
|
GraphicMessageBox mainMessageBox;
|
||||||
int mainMessageBoxState;
|
int mainMessageBoxState;
|
||||||
|
|
||||||
|
GraphicLabel ircOnlinePeopleLabel;
|
||||||
|
GraphicLabel ircOnlinePeopleListLabel;
|
||||||
|
|
||||||
bool announcementLoaded;
|
bool announcementLoaded;
|
||||||
bool needUpdateFromServer;
|
bool needUpdateFromServer;
|
||||||
int autoRefreshTime;
|
int autoRefreshTime;
|
||||||
time_t lastRefreshTimer;
|
time_t lastRefreshTimer;
|
||||||
SimpleTaskThread *updateFromMasterserverThread;
|
SimpleTaskThread *updateFromMasterserverThread;
|
||||||
bool playServerFoundSound;
|
bool playServerFoundSound;
|
||||||
|
|
||||||
Console console;
|
Console console;
|
||||||
|
|
||||||
static DisplayMessageFunction pCB_DisplayMessage;
|
static DisplayMessageFunction pCB_DisplayMessage;
|
||||||
@@ -125,26 +130,39 @@ private:
|
|||||||
Mutex masterServerThreadPtrChangeAccessor;
|
Mutex masterServerThreadPtrChangeAccessor;
|
||||||
bool masterServerThreadInDeletion;
|
bool masterServerThreadInDeletion;
|
||||||
|
|
||||||
|
std::vector<string> ircArgs;
|
||||||
|
IRCThread *ircClient;
|
||||||
|
time_t lastNickListUpdate;
|
||||||
|
|
||||||
|
Console consoleIRC;
|
||||||
|
ChatManager chatManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MenuStateMasterserver(Program *program, MainMenu *mainMenu);
|
MenuStateMasterserver(Program *program, MainMenu *mainMenu);
|
||||||
virtual ~MenuStateMasterserver();
|
~MenuStateMasterserver();
|
||||||
|
|
||||||
void mouseClick(int x, int y, MouseButton mouseButton);
|
void mouseClick(int x, int y, MouseButton mouseButton);
|
||||||
void mouseMove(int x, int y, const MouseState *mouseState);
|
void mouseMove(int x, int y, const MouseState *mouseState);
|
||||||
void update();
|
void update();
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
virtual void keyDown(char key);
|
virtual void keyDown(char key);
|
||||||
|
virtual void keyPress(char c);
|
||||||
|
virtual void keyUp(char key);
|
||||||
|
|
||||||
virtual void simpleTask();
|
virtual void simpleTask();
|
||||||
|
|
||||||
static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; }
|
static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; }
|
||||||
|
|
||||||
|
virtual void IRC_CallbackEvent(const char* origin, const char **params, unsigned int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showMessageBox(const string &text, const string &header, bool toggle);
|
void showMessageBox(const string &text, const string &header, bool toggle);
|
||||||
bool connectToServer(string ipString, int port);
|
bool connectToServer(string ipString, int port);
|
||||||
void clearServerLines();
|
void clearServerLines();
|
||||||
void updateServerInfo();
|
void updateServerInfo();
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -49,6 +49,27 @@ ELSE()
|
|||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
# stupid hack because cmake WILL NOT find libircclient for some reason
|
||||||
|
if(WIN32)
|
||||||
|
|
||||||
|
if(EXISTS ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include/libircclient.h)
|
||||||
|
set(LIBIRCCLIENT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include)
|
||||||
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/build/lib)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
else()
|
||||||
|
#CHECK_INCLUDE_FILES(libircclient.h LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
FIND_PATH(LIBIRCCLIENT_INCLUDE_DIR NAME libircclient.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#check_include_files("libircclient/libircclient.h;libircclient/include/libircclient.h" LIBIRCCLIENT_H_)
|
||||||
|
if(NOT LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
message(FATAL_ERROR "missing libircclient : please install it [${LIBIRCCLIENT_INCLUDE_DIR}] [${CMAKE_FIND_ROOT_PATH}]")
|
||||||
|
endif()
|
||||||
|
INCLUDE_DIRECTORIES(${LIBIRCCLIENT_INCLUDE_DIR})
|
||||||
|
#SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ircclient)
|
||||||
|
|
||||||
|
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
# glest map editor
|
# glest map editor
|
||||||
|
|
||||||
|
@@ -9,11 +9,14 @@ ADD_SUBDIRECTORY(sources/streflop)
|
|||||||
|
|
||||||
SET(EXTERNAL_LIBS "")
|
SET(EXTERNAL_LIBS "")
|
||||||
|
|
||||||
|
INCLUDE (CheckIncludeFiles)
|
||||||
|
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
|
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/lib
|
${PROJECT_SOURCE_DIR}/source/win32_deps/lib
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib
|
${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib
|
||||||
${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/lib)
|
${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/lib
|
||||||
|
${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/build/lib)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
|
||||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/openal-soft-1.12.854/include)
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/openal-soft-1.12.854/include)
|
||||||
@@ -31,14 +34,31 @@ IF(WIN32)
|
|||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/lib)
|
||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/xerces-c-src_2_8_0/lib)
|
||||||
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/lib)
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/wxWidgets-2.8.10/lib)
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
IF(WIN32)
|
|
||||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
|
||||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/posix)
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/posix)
|
||||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32)
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
# stupid hack because cmake WILL NOT find libircclient for some reason
|
||||||
|
if(WIN32)
|
||||||
|
|
||||||
|
if(EXISTS ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include/libircclient.h)
|
||||||
|
set(LIBIRCCLIENT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/include)
|
||||||
|
link_directories(${PROJECT_SOURCE_DIR}/source/win32_deps/libircclient/build/lib)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
CHECK_INCLUDE_FILES(libircclient/libircclient.h LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
#FIND_PATH(LIBIRCCLIENT_INCLUDE_DIR NAME libircclient/libircclient.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#check_include_files("libircclient/libircclient.h;libircclient/include/libircclient.h" LIBIRCCLIENT_H_)
|
||||||
|
if(NOT LIBIRCCLIENT_INCLUDE_DIR)
|
||||||
|
message(FATAL_ERROR "missing libircclient : please install it [${LIBIRCCLIENT_INCLUDE_DIR}]")
|
||||||
|
endif()
|
||||||
|
INCLUDE_DIRECTORIES(${LIBIRCCLIENT_INCLUDE_DIR})
|
||||||
|
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ircclient)
|
||||||
|
|
||||||
FIND_PACKAGE(SDL REQUIRED)
|
FIND_PACKAGE(SDL REQUIRED)
|
||||||
INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
|
INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
|
||||||
IF(UNIX)
|
IF(UNIX)
|
||||||
@@ -135,6 +155,7 @@ INCLUDE_DIRECTORIES( ${MG_INCLUDES_ROOT}platform/sdl )
|
|||||||
|
|
||||||
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)
|
||||||
|
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/posix/ircclient.cpp)
|
||||||
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/sdl/gl_wrap.cpp)
|
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/sdl/gl_wrap.cpp)
|
||||||
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/sdl/thread.cpp)
|
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/sdl/thread.cpp)
|
||||||
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/sdl/window.cpp)
|
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${PROJECT_SOURCE_DIR}/source/shared_lib/sources/platform/sdl/window.cpp)
|
||||||
@@ -218,7 +239,7 @@ ENDIF()
|
|||||||
#ADD_LIBRARY(libglest SHARED ${MG_SOURCE_FILES} ${MG_INCLUDE_FILES})
|
#ADD_LIBRARY(libglest SHARED ${MG_SOURCE_FILES} ${MG_INCLUDE_FILES})
|
||||||
#ADD_LIBRARY(libglest STATIC ${MG_SOURCE_FILES} ${MG_INCLUDE_FILES})
|
#ADD_LIBRARY(libglest STATIC ${MG_SOURCE_FILES} ${MG_INCLUDE_FILES})
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
TARGET_LINK_LIBRARIES(libglest stdc++ gcc odbc32 wsock32 winspool winmm shell32 comctl32 ctl3d32 advapi32 wsock32 opengl32 glu32 ole32 oleaut32 uuid mingw32 ddraw dsound dxguid ws2_32 iphlpapi wsock32 libogg libvorbis libvorbisfile zlib jpeg libpng xerces-c2_8_0 OpenAL32 libcurl winmm gdi32 opengl32 glu32 SDL SDLmain lua5.1 streflop libglest stdc++ moldname mingwex msvcrt user32 kernel32)
|
TARGET_LINK_LIBRARIES(libglest stdc++ gcc odbc32 wsock32 winspool winmm shell32 comctl32 ctl3d32 advapi32 wsock32 opengl32 glu32 ole32 oleaut32 uuid mingw32 ddraw dsound dxguid ws2_32 iphlpapi wsock32 libogg libvorbis libvorbisfile zlib jpeg libpng xerces-c2_8_0 OpenAL32 libcurl winmm gdi32 opengl32 glu32 SDL SDLmain lua5.1 ircclient streflop libglest stdc++ moldname mingwex msvcrt user32 kernel32)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
TARGET_LINK_LIBRARIES(libglest streflop)
|
TARGET_LINK_LIBRARIES(libglest streflop)
|
||||||
TARGET_LINK_LIBRARIES(libglest ${EXTERNAL_LIBS})
|
TARGET_LINK_LIBRARIES(libglest ${EXTERNAL_LIBS})
|
||||||
|
66
source/shared_lib/include/platform/posix/ircclient.h
Normal file
66
source/shared_lib/include/platform/posix/ircclient.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of MegaGlest Shared Library (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and
|
||||||
|
// Mark Vejvoda (mark_vejvoda@hotmail.com)
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
#ifndef _SHARED_PLATFORMCOMMON_IRCTHREAD_H_
|
||||||
|
#define _SHARED_PLATFORMCOMMON_IRCTHREAD_H_
|
||||||
|
|
||||||
|
#include "base_thread.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
#include <libircclient/libircclient.h>
|
||||||
|
#else
|
||||||
|
#include "libircclient.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class IRCThreadThread
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class IRCCallbackInterface {
|
||||||
|
public:
|
||||||
|
virtual void IRC_CallbackEvent(const char* origin, const char **params, unsigned int count) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class IRCThread : public BaseThread
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::vector<string> argv;
|
||||||
|
irc_session_t *ircSession;
|
||||||
|
|
||||||
|
public:
|
||||||
|
IRCThread(const std::vector<string> &argv,IRCCallbackInterface *callbackObj);
|
||||||
|
virtual void execute();
|
||||||
|
virtual void signalQuit();
|
||||||
|
virtual bool shutdownAndWait();
|
||||||
|
|
||||||
|
void SendIRCCmdMessage(string target, string msg);
|
||||||
|
std::vector<string> GetIRCConnectedNickList(string target);
|
||||||
|
|
||||||
|
static IRCCallbackInterface *callbackObj;
|
||||||
|
|
||||||
|
std::vector<string> getNickList() { return eventData; }
|
||||||
|
|
||||||
|
static std::vector<string> eventData;
|
||||||
|
static bool eventDataDone;
|
||||||
|
static bool isConnected;
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
@@ -1,52 +1,43 @@
|
|||||||
/*
|
// ==============================================================
|
||||||
* Copyright (C) 2004-2009 Georgy Yunaev gyunaev@ulduzsoft.com
|
// This file is part of MegaGlest Shared Library (www.glest.org)
|
||||||
*
|
//
|
||||||
* This example is free, and not covered by LGPL license. There is no
|
// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and
|
||||||
* restriction applied to their modification, redistribution, using and so on.
|
// Mark Vejvoda (mark_vejvoda@hotmail.com)
|
||||||
* You can study them, modify them, use them in your own program - either
|
//
|
||||||
* completely or partially. By using it you may give me some credits in your
|
// You can redistribute this code and/or modify it under
|
||||||
* program, but you don't have to.
|
// the terms of the GNU General Public License as published
|
||||||
*
|
// by the Free Software Foundation; either version 2 of the
|
||||||
*
|
// License, or (at your option) any later version
|
||||||
* This example tests most features of libirc. It can join the specific
|
// ==============================================================
|
||||||
* channel, welcoming all the people there, and react on some messages -
|
|
||||||
* 'help', 'quit', 'dcc chat', 'dcc send', 'ctcp'. Also it can reply to
|
#include "ircclient.h"
|
||||||
* CTCP requests, receive DCC files and accept DCC chats.
|
#include "util.h"
|
||||||
*
|
#include "platform_common.h"
|
||||||
* Features used:
|
|
||||||
* - nickname parsing;
|
using namespace Shared::Util;
|
||||||
* - handling 'channel' event to track the messages;
|
using namespace Shared::PlatformCommon;
|
||||||
* - handling dcc and ctcp events;
|
|
||||||
* - using internal ctcp rely procedure;
|
namespace Shared { namespace PlatformCommon {
|
||||||
* - generating channel messages;
|
|
||||||
* - handling dcc send and dcc chat events;
|
|
||||||
* - initiating dcc send and dcc chat.
|
|
||||||
*
|
|
||||||
* $Id: irctest.c 73 2009-01-03 11:14:59Z gyunaev $
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <libircclient/libircclient.h>
|
IRCCallbackInterface *IRCThread::callbackObj=NULL;
|
||||||
|
std::vector<string> IRCThread::eventData;
|
||||||
|
bool IRCThread::eventDataDone = false;
|
||||||
|
bool IRCThread::isConnected = false;
|
||||||
//
|
//
|
||||||
// We store data in IRC session context.
|
// We store data in IRC session context.
|
||||||
//
|
//
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
string channel;
|
||||||
char * channel;
|
string nick;
|
||||||
char * nick;
|
|
||||||
|
|
||||||
} irc_ctx_t;
|
} irc_ctx_t;
|
||||||
|
|
||||||
|
void addlog (const char * fmt, ...) {
|
||||||
void addlog (const char * fmt, ...)
|
|
||||||
{
|
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
va_list va_alist;
|
va_list va_alist;
|
||||||
@@ -58,68 +49,65 @@ void addlog (const char * fmt, ...)
|
|||||||
vsnprintf (buf, sizeof(buf), fmt, va_alist);
|
vsnprintf (buf, sizeof(buf), fmt, va_alist);
|
||||||
#endif
|
#endif
|
||||||
va_end (va_alist);
|
va_end (va_alist);
|
||||||
|
printf ("===> IRC: %s\n", buf);
|
||||||
|
|
||||||
printf ("%s\n", buf);
|
if ( (fp = fopen ("irctest.log", "ab")) != 0 ) {
|
||||||
|
|
||||||
if ( (fp = fopen ("irctest.log", "ab")) != 0 )
|
|
||||||
{
|
|
||||||
fprintf (fp, "%s\n", buf);
|
fprintf (fp, "%s\n", buf);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dump_event (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) {
|
||||||
void dump_event (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
|
char buf[512]="";
|
||||||
{
|
int cnt=0;
|
||||||
char buf[512];
|
|
||||||
int cnt;
|
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
for ( cnt = 0; cnt < count; cnt++ )
|
for ( cnt = 0; cnt < count; cnt++ ) {
|
||||||
{
|
|
||||||
if ( cnt )
|
if ( cnt )
|
||||||
strcat (buf, "|");
|
strcat (buf, "|");
|
||||||
|
|
||||||
strcat (buf, params[cnt]);
|
strcat (buf, params[cnt]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
addlog ("Event \"%s\", origin: \"%s\", params: %d [%s]", event, origin ? origin : "NULL", cnt, buf);
|
addlog ("Event \"%s\", origin: \"%s\", params: %d [%s]", event, origin ? origin : "NULL", cnt, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void event_join(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) {
|
||||||
void event_join (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
|
|
||||||
{
|
|
||||||
dump_event (session, event, origin, params, count);
|
dump_event (session, event, origin, params, count);
|
||||||
irc_cmd_user_mode (session, "+i");
|
|
||||||
irc_cmd_msg (session, params[0], "Hi all");
|
if(IRCThread::isConnected == false) {
|
||||||
|
irc_cmd_user_mode (session, "+i");
|
||||||
|
irc_cmd_msg (session, params[0], "MG Bot says hello!");
|
||||||
|
//GetIRCConnectedNickList(argv[2]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
char realNick[128]="";
|
||||||
|
irc_target_get_nick(origin,&realNick[0],127);
|
||||||
|
printf ("===> IRC: user joined channel realNick [%s] origin [%s]\n", realNick,origin);
|
||||||
|
IRCThread::eventData.push_back(realNick);
|
||||||
|
}
|
||||||
|
|
||||||
|
IRCThread::isConnected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void event_connect (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) {
|
||||||
void event_connect (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
|
|
||||||
{
|
|
||||||
irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
|
irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
|
||||||
dump_event (session, event, origin, params, count);
|
dump_event (session, event, origin, params, count);
|
||||||
|
|
||||||
irc_cmd_join (session, ctx->channel, 0);
|
irc_cmd_join (session, ctx->channel.c_str(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void event_privmsg (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) {
|
||||||
void event_privmsg (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
|
|
||||||
{
|
|
||||||
dump_event (session, event, origin, params, count);
|
dump_event (session, event, origin, params, count);
|
||||||
|
|
||||||
printf ("'%s' said me (%s): %s\n",
|
printf ("'%s' said me (%s): %s\n",
|
||||||
origin ? origin : "someone",
|
origin ? origin : "someone",
|
||||||
params[0], params[1] );
|
params[0], params[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dcc_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void * ctx, const char * data, unsigned int length) {
|
||||||
void dcc_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void * ctx, const char * data, unsigned int length)
|
|
||||||
{
|
|
||||||
static int count = 1;
|
static int count = 1;
|
||||||
char buf[12];
|
char buf[12]="";
|
||||||
|
|
||||||
switch (status)
|
switch (status)
|
||||||
{
|
{
|
||||||
@@ -133,7 +121,7 @@ void dcc_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void
|
|||||||
printf ("DCC %d: chat connected\n", id);
|
printf ("DCC %d: chat connected\n", id);
|
||||||
irc_dcc_msg (session, id, "Hehe");
|
irc_dcc_msg (session, id, "Hehe");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf ("DCC %d: %s\n", id, data);
|
printf ("DCC %d: %s\n", id, data);
|
||||||
sprintf (buf, "DCC [%d]: %d", id, count++);
|
sprintf (buf, "DCC [%d]: %d", id, count++);
|
||||||
@@ -147,42 +135,36 @@ void dcc_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dcc_file_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void * ctx, const char * data, unsigned int length) {
|
||||||
void dcc_file_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void * ctx, const char * data, unsigned int length)
|
if ( status == 0 && length == 0 ) {
|
||||||
{
|
|
||||||
if ( status == 0 && length == 0 )
|
|
||||||
{
|
|
||||||
printf ("File sent successfully\n");
|
printf ("File sent successfully\n");
|
||||||
|
|
||||||
if ( ctx )
|
if ( ctx )
|
||||||
fclose ((FILE*) ctx);
|
fclose ((FILE*) ctx);
|
||||||
}
|
}
|
||||||
else if ( status )
|
else if ( status ) {
|
||||||
{
|
|
||||||
printf ("File sent error: %d\n", status);
|
printf ("File sent error: %d\n", status);
|
||||||
|
|
||||||
if ( ctx )
|
if ( ctx )
|
||||||
fclose ((FILE*) ctx);
|
fclose ((FILE*) ctx);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if ( ctx )
|
if ( ctx )
|
||||||
fwrite (data, 1, length, (FILE*) ctx);
|
fwrite (data, 1, length, (FILE*) ctx);
|
||||||
printf ("File sent progress: %d\n", length);
|
printf ("File sent progress: %d\n", length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void event_channel(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) {
|
||||||
void event_channel (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
|
char nickbuf[128]="";
|
||||||
{
|
|
||||||
char nickbuf[128];
|
|
||||||
|
|
||||||
if ( count != 2 )
|
if ( count != 2 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf ("'%s' said in channel %s: %s\n",
|
printf ("===> IRC: '%s' said in channel %s: %s\n",origin ? origin : "someone",params[0], params[1] );
|
||||||
origin ? origin : "someone",
|
if(IRCThread::callbackObj) {
|
||||||
params[0], params[1] );
|
IRCThread::callbackObj->IRC_CallbackEvent(origin, params, count);
|
||||||
|
}
|
||||||
|
|
||||||
if ( !origin )
|
if ( !origin )
|
||||||
return;
|
return;
|
||||||
@@ -205,24 +187,24 @@ void event_channel (irc_session_t * session, const char * event, const char * or
|
|||||||
irc_cmd_ctcp_request (session, nickbuf, "TIME");
|
irc_cmd_ctcp_request (session, nickbuf, "TIME");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !strcmp (params[1], "dcc chat") )
|
if ( !strcmp (params[1], "dcc chat") ) {
|
||||||
{
|
|
||||||
irc_dcc_t dccid;
|
irc_dcc_t dccid;
|
||||||
irc_dcc_chat (session, 0, nickbuf, dcc_recv_callback, &dccid);
|
irc_dcc_chat (session, 0, nickbuf, dcc_recv_callback, &dccid);
|
||||||
printf ("DCC chat ID: %d\n", dccid);
|
printf ("DCC chat ID: %d\n", dccid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !strcmp (params[1], "dcc send") )
|
if ( !strcmp (params[1], "dcc send") ) {
|
||||||
{
|
|
||||||
irc_dcc_t dccid;
|
irc_dcc_t dccid;
|
||||||
irc_dcc_sendfile (session, 0, nickbuf, "irctest.c", dcc_file_recv_callback, &dccid);
|
irc_dcc_sendfile (session, 0, nickbuf, "irctest.c", dcc_file_recv_callback, &dccid);
|
||||||
printf ("DCC send ID: %d\n", dccid);
|
printf ("DCC send ID: %d\n", dccid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !strcmp (params[1], "topic") )
|
if ( !strcmp (params[1], "topic") ) {
|
||||||
irc_cmd_topic (session, params[0], 0);
|
irc_cmd_topic (session, params[0], 0);
|
||||||
else if ( strstr (params[1], "topic ") == params[1] )
|
}
|
||||||
|
else if ( strstr (params[1], "topic ") == params[1] ) {
|
||||||
irc_cmd_topic (session, params[0], params[1] + 6);
|
irc_cmd_topic (session, params[0], params[1] + 6);
|
||||||
|
}
|
||||||
|
|
||||||
if ( strstr (params[1], "mode ") == params[1] )
|
if ( strstr (params[1], "mode ") == params[1] )
|
||||||
irc_cmd_channel_mode (session, params[0], params[1] + 5);
|
irc_cmd_channel_mode (session, params[0], params[1] + 5);
|
||||||
@@ -234,17 +216,13 @@ void event_channel (irc_session_t * session, const char * event, const char * or
|
|||||||
irc_cmd_whois (session, params[1] + 5);
|
irc_cmd_whois (session, params[1] + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void irc_event_dcc_chat(irc_session_t * session, const char * nick, const char * addr, irc_dcc_t dccid) {
|
||||||
void irc_event_dcc_chat (irc_session_t * session, const char * nick, const char * addr, irc_dcc_t dccid)
|
|
||||||
{
|
|
||||||
printf ("DCC chat [%d] requested from '%s' (%s)\n", dccid, nick, addr);
|
printf ("DCC chat [%d] requested from '%s' (%s)\n", dccid, nick, addr);
|
||||||
|
|
||||||
irc_dcc_accept (session, dccid, 0, dcc_recv_callback);
|
irc_dcc_accept (session, dccid, 0, dcc_recv_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void irc_event_dcc_send(irc_session_t * session, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid) {
|
||||||
void irc_event_dcc_send (irc_session_t * session, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid)
|
|
||||||
{
|
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
printf ("DCC send [%d] requested from '%s' (%s): %s (%lu bytes)\n", dccid, nick, addr, filename, size);
|
printf ("DCC send [%d] requested from '%s' (%s): %s (%lu bytes)\n", dccid, nick, addr, filename, size);
|
||||||
|
|
||||||
@@ -254,70 +232,226 @@ void irc_event_dcc_send (irc_session_t * session, const char * nick, const char
|
|||||||
irc_dcc_accept (session, dccid, fp, dcc_file_recv_callback);
|
irc_dcc_accept (session, dccid, fp, dcc_file_recv_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_numeric (irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count)
|
void event_leave(irc_session_t *session, const char *event, const char *origin, const char ** params, unsigned count) {
|
||||||
{
|
char buf[24]="";
|
||||||
char buf[24];
|
sprintf (buf, "%s", event);
|
||||||
|
|
||||||
|
// someone left the channel.
|
||||||
|
|
||||||
|
if(origin) {
|
||||||
|
printf ("===> IRC: user left channel [%s]\n", origin);
|
||||||
|
|
||||||
|
char realNick[128]="";
|
||||||
|
irc_target_get_nick(origin,&realNick[0],127);
|
||||||
|
|
||||||
|
printf ("===> IRC: user left channel realNick [%s]\n", realNick);
|
||||||
|
|
||||||
|
for(int i = 0; i < IRCThread::eventData.size(); ++i) {
|
||||||
|
printf ("===> IRC: lookingfor match [%s] realNick [%s]\n", IRCThread::eventData[i].c_str(),realNick);
|
||||||
|
|
||||||
|
if(IRCThread::eventData[i] == realNick) {
|
||||||
|
IRCThread::eventData.erase(IRCThread::eventData.begin() + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dump_event (session, buf, origin, params, count);
|
||||||
|
}
|
||||||
|
void event_numeric(irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count) {
|
||||||
|
char buf[24]="";
|
||||||
sprintf (buf, "%d", event);
|
sprintf (buf, "%d", event);
|
||||||
|
|
||||||
|
switch (event) {
|
||||||
|
case LIBIRC_RFC_ERR_NICKNAMEINUSE :
|
||||||
|
case LIBIRC_RFC_ERR_NICKCOLLISION :
|
||||||
|
//irc_auto_rename_nick(session);
|
||||||
|
break;
|
||||||
|
case LIBIRC_RFC_RPL_TOPIC :
|
||||||
|
break;
|
||||||
|
case LIBIRC_RFC_RPL_NAMREPLY :
|
||||||
|
{
|
||||||
|
if(event == LIBIRC_RFC_RPL_NAMREPLY) {
|
||||||
|
IRCThread::eventData.clear();
|
||||||
|
if(count >= 4) {
|
||||||
|
for(int i = 3; i < count && params[i]; ++i) {
|
||||||
|
|
||||||
|
vector<string> tokens;
|
||||||
|
Tokenize(params[i],tokens," ");
|
||||||
|
|
||||||
|
for(int j = 0; j < tokens.size(); ++j) {
|
||||||
|
IRCThread::eventData.push_back(tokens[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LIBIRC_RFC_RPL_ENDOFNAMES:
|
||||||
|
IRCThread::eventDataDone = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
dump_event (session, buf, origin, params, count);
|
dump_event (session, buf, origin, params, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
IRCThread::IRCThread(const std::vector<string> &argv, IRCCallbackInterface *callbackObj) : BaseThread() {
|
||||||
{
|
this->argv = argv;
|
||||||
irc_callbacks_t callbacks;
|
this->callbackObj = callbackObj;
|
||||||
irc_ctx_t ctx;
|
ircSession = NULL;
|
||||||
irc_session_t * s;
|
IRCThread::eventData.clear();
|
||||||
|
IRCThread::eventDataDone = false;
|
||||||
if ( argc != 4 )
|
isConnected = false;
|
||||||
{
|
|
||||||
printf ("Usage: %s <server> <nick> <channel>\n", argv[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (&callbacks, 0, sizeof(callbacks));
|
|
||||||
|
|
||||||
callbacks.event_connect = event_connect;
|
|
||||||
callbacks.event_join = event_join;
|
|
||||||
callbacks.event_nick = dump_event;
|
|
||||||
callbacks.event_quit = dump_event;
|
|
||||||
callbacks.event_part = dump_event;
|
|
||||||
callbacks.event_mode = dump_event;
|
|
||||||
callbacks.event_topic = dump_event;
|
|
||||||
callbacks.event_kick = dump_event;
|
|
||||||
callbacks.event_channel = event_channel;
|
|
||||||
callbacks.event_privmsg = event_privmsg;
|
|
||||||
callbacks.event_notice = dump_event;
|
|
||||||
callbacks.event_invite = dump_event;
|
|
||||||
callbacks.event_umode = dump_event;
|
|
||||||
callbacks.event_ctcp_rep = dump_event;
|
|
||||||
callbacks.event_ctcp_action = dump_event;
|
|
||||||
callbacks.event_unknown = dump_event;
|
|
||||||
callbacks.event_numeric = event_numeric;
|
|
||||||
|
|
||||||
callbacks.event_dcc_chat_req = irc_event_dcc_chat;
|
|
||||||
callbacks.event_dcc_send_req = irc_event_dcc_send;
|
|
||||||
|
|
||||||
s = irc_create_session (&callbacks);
|
|
||||||
|
|
||||||
if ( !s )
|
|
||||||
{
|
|
||||||
printf ("Could not create session\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.channel = argv[3];
|
|
||||||
ctx.nick = argv[2];
|
|
||||||
|
|
||||||
irc_set_ctx (s, &ctx);
|
|
||||||
|
|
||||||
if ( irc_connect (s, argv[1], 6667, 0, argv[2], 0, 0) )
|
|
||||||
{
|
|
||||||
printf ("Could not connect: %s\n", irc_strerror (irc_errno(s)));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
irc_run (s);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
void IRCThread::signalQuit() {
|
||||||
|
printf ("===> IRC: signalQuit [%p]\n",ircSession);
|
||||||
|
|
||||||
|
if(ircSession != NULL) {
|
||||||
|
callbackObj=NULL;
|
||||||
|
printf ("===> IRC: Quitting Channel\n");
|
||||||
|
irc_cmd_quit(ircSession, "MG Bot is closing!");
|
||||||
|
BaseThread::signalQuit();
|
||||||
|
isConnected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IRCThread::shutdownAndWait() {
|
||||||
|
printf ("===> IRC: shutdownAndWait [%p]\n",ircSession);
|
||||||
|
|
||||||
|
signalQuit();
|
||||||
|
BaseThread::shutdownAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRCThread::SendIRCCmdMessage(string target, string msg) {
|
||||||
|
if(ircSession != NULL && isConnected == true) {
|
||||||
|
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());
|
||||||
|
int ret = irc_cmd_msg (ircSession, target.c_str(), msg.c_str());
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<string> IRCThread::GetIRCConnectedNickList(string target) {
|
||||||
|
IRCThread::eventDataDone = false;
|
||||||
|
//IRCThread::eventData.clear();
|
||||||
|
if(ircSession != NULL && isConnected == true) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending IRC nick list command to [%s]\n",__FILE__,__FUNCTION__,__LINE__,target.c_str());
|
||||||
|
int ret = irc_cmd_names (ircSession, target.c_str());
|
||||||
|
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);
|
||||||
|
|
||||||
|
for(time_t tElapsed = time(NULL);
|
||||||
|
IRCThread::eventDataDone == false &&
|
||||||
|
this->getQuitStatus() == false &&
|
||||||
|
difftime(time(NULL),tElapsed) <= 5;) {
|
||||||
|
sleep(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return IRCThread::eventData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRCThread::execute() {
|
||||||
|
{
|
||||||
|
RunningStatusSafeWrapper runningStatus(this);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] argv.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,argv.size());
|
||||||
|
|
||||||
|
if(getQuitStatus() == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"IRC thread is running\n");
|
||||||
|
|
||||||
|
try {
|
||||||
|
irc_callbacks_t callbacks;
|
||||||
|
irc_ctx_t ctx;
|
||||||
|
ircSession=NULL;
|
||||||
|
|
||||||
|
if(argv.size() != 3) {
|
||||||
|
printf ("===> IRC Usage: <server> <nick> <channel> : got params [%ld]\n",argv.size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset (&callbacks, 0, sizeof(callbacks));
|
||||||
|
|
||||||
|
callbacks.event_connect = event_connect;
|
||||||
|
callbacks.event_join = event_join;
|
||||||
|
callbacks.event_nick = dump_event;
|
||||||
|
callbacks.event_quit = dump_event;
|
||||||
|
callbacks.event_part = event_leave;
|
||||||
|
callbacks.event_mode = dump_event;
|
||||||
|
callbacks.event_topic = dump_event;
|
||||||
|
callbacks.event_kick = dump_event;
|
||||||
|
callbacks.event_channel = event_channel;
|
||||||
|
callbacks.event_privmsg = event_privmsg;
|
||||||
|
callbacks.event_notice = dump_event;
|
||||||
|
callbacks.event_invite = dump_event;
|
||||||
|
callbacks.event_umode = dump_event;
|
||||||
|
callbacks.event_ctcp_rep = dump_event;
|
||||||
|
callbacks.event_ctcp_action = dump_event;
|
||||||
|
callbacks.event_unknown = dump_event;
|
||||||
|
callbacks.event_numeric = event_numeric;
|
||||||
|
|
||||||
|
callbacks.event_dcc_chat_req = irc_event_dcc_chat;
|
||||||
|
callbacks.event_dcc_send_req = irc_event_dcc_send;
|
||||||
|
|
||||||
|
if(this->getQuitStatus() == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ircSession = irc_create_session (&callbacks);
|
||||||
|
|
||||||
|
if(!ircSession) {
|
||||||
|
printf ("===> IRC Could not create session\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.channel = argv[2];
|
||||||
|
ctx.nick = argv[1];
|
||||||
|
|
||||||
|
if(this->getQuitStatus() == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
irc_set_ctx(ircSession, &ctx);
|
||||||
|
|
||||||
|
if(irc_connect(ircSession, argv[0].c_str(), 6667, 0, argv[1].c_str(), 0, 0)) {
|
||||||
|
printf ("===> IRC Could not connect: %s\n", irc_strerror (irc_errno(ircSession)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this->getQuitStatus() == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetIRCConnectedNickList(argv[2]);
|
||||||
|
|
||||||
|
if(this->getQuitStatus() == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int iAttempts=1;
|
||||||
|
this->getQuitStatus() == false && iAttempts <= 5;
|
||||||
|
++iAttempts) {
|
||||||
|
if(irc_run(ircSession)) {
|
||||||
|
printf ("===> IRC Could not run the session: %s\n", irc_strerror (irc_errno(ircSession)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf ("===> IRC exiting IRC CLient!\n");
|
||||||
|
}
|
||||||
|
catch(const exception &ex) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||||
|
}
|
||||||
|
catch(...) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] IRC thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
Reference in New Issue
Block a user