mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-03 08:26:01 +00:00
3 crash fixes+fixed timeout issues
This commit is contained in:
parent
f286a95d8e
commit
3aeb2cae1b
@ -17,6 +17,8 @@ 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;
|
extern int ping;
|
||||||
|
extern bool Terminate;
|
||||||
|
extern bool TCPTerminate;
|
||||||
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();
|
||||||
@ -41,14 +43,22 @@ std::string Parse(const std::string& Data){
|
|||||||
if(!SubCode)return UlStatus+ "\n" + "Up" + std::to_string(ping);
|
if(!SubCode)return UlStatus+ "\n" + "Up" + std::to_string(ping);
|
||||||
case 'M':
|
case 'M':
|
||||||
return MStatus;
|
return MStatus;
|
||||||
|
case 'Q':
|
||||||
|
if(SubCode == 'S'){
|
||||||
|
Terminate = true;
|
||||||
|
TCPTerminate = true; ////Revisit later when TCP is stable
|
||||||
|
}
|
||||||
|
if(SubCode == 'G')exit(2);
|
||||||
|
return "";
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CoreNetworkThread(){
|
[[noreturn]] void CoreNetworkThread(){
|
||||||
do{
|
do{
|
||||||
|
std::cout << "Core Network on start!" << std::endl;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
int iResult;
|
int iResult;
|
||||||
SOCKET ListenSocket = INVALID_SOCKET;
|
SOCKET ListenSocket = INVALID_SOCKET;
|
||||||
@ -76,14 +86,14 @@ void CoreNetworkThread(){
|
|||||||
// Resolve the server address and port
|
// Resolve the server address and port
|
||||||
iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result);
|
iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result);
|
||||||
if ( iResult != 0 ) {
|
if ( iResult != 0 ) {
|
||||||
std::cout << "getaddrinfo failed with error: " << iResult << std::endl;
|
std::cout << "(Core) getaddrinfo failed with error: " << iResult << std::endl;
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a socket for connecting to server
|
// Create a socket for connecting to server
|
||||||
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
|
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
|
||||||
if (ListenSocket == INVALID_SOCKET) {
|
if (ListenSocket == INVALID_SOCKET) {
|
||||||
std::cout << "socket failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Core) socket failed with error: " << WSAGetLastError() << std::endl;
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
@ -91,7 +101,7 @@ void CoreNetworkThread(){
|
|||||||
// Setup the TCP listening socket
|
// Setup the TCP listening socket
|
||||||
iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
|
iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
|
||||||
if (iResult == SOCKET_ERROR) {
|
if (iResult == SOCKET_ERROR) {
|
||||||
std::cout << "bind failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Core) bind failed with error: " << WSAGetLastError() << std::endl;
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
closesocket(ListenSocket);
|
closesocket(ListenSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
@ -101,13 +111,13 @@ void CoreNetworkThread(){
|
|||||||
|
|
||||||
iResult = listen(ListenSocket, SOMAXCONN);
|
iResult = listen(ListenSocket, SOMAXCONN);
|
||||||
if (iResult == SOCKET_ERROR) {
|
if (iResult == SOCKET_ERROR) {
|
||||||
std::cout << "listen failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Core) listen failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ListenSocket);
|
closesocket(ListenSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
ClientSocket = accept(ListenSocket, nullptr, nullptr);
|
ClientSocket = accept(ListenSocket, nullptr, nullptr);
|
||||||
if (ClientSocket == INVALID_SOCKET) {
|
if (ClientSocket == INVALID_SOCKET) {
|
||||||
std::cout << "accept failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Core) accept failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ListenSocket);
|
closesocket(ListenSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
@ -124,14 +134,14 @@ void CoreNetworkThread(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (iResult == 0)
|
else if (iResult == 0)
|
||||||
std::cout << "Connection closing...\n";
|
std::cout << "(Core) Connection closing...\n";
|
||||||
else {
|
else {
|
||||||
std::cout << "(Core Network) recv failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Core) recv failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
if(!Response.empty()){
|
if(!Response.empty()){
|
||||||
iSendResult = send( ClientSocket, Response.c_str(), int(Response.length()), 0);
|
iSendResult = send( ClientSocket, Response.c_str(), Response.length(), 0);
|
||||||
if (iSendResult == SOCKET_ERROR) {
|
if (iSendResult == SOCKET_ERROR) {
|
||||||
std::cout << "send failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "send failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
@ -144,9 +154,10 @@ void CoreNetworkThread(){
|
|||||||
|
|
||||||
iResult = shutdown(ClientSocket, SD_SEND);
|
iResult = shutdown(ClientSocket, SD_SEND);
|
||||||
if (iResult == SOCKET_ERROR) {
|
if (iResult == SOCKET_ERROR) {
|
||||||
std::cout << "shutdown failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Core) shutdown failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
Sleep(500);
|
||||||
}
|
}
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
12
main.cpp
12
main.cpp
@ -39,22 +39,18 @@ void Exit(const std::string& Msg){
|
|||||||
std::string CheckDir(char*dir, const std::string& ver){
|
std::string CheckDir(char*dir, const std::string& ver){
|
||||||
system(("title BeamMP Launcher v" + ver).c_str());
|
system(("title BeamMP Launcher v" + ver).c_str());
|
||||||
char*temp;size_t len;
|
char*temp;size_t len;
|
||||||
|
struct stat info{};
|
||||||
_dupenv_s(&temp, &len,"APPDATA");
|
_dupenv_s(&temp, &len,"APPDATA");
|
||||||
std::string DN = "BeamMP-Launcher.exe",CDir = dir, AD = temp,FN = CDir.substr(CDir.find_last_of('\\')+1,CDir.size());
|
std::string DN = "BeamMP-Launcher.exe",CDir = dir, AD = temp,FN = CDir.substr(CDir.find_last_of('\\')+1,CDir.size());
|
||||||
AD += "\\BeamMP-Launcher";
|
AD += "\\BeamMP-Launcher";
|
||||||
|
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
||||||
if(FN != DN){
|
if(FN != DN)SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
||||||
SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(CDir.substr(0,CDir.find_last_of('\\')) != AD){
|
if(CDir.substr(0,CDir.find_last_of('\\')) != AD){
|
||||||
_mkdir(AD.c_str());
|
_mkdir(AD.c_str());
|
||||||
SystemExec(R"(move "BeamMP-Launcher.exe" ")" + AD + "\">nul");
|
SystemExec(R"(move "BeamMP-Launcher.exe" ")" + AD + "\">nul");
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCurrentDirectoryA(AD.c_str());
|
SetCurrentDirectoryA(AD.c_str());
|
||||||
SystemExec("rename *.exe " + DN + ">nul");
|
SystemExec("rename *.exe " + DN + ">nul");
|
||||||
|
|
||||||
SystemExec(R"(powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\BeamMP-Launcher.lnk');$s.TargetPath=')"+AD+"\\"+DN+"';$s.Save()\"");
|
SystemExec(R"(powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\BeamMP-Launcher.lnk');$s.TargetPath=')"+AD+"\\"+DN+"';$s.Save()\"");
|
||||||
CreateDirectoryA("BeamNG",nullptr);
|
CreateDirectoryA("BeamNG",nullptr);
|
||||||
CreateDirectoryA("BeamNG\\mods",nullptr);
|
CreateDirectoryA("BeamNG\\mods",nullptr);
|
||||||
@ -80,7 +76,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.40", Path = CheckDir(argv[0],ver),HTTP_Result;
|
std::string ver = "0.51", Path = CheckDir(argv[0],ver),HTTP_Result;
|
||||||
CheckForUpdates(ver); //Update Check
|
CheckForUpdates(ver); //Update Check
|
||||||
|
|
||||||
//Security
|
//Security
|
||||||
|
124
proxy.cpp
124
proxy.cpp
@ -21,14 +21,17 @@ typedef struct {
|
|||||||
} Client;
|
} Client;
|
||||||
std::chrono::time_point<std::chrono::steady_clock> PingStart,PingEnd;
|
std::chrono::time_point<std::chrono::steady_clock> PingStart,PingEnd;
|
||||||
extern std::vector<std::string> GlobalInfo;
|
extern std::vector<std::string> GlobalInfo;
|
||||||
std::queue<std::string> RUDPData;
|
|
||||||
std::queue<std::string> RUDPToSend;
|
std::queue<std::string> RUDPToSend;
|
||||||
|
std::queue<std::string> RUDPData;
|
||||||
|
bool TCPTerminate = false;
|
||||||
bool Terminate = false;
|
bool Terminate = false;
|
||||||
|
bool CServer = true;
|
||||||
int ping = 0;
|
int ping = 0;
|
||||||
void CoreNetworkThread();
|
|
||||||
|
[[noreturn]] void CoreNetworkThread();
|
||||||
|
|
||||||
void AutoPing(ENetPeer*peer){
|
void AutoPing(ENetPeer*peer){
|
||||||
while(!Terminate){
|
while(!Terminate && peer != nullptr){
|
||||||
enet_peer_send(peer, 0, enet_packet_create("p", 2, ENET_PACKET_FLAG_RELIABLE));
|
enet_peer_send(peer, 0, enet_packet_create("p", 2, ENET_PACKET_FLAG_RELIABLE));
|
||||||
PingStart = std::chrono::high_resolution_clock::now();
|
PingStart = std::chrono::high_resolution_clock::now();
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
@ -51,18 +54,15 @@ void RUDPParser(const std::string& Data,ENetPeer*peer){
|
|||||||
if(SubCode == 'R')NameRespond(peer);
|
if(SubCode == 'R')NameRespond(peer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout << "Received: " << Data << std::endl;
|
///std::cout << "Received: " << Data << std::endl;
|
||||||
RUDPData.push(Data);
|
RUDPData.push(Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
void HandleEvent(ENetEvent event,Client client){
|
void HandleEvent(ENetEvent event,Client client){
|
||||||
switch (event.type){
|
switch (event.type){
|
||||||
case ENET_EVENT_TYPE_CONNECT:
|
case ENET_EVENT_TYPE_CONNECT:
|
||||||
printf("Client Connected port : %u.\n",event.peer->address.port);
|
std::cout << "(Launcher->Server) Client Connected!" << std::endl;
|
||||||
//Name Of the Server
|
//printf("Client Connected port : %u.\n",event.peer->address.port);
|
||||||
event.peer->data = (void *)"Connected Server";
|
event.peer->data = (void *)"Connected Server";
|
||||||
break;
|
break;
|
||||||
case ENET_EVENT_TYPE_RECEIVE:
|
case ENET_EVENT_TYPE_RECEIVE:
|
||||||
@ -71,12 +71,13 @@ void HandleEvent(ENetEvent event,Client client){
|
|||||||
break;
|
break;
|
||||||
case ENET_EVENT_TYPE_DISCONNECT:
|
case ENET_EVENT_TYPE_DISCONNECT:
|
||||||
printf ("%s disconnected.\n", (char *)event.peer->data);
|
printf ("%s disconnected.\n", (char *)event.peer->data);
|
||||||
// Reset the peer's client information.
|
|
||||||
event.peer->data = nullptr;
|
event.peer->data = nullptr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
|
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT:
|
||||||
printf ("%s timeout.\n", (char *)event.peer->data);
|
printf ("%s timeout.\n", (char *)event.peer->data);
|
||||||
|
CServer = true;
|
||||||
|
Terminate = true;
|
||||||
event.peer->data = nullptr;
|
event.peer->data = nullptr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ void RUDPClientThread(const std::string& IP, int Port){
|
|||||||
address.port = Port;
|
address.port = Port;
|
||||||
|
|
||||||
|
|
||||||
std::cout << "starting client...\n";
|
std::cout << "(Launcher->Server) Connecting...\n";
|
||||||
|
|
||||||
enet_address_set_host(&address, IP.c_str());
|
enet_address_set_host(&address, IP.c_str());
|
||||||
client.host = enet_host_create(nullptr, 1, 2, 0, 0);
|
client.host = enet_host_create(nullptr, 1, 2, 0, 0);
|
||||||
@ -108,16 +109,16 @@ void RUDPClientThread(const std::string& IP, int Port){
|
|||||||
}
|
}
|
||||||
std::thread Ping(AutoPing,client.peer);
|
std::thread Ping(AutoPing,client.peer);
|
||||||
Ping.detach();
|
Ping.detach();
|
||||||
do {
|
|
||||||
ENetEvent event;
|
ENetEvent event;
|
||||||
|
do {
|
||||||
enet_host_service(client.host, &event, 0);
|
enet_host_service(client.host, &event, 0);
|
||||||
HandleEvent(event,client); //Handles the Events
|
HandleEvent(event,client);
|
||||||
while (!RUDPToSend.empty()){
|
while (!RUDPToSend.empty()){
|
||||||
ENetPacket* packet = enet_packet_create(RUDPToSend.front().c_str(),
|
ENetPacket* packet = enet_packet_create(RUDPToSend.front().c_str(),
|
||||||
RUDPToSend.front().length()+1,
|
RUDPToSend.front().length()+1,
|
||||||
ENET_PACKET_FLAG_RELIABLE);
|
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT);
|
||||||
enet_peer_send(client.peer, 0, packet);
|
enet_peer_send(client.peer, 0, packet);
|
||||||
std::cout << "sending : " << RUDPToSend.front() << std::endl;
|
std::cout << "(Launcher->Server) sending : " << RUDPToSend.front() << std::endl;
|
||||||
RUDPToSend.pop();
|
RUDPToSend.pop();
|
||||||
}
|
}
|
||||||
while(RUDPToSend.empty() && Interval < 1000){
|
while(RUDPToSend.empty() && Interval < 1000){
|
||||||
@ -125,13 +126,36 @@ void RUDPClientThread(const std::string& IP, int Port){
|
|||||||
Interval = std::chrono::duration_cast<std::chrono::milliseconds>(done-start).count();
|
Interval = std::chrono::duration_cast<std::chrono::milliseconds>(done-start).count();
|
||||||
}
|
}
|
||||||
} while (!Terminate);
|
} while (!Terminate);
|
||||||
|
enet_peer_disconnect(client.peer,0);
|
||||||
|
enet_host_service(client.host, &event, 0);
|
||||||
|
HandleEvent(event,client);
|
||||||
|
CServer = true;
|
||||||
|
std::cout << "(Launcher->Server) Terminated!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TCPRespond(SOCKET *CS){
|
||||||
|
int iSendResult;
|
||||||
|
SOCKET ClientSocket = *CS;
|
||||||
|
while(ClientSocket != INVALID_SOCKET){
|
||||||
|
while (!RUDPData.empty()) {
|
||||||
|
RUDPData.front() += "\n";
|
||||||
|
iSendResult = send(ClientSocket, RUDPData.front().c_str(), RUDPData.front().length(), 0);
|
||||||
|
if (iSendResult == SOCKET_ERROR) {
|
||||||
|
std::cout << "(Proxy) send failed with error: " << WSAGetLastError() << std::endl;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
RUDPData.pop();
|
||||||
|
std::cout << "(Proxy->Game) Bytes sent: " << iSendResult << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
|
||||||
void TCPServerThread(const std::string& IP, int Port){
|
void TCPServerThread(const std::string& IP, int Port){
|
||||||
|
std::cout << "Proxy Started! " << IP << ":" << Port << std::endl;
|
||||||
|
do {
|
||||||
Terminate = false;
|
Terminate = false;
|
||||||
std::cout << "Proxy Started!" << std::endl;
|
std::cout << "Proxy on Start" << std::endl;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
int iResult;
|
int iResult;
|
||||||
SOCKET ListenSocket = INVALID_SOCKET;
|
SOCKET ListenSocket = INVALID_SOCKET;
|
||||||
@ -147,7 +171,9 @@ void TCPServerThread(const std::string& IP, int Port){
|
|||||||
// Initialize Winsock
|
// Initialize Winsock
|
||||||
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||||
if (iResult != 0) {
|
if (iResult != 0) {
|
||||||
std::cout <<"WSAStartup failed with error: " << iResult << std::endl;
|
std::cout << "(Proxy) WSAStartup failed with error: " << iResult << std::endl;
|
||||||
|
std::cin.get();
|
||||||
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMemory(&hints, sizeof(hints));
|
ZeroMemory(&hints, sizeof(hints));
|
||||||
@ -159,90 +185,87 @@ void TCPServerThread(const std::string& IP, int Port){
|
|||||||
// Resolve the server address and port
|
// Resolve the server address and port
|
||||||
iResult = getaddrinfo(nullptr, DEFAULT_PORT, &hints, &result);
|
iResult = getaddrinfo(nullptr, DEFAULT_PORT, &hints, &result);
|
||||||
if (iResult != 0) {
|
if (iResult != 0) {
|
||||||
std::cout << "getaddrinfo failed with error: " << iResult << std::endl;
|
std::cout << "(Proxy) getaddrinfo failed with error: " << iResult << std::endl;
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a socket for connecting to server
|
// Create a socket for connecting to server
|
||||||
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
|
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
|
||||||
if (ListenSocket == INVALID_SOCKET) {
|
if (ListenSocket == INVALID_SOCKET) {
|
||||||
std::cout << "socket failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Proxy) socket failed with error: " << WSAGetLastError() << std::endl;
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the TCP listening socket
|
// Setup the TCP listening socket
|
||||||
iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen);
|
iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen);
|
||||||
if (iResult == SOCKET_ERROR) {
|
if (iResult == SOCKET_ERROR) {
|
||||||
std::cout << "bind failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Proxy) bind failed with error: " << WSAGetLastError() << std::endl;
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
closesocket(ListenSocket);
|
closesocket(ListenSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
|
||||||
iResult = listen(ListenSocket, SOMAXCONN);
|
iResult = listen(ListenSocket, SOMAXCONN);
|
||||||
if (iResult == SOCKET_ERROR) {
|
if (iResult == SOCKET_ERROR) {
|
||||||
std::cout << "listen failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Proxy) listen failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ListenSocket);
|
closesocket(ListenSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
ClientSocket = accept(ListenSocket, NULL, NULL);
|
ClientSocket = accept(ListenSocket, NULL, NULL);
|
||||||
if (ClientSocket == INVALID_SOCKET) {
|
if (ClientSocket == INVALID_SOCKET) {
|
||||||
std::cout << "accept failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Proxy) accept failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ListenSocket);
|
closesocket(ListenSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
closesocket(ListenSocket);
|
closesocket(ListenSocket);
|
||||||
|
std::cout << "(Proxy) Game Connected!" << std::endl;
|
||||||
|
if(CServer){
|
||||||
std::thread t1(RUDPClientThread, IP, Port);
|
std::thread t1(RUDPClientThread, IP, Port);
|
||||||
t1.detach();
|
t1.detach();
|
||||||
|
CServer = false;
|
||||||
|
}
|
||||||
|
std::thread TCPSend(TCPRespond,&ClientSocket);
|
||||||
|
TCPSend.detach();
|
||||||
do {
|
do {
|
||||||
while(!RUDPData.empty()){
|
std::cout << "(Proxy) Waiting for Game Data..." << std::endl;
|
||||||
iSendResult = send( ClientSocket, RUDPData.front().c_str(), int(RUDPData.front().length())+1, 0);
|
|
||||||
if (iSendResult == SOCKET_ERROR) {
|
|
||||||
std::cout << "send failed with error: " << WSAGetLastError() << std::endl;
|
|
||||||
closesocket(ClientSocket);
|
|
||||||
WSACleanup();
|
|
||||||
}else{
|
|
||||||
RUDPData.pop();
|
|
||||||
std::cout << "Bytes sent: " << iSendResult << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
|
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
|
||||||
if (iResult > 0) {
|
if (iResult > 0) {
|
||||||
std::string buff = recvbuf;
|
std::string buff = recvbuf;
|
||||||
buff.resize(iResult);
|
buff.resize(iResult);
|
||||||
RUDPToSend.push(buff);
|
RUDPToSend.push(buff);
|
||||||
std::cout << "size : " << buff.size() << std::endl;
|
std::cout << "(Game->Launcher) Data : " << buff.c_str() << std::endl;
|
||||||
std::cout << "Data : " << buff.c_str() << std::endl;
|
} else if (iResult == 0) {
|
||||||
}
|
std::cout << "(Proxy) Connection closing...\n";
|
||||||
|
closesocket(ClientSocket);
|
||||||
|
WSACleanup();
|
||||||
|
|
||||||
else if (iResult == 0) {
|
continue;
|
||||||
std::cout << "Connection closing...\n";
|
} else {
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << "(Proxy) recv failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Proxy) recv failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (iResult > 0);
|
} while (iResult > 0);
|
||||||
|
|
||||||
iResult = shutdown(ClientSocket, SD_SEND);
|
iResult = shutdown(ClientSocket, SD_SEND);
|
||||||
if (iResult == SOCKET_ERROR) {
|
if (iResult == SOCKET_ERROR) {
|
||||||
std::cout << "shutdown failed with error: " << WSAGetLastError() << std::endl;
|
std::cout << "(Proxy) shutdown failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
Terminate = true;
|
}while (!TCPTerminate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -254,7 +277,6 @@ void ProxyStart(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProxyThread(const std::string& IP, int Port){
|
void ProxyThread(const std::string& IP, int Port){
|
||||||
Terminate = false;
|
|
||||||
std::thread t1(TCPServerThread,IP,Port);
|
std::thread t1(TCPServerThread,IP,Port);
|
||||||
t1.detach();
|
t1.detach();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user