Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Internet Ranking integration #338

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ find_package(JPEG REQUIRED)
find_package(Vorbis REQUIRED)
find_package(OGG REQUIRED)
find_package(LibArchive REQUIRED)
find_package(CryptoPP REQUIRED)

# All projects use unicode define
# this is mainly for windows functions either being defined to call A or W prefixed functions
Expand Down
1 change: 1 addition & 0 deletions Main/include/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Application

private:
bool m_LoadConfig();
bool m_LoadSettingsStyleConfig(String skin);
void m_SaveConfig();
void m_InitDiscord();
bool m_Init();
Expand Down
7 changes: 6 additions & 1 deletion Main/include/GameConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ DefineEnum(GameConfigKeys,
MultiplayerUsername,

RollIgnoreDuration,
LaserSlamLength
LaserSlamLength,

// Internet Ranking
IRBaseURL,
IRUsername,
IRPassword
);

DefineEnum(SpeedMods,
Expand Down
82 changes: 82 additions & 0 deletions Main/include/SkinConfig.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "Shared/Config.hpp"
#include "stdafx.h"

struct SkinSetting
Expand Down Expand Up @@ -108,3 +109,84 @@ class SkinConfig : ConfigBase
return targetType;
}
};

DefineEnum(SettingsStyleConfigKeys,
// Screen settings
BackgroundColor,
BorderColor,
BorderWidth,
TextColor,

ButtonTextColor,
ButtonTextColorHover,
ButtonBackgroundColor,
ButtonBackgroundColorHover,
ButtonBorderColor,
ButtonBorderWidth,
ButtonPaddingLeftRight,
ButtonPaddingTopBottom,
ButtonRounding,

NodeTextColor,
NodeArrowColor,
NodeArrowBackgroundColor,

OptionTextColor,
OptionColor,
OptionColorHover,
OptionColorChecked,
OptionColorCheckedHover,
OptionBorderColor,
OptionBorderWidth,

CheckTextColor,
CheckColor,
CheckColorHover,
CheckColorChecked,
CheckColorCheckedHover,
CheckBorderColor,
CheckBorderWidth,

SliderBarEmptyColor,
SliderBarFilledColor,
SliderBallColor,
SliderBallColorHover,

ComboButtonBackgroundColor,
ComboButtonTextColor,
ComboButtonBackgroundColorHover,
ComboButtonTextColorHover,
ComboButtonArrowColor,

ComboBoxBackgroundColor,
ComboBoxTextColor,
ComboBoxBackgroundColorHover,
ComboBoxTextColorHover,

PropertyTextColor,
PropertyBackgroundColor,
PropertyArrowColor,
PropertyEditTextColor,
PropertyEditBackgroundColor,
PropertyEditSelectedTextColor,
PropertyEditSelectedBackgroundColor,

EditTextColor,
EditBackgroundColor,
EditSelectedTextColor,
EditSelectedBackgroundColor



);

// Config for game settings
class SettingsStyleConfig : public Config<Enum_SettingsStyleConfigKeys>
{
public:
SettingsStyleConfig();
virtual void InitDefaults() override;
};

// Main config instance
extern class SettingsStyleConfig g_settingsStyleConfig;
24 changes: 24 additions & 0 deletions Main/src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "archive_entry.h"

GameConfig g_gameConfig;
SettingsStyleConfig g_settingsStyleConfig;
SkinConfig* g_skinConfig;
OpenGL* g_gl = nullptr;
Graphics::Window* g_gameWindow = nullptr;
Expand Down Expand Up @@ -415,6 +416,23 @@ void Application::m_unpackSkins()
}
}

bool Application::m_LoadSettingsStyleConfig(String skin)
{
File configFile;

// Reset to defaults incase skin can't load;
g_settingsStyleConfig.Clear();
g_settingsStyleConfig.InitDefaults();

if (configFile.OpenRead(Path::Absolute("skins/" + skin + "/style.cfg")))
{
FileReader reader(configFile);
if (g_settingsStyleConfig.Load(reader))
return true;
}
return false;
}

bool Application::m_LoadConfig()
{
File configFile;
Expand Down Expand Up @@ -679,6 +697,9 @@ bool Application::m_Init()
}

g_skinConfig = new SkinConfig(m_skin);

m_LoadSettingsStyleConfig(m_skin);

// Window cursor
Image cursorImg = ImageRes::Create(Path::Absolute("skins/" + m_skin + "/textures/cursor.png"));
g_gameWindow->SetCursor(cursorImg, Vector2i(5, 5));
Expand Down Expand Up @@ -1284,6 +1305,9 @@ void Application::ReloadSkin()
delete g_skinConfig;
}
g_skinConfig = new SkinConfig(m_skin);

m_LoadSettingsStyleConfig(m_skin);

g_guiState.fontCahce.clear();
g_guiState.textCache.clear();
g_guiState.nextTextId.clear();
Expand Down
5 changes: 5 additions & 0 deletions Main/src/GameConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ void GameConfig::InitDefaults()

Set(GameConfigKeys::RollIgnoreDuration, 100.f);
Set(GameConfigKeys::LaserSlamLength, 100.f);

// Internet Ranking
Set(GameConfigKeys::IRBaseURL, "https://api.orchestra.fm");
Set(GameConfigKeys::IRUsername, "");
Set(GameConfigKeys::IRPassword, "");
}
54 changes: 53 additions & 1 deletion Main/src/ScoreScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
#include "Shared/Time.hpp"
#include "json.hpp"
#include "CollectionDialog.hpp"
#include <cpr/cpr.h>
#include "cryptopp/cryptlib.h"
#include "cryptopp/hex.h"
#include "cryptopp/sha3.h"
#include <cryptopp/filters.h>
#include <cryptopp/files.h>


class ScoreScreen_Impl : public ScoreScreen
{
Expand Down Expand Up @@ -209,7 +216,49 @@ class ScoreScreen_Impl : public ScoreScreen
m_graphTex->SetWrap(Graphics::TextureWrap::Clamp, Graphics::TextureWrap::Clamp);

m_numPlayersSeen = m_stats->size();
m_displayId = static_cast<String>((*m_stats)[m_displayIndex].value("uid",""));
m_displayId = static_cast<String>((*m_stats)[m_displayIndex].value("uid", ""));

}

void SubmitScoreToIR(class Game* game) {
Scoring& m_scoring = game->GetScoring();

// check if we can login
String url = g_gameConfig.GetString(GameConfigKeys::IRBaseURL);

// hash the file of the chart we played
CryptoPP::SHA3_512 hash;
String digest;
CryptoPP::FileSource f(
std::istringstream(game->GetDifficultyIndex().path),
true,
new CryptoPP::HashFilter(
hash,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(digest))));

// get the ids from the file hash
auto res = nlohmann::json::parse(cpr::Get(cpr::Url{ url + "/api/v0/board/sha3/" + digest }).text);

uint64 track_id = res["track_id"];
uint64 board_id = res["id"];

// post the score
nlohmann::json score_info = {
{"track", track_id, },
{"board", board_id, },
{"score", m_scoring.CalculateCurrentScore(), },
{"combo", m_scoring.maxComboCounter, },
{"rate", m_scoring.currentGauge, },
{"criticals", m_scoring.categorizedHits[2], },
{"nears", m_scoring.categorizedHits[1] , },
{"errors", m_scoring.categorizedHits[0], },
{"mods", m_flags, },
//{"replaydata", 0, }, does usc have replays?
};
cpr::Post(cpr::Url{ url + "/api/v0/score" },
cpr::Body{ score_info.dump() },
cpr::Header{ {"Content-Type", "application/json"} });

}

Expand Down Expand Up @@ -251,6 +300,9 @@ class ScoreScreen_Impl : public ScoreScreen
loadScoresFromGame(game);
}

// TODO: check if Internet Ranking is enabled
SubmitScoreToIR(game);

for (HitStat* stat : scoring.hitStats)
{
if (!stat->forReplay)
Expand Down
Loading