1#ifndef CAVOKE_CLIENT_NETWORK_MANAGER_H
2#define CAVOKE_CLIENT_NETWORK_MANAGER_H
4#include <QOAuth2AuthorizationCodeFlow>
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"
26 const static inline QUrl DEFAULT_HOST{
"https://develop.api.cavoke.wlko.me"};
28 void changeHost(
const QUrl &newHost);
35 void getGamesConfig(
const QString &gameId);
36 void getGamesClient(
const QString &gameId);
38 void sendMove(
const QString &jsonMove);
41 void joinSession(
const QString &sessionId);
42 void validateSession();
43 void getSessionInfo();
44 void getSessionInfo(
const QString &sessionId);
47 void changeRoleInSession(
int newRole);
50 void createRoom(
const QString &display_name);
51 void joinRoom(
const QString &invite_code);
53 void roomCreateSession(
const QString &game_id);
56 void changeName(
const QString &new_name);
58 void getMyUserStatistics();
59 void getMyUserGameStatistics(
const QString &gameId);
60 void getGameStatistics(
const QString &gameId);
62 void startGamePolling();
63 void stopGamePolling();
64 void startSessionPolling();
65 void stopSessionPolling();
66 void startValidationPolling();
67 void stopValidationPolling();
68 void startRoomPolling();
69 void stopRoomPolling();
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);
78 void gotDisplayName(
const QString &displayName);
82 void gotRoomInfo(
const RoomInfo &roomInfo);
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);
100 QOAuth2AuthorizationCodeFlow *oauth2;
101 QNetworkAccessManager manager;
102 QTimer *gamePollingTimer =
nullptr;
103 QTimer *sessionPollingTimer =
nullptr;
104 QTimer *validationPollingTimer =
nullptr;
105 QTimer *roomPollingTimer =
nullptr;
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"};
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"};
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"};
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"};
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/"};
144 const static inline QUrl STATISTICS_GAME{
"statistics/game/"};