Splitted different client states into classes
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <qlogging.h>
|
||||
#include <QTcpServer>
|
||||
#include <QList>
|
||||
#include <QPointer>
|
||||
#include <QTimer>
|
||||
|
||||
#include "client.h"
|
||||
#include "server.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -22,43 +18,7 @@ int main(int argc, char *argv[])
|
||||
"%{function}(): "
|
||||
"%{message}"));
|
||||
|
||||
QList<QPointer<Client>> clients;
|
||||
|
||||
QTimer timer;
|
||||
timer.setInterval(100);
|
||||
QObject::connect(&timer, &QTimer::timeout, [&clients](){
|
||||
const auto now = QDateTime::currentDateTime();
|
||||
for (auto iter = std::begin(clients); iter != std::end(clients); )
|
||||
{
|
||||
if ((*iter).isNull())
|
||||
{
|
||||
iter = clients.erase(iter);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto &client = **iter;
|
||||
if (client.state() == PlayState)
|
||||
{
|
||||
client.keepAlive();
|
||||
client.sendChatMessage();
|
||||
client.trialDisconnect();
|
||||
}
|
||||
|
||||
iter++;
|
||||
}
|
||||
});
|
||||
timer.start();
|
||||
|
||||
QTcpServer server;
|
||||
|
||||
QObject::connect(&server, &QTcpServer::newConnection, [&server,&clients](){
|
||||
clients.append(new Client(server.nextPendingConnection()));
|
||||
});
|
||||
|
||||
if(!server.listen(QHostAddress::Any, 25565))
|
||||
qFatal("could not start listening %s", server.errorString().toUtf8().constData());
|
||||
|
||||
qDebug() << "started listening";
|
||||
Server server;
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user