diff --git a/Data/LevelData.cpp b/Data/LevelData.cpp index 06b48a238..1499bcef5 100644 --- a/Data/LevelData.cpp +++ b/Data/LevelData.cpp @@ -13,12 +13,14 @@ namespace hg void LevelData::addEvent(Json::Value mEventRoot) { events.push_back(mEventRoot); } - void LevelData::setPackPath(const string& mPackPath) { packPath = mPackPath; } - void LevelData::setJsonRootPath(const string& mJsonRootPath) { jsonRootPath = mJsonRootPath; } - void LevelData::setLuaScriptPath(const string& mLuaScriptPath) { luaScriptPath = mLuaScriptPath; } + void LevelData::setPackPath(const string& mPath) { packPath = mPath; } + void LevelData::setLevelRootPath(const string& mPath) { levelRootPath = mPath; } + void LevelData::setStyleRootPath(const string& mPath) { styleRootPath = mPath; } + void LevelData::setLuaScriptPath(const string& mPath) { luaScriptPath = mPath; } string LevelData::getPackPath() { return packPath; } - string LevelData::getJsonRootPath() { return jsonRootPath; } + string LevelData::getLevelRootPath() { return levelRootPath; } + string LevelData::getStyleRootPath() { return styleRootPath; } string LevelData::getLuaScriptPath() { return luaScriptPath; } Json::Value& LevelData::getRoot() { return root; } diff --git a/Data/LevelData.h b/Data/LevelData.h index bbaf00969..89641f332 100644 --- a/Data/LevelData.h +++ b/Data/LevelData.h @@ -17,7 +17,7 @@ namespace hg Json::Value root; int currentPattern{-1}; std::vector events; - std::string packPath, jsonRootPath, luaScriptPath; + std::string packPath, levelRootPath, styleRootPath, luaScriptPath; public: LevelData() = default; @@ -27,11 +27,13 @@ namespace hg Json::Value& getRoot(); - void setPackPath(const std::string& mPackPath); - void setJsonRootPath(const std::string& mJsonRootPath); - void setLuaScriptPath(const std::string& mLuaScriptPath); + void setPackPath(const std::string& mPath); + void setLevelRootPath(const std::string& mPath); + void setStyleRootPath(const std::string& mPath); + void setLuaScriptPath(const std::string& mPath); std::string getPackPath(); - std::string getJsonRootPath(); + std::string getLevelRootPath(); + std::string getStyleRootPath(); std::string getLuaScriptPath(); std::string getId(); diff --git a/Data/StyleData.cpp b/Data/StyleData.cpp index be965b714..4679bd289 100644 --- a/Data/StyleData.cpp +++ b/Data/StyleData.cpp @@ -87,6 +87,9 @@ namespace hg } } + void StyleData::setRootPath(const std::string& mPath) { rootPath = mPath; } + string StyleData::getRootPath() { return rootPath; } + string StyleData::getId() { return root["id"].asString(); } float StyleData::getHueMin() { return root["hue_min"].asFloat(); } float StyleData::getHueMax() { return root["hue_max"].asFloat(); } diff --git a/Data/StyleData.h b/Data/StyleData.h index c7c9866e5..cf3f0c817 100644 --- a/Data/StyleData.h +++ b/Data/StyleData.h @@ -15,6 +15,7 @@ namespace hg private: Json::Value root; float currentHue, currentSwapTime, pulseFactor{0}; + std::string rootPath; public: StyleData() = default; @@ -23,11 +24,14 @@ namespace hg void update(float mFrameTime); void drawBackground(sf::RenderTarget& mRenderTarget, sf::Vector2f mCenterPos, int mSides); + void setRootPath(const std::string& mPath); + + std::string getRootPath(); std::string getId(); float getHueMin(); float getHueMax(); bool getHuePingPong(); - float getHueIncrement(); + float getHueIncrement(); sf::Color calculateColor(Json::Value mColorRoot); diff --git a/Global/Assets.cpp b/Global/Assets.cpp index b2f92e444..31443eada 100644 --- a/Global/Assets.cpp +++ b/Global/Assets.cpp @@ -114,6 +114,7 @@ namespace hg for(auto filePath : getFilesByExtension(mPath + "Styles/", ".json")) { StyleData styleData{loadStyleFromJson(getJsonFileRoot(filePath))}; + styleData.setRootPath(filePath); styleDataMap.insert(make_pair(styleData.getId(), styleData)); } } @@ -123,10 +124,11 @@ namespace hg { Json::Value root{getJsonFileRoot(filePath)}; string luaScriptPath{mPath + "Scripts/" + root["lua_file"].asString()}; - + LevelData levelData{loadLevelFromJson(root)}; levelData.setPackPath(mPath); - levelData.setJsonRootPath(filePath); + levelData.setLevelRootPath(filePath); + levelData.setStyleRootPath(getStyleData(levelData.getStyleId()).getRootPath()); levelData.setLuaScriptPath(luaScriptPath); levelDataMap.insert(make_pair(levelData.getId(), levelData)); levelIdsByPackMap[levelData.getPackPath()].push_back(levelData.getId()); diff --git a/HexagonGame.cpp b/HexagonGame.cpp index 831fe296d..612424bfb 100644 --- a/HexagonGame.cpp +++ b/HexagonGame.cpp @@ -157,7 +157,7 @@ namespace hg if(status.scoreInvalid || !isEligibleForScore()) return; - string validator{Online::getValidator(levelData.getPackPath(), levelData.getId(), levelData.getJsonRootPath(), levelData.getLuaScriptPath(), difficultyMult)}; + string validator{Online::getValidator(levelData.getPackPath(), levelData.getId(), levelData.getLevelRootPath(), levelData.getStyleRootPath(), levelData.getLuaScriptPath(), difficultyMult)}; Online::startSendScore(getCurrentProfile().getName(), validator, status.currentTime); } void HexagonGame::goToMenu(bool mSendScores) diff --git a/MenuGame.cpp b/MenuGame.cpp index eb5ef755f..7a2133884 100644 --- a/MenuGame.cpp +++ b/MenuGame.cpp @@ -173,7 +173,7 @@ namespace hg void MenuGame::refreshScores() { float difficultyMult{difficultyMultipliers[difficultyMultIndex % difficultyMultipliers.size()]}; - string validator{Online::getValidator(levelData.getPackPath(), levelData.getId(), levelData.getJsonRootPath(), levelData.getLuaScriptPath(), difficultyMult)}; + string validator{Online::getValidator(levelData.getPackPath(), levelData.getId(), levelData.getLevelRootPath(), levelData.getStyleRootPath(), levelData.getLuaScriptPath(), difficultyMult)}; Online::startGetScores(currentScores, validator); } string MenuGame::getLeaderboard() diff --git a/Online/Online.cpp b/Online/Online.cpp index 5160449ec..71a1e6fcf 100644 --- a/Online/Online.cpp +++ b/Online/Online.cpp @@ -203,32 +203,29 @@ namespace hg for(unsigned int i{0}; i < mString.size(); ++i) if(!iscntrl(mString[i])) result += mString[i]; return result; } - string getValidator(const string& mPackPath, const string& mLevelId, const string& mJsonRootPath, const string& mLuaScriptPath, float mDifficultyMultiplier) + string getValidator(const string& mPackPath, const string& mLevelId, const string& mLevelRootPath, const string& mStyleRootPath, const string& mLuaScriptPath, float mDifficultyMultiplier) { string luaScriptContents{getFileContents(mLuaScriptPath)}; - unordered_set luaScriptNames; recursiveFillIncludedLuaFileNames(luaScriptNames, mPackPath, luaScriptContents); - string result{""}; - result.append(getUrlEncoded(mLevelId)); - result.append(getMD5Hash(getFileContents(mJsonRootPath) + HG_SERVER_KEY)); - result.append(getMD5Hash(luaScriptContents + HG_SERVER_KEY)); + string toEncrypt{""}; + toEncrypt.append(mLevelId); + toEncrypt.append(toStr(mDifficultyMultiplier)); + toEncrypt.append(getFileContents(mLevelRootPath)); + toEncrypt.append(getFileContents(mStyleRootPath)); + toEncrypt.append(luaScriptContents); for(auto& luaScriptName : luaScriptNames) { string path{mPackPath + "/Scripts/" + luaScriptName}; string contents{getFileContents(path)}; - string hash{getMD5Hash(contents + HG_SERVER_KEY)}; - string compressedHash{""}; - - for(unsigned int i{0}; i < hash.length(); ++i) if(i % 3 == 0) compressedHash.append(toStr(hash[i])); - - result.append(compressedHash); + toEncrypt.append(contents); } - result.append(getUrlEncoded(toStr(mDifficultyMultiplier))); + toEncrypt = getControlStripped(toEncrypt); + string result{getUrlEncoded(mLevelId) + getMD5Hash(toEncrypt + HG_SERVER_KEY)}; return result; } string get181Validator(const string& mPackPath, const string& mLevelId, const string& mJsonRootPath, const string& mLuaScriptPath, float mDifficultyMultiplier) diff --git a/Online/Online.h b/Online/Online.h index 7e89afa6a..33ff0eae7 100644 --- a/Online/Online.h +++ b/Online/Online.h @@ -20,7 +20,7 @@ namespace hg std::string getServerMessage(); Json::Value getScores(const std::string& mValidator); std::string getMD5Hash(const std::string& mString); - std::string getValidator(const std::string& mPackPath, const std::string& mLevelId, const std::string& mJsonRootPath, const std::string& mLuaScriptPath, float mDifficultyMultiplier); + std::string getValidator(const std::string& mPackPath, const std::string& mLevelId, const std::string& mLevelRootPath, const std::string& mStyleRootPath, const std::string& mLuaScriptPath, float mDifficultyMultiplier); std::string get181Validator(const std::string& mPackPath, const std::string& mLevelId, const std::string& mJsonRootPath, const std::string& mLuaScriptPath, float mDifficultyMultiplier); } }