- attempt to avoid IRC client crashes on Internet menu if user does not have an Internet connection

This commit is contained in:
Mark Vejvoda
2010-12-29 21:03:57 +00:00
parent 4fb1b1092f
commit 2ca50ee9f9
4 changed files with 67 additions and 30 deletions

View File

@@ -234,6 +234,8 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
ircArgs.push_back(IRC_SERVER);
ircArgs.push_back(szIRCNick);
ircArgs.push_back(IRC_CHANNEL);
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
ircClient = new IRCThread(ircArgs,this);
ircClient->setUniqueID(__FILE__);
ircClient->start();
@@ -255,12 +257,21 @@ void MenuStateMasterserver::setButtonLinePosition(int pos){
listBoxAutoRefresh.setY(pos);
}
void MenuStateMasterserver::IRC_CallbackEvent(const char* origin, const char **params, unsigned int count) {
void MenuStateMasterserver::IRC_CallbackEvent(IRCEventType evt, const char* origin, const char **params, unsigned int count) {
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
if(ircClient != NULL) {
if(evt == IRC_evt_exitThread) {
ircClient = NULL;
}
else if(evt == IRC_evt_chatText) {
//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__);
@@ -297,9 +308,11 @@ void MenuStateMasterserver::cleanup() {
clearUserButtons();
//printf("Exiting master server menu [%p]\n",ircClient);
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
if(ircClient != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ircClient->setCallbackObj(NULL);
ircClient->signalQuit();
//if(ircClient->shutdownAndWait() == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -526,6 +539,7 @@ void MenuStateMasterserver::render(){
renderer.renderLabel(&externalConnectPort,&titleLabelColor);
renderer.renderLabel(&selectButton,&titleLabelColor);
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
if(ircClient != NULL &&
ircClient->isConnected() == true &&
ircClient->getHasJoinedChannel() == true) {
@@ -536,6 +550,8 @@ void MenuStateMasterserver::render(){
const Vec4f titleLabelColor = RED;
renderer.renderLabel(&ircOnlinePeopleLabel,&titleLabelColor);
}
safeMutexIRCPtr.ReleaseLock();
const Vec4f titleLabelColorList = YELLOW;
for(int i=0; i<serverLines.size() && i<serverLinesToRender; ++i){
@@ -591,7 +607,7 @@ void MenuStateMasterserver::update() {
//console
consoleIRC.update();
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
if(ircClient != NULL) {
std::vector<string> nickList = ircClient->getNickList();
bool isNew=false;
@@ -620,6 +636,7 @@ void MenuStateMasterserver::update() {
oldNickList=nickList;
}
}
safeMutexIRCPtr.ReleaseLock();
if(threadedErrorMsg != "") {
std::string sError = threadedErrorMsg;
@@ -892,6 +909,7 @@ void MenuStateMasterserver::keyDown(char key) {
if(chatManager.getEditEnabled() == true) {
//printf("keyDown key [%d] chatManager.getText() [%s]\n",key,chatManager.getText().c_str());
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
if(key == vkReturn && ircClient != NULL) {
ircClient->SendIRCCmdMessage(IRC_CHANNEL, chatManager.getText());
}

View File

@@ -98,6 +98,7 @@ private:
bool masterServerThreadInDeletion;
std::vector<string> ircArgs;
Mutex mutexIRCClient;
IRCThread *ircClient;
std::vector<string> oldNickList;
@@ -121,8 +122,6 @@ public:
static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; }
virtual void IRC_CallbackEvent(const char* origin, const char **params, unsigned int count);
private:
void showMessageBox(const string &text, const string &header, bool toggle);
bool connectToServer(string ipString, int port);
@@ -132,6 +131,7 @@ private:
void clearUserButtons();
void updateServerInfo();
void cleanup();
virtual void IRC_CallbackEvent(IRCEventType evt, const char* origin, const char **params, unsigned int count);
};

View File

@@ -31,9 +31,14 @@ namespace Shared { namespace PlatformCommon {
// class IRCThreadThread
// =====================================================
enum IRCEventType {
IRC_evt_chatText = 0,
IRC_evt_exitThread = 1
};
class IRCCallbackInterface {
public:
virtual void IRC_CallbackEvent(const char* origin, const char **params, unsigned int count) = 0;
virtual void IRC_CallbackEvent(IRCEventType evt, const char* origin, const char **params, unsigned int count) = 0;
};
class IRCThread : public BaseThread
@@ -51,6 +56,7 @@ protected:
time_t lastNickListUpdate;
std::vector<string> eventData;
Mutex mutexIRCCB;
IRCCallbackInterface *callbackObj;
public:
@@ -84,7 +90,8 @@ public:
std::vector<string> & getCachedNickList() { return eventData; }
void setCachedNickList(std::vector<string> &list) { eventData = list; }
IRCCallbackInterface * getCallbackObj() { return callbackObj;}
IRCCallbackInterface * getCallbackObj();
void setCallbackObj(IRCCallbackInterface *cb);
};
}}//end namespace

View File

@@ -192,7 +192,7 @@ void event_channel(irc_session_t * session, const char * event, const char * ori
IRCThread *ctx = (IRCThread *)irc_get_ctx(session);
if(ctx != NULL) {
if(ctx->getCallbackObj() != NULL) {
ctx->getCallbackObj()->IRC_CallbackEvent(nickbuf, params, count);
ctx->getCallbackObj()->IRC_CallbackEvent(IRC_evt_chatText, nickbuf, params, count);
}
}
@@ -411,6 +411,15 @@ std::vector<string> IRCThread::getNickList() {
return nickList;
}
IRCCallbackInterface * IRCThread::getCallbackObj() {
MutexSafeWrapper safeMutex(&mutexIRCCB);
return callbackObj;
}
void IRCThread::setCallbackObj(IRCCallbackInterface *cb) {
MutexSafeWrapper safeMutex(&mutexIRCCB);
callbackObj=cb;
}
void IRCThread::execute() {
{
RunningStatusSafeWrapper runningStatus(this);
@@ -509,6 +518,9 @@ void IRCThread::execute() {
// Delete ourself when the thread is done (no other actions can happen after this
// such as the mutex which modifies the running status of this method
if(getCallbackObj() != NULL) {
getCallbackObj()->IRC_CallbackEvent(IRC_evt_exitThread, NULL, NULL, 0);
}
delete this;
}