From 1a6cdf3a0685b2b81504dab463974ce679597332 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 30 Aug 2011 23:45:51 +0000 Subject: [PATCH] - bugfix for IRC nicks using non standard ascii chars (we replace invalid chars on IRC with - --- .../menu/menu_state_masterserver.cpp | 2 + .../include/platform/posix/ircclient.h | 2 + .../sources/platform/posix/ircclient.cpp | 47 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index 8e1a11f36..023127325 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -253,6 +253,8 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen string netPlayerName=Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()); string ircname=netPlayerName.substr(0,9); sprintf(szIRCNick,"MG_%s_%d",ircname.c_str(),randomNickId); + normalizeNick(szIRCNick); + currentIrcNick=ircname; consoleIRC.setStringToHighlight(currentIrcNick); diff --git a/source/shared_lib/include/platform/posix/ircclient.h b/source/shared_lib/include/platform/posix/ircclient.h index 2baccd6a8..bd9c4ab0a 100644 --- a/source/shared_lib/include/platform/posix/ircclient.h +++ b/source/shared_lib/include/platform/posix/ircclient.h @@ -36,6 +36,8 @@ enum IRCEventType { IRC_evt_exitThread = 1 }; +void normalizeNick(char *nick); + class IRCCallbackInterface { public: virtual void IRC_CallbackEvent(IRCEventType evt, const char* origin, const char **params, unsigned int count) = 0; diff --git a/source/shared_lib/sources/platform/posix/ircclient.cpp b/source/shared_lib/sources/platform/posix/ircclient.cpp index 366929b8d..1971e478a 100644 --- a/source/shared_lib/sources/platform/posix/ircclient.cpp +++ b/source/shared_lib/sources/platform/posix/ircclient.cpp @@ -555,4 +555,51 @@ void IRCThread::execute() { delete this; } +void normalizeNick(char *nick) { + // http://tools.ietf.org/html/rfc1459#section-2.3.1 +// ::= [ "," ] +// ::= | '@' | | +// ::= ('#' | '&') +// ::= +// ::= see RFC 952 [DNS:4] for details on allowed hostnames +// ::= { | | } +// ::= ('#' | '$') +// ::= +// +// Other parameter syntaxes are: +// +// ::= { } +// ::= 'a' ... 'z' | 'A' ... 'Z' +// ::= '0' ... '9' +// ::= '-' | '[' | ']' | '\' | '`' | '^' | '{' | '}' + + if(nick != NULL && strlen(nick) > 0) { + char *newNick = new char[strlen(nick)+1]; + memset(newNick,0,strlen(nick)+1); + bool nickChanged = false; + + for(int i = 0; i < strlen(nick); ++i) { + if(nick[i] == '-' || nick[i] == '[' || nick[i] == ']' || nick[i] == '_' || + nick[i] == '\\' || nick[i] == '`' || nick[i] == '^' || + nick[i] == '{' || nick[i] == '}' || + (nick[i] >= '0' && nick[i] <= '9') || + (nick[i] >= 'a' && nick[i] <= 'z') || + (nick[i] >= 'A' && nick[i] <= 'Z')) { + strncat(newNick,&nick[i],1); + } + else { + strcat(newNick,"-"); + nickChanged = true; + } + } + + if(nickChanged == true) { + strcpy(nick,newNick); + } + + delete [] newNick; + } +} + }}//end namespace