mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
CloseSocketProper instead of closesocket
This commit is contained in:
parent
fedca58e8e
commit
fa9bc16038
@ -16,9 +16,14 @@ inline void ZeroMemory(void* dst, size_t len) {
|
||||
Assert(std::memset(dst, 0, len) != nullptr);
|
||||
}
|
||||
// provides unix equivalent of closesocket call in win32
|
||||
inline void closesocket(int socket) {
|
||||
inline void CloseSocketProper(int socket) {
|
||||
#ifndef WIN32
|
||||
shutdown(socket, SHUT_RDWR);
|
||||
close(socket);
|
||||
#else // WIN32
|
||||
shutdown(socket, SD_BOTH);
|
||||
closesocket(socket);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
#ifndef __try
|
||||
|
@ -348,7 +348,7 @@ int lua_dropPlayer(lua_State* L) {
|
||||
Respond(c, "C:Server:You have been Kicked from the server! " + Reason, true);
|
||||
c->SetStatus(-2);
|
||||
info(Sec("Closing socket due to kick"));
|
||||
closesocket(c->GetTCPSock());
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
|
||||
} else
|
||||
SendError(L, Sec("DropPlayer not enough arguments"));
|
||||
|
@ -86,7 +86,7 @@ void Check(SOCKET TCPSock, std::reference_wrapper<std::atomic_bool> ok) {
|
||||
accum += 100;
|
||||
if (accum >= 5000) {
|
||||
error(Sec("Identification timed out (Check accum)"));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -142,14 +142,14 @@ void Identification(SOCKET TCPSock, RSA* Skey) {
|
||||
std::string Name, DID, Role;
|
||||
if (!Send(TCPSock, GenerateM(Skey))) {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
return;
|
||||
}
|
||||
std::string msg = Rcv(TCPSock);
|
||||
auto Keys = Parse(msg);
|
||||
if (!Send(TCPSock, RSA_E("HC", Keys.second, Keys.first))) {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -161,23 +161,23 @@ void Identification(SOCKET TCPSock, RSA* Skey) {
|
||||
Ver = Ver.substr(2);
|
||||
if (Ver.length() > 4 || Ver != GetCVer()) {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
return;
|
||||
}
|
||||
Res = RSA_D(Res, Skey);
|
||||
if (Res.size() < 3 || Res.substr(0, 2) != Sec("NR")) {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
return;
|
||||
}
|
||||
if (Res.find(':') == std::string::npos) {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
return;
|
||||
}
|
||||
Name = Res.substr(2, Res.find(':') - 2);
|
||||
@ -185,7 +185,7 @@ void Identification(SOCKET TCPSock, RSA* Skey) {
|
||||
Role = GetRole(DID);
|
||||
if (Role.empty() || Role.find(Sec("Error")) != std::string::npos) {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
return;
|
||||
}
|
||||
// DebugPrintTIDInternal(std::string("Client(") + Name + ")");
|
||||
@ -194,7 +194,7 @@ void Identification(SOCKET TCPSock, RSA* Skey) {
|
||||
if (c != nullptr) {
|
||||
if (c->GetDID() == DID) {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(c->GetTCPSock());
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
c->SetStatus(-2);
|
||||
break;
|
||||
}
|
||||
@ -205,7 +205,7 @@ void Identification(SOCKET TCPSock, RSA* Skey) {
|
||||
CreateClient(TCPSock, Name, DID, Role);
|
||||
} else {
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
}
|
||||
}
|
||||
void Identify(SOCKET TCPSock) {
|
||||
@ -222,7 +222,7 @@ void Identify(SOCKET TCPSock) {
|
||||
}__except(1){
|
||||
if(TCPSock != -1){
|
||||
error("died on " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(TCPSock);
|
||||
CloseSocketProper(TCPSock);
|
||||
}
|
||||
}
|
||||
#endif // WIN32*/
|
||||
@ -271,7 +271,7 @@ void TCPServerMain() {
|
||||
}
|
||||
} while (client);
|
||||
|
||||
closesocket(client);
|
||||
CloseSocketProper(client);
|
||||
WSACleanup();
|
||||
#else // unix
|
||||
// wondering why we need slightly different implementations of this?
|
||||
@ -313,6 +313,6 @@ void TCPServerMain() {
|
||||
} while (client);
|
||||
|
||||
debug("all ok, arrived at " + std::string(__func__) + ":" + std::to_string(__LINE__));
|
||||
closesocket(client);
|
||||
CloseSocketProper(client);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ void STCPSend(Client* c, std::string Data) {
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
info(Sec("Closing socket, BytesSent < 0"));
|
||||
closesocket(c->GetTCPSock());
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
}
|
||||
}
|
||||
void SendFile(Client* c, const std::string& Name) {
|
||||
@ -108,13 +108,13 @@ bool STCPRecv(Client* c) {
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
info(Sec("Closing socket in STCP receive, BytesRcv == 0"));
|
||||
closesocket(c->GetTCPSock());
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
return false;
|
||||
} else if (BytesRcv < 0) {
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
info(Sec("Closing socket in STCP receive, BytesRcv < 0"));
|
||||
closesocket(c->GetTCPSock());
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
return false;
|
||||
}
|
||||
if (strcmp(buf, "Done") == 0)
|
||||
|
@ -32,7 +32,7 @@ void TCPSend(Client* c, const std::string& Data) {
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
// info(Sec("Closing socket, Temp < 0"));
|
||||
closesocket(c->GetTCPSock());
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
return;
|
||||
}
|
||||
Sent += Temp;
|
||||
@ -55,7 +55,7 @@ bool CheckBytes(Client* c, int32_t BytesRcv) {
|
||||
if (c->GetStatus() > -1)
|
||||
c->SetStatus(-1);
|
||||
info(Sec("Closing socket in CheckBytes, BytesRcv < 0"));
|
||||
closesocket(c->GetTCPSock());
|
||||
CloseSocketProper(c->GetTCPSock());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -323,7 +323,7 @@ void LOOP() {
|
||||
error(Sec("fatal: ") + std::string(e.what()));
|
||||
}
|
||||
}
|
||||
/*closesocket(UDPSock);
|
||||
/*CloseSocketProper(UDPSock);
|
||||
WSACleanup();
|
||||
return;*/
|
||||
#else // unix
|
||||
@ -369,7 +369,7 @@ void LOOP() {
|
||||
error(Sec("fatal: ") + std::string(e.what()));
|
||||
}
|
||||
}
|
||||
/*closesocket(UDPSock); // TODO: Why not this? We did this in TCPServerMain?
|
||||
/*CloseSocketProper(UDPSock); // TODO: Why not this? We did this in TCPServerMain?
|
||||
return;
|
||||
*/
|
||||
#endif // WIN32
|
||||
|
Loading…
x
Reference in New Issue
Block a user