Added more error returns on auth fail

This commit is contained in:
Anonymous275 2020-12-22 17:12:38 +02:00
parent 5630624757
commit b7ffa153b1
2 changed files with 12 additions and 4 deletions

View File

@ -32,16 +32,23 @@ void UpdateKey(const char* newKey){
/// "Guest":"Name" /// "Guest":"Name"
/// "pk":"private_key" /// "pk":"private_key"
std::string GetFail(const std::string& R){
static std::string DRet = R"({"success":false,"message":)";
DRet += "\""+R+"\"}";
error(R);
return DRet;
}
std::string Login(const std::string& fields){ std::string Login(const std::string& fields){
info("Attempting to authenticate..."); info("Attempting to authenticate...");
std::string Buffer = PostHTTP("https://auth.beammp.com/userlogin", fields); std::string Buffer = PostHTTP("https://auth.beammp.com/userlogin", fields);
json::Document d; json::Document d;
d.Parse(Buffer.c_str()); d.Parse(Buffer.c_str());
if(Buffer == "-1"){ if(Buffer == "-1"){
fatal("Failed to communicate with the auth system!"); return GetFail("Failed to communicate with the auth system!");
} }
if (Buffer.find('{') == -1 || d.HasParseError()) { if (Buffer.find('{') == -1 || d.HasParseError()) {
fatal("Invalid answer from authentication servers, please try again later!"); return GetFail("Invalid answer from authentication servers, please try again later!");
} }
if(!d["success"].IsNull() && d["success"].GetBool()){ if(!d["success"].IsNull() && d["success"].GetBool()){
LoginAuth = true; LoginAuth = true;
@ -61,7 +68,7 @@ std::string Login(const std::string& fields){
d.Accept(writer); d.Accept(writer);
return buffer.GetString(); return buffer.GetString();
} }
return "{\"success\":false}"; return GetFail("Invalid message parsing!");
} }
void CheckLocalKey(){ void CheckLocalKey(){

View File

@ -27,7 +27,7 @@ std::string GetVer(){
return "1.80"; return "1.80";
} }
std::string GetPatch(){ std::string GetPatch(){
return ""; return ".1";
} }
void ReLaunch(int argc,char*args[]){ void ReLaunch(int argc,char*args[]){
std::string Arg; std::string Arg;
@ -182,6 +182,7 @@ void InitLauncher(int argc, char* argv[]) {
CheckName(argc, argv); CheckName(argc, argv);
CheckLocalKey(); //will replace RequestRole CheckLocalKey(); //will replace RequestRole
Discord_Main(); Discord_Main();
//Dev = true;
//RequestRole(); //RequestRole();
CustomPort(argc, argv); CustomPort(argc, argv);
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch()); CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());