Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More "new server" work

  • Loading branch information...
commit 6f7326244e49882ce2da7551f41efac28ea32f00 1 parent 8935ddd
@SuperV1234 authored
View
2  include/SSVOpenHexagon/Core/MenuGame.h
@@ -34,7 +34,7 @@ namespace hg
std::string scoresMessage;
float exitTimer{0};
bool mustTakeScreenshot{false};
- std::string currentScores{""}, profileNewName{""};
+ std::string currentLeaderboard{""}, currentPlayerScore{""}, profileNewName{""};
sf::Sprite titleBar{getAssetManager().getTexture("titleBar.png")}, creditsBar1{getAssetManager().getTexture("creditsBar1.png")},
creditsBar2{getAssetManager().getTexture("creditsBar2.png")}, bottomBar{getAssetManager().getTexture("bottomBar.png")};
View
2  include/SSVOpenHexagon/Online/Online.h
@@ -13,7 +13,7 @@ namespace hg
{
void startCheckUpdates();
void startSendScore(const std::string& mName, const std::string& mValidator, float mDifficulty, float mScore);
- void startGetScores(std::string& mTargetString, const std::string& mName, const std::string& mValidator, float mDifficulty);
+ void startGetScores(std::string& mTargetScores, std::string& mTargetPlayerScore, const std::string& mName, const std::string& mValidator, float mDifficulty);
void cleanUp();
void terminateAll();
View
BIN  ohnewbuild.7z
Binary file not shown
View
21 src/SSVOpenHexagon/Core/MenuGame.cpp
@@ -149,6 +149,7 @@ namespace hg
hexagonGame.newGame(levelDataIds[currentIndex], true, difficultyMultipliers[difficultyMultIndex % difficultyMultipliers.size()]);
}
else if(state == s::OPTIONS) optionsMenu.executeCurrentItem();
+ else if(state == s::PROFILE_NEW) if(!profileNewName.empty()) { createProfile(profileNewName); setCurrentProfile(profileNewName); state = States::MAIN; }
}, t::SINGLE);
game.addInput({{k::F1}}, [&](float) { playSound("beep.ogg"); if(state == s::PROFILES) { profileNewName = ""; state = s::PROFILE_NEW; } }, t::SINGLE);
game.addInput({{k::F2}, {k::J}}, [&](float) { playSound("beep.ogg"); if(state == s::MAIN ) { profileNewName = ""; state = s::PROFILES; } }, t::SINGLE);
@@ -161,6 +162,7 @@ namespace hg
game.addInput({{k::Escape}}, [&](float mFrameTime) { if(state != s::OPTIONS) exitTimer += mFrameTime; });
game.addInput({{k::F12}}, [&](float){ mustTakeScreenshot = true; }, t::SINGLE);
game.addInput({{k::LAlt, k::Return}}, [&](float){ setFullscreen(window, !window.getFullscreen()); }, t::SINGLE);
+ game.addInput({{k::BackSpace}}, [&](float){ if(state == s::PROFILE_NEW && !profileNewName.empty()) profileNewName.erase(profileNewName.end() - 1); }, t::SINGLE);
}
void MenuGame::setIndex(int mIndex)
@@ -183,14 +185,14 @@ namespace hg
if(state != States::MAIN) return;
float difficultyMult{difficultyMultipliers[difficultyMultIndex % difficultyMultipliers.size()]};
string validator{Online::getValidator(levelData.getPackPath(), levelData.getId(), levelData.getLevelRootPath(), levelData.getStyleRootPath(), levelData.getLuaScriptPath())};
- Online::startGetScores(currentScores, getCurrentProfile().getName(), validator, difficultyMult);
+ Online::startGetScores(currentLeaderboard, currentPlayerScore, getCurrentProfile().getName(), validator, difficultyMult);
}
string MenuGame::getLeaderboard()
{
- if(currentScores == "") return "refreshing...";
+ if(currentLeaderboard == "" || currentPlayerScore == "") return "refreshing...";
unsigned int leaderboardRecordCount{8};
- Json::Value root{getRootFromString(currentScores)};
+ Json::Value root{getRootFromString(currentLeaderboard)};
using RecordPair = pair<string, float>;
vector<RecordPair> recordPairs;
@@ -242,18 +244,7 @@ namespace hg
if(state == States::PROFILE_NEW)
{
- Event e;
- while(window.getRenderWindow().pollEvent(e))
- if(e.type == Event::TextEntered)
- {
- if(e.text.unicode > 47 && e.text.unicode < 126 && profileNewName.size() < 16)
- {
- char c{static_cast<char>(e.text.unicode)};
- if(isalnum(c)) { playSound("beep.ogg"); profileNewName.append(toStr(c)); }
- }
- else if(e.text.unicode == 8 && !profileNewName.empty()) profileNewName.erase(profileNewName.end() - 1);
- else if(e.text.unicode == 13 && !profileNewName.empty()) { createProfile(profileNewName); setCurrentProfile(profileNewName); state = States::MAIN; }
- }
+ for(auto& c : game.getEnteredChars()) if(profileNewName.size() < 16 && isalnum(c)) { playSound("beep.ogg"); profileNewName.append(toStr(c)); }
}
else if(state == States::PROFILES) { profileNewName = getProfileNames()[profileIndex % getProfileNames().size()]; }
else if(state == States::MAIN) { styleData.update(mFrameTime); backgroundCamera.rotate(levelData.getRotationSpeed() * 10 * mFrameTime); }
View
70 src/SSVOpenHexagon/Online/Online.cpp
@@ -30,6 +30,9 @@ namespace hg
using Response = Http::Response;
using Status = Http::Response::Status;
+ const IpAddress hostIp{"209.236.124.147"};
+ const unsigned short hostPort{27272};
+
const string host{"http://vittorioromeo.info"};
const string folder{"Misc/Linked/OHServer/"};
const string infoFile{"OHInfo.json"};
@@ -107,101 +110,82 @@ namespace hg
ThreadWrapper& thread = memoryManager.create([=]
{
- log("Sending score to server...", "Online");
+ log("Submitting score...", "Online");
string scoreString{toStr(mScore)};
- //string body{"n=" + mName + "&v=" + mValidator + "&s=" + scoreString + "&k=" + HG_ENCRYPTIONKEY};
+ TcpSocket socket;
Packet packet0x00, packet0x10;
packet0x00 << int8_t{0x00} << (string)mValidator << (float)mDifficulty << (string)mName << (float)mScore << (string)HG_ENCRYPTIONKEY;
- TcpSocket socket;
- socket.connect("209.236.124.147", 27272);
+ socket.connect(hostIp, hostPort);
socket.send(packet0x00);
socket.receive(packet0x10);
uint8_t packetID, pass;
if(packet0x10 >> packetID >> pass)
{
- if(packetID == 0x10)
- {
- if(pass == 0) cout << "Successfully submitted score!";
- else cout << "Oops! Something went wrong!";
- }
+ if(packetID == 0x10 && pass == 0) log("Score successfully sumbitted", "Online");
+ else log("Error: could not submit score", "Online");
}
socket.disconnect();
- //Response response{getPostResponse(host, folder, sendScoreFile, body)};
- //Status status{response.getStatus()};
-
- //if(status == Response::Ok) log("Score sent successfully: " + mName + ", " + scoreString, "Online");
- //else log("Send score error: " + status, "Online");
-
- //log("Finished sending score", "Online"); log(""); log(response.getBody(), "Server Message");
+ log("Finished submitting score", "Online");
startCheckScores();
cleanUp();
});
ThreadWrapper& checkThread = memoryManager.create([&thread]
{
- log("Checking if score can be sent...", "Online");
+ log("Checking score submission validity...", "Online");
while(serverVersion == -1)
{
- log("Can't send score to server - version not checked, retrying...", "Online");
+ log("Can't submit score - version not checked, retrying...", "Online");
sleep(seconds(5)); startCheckUpdates();
}
if(serverVersion > getVersion()) { log("Can't send score to server - version outdated", "Online"); return; }
- log("Score can be sent - sending", "Online");
+ log("Score submission valid - submitting", "Online");
thread.launch();
cleanUp();
});
checkThread.launch();
}
- void startGetScores(string& mTargetString, const string& mName, const string& mValidator, float mDifficulty)
+ void startGetScores(string& mTargetScores, string& mTargetPlayerScore, const string& mName, const string& mValidator, float mDifficulty)
{
if(!getOnline()) { log("Online disabled, aborting", "Online"); return; }
- ThreadWrapper& thread = memoryManager.create([=, &mTargetString]
+ ThreadWrapper& thread = memoryManager.create([=, &mTargetScores, &mTargetPlayerScore]
{
- mTargetString = "";
+ mTargetScores = "";
+ mTargetPlayerScore = "";
log("Getting scores from server...", "Online");
+ TcpSocket socket;
Packet packet0x01, packet0x11;
packet0x01 << int8_t{0x01} << (string)mValidator << (float)mDifficulty << (string)mName;
- TcpSocket socket;
- socket.connect("209.236.124.147", 27272);
+ socket.connect(hostIp, hostPort);
socket.send(packet0x01);
socket.receive(packet0x11);
uint8_t packetID, pass;
string response[2];
-
if(packet0x11 >> packetID >> pass)
{
- if(pass == 0)
+ if(packetID == 0x11 && pass == 0)
{
- if(packet0x11 >> response[0] >> response[1]) cout << "Received scores!" << endl << response[0]<< endl << response[1] << endl;
- else cout<<"Oops! Something went wrong with getting the scores!";
+ if(packet0x11 >> response[0] >> response[1])
+ {
+ cout << "Received scores!" << endl << response[0]<< endl << response[1] << endl;
+ mTargetScores = response[0];
+ mTargetPlayerScore = response[1];
+ }
+ else log("Error: could not get scores", "Online");
}
- else cout<<"Oops! Something went wrong with getting the scores!";
+ else log("Error: could not get scores", "Online");
}
socket.disconnect();
-
-
-
- //string body{"v=" + mValidator};
- //Response response{getPostResponse(host, folder, getScoresFile, body)};
- //Status status{response.getStatus()};
-
- //if(status == Response::Ok)
- //{
- // log("Scores got successfully", "Online");
- // mTargetString = response.getBody();
- //}
- //else log("Get scores error: " + status, "Online");
-
log("Finished getting scores", "Online");
cleanUp();
});
Please sign in to comment.
Something went wrong with that request. Please try again.