Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
network_manager.h
1#ifndef CAVOKE_CLIENT_NETWORK_MANAGER_H
2#define CAVOKE_CLIENT_NETWORK_MANAGER_H
3
4#include <QOAuth2AuthorizationCodeFlow>
5#include <QUrlQuery>
6#include <QUuid>
7#include <QtCore/QFile>
8#include <QtCore/QJsonArray>
9#include <QtCore/QJsonDocument>
10#include <QtCore/QJsonObject>
11#include <QtCore/QTemporaryFile>
12#include <QtCore/QTimer>
13#include <QtNetwork/QNetworkReply>
14#include "AuthenticationManager.h"
15#include "entities/gameinfo.h"
16#include "entities/gamestatistics.h"
17#include "entities/roominfo.h"
18#include "entities/sessioninfo.h"
19#include "entities/usergamestatistics.h"
20#include "entities/userstatistics.h"
21#include "entities/validationresult.h"
22
23struct NetworkManager : public QObject {
24 Q_OBJECT
25public:
26 const static inline QUrl DEFAULT_HOST{"https://develop.api.cavoke.wlko.me"};
27 explicit NetworkManager(QObject *parent = nullptr);
28 void changeHost(const QUrl &newHost);
29 QString getUserId();
30
31public slots:
32 void getHealth();
33
34 void getGamesList();
35 void getGamesConfig(const QString &gameId);
36 void getGamesClient(const QString &gameId);
37
38 void sendMove(const QString &jsonMove);
39 void getPlayState();
40
41 void joinSession(const QString &sessionId);
42 void validateSession();
43 void getSessionInfo();
44 void getSessionInfo(const QString &sessionId);
45 void startSession();
46 void leaveSession();
47 void changeRoleInSession(int newRole);
48
49 void getRoomInfo();
50 void createRoom(const QString &display_name);
51 void joinRoom(const QString &invite_code);
52 void leaveRoom();
53 void roomCreateSession(const QString &game_id);
54
55 void getMe();
56 void changeName(const QString &new_name);
57
58 void getMyUserStatistics();
59 void getMyUserGameStatistics(const QString &gameId);
60 void getGameStatistics(const QString &gameId);
61
62 void startGamePolling();
63 void stopGamePolling();
64 void startSessionPolling();
65 void stopSessionPolling();
66 void startValidationPolling();
67 void stopValidationPolling();
68 void startRoomPolling();
69 void stopRoomPolling();
70
71signals:
72 void finalizedGamesList(QJsonArray list);
73 void gotGameUpdate(const QString &jsonField);
74 void downloadedGameFile(QFile *file, const QString &gameId);
75 void gotGameInfo(const GameInfo &gameInfo);
76 void gotSessionInfo(const SessionInfo &sessionInfo);
77 void gotValidationResult(const ValidationResult &validationResult);
78 void gotDisplayName(const QString &displayName);
79 void gotUserStatistics(const UserStatistics &userStatistics);
80 void gotUserGameStatistics(const UserGameStatistics &userGameStatistics);
81 void gotGameStatistics(const GameStatistics &gameStatistics);
82 void gotRoomInfo(const RoomInfo &roomInfo);
83
84private slots:
85 void gotHealth(QNetworkReply *reply);
86 void gotGamesList(QNetworkReply *reply);
87 void gotGamesConfig(QNetworkReply *reply);
88 void gotSession(QNetworkReply *reply);
89 void gotValidatedSession(QNetworkReply *reply);
90 void gotPostResponse(QNetworkReply *reply);
91 void gotPlayState(QNetworkReply *reply);
92 void gotGamesClient(QNetworkReply *reply, const QString &gameId);
93 void gotMyself(QNetworkReply *reply);
94 void gotUserStatistics(QNetworkReply *reply);
95 void gotUserGameStatistics(QNetworkReply *reply);
96 void gotGameStatistics(QNetworkReply *reply);
97 void gotRoom(QNetworkReply *reply);
98
99private:
100 QOAuth2AuthorizationCodeFlow *oauth2;
101 QNetworkAccessManager manager;
102 QTimer *gamePollingTimer = nullptr;
103 QTimer *sessionPollingTimer = nullptr;
104 QTimer *validationPollingTimer = nullptr;
105 QTimer *roomPollingTimer = nullptr;
106 QString sessionId;
107 QString roomId;
112 QString queryUserId;
113 QUrl HOST{DEFAULT_HOST};
114 const static inline QUrl HEALTH{"health"};
115 const static inline QUrl GAMES_LIST{"games/list"};
116 const static inline QUrl GAMES{"games/"};
117 const static inline QUrl GET_CONFIG{"get_config"};
118 const static inline QUrl GET_CLIENT{"get_client"};
119 // Rooms activity
120 const static inline QUrl ROOMS{"rooms/"};
121 const static inline QUrl GET_INFO{"get_info"};
122 const static inline QUrl ROOMS_CREATE{"rooms/create"};
123 const static inline QUrl ROOMS_JOIN{"rooms/join"};
124 const static inline QUrl LEAVE{"leave"};
125 const static inline QUrl CREATE_SESSION{"create_session"};
126
127 const static inline QUrl JOIN{"join"};
128 const static inline QUrl SESSIONS{"sessions/"};
129 const static inline QUrl VALIDATE{"validate"};
130 const static inline QUrl START{"start"};
131 const static inline QUrl CHANGE_ROLE{"change_role"};
132
133 const static inline QUrl PLAY{"play/"};
134 const static inline QUrl SEND_MOVE{"send_move"};
135 const static inline QUrl GET_STATE{"get_state"};
136
137 const static inline QUrl PROFILE{"profile/"};
138 const static inline QUrl GET_ME{"get_me"};
139 const static inline QUrl CHANGE_NAME{"change_name"};
140 const static inline QUrl MY_USER_STATISTICS{"my_user_statistics"};
141 const static inline QUrl MY_USER_GAME_STATISTICS{
142 "my_user_game_statistics/"};
143
144 const static inline QUrl STATISTICS_GAME{"statistics/game/"};
145};
146
147#endif // CAVOKE_CLIENT_NETWORK_MANAGER_H