Cleanup + mod sync rewrite

This commit is contained in:
Anonymous275 2020-07-02 20:43:34 +03:00
parent 04b5b13ef9
commit c8bddb0d3e
11 changed files with 138 additions and 123 deletions

View File

@ -16,11 +16,12 @@ extern std::string MStatus;
extern int ping; extern int ping;
extern bool Terminate; extern bool Terminate;
extern bool TCPTerminate; extern bool TCPTerminate;
extern bool MPDEV; extern bool Dev;
extern std::string ListOfMods; extern std::string ListOfMods;
bool Confirm = false; bool Confirm = false;
std::set<std::string> Conf; std::set<std::string> Conf;
void StartSync(const std::string &Data){ void StartSync(const std::string &Data){
UlStatus = "UlLoading...";
Terminate = false; Terminate = false;
Conf.clear(); Conf.clear();
std::thread t1(ProxyThread,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1))); std::thread t1(ProxyThread,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
@ -74,11 +75,11 @@ bool once = false;
try { try {
std::cout << "Ready!" << std::endl; std::cout << "Ready!" << std::endl;
do { do {
if (MPDEV)std::cout << "Core Network on start!" << std::endl; if (Dev)std::cout << "Core Network on start!" << std::endl;
WSADATA wsaData; WSADATA wsaData;
int iResult; int iResult;
auto ListenSocket = INVALID_SOCKET; SOCKET ListenSocket;
auto ClientSocket = INVALID_SOCKET; SOCKET ClientSocket;
struct addrinfo *result = nullptr; struct addrinfo *result = nullptr;
struct addrinfo hints{}; struct addrinfo hints{};
@ -88,9 +89,9 @@ bool once = false;
int recvbuflen = 64000; int recvbuflen = 64000;
// Initialize Winsock // Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); iResult = WSAStartup(514, &wsaData); //2.2
if (iResult != 0) { if (iResult != 0) {
if (MPDEV)std::cout << "WSAStartup failed with error: " << iResult << std::endl; if (Dev)std::cout << "WSAStartup failed with error: " << iResult << std::endl;
} }
ZeroMemory(&hints, sizeof(hints)); ZeroMemory(&hints, sizeof(hints));
@ -102,14 +103,14 @@ bool once = false;
// Resolve the server address and port // Resolve the server address and port
iResult = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT).c_str(), &hints, &result); iResult = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT).c_str(), &hints, &result);
if (iResult != 0) { if (iResult != 0) {
if (MPDEV)std::cout << "(Core) getaddrinfo failed with error: " << iResult << std::endl; if (Dev)std::cout << "(Core) getaddrinfo failed with error: " << iResult << std::endl;
WSACleanup(); WSACleanup();
} }
// Create a socket for connecting to server // Create a socket for connecting to server
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (ListenSocket == INVALID_SOCKET) { if (ListenSocket == -1) {
if (MPDEV)std::cout << "(Core) socket failed with error: " << WSAGetLastError() << std::endl; if (Dev)std::cout << "(Core) socket failed with error: " << WSAGetLastError() << std::endl;
freeaddrinfo(result); freeaddrinfo(result);
WSACleanup(); WSACleanup();
} }
@ -117,7 +118,7 @@ bool once = false;
// Setup the TCP listening socket // Setup the TCP listening socket
iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen); iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if (MPDEV)Exit("(Core) bind failed with error: " + std::to_string(WSAGetLastError())); if (Dev)Exit("(Core) bind failed with error: " + std::to_string(WSAGetLastError()));
freeaddrinfo(result); freeaddrinfo(result);
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
@ -125,13 +126,13 @@ bool once = false;
iResult = listen(ListenSocket, SOMAXCONN); iResult = listen(ListenSocket, SOMAXCONN);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if (MPDEV)std::cout << "(Core) listen failed with error: " << WSAGetLastError() << std::endl; if (Dev)std::cout << "(Core) listen failed with error: " << WSAGetLastError() << std::endl;
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
} }
ClientSocket = accept(ListenSocket, nullptr, nullptr); ClientSocket = accept(ListenSocket, nullptr, nullptr);
if (ClientSocket == INVALID_SOCKET) { if (ClientSocket == -1) {
if (MPDEV)std::cout << "(Core) accept failed with error: " << WSAGetLastError() << std::endl; if (Dev)std::cout << "(Core) accept failed with error: " << WSAGetLastError() << std::endl;
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
} }
@ -149,16 +150,16 @@ bool once = false;
data.resize(iResult); data.resize(iResult);
Response = Parse(data) + "\n"; Response = Parse(data) + "\n";
} else if (iResult == 0) { } else if (iResult == 0) {
if (MPDEV)std::cout << "(Core) Connection closing...\n"; if (Dev)std::cout << "(Core) Connection closing...\n";
} else { } else {
if (MPDEV)std::cout << "(Core) recv failed with error: " << WSAGetLastError() << std::endl; if (Dev)std::cout << "(Core) recv failed with error: " << WSAGetLastError() << std::endl;
closesocket(ClientSocket); closesocket(ClientSocket);
WSACleanup(); WSACleanup();
} }
if (!Response.empty()) { if (!Response.empty()) {
iSendResult = send(ClientSocket, Response.c_str(), Response.length(), 0); iSendResult = send(ClientSocket, Response.c_str(), Response.length(), 0);
if (iSendResult == SOCKET_ERROR) { if (iSendResult == SOCKET_ERROR) {
if (MPDEV)std::cout << "send failed with error: " << WSAGetLastError() << std::endl; if (Dev)std::cout << "send failed with error: " << WSAGetLastError() << std::endl;
closesocket(ClientSocket); closesocket(ClientSocket);
WSACleanup(); WSACleanup();
} else { } else {
@ -169,7 +170,7 @@ bool once = false;
iResult = shutdown(ClientSocket, SD_SEND); iResult = shutdown(ClientSocket, SD_SEND);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if (MPDEV)std::cout << "(Core) shutdown failed with error: " << WSAGetLastError() << std::endl; if (Dev)std::cout << "(Core) shutdown failed with error: " << WSAGetLastError() << std::endl;
closesocket(ClientSocket); closesocket(ClientSocket);
WSACleanup(); WSACleanup();
Sleep(500); Sleep(500);

View File

@ -11,7 +11,7 @@
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include <vector> #include <vector>
extern bool MPDEV; extern bool Dev;
static const char* APPLICATION_ID = "629743237988352010"; static const char* APPLICATION_ID = "629743237988352010";
static int64_t StartTime; static int64_t StartTime;
static int SendPresence = 1; static int SendPresence = 1;
@ -61,22 +61,22 @@ static void handleDiscordReady(const DiscordUser* connectedUser)
static void handleDiscordDisconnected(int errcode, const char* message) static void handleDiscordDisconnected(int errcode, const char* message)
{ {
if(MPDEV)printf("\nDiscord: disconnected (%d: %s)\n", errcode, message); if(Dev)printf("\nDiscord: disconnected (%d: %s)\n", errcode, message);
} }
static void handleDiscordError(int errcode, const char* message) static void handleDiscordError(int errcode, const char* message)
{ {
if(MPDEV)printf("\nDiscord: error (%d: %s)\n", errcode, message); if(Dev)printf("\nDiscord: error (%d: %s)\n", errcode, message);
} }
static void handleDiscordJoin(const char* secret) static void handleDiscordJoin(const char* secret)
{ {
if(MPDEV)printf("\nDiscord: join (%s)\n", secret); if(Dev)printf("\nDiscord: join (%s)\n", secret);
} }
static void handleDiscordSpectate(const char* secret) static void handleDiscordSpectate(const char* secret)
{ {
if(MPDEV)printf("\nDiscord: spectate (%s)\n", secret); if(Dev)printf("\nDiscord: spectate (%s)\n", secret);
} }
static void handleDiscordJoinRequest(const DiscordUser* request) static void handleDiscordJoinRequest(const DiscordUser* request)

View File

@ -5,7 +5,7 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
extern std::string MStatus; extern std::string MStatus;
extern bool MPDEV; extern bool Dev;
Memory Game; Memory Game;
std::string GameVer(HANDLE processHandle, long long Address){ std::string GameVer(HANDLE processHandle, long long Address){
//lib_Beam //lib_Beam
@ -23,7 +23,7 @@ void SetPID(DWORD PID){
Game.PID = PID; Game.PID = PID;
} }
[[noreturn]] void MemoryInit(){ [[noreturn]] void MemoryInit(){
if(Game.PID == 0 && !MPDEV)exit(4); if(Game.PID == 0 && !Dev)exit(4);
HANDLE processHandle; HANDLE processHandle;
long long ExeBase; //BeamNG.drive.x64.exe long long ExeBase; //BeamNG.drive.x64.exe
long long Lib1 = 0x180000000; //libbeamng.x64.dll Contains Vehicle Data long long Lib1 = 0x180000000; //libbeamng.x64.dll Contains Vehicle Data

View File

@ -16,16 +16,16 @@ bool Terminate = false;
bool CServer = true; bool CServer = true;
bool gameConected = false; bool gameConected = false;
SOCKET ClientSocket; SOCKET ClientSocket;
extern bool MPDEV; extern bool Dev;
int ping = 0; int ping = 0;
void GameSend(const std::string&Data){ void GameSend(const std::string&Data){
if(TCPTerminate || !gameConected || ClientSocket == -1)return; if(TCPTerminate || !gameConected || ClientSocket == -1)return;
int iSendResult = send(ClientSocket, (Data + "\n").c_str(), int(Data.length()) + 1, 0); int iSendResult = send(ClientSocket, (Data + "\n").c_str(), int(Data.length()) + 1, 0);
if (iSendResult == SOCKET_ERROR) { if (iSendResult == SOCKET_ERROR) {
if (MPDEV)std::cout << "(Proxy) send failed with error: " << WSAGetLastError() << std::endl; if (Dev)std::cout << "(Proxy) send failed with error: " << WSAGetLastError() << std::endl;
} else { } else {
if (MPDEV && Data.length() > 1000) { if (Dev && Data.length() > 1000) {
std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << std::endl; std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << std::endl;
} }
//std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << " : " << Data << std::endl; //std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << " : " << Data << std::endl;
@ -45,11 +45,11 @@ void ServerSend(const std::string&Data, bool Rel){
else TCPSend(Data); else TCPSend(Data);
}else UDPSend(Data); }else UDPSend(Data);
if (MPDEV && Data.length() > 1000) { if (Dev && Data.length() > 1000) {
std::cout << "(Launcher->Server) Bytes sent: " + std::to_string(Data.length()) + " : " std::cout << "(Launcher->Server) Bytes sent: " + std::to_string(Data.length()) + " : "
+ Data.substr(0, 10) + Data.substr(0, 10)
+ Data.substr(Data.length() - 10) + "\n"; + Data.substr(Data.length() - 10) + "\n";
}else if(MPDEV && C == 'Z'){ }else if(Dev && C == 'Z'){
//std::cout << "(Game->Launcher) : " << Data << std::endl; //std::cout << "(Game->Launcher) : " << Data << std::endl;
} }
} }
@ -109,14 +109,14 @@ void Reset() {
std::string Compress(const std::string&Data); std::string Compress(const std::string&Data);
std::string Decompress(const std::string&Data); std::string Decompress(const std::string&Data);
void TCPGameServer(const std::string& IP, int Port){ void TCPGameServer(const std::string& IP, int Port){
if(MPDEV)std::cout << "Game server Started! " << IP << ":" << Port << std::endl; if(Dev)std::cout << "Game server Started! " << IP << ":" << Port << std::endl;
do { do {
Reset(); Reset();
if(CServer) { if(CServer) {
std::thread Client(TCPClientMain, IP, Port); std::thread Client(TCPClientMain, IP, Port);
Client.detach(); Client.detach();
} }
if(MPDEV)std::cout << "Game server on Start" << std::endl; if(Dev)std::cout << "Game server on Start" << std::endl;
WSADATA wsaData; WSADATA wsaData;
int iResult; int iResult;
SOCKET ListenSocket = INVALID_SOCKET; SOCKET ListenSocket = INVALID_SOCKET;
@ -130,7 +130,7 @@ void TCPGameServer(const std::string& IP, int Port){
// Initialize Winsock // Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) { if (iResult != 0) {
if(MPDEV)std::cout << "(Proxy) WSAStartup failed with error: " << iResult << std::endl; if(Dev)std::cout << "(Proxy) WSAStartup failed with error: " << iResult << std::endl;
exit(-1); exit(-1);
} }
@ -142,7 +142,7 @@ void TCPGameServer(const std::string& IP, int Port){
// Resolve the server address and port // Resolve the server address and port
iResult = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT+1).c_str(), &hints, &result); iResult = getaddrinfo(nullptr, std::to_string(DEFAULT_PORT+1).c_str(), &hints, &result);
if (iResult != 0) { if (iResult != 0) {
if(MPDEV)std::cout << "(Proxy) getaddrinfo failed with error: " << iResult << std::endl; if(Dev)std::cout << "(Proxy) getaddrinfo failed with error: " << iResult << std::endl;
WSACleanup(); WSACleanup();
break; break;
} }
@ -150,7 +150,7 @@ void TCPGameServer(const std::string& IP, int Port){
// Create a socket for connecting to server // Create a socket for connecting to server
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (ListenSocket == INVALID_SOCKET) { if (ListenSocket == INVALID_SOCKET) {
if(MPDEV)std::cout << "(Proxy) socket failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(Proxy) socket failed with error: " << WSAGetLastError() << std::endl;
freeaddrinfo(result); freeaddrinfo(result);
WSACleanup(); WSACleanup();
break; break;
@ -159,7 +159,7 @@ void TCPGameServer(const std::string& IP, int Port){
// Setup the TCP listening socket // Setup the TCP listening socket
iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen); iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if(MPDEV)std::cout << "(Proxy) bind failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(Proxy) bind failed with error: " << WSAGetLastError() << std::endl;
freeaddrinfo(result); freeaddrinfo(result);
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
@ -170,20 +170,20 @@ void TCPGameServer(const std::string& IP, int Port){
iResult = listen(ListenSocket, SOMAXCONN); iResult = listen(ListenSocket, SOMAXCONN);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if(MPDEV)std::cout << "(Proxy) listen failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(Proxy) listen failed with error: " << WSAGetLastError() << std::endl;
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
continue; continue;
} }
Socket = accept(ListenSocket, nullptr, nullptr); Socket = accept(ListenSocket, nullptr, nullptr);
if (Socket == INVALID_SOCKET) { if (Socket == INVALID_SOCKET) {
if(MPDEV)std::cout << "(Proxy) accept failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(Proxy) accept failed with error: " << WSAGetLastError() << std::endl;
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
continue; continue;
} }
closesocket(ListenSocket); closesocket(ListenSocket);
if(MPDEV)std::cout << "(Proxy) Game Connected!" << std::endl; if(Dev)std::cout << "(Proxy) Game Connected!" << std::endl;
gameConected = true; gameConected = true;
if(CServer){ if(CServer){
std::thread t1(NetMain, IP, Port); std::thread t1(NetMain, IP, Port);
@ -204,13 +204,13 @@ void TCPGameServer(const std::string& IP, int Port){
ServerSend(buff,false); ServerSend(buff,false);
} else if (iResult == 0) { } else if (iResult == 0) {
if(MPDEV)std::cout << "(Proxy) Connection closing...\n"; if(Dev)std::cout << "(Proxy) Connection closing...\n";
closesocket(Socket); closesocket(Socket);
WSACleanup(); WSACleanup();
Terminate = true; Terminate = true;
continue; continue;
} else { } else {
if(MPDEV)std::cout << "(Proxy) recv failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(Proxy) recv failed with error: " << WSAGetLastError() << std::endl;
closesocket(Socket); closesocket(Socket);
WSACleanup(); WSACleanup();
continue; continue;
@ -219,7 +219,7 @@ void TCPGameServer(const std::string& IP, int Port){
iResult = shutdown(Socket, SD_SEND); iResult = shutdown(Socket, SD_SEND);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if(MPDEV)std::cout << "(Proxy) shutdown failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(Proxy) shutdown failed with error: " << WSAGetLastError() << std::endl;
TCPTerminate = true; TCPTerminate = true;
Terminate = true; Terminate = true;
closesocket(Socket); closesocket(Socket);
@ -235,7 +235,7 @@ void VehicleNetworkStart();
void CoreNetworkThread(); void CoreNetworkThread();
void ProxyStart(){ void ProxyStart(){
std::thread t1(CoreNetworkThread); std::thread t1(CoreNetworkThread);
if(MPDEV)std::cout << "Core Network Started!\n"; if(Dev)std::cout << "Core Network Started!\n";
t1.join(); t1.join();
} }

View File

@ -12,7 +12,7 @@
extern bool Terminate; extern bool Terminate;
extern int ClientID; extern int ClientID;
extern bool MPDEV; extern bool Dev;
SOCKET UDPSock; SOCKET UDPSock;
sockaddr_in ToServer{}; sockaddr_in ToServer{};
struct PacketData{ struct PacketData{
@ -149,7 +149,7 @@ void HandleChunk(const std::string&Data){
void UDPParser(const std::string&Packet){ void UDPParser(const std::string&Packet){
if(Packet.substr(0,4) == "ACK:"){ if(Packet.substr(0,4) == "ACK:"){
AckID(stoi(Packet.substr(4))); AckID(stoi(Packet.substr(4)));
if(MPDEV)std::cout << "Got Ack for data" << std::endl; if(Dev)std::cout << "Got Ack for data" << std::endl;
return; return;
}else if(Packet.substr(0,3) == "BD:"){ }else if(Packet.substr(0,3) == "BD:"){
int pos = Packet.find(':',4); int pos = Packet.find(':',4);

View File

@ -5,27 +5,26 @@
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include <WS2tcpip.h> #include <WS2tcpip.h>
#include <thread>
extern std::string UlStatus; extern std::string UlStatus;
extern bool Terminate; extern bool Terminate;
extern bool MPDEV; extern bool Dev;
SOCKET TCPSock; SOCKET TCPSock;
void TCPSend(const std::string&Data){ void TCPSend(const std::string&Data){
if(TCPSock == INVALID_SOCKET){ if(TCPSock == -1){
Terminate = true; Terminate = true;
return; return;
} }
int BytesSent = send(TCPSock, Data.c_str(), int(Data.length())+1, 0); int BytesSent = send(TCPSock, Data.c_str(), int(Data.length())+1, 0);
if (BytesSent == 0){ if (BytesSent == 0){
if(MPDEV)std::cout << "(TCP) Connection closing..." << std::endl; if(Dev)std::cout << "(TCP) Connection closing..." << std::endl;
Terminate = true; Terminate = true;
return; return;
} }
else if (BytesSent < 0) { else if (BytesSent < 0) {
if(MPDEV)std::cout << "(TCP) send failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(TCP) send failed with error: " << WSAGetLastError() << std::endl;
closesocket(TCPSock); closesocket(TCPSock);
Terminate = true; Terminate = true;
return; return;
@ -38,18 +37,18 @@ void TCPRcv(){
char buf[4096]; char buf[4096];
int len = 4096; int len = 4096;
ZeroMemory(buf, len); ZeroMemory(buf, len);
if(TCPSock == INVALID_SOCKET){ if(TCPSock == -1){
Terminate = true; Terminate = true;
return; return;
} }
int BytesRcv = recv(TCPSock, buf, len,0); int BytesRcv = recv(TCPSock, buf, len,0);
if (BytesRcv == 0){ if (BytesRcv == 0){
if(MPDEV)std::cout << "(TCP) Connection closing..." << std::endl; if(Dev)std::cout << "(TCP) Connection closing..." << std::endl;
Terminate = true; Terminate = true;
return; return;
} }
else if (BytesRcv < 0) { else if (BytesRcv < 0) {
if(MPDEV)std::cout << "(TCP) recv failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(TCP) recv failed with error: " << WSAGetLastError() << std::endl;
closesocket(TCPSock); closesocket(TCPSock);
Terminate = true; Terminate = true;
return; return;
@ -84,6 +83,7 @@ void TCPClientMain(const std::string& IP,int Port){
std::cout << "Client: connect failed! Error code: " << WSAGetLastError() << std::endl; std::cout << "Client: connect failed! Error code: " << WSAGetLastError() << std::endl;
closesocket(TCPSock); closesocket(TCPSock);
WSACleanup(); WSACleanup();
Terminate = true;
return; return;
} }
getsockname(TCPSock, (SOCKADDR *)&ServerAddr, (int *)sizeof(ServerAddr)); getsockname(TCPSock, (SOCKADDR *)&ServerAddr, (int *)sizeof(ServerAddr));
@ -92,12 +92,12 @@ void TCPClientMain(const std::string& IP,int Port){
while(!Terminate)TCPRcv(); while(!Terminate)TCPRcv();
GameSend("T"); GameSend("T");
////Game Send Terminate ////Game Send Terminate
if( shutdown(TCPSock, SD_SEND) != 0 && MPDEV) if( shutdown(TCPSock, SD_SEND) != 0 && Dev)
std::cout << "(TCP) shutdown error code: " << WSAGetLastError() << std::endl; std::cout << "(TCP) shutdown error code: " << WSAGetLastError() << std::endl;
if(closesocket(TCPSock) != 0 && MPDEV) if(closesocket(TCPSock) != 0 && Dev)
std::cout << "(TCP) Cannot close socket. Error code: " << WSAGetLastError() << std::endl; std::cout << "(TCP) Cannot close socket. Error code: " << WSAGetLastError() << std::endl;
if(WSACleanup() != 0 && MPDEV) if(WSACleanup() != 0 && Dev)
std::cout << "(TCP) Client: WSACleanup() failed!..." << std::endl; std::cout << "(TCP) Client: WSACleanup() failed!..." << std::endl;
} }

View File

@ -9,20 +9,19 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <set>
extern std::vector<std::string> GlobalInfo; extern std::vector<std::string> GlobalInfo;
void Exit(const std::string& Msg); void Exit(const std::string& Msg);
namespace fs = std::experimental::filesystem; namespace fs = std::experimental::filesystem;
extern std::string UlStatus; extern std::string UlStatus;
extern bool TCPTerminate; extern bool TCPTerminate;
extern std::string ver;
extern bool Terminate; extern bool Terminate;
extern bool Confirm; extern bool Confirm;
extern bool MPDEV; extern bool Dev;
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){
std::vector<std::string> Val; std::vector<std::string> Val;
size_t pos = 0; size_t pos;
std::string token,s = String; std::string token,s = String;
while ((pos = s.find(delimiter)) != std::string::npos) { while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos); token = s.substr(0, pos);
@ -34,25 +33,25 @@ std::vector<std::string> Split(const std::string& String,const std::string& deli
} }
void STCPSend(SOCKET socket,const std::string&Data){ void STCPSend(SOCKET socket,const std::string&Data){
if(socket == INVALID_SOCKET){ if(socket == -1){
Terminate = true; Terminate = true;
return; return;
} }
int BytesSent = send(socket, Data.c_str(), int(Data.length())+1, 0); int BytesSent = send(socket, Data.c_str(), int(Data.length())+1, 0);
if (BytesSent == 0){ if (BytesSent == 0){
if(MPDEV)std::cout << "(TCP) Connection closing..." << std::endl; if(Dev)std::cout << "(TCP) Connection closing..." << std::endl;
Terminate = true; Terminate = true;
return; return;
} }
else if (BytesSent < 0) { else if (BytesSent < 0) {
if(MPDEV)std::cout << "(TCP) send failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(TCP) send failed with error: " << WSAGetLastError() << std::endl;
closesocket(socket); closesocket(socket);
Terminate = true; Terminate = true;
return; return;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
std::pair<char*,int> STCPRecv(SOCKET socket){ std::pair<char*,size_t> STCPRecv(SOCKET socket){
char buf[64000]; char buf[64000];
int len = 64000; int len = 64000;
ZeroMemory(buf, len); ZeroMemory(buf, len);
@ -87,10 +86,11 @@ void WaitForConfirm(){
} }
void SyncResources(SOCKET Sock){ void SyncResources(SOCKET Sock){
if(MPDEV)std::cout << "SyncResources Called" << std::endl; std::cout << "Checking Resources..." << std::endl;
std::string HandShakeVer = "1.43";
CheckForDir(); CheckForDir();
STCPSend(Sock,"NR" + GlobalInfo.at(0) + ":" +GlobalInfo.at(2)); STCPSend(Sock,"NR" + GlobalInfo.at(0) + ":" +GlobalInfo.at(2));
STCPSend(Sock,"VC" + ver); STCPSend(Sock,"VC" + HandShakeVer);
auto Res = STCPRecv(Sock); auto Res = STCPRecv(Sock);
std::string msg = Res.first; std::string msg = Res.first;
if(msg.size() < 2 || msg.substr(0,2) != "WS"){ if(msg.size() < 2 || msg.substr(0,2) != "WS"){
@ -124,18 +124,17 @@ void SyncResources(SOCKET Sock){
if(t.empty())ListOfMods = "-"; if(t.empty())ListOfMods = "-";
else ListOfMods = t; else ListOfMods = t;
t.clear(); t.clear();
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) { for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
int pos = FN->find_last_of('/'); int pos = FN->find_last_of('/');
if (pos == std::string::npos)continue; if (pos == std::string::npos)continue;
Amount++; Amount++;
} }
if(!FNames.empty())std::cout << "Syncing..." << std::endl;
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) { for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
int pos = FN->find_last_of('/'); int pos = FN->find_last_of('/');
if (pos != std::string::npos) { if (pos != std::string::npos) {
a = "Resources" + FN->substr(pos); a = "Resources" + FN->substr(pos);
} else continue; } else continue;
char *Data;
Pos++; Pos++;
if (stat(a.c_str(), &info) == 0) { if (stat(a.c_str(), &info) == 0) {
if (FS->find_first_not_of("0123456789") != std::string::npos)continue; if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
@ -149,36 +148,37 @@ void SyncResources(SOCKET Sock){
}else remove(a.c_str()); }else remove(a.c_str());
} }
CheckForDir(); CheckForDir();
std::ofstream LFS;
do { do {
STCPSend(Sock, "f" + *FN); STCPSend(Sock, "f" + *FN);
//std::set<std::pair<char*,int>> segments; int Recv = 0,Size = std::stoi(*FS);
char*File = new char[Size];
ZeroMemory(File,Size);
do { do {
auto Pair = STCPRecv(Sock); auto Pair = STCPRecv(Sock);
Data = Pair.first; char* Data = Pair.first;
size_t BytesRcv = Pair.second;
if (strcmp(Data, "Cannot Open") == 0 || Terminate)break; if (strcmp(Data, "Cannot Open") == 0 || Terminate)break;
if (!LFS.is_open()) { memcpy_s(File+Recv,BytesRcv,Data,BytesRcv);
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary); Recv += BytesRcv;
} float per = float(Recv)/std::stof(*FS) * 100;
LFS.write(Data,Pair.second);
/*char* Segment = new char[Pair.second];
memcpy_s(Segment,Pair.second,Data,Pair.second);
segments.insert(std::make_pair(Segment,Pair.second));
total += Pair.second;*/
float per = LFS.tellp()/ std::stof(*FS) * 100;
std::string Percent = std::to_string(truncf(per * 10) / 10); std::string Percent = std::to_string(truncf(per * 10) / 10);
UlStatus = "UlDownloading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) + UlStatus = "UlDownloading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
"): " + a.substr(a.find_last_of('/')) + " (" + "): " + a.substr(a.find_last_of('/')) + " (" +
Percent.substr(0, Percent.find('.') + 2) + "%)"; Percent.substr(0, Percent.find('.') + 2) + "%)";
} while (LFS.tellp() != std::stoi(*FS) && LFS.tellp() < std::stoi(*FS)); delete[] Data;
} while (Recv != Size && Recv < Size && !Terminate);
UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) + UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
"): " + a.substr(a.find_last_of('/')); "): " + a.substr(a.find_last_of('/'));
/*for(auto p : segments){ std::ofstream LFS;
LFS.write(p.first,p.second); if (!LFS.is_open()) {
}*/ LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
//segments.clear(); }
LFS.write(File,Recv);
LFS.close(); LFS.close();
}while(fs::file_size(a) != std::stoi(*FS)); ZeroMemory(File,Size);
delete[] File;
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing); fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing);
WaitForConfirm(); WaitForConfirm();
} }

View File

@ -4,14 +4,14 @@
#include <iostream> #include <iostream>
void Download(const std::string& URL,const std::string& path); int Download(const std::string& URL,const std::string& path);
std::string HTTP_REQUEST(const std::string&url,int port); std::string HTTP_REQUEST(const std::string&url,int port);
std::string HTA(const std::string& hex); std::string HTA(const std::string& hex);
void SystemExec(const std::string& cmd); void SystemExec(const std::string& cmd);
void WinExec(const std::string& cmd); void WinExec(const std::string& cmd);
void Exit(const std::string& Msg); void Exit(const std::string& Msg);
void ReLaunch(int argc,char*args[]);
void CheckForUpdates(const std::string& CV){ void CheckForUpdates(int argc,char*args[],const std::string& CV){
std::string link = "https://beamng-mp.com/builds/launcher?version=true"; std::string link = "https://beamng-mp.com/builds/launcher?version=true";
std::string HTTP = HTTP_REQUEST(link,443); std::string HTTP = HTTP_REQUEST(link,443);
link = "https://beamng-mp.com/builds/launcher?download=true"; link = "https://beamng-mp.com/builds/launcher?download=true";
@ -21,6 +21,7 @@ void CheckForUpdates(const std::string& CV){
struct stat buffer{}; struct stat buffer{};
if(stat ("BeamMP-Launcher.back", &buffer) == 0)remove("BeamMP-Launcher.back"); if(stat ("BeamMP-Launcher.back", &buffer) == 0)remove("BeamMP-Launcher.back");
if(HTTP > CV){ if(HTTP > CV){
ReLaunch(argc,args);
system("cls"); system("cls");
std::cout << "Update found!" << std::endl; std::cout << "Update found!" << std::endl;
std::cout << "Updating..." << std::endl; std::cout << "Updating..." << std::endl;

View File

@ -10,7 +10,7 @@
#include <queue> #include <queue>
extern bool TCPTerminate; extern bool TCPTerminate;
extern bool MPDEV; extern bool Dev;
void Print(const std::string&MSG); void Print(const std::string&MSG);
std::queue<std::string> VNTCPQueue; std::queue<std::string> VNTCPQueue;
//void RUDPSEND(const std::string&Data,bool Rel); //void RUDPSEND(const std::string&Data,bool Rel);
@ -24,12 +24,12 @@ void Responder(const SOCKET *CS){
VNTCPQueue.front() += "\n"; VNTCPQueue.front() += "\n";
iSendResult = send(ClientSocket, VNTCPQueue.front().c_str(), VNTCPQueue.front().length(), 0); iSendResult = send(ClientSocket, VNTCPQueue.front().c_str(), VNTCPQueue.front().length(), 0);
if (iSendResult == SOCKET_ERROR) { if (iSendResult == SOCKET_ERROR) {
if(MPDEV)std::cout << "(VN) send failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(VN) send failed with error: " << WSAGetLastError() << std::endl;
break; break;
} else { } else {
if(iSendResult > 1000){ if(iSendResult > 1000){
if(MPDEV){std::cout << "(Launcher->Game VN) Bytes sent: " << iSendResult << " : " << VNTCPQueue.front().substr(0,10) if(Dev){std::cout << "(Launcher->Game VN) Bytes sent: " << iSendResult << " : " << VNTCPQueue.front().substr(0, 10)
<< VNTCPQueue.front().substr(VNTCPQueue.front().length()-10) << std::endl;} << VNTCPQueue.front().substr(VNTCPQueue.front().length()-10) << std::endl;}
} }
VNTCPQueue.pop(); VNTCPQueue.pop();
} }
@ -41,7 +41,7 @@ std::string Compress(const std::string&Data);
std::string Decompress(const std::string&Data); std::string Decompress(const std::string&Data);
void VehicleNetworkStart(){ void VehicleNetworkStart(){
do { do {
if(MPDEV)std::cout << "VN on Start" << std::endl; if(Dev)std::cout << "VN on Start" << std::endl;
WSADATA wsaData; WSADATA wsaData;
int iResult; int iResult;
SOCKET ListenSocket = INVALID_SOCKET; SOCKET ListenSocket = INVALID_SOCKET;
@ -57,7 +57,7 @@ void VehicleNetworkStart(){
// Initialize Winsock // Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) { if (iResult != 0) {
if(MPDEV)std::cout << "(VN) WSAStartup failed with error: " << iResult << std::endl; if(Dev)std::cout << "(VN) WSAStartup failed with error: " << iResult << std::endl;
std::cin.get(); std::cin.get();
exit(-1); exit(-1);
} }
@ -71,7 +71,7 @@ void VehicleNetworkStart(){
// Resolve the server address and port // Resolve the server address and port
iResult = getaddrinfo(nullptr, DEFAULT_PORT, &hints, &result); iResult = getaddrinfo(nullptr, DEFAULT_PORT, &hints, &result);
if (iResult != 0) { if (iResult != 0) {
if(MPDEV)std::cout << "(VN) getaddrinfo failed with error: " << iResult << std::endl; if(Dev)std::cout << "(VN) getaddrinfo failed with error: " << iResult << std::endl;
WSACleanup(); WSACleanup();
break; break;
} }
@ -79,7 +79,7 @@ void VehicleNetworkStart(){
// Create a socket for connecting to server // Create a socket for connecting to server
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (ListenSocket == INVALID_SOCKET) { if (ListenSocket == INVALID_SOCKET) {
if(MPDEV)std::cout << "(VN) socket failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(VN) socket failed with error: " << WSAGetLastError() << std::endl;
freeaddrinfo(result); freeaddrinfo(result);
WSACleanup(); WSACleanup();
break; break;
@ -88,7 +88,7 @@ void VehicleNetworkStart(){
// Setup the TCP listening socket // Setup the TCP listening socket
iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen); iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if(MPDEV)std::cout << "(VN) bind failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(VN) bind failed with error: " << WSAGetLastError() << std::endl;
freeaddrinfo(result); freeaddrinfo(result);
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
@ -99,20 +99,20 @@ void VehicleNetworkStart(){
iResult = listen(ListenSocket, SOMAXCONN); iResult = listen(ListenSocket, SOMAXCONN);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if(MPDEV)std::cout << "(VN) listen failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(VN) listen failed with error: " << WSAGetLastError() << std::endl;
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
continue; continue;
} }
ClientSocket = accept(ListenSocket, NULL, NULL); ClientSocket = accept(ListenSocket, NULL, NULL);
if (ClientSocket == INVALID_SOCKET) { if (ClientSocket == INVALID_SOCKET) {
if(MPDEV)std::cout << "(VN) accept failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(VN) accept failed with error: " << WSAGetLastError() << std::endl;
closesocket(ListenSocket); closesocket(ListenSocket);
WSACleanup(); WSACleanup();
continue; continue;
} }
closesocket(ListenSocket); closesocket(ListenSocket);
if(MPDEV)std::cout << "(VN) Game Connected!" << std::endl; if(Dev)std::cout << "(VN) Game Connected!" << std::endl;
std::thread TCPSend(Responder,&ClientSocket); std::thread TCPSend(Responder,&ClientSocket);
TCPSend.detach(); TCPSend.detach();
@ -125,7 +125,7 @@ void VehicleNetworkStart(){
memcpy(&buff[0],recvbuf,iResult); memcpy(&buff[0],recvbuf,iResult);
buff.resize(iResult); buff.resize(iResult);
//Print(buff); //Print(buff);
if(MPDEV) { if(Dev) {
std::string cmp = Compress(buff), dcm = Decompress(cmp); std::string cmp = Compress(buff), dcm = Decompress(cmp);
std::cout << "Compressed Size : " << cmp.length() << std::endl; std::cout << "Compressed Size : " << cmp.length() << std::endl;
std::cout << "Decompressed Size : " << dcm.length() << std::endl; std::cout << "Decompressed Size : " << dcm.length() << std::endl;
@ -138,13 +138,13 @@ void VehicleNetworkStart(){
//RUDPSEND(buff,false); //RUDPSEND(buff,false);
//std::cout << "(Game->Launcher VN) Data : " << buff.length() << std::endl; //std::cout << "(Game->Launcher VN) Data : " << buff.length() << std::endl;
} else if (iResult == 0) { } else if (iResult == 0) {
if(MPDEV)std::cout << "(VN) Connection closing...\n"; if(Dev)std::cout << "(VN) Connection closing...\n";
closesocket(ClientSocket); closesocket(ClientSocket);
WSACleanup(); WSACleanup();
continue; continue;
} else { } else {
if(MPDEV)std::cout << "(VN) recv failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(VN) recv failed with error: " << WSAGetLastError() << std::endl;
closesocket(ClientSocket); closesocket(ClientSocket);
WSACleanup(); WSACleanup();
continue; continue;
@ -153,7 +153,7 @@ void VehicleNetworkStart(){
iResult = shutdown(ClientSocket, SD_SEND); iResult = shutdown(ClientSocket, SD_SEND);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
if(MPDEV)std::cout << "(VN) shutdown failed with error: " << WSAGetLastError() << std::endl; if(Dev)std::cout << "(VN) shutdown failed with error: " << WSAGetLastError() << std::endl;
closesocket(ClientSocket); closesocket(ClientSocket);
WSACleanup(); WSACleanup();
continue; continue;

View File

@ -14,7 +14,7 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *use
} }
std::string HTTP_REQUEST(const std::string& IP,int port){ std::string HTTP_REQUEST(const std::string& IP,int port){
CURL *curl; CURL *curl;
CURLcode res; //CURLcode res;
std::string readBuffer; std::string readBuffer;
curl = curl_easy_init(); curl = curl_easy_init();
if(curl) { if(curl) {
@ -22,7 +22,7 @@ std::string HTTP_REQUEST(const std::string& IP,int port){
curl_easy_setopt(curl, CURLOPT_PORT, port); curl_easy_setopt(curl, CURLOPT_PORT, port);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl); curl_easy_perform(curl);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
curl_global_cleanup(); curl_global_cleanup();
@ -65,7 +65,7 @@ static size_t my_fwrite(void *buffer,size_t size,size_t nmemb,void *stream)
return fwrite(buffer, size, nmemb, out->stream); return fwrite(buffer, size, nmemb, out->stream);
} }
void Download(const std::string& URL,const std::string& Path) int Download(const std::string& URL,const std::string& Path)
{ {
CURL *curl; CURL *curl;
CURLcode res; CURLcode res;
@ -85,10 +85,11 @@ void Download(const std::string& URL,const std::string& Path)
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
if(CURLE_OK != res) { if(CURLE_OK != res) {
Exit("Failed to download! Code : " + std::to_string(res)); return res;
} }
} }
if(file.stream)fclose(file.stream); if(file.stream)fclose(file.stream);
curl_global_cleanup(); curl_global_cleanup();
std::cout << std::endl; std::cout << std::endl;
return -1;
} }

View File

@ -10,18 +10,18 @@
#include <vector> #include <vector>
#include <thread> #include <thread>
void Download(const std::string& URL,const std::string& OutFileName); int Download(const std::string& URL,const std::string& OutFileName);
void StartGame(const std::string&ExeDir,const std::string&Current); void StartGame(const std::string&ExeDir,const std::string&Current);
std::string HTTP_REQUEST(const std::string&url,int port); std::string HTTP_REQUEST(const std::string&url,int port);
void CheckForUpdates(const std::string& CV); void CheckForUpdates(int argc,char*args[],const std::string& CV);
std::vector<std::string> GetDiscordInfo(); std::vector<std::string> GetDiscordInfo();
extern std::vector<std::string> SData; extern std::vector<std::string> SData;
std::vector<std::string> GlobalInfo; std::vector<std::string> GlobalInfo;
std::string getHardwareID(); std::string getHardwareID();
std::string ver = "1.43"; char* ver = (char*)"1.45";
int DEFAULT_PORT = 4444; int DEFAULT_PORT = 4444;
void Discord_Main(); void Discord_Main();
bool MPDEV = false; bool Dev = false;
void ProxyStart(); void ProxyStart();
void ExitError(); void ExitError();
void Check(); void Check();
@ -35,7 +35,7 @@ void WinExec(const std::string& cmd){
void Exit(const std::string& Msg){ void Exit(const std::string& Msg){
std::cout << Msg << std::endl; std::cout << Msg << std::endl;
std::cout << "Press Enter to continue . . ."; std::cout << "Press Enter to continue...";
std::cin.ignore(); std::cin.ignore();
exit(-1); exit(-1);
} }
@ -56,7 +56,10 @@ std::string CheckDir(int argc,char*args[]){
if(stat(DN.c_str(),&info)==0)remove(DN.c_str()); if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
SystemExec("rename \""+ FN +"\" " + DN + ">nul"); SystemExec("rename \""+ FN +"\" " + DN + ">nul");
} }
if(stat("BeamNG",&info))SystemExec("mkdir BeamNG>nul"); if(stat("BeamNG",&info)){
SystemExec("mkdir BeamNG>nul");
if(stat("BeamNG",&info))ReLaunch(argc,args);
}
if(!stat("BeamNG\\mods",&info))SystemExec("RD /S /Q BeamNG\\mods>nul"); if(!stat("BeamNG\\mods",&info))SystemExec("RD /S /Q BeamNG\\mods>nul");
if(!stat("BeamNG\\mods",&info))ReLaunch(argc,args); if(!stat("BeamNG\\mods",&info))ReLaunch(argc,args);
SystemExec("mkdir BeamNG\\mods>nul"); SystemExec("mkdir BeamNG\\mods>nul");
@ -84,7 +87,7 @@ int main(int argc, char* argv[]){
struct stat info{}; struct stat info{};
system("cls"); system("cls");
std::string link, HTTP_Result; std::string link, HTTP_Result;
SetWindowTextA(GetConsoleWindow(),("BeamMP Launcher v" + ver).c_str()); SetWindowTextA(GetConsoleWindow(),("BeamMP Launcher v" + std::string(ver)).c_str());
std::thread t1(Discord_Main); std::thread t1(Discord_Main);
t1.detach(); t1.detach();
std::cout << "Connecting to discord client..." << std::endl; std::cout << "Connecting to discord client..." << std::endl;
@ -102,9 +105,9 @@ int main(int argc, char* argv[]){
exit(-1); exit(-1);
} }
} }
}else MPDEV = true; }else Dev = true;
std::string Path = CheckDir(argc,argv); std::string Path = CheckDir(argc,argv);
std::thread CFU(CheckForUpdates,ver); std::thread CFU(CheckForUpdates,argc,argv,std::string(ver));
CFU.join(); CFU.join();
if(argc > 1){ if(argc > 1){
@ -115,7 +118,7 @@ int main(int argc, char* argv[]){
std::cout << "Running on custom port : " << DEFAULT_PORT << std::endl; std::cout << "Running on custom port : " << DEFAULT_PORT << std::endl;
} }
} }
if(argc > 2)MPDEV = false; if(argc > 2)Dev = false;
} }
//Security //Security
@ -124,17 +127,26 @@ int main(int argc, char* argv[]){
delete Sec; delete Sec;
if(SData.size() != 3)ExitError(); if(SData.size() != 3)ExitError();
std::string GamePath = SData.at(2); std::string GamePath = SData.at(2);
if(MPDEV)std::cout << "You own BeamNG on this machine!" << std::endl; if(Dev)std::cout << "You own BeamNG on this machine!" << std::endl;
std::cout << "Game Version : " << CheckVer(GamePath) << std::endl; std::cout << "Game Version : " << CheckVer(GamePath) << std::endl;
std::string ExeDir = GamePath.substr(0,GamePath.find_last_of('\\')) + R"(\Bin64\BeamNG.drive.x64.exe)"; std::string ExeDir = GamePath.substr(0,GamePath.find_last_of('\\')) + R"(\Bin64\BeamNG.drive.x64.exe)";
std::string Settings = Path + "\\settings\\uiapps-layouts.json"; std::string DUI = Path + R"(\settings\uiapps-layouts.json)";
if(stat(Settings.c_str(),&info)!=0){ std::string GS = Path + R"(\settings\game-settings.ini)";
if(stat(DUI.c_str(),&info)!=0 || stat(GS.c_str(),&info)!=0){
link = "https://beamng-mp.com/client-ui-data"; link = "https://beamng-mp.com/client-ui-data";
std::cout << "Downloading default config..." << std::endl; std::cout << "Downloading default config..." << std::endl;
Download(link,Settings); if(int i = Download(link,DUI) != -1){
std::cout << "Error! Failed to download code : " << i << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(3));
ReLaunch(argc,argv);
}
link = "https://beamng-mp.com/client-settings-data";
Download(link,GS);
std::cout << "Download Complete!" << std::endl; std::cout << "Download Complete!" << std::endl;
} }
if(!MPDEV){ DUI.clear();
GS.clear();
if(!Dev){
std::cout << "Downloading mod..." << std::endl; std::cout << "Downloading mod..." << std::endl;
link = "https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2); link = "https://beamng-mp.com/builds/client?did="+GlobalInfo.at(2);
Download(link,Path + R"(\mods\BeamMP.zip)"); Download(link,Path + R"(\mods\BeamMP.zip)");