mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-23 16:36:49 +00:00
clarify thread names
This commit is contained in:
@@ -48,6 +48,7 @@ void TLuaEngine::operator()() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto ResultCheckThread = std::thread([&] {
|
auto ResultCheckThread = std::thread([&] {
|
||||||
|
RegisterThread("ResultCheckThread");
|
||||||
while (!mShutdown) {
|
while (!mShutdown) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
std::unique_lock Lock(mResultsToCheckMutex);
|
std::unique_lock Lock(mResultsToCheckMutex);
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ void TNetwork::UDPServerMain() {
|
|||||||
WSADATA data;
|
WSADATA data;
|
||||||
if (WSAStartup(514, &data)) {
|
if (WSAStartup(514, &data)) {
|
||||||
beammp_error(("Can't start Winsock!"));
|
beammp_error(("Can't start Winsock!"));
|
||||||
//return;
|
// return;
|
||||||
}
|
}
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
mUDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
mUDPSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
// Create a server hint structure for the server
|
// Create a server hint structure for the server
|
||||||
sockaddr_in serverAddr {};
|
sockaddr_in serverAddr {};
|
||||||
serverAddr.sin_addr.s_addr = INADDR_ANY; //Any Local
|
serverAddr.sin_addr.s_addr = INADDR_ANY; // Any Local
|
||||||
serverAddr.sin_family = AF_INET; // Address format is IPv4
|
serverAddr.sin_family = AF_INET; // Address format is IPv4
|
||||||
serverAddr.sin_port = htons(uint16_t(Application::Settings.Port)); // Convert from little to big endian
|
serverAddr.sin_port = htons(uint16_t(Application::Settings.Port)); // Convert from little to big endian
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ void TNetwork::UDPServerMain() {
|
|||||||
beammp_error("bind() failed: " + GetPlatformAgnosticErrorString());
|
beammp_error("bind() failed: " + GetPlatformAgnosticErrorString());
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
exit(-1);
|
exit(-1);
|
||||||
//return;
|
// return;
|
||||||
}
|
}
|
||||||
|
|
||||||
beammp_info(("Vehicle data network online on port ") + std::to_string(Application::Settings.Port) + (" with a Max of ")
|
beammp_info(("Vehicle data network online on port ") + std::to_string(Application::Settings.Port) + (" with a Max of ")
|
||||||
@@ -65,7 +65,7 @@ void TNetwork::UDPServerMain() {
|
|||||||
while (!mShutdown) {
|
while (!mShutdown) {
|
||||||
try {
|
try {
|
||||||
sockaddr_in client {};
|
sockaddr_in client {};
|
||||||
std::string Data = UDPRcvFromClient(client); //Receives any data from Socket
|
std::string Data = UDPRcvFromClient(client); // Receives any data from Socket
|
||||||
size_t Pos = Data.find(':');
|
size_t Pos = Data.find(':');
|
||||||
if (Data.empty() || Pos > 2)
|
if (Data.empty() || Pos > 2)
|
||||||
continue;
|
continue;
|
||||||
@@ -163,7 +163,7 @@ void TNetwork::TCPServerMain() {
|
|||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef GetObject //Fixes Windows
|
#undef GetObject // Fixes Windows
|
||||||
|
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
namespace json = rapidjson;
|
namespace json = rapidjson;
|
||||||
@@ -331,7 +331,7 @@ void TNetwork::Authentication(const TConnection& ClientConnection) {
|
|||||||
ClientKick(*Client, Reason);
|
ClientKick(*Client, Reason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mServer.ClientCount() < size_t(Application::Settings.MaxPlayers)) {
|
if (mServer.ClientCount() < size_t(Application::Settings.MaxPlayers)) {
|
||||||
beammp_info("Identification success");
|
beammp_info("Identification success");
|
||||||
mServer.InsertClient(Client);
|
mServer.InsertClient(Client);
|
||||||
@@ -368,16 +368,16 @@ bool TNetwork::TCPSend(TClient& c, const std::string& Data, bool IsSync) {
|
|||||||
do {
|
do {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int32_t Temp = send(c.GetTCPSock(), &Send[Sent], Size - Sent, 0);
|
int32_t Temp = send(c.GetTCPSock(), &Send[Sent], Size - Sent, 0);
|
||||||
#else //WIN32
|
#else // WIN32
|
||||||
int32_t Temp = send(c.GetTCPSock(), &Send[Sent], Size - Sent, MSG_NOSIGNAL);
|
int32_t Temp = send(c.GetTCPSock(), &Send[Sent], Size - Sent, MSG_NOSIGNAL);
|
||||||
#endif //WIN32
|
#endif // WIN32
|
||||||
if (Temp == 0) {
|
if (Temp == 0) {
|
||||||
beammp_debug("send() == 0: " + GetPlatformAgnosticErrorString());
|
beammp_debug("send() == 0: " + GetPlatformAgnosticErrorString());
|
||||||
if (c.GetStatus() > -1)
|
if (c.GetStatus() > -1)
|
||||||
c.SetStatus(-1);
|
c.SetStatus(-1);
|
||||||
return false;
|
return false;
|
||||||
} else if (Temp < 0) {
|
} else if (Temp < 0) {
|
||||||
beammp_debug("send() < 0: " + GetPlatformAgnosticErrorString()); //TODO fix it was spamming yet everyone stayed on the server
|
beammp_debug("send() < 0: " + GetPlatformAgnosticErrorString()); // TODO fix it was spamming yet everyone stayed on the server
|
||||||
if (c.GetStatus() > -1)
|
if (c.GetStatus() > -1)
|
||||||
c.SetStatus(-1);
|
c.SetStatus(-1);
|
||||||
CloseSocketProper(c.GetTCPSock());
|
CloseSocketProper(c.GetTCPSock());
|
||||||
@@ -461,6 +461,7 @@ void TNetwork::ClientKick(TClient& c, const std::string& R) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TNetwork::Looper(const std::weak_ptr<TClient>& c) {
|
void TNetwork::Looper(const std::weak_ptr<TClient>& c) {
|
||||||
|
RegisterThreadAuto();
|
||||||
while (!c.expired()) {
|
while (!c.expired()) {
|
||||||
auto Client = c.lock();
|
auto Client = c.lock();
|
||||||
if (Client->GetStatus() < 0) {
|
if (Client->GetStatus() < 0) {
|
||||||
@@ -468,7 +469,7 @@ void TNetwork::Looper(const std::weak_ptr<TClient>& c) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!Client->IsSyncing() && Client->IsSynced() && Client->MissedPacketQueueSize() != 0) {
|
if (!Client->IsSyncing() && Client->IsSynced() && Client->MissedPacketQueueSize() != 0) {
|
||||||
//debug("sending " + std::to_string(Client->MissedPacketQueueSize()) + " queued packets");
|
// debug("sending " + std::to_string(Client->MissedPacketQueueSize()) + " queued packets");
|
||||||
while (Client->MissedPacketQueueSize() > 0) {
|
while (Client->MissedPacketQueueSize() > 0) {
|
||||||
std::string QData {};
|
std::string QData {};
|
||||||
{ // locked context
|
{ // locked context
|
||||||
@@ -611,7 +612,7 @@ void TNetwork::OnConnect(const std::weak_ptr<TClient>& c) {
|
|||||||
SyncResources(*LockedClient);
|
SyncResources(*LockedClient);
|
||||||
if (LockedClient->GetStatus() < 0)
|
if (LockedClient->GetStatus() < 0)
|
||||||
return;
|
return;
|
||||||
(void)Respond(*LockedClient, "M" + Application::Settings.MapName, true); //Send the Map on connect
|
(void)Respond(*LockedClient, "M" + Application::Settings.MapName, true); // Send the Map on connect
|
||||||
beammp_info(LockedClient->GetName() + " : Connected");
|
beammp_info(LockedClient->GetName() + " : Connected");
|
||||||
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoining", "", LockedClient->GetID()));
|
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoining", "", LockedClient->GetID()));
|
||||||
}
|
}
|
||||||
@@ -689,7 +690,7 @@ void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) {
|
|||||||
// TODO: handle
|
// TODO: handle
|
||||||
}
|
}
|
||||||
|
|
||||||
///Wait for connections
|
/// Wait for connections
|
||||||
int T = 0;
|
int T = 0;
|
||||||
while (c.GetDownSock() < 1 && T < 50) {
|
while (c.GetDownSock() < 1 && T < 50) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
@@ -707,9 +708,11 @@ void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) {
|
|||||||
|
|
||||||
std::thread SplitThreads[2] {
|
std::thread SplitThreads[2] {
|
||||||
std::thread([&] {
|
std::thread([&] {
|
||||||
|
RegisterThread("SplitLoad_0");
|
||||||
SplitLoad(c, 0, MSize, false, FileName);
|
SplitLoad(c, 0, MSize, false, FileName);
|
||||||
}),
|
}),
|
||||||
std::thread([&] {
|
std::thread([&] {
|
||||||
|
RegisterThread("SplitLoad_1");
|
||||||
SplitLoad(c, MSize, Size, true, FileName);
|
SplitLoad(c, MSize, Size, true, FileName);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
@@ -723,7 +726,7 @@ void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) {
|
|||||||
|
|
||||||
void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name) {
|
void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name) {
|
||||||
std::ifstream f(Name.c_str(), std::ios::binary);
|
std::ifstream f(Name.c_str(), std::ios::binary);
|
||||||
uint32_t Split = 0x7735940; //125MB
|
uint32_t Split = 0x7735940; // 125MB
|
||||||
char* Data;
|
char* Data;
|
||||||
if (Size > Split)
|
if (Size > Split)
|
||||||
Data = new char[Split];
|
Data = new char[Split];
|
||||||
@@ -876,10 +879,10 @@ void TNetwork::SendToAll(TClient* c, const std::string& Data, bool Self, bool Re
|
|||||||
} else {
|
} else {
|
||||||
Client->EnqueuePacket(Data);
|
Client->EnqueuePacket(Data);
|
||||||
}
|
}
|
||||||
//ret = SendLarge(*Client, Data);
|
// ret = SendLarge(*Client, Data);
|
||||||
} else {
|
} else {
|
||||||
Client->EnqueuePacket(Data);
|
Client->EnqueuePacket(Data);
|
||||||
//ret = TCPSend(*Client, Data);
|
// ret = TCPSend(*Client, Data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = UDPSend(*Client, Data);
|
ret = UDPSend(*Client, Data);
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ int main(int argc, char** argv) try {
|
|||||||
Application::Console().InitializeLuaConsole(LuaEngine);
|
Application::Console().InitializeLuaConsole(LuaEngine);
|
||||||
Application::CheckForUpdates();
|
Application::CheckForUpdates();
|
||||||
|
|
||||||
|
RegisterThread("Main(Waiting)");
|
||||||
while (!Shutdown) {
|
while (!Shutdown) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user