mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +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);
|
void SyncResources(const std::string& IP, int port);
|
||||||
extern std::string UlStatus;
|
extern std::string UlStatus;
|
||||||
extern std::string MStatus;
|
extern std::string MStatus;
|
||||||
|
extern int ping;
|
||||||
void StartSync(const std::string &Data){
|
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,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
||||||
t1.detach();
|
t1.detach();
|
||||||
@ -24,8 +25,8 @@ void StartSync(const std::string &Data){
|
|||||||
std::string Parse(const std::string& Data){
|
std::string Parse(const std::string& Data){
|
||||||
char Code = Data.substr(0,1).at(0), SubCode = 0;
|
char Code = Data.substr(0,1).at(0), SubCode = 0;
|
||||||
if(Data.length() > 1)SubCode = Data.substr(1,1).at(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){
|
||||||
case 'A':
|
case 'A':
|
||||||
return Data.substr(0,1);
|
return Data.substr(0,1);
|
||||||
@ -35,9 +36,9 @@ std::string Parse(const std::string& Data){
|
|||||||
StartSync(Data);
|
StartSync(Data);
|
||||||
return "";
|
return "";
|
||||||
case 'U':
|
case 'U':
|
||||||
if(SubCode == 'l'){
|
if(SubCode == 'l')return UlStatus;
|
||||||
return UlStatus;
|
if(SubCode == 'p')return "Up" + std::to_string(ping);
|
||||||
}
|
if(!SubCode)return UlStatus+ "\n" + "Up" + std::to_string(ping);
|
||||||
case 'M':
|
case 'M':
|
||||||
return MStatus;
|
return MStatus;
|
||||||
default:
|
default:
|
||||||
@ -125,7 +126,7 @@ void CoreNetworkThread(){
|
|||||||
else if (iResult == 0)
|
else if (iResult == 0)
|
||||||
std::cout << "Connection closing...\n";
|
std::cout << "Connection closing...\n";
|
||||||
else {
|
else {
|
||||||
std::cout << "recv failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Core Network) recv failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
@ -136,7 +137,7 @@ void CoreNetworkThread(){
|
|||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}else{
|
}else{
|
||||||
std::cout << "Bytes sent: " << iSendResult << std::endl;
|
///std::cout << "Bytes sent: " << iSendResult << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (iResult > 0);
|
} while (iResult > 0);
|
||||||
|
@ -134,7 +134,7 @@ void SyncResources(const std::string&IP,int Port){
|
|||||||
else if (iResult == 0)
|
else if (iResult == 0)
|
||||||
printf("Connection closing...\n");
|
printf("Connection closing...\n");
|
||||||
else {
|
else {
|
||||||
printf("recv failed with error: %d\n", WSAGetLastError());
|
printf("(Resources) recv failed with error: %d\n", WSAGetLastError());
|
||||||
closesocket(SendingSocket);
|
closesocket(SendingSocket);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -159,5 +159,5 @@ void SyncResources(const std::string&IP,int Port){
|
|||||||
|
|
||||||
UlStatus = "Uldone";
|
UlStatus = "Uldone";
|
||||||
std::cout << "Done!" << std::endl;
|
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);
|
void SyncResources(const std::string&IP,int Port);
|
||||||
int main(int argc, char* argv[])
|
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
|
CheckForUpdates(ver); //Update Check
|
||||||
|
|
||||||
//Security
|
//Security
|
||||||
|
20
proxy.cpp
20
proxy.cpp
@ -5,9 +5,10 @@
|
|||||||
#define ENET_IMPLEMENTATION
|
#define ENET_IMPLEMENTATION
|
||||||
#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 <cstdio>
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
@ -23,10 +24,9 @@ std::queue<std::string> RUDPData;
|
|||||||
std::queue<std::string> RUDPToSend;
|
std::queue<std::string> RUDPToSend;
|
||||||
bool Terminate = false;
|
bool Terminate = false;
|
||||||
|
|
||||||
|
int ping = 0;
|
||||||
void CoreNetworkThread();
|
void CoreNetworkThread();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
void HandleEvent(ENetEvent event,Client client){
|
void HandleEvent(ENetEvent event,Client client){
|
||||||
@ -85,10 +85,19 @@ void RUDPClientThread(const std::string& IP, int Port){
|
|||||||
RUDPToSend.front().size()+1,
|
RUDPToSend.front().size()+1,
|
||||||
ENET_PACKET_FLAG_RELIABLE); //Create A reliable packet using the data
|
ENET_PACKET_FLAG_RELIABLE); //Create A reliable packet using the data
|
||||||
enet_peer_send(client.peer, 0, packet);
|
enet_peer_send(client.peer, 0, packet);
|
||||||
|
ping = client.peer->ping;
|
||||||
|
|
||||||
std::cout << "sending : " << RUDPToSend.front() << std::endl;
|
std::cout << "sending : " << RUDPToSend.front() << std::endl;
|
||||||
RUDPToSend.pop();
|
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);
|
} while (!Terminate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +105,7 @@ void RUDPClientThread(const std::string& IP, int Port){
|
|||||||
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
||||||
void TCPServerThread(const std::string& IP, int Port){
|
void TCPServerThread(const std::string& IP, int Port){
|
||||||
Terminate = false;
|
Terminate = false;
|
||||||
|
std::cout << "Proxy Started!" << std::endl;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
int iResult;
|
int iResult;
|
||||||
SOCKET ListenSocket = INVALID_SOCKET;
|
SOCKET ListenSocket = INVALID_SOCKET;
|
||||||
@ -190,7 +200,7 @@ void TCPServerThread(const std::string& IP, int Port){
|
|||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "recv failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Proxy) recv failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user