mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-05 07:16:29 +00:00
added discord-rpc
This commit is contained in:
2
.github/workflows/cmake-windows.yml
vendored
2
.github/workflows/cmake-windows.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
uses: lukka/run-vcpkg@v7
|
||||
id: runvcpkg
|
||||
with:
|
||||
vcpkgArguments: 'discord-rpc zlib rapidjson openssl'
|
||||
vcpkgArguments: 'zlib openssl'
|
||||
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||
vcpkgGitCommitId: '75522bb1f2e7d863078bcd06322348f053a9e33f'
|
||||
vcpkgTriplet: 'x64-windows-static'
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -13,3 +13,6 @@
|
||||
[submodule "include/easyloggingpp"]
|
||||
path = include/easyloggingpp
|
||||
url = https://github.com/amrayn/easyloggingpp.git
|
||||
[submodule "include/discord-rpc"]
|
||||
path = include/discord-rpc
|
||||
url = https://github.com/discord/discord-rpc.git
|
||||
|
||||
@@ -16,6 +16,7 @@ if (WIN32)
|
||||
endif(WIN32)
|
||||
|
||||
set(wxUSE_STL ON)
|
||||
set(BUILD_EXAMPLES OFF)
|
||||
set(wxBUILD_SHARED OFF)
|
||||
set(build_static_lib ON)
|
||||
set(wxBUILD_MSVC_MULTIPROC ON)
|
||||
@@ -23,6 +24,7 @@ set(wxBUILD_USE_STATIC_RUNTIME ON)
|
||||
|
||||
add_subdirectory(include/wxWidgets)
|
||||
add_subdirectory(include/rapidjson)
|
||||
add_subdirectory(include/discord-rpc)
|
||||
add_subdirectory(include/cpp-httplib)
|
||||
add_subdirectory(include/tomlplusplus)
|
||||
|
||||
@@ -38,15 +40,13 @@ add_executable(${PROJECT_NAME}
|
||||
src/gui/gifs.cpp src/gui/gifs.h
|
||||
src/Network/Http.cpp include/Http.h
|
||||
src/Login.cpp src/Config.cpp
|
||||
src/Discord.cpp
|
||||
)
|
||||
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/lib/discord-rpc.lib
|
||||
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32 wx::net wx::core wx::base)
|
||||
elseif (UNIX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s")
|
||||
target_link_libraries(${PROJECT_NAME} wx::net wx::core wx::base)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
ZLIB::ZLIB discord-rpc OpenSSL::SSL OpenSSL::Crypto ws2_32 wx::net wx::core wx::base)
|
||||
else(WIN32) #MINGW
|
||||
add_definitions("-D_WIN32_WINNT=0x0600")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
||||
|
||||
@@ -5,27 +5,36 @@
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
class Launcher {
|
||||
public: //constructors
|
||||
Launcher(int argc, char* argv[]);
|
||||
~Launcher();
|
||||
public: //available functions
|
||||
std::string Login(const std::string& fields);
|
||||
void checkLocalKey();
|
||||
void runDiscordRPC();
|
||||
void loadConfig();
|
||||
void launchGame();
|
||||
void checkKey();
|
||||
public: //Getters
|
||||
const std::string& getFullVersion();
|
||||
const std::string& getWorkingDir();
|
||||
const std::string& getUserRole();
|
||||
const std::string& getVersion();
|
||||
private: //functions
|
||||
void richPresence();
|
||||
void WindowsInit();
|
||||
private: //variables
|
||||
std::string DirPath;
|
||||
std::string UserRole;
|
||||
std::string PublicKey;
|
||||
bool EnableUI = true;
|
||||
bool Shutdown = false;
|
||||
std::string DirPath{};
|
||||
bool LoginAuth = false;
|
||||
std::string UserRole{};
|
||||
std::string PublicKey{};
|
||||
std::thread DiscordRPC{};
|
||||
std::string DiscordMessage{};
|
||||
std::string Version{"3.0"};
|
||||
std::string TargetBuild{"default"};
|
||||
std::string FullVersion{Version + ".0"};
|
||||
};
|
||||
|
||||
1
include/discord-rpc
Submodule
1
include/discord-rpc
Submodule
Submodule include/discord-rpc added at e4c0c569ec
@@ -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