fixed major bug
This commit is contained in:
parent
49ba5d82df
commit
2f6c2be025
2
main.cpp
2
main.cpp
@ -7,7 +7,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
// set up the socket
|
||||
SocketIRC sock;
|
||||
sock.setServer("irc.freenode.net");
|
||||
sock.setServer("localhost");
|
||||
sock.setPort(6667);
|
||||
|
||||
// set up the bot
|
||||
|
10
message.cpp
10
message.cpp
@ -5,14 +5,15 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
Message::Message(QString str, UserList users)
|
||||
Message::Message(QString str, UserList* users)
|
||||
{
|
||||
if(str.startsWith("PING"))
|
||||
{
|
||||
command = "PING";
|
||||
target = "PING";
|
||||
src = NULL;
|
||||
args = str.split(':')[1];
|
||||
nick = str.split(':')[1];
|
||||
args = nick;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -25,8 +26,9 @@ Message::Message(QString str, UserList users)
|
||||
// the interesting infos before the separator are separated by spaces
|
||||
QStringList list = str.split(' ');
|
||||
// source of the message (creates the user if he is new)
|
||||
QString nick = list.takeFirst();
|
||||
src = users.getOrAdd(nick.left(nick.indexOf('!')));
|
||||
QString temp = list.takeFirst();
|
||||
nick = temp.left(temp.indexOf('!'));
|
||||
src = users->getFromNick(nick);
|
||||
// command issued by the source
|
||||
command = list.takeFirst();
|
||||
// target of the command
|
||||
|
@ -10,11 +10,12 @@ class Message
|
||||
{
|
||||
public:
|
||||
User* src;
|
||||
QString nick;
|
||||
QString command;
|
||||
QString target;
|
||||
QString target2;
|
||||
QString args;
|
||||
Message(QString str, UserList users);
|
||||
Message(QString str, UserList* users);
|
||||
~Message();
|
||||
};
|
||||
|
||||
|
@ -7,23 +7,25 @@ using namespace std;
|
||||
|
||||
void SparrowBot::receiveMsg(QString str)
|
||||
{
|
||||
Message msg = Message(str, users);
|
||||
Message msg = Message(str, &users);
|
||||
|
||||
switch(status)
|
||||
{
|
||||
case OFFLINE :
|
||||
status = ONLINE;
|
||||
sendMsg(QString("NICK %1\r\nUSER %2 0 * %3\r\n").arg(nick).arg(nick).arg(nick));
|
||||
emit sendMsg(QString("NICK %1\r\nUSER %2 0 * %3\r\n").arg(nick).arg(nick).arg(nick));
|
||||
break;
|
||||
case ONLINE :
|
||||
if(str.contains("PING"))
|
||||
{
|
||||
status = ON_CHAN;
|
||||
sendMsg(QString("PONG :%1\r\n").arg(msg.args));
|
||||
sendMsg("JOIN #" + chan + "\r\n");
|
||||
emit sendMsg(QString("PONG :%1\r\n").arg(msg.nick));
|
||||
emit sendMsg("JOIN #" + chan + "\r\n");
|
||||
}
|
||||
break;
|
||||
case ON_CHAN :
|
||||
if(str.contains("PING"))
|
||||
emit sendMsg(QString("PONG :%1\r\n").arg(msg.nick));
|
||||
handleMessage(msg);
|
||||
break;
|
||||
}
|
||||
@ -79,7 +81,10 @@ void SparrowBot::handleMessage(Message msg)
|
||||
users.remove(msg.src);
|
||||
else if(msg.command.compare("JOIN", Qt::CaseInsensitive) == 0
|
||||
&& msg.args.contains(chan))
|
||||
emit sendMsg(QString("WHOIS %1\r\n").arg(msg.src->getNick()));
|
||||
{
|
||||
users.getOrAdd(msg.nick);
|
||||
emit sendMsg(QString("WHOIS %1\r\n").arg(msg.nick));
|
||||
}
|
||||
|
||||
// 353 = code de la ligne qui liste les nicks connectés
|
||||
// on les parse et on effectue un WHOIS sur chaque nick
|
||||
@ -89,9 +94,8 @@ void SparrowBot::handleMessage(Message msg)
|
||||
QStringList names = msg.args.split(' ');
|
||||
for(QString s : names)
|
||||
{
|
||||
User* u = new User(s);
|
||||
users.push_back(u);
|
||||
emit sendMsg(QString("WHOIS %1\r\n").arg(u->getNick()));
|
||||
users.getOrAdd(s);
|
||||
emit sendMsg(QString("WHOIS %1\r\n").arg(s));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user