mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Fix Windows socket WSAENOTCONN disconnect; add boss encounter frames
Socket fixes (fixes Windows-only connection failure): - WorldSocket::connect() now waits for non-blocking connect to complete with select() before returning, preventing WSAENOTCONN on the first recv() call on Windows (Linux handles this implicitly but Windows requires writability poll after non-blocking connect) - Add net::isConnectionClosed() helper: treats WSAENOTCONN/WSAECONNRESET/ WSAESHUTDOWN/WSAECONNABORTED as graceful peer-close rather than recv errors - Apply isConnectionClosed() in both WorldSocket and TCPSocket recv loops UI: - Add renderBossFrames(): displays boss unit health bars in top-right corner when SMSG_UPDATE_INSTANCE_ENCOUNTER_UNIT has active slots; supports click-to-target and color-coded health bars (red→orange→yellow as HP drops)
This commit is contained in:
parent
b6dfa8b747
commit
1c1cdf0f23
6 changed files with 135 additions and 1 deletions
|
|
@ -153,6 +153,11 @@ void TCPSocket::update() {
|
|||
if (net::isWouldBlock(err)) {
|
||||
break;
|
||||
}
|
||||
if (net::isConnectionClosed(err)) {
|
||||
// Peer closed the connection — treat the same as recv() returning 0
|
||||
sawClose = true;
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_ERROR("Receive failed: ", net::errorString(err));
|
||||
disconnect();
|
||||
|
|
|
|||
|
|
@ -128,6 +128,39 @@ bool WorldSocket::connect(const std::string& host, uint16_t port) {
|
|||
sockfd = INVALID_SOCK;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Non-blocking connect in progress — wait up to 10s for completion.
|
||||
// On Windows, calling recv() before the connect completes returns
|
||||
// WSAENOTCONN; we must poll writability before declaring connected.
|
||||
fd_set writefds, errfds;
|
||||
FD_ZERO(&writefds);
|
||||
FD_ZERO(&errfds);
|
||||
FD_SET(sockfd, &writefds);
|
||||
FD_SET(sockfd, &errfds);
|
||||
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 10;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
int sel = ::select(static_cast<int>(sockfd) + 1, nullptr, &writefds, &errfds, &tv);
|
||||
if (sel <= 0) {
|
||||
LOG_ERROR("World server connection timed out (", host, ":", port, ")");
|
||||
net::closeSocket(sockfd);
|
||||
sockfd = INVALID_SOCK;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify the socket error code — writeable doesn't guarantee success on all platforms
|
||||
int sockErr = 0;
|
||||
socklen_t errLen = sizeof(sockErr);
|
||||
getsockopt(sockfd, SOL_SOCKET, SO_ERROR,
|
||||
reinterpret_cast<char*>(&sockErr), &errLen);
|
||||
if (sockErr != 0) {
|
||||
LOG_ERROR("Failed to connect to world server: ", net::errorString(sockErr));
|
||||
net::closeSocket(sockfd);
|
||||
sockfd = INVALID_SOCK;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
connected = true;
|
||||
|
|
@ -369,6 +402,11 @@ void WorldSocket::update() {
|
|||
if (net::isWouldBlock(err)) {
|
||||
break;
|
||||
}
|
||||
if (net::isConnectionClosed(err)) {
|
||||
// Peer closed the connection — treat the same as recv() returning 0
|
||||
sawClose = true;
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_ERROR("Receive failed: ", net::errorString(err));
|
||||
disconnect();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue