Implemented EncodeURI stub function.

pull/28/head
sigonasr2 11 months ago
parent 57f0b84dff
commit fc9d9590d3
  1. 1
      Crawler/Crawler.vcxproj
  2. 3
      Crawler/Crawler.vcxproj.filters
  3. 2
      Crawler/LoadFileButton.h
  4. 2
      Crawler/MainMenuWindow.cpp
  5. 2
      Crawler/MenuComponent.cpp
  6. 2
      Crawler/MenuComponent.h
  7. 46
      Crawler/SaveFile.cpp
  8. 8
      Crawler/TextEntryLabel.h
  9. 2
      Crawler/Version.h
  10. 12
      Crawler/olcPixelGameEngine.h

@ -300,6 +300,7 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\Downloads\olcPixelGameEngine (1).h" />
<ClInclude Include="Ability.h" />
<ClInclude Include="Animation.h" />
<ClInclude Include="Attributable.h" />

@ -402,6 +402,9 @@
<ClInclude Include="olcPGEX_SplashScreen.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\Downloads\olcPixelGameEngine (1).h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Player.cpp">

@ -64,7 +64,7 @@ public:
animationTime+=game->GetElapsedTime();
}
inline void DrawDecal(ViewPort&window,bool focused){
inline void DrawDecal(ViewPort&window,bool focused)override{
MenuComponent::DrawDecal(window,focused);
if(playTime==-1){

@ -48,10 +48,10 @@ void Menu::InitializeMainMenuWindow(){
Menu*mainMenuWindow=CreateMenu(MAIN_MENU,CENTERED,vi2d{96,96});
mainMenuWindow->ADD("New Game Button",MenuComponent)({{12,4},{72,24}},"New Game",[&](MenuFuncData data){
game->TextEntryEnable(true);
#ifdef __EMSCRIPTEN__
data.menu.S(A::NEXT_MENU)="New Game";
if(SaveFile::GetUserID().length()==0){
game->TextEntryEnable(true);
Menu::OpenMenu(USER_ID);
}else{
Menu::OpenMenu(SAVE_FILE_NAME);

@ -195,7 +195,7 @@ const vf2d&MenuComponent::GetSize()const{
return rect.size;
}
std::string MenuComponent::GetLabel(){
const std::string&MenuComponent::GetLabel()const{
return label;
}

@ -142,7 +142,7 @@ public:
virtual bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
//Called whenever equipment and base stats are updated, notifying a component that numbers that may be displayed have changed.
virtual void OnEquipStatsUpdate();
std::string GetLabel();
virtual const std::string&GetLabel()const;
std::string GetName();
virtual void SetSelected(bool selected)final;
virtual void SetSelectionType(SelectionType selectionType)final;

@ -209,7 +209,25 @@ const std::string SaveFile::CreateServerRequest(const SaveFileOperation::Operati
auto CalculateChecksum=[](std::string_view operation,std::string_view data){
return username.length()*8+data.length()*2+operation.length();
};
std::string dataString=std::format("?username={}",username);
auto EncodeURI=[](std::string str){
return std::accumulate(str.begin(),str.end(),""s,[](std::string str,const char&c){
/*
* Implementation Source: https://262.ecma-international.org/5.1/#sec-15.1.3.4
uriReserved ::: one of
; / ? : @ & = + $ ,
uriMark ::: one of
- _ . ! ~ * ' ( )
Let unescapedURISet be a String containing one instance of each character valid in uriReserved and uriUnescaped plus #.
*/
const std::array uriReserved={';','/','?',':','@','&','=','+','$',',','-','_','.','!','~','*','\'','(',')','#'};
if(c>='A'&&c<='Z'||c>='a'&&c<='z'||c>='0'&&c<='9'||std::find(uriReserved.begin(),uriReserved.end(),c)!=uriReserved.end())return std::move(str)+c;
std::string convertedChar=std::format("%{:02x}",c);
std::for_each(convertedChar.begin(),convertedChar.end(),[](char&c){c=char(std::toupper(c));});
return std::move(str)+convertedChar;
});
};
std::string dataString=std::format("\"username\":\"{}\"",EncodeURI(username));
std::string operationName="";
switch(operation){
case SaveFileOperation::GET_LOAD_FILES:{
@ -229,35 +247,41 @@ const std::string SaveFile::CreateServerRequest(const SaveFileOperation::Operati
//Data should contain the entire contents of our metadata save file.
}break;
}
dataString+="&operation="+operationName;
dataString+="&checksum="+std::to_string(CalculateChecksum(operationName,data));
dataString+="&data="+std::string(data);
return "save_server"_S+dataString;
dataString+=",\"operation\":\""+EncodeURI(operationName)+"\"";
dataString+=",\"checksum\":\""+EncodeURI(std::to_string(CalculateChecksum(operationName,data)))+"\"";
dataString+=",\"data\":\""+EncodeURI(std::string(data))+"\"";
return "{"+dataString+"}";
}
const void SaveFile::Server_GetLoadInfo(std::function<void(std::string_view)>respCallbackFunc){
game->SendRequest(CreateServerRequest(SaveFileOperation::GET_LOAD_FILES,"0"),"");
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::GET_LOAD_FILES,"0"));
game->responseCallback=respCallbackFunc;
}
const void SaveFile::Server_GetFile(std::function<void(std::string_view)>respCallbackFunc){
game->SendRequest(CreateServerRequest(SaveFileOperation::GET_FILE,std::to_string(saveFileID)),"");
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::GET_FILE,std::to_string(saveFileID)));
game->responseCallback=respCallbackFunc;
}
const void SaveFile::Server_SaveFile(std::function<void(std::string_view)>respCallbackFunc){
std::stringstream fileContents;
std::ifstream file("save_file_path"_S+std::format("save.{:04}",saveFileID));
while(file.good()){
fileContents<<char(file.get());
int val=file.get();
if(val!=-1){
fileContents<<char(val);
}
}
game->SendRequest(CreateServerRequest(SaveFileOperation::SAVE_FILE,std::to_string(saveFileID)+"|"+fileContents.str()),"");
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::SAVE_FILE,std::to_string(saveFileID)+"|"+fileContents.str()));
game->responseCallback=respCallbackFunc;
}
const void SaveFile::Server_SaveMetadataFile(std::function<void(std::string_view)>respCallbackFunc){
std::stringstream fileContents;
std::ifstream file("save_file_path"_S+"metadata.dat");
while(file.good()){
fileContents<<char(file.get());
int val=file.get();
if(val!=-1){
fileContents<<char(val);
}
}
game->SendRequest(CreateServerRequest(SaveFileOperation::SAVE_METADATA_FILE,fileContents.str()),"");
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::SAVE_METADATA_FILE,fileContents.str()));
game->responseCallback=respCallbackFunc;
}

@ -76,4 +76,12 @@ public:
}
}
}
inline const std::string&GetLabel()const override{
if(censored){
return game->TextEntryGetString();
}else{
MenuLabel::GetLabel();
}
}
};

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 5287
#define VERSION_BUILD 5293
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -1205,7 +1205,7 @@ namespace olc
// Text Entry Routines
void TextEntryEnable(const bool bEnable, const std::string& sText = "");
std::string TextEntryGetString() const;
const std::string&TextEntryGetString() const;
int32_t TextEntryGetCursor() const;
bool IsTextEntryEnabled() const;
void TextEntrySetCharLimit(const uint8_t charLimit);
@ -4294,7 +4294,7 @@ namespace olc
}
}
std::string PixelGameEngine::TextEntryGetString() const
const std::string&PixelGameEngine::TextEntryGetString() const
{ return sTextEntryString; }
int32_t PixelGameEngine::TextEntryGetCursor() const
@ -7217,14 +7217,18 @@ namespace olc
virtual olc::rcode SendRequest(std::string_view url,std::string_view data)override{
EM_ASM({
requestResp="";
fetch(UTF8ToString($0)).then((resp)=>{
fetch(UTF8ToString($0),{
headers: {
"Content-Type": "application/json",
},
method: "POST",body:UTF8ToString($1)}).then((resp)=>{
if(resp.ok){
resp.text();
}
throw new Error(resp.text());
}).then((data)=>{requestResp=data;})
.catch((err)=>{requestResp="ERR";});
},std::string(url).c_str());
},std::string(url).c_str(),std::string(data).c_str());
return olc::rcode::OK;
}

Loading…
Cancel
Save