mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-08-29 13:30:43 +00:00
version 0.56
This commit is contained in:
@@ -139,8 +139,6 @@ void SyncResources(const std::string&IP,int Port){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}while (iResult > 0);
|
}while (iResult > 0);
|
||||||
|
|
||||||
|
|
||||||
if(BytesSent == SOCKET_ERROR)
|
if(BytesSent == SOCKET_ERROR)
|
||||||
printf("Client: send() error %ld.\n", WSAGetLastError());
|
printf("Client: send() error %ld.\n", WSAGetLastError());
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ std::string CheckDir(char*dir, const std::string& ver){
|
|||||||
_dupenv_s(&temp, &len,"APPDATA");
|
_dupenv_s(&temp, &len,"APPDATA");
|
||||||
std::string DN = "BeamMP-Launcher.exe",CDir = dir, AD = temp,FN = CDir.substr(CDir.find_last_of('\\')+1,CDir.size());
|
std::string DN = "BeamMP-Launcher.exe",CDir = dir, AD = temp,FN = CDir.substr(CDir.find_last_of('\\')+1,CDir.size());
|
||||||
AD += "\\BeamMP-Launcher";
|
AD += "\\BeamMP-Launcher";
|
||||||
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
if(FN != DN){
|
||||||
if(FN != DN)SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
||||||
|
SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
||||||
|
}
|
||||||
if(CDir.substr(0,CDir.find_last_of('\\')) != AD){
|
if(CDir.substr(0,CDir.find_last_of('\\')) != AD){
|
||||||
_mkdir(AD.c_str());
|
_mkdir(AD.c_str());
|
||||||
SystemExec(R"(move "BeamMP-Launcher.exe" ")" + AD + "\">nul");
|
SystemExec(R"(move "BeamMP-Launcher.exe" ")" + AD + "\">nul");
|
||||||
@@ -76,7 +78,7 @@ std::string CheckVer(const std::string &path){
|
|||||||
void SyncResources(const std::string&IP,int Port);
|
void SyncResources(const std::string&IP,int Port);
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
std::string ver = "0.51", Path = CheckDir(argv[0],ver),HTTP_Result;
|
std::string ver = "0.56", Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||||
CheckForUpdates(ver); //Update Check
|
CheckForUpdates(ver); //Update Check
|
||||||
|
|
||||||
//Security
|
//Security
|
||||||
@@ -92,10 +94,14 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
std::cout << "HWID : " << getHardwareID() << std::endl;
|
std::cout << "HWID : " << getHardwareID() << std::endl;
|
||||||
|
|
||||||
std::string ExeDir = GamePath.substr(0,GamePath.find_last_of('\\')) + "\\Bin64\\BeamNG.drive.x64.exe";
|
|
||||||
Download("https://beamng-mp.com/builds/client?did="+Discord_Main().at(2),Path + R"(\mods\BeamMP.zip)");
|
|
||||||
HTTP_Result = HTTP_REQUEST("https://beamng-mp.com/entitlement?did="+Discord_Main().at(2),443);
|
HTTP_Result = HTTP_REQUEST("https://beamng-mp.com/entitlement?did="+Discord_Main().at(2),443);
|
||||||
std::cout << "you have : " << HTTP_Result << std::endl;
|
std::cout << "you have : " << HTTP_Result << std::endl;
|
||||||
|
if(HTTP_Result.find("[\"MDEV\"]") == std::string::npos)exit(-1); ///Remove later
|
||||||
|
|
||||||
|
|
||||||
|
std::string ExeDir = GamePath.substr(0,GamePath.find_last_of('\\')) + "\\Bin64\\BeamNG.drive.x64.exe";
|
||||||
|
Download("https://beamng-mp.com/builds/client?did="+Discord_Main().at(2),Path + R"(\mods\BeamMP.zip)");
|
||||||
|
|
||||||
|
|
||||||
/*if(HTTP_Result.find("[\"MDEV\"]") != std::string::npos){
|
/*if(HTTP_Result.find("[\"MDEV\"]") != std::string::npos){
|
||||||
WinExec(ExeDir + " -cefdev -console -nocrashreport -userpath " + Path);
|
WinExec(ExeDir + " -cefdev -console -nocrashreport -userpath " + Path);
|
||||||
@@ -104,8 +110,6 @@ int main(int argc, char* argv[])
|
|||||||
}*/
|
}*/
|
||||||
//std::cout << "Game Launched!\n";
|
//std::cout << "Game Launched!\n";
|
||||||
|
|
||||||
///HTTP REQUEST FOR SERVER LIST
|
|
||||||
///Mods
|
|
||||||
|
|
||||||
ProxyStart(); //Proxy main start
|
ProxyStart(); //Proxy main start
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,15 @@
|
|||||||
////
|
////
|
||||||
|
|
||||||
#define ENET_IMPLEMENTATION
|
#define ENET_IMPLEMENTATION
|
||||||
|
#include <condition_variable>
|
||||||
#include "include/enet.h"
|
#include "include/enet.h"
|
||||||
#include <WinSock2.h>
|
#include <WinSock2.h>
|
||||||
#include <iostream>
|
|
||||||
#include <chrono>
|
|
||||||
#include <WS2tcpip.h>
|
#include <WS2tcpip.h>
|
||||||
#include <cstdio>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#define DEFAULT_BUFLEN 64000
|
#define DEFAULT_BUFLEN 64000
|
||||||
#define DEFAULT_PORT "4445"
|
#define DEFAULT_PORT "4445"
|
||||||
@@ -34,7 +34,7 @@ void AutoPing(ENetPeer*peer){
|
|||||||
while(!Terminate && peer != nullptr){
|
while(!Terminate && peer != nullptr){
|
||||||
enet_peer_send(peer, 0, enet_packet_create("p", 2, ENET_PACKET_FLAG_RELIABLE));
|
enet_peer_send(peer, 0, enet_packet_create("p", 2, ENET_PACKET_FLAG_RELIABLE));
|
||||||
PingStart = std::chrono::high_resolution_clock::now();
|
PingStart = std::chrono::high_resolution_clock::now();
|
||||||
Sleep(1000);
|
std::this_thread::sleep_for(std::chrono::seconds (1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void NameRespond(ENetPeer*peer){
|
void NameRespond(ENetPeer*peer){
|
||||||
@@ -88,17 +88,12 @@ void RUDPClientThread(const std::string& IP, int Port){
|
|||||||
if (enet_initialize() != 0) {
|
if (enet_initialize() != 0) {
|
||||||
std::cout << "An error occurred while initializing RUDP.\n";
|
std::cout << "An error occurred while initializing RUDP.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
|
||||||
int Interval = 0;
|
|
||||||
|
|
||||||
Client client;
|
Client client;
|
||||||
ENetAddress address = {0};
|
ENetAddress address = {0};
|
||||||
|
|
||||||
address.host = ENET_HOST_ANY;
|
address.host = ENET_HOST_ANY;
|
||||||
address.port = Port;
|
address.port = Port;
|
||||||
|
std::mutex m;
|
||||||
|
|
||||||
std::cout << "(Launcher->Server) Connecting...\n";
|
std::cout << "(Launcher->Server) Connecting...\n";
|
||||||
|
|
||||||
enet_address_set_host(&address, IP.c_str());
|
enet_address_set_host(&address, IP.c_str());
|
||||||
@@ -114,17 +109,17 @@ void RUDPClientThread(const std::string& IP, int Port){
|
|||||||
enet_host_service(client.host, &event, 0);
|
enet_host_service(client.host, &event, 0);
|
||||||
HandleEvent(event,client);
|
HandleEvent(event,client);
|
||||||
while (!RUDPToSend.empty()){
|
while (!RUDPToSend.empty()){
|
||||||
|
int Rel = 8;
|
||||||
|
char C = RUDPToSend.front().at(0);
|
||||||
|
if(C=='s'||C=='d'||C=='m'||C=='r')Rel = 1;
|
||||||
ENetPacket* packet = enet_packet_create(RUDPToSend.front().c_str(),
|
ENetPacket* packet = enet_packet_create(RUDPToSend.front().c_str(),
|
||||||
RUDPToSend.front().length()+1,
|
RUDPToSend.front().length()+1,
|
||||||
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT);
|
Rel);
|
||||||
enet_peer_send(client.peer, 0, packet);
|
enet_peer_send(client.peer, 0, packet);
|
||||||
std::cout << "(Launcher->Server) sending " << RUDPToSend.front().length() << " Bytes" << std::endl;
|
std::cout << "(Launcher->Server) sending " << RUDPToSend.front().length() << " Bytes" << std::endl;
|
||||||
RUDPToSend.pop();
|
RUDPToSend.pop();
|
||||||
}
|
}
|
||||||
while(RUDPToSend.empty() && Interval < 1000){
|
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||||
auto done = std::chrono::high_resolution_clock::now();
|
|
||||||
Interval = std::chrono::duration_cast<std::chrono::milliseconds>(done-start).count();
|
|
||||||
}
|
|
||||||
} while (!Terminate);
|
} while (!Terminate);
|
||||||
enet_peer_disconnect(client.peer,0);
|
enet_peer_disconnect(client.peer,0);
|
||||||
enet_host_service(client.host, &event, 0);
|
enet_host_service(client.host, &event, 0);
|
||||||
@@ -133,10 +128,11 @@ void RUDPClientThread(const std::string& IP, int Port){
|
|||||||
std::cout << "(Launcher->Server) Terminated!" << std::endl;
|
std::cout << "(Launcher->Server) Terminated!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPRespond(SOCKET *CS){
|
void TCPRespond(const SOCKET *CS){
|
||||||
int iSendResult;
|
|
||||||
SOCKET ClientSocket = *CS;
|
SOCKET ClientSocket = *CS;
|
||||||
while(ClientSocket != INVALID_SOCKET){
|
int iSendResult;
|
||||||
|
std::mutex m;
|
||||||
|
while(!TCPTerminate){
|
||||||
while (!RUDPData.empty()) {
|
while (!RUDPData.empty()) {
|
||||||
RUDPData.front() += "\n";
|
RUDPData.front() += "\n";
|
||||||
iSendResult = send(ClientSocket, RUDPData.front().c_str(), RUDPData.front().length(), 0);
|
iSendResult = send(ClientSocket, RUDPData.front().c_str(), RUDPData.front().length(), 0);
|
||||||
@@ -148,13 +144,13 @@ void TCPRespond(SOCKET *CS){
|
|||||||
std::cout << "(Proxy->Game) Bytes sent: " << iSendResult << std::endl;
|
std::cout << "(Proxy->Game) Bytes sent: " << iSendResult << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServerThread(const std::string& IP, int Port){
|
void TCPServerThread(const std::string& IP, int Port){
|
||||||
std::cout << "Proxy Started! " << IP << ":" << Port << std::endl;
|
std::cout << "Proxy Started! " << IP << ":" << Port << std::endl;
|
||||||
do {
|
do {
|
||||||
Terminate = false;
|
|
||||||
std::cout << "Proxy on Start" << std::endl;
|
std::cout << "Proxy on Start" << std::endl;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
int iResult;
|
int iResult;
|
||||||
@@ -241,7 +237,7 @@ void TCPServerThread(const std::string& IP, int Port){
|
|||||||
std::string buff = recvbuf;
|
std::string buff = recvbuf;
|
||||||
buff.resize(iResult);
|
buff.resize(iResult);
|
||||||
RUDPToSend.push(buff);
|
RUDPToSend.push(buff);
|
||||||
///std::cout << "(Game->Launcher) Data : " << buff.c_str() << std::endl;
|
std::cout << "(Game->Launcher) Data : " << buff.length() << std::endl;
|
||||||
} else if (iResult == 0) {
|
} else if (iResult == 0) {
|
||||||
std::cout << "(Proxy) Connection closing...\n";
|
std::cout << "(Proxy) Connection closing...\n";
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
@@ -277,6 +273,8 @@ void ProxyStart(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProxyThread(const std::string& IP, int Port){
|
void ProxyThread(const std::string& IP, int Port){
|
||||||
|
Terminate = false;
|
||||||
|
TCPTerminate = false;
|
||||||
std::thread t1(TCPServerThread,IP,Port);
|
std::thread t1(TCPServerThread,IP,Port);
|
||||||
t1.detach();
|
t1.detach();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user