- bugfix for IRC nicks using non standard ascii chars (we replace invalid chars on IRC with -

This commit is contained in:
Mark Vejvoda
2011-08-30 23:45:51 +00:00
parent 3eb375904c
commit 1a6cdf3a06
3 changed files with 51 additions and 0 deletions

View File

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

View File

@@ -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;

View File

@@ -555,4 +555,51 @@ void IRCThread::execute() {
delete this;
}
void normalizeNick(char *nick) {
// http://tools.ietf.org/html/rfc1459#section-2.3.1
// <target> ::= <to> [ "," <target> ]
// <to> ::= <channel> | <user> '@' <servername> | <nick> | <mask>
// <channel> ::= ('#' | '&') <chstring>
// <servername> ::= <host>
// <host> ::= see RFC 952 [DNS:4] for details on allowed hostnames
// <nick> ::= <letter> { <letter> | <number> | <special> }
// <mask> ::= ('#' | '$') <chstring>
// <chstring> ::= <any 8bit code except SPACE, BELL, NUL, CR, LF and
// comma (',')>
//
// Other parameter syntaxes are:
//
// <user> ::= <nonwhite> { <nonwhite> }
// <letter> ::= 'a' ... 'z' | 'A' ... 'Z'
// <number> ::= '0' ... '9'
// <special> ::= '-' | '[' | ']' | '\' | '`' | '^' | '{' | '}'
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