void Serveur::readServeur() { QString message=QString::fromUtf8(this->readAll()); QString currentChan=tab->tabText(tab->currentIndex()); if(message.startsWith("PING :")) { QStringList liste=message.split(" "); QString msg="PONG "+liste.at(1); sendData(msg); } else if(message.contains("Nickname is already in use.")) { pseudo=pseudo+"_2"; pseudo.remove("\r\n"); sendData("NICK "+pseudo); emit pseudoChanged(pseudo); ecrire("-> Name changed to "+pseudo); } else if(updateUsers==true) { updateUsersList("",message); } QStringList list=message.split("\r\n"); foreach(QString msg,list) { if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <b><\\1></b> \\3"),"",msg2.replace(reg,"\\2 <\\1> \\3")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <i>-> \\1 join \\2</i><br />"),"",msg2.replace(reg,"-> \\1 join \\2")); updateUsersList(msg.replace(reg,"\\2")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+) :(.+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <i>-> \\1 quit \\2 (\\3)</i><br />"),"",msg2.replace(reg,"-> \\1 quit \\2")); updateUsersList(msg.replace(reg,"\\2")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <i>-> \\1 quit this server (\\2)</i><br />"),"",msg2.replace(reg,"-> \\1 left")); updateUsersList(msg.replace(reg,"\\2")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"); QString msg2=msg; ecrire(msg.replace(reg,"<i>\\1 is now called \\2</i><br />"),"",msg2.replace(reg,"-> \\1 is now called \\2")); updateUsersList(currentChan); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\!~[a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <i>-> \\1 kicked \\3 (\\4)</i><br />"),"",msg2.replace(reg,"-> \\1 quit \\3")); updateUsersList(msg.replace(reg,"\\2")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE ([a-zA-Z0-9]+) :(.+)"))) { if(conversations.contains(currentChan)) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); ecrire(msg.replace(reg,"<b>[NOTICE] <i>\\1</i> : \\2 <br />"),currentChan); } else if(currentChan==serveur) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); ecrire(msg.replace(reg,"<b>[NOTICE] <i>\\1</i> : \\2 <br />")); } } else if(msg.contains("/MOTD command.")) { joins(); } } //} }
void UsersWindow::shown() { updateLearningButtons(); ui->scrollPane->SetSelectedIndex(-1); updateUsersList(); }
void IRCServer::ProcessLine(QString line, QString channel) { QStringList validCommands; QRegExp linematch; QRegExp actionmatch; linematch.setPattern("^(:?([A-Za-z0-9_\\-\\\\\\[\\]{}^`|.]+)?!?(\\S+)? )?([A-Z0-9]+) ?([A-Za-z0-9_\\-\\\\\\[\\]{}^`|.*#]+)?( [@=] ([#&][^\\x07\\x2C\\s]{0,200}))?([ :]+)?([\\S ]+)?$"); validCommands << "353" << "376" << "JOIN" << "KICK" << "MODE"; validCommands << "NICK" << "NOTICE" << "PART" << "PING" << "PRIVMSG"; validCommands << "QUIT" << "TOPIC" << "372" << "432" << "433"; validCommands << "332"; actionmatch.setPattern("\\001ACTION(.+)\\001"); linematch.isMinimal(); actionmatch.isMinimal(); int pos = linematch.indexIn(line); if (pos > -1) { writeToLog("[RCV] " + line); QStringList list; QStringList splitted; QString sender = linematch.cap(2); QString userhost = linematch.cap(3); QString command = linematch.cap(4); QString receiver = linematch.cap(5); QString destination = linematch.cap(7); QString content = linematch.cap(9); QString response; QString username; QString reason; QString channel; QString topic; switch (validCommands.indexOf(command)) { case 0: // 353 (Names) if (delist == true) users.clear(); list = content.split(" "); for (int i = 0; i < list.count(); i++) { users.append(list.at(i)); } if (list.count() < 53) delist = true; else delist = false; updateUserModel(); break; case 1: // 376 (End of MOTD) joinChannel(); break; case 2: // JOIN response = GUIUtil::HtmlEscape("Join: " + sender + " (" + userhost + ")"); addUser(sender); writeToUI(response, receiver); break; case 3: // KICK splitted = content.split(" :"); username = splitted.at(0); reason = splitted.at(1); removeUser(username); response = GUIUtil::HtmlEscape(sender + " kicked " + username + ". Reason: " + reason); writeToUI(response, receiver); break; case 4: // MODE response = GUIUtil::HtmlEscape(sender + " sets mode: " + content); if (receiver.startsWith("#")) { updateUsersList(receiver); writeToUI(response, receiver); } else { writeToUI(response); } break; case 5: // NICK response = GUIUtil::HtmlEscape(sender + " is now known as `" + content); removeUser(sender); addUser(content); writeToUI(response); break; case 6: // NOTICE writeToUI(GUIUtil::HtmlEscape(content)); break; case 7: // PART response = GUIUtil::HtmlEscape("Parts: " + sender + " (" + userhost + ")"); removeUser(sender); writeToUI(response, receiver); break; case 8: // PING response = "PONG " + content; sendData(response); break; case 9: // PRIVMSG int posact; posact = actionmatch.indexIn(content); if (posact > -1) { QString actionmsg = actionmatch.cap(1); response = GUIUtil::HtmlEscape(sender + " " + actionmsg.trimmed()); } else { if (receiver == nickname) { response = GUIUtil::HtmlEscape(sender + " -> you: " + content); } else { response = GUIUtil::HtmlEscape("<" + sender + "> " + content); } } if (receiver.startsWith("#") || receiver == nickname) { writeToUI(response, receiver); } else { writeToUI(response); } break; case 10: // QUIT response = GUIUtil::HtmlEscape("Quit: " + sender + " (" + userhost + ")"); removeUser(sender); writeToUI(response); break; case 11: // TOPIC response = GUIUtil::HtmlEscape(sender + " changes topic to '" + content + "'"); writeToUI(response, receiver); break; case 12: // 372 (MOTD) writeToUI(GUIUtil::HtmlEscape(content)); break; case 13: // 432 (Invalid nickname) response = "ERROR: " + content; writeToUI(GUIUtil::HtmlEscape(response)); break; case 14: // 433 (Nick already in use) response = "Nickname is already in use, please choose another. Type /nick YOURNEWNAME"; writeToUI(GUIUtil::HtmlEscape(response)); break; case 15: // 332 (Topic on join) splitted = content.split(" :"); channel = splitted.at(0); topic = splitted.at(1); response = GUIUtil::HtmlEscape("Topic for " + channel + " is '" + topic + "'"); writeToUI(response, channel); break; default: // Do nothing break; } } else { writeToLog("[ERR] " + line); } }
void Serveur::readServeur() { QString message=QString::fromUtf8(this->readAll()); QString currentChan=tab->tabText(tab->currentIndex()); if(message.startsWith("PING :")) { QStringList liste=message.split(" "); QString msg="PONG "+liste.at(1); sendData(msg); } else if(message.contains("Nickname is already in use.")) { pseudo=pseudo+"_2"; pseudo.remove("\r\n"); sendData("NICK "+pseudo); emit pseudoChanged(pseudo); ecrire("-> Name changed to "+pseudo); } else if(updateUsers==true) { updateUsersList("",message); } QStringList list=message.split("\r\n"); foreach(QString msg,list) { if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <b><\\1></b> \\3"),"",msg2.replace(reg,"\\2 <\\1> \\3")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <i>-> \\1 join \\2</i><br />"),"",msg2.replace(reg,"-> \\1 join \\2")); updateUsersList(msg.replace(reg,"\\2")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+) :(.+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <i>-> \\1 quit \\2 (\\3)</i><br />"),"",msg2.replace(reg,"-> \\1 quit \\2")); updateUsersList(msg.replace(reg,"\\2")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <i>-> \\1 quit this server (\\2)</i><br />"),"",msg2.replace(reg,"-> \\1 left")); updateUsersList(msg.replace(reg,"\\2")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"); QString msg2=msg; ecrire(msg.replace(reg,"<i>\\1 is now called \\2</i><br />"),"",msg2.replace(reg,"-> \\1 is now called \\2")); updateUsersList(currentChan); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"))) { QRegExp reg(":([a-zA-Z0-9]+)\\!~[a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"); QString msg2=msg; ecrire(msg.replace(reg,"\\2 <i>-> \\1 kicked \\3 (\\4)</i><br />"),"",msg2.replace(reg,"-> \\1 quit \\3")); updateUsersList(msg.replace(reg,"\\2")); } else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE ([a-zA-Z0-9]+) :(.+)"))) { if(conversations.contains(currentChan)) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); ecrire(msg.replace(reg,"<b>[NOTICE] <i>\\1</i> : \\2 <br />"),currentChan); } else if(currentChan==serveur) { QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); ecrire(msg.replace(reg,"<b>[NOTICE] <i>\\1</i> : \\2 <br />")); } } else if(msg.contains("/MOTD command.")) { joins(); } else if(msg.contains(QRegExp("= ([a-zA-Z0-9\\#]+) :"))) { QStringList msg3 = msg.split("= "); QStringList msg4 = msg3[1].split(" :"); updateUsersList(msg4[0],msg); } else { QString trimmedMsg = msg.trimmed(); QStringList splitMsg = trimmedMsg.split(" "); if((splitMsg.size() > 7 && (splitMsg.at(3)+splitMsg.at(4)+splitMsg.at(5)+splitMsg.at(6)+splitMsg.at(7)).toStdString() == "#dopecoin:Endof/NAMESlist.") || (splitMsg.size() > 7 && (splitMsg.at(3)+splitMsg.at(4)+splitMsg.at(5)+splitMsg.at(6)+splitMsg.at(7)).toStdString() == "#dopecoin:Endof/WHOlist.") || (splitMsg.size() > 1 && splitMsg.at(0).toStdString() == "PING")) return; ecrire(trimmedMsg, QString::fromStdString("Console/PM")); } } }