mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 15:36:10 +00:00
Merge branch 'performance-improvements'
This commit is contained in:
commit
e46d4b2f0e
@ -41,12 +41,12 @@ int KillSocket(uint64_t Dead);
|
||||
void UUl(const std::string& R);
|
||||
void UDPSend(std::string Data);
|
||||
bool CheckBytes(int32_t Bytes);
|
||||
void GameSend(std::string Data);
|
||||
void GameSend(std::string_view Data);
|
||||
void SendLarge(std::string Data);
|
||||
std::string TCPRcv(uint64_t Sock);
|
||||
void SyncResources(uint64_t TCPSock);
|
||||
std::string GetAddr(const std::string& IP);
|
||||
void ServerParser(const std::string& Data);
|
||||
void ServerParser(std::string_view Data);
|
||||
std::string Login(const std::string& fields);
|
||||
void TCPSend(const std::string& Data, uint64_t Sock);
|
||||
void TCPClientMain(const std::string& IP, int Port);
|
||||
|
@ -230,8 +230,7 @@ void GameHandler(SOCKET Client) {
|
||||
if (Temp < 1)
|
||||
break;
|
||||
|
||||
std::thread Respond(Parse, Ret, Client);
|
||||
Respond.detach();
|
||||
Parse(Ret, Client);
|
||||
} while (Temp > 0);
|
||||
if (Temp == 0) {
|
||||
debug("(Core) Connection closing");
|
||||
|
@ -56,13 +56,12 @@ bool CheckBytes(uint32_t Bytes) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameSend(std::string Data) {
|
||||
void GameSend(std::string_view Data) {
|
||||
static std::mutex Lock;
|
||||
std::scoped_lock Guard(Lock);
|
||||
if (TCPTerminate || !GConnected || CSocket == -1)
|
||||
return;
|
||||
int32_t Size, Temp, Sent;
|
||||
Data += '\n';
|
||||
Size = int32_t(Data.size());
|
||||
Sent = 0;
|
||||
#ifdef DEBUG
|
||||
@ -78,6 +77,11 @@ void GameSend(std::string Data) {
|
||||
return;
|
||||
Sent += Temp;
|
||||
} while (Sent < Size);
|
||||
// send separately to avoid an allocation for += "\n"
|
||||
Temp = send(CSocket, "\n", 1, 0);
|
||||
if (!CheckBytes(Temp)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
void ServerSend(std::string Data, bool Rel) {
|
||||
if (Terminate || Data.empty())
|
||||
@ -194,7 +198,7 @@ void AutoPing() {
|
||||
}
|
||||
}
|
||||
int ClientID = -1;
|
||||
void ParserAsync(const std::string& Data) {
|
||||
void ParserAsync(std::string_view Data) {
|
||||
if (Data.empty())
|
||||
return;
|
||||
char Code = Data.at(0), SubCode = 0;
|
||||
@ -217,7 +221,7 @@ void ParserAsync(const std::string& Data) {
|
||||
}
|
||||
GameSend(Data);
|
||||
}
|
||||
void ServerParser(const std::string& Data) {
|
||||
void ServerParser(std::string_view Data) {
|
||||
ParserAsync(Data);
|
||||
}
|
||||
void NetMain(const std::string& IP, int Port) {
|
||||
|
@ -296,13 +296,14 @@ void SyncResources(SOCKET Sock) {
|
||||
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
||||
}
|
||||
auto name = GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/'));
|
||||
auto modname = a.substr(a.find_last_of('/'));
|
||||
#if defined(__linux__)
|
||||
// Linux version of the game doesnt support uppercase letters in mod names
|
||||
for (char& c : name) {
|
||||
for (char& c : modname) {
|
||||
c = ::tolower(c);
|
||||
}
|
||||
#endif
|
||||
auto name = GetGamePath() + "mods/multiplayer" + modname;
|
||||
auto tmp_name = name + ".tmp";
|
||||
fs::copy_file(a, tmp_name, fs::copy_options::overwrite_existing);
|
||||
fs::rename(tmp_name, name);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#endif
|
||||
|
||||
#include "Logger.h"
|
||||
#include <array>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
@ -48,7 +49,7 @@ void SendLarge(std::string Data) {
|
||||
TCPSend(Data, TCPSock);
|
||||
}
|
||||
|
||||
void UDPParser(std::string Packet) {
|
||||
void UDPParser(std::string_view Packet) {
|
||||
if (Packet.substr(0, 4) == "ABG:") {
|
||||
auto substr = Packet.substr(4);
|
||||
auto res = DeComp(std::span<char>(substr.data(), substr.size()));
|
||||
@ -64,13 +65,14 @@ void UDPRcv() {
|
||||
socklen_t clientLength = sizeof(FromServer);
|
||||
#endif
|
||||
ZeroMemory(&FromServer, clientLength);
|
||||
std::string Ret(10240, 0);
|
||||
static thread_local std::array<char, 10240> Ret {};
|
||||
if (UDPSock == -1)
|
||||
return;
|
||||
int32_t Rcv = recvfrom(UDPSock, &Ret[0], 10240, 0, (sockaddr*)&FromServer, &clientLength);
|
||||
int32_t Rcv = recvfrom(UDPSock, Ret.data(), Ret.size() - 1, 0, (sockaddr*)&FromServer, &clientLength);
|
||||
if (Rcv == SOCKET_ERROR)
|
||||
return;
|
||||
UDPParser(Ret.substr(0, Rcv));
|
||||
Ret[Rcv] = 0;
|
||||
UDPParser(std::string_view(Ret.data(), Rcv));
|
||||
}
|
||||
void UDPClientMain(const std::string& IP, int Port) {
|
||||
#ifdef _WIN32
|
||||
|
Loading…
x
Reference in New Issue
Block a user