mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-08-27 04:37:41 +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);
|
||||
if (C == 'O' || C == 'T')
|
||||
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;
|
||||
if (compressBound(Data.size()) > 1024)
|
||||
Rel = true;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Network/network.hpp"
|
||||
#include "Zlib/Compressor.h"
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <ws2tcpip.h>
|
||||
@@ -21,12 +22,17 @@
|
||||
|
||||
#include "Logger.h"
|
||||
#include <array>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
SOCKET UDPSock = -1;
|
||||
sockaddr_in* ToServer = nullptr;
|
||||
|
||||
std::mutex UDPSendMutex;
|
||||
|
||||
void UDPSend(std::string Data) {
|
||||
std::scoped_lock lock(UDPSendMutex);
|
||||
if (ClientID == -1 || UDPSock == -1)
|
||||
return;
|
||||
if (Data.length() > 400) {
|
||||
@@ -78,6 +84,7 @@ void UDPRcv() {
|
||||
Ret[Rcv] = 0;
|
||||
UDPParser(std::string_view(Ret.data(), Rcv));
|
||||
}
|
||||
|
||||
void UDPClientMain(const std::string& IP, int Port) {
|
||||
#ifdef _WIN32
|
||||
WSADATA data;
|
||||
@@ -93,9 +100,16 @@ 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);
|
||||
if (!magic.empty())
|
||||
for (int i = 0; i < 10; i++)
|
||||
UDPSend(magic);
|
||||
std::future<void> magicSend;
|
||||
|
||||
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));
|
||||
TCPSend("H", TCPSock);
|
||||
UDPSend("p");
|
||||
@@ -104,6 +118,11 @@ void UDPClientMain(const std::string& IP, int Port) {
|
||||
UDPRcv();
|
||||
}
|
||||
debug("UDP receive loop done");
|
||||
|
||||
if (magicSend.valid()) {
|
||||
magicSend.get();
|
||||
}
|
||||
|
||||
KillSocket(UDPSock);
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user