mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-17 16:57:11 +00:00
Merge pull request #16 from lionkor/v3
Fix 10038, add more explanatory error messages
This commit is contained in:
commit
23a5468e29
2
.github/workflows/cmake-windows.yml
vendored
2
.github/workflows/cmake-windows.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
vcpkgArguments: 'zlib discord-rpc nlohmann-json openssl minhook'
|
vcpkgArguments: 'zlib discord-rpc nlohmann-json openssl minhook'
|
||||||
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
|
||||||
vcpkgGitCommitId: '75522bb1f2e7d863078bcd06322348f053a9e33f'
|
vcpkgGitCommitId: 'b33f616f85e207012aa8229706d8e603efd5794d'
|
||||||
vcpkgTriplet: 'x64-windows-static'
|
vcpkgTriplet: 'x64-windows-static'
|
||||||
|
|
||||||
- name: Create Build Environment
|
- name: Create Build Environment
|
||||||
|
@ -38,6 +38,7 @@ private:
|
|||||||
void UpdateUl(bool D, const std::string& msg);
|
void UpdateUl(bool D, const std::string& msg);
|
||||||
std::unique_ptr<sockaddr_in> UDPSockAddress;
|
std::unique_ptr<sockaddr_in> UDPSockAddress;
|
||||||
void ServerParser(const std::string& Data);
|
void ServerParser(const std::string& Data);
|
||||||
|
static std::string GetSocketApiError();
|
||||||
void TCPSend(const std::string& Data);
|
void TCPSend(const std::string& Data);
|
||||||
void UDPParser(std::string Packet);
|
void UDPParser(std::string Packet);
|
||||||
void SendLarge(std::string Data);
|
void SendLarge(std::string Data);
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit fad31557de3acc40e704ad63bb11e7089190c16a
|
Subproject commit 7d75e9ed0359650224b29cdf6728c5fe0a19fffb
|
@ -1 +1 @@
|
|||||||
Subproject commit 33f53aa4583c132e70dc21f2d7fe004706267784
|
Subproject commit fee8e97b4eeb34fe2e6e6294413d84e9e7a072a7
|
@ -1 +1 @@
|
|||||||
Subproject commit 8e669aa6990e0ed219c169d491472d749f54c393
|
Subproject commit 27816dbbd168a84a0a7a252d7d75b0ca4dc1e073
|
@ -30,16 +30,21 @@ void Server::TCPClientMain() {
|
|||||||
SOCKADDR_IN ServerAddr;
|
SOCKADDR_IN ServerAddr;
|
||||||
TCPSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
TCPSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if(TCPSocket == -1) {
|
if(TCPSocket == -1) {
|
||||||
LOG(ERROR) << "Socket failed! Error code: " << WSAGetLastError();
|
LOG(ERROR) << "Socket failed! Error code: " << GetSocketApiError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const char optval = 0;
|
||||||
|
int status = ::setsockopt(TCPSocket, SOL_SOCKET, SO_DONTLINGER, &optval, sizeof(optval));
|
||||||
|
if (status < 0) {
|
||||||
|
LOG(INFO) << "Failed to set DONTLINGER: " << GetSocketApiError();
|
||||||
|
}
|
||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(Port);
|
ServerAddr.sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
||||||
int status = connect(TCPSocket, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
|
status = connect(TCPSocket, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
UStatus = "Connection Failed!";
|
UStatus = "Connection Failed!";
|
||||||
LOG(ERROR) << "Connect failed! Error code: " << WSAGetLastError();
|
LOG(ERROR) << "Connect failed! Error code: " << GetSocketApiError();
|
||||||
Close();
|
Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -69,7 +74,7 @@ void Server::UDPSend(std::string Data) {
|
|||||||
}
|
}
|
||||||
std::string Packet = char(ClientID+1) + std::string(":") + Data;
|
std::string Packet = char(ClientID+1) + std::string(":") + Data;
|
||||||
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)UDPSockAddress.get(), sizeof(sockaddr_in));
|
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)UDPSockAddress.get(), sizeof(sockaddr_in));
|
||||||
if (sendOk == SOCKET_ERROR)LOG(ERROR) << "UDP Socket Error Code : " << WSAGetLastError();
|
if (sendOk == SOCKET_ERROR)LOG(ERROR) << "UDP Socket Error Code : " << GetSocketApiError();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::UDPParser(std::string Packet) {
|
void Server::UDPParser(std::string Packet) {
|
||||||
@ -136,6 +141,30 @@ void Server::SendLarge(std::string Data) {
|
|||||||
TCPSend(Data);
|
TCPSend(Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Server::GetSocketApiError() {
|
||||||
|
// This will provide us with the error code and an error message, all in one.
|
||||||
|
// The resulting format is "<CODE> - <MESSAGE>"
|
||||||
|
int err;
|
||||||
|
char msgbuf[256];
|
||||||
|
msgbuf[0] = '\0';
|
||||||
|
|
||||||
|
err = WSAGetLastError();
|
||||||
|
|
||||||
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
nullptr,
|
||||||
|
err,
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
msgbuf,
|
||||||
|
sizeof(msgbuf),
|
||||||
|
nullptr);
|
||||||
|
|
||||||
|
if (*msgbuf) {
|
||||||
|
return std::to_string(WSAGetLastError()) + " - " + std::string(msgbuf);
|
||||||
|
} else {
|
||||||
|
return std::to_string(WSAGetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Server::ServerSend(std::string Data, bool Rel) {
|
void Server::ServerSend(std::string Data, bool Rel) {
|
||||||
if(Terminate || Data.empty())return;
|
if(Terminate || Data.empty())return;
|
||||||
char C = 0;
|
char C = 0;
|
||||||
@ -225,7 +254,7 @@ bool Server::CheckBytes(int32_t Bytes) {
|
|||||||
Terminate = true;
|
Terminate = true;
|
||||||
return false;
|
return false;
|
||||||
}else if (Bytes < 0) {
|
}else if (Bytes < 0) {
|
||||||
//debug("(TCP CB) recv failed with error: " + std::to_string(WSAGetLastError()));
|
//debug("(TCP CB) recv failed with error: " + GetSocketApiError();
|
||||||
KillSocket(TCPSocket);
|
KillSocket(TCPSocket);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user