/*! * \param newCodec Text codec * * Changes text encoding to a different codec.\n * For example, UTF-8 */ void ICommand::charset(QString newCodec) { QList<QByteArray> codecList = QTextCodec::availableCodecs(); bool exist = false; QByteArray codec; codec.append(newCodec); for (int i = 0; i <= codecList.length()-1; i++) { QString item = codecList[i]; if (item.toUpper() == newCodec.toUpper()) { newCodec = item.toUpper(); exist = true; break; } } if (! exist) { localMsg( tr("/Charset: Encoding '%1' doesn't exsist.") .arg(newCodec) ); } else { localMsg( tr("/Charset: Set encoding to '%1'") .arg(newCodec) ); conf->charset = newCodec; } }
bool MsgCatalogLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad , XMLCh* const toFill , const unsigned int maxChars , const char* const repText1 , const char* const repText2 , const char* const repText3 , const char* const repText4 , MemoryManager * const manager) { char * msgId; int size=0; char* repTexts = PackingRepText(repText1, repText2, repText3, repText4, size); if (XMLString::equals(fMsgDomain, XMLUni::fgXMLErrDomain)) { if(msgToLoad < 7) msgId = Warnings[msgToLoad - 2]; else msgId = Errors[msgToLoad - 9]; } else if (XMLString::equals(fMsgDomain, XMLUni::fgExceptDomain)) msgId = Exceptions[msgToLoad - 2]; else if (XMLString::equals(fMsgDomain, XMLUni::fgValidityDomain)) msgId = Invalid[msgToLoad - 2]; else if (XMLString::equals(fMsgDomain, XMLUni::fgXMLDOMMsgDomain)) msgId = DOMMsg[msgToLoad - 2]; // Call the other version to load up the message // note that no one is deleting repTexts... if (!localMsg(msgId, toFill, maxChars, repTexts, size)) return false; return true; }
bool MsgCatalogLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad , XMLCh* const toFill , const unsigned int maxChars) { char * msgId; char * repTexts = NULL; int size = 0; if (XMLString::equals(fMsgDomain, XMLUni::fgXMLErrDomain)) { if(msgToLoad < 7) // Warning messages msgId = Warnings[msgToLoad - 2]; else // Fatal Errors msgId = Errors[msgToLoad - 9]; } else if (XMLString::equals(fMsgDomain, XMLUni::fgExceptDomain)) msgId = Exceptions[msgToLoad - 2]; else if (XMLString::equals(fMsgDomain, XMLUni::fgValidityDomain)) msgId = Invalid[msgToLoad - 2]; else if (XMLString::equals(fMsgDomain, XMLUni::fgXMLDOMMsgDomain)) msgId = DOMMsg[msgToLoad - 2]; if (!localMsg(msgId, toFill, maxChars, repTexts, size)) return false; return true; }
/*! * \param channel Target channel * \param nickname Target nickname * * This command utilizes IAL to set a ban on the given member.\n * IAL sees if it got the hostname on the given nickname, if not, it will obtain it and set the ban. */ void ICommand::ban(QString channel, QString nickname) { if (channel.isEmpty()) { subwindow_t wt = getCurrentSubwin(); if (wt.type != WT_CHANNEL) { localMsg(NotInAChannel("/Ban")); return; } channel = wt.widget->getTarget(); } connection->ial.setChannelBan(channel, nickname); }
/* Method called from handleRecv() of client/server to interpret what action needs to be called for this message. */ char commonInterface::checkMessage(char *msg) { char retVal = (char)0; if(!msg || (strlen(msg) == 0)) return retVal; string localMsg(msg); char *command = NULL; command = strtok(const_cast<char*>(localMsg.c_str()), ":"); if(strcmp(command, "REGISTER") == 0) { return REGISTER; } else if(strcmp(command, "CONNECT") == 0) { return CONNECT; } else if(strcmp(command, "TERMINATE") == 0) { return TERMINATE; } else if(strcmp(command, "EXIT") == 0) { return EXIT; } else if(strcmp(command, "UPLOAD") == 0) { return UPLOAD; } else if(strcmp(command, "DOWNLOAD") == 0) { return DOWNLOAD; } else if(strcmp(command, "STATS") == 0) //For handling the Stats messages from server { return SENDSTATS; } else { //Invalid case. Return error; return retVal; } }
/* Utility method to split the string "msg" based on the delimiter specified by the "delimited". It returns the vector<string> of the tokens. */ vector<string> commonInterface::splitMessage(const char *msg, char delimiter) { vector<string> message; message.clear(); if(!msg || (strlen(msg)<=0)) return message; //Create a local copy of the msg string localMsg(msg); /*char *tokens = strtok(const_cast<char *>(localMsg.c_str()), &delimiter); while (tokens != NULL) { message.push_back(tokens); tokens = strtok (NULL, &delimiter); }*/ string token = ""; for(int i=0;i<localMsg.length();i++) { if(localMsg[i] == delimiter) { message.push_back(token); token = ""; } else { token = token+localMsg[i]; } } if(token.length() > 0) { message.push_back(token); } return message; }
/*! * \param command A command to parse, for example "/join #channel key" * * \return true when command was found, false otherwise.\n Note that, even if a command fails to execute, true is still returned. */ bool ICommand::parse(QString command) { /* This function must return true if the command was found, even if the command resulted in an error! ONLY return false if the command was not found. */ if (command[0] == '/') command = command.mid(1); QStringList token = command.split(' '); QString t1 = token[0].toUpper(); if (t1 == "JOIN") { if (! connection->isOnline()) { localMsg(NotConnectedToServer("/Join")); return true; } if (token.count() == 1) { localMsg(InsufficientParameters("/Join")); return true; } if (token.count() == 2) { join(token.at(1)); return true; } QString pass = command.mid(t1.length() + token.at(1).length() + 2); join(token.at(1), pass); return true; } if (t1 == "PART") { if (! connection->isOnline()) { localMsg(NotConnectedToServer("/Part")); return true; } if (token.count() == 1) { localMsg(InsufficientParameters("/Part")); return true; } if (token.count() == 2) { part(token.at(1)); return true; } QString reason = command.mid(t1.length() + token[1].length() + 2); part(token.at(1), reason); return true; } if (t1 == "QUIT") { QString reason; reason = command.mid(5); quit(reason); } if (t1 == "NOTICE") { if (! connection->isOnline()) { localMsg(NotConnectedToServer("/Notice")); return true; } if (token.count() < 3) { localMsg(InsufficientParameters("/Notice")); return true; } QString text = command.mid(token[1].length()+8); notice(token[1], text); return true; } if (t1 == "MSG") { if (! connection->isOnline()) { localMsg(NotConnectedToServer("/Msg")); return true; } if (token.count() < 3) { localMsg(InsufficientParameters("/Msg")); return true; } QString text = command.mid(token[1].length()+5); msg(token[1], text); return true; } if (t1 == "ME") { if (! connection->isOnline()) { localMsg(NotConnectedToServer("/Me")); return true; } subwindow_t wt = winlist->value(activewin()); if ((wt.type != WT_CHANNEL) && (wt.type != WT_PRIVMSG)) { localMsg(tr("You're not in a chat window!")); return true; } QString target = wt.widget->getTarget(); me(target, command.mid(3)); return true; } if (t1 == "CTCP") { if (! connection->isOnline()) { localMsg(NotConnectedToServer("/Ctcp")); return true; } if (token.count() < 3) { localMsg(InsufficientParameters("/Ctcp")); return true; } // /ctcp target msg param param param ... int skip = 0; for (int i = 0; i <= 1; ++i) skip += token[i].length() + 1; QString msg = command.mid(skip).toUpper(); if (msg == "PING") { QString ms = QString::number( QDateTime::currentMSecsSinceEpoch() ); msg += ' '; msg += ms; } ctcp(token[1], msg); return true; } if (t1 == "KICK") { // kick #chan nick [reason] if (token.count() < 2) { localMsg(InsufficientParameters("/Kick")); return true; } QString channel = token[1]; QString nickname; int l = 5; if (! connection->isValidChannel(channel)) { channel.clear(); nickname = token[1]; l += nickname.length() + 1; } else { nickname = token[2]; l += nickname.length() + channel.length() + 2; } QString reason = command.mid(l); kick(channel, nickname, reason); return true; } if (t1 == "KILL") { if (token.count() < 2) { localMsg(InsufficientParameters("/Kill")); return true; } QString nickname = token[1]; QString reason = command.mid(nickname.length() + 5); kill(nickname, reason); return true; } if (t1 == "BAN") { if (token.count() < 2) { localMsg(InsufficientParameters("/Ban")); return true; } QString channel = token[1]; QString nickname; if (token.count() == 2) { channel.clear(); nickname = token[1]; } else nickname = token[2]; ban(channel, nickname); return true; } if ((t1 == "RAW") || (t1 == "QUOTE")) { if (! connection->isOnline()) { localMsg( tr("/%1: Not connected to server.") .arg(t1) ); return true; } if (token.count() < 2) { localMsg( tr("/%1: Insufficient parameters.") .arg(t1) ); return true; } QString c = command.mid(t1.length()+1); raw(c); return true; } if (t1 == "CHARSET") { if (token.count() < 2) { localMsg( tr("/Charset: Current set is '%1'") .arg(conf->charset)); return true; } charset(token[1]); return true; } if (t1 == "CLEAR") { if (token.count() == 1) { // clear active window } subwindow_t sw = getCurrentSubwin(); if (sw.type == WT_NOTHING) return true; sw.widget->clear(); return true; } if (t1 == "PING") { if (! connection->isOnline()) { localMsg(NotConnectedToServer("/Ping")); return true; } ping(); return true; } if (t1 == "QUERY") { if (token.count() < 2) { localMsg(InsufficientParameters("/Query")); return true; } query(token[1]); return true; } if (t1 == "CHANSETTINGS") { chansettings(); return true; } return false; // Command wasn't found. }