41 lines
922 B
C++
41 lines
922 B
C++
#include "message.h"
|
|
|
|
#include <QStringList>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
Message::Message(QString str)
|
|
{
|
|
if(str.startsWith("PING"))
|
|
{
|
|
command = "PING";
|
|
target = "PING";
|
|
src = str.right(str.size()-(str.indexOf(':')+1));
|
|
args = str;
|
|
}
|
|
else
|
|
{
|
|
// remove the first char, which is ':'
|
|
str = str.remove(0, 1);
|
|
// locate the mid ':' separator
|
|
int mid = str.indexOf(':');
|
|
// the arguments are after the separator
|
|
args = str.right(str.size()-(mid+1));
|
|
// the interesting infos before the separator are separated by spaces
|
|
QStringList list = str.split(' ');
|
|
// source of the message
|
|
src = list.takeFirst();
|
|
// command issued by the source
|
|
command = list.takeFirst();
|
|
// target of the command
|
|
target = list.takeFirst();
|
|
}
|
|
}
|
|
|
|
Message::~Message()
|
|
{
|
|
|
|
}
|
|
|