Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ircsession.cpp

Go to the documentation of this file.
00001 
00002 #include "ircsession.h"
00003 #include "ircmessageparser.h"
00004 #include "ircchannelperson.h"
00005 #include "ircversion.h"
00006 
00007 IRCSession::IRCSession(QObject *parent, IRCServer *server)
00008     : QObject(parent)
00009 {
00010     m_server = server;
00011     m_connection = new IRCConnection(m_server);
00012     m_parser     = new IRCMessageParser(this);
00013     connect(m_connection, SIGNAL(messageArrived(IRCMessage*)), this, SLOT(handleMessage(IRCMessage*)));
00014     connect(m_parser, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
00015     connect(m_connection, SIGNAL(outputReady(IRCOutput)), this, SIGNAL(outputReady(IRCOutput)));
00016 }
00017 
00018 IRCSession::~IRCSession() {
00019     /* We want this to get deleted automatically */
00020     m_channels.setAutoDelete(TRUE);
00021     m_people.setAutoDelete(TRUE);
00022         
00023     delete m_parser;
00024     delete m_connection;
00025 }
00026 
00027 void IRCSession::beginSession() {
00028     m_connection->doConnect();
00029 }
00030 
00031 void IRCSession::join(QString channelname) {
00032     m_connection->sendLine("JOIN " + channelname);
00033 }
00034 
00035 void IRCSession::quit(){
00036     m_connection->sendLine("QUIT :[OI] I'm too good to need a reason");
00037 }
00038 
00039 void IRCSession::quit(QString message){
00040     m_connection->sendLine("QUIT :" + message);
00041 }
00042 
00043 void IRCSession::topic(IRCChannel *channel, QString message){
00044     m_connection->sendLine("TOPIC :" + channel->channelname() + " " + message);
00045 }
00046 
00047 void IRCSession::mode(IRCChannel *channel, QString message){
00048     m_connection->sendLine("MODE " + channel->channelname() + " " + message);
00049 }
00050 
00051 void IRCSession::mode(IRCPerson *person, QString message){
00052     m_connection->sendLine("MODE " + person->nick() + " " + message);
00053 }
00054 
00055 void IRCSession::mode(QString message){
00056     m_connection->sendLine("MODE " + message);
00057 }
00058 
00059 void IRCSession::raw(QString message){
00060     m_connection->sendLine(message);
00061 }
00062 
00063 void IRCSession::kick(IRCChannel *channel, IRCPerson *person) {
00064     m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :0wn3d - no reason");
00065 }
00066 
00067 void IRCSession::op(IRCChannel *channel, IRCPerson *person) {
00068     m_connection->sendLine("MODE " + channel->channelname() + " +ooo " + person->nick());
00069 }
00070 
00071 void IRCSession::kick(IRCChannel *channel, IRCPerson *person, QString message) {
00072     m_connection->sendLine("KICK " + channel->channelname() + " " + person->nick() +" :" + message);
00073 } 
00074 
00075 void IRCSession::sendMessage(IRCPerson *person, QString message) {
00076     m_connection->sendLine("PRIVMSG " + person->nick() + " :" + message);
00077 }
00078 
00079 void IRCSession::sendMessage(IRCChannel *channel, QString message) {
00080     m_connection->sendLine("PRIVMSG " + channel->channelname() + " :" + message);
00081 }
00082 
00083 void IRCSession::sendAction(IRCChannel *channel, QString message) {
00084     m_connection->sendLine("PRIVMSG " + channel->channelname() + " :\001ACTION " + message + "\001");
00085 }
00086 
00087 void IRCSession::sendAction(IRCPerson *person, QString message) {
00088     m_connection->sendLine("PRIVMSG " + person->nick() + " :\001ACTION " + message + "\001");
00089 }
00090 
00091 bool IRCSession::isSessionActive() {
00092     return m_connection->isConnected(); 
00093 }
00094 
00095 bool IRCSession::isLoggedIn() {
00096     return m_connection->isLoggedIn();
00097 }
00098 
00099 void IRCSession::endSession() {
00100     if (m_connection->isLoggedIn())
00101         quit(APP_VERSION);
00102     else
00103         m_connection->close();
00104 }
00105 
00106 void IRCSession::part(IRCChannel *channel) {
00107     m_connection->sendLine("PART " + channel->channelname() + " :" + APP_VERSION);
00108 }
00109 
00110 void IRCSession::setValidUsermodes(const QString &modes) {
00111     m_validUsermodes = modes;
00112 }
00113 
00114 void IRCSession::setValidChannelmodes(const QString &modes) {
00115     m_validChannelmodes = modes;
00116 }
00117 
00118 void IRCSession::updateNickname(const QString &oldNickname, const QString &newNickname) {
00119     QList<IRCChannel> channels;
00120     IRCOutput output;
00121     
00122     if (oldNickname == m_server->nick()) {
00123         m_server->setNick(newNickname);
00124         output = IRCOutput(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg(newNickname));
00125         channels = m_channels;
00126     }
00127 
00128     else {
00129         IRCPerson *person = getPerson(oldNickname);
00130         
00131         if(!person) {
00132             emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
00133             return;
00134         }
00135         
00136         getChannelsByPerson(person, channels);
00137         output = IRCOutput(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg(oldNickname).arg(newNickname));
00138     }
00139 
00140     QListIterator<IRCChannel> it(channels);
00141     for (;it.current(); ++it) {
00142         IRCChannelPerson *chanperson = it.current()->getPerson(oldNickname);
00143         it.current()->removePerson(chanperson);
00144         chanperson->setNick(newNickname);
00145         it.current()->addPerson(chanperson);
00146     }
00147 
00148     emit updateChannels();
00149     output.addParam(new QString(newNickname));
00150     emit outputReady(output);
00151 }
00152 
00153 IRCChannel *IRCSession::getChannel(QString channelname) {
00154     QListIterator<IRCChannel> it(m_channels);
00155     for (; it.current(); ++it) {
00156         if (it.current()->channelname() == channelname) {
00157             return it.current();
00158         }
00159     }
00160     return 0;
00161 }
00162 
00163 IRCPerson *IRCSession::getPerson(QString nickname) {
00164     QListIterator<IRCPerson> it(m_people);
00165     for (; it.current(); ++it) {
00166         if (it.current()->nick() == nickname) {
00167             return it.current();
00168         }
00169     }
00170     return 0;
00171 }
00172 
00173 void IRCSession::getChannelsByPerson(IRCPerson *person, QList<IRCChannel> &channels) {
00174     QListIterator<IRCChannel> it(m_channels);
00175     for (; it.current(); ++it) {
00176         if (it.current()->getPerson(person->nick()) != 0) {
00177             channels.append(it.current());
00178         }
00179     }
00180 }
00181 
00182 void IRCSession::addPerson(IRCPerson *person) {
00183     m_people.append(person);
00184 }
00185 
00186 void IRCSession::addChannel(IRCChannel *channel) {
00187     m_channels.append(channel);
00188 }
00189 
00190 void IRCSession::removeChannel(IRCChannel *channel) {
00191     m_channels.remove(channel);
00192 }
00193 
00194 void IRCSession::removePerson(IRCPerson *person) {
00195     m_people.remove(person);
00196 }
00197 
00198 void IRCSession::handleMessage(IRCMessage *message) {
00199     m_parser->parse(message);
00200 }
00201 
00202 void IRCSession::whois(const QString &nickname) {
00203     m_connection->whois(nickname);
00204 }
00205 
00206 void IRCSession::sendCTCPPing(const QString &nickname) {
00207     m_connection->sendCTCPPing(nickname);
00208 }
00209 
00210 void IRCSession::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
00211     m_connection->sendCTCPRequest(nickname, type, args);
00212 }
00213 
00214 void IRCSession::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
00215     m_connection->sendCTCPReply(nickname, type, args);
00216 }

Generated on Sat Nov 5 16:17:41 2005 for OPIE by  doxygen 1.4.2