1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "netsoullistusers.h"
-
- NetSoulListUsers::NetSoulListUsers(QObject* parent) : QObject(parent)
- {
- socket = new QTcpSocket(this);
- connect(socket, SIGNAL(connected()), this, SLOT(connectedToNS()));
- connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sockError(QAbstractSocket::SocketError)));
- connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
- }
-
- void NetSoulListUsers::list()
- {
- socket->connectToHost("ns-server.epita.fr", 4242);
- }
-
- void NetSoulListUsers::connectedToNS()
- {
- socket->write("list_users\n");
- }
-
- void NetSoulListUsers::sockError(QAbstractSocket::SocketError)
- {
- emit NSError();
- }
-
- void NetSoulListUsers::readyRead()
- {
- buf += QString(socket->readAll());
- if(buf.endsWith("cmd end\n"))
- {
- QList<QList<QString> > users;
- QStringList usrs = buf.split("\n", QString::SkipEmptyParts);
- for(int i = 1; i < usrs.size() - 1; ++i)
- users.append(usrs.at(i).split(" "));
- socket->disconnectFromHost();
- emit listed(users);
- }
- }
|