Skip to content

Commit

Permalink
New validation system
Browse files Browse the repository at this point in the history
Old scores must be converted!
  • Loading branch information
vittorioromeo committed Mar 11, 2013
1 parent 6d0eb83 commit e6cc36f
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 28 deletions.
10 changes: 6 additions & 4 deletions Data/LevelData.cpp
Expand Up @@ -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; }
Expand Down
12 changes: 7 additions & 5 deletions Data/LevelData.h
Expand Up @@ -17,7 +17,7 @@ namespace hg
Json::Value root;
int currentPattern{-1};
std::vector<Json::Value> events;
std::string packPath, jsonRootPath, luaScriptPath;
std::string packPath, levelRootPath, styleRootPath, luaScriptPath;

public:
LevelData() = default;
Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions Data/StyleData.cpp
Expand Up @@ -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(); }
Expand Down
6 changes: 5 additions & 1 deletion Data/StyleData.h
Expand Up @@ -15,6 +15,7 @@ namespace hg
private:
Json::Value root;
float currentHue, currentSwapTime, pulseFactor{0};
std::string rootPath;

public:
StyleData() = default;
Expand All @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions Global/Assets.cpp
Expand Up @@ -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));
}
}
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion HexagonGame.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion MenuGame.cpp
Expand Up @@ -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()
Expand Down
23 changes: 10 additions & 13 deletions Online/Online.cpp
Expand Up @@ -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<string> 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)
Expand Down
2 changes: 1 addition & 1 deletion Online/Online.h
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit e6cc36f

Please sign in to comment.