Use WSA error codes for startup/shutdown

This commit is contained in:
Amos 2022-02-14 02:33:13 +01:00
parent 6e3fb73a82
commit 04be5e0e64
3 changed files with 9 additions and 6 deletions

View File

@ -42,6 +42,7 @@
#include "engine/baseclient.h"
#include "engine/host_cmd.h"
#include "engine/host_state.h"
#include "engine/net.h"
#include "engine/net_chan.h"
#include "engine/sv_main.h"
#include "engine/sys_dll.h"
@ -73,7 +74,7 @@ void Systems_Init()
int nError = ::WSAStartup(MAKEWORD(2, 2), &wsaData);
if (nError != 0)
{
std::cerr << "Failed to start Winsock via WSAStartup. Error: " << nError << std::endl;
std::cerr << "Failed to start Winsock via WSAStartup: (" << NET_ErrorString(WSAGetLastError()) << ")." << std::endl;
}
// Begin the detour transaction to hook the the process
@ -149,7 +150,7 @@ void Systems_Shutdown()
int nError = ::WSACleanup();
if (nError != 0)
{
std::cerr << "Failed to stop winsock via WSACleanup. Error: " << nError << std::endl;
std::cerr << "Failed to stop winsock via WSACleanup: (" << NET_ErrorString(WSAGetLastError()) << ")." << std::endl;
}
// Begin the detour transaction to unhook the the process

View File

@ -51,6 +51,7 @@ const char* NET_ErrorString(int iCode)
case WSAELOOP : return "WSAELOOP";
case WSAENAMETOOLONG : return "WSAENAMETOOLONG";
case WSAEHOSTDOWN : return "WSAEHOSTDOWN";
case WSAEPROCLIM : return "WSAEPROCLIM";
case WSASYSNOTREADY : return "WSASYSNOTREADY";
case WSAVERNOTSUPPORTED: return "WSAVERNOTSUPPORTED";
case WSANOTINITIALISED : return "WSANOTINITIALISED";

View File

@ -10,6 +10,7 @@
#include "tier2/socketcreator.h"
#include "protoc/sv_rcon.pb.h"
#include "protoc/cl_rcon.pb.h"
#include "engine/net.h"
#include "netconsole/netconsole.h"
//-----------------------------------------------------------------------------
@ -23,7 +24,7 @@ bool CNetCon::Init(void)
if (nError != 0)
{
std::cerr << "Failed to start Winsock via WSAStartup. Error: " << nError << std::endl;
std::cerr << "Failed to start Winsock via WSAStartup: (" << NET_ErrorString(WSAGetLastError()) << ")." << std::endl;
return false;
}
@ -47,7 +48,7 @@ bool CNetCon::Shutdown(void)
int nError = ::WSACleanup();
if (nError != 0)
{
std::cerr << "Failed to stop winsock via WSACleanup. Error: " << nError << std::endl;
std::cerr << "Failed to stop winsock via WSACleanup: (" << NET_ErrorString(WSAGetLastError()) << ")." << std::endl;
return false;
}
return true;
@ -212,7 +213,7 @@ bool CNetCon::Connect(const std::string& svInAdr, const std::string& svInPort)
if (m_pSocket->ConnectSocket(*m_pNetAdr2, true) == SOCKET_ERROR)
{
std::cerr << "Failed to connect. Error: 'SOCKET_ERROR'. Verify IP and PORT." << std::endl;
std::cerr << "Failed to connect. Error: (SOCKET_ERROR). Verify IP and PORT." << std::endl;
return false;
}
std::cout << "Connected to: " << m_pNetAdr2->GetIPAndPort() << std::endl;
@ -240,7 +241,7 @@ void CNetCon::Send(const std::string& svMessage) const
int nSendResult = ::send(m_pSocket->GetAcceptedSocketData(0)->m_hSocket, svMessage.c_str(), svMessage.size(), MSG_NOSIGNAL);
if (nSendResult == SOCKET_ERROR)
{
std::cout << "Failed to send message: SOCKET_ERROR." << std::endl;
std::cout << "Failed to send message: (SOCKET_ERROR)." << std::endl;
}
}