mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-16 00:06:41 +00:00
added new log prefix, ready for new system
This commit is contained in:
parent
f858c462af
commit
fa31090143
@ -6,6 +6,7 @@
|
||||
#include <iostream>
|
||||
void InitLog();
|
||||
void except(const std::string& toPrint);
|
||||
void fatal(const std::string& toPrint);
|
||||
void debug(const std::string& toPrint);
|
||||
void error(const std::string& toPrint);
|
||||
void info(const std::string& toPrint);
|
||||
|
@ -20,16 +20,12 @@ std::string Write(const std::string&Path){
|
||||
LPCTSTR sk = Sec("Software\\BeamNG\\BeamNG.drive");
|
||||
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||
if (openRes != ERROR_SUCCESS){
|
||||
error(Sec("Please launch the game at least once"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
exit(5);
|
||||
fatal(Sec("Please launch the game at least once"));
|
||||
}
|
||||
std::string Query = QueryKey(hKey,4);
|
||||
LONG setRes = RegSetValueEx(hKey, Sec("userpath_override"), 0, REG_SZ, (LPBYTE)Path.c_str(), DWORD(Path.size()));
|
||||
if(setRes != ERROR_SUCCESS){
|
||||
error(Sec("Failed to launch the game"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
exit(5);
|
||||
fatal(Sec("Failed to launch the game")); //not fatal later
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
return Query;
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
std::string getDate() {
|
||||
typedef std::chrono::duration<int, std::ratio_multiply<std::chrono::hours::period, std::ratio<24>>::type> days;
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
@ -70,6 +72,13 @@ void error(const std::string& toPrint) {
|
||||
std::cout << Print;
|
||||
addToLog(Print);
|
||||
}
|
||||
void fatal(const std::string& toPrint) {
|
||||
std::string Print = getDate() + Sec("[FATAL] ") + toPrint + "\n";
|
||||
std::cout << Print;
|
||||
addToLog(Print);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
_Exit(-1);
|
||||
}
|
||||
void except(const std::string& toPrint) {
|
||||
std::string Print = getDate() + Sec("[EXCEP] ") + toPrint + "\n";
|
||||
std::cout << Print;
|
||||
|
@ -3,24 +3,64 @@
|
||||
///
|
||||
|
||||
#include "Curl/http.h"
|
||||
#include <iostream>
|
||||
#include "Logger.h"
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#include <filesystem>
|
||||
|
||||
//check file if not present flag for login to the core network
|
||||
//to then get user and pass
|
||||
//if present use to contact the backend to refresh and get a public key for servers
|
||||
//public keys are one time use for a random server
|
||||
|
||||
using namespace std::filesystem;
|
||||
|
||||
void UpdateKey(const char* newKey){
|
||||
if(newKey){
|
||||
std::ofstream Key("key");
|
||||
if(Key.is_open()){
|
||||
Key << newKey;
|
||||
Key.close();
|
||||
}else fatal("Cannot write to disk!");
|
||||
}else if(exists("key")){
|
||||
remove("key");
|
||||
}
|
||||
}
|
||||
|
||||
void AskUser(){
|
||||
//Flag Core Network Update to have a login screen
|
||||
}
|
||||
|
||||
/// "username":"password"
|
||||
/// "Guest":"Name"
|
||||
/// "pk":"private_key"
|
||||
|
||||
|
||||
///TODO: test with no internet connection
|
||||
void CheckLocalKey(){
|
||||
for(int C = 1; C <= 10; C++) {
|
||||
std::cout << PostHTTP("https://auth.beammp.com/userlogin", R"({"username":"Anonymous275", "password":"SimonAS1482001"})") << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
if(exists("key") && file_size("key") < 100){
|
||||
std::ifstream Key("key");
|
||||
if(Key.is_open()) {
|
||||
auto Size = file_size("key");
|
||||
std::string Buffer(Size, 0);
|
||||
Key.read(&Buffer[0], Size);
|
||||
Key.close();
|
||||
|
||||
std::cout << "Key : " << Buffer << std::endl;
|
||||
Buffer = PostHTTP("https://auth.beammp.com/userlogin", R"({"username":"Anonymous275", "password":""})");
|
||||
std::cout << "Ret : " << Buffer << std::endl;
|
||||
if (Buffer == "-1" || Buffer.find('{') == -1) {
|
||||
fatal("Cannot connect to authentication servers please try again later!");
|
||||
}
|
||||
}else{
|
||||
warn("Could not open saved key!");
|
||||
UpdateKey(nullptr);
|
||||
AskUser();
|
||||
}
|
||||
}else{
|
||||
UpdateKey(nullptr);
|
||||
AskUser();
|
||||
std::cout << "No valid Key i am sad now" << std::endl;
|
||||
}
|
||||
system("pause");
|
||||
|
||||
}
|
||||
|
@ -63,9 +63,7 @@ void RequestRole(){
|
||||
if(HTTP_Result == "-1"){
|
||||
HTTP_Result = HTTP_REQUEST(Sec("https://backup1.beammp.com/entitlement?did=")+GetDID()+Sec("&t=l"),443);
|
||||
if(HTTP_Result == "-1") {
|
||||
error(Sec("Sorry Backend System Outage! Don't worry it will back on soon!"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(-1);
|
||||
fatal(Sec("Sorry Backend System Outage! Don't worry it will back on soon!"));
|
||||
}
|
||||
}
|
||||
if(HTTP_Result.find(Sec("\"MDEV\"")) != NPos || HTTP_Result.find(Sec("\"CON\"")) != NPos){
|
||||
@ -74,9 +72,7 @@ void RequestRole(){
|
||||
}
|
||||
}
|
||||
if(HTTP_Result.find(Sec("Error")) != NPos){
|
||||
error(Sec("Sorry You need to be in the official BeamMP Discord to proceed! https://discord.gg/beammp"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(-1);
|
||||
fatal(Sec("Sorry You need to be in the official BeamMP Discord to proceed! https://discord.gg/beammp"));
|
||||
}
|
||||
info(Sec("Client Connected!"));
|
||||
}
|
||||
@ -90,9 +86,7 @@ void CheckForUpdates(int argc,char*args[],const std::string& CV){
|
||||
HTTP = HTTP_REQUEST(link,443);
|
||||
fallback = true;
|
||||
if(HTTP.find_first_of("0123456789") == std::string::npos) {
|
||||
error(Sec("Primary Servers Offline! sorry for the inconvenience!"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(4));
|
||||
exit(-1);
|
||||
fatal(Sec("Primary Servers Offline! sorry for the inconvenience!"));
|
||||
}
|
||||
}
|
||||
if(fallback){
|
||||
|
Loading…
x
Reference in New Issue
Block a user