aboutsummaryrefslogtreecommitdiff
path: root/include/demoserver.h
blob: cadc52ddb900ba5b251a03bf5a93805b041fff84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef DEMOSERVER_H
#define DEMOSERVER_H

#include "aopacket.h"

#include <QDebug>
#include <QObject>
#include <QQueue>
#include <QTcpServer>
#include <QTcpSocket>
#include <QTimer>
#include <QFileDialog>
#include <QMessageBox>

class DemoServer : public QObject
{
    Q_OBJECT
public:
    explicit DemoServer(QObject *parent = nullptr);

    bool server_started = false;
    int port = 27088;
    int max_wait = -1;

private:
    void handle_packet(AOPacket packet);
    void load_demo(QString filename);
    void reset_state();

    QTcpServer* tcp_server;
    QTcpSocket* client_sock = nullptr;
    bool client_connected = false;
    bool partial_packet = false;
    QString temp_packet = "";
    QQueue<QString> demo_data;
    QString sc_packet;
    int num_chars = 0;
    QString p_path;
    QTimer *timer;
    int elapsed_time = 0;

private slots:
    void accept_connection();
    void destroy_connection();
    void recv_data();
    void client_disconnect();
    void playback();

public slots:
    void start_server();

signals:
    void skip_timers(qint64 msecs);
};

#endif // DEMOSERVER_H