mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-08-27 12:41:32 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 92cf7a9c67 | |||
| 89f564f09d | |||
| 2bb5686c68 | |||
| f8c9fd7992 | |||
| d3daa6621c | |||
| d38d8ffce3 |
@@ -77,7 +77,7 @@ void ServerSend(std::string Data, bool Rel) {
|
|||||||
C = Data.at(0);
|
C = Data.at(0);
|
||||||
if (C == 'O' || C == 'T')
|
if (C == 'O' || C == 'T')
|
||||||
Ack = true;
|
Ack = true;
|
||||||
if (C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')
|
if (C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C' || C == 't')
|
||||||
Rel = true;
|
Rel = true;
|
||||||
if (compressBound(Data.size()) > 1024)
|
if (compressBound(Data.size()) > 1024)
|
||||||
Rel = true;
|
Rel = true;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "Network/network.hpp"
|
#include "Network/network.hpp"
|
||||||
#include "Zlib/Compressor.h"
|
#include "Zlib/Compressor.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
@@ -21,12 +22,17 @@
|
|||||||
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <future>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
SOCKET UDPSock = -1;
|
SOCKET UDPSock = -1;
|
||||||
sockaddr_in* ToServer = nullptr;
|
sockaddr_in* ToServer = nullptr;
|
||||||
|
|
||||||
|
std::mutex UDPSendMutex;
|
||||||
|
|
||||||
void UDPSend(std::string Data) {
|
void UDPSend(std::string Data) {
|
||||||
|
std::scoped_lock lock(UDPSendMutex);
|
||||||
if (ClientID == -1 || UDPSock == -1)
|
if (ClientID == -1 || UDPSock == -1)
|
||||||
return;
|
return;
|
||||||
if (Data.length() > 400) {
|
if (Data.length() > 400) {
|
||||||
@@ -78,6 +84,7 @@ void UDPRcv() {
|
|||||||
Ret[Rcv] = 0;
|
Ret[Rcv] = 0;
|
||||||
UDPParser(std::string_view(Ret.data(), Rcv));
|
UDPParser(std::string_view(Ret.data(), Rcv));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPClientMain(const std::string& IP, int Port) {
|
void UDPClientMain(const std::string& IP, int Port) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA data;
|
WSADATA data;
|
||||||
@@ -93,9 +100,16 @@ void UDPClientMain(const std::string& IP, int Port) {
|
|||||||
ToServer->sin_port = htons(Port);
|
ToServer->sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ToServer->sin_addr);
|
||||||
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
UDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (!magic.empty())
|
std::future<void> magicSend;
|
||||||
for (int i = 0; i < 10; i++)
|
|
||||||
UDPSend(magic);
|
if (!magic.empty()) {
|
||||||
|
magicSend = std::async(std::launch::async, ([](){
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
UDPSend(magic);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
GameSend("P" + std::to_string(ClientID));
|
GameSend("P" + std::to_string(ClientID));
|
||||||
TCPSend("H", TCPSock);
|
TCPSend("H", TCPSock);
|
||||||
UDPSend("p");
|
UDPSend("p");
|
||||||
@@ -104,6 +118,11 @@ void UDPClientMain(const std::string& IP, int Port) {
|
|||||||
UDPRcv();
|
UDPRcv();
|
||||||
}
|
}
|
||||||
debug("UDP receive loop done");
|
debug("UDP receive loop done");
|
||||||
|
|
||||||
|
if (magicSend.valid()) {
|
||||||
|
magicSend.get();
|
||||||
|
}
|
||||||
|
|
||||||
KillSocket(UDPSock);
|
KillSocket(UDPSock);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user