59 lines
991 B
C++
59 lines
991 B
C++
#ifndef SERVER_H
|
|
#define SERVER_H
|
|
|
|
#include <QObject>
|
|
#include <vector>
|
|
#include "packet.h"
|
|
|
|
class QTimer;
|
|
class QTcpServer;
|
|
class QTcpSocket;
|
|
class Client;
|
|
|
|
class Server : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit Server(unsigned short port = 20202, QObject *parent = 0);
|
|
QTcpServer* server;
|
|
QTimer* timer;
|
|
std::vector<Client*> clients;
|
|
int currentClient;
|
|
|
|
signals:
|
|
void outMessage(QString);
|
|
void errMessage(QString);
|
|
|
|
public slots:
|
|
void update();
|
|
void on_newConnection();
|
|
};
|
|
|
|
class Client : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
Client(QTcpSocket* mySocket);
|
|
~Client();
|
|
bool isOk() {return ok;}
|
|
void update();
|
|
void sendDelta();
|
|
void sendFull(const std::vector<Client*> &clients, int id);
|
|
|
|
private:
|
|
bool ok;
|
|
QTcpSocket* socket;
|
|
InitClientPacket info;
|
|
|
|
public slots:
|
|
void on_disconnected();
|
|
void on_readyRead();
|
|
|
|
signals:
|
|
void outMessage(QString);
|
|
void errMessage(QString);
|
|
};
|
|
|
|
#endif // SERVER_H
|