mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-04 06:46:06 +00:00
Compare commits
22 Commits
new-protoc
...
add-warnin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e5fe80202 | ||
|
|
7ff4681263 | ||
|
|
3be1262b07 | ||
|
|
cfcabf31a4 | ||
|
|
5714c3de76 | ||
|
|
12711d77c7 | ||
|
|
e08a4de6db | ||
|
|
acd5f4ed09 | ||
|
|
c4e7b9a919 | ||
|
|
3db1f6773e | ||
|
|
8c9d3a5455 | ||
|
|
9dcfa1dca4 | ||
|
|
bd4cfe06b1 | ||
|
|
9c7034e401 | ||
|
|
aeb167c1e8 | ||
|
|
7967ec38e8 | ||
|
|
250be2ccdc | ||
|
|
6158069d4d | ||
|
|
b2e5b8d2d3 | ||
|
|
5db1b48e07 | ||
|
|
56dcfcc5ed | ||
|
|
7c1106a46a |
@@ -13,6 +13,8 @@ void NetReset();
|
|||||||
extern bool Dev;
|
extern bool Dev;
|
||||||
extern int ping;
|
extern int ping;
|
||||||
|
|
||||||
|
extern bool ModWarningConfirmed;
|
||||||
|
|
||||||
[[noreturn]] void CoreNetwork();
|
[[noreturn]] void CoreNetwork();
|
||||||
extern int ProxyPort;
|
extern int ProxyPort;
|
||||||
extern int ClientID;
|
extern int ClientID;
|
||||||
@@ -46,3 +48,4 @@ void TCPClientMain(const std::string& IP,int Port);
|
|||||||
void UDPClientMain(const std::string& IP,int Port);
|
void UDPClientMain(const std::string& IP,int Port);
|
||||||
void TCPGameServer(const std::string& IP, int Port);
|
void TCPGameServer(const std::string& IP, int Port);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include "Startup.h"
|
#include "Startup.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -24,6 +25,8 @@ bool TCPTerminate = false;
|
|||||||
int DEFAULT_PORT = 4444;
|
int DEFAULT_PORT = 4444;
|
||||||
bool Terminate = false;
|
bool Terminate = false;
|
||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
|
std::string Username = "";
|
||||||
|
std::string UserRole = "";
|
||||||
std::string UlStatus;
|
std::string UlStatus;
|
||||||
std::string MStatus;
|
std::string MStatus;
|
||||||
bool ModLoaded;
|
bool ModLoaded;
|
||||||
@@ -55,6 +58,8 @@ bool IsAllowedLink(const std::string& Link) {
|
|||||||
return std::regex_search(Link,link_match, link_pattern) && link_match.position() == 0;
|
return std::regex_search(Link,link_match, link_pattern) && link_match.position() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ModWarningConfirmed = false;
|
||||||
|
|
||||||
void Parse(std::string Data,SOCKET CSocket){
|
void Parse(std::string Data,SOCKET CSocket){
|
||||||
char Code = Data.at(0), SubCode = 0;
|
char Code = Data.at(0), SubCode = 0;
|
||||||
if(Data.length() > 1)SubCode = Data.at(1);
|
if(Data.length() > 1)SubCode = Data.at(1);
|
||||||
@@ -84,6 +89,17 @@ void Parse(std::string Data,SOCKET CSocket){
|
|||||||
}
|
}
|
||||||
Data.clear();
|
Data.clear();
|
||||||
break;
|
break;
|
||||||
|
// response to "WMODS_FOUND" message, either Y (yes ok) or N (no)
|
||||||
|
case 'W': {
|
||||||
|
if (SubCode == 'Y') {
|
||||||
|
ModWarningConfirmed = true;
|
||||||
|
} else if (SubCode == 'N') {
|
||||||
|
ModWarningConfirmed = false;
|
||||||
|
NetReset();
|
||||||
|
Terminate = true;
|
||||||
|
TCPTerminate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
case 'P':
|
case 'P':
|
||||||
Data = Code + std::to_string(ProxyPort);
|
Data = Code + std::to_string(ProxyPort);
|
||||||
break;
|
break;
|
||||||
@@ -126,7 +142,16 @@ void Parse(std::string Data,SOCKET CSocket){
|
|||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
if (SubCode == 'c'){
|
if (SubCode == 'c'){
|
||||||
Data = "N{\"Auth\":"+std::to_string(LoginAuth)+"}";
|
nlohmann::json Auth = {
|
||||||
|
{"Auth", LoginAuth ? 1 : 0 },
|
||||||
|
};
|
||||||
|
if (!Username.empty()) {
|
||||||
|
Auth["username"] = Username;
|
||||||
|
}
|
||||||
|
if (!UserRole.empty()) {
|
||||||
|
Auth["role"] = UserRole;
|
||||||
|
}
|
||||||
|
Data = "N" + Auth.dump();
|
||||||
}else{
|
}else{
|
||||||
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
Data = "N" + Login(Data.substr(Data.find(':') + 1));
|
||||||
}
|
}
|
||||||
@@ -193,6 +218,10 @@ void localRes(){
|
|||||||
}
|
}
|
||||||
ConfList = new std::set<std::string>;
|
ConfList = new std::set<std::string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint64_t TheClientSocket;
|
||||||
|
|
||||||
void CoreMain() {
|
void CoreMain() {
|
||||||
debug("Core Network on start!");
|
debug("Core Network on start!");
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
@@ -241,6 +270,7 @@ void CoreMain() {
|
|||||||
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
error("(Core) accept failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
TheClientSocket = CSocket;
|
||||||
localRes();
|
localRes();
|
||||||
info("Game Connected!");
|
info("Game Connected!");
|
||||||
GameHandler(CSocket);
|
GameHandler(CSocket);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#include <future>
|
#include <future>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
extern SOCKET TheClientSocket;
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
std::string ListOfMods;
|
std::string ListOfMods;
|
||||||
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
|
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
|
||||||
@@ -221,6 +223,23 @@ void SyncResources(SOCKET Sock){
|
|||||||
std::string Ret = Auth(Sock);
|
std::string Ret = Auth(Sock);
|
||||||
if(Ret.empty())return;
|
if(Ret.empty())return;
|
||||||
|
|
||||||
|
ModWarningConfirmed = false;
|
||||||
|
Terminate = false;
|
||||||
|
|
||||||
|
std::string Data = "WMODS_FOUND";
|
||||||
|
send(TheClientSocket, (Data + "\n").c_str(), int(Data.size())+1, 0);
|
||||||
|
|
||||||
|
while (!Terminate && !ModWarningConfirmed) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModWarningConfirmed) {
|
||||||
|
UlStatus = "UlMods rejected!";
|
||||||
|
info("Mods rejected by user!");
|
||||||
|
// game has already cancelled by now
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
info("Checking Resources...");
|
info("Checking Resources...");
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ namespace fs = std::filesystem;
|
|||||||
std::string PublicKey;
|
std::string PublicKey;
|
||||||
std::string PrivateKey;
|
std::string PrivateKey;
|
||||||
extern bool LoginAuth;
|
extern bool LoginAuth;
|
||||||
std::string Role;
|
extern std::string Username;
|
||||||
|
extern std::string UserRole;
|
||||||
|
|
||||||
void UpdateKey(const char* newKey){
|
void UpdateKey(const char* newKey){
|
||||||
if(newKey && std::isalnum(newKey[0])){
|
if(newKey && std::isalnum(newKey[0])){
|
||||||
@@ -45,39 +46,51 @@ std::string GetFail(const std::string& R){
|
|||||||
|
|
||||||
std::string Login(const std::string& fields){
|
std::string Login(const std::string& fields){
|
||||||
if(fields == "LO"){
|
if(fields == "LO"){
|
||||||
|
Username = "";
|
||||||
|
UserRole = "";
|
||||||
LoginAuth = false;
|
LoginAuth = false;
|
||||||
UpdateKey(nullptr);
|
UpdateKey(nullptr);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
info("Attempting to authenticate...");
|
info("Attempting to authenticate...");
|
||||||
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
try {
|
||||||
|
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
||||||
|
|
||||||
if(Buffer == "-1"){
|
if(Buffer == "-1"){
|
||||||
return GetFail("Failed to communicate with the auth system!");
|
return GetFail("Failed to communicate with the auth system!");
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
|
||||||
|
|
||||||
if (Buffer.at(0) != '{' || d.is_discarded()) {
|
|
||||||
error(Buffer);
|
|
||||||
return GetFail("Invalid answer from authentication servers, please try again later!");
|
|
||||||
}
|
|
||||||
if(d.contains("success") && d["success"].get<bool>()){
|
|
||||||
LoginAuth = true;
|
|
||||||
if(!d.contains("private_key")) {
|
|
||||||
UpdateKey(d["private_key"].get<std::string>().c_str());
|
|
||||||
}
|
}
|
||||||
if(!d.contains("public_key")){
|
|
||||||
PublicKey = d["public_key"].get<std::string>();
|
nlohmann::json d = nlohmann::json::parse(Buffer, nullptr, false);
|
||||||
|
|
||||||
|
if (Buffer.at(0) != '{' || d.is_discarded()) {
|
||||||
|
error(Buffer);
|
||||||
|
return GetFail("Invalid answer from authentication servers, please try again later!");
|
||||||
}
|
}
|
||||||
info("Authentication successful!");
|
if(d.contains("success") && d["success"].get<bool>()){
|
||||||
}else info("Authentication failed!");
|
LoginAuth = true;
|
||||||
if(!d.contains("message")){
|
if (d.contains("username")) {
|
||||||
d.erase("private_key");
|
Username = d["username"].get<std::string>();
|
||||||
d.erase("public_key");
|
}
|
||||||
return d.dump();
|
if (d.contains("role")) {
|
||||||
|
UserRole = d["role"].get<std::string>();
|
||||||
|
}
|
||||||
|
if(d.contains("private_key")) {
|
||||||
|
UpdateKey(d["private_key"].get<std::string>().c_str());
|
||||||
|
}
|
||||||
|
if(d.contains("public_key")){
|
||||||
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
|
}
|
||||||
|
info("Authentication successful!");
|
||||||
|
}else info("Authentication failed!");
|
||||||
|
if(d.contains("message")){
|
||||||
|
d.erase("private_key");
|
||||||
|
d.erase("public_key");
|
||||||
|
return d.dump();
|
||||||
|
}
|
||||||
|
return GetFail("Invalid message parsing!");
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
return GetFail(e.what());
|
||||||
}
|
}
|
||||||
return GetFail("Invalid message parsing!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckLocalKey(){
|
void CheckLocalKey(){
|
||||||
@@ -109,7 +122,12 @@ void CheckLocalKey(){
|
|||||||
LoginAuth = true;
|
LoginAuth = true;
|
||||||
UpdateKey(d["private_key"].get<std::string>().c_str());
|
UpdateKey(d["private_key"].get<std::string>().c_str());
|
||||||
PublicKey = d["public_key"].get<std::string>();
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
Role = d["role"].get<std::string>();
|
if (d.contains("username")) {
|
||||||
|
Username = d["username"].get<std::string>();
|
||||||
|
}
|
||||||
|
if (d.contains("role")) {
|
||||||
|
UserRole = d["role"].get<std::string>();
|
||||||
|
}
|
||||||
//info(Role);
|
//info(Role);
|
||||||
}else{
|
}else{
|
||||||
info("Auto-Authentication unsuccessful please re-login!");
|
info("Auto-Authentication unsuccessful please re-login!");
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ std::string GetVer(){
|
|||||||
return "2.0";
|
return "2.0";
|
||||||
}
|
}
|
||||||
std::string GetPatch(){
|
std::string GetPatch(){
|
||||||
return ".84";
|
return ".85";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetEP(char*P){
|
std::string GetEP(char*P){
|
||||||
|
|||||||
Reference in New Issue
Block a user