mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-12 02:36:01 +00:00
added discord-rpc
This commit is contained in:
@@ -11,27 +11,28 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
||||
|
||||
void Launcher::loadConfig() {
|
||||
if(fs::exists("Launcher.cfg")){
|
||||
std::ifstream cfg("Launcher.cfg");
|
||||
if(cfg.is_open()) {
|
||||
auto Size = fs::file_size("Launcher.cfg");
|
||||
std::string Buffer(Size, 0);
|
||||
cfg.read(&Buffer[0], std::streamsize(Size));
|
||||
cfg.close();
|
||||
toml::table config = toml::parse(cfg);
|
||||
LOG(INFO) << "Parsing";
|
||||
if(config["Port"].is_value()) {
|
||||
/*auto Port = config["Port"].as_integer()->get();
|
||||
LOG(INFO) << Port;*/
|
||||
LOG(INFO) << "Got port";
|
||||
}
|
||||
}else LOG(FATAL) << "Failed to open Launcher.cfg!";
|
||||
if(fs::exists("Launcher.cfg")) {
|
||||
toml::table config = toml::parse_file("Launcher.cfg");
|
||||
auto ui = config["UI"];
|
||||
auto build = config["Build"];
|
||||
if(ui.is_boolean()) {
|
||||
EnableUI = ui.as_boolean()->get();
|
||||
} else LOG(ERROR) << "Failed to get 'UI' boolean from config";
|
||||
|
||||
//Default -1 / Release 1 / EA 2 / Dev 3 / Custom 3
|
||||
if(build.is_string()) {
|
||||
TargetBuild = build.as_string()->get();
|
||||
for(char& c : TargetBuild)c = char(tolower(c));
|
||||
} else LOG(ERROR) << "Failed to get 'Build' string from config";
|
||||
|
||||
} else {
|
||||
std::ofstream cfg("Launcher.cfg");
|
||||
if(cfg.is_open()){
|
||||
cfg <<
|
||||
R"(Port = 4444
|
||||
R"(UI = true
|
||||
Build = "Default"
|
||||
)";
|
||||
cfg.close();
|
||||
|
||||
27
src/Discord.cpp
Normal file
27
src/Discord.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 1/18/22
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
|
||||
#include <discord_rpc.h>
|
||||
#include "Launcher.h"
|
||||
|
||||
void Launcher::richPresence() {
|
||||
Discord_Initialize("629743237988352010", nullptr, 1,nullptr);
|
||||
while(!Shutdown) {
|
||||
DiscordRichPresence discordPresence;
|
||||
memset(&discordPresence, 0, sizeof(discordPresence));
|
||||
if(DiscordMessage.empty()) DiscordMessage = "Playing with friends!";
|
||||
discordPresence.state = DiscordMessage.c_str();
|
||||
discordPresence.startTimestamp = 0;
|
||||
discordPresence.largeImageKey = "mainlogo";
|
||||
Discord_UpdatePresence(&discordPresence);
|
||||
Discord_RunCallbacks();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
Discord_ClearPresence();
|
||||
}
|
||||
|
||||
void Launcher::runDiscordRPC() {
|
||||
DiscordRPC = std::thread(&Launcher::richPresence, this);
|
||||
}
|
||||
@@ -15,6 +15,12 @@ Launcher::Launcher(int argc, char* argv[]) : DirPath(argv[0]) {
|
||||
WindowsInit();
|
||||
}
|
||||
|
||||
Launcher::~Launcher() {
|
||||
if(DiscordRPC.joinable()) {
|
||||
DiscordRPC.join();
|
||||
}
|
||||
}
|
||||
|
||||
void Launcher::launchGame() {
|
||||
ShellExecuteA(nullptr, nullptr, "steam://rungameid/284160", nullptr, nullptr, SW_SHOWNORMAL);
|
||||
ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
|
||||
@@ -43,3 +49,4 @@ const std::string& Launcher::getUserRole() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ std::string Launcher::Login(const std::string& fields) {
|
||||
return GetFail("Invalid message parsing!");
|
||||
}
|
||||
|
||||
void Launcher::checkLocalKey() {
|
||||
void Launcher::checkKey() {
|
||||
if(fs::exists("key") && fs::file_size("key") < 100){
|
||||
std::ifstream Key("key");
|
||||
if(Key.is_open()) {
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
#include "Logger.h"
|
||||
int main(int argc, char* argv[]) {
|
||||
Launcher launcher(argc, argv);
|
||||
launcher.checkLocalKey();
|
||||
launcher.loadConfig();
|
||||
launcher.checkKey();
|
||||
//UI call
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user