mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-03-26 17:48:12 +05:00
Modernize project codebase (#906)
* Fixed boats falling and a TP glitch #266 * Replaced every C-style cast with C++ ones * Replaced every C-style cast with C++ ones * Fixed boats falling and a TP glitch #266 * Updated NULL to nullptr and fixing some type issues * Modernized and fixed a few bugs - Replaced most instances of `NULL` with `nullptr`. - Replaced most `shared_ptr(new ...)` with `make_shared`. - Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances. * Fixing more conflicts * Replace int loops with size_t and start work on overrides * Add safety checks and fix a issue with vector going OOR
This commit is contained in:
@@ -16,8 +16,8 @@ static bool RecvExact(SOCKET sock, BYTE* buf, int len);
|
||||
|
||||
SOCKET WinsockNetLayer::s_listenSocket = INVALID_SOCKET;
|
||||
SOCKET WinsockNetLayer::s_hostConnectionSocket = INVALID_SOCKET;
|
||||
HANDLE WinsockNetLayer::s_acceptThread = NULL;
|
||||
HANDLE WinsockNetLayer::s_clientRecvThread = NULL;
|
||||
HANDLE WinsockNetLayer::s_acceptThread = nullptr;
|
||||
HANDLE WinsockNetLayer::s_clientRecvThread = nullptr;
|
||||
|
||||
bool WinsockNetLayer::s_isHost = false;
|
||||
bool WinsockNetLayer::s_connected = false;
|
||||
@@ -34,14 +34,14 @@ CRITICAL_SECTION WinsockNetLayer::s_connectionsLock;
|
||||
std::vector<Win64RemoteConnection> WinsockNetLayer::s_connections;
|
||||
|
||||
SOCKET WinsockNetLayer::s_advertiseSock = INVALID_SOCKET;
|
||||
HANDLE WinsockNetLayer::s_advertiseThread = NULL;
|
||||
HANDLE WinsockNetLayer::s_advertiseThread = nullptr;
|
||||
volatile bool WinsockNetLayer::s_advertising = false;
|
||||
Win64LANBroadcast WinsockNetLayer::s_advertiseData = {};
|
||||
CRITICAL_SECTION WinsockNetLayer::s_advertiseLock;
|
||||
int WinsockNetLayer::s_hostGamePort = WIN64_NET_DEFAULT_PORT;
|
||||
|
||||
SOCKET WinsockNetLayer::s_discoverySock = INVALID_SOCKET;
|
||||
HANDLE WinsockNetLayer::s_discoveryThread = NULL;
|
||||
HANDLE WinsockNetLayer::s_discoveryThread = nullptr;
|
||||
volatile bool WinsockNetLayer::s_discovering = false;
|
||||
CRITICAL_SECTION WinsockNetLayer::s_discoveryLock;
|
||||
std::vector<Win64LANSession> WinsockNetLayer::s_discoveredSessions;
|
||||
@@ -56,7 +56,7 @@ CRITICAL_SECTION WinsockNetLayer::s_smallIdToSocketLock;
|
||||
|
||||
SOCKET WinsockNetLayer::s_splitScreenSocket[XUSER_MAX_COUNT] = { INVALID_SOCKET, INVALID_SOCKET, INVALID_SOCKET, INVALID_SOCKET };
|
||||
BYTE WinsockNetLayer::s_splitScreenSmallId[XUSER_MAX_COUNT] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
HANDLE WinsockNetLayer::s_splitScreenRecvThread[XUSER_MAX_COUNT] = { NULL, NULL, NULL, NULL };
|
||||
HANDLE WinsockNetLayer::s_splitScreenRecvThread[XUSER_MAX_COUNT] = {nullptr, nullptr, nullptr, nullptr};
|
||||
|
||||
bool g_Win64MultiplayerHost = false;
|
||||
bool g_Win64MultiplayerJoin = false;
|
||||
@@ -116,11 +116,11 @@ void WinsockNetLayer::Shutdown()
|
||||
}
|
||||
|
||||
// Stop accept loop first so no new RecvThread can be created while shutting down.
|
||||
if (s_acceptThread != NULL)
|
||||
if (s_acceptThread != nullptr)
|
||||
{
|
||||
WaitForSingleObject(s_acceptThread, 2000);
|
||||
CloseHandle(s_acceptThread);
|
||||
s_acceptThread = NULL;
|
||||
s_acceptThread = nullptr;
|
||||
}
|
||||
|
||||
std::vector<HANDLE> recvThreads;
|
||||
@@ -133,10 +133,10 @@ void WinsockNetLayer::Shutdown()
|
||||
closesocket(s_connections[i].tcpSocket);
|
||||
s_connections[i].tcpSocket = INVALID_SOCKET;
|
||||
}
|
||||
if (s_connections[i].recvThread != NULL)
|
||||
if (s_connections[i].recvThread != nullptr)
|
||||
{
|
||||
recvThreads.push_back(s_connections[i].recvThread);
|
||||
s_connections[i].recvThread = NULL;
|
||||
s_connections[i].recvThread = nullptr;
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&s_connectionsLock);
|
||||
@@ -152,11 +152,11 @@ void WinsockNetLayer::Shutdown()
|
||||
s_connections.clear();
|
||||
LeaveCriticalSection(&s_connectionsLock);
|
||||
|
||||
if (s_clientRecvThread != NULL)
|
||||
if (s_clientRecvThread != nullptr)
|
||||
{
|
||||
WaitForSingleObject(s_clientRecvThread, 2000);
|
||||
CloseHandle(s_clientRecvThread);
|
||||
s_clientRecvThread = NULL;
|
||||
s_clientRecvThread = nullptr;
|
||||
}
|
||||
|
||||
for (int i = 0; i < XUSER_MAX_COUNT; i++)
|
||||
@@ -166,11 +166,11 @@ void WinsockNetLayer::Shutdown()
|
||||
closesocket(s_splitScreenSocket[i]);
|
||||
s_splitScreenSocket[i] = INVALID_SOCKET;
|
||||
}
|
||||
if (s_splitScreenRecvThread[i] != NULL)
|
||||
if (s_splitScreenRecvThread[i] != nullptr)
|
||||
{
|
||||
WaitForSingleObject(s_splitScreenRecvThread[i], 2000);
|
||||
CloseHandle(s_splitScreenRecvThread[i]);
|
||||
s_splitScreenRecvThread[i] = NULL;
|
||||
s_splitScreenRecvThread[i] = nullptr;
|
||||
}
|
||||
s_splitScreenSmallId[i] = 0xFF;
|
||||
}
|
||||
@@ -216,22 +216,22 @@ bool WinsockNetLayer::HostGame(int port, const char* bindIp)
|
||||
LeaveCriticalSection(&s_smallIdToSocketLock);
|
||||
|
||||
struct addrinfo hints = {};
|
||||
struct addrinfo* result = NULL;
|
||||
struct addrinfo* result = nullptr;
|
||||
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_flags = (bindIp == NULL || bindIp[0] == 0) ? AI_PASSIVE : 0;
|
||||
hints.ai_flags = (bindIp == nullptr || bindIp[0] == 0) ? AI_PASSIVE : 0;
|
||||
|
||||
char portStr[16];
|
||||
sprintf_s(portStr, "%d", port);
|
||||
|
||||
const char* resolvedBindIp = (bindIp != NULL && bindIp[0] != 0) ? bindIp : NULL;
|
||||
const char* resolvedBindIp = (bindIp != nullptr && bindIp[0] != 0) ? bindIp : nullptr;
|
||||
int iResult = getaddrinfo(resolvedBindIp, portStr, &hints, &result);
|
||||
if (iResult != 0)
|
||||
{
|
||||
app.DebugPrintf("getaddrinfo failed for %s:%d - %d\n",
|
||||
resolvedBindIp != NULL ? resolvedBindIp : "*",
|
||||
resolvedBindIp != nullptr ? resolvedBindIp : "*",
|
||||
port,
|
||||
iResult);
|
||||
return false;
|
||||
@@ -248,7 +248,7 @@ bool WinsockNetLayer::HostGame(int port, const char* bindIp)
|
||||
int opt = 1;
|
||||
setsockopt(s_listenSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(opt));
|
||||
|
||||
iResult = ::bind(s_listenSocket, result->ai_addr, (int)result->ai_addrlen);
|
||||
iResult = ::bind(s_listenSocket, result->ai_addr, static_cast<int>(result->ai_addrlen));
|
||||
freeaddrinfo(result);
|
||||
if (iResult == SOCKET_ERROR)
|
||||
{
|
||||
@@ -270,10 +270,10 @@ bool WinsockNetLayer::HostGame(int port, const char* bindIp)
|
||||
s_active = true;
|
||||
s_connected = true;
|
||||
|
||||
s_acceptThread = CreateThread(NULL, 0, AcceptThreadProc, NULL, 0, NULL);
|
||||
s_acceptThread = CreateThread(nullptr, 0, AcceptThreadProc, nullptr, 0, nullptr);
|
||||
|
||||
app.DebugPrintf("Win64 LAN: Hosting on %s:%d\n",
|
||||
resolvedBindIp != NULL ? resolvedBindIp : "*",
|
||||
resolvedBindIp != nullptr ? resolvedBindIp : "*",
|
||||
port);
|
||||
return true;
|
||||
}
|
||||
@@ -297,15 +297,15 @@ bool WinsockNetLayer::JoinGame(const char* ip, int port)
|
||||
// Without this, the old thread can read from the new socket (s_hostConnectionSocket
|
||||
// is a global) and steal bytes from the new connection's TCP stream, causing
|
||||
// packet stream misalignment on reconnect.
|
||||
if (s_clientRecvThread != NULL)
|
||||
if (s_clientRecvThread != nullptr)
|
||||
{
|
||||
WaitForSingleObject(s_clientRecvThread, 5000);
|
||||
CloseHandle(s_clientRecvThread);
|
||||
s_clientRecvThread = NULL;
|
||||
s_clientRecvThread = nullptr;
|
||||
}
|
||||
|
||||
struct addrinfo hints = {};
|
||||
struct addrinfo* result = NULL;
|
||||
struct addrinfo* result = nullptr;
|
||||
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
@@ -337,7 +337,7 @@ bool WinsockNetLayer::JoinGame(const char* ip, int port)
|
||||
int noDelay = 1;
|
||||
setsockopt(s_hostConnectionSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&noDelay, sizeof(noDelay));
|
||||
|
||||
iResult = connect(s_hostConnectionSocket, result->ai_addr, (int)result->ai_addrlen);
|
||||
iResult = connect(s_hostConnectionSocket, result->ai_addr, static_cast<int>(result->ai_addrlen));
|
||||
if (iResult == SOCKET_ERROR)
|
||||
{
|
||||
int err = WSAGetLastError();
|
||||
@@ -397,7 +397,7 @@ bool WinsockNetLayer::JoinGame(const char* ip, int port)
|
||||
s_active = true;
|
||||
s_connected = true;
|
||||
|
||||
s_clientRecvThread = CreateThread(NULL, 0, ClientRecvThreadProc, NULL, 0, NULL);
|
||||
s_clientRecvThread = CreateThread(nullptr, 0, ClientRecvThreadProc, nullptr, 0, nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -416,10 +416,10 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void* data, int dataSize)
|
||||
EnterCriticalSection(&s_sendLock);
|
||||
|
||||
BYTE header[4];
|
||||
header[0] = (BYTE)((dataSize >> 24) & 0xFF);
|
||||
header[1] = (BYTE)((dataSize >> 16) & 0xFF);
|
||||
header[2] = (BYTE)((dataSize >> 8) & 0xFF);
|
||||
header[3] = (BYTE)(dataSize & 0xFF);
|
||||
header[0] = static_cast<BYTE>((dataSize >> 24) & 0xFF);
|
||||
header[1] = static_cast<BYTE>((dataSize >> 16) & 0xFF);
|
||||
header[2] = static_cast<BYTE>((dataSize >> 8) & 0xFF);
|
||||
header[3] = static_cast<BYTE>(dataSize & 0xFF);
|
||||
|
||||
int totalSent = 0;
|
||||
int toSend = 4;
|
||||
@@ -437,7 +437,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void* data, int dataSize)
|
||||
totalSent = 0;
|
||||
while (totalSent < dataSize)
|
||||
{
|
||||
int sent = send(sock, (const char*)data + totalSent, dataSize - totalSent, 0);
|
||||
int sent = send(sock, static_cast<const char *>(data) + totalSent, dataSize - totalSent, 0);
|
||||
if (sent == SOCKET_ERROR || sent == 0)
|
||||
{
|
||||
LeaveCriticalSection(&s_sendLock);
|
||||
@@ -512,7 +512,7 @@ void WinsockNetLayer::HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsig
|
||||
INetworkPlayer* pPlayerFrom = g_NetworkManager.GetPlayerBySmallId(fromSmallId);
|
||||
INetworkPlayer* pPlayerTo = g_NetworkManager.GetPlayerBySmallId(toSmallId);
|
||||
|
||||
if (pPlayerFrom == NULL || pPlayerTo == NULL)
|
||||
if (pPlayerFrom == nullptr || pPlayerTo == nullptr)
|
||||
{
|
||||
app.DebugPrintf("NET RECV: DROPPED %u bytes from=%d to=%d (player NULL: from=%p to=%p)\n",
|
||||
dataSize, fromSmallId, toSmallId, pPlayerFrom, pPlayerTo);
|
||||
@@ -522,7 +522,7 @@ void WinsockNetLayer::HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsig
|
||||
if (s_isHost)
|
||||
{
|
||||
::Socket* pSocket = pPlayerFrom->GetSocket();
|
||||
if (pSocket != NULL)
|
||||
if (pSocket != nullptr)
|
||||
pSocket->pushDataToQueue(data, dataSize, false);
|
||||
else
|
||||
app.DebugPrintf("NET RECV: DROPPED %u bytes, host pSocket NULL for from=%d\n", dataSize, fromSmallId);
|
||||
@@ -530,7 +530,7 @@ void WinsockNetLayer::HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsig
|
||||
else
|
||||
{
|
||||
::Socket* pSocket = pPlayerTo->GetSocket();
|
||||
if (pSocket != NULL)
|
||||
if (pSocket != nullptr)
|
||||
pSocket->pushDataToQueue(data, dataSize, true);
|
||||
else
|
||||
app.DebugPrintf("NET RECV: DROPPED %u bytes, client pSocket NULL for to=%d\n", dataSize, toSmallId);
|
||||
@@ -541,7 +541,7 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
|
||||
{
|
||||
while (s_active)
|
||||
{
|
||||
SOCKET clientSocket = accept(s_listenSocket, NULL, NULL);
|
||||
SOCKET clientSocket = accept(s_listenSocket, nullptr, nullptr);
|
||||
if (clientSocket == INVALID_SOCKET)
|
||||
{
|
||||
if (s_active)
|
||||
@@ -561,7 +561,7 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
|
||||
}
|
||||
|
||||
extern CPlatformNetworkManagerStub* g_pPlatformNetworkManager;
|
||||
if (g_pPlatformNetworkManager != NULL && !g_pPlatformNetworkManager->CanAcceptMoreConnections())
|
||||
if (g_pPlatformNetworkManager != nullptr && !g_pPlatformNetworkManager->CanAcceptMoreConnections())
|
||||
{
|
||||
app.DebugPrintf("Win64 LAN: Rejecting connection, server at max players\n");
|
||||
SendRejectWithReason(clientSocket, DisconnectPacket::eDisconnect_ServerFull);
|
||||
@@ -604,11 +604,11 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
|
||||
conn.tcpSocket = clientSocket;
|
||||
conn.smallId = assignedSmallId;
|
||||
conn.active = true;
|
||||
conn.recvThread = NULL;
|
||||
conn.recvThread = nullptr;
|
||||
|
||||
EnterCriticalSection(&s_connectionsLock);
|
||||
s_connections.push_back(conn);
|
||||
int connIdx = (int)s_connections.size() - 1;
|
||||
int connIdx = static_cast<int>(s_connections.size()) - 1;
|
||||
LeaveCriticalSection(&s_connectionsLock);
|
||||
|
||||
app.DebugPrintf("Win64 LAN: Client connected, assigned smallId=%d\n", assignedSmallId);
|
||||
@@ -627,10 +627,10 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
|
||||
|
||||
DWORD* threadParam = new DWORD;
|
||||
*threadParam = connIdx;
|
||||
HANDLE hThread = CreateThread(NULL, 0, RecvThreadProc, threadParam, 0, NULL);
|
||||
HANDLE hThread = CreateThread(nullptr, 0, RecvThreadProc, threadParam, 0, nullptr);
|
||||
|
||||
EnterCriticalSection(&s_connectionsLock);
|
||||
if (connIdx < (int)s_connections.size())
|
||||
if (connIdx < static_cast<int>(s_connections.size()))
|
||||
s_connections[connIdx].recvThread = hThread;
|
||||
LeaveCriticalSection(&s_connectionsLock);
|
||||
}
|
||||
@@ -639,11 +639,11 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param)
|
||||
|
||||
DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param)
|
||||
{
|
||||
DWORD connIdx = *(DWORD*)param;
|
||||
delete (DWORD*)param;
|
||||
DWORD connIdx = *static_cast<DWORD *>(param);
|
||||
delete static_cast<DWORD *>(param);
|
||||
|
||||
EnterCriticalSection(&s_connectionsLock);
|
||||
if (connIdx >= (DWORD)s_connections.size())
|
||||
if (connIdx >= static_cast<DWORD>(s_connections.size()))
|
||||
{
|
||||
LeaveCriticalSection(&s_connectionsLock);
|
||||
return 0;
|
||||
@@ -665,10 +665,10 @@ DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param)
|
||||
}
|
||||
|
||||
int packetSize =
|
||||
((uint32_t)header[0] << 24) |
|
||||
((uint32_t)header[1] << 16) |
|
||||
((uint32_t)header[2] << 8) |
|
||||
((uint32_t)header[3]);
|
||||
(static_cast<uint32_t>(header[0]) << 24) |
|
||||
(static_cast<uint32_t>(header[1]) << 16) |
|
||||
(static_cast<uint32_t>(header[2]) << 8) |
|
||||
static_cast<uint32_t>(header[3]);
|
||||
|
||||
if (packetSize <= 0 || packetSize > WIN64_NET_MAX_PACKET_SIZE)
|
||||
{
|
||||
@@ -679,7 +679,7 @@ DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((int)recvBuf.size() < packetSize)
|
||||
if (static_cast<int>(recvBuf.size()) < packetSize)
|
||||
{
|
||||
recvBuf.resize(packetSize);
|
||||
app.DebugPrintf("Win64 LAN: Resized host recv buffer to %d bytes for client smallId=%d\n", packetSize, clientSmallId);
|
||||
@@ -792,14 +792,14 @@ bool WinsockNetLayer::JoinSplitScreen(int padIndex, BYTE* outSmallId)
|
||||
}
|
||||
|
||||
struct addrinfo hints = {};
|
||||
struct addrinfo* result = NULL;
|
||||
struct addrinfo* result = nullptr;
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
|
||||
char portStr[16];
|
||||
sprintf_s(portStr, "%d", g_Win64MultiplayerPort);
|
||||
if (getaddrinfo(g_Win64MultiplayerIP, portStr, &hints, &result) != 0 || result == NULL)
|
||||
if (getaddrinfo(g_Win64MultiplayerIP, portStr, &hints, &result) != 0 || result == nullptr)
|
||||
{
|
||||
app.DebugPrintf("Win64 LAN: Split-screen getaddrinfo failed for %s:%d\n", g_Win64MultiplayerIP, g_Win64MultiplayerPort);
|
||||
return false;
|
||||
@@ -850,8 +850,8 @@ bool WinsockNetLayer::JoinSplitScreen(int padIndex, BYTE* outSmallId)
|
||||
|
||||
int* threadParam = new int;
|
||||
*threadParam = padIndex;
|
||||
s_splitScreenRecvThread[padIndex] = CreateThread(NULL, 0, SplitScreenRecvThreadProc, threadParam, 0, NULL);
|
||||
if (s_splitScreenRecvThread[padIndex] == NULL)
|
||||
s_splitScreenRecvThread[padIndex] = CreateThread(nullptr, 0, SplitScreenRecvThreadProc, threadParam, 0, nullptr);
|
||||
if (s_splitScreenRecvThread[padIndex] == nullptr)
|
||||
{
|
||||
delete threadParam;
|
||||
closesocket(sock);
|
||||
@@ -874,11 +874,11 @@ void WinsockNetLayer::CloseSplitScreenConnection(int padIndex)
|
||||
s_splitScreenSocket[padIndex] = INVALID_SOCKET;
|
||||
}
|
||||
s_splitScreenSmallId[padIndex] = 0xFF;
|
||||
if (s_splitScreenRecvThread[padIndex] != NULL)
|
||||
if (s_splitScreenRecvThread[padIndex] != nullptr)
|
||||
{
|
||||
WaitForSingleObject(s_splitScreenRecvThread[padIndex], 2000);
|
||||
CloseHandle(s_splitScreenRecvThread[padIndex]);
|
||||
s_splitScreenRecvThread[padIndex] = NULL;
|
||||
s_splitScreenRecvThread[padIndex] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -952,7 +952,7 @@ DWORD WINAPI WinsockNetLayer::ClientRecvThreadProc(LPVOID param)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((int)recvBuf.size() < packetSize)
|
||||
if (static_cast<int>(recvBuf.size()) < packetSize)
|
||||
{
|
||||
recvBuf.resize(packetSize);
|
||||
app.DebugPrintf("Win64 LAN: Resized client recv buffer to %d bytes\n", packetSize);
|
||||
@@ -980,7 +980,7 @@ bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t* hostName, un
|
||||
memset(&s_advertiseData, 0, sizeof(s_advertiseData));
|
||||
s_advertiseData.magic = WIN64_LAN_BROADCAST_MAGIC;
|
||||
s_advertiseData.netVersion = netVer;
|
||||
s_advertiseData.gamePort = (WORD)gamePort;
|
||||
s_advertiseData.gamePort = static_cast<WORD>(gamePort);
|
||||
wcsncpy_s(s_advertiseData.hostName, 32, hostName, _TRUNCATE);
|
||||
s_advertiseData.playerCount = 1;
|
||||
s_advertiseData.maxPlayers = MINECRAFT_NET_MAX_PLAYERS;
|
||||
@@ -1002,7 +1002,7 @@ bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t* hostName, un
|
||||
setsockopt(s_advertiseSock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast));
|
||||
|
||||
s_advertising = true;
|
||||
s_advertiseThread = CreateThread(NULL, 0, AdvertiseThreadProc, NULL, 0, NULL);
|
||||
s_advertiseThread = CreateThread(nullptr, 0, AdvertiseThreadProc, nullptr, 0, nullptr);
|
||||
|
||||
app.DebugPrintf("Win64 LAN: Started advertising on UDP port %d\n", WIN64_LAN_DISCOVERY_PORT);
|
||||
return true;
|
||||
@@ -1018,11 +1018,11 @@ void WinsockNetLayer::StopAdvertising()
|
||||
s_advertiseSock = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if (s_advertiseThread != NULL)
|
||||
if (s_advertiseThread != nullptr)
|
||||
{
|
||||
WaitForSingleObject(s_advertiseThread, 2000);
|
||||
CloseHandle(s_advertiseThread);
|
||||
s_advertiseThread = NULL;
|
||||
s_advertiseThread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1108,7 +1108,7 @@ bool WinsockNetLayer::StartDiscovery()
|
||||
setsockopt(s_discoverySock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout));
|
||||
|
||||
s_discovering = true;
|
||||
s_discoveryThread = CreateThread(NULL, 0, DiscoveryThreadProc, NULL, 0, NULL);
|
||||
s_discoveryThread = CreateThread(nullptr, 0, DiscoveryThreadProc, nullptr, 0, nullptr);
|
||||
|
||||
app.DebugPrintf("Win64 LAN: Listening for LAN games on UDP port %d\n", WIN64_LAN_DISCOVERY_PORT);
|
||||
return true;
|
||||
@@ -1124,11 +1124,11 @@ void WinsockNetLayer::StopDiscovery()
|
||||
s_discoverySock = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if (s_discoveryThread != NULL)
|
||||
if (s_discoveryThread != nullptr)
|
||||
{
|
||||
WaitForSingleObject(s_discoveryThread, 2000);
|
||||
CloseHandle(s_discoveryThread);
|
||||
s_discoveryThread = NULL;
|
||||
s_discoveryThread = nullptr;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&s_discoveryLock);
|
||||
@@ -1162,7 +1162,7 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (recvLen < (int)sizeof(Win64LANBroadcast))
|
||||
if (recvLen < static_cast<int>(sizeof(Win64LANBroadcast)))
|
||||
continue;
|
||||
|
||||
Win64LANBroadcast* broadcast = (Win64LANBroadcast*)recvBuf;
|
||||
@@ -1180,7 +1180,7 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
|
||||
for (size_t i = 0; i < s_discoveredSessions.size(); i++)
|
||||
{
|
||||
if (strcmp(s_discoveredSessions[i].hostIP, senderIP) == 0 &&
|
||||
s_discoveredSessions[i].hostPort == (int)broadcast->gamePort)
|
||||
s_discoveredSessions[i].hostPort == static_cast<int>(broadcast->gamePort))
|
||||
{
|
||||
s_discoveredSessions[i].netVersion = broadcast->netVersion;
|
||||
wcsncpy_s(s_discoveredSessions[i].hostName, 32, broadcast->hostName, _TRUNCATE);
|
||||
@@ -1201,7 +1201,7 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
|
||||
Win64LANSession session;
|
||||
memset(&session, 0, sizeof(session));
|
||||
strncpy_s(session.hostIP, sizeof(session.hostIP), senderIP, _TRUNCATE);
|
||||
session.hostPort = (int)broadcast->gamePort;
|
||||
session.hostPort = static_cast<int>(broadcast->gamePort);
|
||||
session.netVersion = broadcast->netVersion;
|
||||
wcsncpy_s(session.hostName, 32, broadcast->hostName, _TRUNCATE);
|
||||
session.playerCount = broadcast->playerCount;
|
||||
|
||||
Reference in New Issue
Block a user