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