mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +00:00
Auto server connection and sends transfer status to the game
This commit is contained in:
parent
f6a079a962
commit
66373ae44c
@ -5,7 +5,7 @@
|
|||||||
#include <WS2tcpip.h>
|
#include <WS2tcpip.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
#define DEFAULT_BUFLEN 64000
|
#define DEFAULT_BUFLEN 64000
|
||||||
#define DEFAULT_PORT "4444"
|
#define DEFAULT_PORT "4444"
|
||||||
|
|
||||||
@ -13,11 +13,17 @@
|
|||||||
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
||||||
|
|
||||||
std::string HTTP_REQUEST(const std::string&url,int port);
|
std::string HTTP_REQUEST(const std::string&url,int port);
|
||||||
void ProxyThread(const std::string& IP, int port);
|
|
||||||
void SyncResources(const std::string& IP, int port);
|
void SyncResources(const std::string& IP, int port);
|
||||||
|
extern std::string UlStatus;
|
||||||
|
extern std::string MStatus;
|
||||||
|
void StartSync(const std::string &Data){
|
||||||
|
std::thread t1(SyncResources,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
||||||
|
t1.detach();
|
||||||
|
}
|
||||||
|
|
||||||
std::string Parse(const std::string& Data){
|
std::string Parse(const std::string& Data){
|
||||||
char Code = Data.substr(0,1).at(0);
|
char Code = Data.substr(0,1).at(0), SubCode = 0;
|
||||||
|
if(Data.length() > 1)SubCode = Data.substr(1,1).at(0);
|
||||||
std::cout << "Code : " << Code << std::endl;
|
std::cout << "Code : " << Code << std::endl;
|
||||||
std::cout << "Data : " << Data.substr(1) << std::endl;
|
std::cout << "Data : " << Data.substr(1) << std::endl;
|
||||||
switch (Code){
|
switch (Code){
|
||||||
@ -26,9 +32,14 @@ std::string Parse(const std::string& Data){
|
|||||||
case 'B':
|
case 'B':
|
||||||
return Code + HTTP_REQUEST("s1.yourthought.co.uk/servers-info",3599);
|
return Code + HTTP_REQUEST("s1.yourthought.co.uk/servers-info",3599);
|
||||||
case 'C':
|
case 'C':
|
||||||
//ProxyThread(Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
StartSync(Data);
|
||||||
SyncResources(Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
|
||||||
return "";
|
return "";
|
||||||
|
case 'U':
|
||||||
|
if(SubCode == 'l'){
|
||||||
|
return UlStatus;
|
||||||
|
}
|
||||||
|
case 'M':
|
||||||
|
return MStatus;
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
namespace fs = std::experimental::filesystem;
|
namespace fs = std::experimental::filesystem;
|
||||||
|
|
||||||
|
std::string UlStatus = "Ulstart";
|
||||||
|
std::string MStatus = " ";
|
||||||
|
|
||||||
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 = 0;
|
||||||
@ -25,7 +28,7 @@ std::vector<std::string> Split(const std::string& String,const std::string& deli
|
|||||||
Val.push_back(s);
|
Val.push_back(s);
|
||||||
return Val;
|
return Val;
|
||||||
}
|
}
|
||||||
|
void ProxyThread(const std::string& IP, int port);
|
||||||
void SyncResources(const std::string&IP,int Port){
|
void SyncResources(const std::string&IP,int Port){
|
||||||
std::cout << "Called" << std::endl;
|
std::cout << "Called" << std::endl;
|
||||||
std::string FileList;
|
std::string FileList;
|
||||||
@ -91,14 +94,16 @@ void SyncResources(const std::string&IP,int Port){
|
|||||||
if(a.empty() || a.length() < 2)continue;
|
if(a.empty() || a.length() < 2)continue;
|
||||||
if(stat(a.c_str(),&info)==0){
|
if(stat(a.c_str(),&info)==0){
|
||||||
if(fs::file_size(a)==std::stoi(FileSizes.at(index))){
|
if(fs::file_size(a)==std::stoi(FileSizes.at(index))){
|
||||||
|
index++;
|
||||||
continue;
|
continue;
|
||||||
}else remove(a.c_str());
|
}else remove(a.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(a.c_str());
|
LFS.open(a.c_str());
|
||||||
LFS.close();
|
LFS.close();
|
||||||
toSend = "b"+a;
|
toSend = "b"+a;
|
||||||
std::cout << a << std::endl;
|
//std::cout << a << std::endl;
|
||||||
send(SendingSocket, toSend.c_str(), toSend.length(), 0);
|
send(SendingSocket, toSend.c_str(), toSend.length(), 0);
|
||||||
LFS.open (a.c_str(), std::ios_base::app | std::ios::binary);
|
LFS.open (a.c_str(), std::ios_base::app | std::ios::binary);
|
||||||
do{
|
do{
|
||||||
@ -108,12 +113,22 @@ void SyncResources(const std::string&IP,int Port){
|
|||||||
memcpy(&Data[0],recvbuf,iResult);
|
memcpy(&Data[0],recvbuf,iResult);
|
||||||
if(Data.find("Cannot Open") != std::string::npos){File.clear();break;}
|
if(Data.find("Cannot Open") != std::string::npos){File.clear();break;}
|
||||||
LFS << Data;
|
LFS << Data;
|
||||||
std::cout << LFS.tellp()/std::stof(FileSizes.at(index))*100 << std::endl;
|
float per = LFS.tellp()/std::stof(FileSizes.at(index))*100;
|
||||||
|
std::string Percent = std::to_string(truncf(per*10)/10);
|
||||||
|
UlStatus="UlDownloading Resource: "+a.substr(a.find_last_of('/'))+" ("+Percent.substr(0,Percent.find('.')+2)+"%)";
|
||||||
|
//std::cout << UlStatus << std::endl;
|
||||||
}while(LFS.tellp() != std::stoi(FileSizes.at(index)));
|
}while(LFS.tellp() != std::stoi(FileSizes.at(index)));
|
||||||
LFS.close();
|
LFS.close();
|
||||||
File.clear();
|
File.clear();
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toSend = "M";
|
||||||
|
send(SendingSocket, toSend.c_str(), toSend.length(), 0);
|
||||||
|
iResult = recv(SendingSocket, recvbuf, recvbuflen, 0);
|
||||||
|
if(iResult < 0)break;
|
||||||
|
Data.resize(iResult);
|
||||||
|
memcpy(&Data[0],recvbuf,iResult);
|
||||||
|
MStatus = "M" + Data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (iResult == 0)
|
else if (iResult == 0)
|
||||||
@ -141,4 +156,8 @@ void SyncResources(const std::string&IP,int Port){
|
|||||||
|
|
||||||
if(WSACleanup() != 0)
|
if(WSACleanup() != 0)
|
||||||
printf("Client: WSACleanup() failed!...\n");
|
printf("Client: WSACleanup() failed!...\n");
|
||||||
|
|
||||||
|
UlStatus = "Uldone";
|
||||||
|
std::cout << "Done!" << std::endl;
|
||||||
|
//ProxyThread(IP,Port);
|
||||||
}
|
}
|
Binary file not shown.
6
main.cpp
6
main.cpp
@ -79,7 +79,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.21", Path = CheckDir(argv[0],ver),HTTP_Result;
|
std::string ver = "0.31", Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||||
CheckForUpdates(ver); //Update Check
|
CheckForUpdates(ver); //Update Check
|
||||||
|
|
||||||
//Security
|
//Security
|
||||||
@ -110,8 +110,8 @@ int main(int argc, char* argv[])
|
|||||||
///HTTP REQUEST FOR SERVER LIST
|
///HTTP REQUEST FOR SERVER LIST
|
||||||
///Mods
|
///Mods
|
||||||
|
|
||||||
//ProxyStart(); //Proxy main start
|
ProxyStart(); //Proxy main start
|
||||||
SyncResources("95.216.35.232",30817);
|
|
||||||
Exit("");
|
Exit("");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user