1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 : _quitMsg(""), _sentQuit(false)
28 _discardTimer.setSingleShot(true);
29 _joinTimer.setSingleShot(true);
30 _quitTimer.setSingleShot(true);
32 connect(&_discardTimer, SIGNAL(timeout()), this, SIGNAL(finished()));
34 connect(&_joinTimer, SIGNAL(timeout()), this, SLOT(joinTimeout()));
35 connect(&_quitTimer, SIGNAL(timeout()), this, SLOT(quitTimeout()));
37 // wait for a maximum of 1 hour until we discard the netsplit
38 _discardTimer.start(3600000);
41 void Netsplit::userQuit(const QString &sender, const QStringList &channels, const QString &msg)
43 if(_quitMsg.isEmpty())
45 foreach(QString channel, channels) {
46 _quits[channel].append(sender);
48 // now let's wait 5s to finish the netsplit-quit
49 _quitTimer.start(5000);
52 bool Netsplit::userJoined(const QString &sender, const QString &channel) {
53 if(!_quits.contains(channel))
56 QStringList &users = _quits[channel];
57 int idx = users.indexOf(sender);
61 _joins[channel].append(users.takeAt(idx));
63 _quits.remove(channel);
65 // now let's wait 5s to finish the netsplit-join
66 _joinTimer.start(5000);
70 bool Netsplit::isNetsplit(const QString &quitMessage)
72 // check if we find some common chars that disqualify the netsplit as such
73 if(quitMessage.contains(':') || quitMessage.contains('/'))
76 // now test if message consists only of two dns names as the RFC requests
77 // but also allow the commonly used "*.net *.split"
78 QRegExp hostRx("^(?:[\\w\\d-.]+|\\*)\\.[\\w\\d-]+\\s(?:[\\w\\d-.]+|\\*)\\.[\\w\\d-]+$");
79 if(hostRx.exactMatch(quitMessage))
85 void Netsplit::joinTimeout()
91 QHash<QString, QStringList>::iterator it;
92 for(it = _joins.begin(); it != _joins.end(); ++it)
93 emit netsplitJoin(it.key(), it.value(),_quitMsg);
99 void Netsplit::quitTimeout()
101 QHash<QString, QStringList>::iterator it;
102 for(it = _quits.begin(); it != _quits.end(); ++it)
103 emit netsplitQuit(it.key(), it.value(),_quitMsg);