mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 15:36:10 +00:00
ping fix, fixed data timeout
This commit is contained in:
parent
66373ae44c
commit
4d42289b1d
@ -16,6 +16,7 @@ std::string HTTP_REQUEST(const std::string&url,int port);
|
||||
void SyncResources(const std::string& IP, int port);
|
||||
extern std::string UlStatus;
|
||||
extern std::string MStatus;
|
||||
extern int ping;
|
||||
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();
|
||||
@ -24,8 +25,8 @@ void StartSync(const std::string &Data){
|
||||
std::string Parse(const std::string& Data){
|
||||
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;
|
||||
////std::cout << "Code : " << Code << std::endl;
|
||||
////std::cout << "Data : " << Data.substr(1) << std::endl;
|
||||
switch (Code){
|
||||
case 'A':
|
||||
return Data.substr(0,1);
|
||||
@ -35,9 +36,9 @@ std::string Parse(const std::string& Data){
|
||||
StartSync(Data);
|
||||
return "";
|
||||
case 'U':
|
||||
if(SubCode == 'l'){
|
||||
return UlStatus;
|
||||
}
|
||||
if(SubCode == 'l')return UlStatus;
|
||||
if(SubCode == 'p')return "Up" + std::to_string(ping);
|
||||
if(!SubCode)return UlStatus+ "\n" + "Up" + std::to_string(ping);
|
||||
case 'M':
|
||||
return MStatus;
|
||||
default:
|
||||
@ -125,7 +126,7 @@ void CoreNetworkThread(){
|
||||
else if (iResult == 0)
|
||||
std::cout << "Connection closing...\n";
|
||||
else {
|
||||
std::cout << "recv failed with error: " << WSAGetLastError() << std::endl;
|
||||
std::cout << "(Core Network) recv failed with error: " << WSAGetLastError() << std::endl;
|
||||
closesocket(ClientSocket);
|
||||
WSACleanup();
|
||||
}
|
||||
@ -136,7 +137,7 @@ void CoreNetworkThread(){
|
||||
closesocket(ClientSocket);
|
||||
WSACleanup();
|
||||
}else{
|
||||
std::cout << "Bytes sent: " << iSendResult << std::endl;
|
||||
///std::cout << "Bytes sent: " << iSendResult << std::endl;
|
||||
}
|
||||
}
|
||||
} while (iResult > 0);
|
||||
|
@ -134,7 +134,7 @@ void SyncResources(const std::string&IP,int Port){
|
||||
else if (iResult == 0)
|
||||
printf("Connection closing...\n");
|
||||
else {
|
||||
printf("recv failed with error: %d\n", WSAGetLastError());
|
||||
printf("(Resources) recv failed with error: %d\n", WSAGetLastError());
|
||||
closesocket(SendingSocket);
|
||||
break;
|
||||
}
|
||||
@ -159,5 +159,5 @@ void SyncResources(const std::string&IP,int Port){
|
||||
|
||||
UlStatus = "Uldone";
|
||||
std::cout << "Done!" << std::endl;
|
||||
//ProxyThread(IP,Port);
|
||||
ProxyThread(IP,Port);
|
||||
}
|
7893
include/enet.h
7893
include/enet.h
File diff suppressed because it is too large
Load Diff
2
main.cpp
2
main.cpp
@ -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.31", Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||
std::string ver = "0.36", Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||
CheckForUpdates(ver); //Update Check
|
||||
|
||||
//Security
|
||||
|
20
proxy.cpp
20
proxy.cpp
@ -5,9 +5,10 @@
|
||||
#define ENET_IMPLEMENTATION
|
||||
#include "include/enet.h"
|
||||
#include <WinSock2.h>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <WS2tcpip.h>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <queue>
|
||||
@ -23,10 +24,9 @@ std::queue<std::string> RUDPData;
|
||||
std::queue<std::string> RUDPToSend;
|
||||
bool Terminate = false;
|
||||
|
||||
int ping = 0;
|
||||
void CoreNetworkThread();
|
||||
|
||||
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
#pragma clang diagnostic pop
|
||||
void HandleEvent(ENetEvent event,Client client){
|
||||
@ -85,10 +85,19 @@ void RUDPClientThread(const std::string& IP, int Port){
|
||||
RUDPToSend.front().size()+1,
|
||||
ENET_PACKET_FLAG_RELIABLE); //Create A reliable packet using the data
|
||||
enet_peer_send(client.peer, 0, packet);
|
||||
ping = client.peer->ping;
|
||||
|
||||
std::cout << "sending : " << RUDPToSend.front() << std::endl;
|
||||
RUDPToSend.pop();
|
||||
}
|
||||
Sleep(10);
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
int Interval = 0;
|
||||
while(Interval < 200 && RUDPToSend.empty()){
|
||||
auto done = std::chrono::high_resolution_clock::now();
|
||||
Interval = std::chrono::duration_cast<std::chrono::milliseconds>(done-start).count();
|
||||
ping = client.peer->ping;
|
||||
}
|
||||
} while (!Terminate);
|
||||
}
|
||||
|
||||
@ -96,6 +105,7 @@ void RUDPClientThread(const std::string& IP, int Port){
|
||||
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
||||
void TCPServerThread(const std::string& IP, int Port){
|
||||
Terminate = false;
|
||||
std::cout << "Proxy Started!" << std::endl;
|
||||
WSADATA wsaData;
|
||||
int iResult;
|
||||
SOCKET ListenSocket = INVALID_SOCKET;
|
||||
@ -190,7 +200,7 @@ void TCPServerThread(const std::string& IP, int Port){
|
||||
|
||||
}
|
||||
else {
|
||||
std::cout << "recv failed with error: " << WSAGetLastError() << std::endl;
|
||||
std::cout << "(Proxy) recv failed with error: " << WSAGetLastError() << std::endl;
|
||||
closesocket(ClientSocket);
|
||||
WSACleanup();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user