mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-02 07:56:26 +00:00
launcher now waits for the game
This commit is contained in:
parent
042671b146
commit
07f7b69a88
@ -21,8 +21,8 @@ extern bool TCPTerminate;
|
||||
extern bool MPDEV;
|
||||
|
||||
void StartSync(const std::string &Data){
|
||||
//std::thread t1(SyncResources,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
||||
std::thread t1(SyncResources,"127.0.0.1",30814);
|
||||
std::thread t1(SyncResources,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
||||
//std::thread t1(SyncResources,"127.0.0.1",30814);
|
||||
t1.detach();
|
||||
}
|
||||
|
||||
|
@ -19,43 +19,45 @@ extern std::vector<std::string> GlobalInfo;
|
||||
bool TCPTerminate = false;
|
||||
bool Terminate = false;
|
||||
bool CServer = true;
|
||||
SOCKET*ClientSocket;
|
||||
bool gameConected = false;
|
||||
SOCKET ClientSocket;
|
||||
extern bool MPDEV;
|
||||
int ping = 0;
|
||||
|
||||
void GameSend(const std::string&Data){
|
||||
if(!TCPTerminate) {
|
||||
int iSendResult = send(*ClientSocket, (Data + "\n").c_str(), int(Data.length()) + 1, 0);
|
||||
if (iSendResult == SOCKET_ERROR) {
|
||||
if (MPDEV)std::cout << "(Proxy) send failed with error: " << WSAGetLastError() << std::endl;
|
||||
TCPTerminate = true;
|
||||
} else {
|
||||
if (MPDEV && Data.length() > 1000) {
|
||||
std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << std::endl;
|
||||
}
|
||||
//std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << " : " << Data << std::endl;
|
||||
if(TCPTerminate || !gameConected || ClientSocket == -1)return;
|
||||
int iSendResult = send(ClientSocket, (Data + "\n").c_str(), int(Data.length()) + 1, 0);
|
||||
if (iSendResult == SOCKET_ERROR) {
|
||||
if (MPDEV)std::cout << "(Proxy) send failed with error: " << WSAGetLastError() << std::endl;
|
||||
} else {
|
||||
if (MPDEV && Data.length() > 1000) {
|
||||
std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << std::endl;
|
||||
}
|
||||
//std::cout << "(Launcher->Game) Bytes sent: " << iSendResult << " : " << Data << std::endl;
|
||||
}
|
||||
}
|
||||
void TCPSendLarge(const std::string&Data);
|
||||
void TCPSend(const std::string&Data);
|
||||
void UDPSend(const std::string&Data);
|
||||
void ServerSend(const std::string&Data, bool Rel){
|
||||
if(!Terminate){
|
||||
char C = 0;
|
||||
if(Data.length() > 3)C = Data.at(0);
|
||||
if (C == 'O' || C == 'T')Rel = true;
|
||||
if(Terminate || Data.empty())return;
|
||||
char C = 0;
|
||||
if(Data.length() > 3)C = Data.at(0);
|
||||
if (C == 'O' || C == 'T')Rel = true;
|
||||
|
||||
if(Rel)TCPSend(Data);
|
||||
else UDPSend(Data);
|
||||
if(Rel){
|
||||
if(Data.length() > 1000)TCPSendLarge(Data);
|
||||
else TCPSend(Data);
|
||||
}
|
||||
else UDPSend(Data);
|
||||
|
||||
if (MPDEV && Data.length() > 1000) {
|
||||
std::cout << "(Launcher->Server) Bytes sent: " << Data.length()
|
||||
<< " : "
|
||||
<< Data.substr(0, 10)
|
||||
<< Data.substr(Data.length() - 10) << std::endl;
|
||||
}else if(MPDEV && C == 'Z'){
|
||||
//std::cout << "(Game->Launcher) : " << Data << std::endl;
|
||||
}
|
||||
if (MPDEV && Data.length() > 1000) {
|
||||
std::cout << "(Launcher->Server) Bytes sent: " << Data.length()
|
||||
<< " : "
|
||||
<< Data.substr(0, 10)
|
||||
<< Data.substr(Data.length() - 10) << std::endl;
|
||||
}else if(MPDEV && C == 'Z'){
|
||||
//std::cout << "(Game->Launcher) : " << Data << std::endl;
|
||||
}
|
||||
}
|
||||
void NameRespond(){
|
||||
@ -74,6 +76,7 @@ void AutoPing(){
|
||||
std::string UlStatus = "Ulstart";
|
||||
std::string MStatus = " ";
|
||||
void ServerParser(const std::string& Data){
|
||||
if(Data.empty())return;
|
||||
char Code = Data.at(0),SubCode = 0;
|
||||
if(Data.length() > 1)SubCode = Data.at(1);
|
||||
switch (Code) {
|
||||
@ -108,8 +111,8 @@ void NetMain(const std::string& IP, int Port){
|
||||
extern SOCKET UDPSock;
|
||||
extern SOCKET TCPSock;
|
||||
void Reset() {
|
||||
ClientSocket = nullptr;
|
||||
TCPTerminate = false;
|
||||
gameConected = false;
|
||||
Terminate = false;
|
||||
UlStatus = "Ulstart";
|
||||
MStatus = " ";
|
||||
@ -195,13 +198,14 @@ void TCPGameServer(const std::string& IP, int Port){
|
||||
}
|
||||
closesocket(ListenSocket);
|
||||
if(MPDEV)std::cout << "(Proxy) Game Connected!" << std::endl;
|
||||
gameConected = true;
|
||||
if(CServer){
|
||||
std::thread t1(NetMain, IP, Port);
|
||||
t1.detach();
|
||||
CServer = false;
|
||||
}
|
||||
|
||||
ClientSocket = &Socket;
|
||||
ClientSocket = Socket;
|
||||
do {
|
||||
//std::cout << "(Proxy) Waiting for Game Data..." << std::endl;
|
||||
iResult = recv(Socket, recvbuf, recvbuflen, 0);
|
||||
@ -250,8 +254,8 @@ void ProxyStart(){
|
||||
}
|
||||
|
||||
void ProxyThread(const std::string& IP, int Port){
|
||||
auto*t1 = new std::thread(TCPGameServer,IP,Port);
|
||||
t1->detach();
|
||||
std::thread GameThread(TCPGameServer,IP,Port);
|
||||
GameThread.detach();
|
||||
/*std::thread t2(VehicleNetworkStart);
|
||||
t2.detach();*/
|
||||
}
|
@ -6,12 +6,15 @@
|
||||
#include <WS2tcpip.h>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
extern bool Terminate;
|
||||
extern int ClientID;
|
||||
SOCKET UDPSock;
|
||||
sockaddr_in ToServer{};
|
||||
|
||||
std::set<std::pair<int,std::string>> BigDataAcks;
|
||||
void UDPSend(const std::string&Data){
|
||||
if(ClientID == -1 || UDPSock == INVALID_SOCKET)return;
|
||||
std::string Packet = char(ClientID+1) + std::string(":") + Data;
|
||||
@ -19,10 +22,49 @@ void UDPSend(const std::string&Data){
|
||||
if (sendOk == SOCKET_ERROR)std::cout << "Error Code : " << WSAGetLastError() << std::endl;
|
||||
}
|
||||
|
||||
void LOOP(){
|
||||
while(UDPSock != -1) {
|
||||
for (const std::pair<int, std::string>& a : BigDataAcks) {
|
||||
//UDPSend(a.second);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
}
|
||||
}
|
||||
|
||||
void AckID(int ID){
|
||||
if(BigDataAcks.empty())return;
|
||||
for(const std::pair<int,std::string>& a : BigDataAcks){
|
||||
if(a.first == ID)BigDataAcks.erase(a);
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSendLarge(const std::string&Data){
|
||||
static int ID = 0;
|
||||
std::string Header = "BD:" + std::to_string(ID) + ":";
|
||||
//BigDataAcks.insert(std::make_pair(ID,Header+Data));
|
||||
UDPSend(Header+Data);
|
||||
if(ID > 483647)ID = 0;
|
||||
else ID++;
|
||||
}
|
||||
|
||||
void ServerParser(const std::string& Data);
|
||||
void UDPParser(const std::string&Packet){
|
||||
if(Packet.substr(0,4) == "ACK:"){
|
||||
AckID(stoi(Packet.substr(4)));
|
||||
return;
|
||||
}else if(Packet.substr(0,3) == "BD:"){
|
||||
int pos = Packet.find(':',4);
|
||||
std::string pckt = "ACK:" + Packet.substr(3,pos-3);
|
||||
UDPSend(pckt);
|
||||
pckt = Packet.substr(pos+1);
|
||||
ServerParser(pckt);
|
||||
return;
|
||||
}
|
||||
ServerParser(Packet);
|
||||
}
|
||||
void UDPRcv(){
|
||||
char buf[4096];
|
||||
int len = 4096;
|
||||
char buf[10240];
|
||||
int len = 10240;
|
||||
sockaddr_in FromServer{};
|
||||
int clientLength = sizeof(FromServer);
|
||||
ZeroMemory(&FromServer, clientLength);
|
||||
@ -34,7 +76,7 @@ void UDPRcv(){
|
||||
//std::cout << "Error receiving from Server " << WSAGetLastError() << std::endl;
|
||||
return;
|
||||
}
|
||||
ServerParser(std::string(buf));
|
||||
UDPParser(std::string(buf));
|
||||
}
|
||||
void TCPSend(const std::string&Data);
|
||||
void UDPClientMain(const std::string& IP,int Port){
|
||||
@ -49,8 +91,9 @@ void UDPClientMain(const std::string& IP,int Port){
|
||||
ToServer.sin_port = htons(Port);
|
||||
inet_pton(AF_INET, IP.c_str(), &ToServer.sin_addr);
|
||||
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
|
||||
BigDataAcks.clear();
|
||||
std::thread Ack(LOOP);
|
||||
Ack.detach();
|
||||
TCPSend("P");
|
||||
UDPSend("p");
|
||||
while (!Terminate){
|
||||
|
@ -6,10 +6,14 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <WS2tcpip.h>
|
||||
#include <thread>
|
||||
|
||||
#pragma comment (lib, "ws2_32.lib")
|
||||
extern bool Terminate;
|
||||
extern bool MPDEV;
|
||||
SOCKET TCPSock;
|
||||
|
||||
|
||||
void TCPSend(const std::string&Data){
|
||||
if(TCPSock == INVALID_SOCKET){
|
||||
Terminate = true;
|
||||
@ -29,10 +33,11 @@ void TCPSend(const std::string&Data){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ServerParser(const std::string& Data);
|
||||
void TCPRcv(){
|
||||
char buf[10240];
|
||||
int len = 10240;
|
||||
char buf[4096];
|
||||
int len = 4096;
|
||||
ZeroMemory(buf, len);
|
||||
if(TCPSock == INVALID_SOCKET){
|
||||
Terminate = true;
|
||||
@ -67,9 +72,11 @@ void TCPClientMain(const std::string& IP,int Port){
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
ServerAddr.sin_family = AF_INET;
|
||||
ServerAddr.sin_port = htons(Port);
|
||||
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
||||
|
||||
RetCode = connect(TCPSock, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
|
||||
if(RetCode != 0)
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ int main(int argc, char* argv[]){
|
||||
const unsigned long long NPos = std::string::npos;
|
||||
struct stat info{};
|
||||
|
||||
std::string ver = "1.0", link, Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||
std::string ver = "1.1", link, Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||
std::thread CFU(CheckForUpdates,ver);
|
||||
CFU.join();
|
||||
if(argc > 1){
|
||||
@ -115,7 +115,7 @@ int main(int argc, char* argv[]){
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}else MPDEV = false;
|
||||
}else MPDEV = true;
|
||||
//Security
|
||||
auto*Sec = new std::thread(Check);
|
||||
Sec->join();
|
||||
|
Loading…
x
Reference in New Issue
Block a user