Auto server connection and sends transfer status to the game

This commit is contained in:
Anonymous275 2020-04-15 03:05:37 +03:00
parent f6a079a962
commit 66373ae44c
4 changed files with 42 additions and 12 deletions

View File

@ -5,7 +5,7 @@
#include <WS2tcpip.h>
#include <iostream>
#include <string>
#include <thread>
#define DEFAULT_BUFLEN 64000
#define DEFAULT_PORT "4444"
@ -13,11 +13,17 @@
#pragma clang diagnostic ignored "-Wmissing-noreturn"
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);
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){
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 << "Data : " << Data.substr(1) << std::endl;
switch (Code){
@ -26,9 +32,14 @@ std::string Parse(const std::string& Data){
case 'B':
return Code + HTTP_REQUEST("s1.yourthought.co.uk/servers-info",3599);
case 'C':
//ProxyThread(Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
SyncResources(Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
StartSync(Data);
return "";
case 'U':
if(SubCode == 'l'){
return UlStatus;
}
case 'M':
return MStatus;
default:
return "";
}

View File

@ -13,6 +13,9 @@
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> Val;
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);
return Val;
}
void ProxyThread(const std::string& IP, int port);
void SyncResources(const std::string&IP,int Port){
std::cout << "Called" << std::endl;
std::string FileList;
@ -91,14 +94,16 @@ void SyncResources(const std::string&IP,int Port){
if(a.empty() || a.length() < 2)continue;
if(stat(a.c_str(),&info)==0){
if(fs::file_size(a)==std::stoi(FileSizes.at(index))){
index++;
continue;
}else remove(a.c_str());
}
std::ofstream LFS;
LFS.open(a.c_str());
LFS.close();
toSend = "b"+a;
std::cout << a << std::endl;
//std::cout << a << std::endl;
send(SendingSocket, toSend.c_str(), toSend.length(), 0);
LFS.open (a.c_str(), std::ios_base::app | std::ios::binary);
do{
@ -108,12 +113,22 @@ void SyncResources(const std::string&IP,int Port){
memcpy(&Data[0],recvbuf,iResult);
if(Data.find("Cannot Open") != std::string::npos){File.clear();break;}
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)));
LFS.close();
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;
}
else if (iResult == 0)
@ -141,4 +156,8 @@ void SyncResources(const std::string&IP,int Port){
if(WSACleanup() != 0)
printf("Client: WSACleanup() failed!...\n");
UlStatus = "Uldone";
std::cout << "Done!" << std::endl;
//ProxyThread(IP,Port);
}

Binary file not shown.

View File

@ -79,7 +79,7 @@ std::string CheckVer(const std::string &path){
void SyncResources(const std::string&IP,int Port);
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
//Security
@ -110,8 +110,8 @@ int main(int argc, char* argv[])
///HTTP REQUEST FOR SERVER LIST
///Mods
//ProxyStart(); //Proxy main start
SyncResources("95.216.35.232",30817);
ProxyStart(); //Proxy main start
Exit("");
return 0;
}