mirror of
https://github.com/Leahnaya/Sonataria.git
synced 2026-09-08 00:35:43 -05:00
HTTP Request Added for Login
- Imported new HTTP dependency - Updated ScreenRenderer to launch a login thread - Modified Networking to create a login HTTP GET request
This commit is contained in:
@@ -20,7 +20,7 @@ class GameState {
|
||||
public:
|
||||
enum class CurrentState {
|
||||
STARTUP, SHUTDOWN, ERROR_CODE, TEST_MENU_MAIN, TITLE_SCREEN, UPDATES, TEST_MENU_IOCHECK,
|
||||
TEST_MENU_INPUTCHECK, TEST_MENU_SYSINFO, PRELOGIN, LOGIN_DETAILS, SONG_SELECT, GAME, RESULTS, FINAL_RESULTS,
|
||||
TEST_MENU_INPUTCHECK, TEST_MENU_SYSINFO, PRELOGIN, LOGIN_DETAILS, CREATE_PROFILE, SONG_SELECT, GAME, RESULTS, FINAL_RESULTS,
|
||||
TEST_MENU_SOUNDOPTIONS, TEST_MENU_NETWORKING
|
||||
};
|
||||
enum class OnlineState {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "Logger.h"
|
||||
#include "Networking.h"
|
||||
#include <winsock2.h>
|
||||
#include "Logger.h"
|
||||
#include "HTTPRequest.hpp"
|
||||
using namespace std;
|
||||
|
||||
Networking network;
|
||||
@@ -26,7 +28,10 @@ const int PORT = 57015;
|
||||
*/
|
||||
Networking::Networking() {
|
||||
// Set the version of the game
|
||||
this->version = "20220120-J-01";
|
||||
this->version = "20220323-J-01";
|
||||
|
||||
// Set the information for connecting to the server
|
||||
this->ServerAddress = "http://127.0.0.1:3000";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +51,39 @@ string Networking::getLocalVersion() {
|
||||
return this->version;
|
||||
}
|
||||
|
||||
bool Networking::GetProfileData(string cardID) {
|
||||
try {
|
||||
// Build the URL for the connection
|
||||
string URL = this->ServerAddress + "/data/profile/" + cardID;
|
||||
http::Request request{ URL };
|
||||
|
||||
logger.log("Attempting to retrieve profile data... [" + URL + "]");
|
||||
|
||||
// Set a GET Request
|
||||
const auto response = request.send("GET", "", {}, std::chrono::seconds(5));
|
||||
|
||||
if (response.status.code == http::Status::Ok) {
|
||||
// Store the response into data
|
||||
string data = string{ response.body.begin(), response.body.end() };
|
||||
|
||||
// TODO: SAVE THE DATA INTO USERDATA
|
||||
|
||||
logger.log(data);
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
logger.logError("Invalid HTTP Status Code: " + to_string(response.status.code));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
logger.logError("Login Request Failed: ");
|
||||
logger.logError(e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the server for it's status.
|
||||
*
|
||||
|
||||
@@ -17,13 +17,19 @@ class Networking {
|
||||
public:
|
||||
Networking();
|
||||
~Networking();
|
||||
|
||||
string getLocalVersion();
|
||||
|
||||
bool GetProfileData(string);
|
||||
|
||||
int checkConnection();
|
||||
string checkForUpdates();
|
||||
string getLocalVersion();
|
||||
bool downloadUpdate();
|
||||
|
||||
|
||||
private:
|
||||
string version;
|
||||
string ServerAddress;
|
||||
};
|
||||
|
||||
extern Networking network;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <tchar.h>
|
||||
#include "TextureList.h"
|
||||
#include "unzip.h"
|
||||
#include "UserData.h"
|
||||
#include "WindowsAudio.h"
|
||||
using namespace std;
|
||||
|
||||
@@ -58,6 +59,7 @@ int updateDownloadStatus = -1;
|
||||
void execStartupChecks();
|
||||
void execDownloadUpdate();
|
||||
void rThread(sf::RenderWindow* window);
|
||||
void checkForProfile(int& loginComplete);
|
||||
|
||||
/**
|
||||
* Constructor for the screen renderer.
|
||||
@@ -335,11 +337,15 @@ void ScreenRenderer::render(sf::RenderWindow* gameWindow) {
|
||||
|
||||
// Login Thread States
|
||||
/*
|
||||
* 0 - Not completed
|
||||
* 1 - Successfully Completed
|
||||
* 2 - Not Online
|
||||
* -1 - Thread Not Started
|
||||
* 0 - Not completed
|
||||
* 1 - Successfully Completed
|
||||
* 2 - Not Successful For X Reason
|
||||
*/
|
||||
int loginComplete = 1;
|
||||
int loginComplete = -1;
|
||||
|
||||
// Forward declaration of this thread for use in login
|
||||
sf::Thread loginThread(&checkForProfile, loginComplete);
|
||||
|
||||
// The rendering loop
|
||||
/*
|
||||
@@ -413,23 +419,43 @@ void ScreenRenderer::render(sf::RenderWindow* gameWindow) {
|
||||
if (RFIDCardReader::getCardReader()->getLastCardData() != "") {
|
||||
// TODO: LAUNCH THE THREAD TO DO THE LOGIN
|
||||
|
||||
switch (loginComplete) {
|
||||
case -1:
|
||||
// Launch a thread to attempt getting the profile data
|
||||
loginThread.launch();
|
||||
|
||||
if (loginComplete == 1) {
|
||||
gameState.setGameState(GameState::CurrentState::LOGIN_DETAILS);
|
||||
controllerInput.reset();
|
||||
timerRunning = false;
|
||||
}
|
||||
else if (loginComplete == 2) {
|
||||
// Can't login as we are offline or unable to connect
|
||||
// TODO: SHOW ERROR AND ERROR NOISE
|
||||
// Set variable so we know it is checking
|
||||
loginComplete = 0;
|
||||
break;
|
||||
case 0:
|
||||
// TODO: Display a graphic showing that it is attempting to login
|
||||
break;
|
||||
case 1:
|
||||
if (userData.isValidUser()) {
|
||||
// User has a valid profile and already exists
|
||||
gameState.setGameState(GameState::CurrentState::LOGIN_DETAILS);
|
||||
}
|
||||
else {
|
||||
// User doesn't have a profile yet, go to profile creation
|
||||
// TODO: PROFILE CREATION
|
||||
gameState.setGameState(GameState::CurrentState::CREATE_PROFILE);
|
||||
}
|
||||
controllerInput.reset();
|
||||
timerRunning = false;
|
||||
break;
|
||||
case 2:
|
||||
// Can't login as we were unable to connect or some other error occurred
|
||||
// TODO: SHOW ERROR AND ERROR NOISE
|
||||
break;
|
||||
}
|
||||
}
|
||||
//}
|
||||
// TODO: ELSE BLOCK: DRAW GRAPHICS FOR IF SERVER IS OFFLINE OR ON MAINT FOR PRELOGIN
|
||||
}
|
||||
|
||||
// DRAW ALL OTHER GRAPHICS
|
||||
{
|
||||
// TODO: DRAW GRAPHICS FOR IF SERVER IS OFFLINE OR ON MAINT FOR PRELOGIN
|
||||
|
||||
}
|
||||
|
||||
// Switch over to the text shader
|
||||
@@ -994,7 +1020,7 @@ void ScreenRenderer::render(sf::RenderWindow* gameWindow) {
|
||||
testMenuTitle->reset();
|
||||
testMenuTitle->translate(0.f, 900.f, 0.f);
|
||||
testMenuTitle->scale(0.5f);
|
||||
testMenuTitle->render(PROJECTION::ORTHOGRAPHIC, RFIDCardReader::getCardReader()->getLastCardData(), ALIGNMENT::CENTERED);
|
||||
testMenuTitle->render(PROJECTION::ORTHOGRAPHIC, userData.getDisplayName(), ALIGNMENT::CENTERED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1447,4 +1473,23 @@ void execDownloadUpdate() {
|
||||
void rThread(sf::RenderWindow* window) {
|
||||
GameRenderer gameRenderer;
|
||||
gameRenderer.render(window);
|
||||
}
|
||||
}
|
||||
|
||||
void checkForProfile(int& loginComplete) {
|
||||
// Grab the card ID to check for a profile
|
||||
string cardID = RFIDCardReader::getCardReader()->getLastCardData();
|
||||
|
||||
// Clear out the last user data if any
|
||||
userData.clearData();
|
||||
|
||||
// Attempt to get the profile data | Set login complete when done
|
||||
// IF SUCCESS set loginComplete = 1
|
||||
// IF FAILED set loginComplete = 2
|
||||
if (network.GetProfileData(cardID)) {
|
||||
// Grabbed the profile data successfully
|
||||
loginComplete = 1;
|
||||
}
|
||||
else {
|
||||
loginComplete = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\FreeImage\x32;$(SolutionDir)dependencies\PacDrive\include;$(SolutionDir)dependencies\SFML\SFML-2.5.1\include;$(SolutionDir)dependencies\glew-2.1.0\include;$(SolutionDir)dependencies\FreeType\include;$(SolutionDir)dependencies\uFCoder\include;$(SolutionDir)dependencies\ffmpeg-4.5\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\FreeImage\x32;$(SolutionDir)dependencies\PacDrive\include;$(SolutionDir)dependencies\SFML\SFML-2.5.1\include;$(SolutionDir)dependencies\glew-2.1.0\include;$(SolutionDir)dependencies\FreeType\include;$(SolutionDir)dependencies\uFCoder\include;$(SolutionDir)dependencies\ffmpeg-4.5\include;$(SolutionDir)dependencies\HTTPRequest-0.2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<PreprocessorDefinitions>UNICODE;_HAS_STD_BYTE=0;_ITERATOR_DEBUG_LEVEL=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
@@ -131,7 +131,7 @@ copy $(SolutionDir)dependencies\ffmpeg-4.5\bin\swresample-4.dll $(OutputPath)</
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\FreeImage\x32;$(SolutionDir)dependencies\PacDrive\include;$(SolutionDir)dependencies\SFML\SFML-2.5.1\include;$(SolutionDir)dependencies\glew-2.1.0\include;$(SolutionDir)dependencies\FreeType\include;$(SolutionDir)dependencies\uFCoder\include;$(SolutionDir)dependencies\ffmpeg-4.5\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)dependencies\FreeImage\x32;$(SolutionDir)dependencies\PacDrive\include;$(SolutionDir)dependencies\SFML\SFML-2.5.1\include;$(SolutionDir)dependencies\glew-2.1.0\include;$(SolutionDir)dependencies\FreeType\include;$(SolutionDir)dependencies\uFCoder\include;$(SolutionDir)dependencies\ffmpeg-4.5\include;$(SolutionDir)dependencies\HTTPRequest-0.2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>UNICODE;_HAS_STD_BYTE=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
|
||||
@@ -49,4 +49,8 @@ bool UserData::isValidUser() {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string UserData::getDisplayName() {
|
||||
return this->DisplayName;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@ class UserData {
|
||||
~UserData();
|
||||
void clearData();
|
||||
void setUserData(int, string);
|
||||
|
||||
bool isValidUser();
|
||||
string getDisplayName();
|
||||
|
||||
private:
|
||||
string DisplayName;
|
||||
|
||||
1130
dependencies/HTTPRequest-0.2/include/HTTPRequest.hpp
vendored
Normal file
1130
dependencies/HTTPRequest-0.2/include/HTTPRequest.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user