mirror of
https://github.com/glest/glest-source.git
synced 2025-08-10 10:24:01 +02:00
- attempt to avoid IRC client crashes on Internet menu if user does not have an Internet connection
This commit is contained in:
@@ -234,6 +234,8 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
|
|||||||
ircArgs.push_back(IRC_SERVER);
|
ircArgs.push_back(IRC_SERVER);
|
||||||
ircArgs.push_back(szIRCNick);
|
ircArgs.push_back(szIRCNick);
|
||||||
ircArgs.push_back(IRC_CHANNEL);
|
ircArgs.push_back(IRC_CHANNEL);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
|
||||||
ircClient = new IRCThread(ircArgs,this);
|
ircClient = new IRCThread(ircArgs,this);
|
||||||
ircClient->setUniqueID(__FILE__);
|
ircClient->setUniqueID(__FILE__);
|
||||||
ircClient->start();
|
ircClient->start();
|
||||||
@@ -255,12 +257,21 @@ void MenuStateMasterserver::setButtonLinePosition(int pos){
|
|||||||
listBoxAutoRefresh.setY(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] );
|
//printf ("===> IRC: '%s' said in channel %s: %s\n",origin ? origin : "someone",params[0], params[1] );
|
||||||
|
|
||||||
char szBuf[4096]="";
|
char szBuf[4096]="";
|
||||||
sprintf(szBuf,"%s: %s",origin ? origin : "someone",params[1]);
|
sprintf(szBuf,"%s: %s",origin ? origin : "someone",params[1]);
|
||||||
consoleIRC.addLine(szBuf);
|
consoleIRC.addLine(szBuf);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MenuStateMasterserver::cleanup() {
|
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__);
|
||||||
@@ -297,9 +308,11 @@ void MenuStateMasterserver::cleanup() {
|
|||||||
clearUserButtons();
|
clearUserButtons();
|
||||||
|
|
||||||
//printf("Exiting master server menu [%p]\n",ircClient);
|
//printf("Exiting master server menu [%p]\n",ircClient);
|
||||||
|
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
|
||||||
if(ircClient != NULL) {
|
if(ircClient != NULL) {
|
||||||
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__);
|
||||||
|
|
||||||
|
ircClient->setCallbackObj(NULL);
|
||||||
ircClient->signalQuit();
|
ircClient->signalQuit();
|
||||||
//if(ircClient->shutdownAndWait() == true) {
|
//if(ircClient->shutdownAndWait() == 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__);
|
||||||
@@ -526,6 +539,7 @@ void MenuStateMasterserver::render(){
|
|||||||
renderer.renderLabel(&externalConnectPort,&titleLabelColor);
|
renderer.renderLabel(&externalConnectPort,&titleLabelColor);
|
||||||
renderer.renderLabel(&selectButton,&titleLabelColor);
|
renderer.renderLabel(&selectButton,&titleLabelColor);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
|
||||||
if(ircClient != NULL &&
|
if(ircClient != NULL &&
|
||||||
ircClient->isConnected() == true &&
|
ircClient->isConnected() == true &&
|
||||||
ircClient->getHasJoinedChannel() == true) {
|
ircClient->getHasJoinedChannel() == true) {
|
||||||
@@ -536,6 +550,8 @@ void MenuStateMasterserver::render(){
|
|||||||
const Vec4f titleLabelColor = RED;
|
const Vec4f titleLabelColor = RED;
|
||||||
renderer.renderLabel(&ircOnlinePeopleLabel,&titleLabelColor);
|
renderer.renderLabel(&ircOnlinePeopleLabel,&titleLabelColor);
|
||||||
}
|
}
|
||||||
|
safeMutexIRCPtr.ReleaseLock();
|
||||||
|
|
||||||
const Vec4f titleLabelColorList = YELLOW;
|
const Vec4f titleLabelColorList = YELLOW;
|
||||||
|
|
||||||
for(int i=0; i<serverLines.size() && i<serverLinesToRender; ++i){
|
for(int i=0; i<serverLines.size() && i<serverLinesToRender; ++i){
|
||||||
@@ -591,7 +607,7 @@ void MenuStateMasterserver::update() {
|
|||||||
//console
|
//console
|
||||||
consoleIRC.update();
|
consoleIRC.update();
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
|
||||||
if(ircClient != NULL) {
|
if(ircClient != NULL) {
|
||||||
std::vector<string> nickList = ircClient->getNickList();
|
std::vector<string> nickList = ircClient->getNickList();
|
||||||
bool isNew=false;
|
bool isNew=false;
|
||||||
@@ -620,6 +636,7 @@ void MenuStateMasterserver::update() {
|
|||||||
oldNickList=nickList;
|
oldNickList=nickList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
safeMutexIRCPtr.ReleaseLock();
|
||||||
|
|
||||||
if(threadedErrorMsg != "") {
|
if(threadedErrorMsg != "") {
|
||||||
std::string sError = threadedErrorMsg;
|
std::string sError = threadedErrorMsg;
|
||||||
@@ -892,6 +909,7 @@ void MenuStateMasterserver::keyDown(char key) {
|
|||||||
|
|
||||||
if(chatManager.getEditEnabled() == true) {
|
if(chatManager.getEditEnabled() == true) {
|
||||||
//printf("keyDown key [%d] chatManager.getText() [%s]\n",key,chatManager.getText().c_str());
|
//printf("keyDown key [%d] chatManager.getText() [%s]\n",key,chatManager.getText().c_str());
|
||||||
|
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
|
||||||
if(key == vkReturn && ircClient != NULL) {
|
if(key == vkReturn && ircClient != NULL) {
|
||||||
ircClient->SendIRCCmdMessage(IRC_CHANNEL, chatManager.getText());
|
ircClient->SendIRCCmdMessage(IRC_CHANNEL, chatManager.getText());
|
||||||
}
|
}
|
||||||
|
@@ -98,6 +98,7 @@ private:
|
|||||||
bool masterServerThreadInDeletion;
|
bool masterServerThreadInDeletion;
|
||||||
|
|
||||||
std::vector<string> ircArgs;
|
std::vector<string> ircArgs;
|
||||||
|
Mutex mutexIRCClient;
|
||||||
IRCThread *ircClient;
|
IRCThread *ircClient;
|
||||||
std::vector<string> oldNickList;
|
std::vector<string> oldNickList;
|
||||||
|
|
||||||
@@ -121,8 +122,6 @@ public:
|
|||||||
|
|
||||||
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);
|
||||||
@@ -132,6 +131,7 @@ private:
|
|||||||
void clearUserButtons();
|
void clearUserButtons();
|
||||||
void updateServerInfo();
|
void updateServerInfo();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
virtual void IRC_CallbackEvent(IRCEventType evt, const char* origin, const char **params, unsigned int count);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -31,9 +31,14 @@ namespace Shared { namespace PlatformCommon {
|
|||||||
// class IRCThreadThread
|
// class IRCThreadThread
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
|
enum IRCEventType {
|
||||||
|
IRC_evt_chatText = 0,
|
||||||
|
IRC_evt_exitThread = 1
|
||||||
|
};
|
||||||
|
|
||||||
class IRCCallbackInterface {
|
class IRCCallbackInterface {
|
||||||
public:
|
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
|
class IRCThread : public BaseThread
|
||||||
@@ -51,6 +56,7 @@ protected:
|
|||||||
time_t lastNickListUpdate;
|
time_t lastNickListUpdate;
|
||||||
std::vector<string> eventData;
|
std::vector<string> eventData;
|
||||||
|
|
||||||
|
Mutex mutexIRCCB;
|
||||||
IRCCallbackInterface *callbackObj;
|
IRCCallbackInterface *callbackObj;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -84,7 +90,8 @@ public:
|
|||||||
std::vector<string> & getCachedNickList() { return eventData; }
|
std::vector<string> & getCachedNickList() { return eventData; }
|
||||||
void setCachedNickList(std::vector<string> &list) { eventData = list; }
|
void setCachedNickList(std::vector<string> &list) { eventData = list; }
|
||||||
|
|
||||||
IRCCallbackInterface * getCallbackObj() { return callbackObj;}
|
IRCCallbackInterface * getCallbackObj();
|
||||||
|
void setCallbackObj(IRCCallbackInterface *cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -192,7 +192,7 @@ void event_channel(irc_session_t * session, const char * event, const char * ori
|
|||||||
IRCThread *ctx = (IRCThread *)irc_get_ctx(session);
|
IRCThread *ctx = (IRCThread *)irc_get_ctx(session);
|
||||||
if(ctx != NULL) {
|
if(ctx != NULL) {
|
||||||
if(ctx->getCallbackObj() != 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;
|
return nickList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IRCCallbackInterface * IRCThread::getCallbackObj() {
|
||||||
|
MutexSafeWrapper safeMutex(&mutexIRCCB);
|
||||||
|
return callbackObj;
|
||||||
|
}
|
||||||
|
void IRCThread::setCallbackObj(IRCCallbackInterface *cb) {
|
||||||
|
MutexSafeWrapper safeMutex(&mutexIRCCB);
|
||||||
|
callbackObj=cb;
|
||||||
|
}
|
||||||
|
|
||||||
void IRCThread::execute() {
|
void IRCThread::execute() {
|
||||||
{
|
{
|
||||||
RunningStatusSafeWrapper runningStatus(this);
|
RunningStatusSafeWrapper runningStatus(this);
|
||||||
@@ -509,6 +518,9 @@ void IRCThread::execute() {
|
|||||||
|
|
||||||
// Delete ourself when the thread is done (no other actions can happen after this
|
// 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
|
// 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;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user