Skip to content

Commit

Permalink
fix bindaddress test on unix, ignore selecting units when mouse is on…
Browse files Browse the repository at this point in the history
… bottom hud area
  • Loading branch information
FolkertVanVerseveld committed Feb 28, 2024
1 parent 14e1f98 commit e7bff9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion game/src/net/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,11 @@ void TcpSocket::bind(const char *address, uint16_t port) {
sockaddr_in dst{ 0 };

dst.sin_family = AF_INET;
dst.sin_addr.s_addr = inet_addr(address);
dst.sin_port = htons(port);

if (inet_pton(AF_INET, address, &dst.sin_addr.s_addr) != 1)
throw std::runtime_error(std::string("bind failed: invalid address"));

// https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind
int r = ::bind(sock, (const sockaddr *)&dst, sizeof dst);

Expand Down
5 changes: 5 additions & 0 deletions game/src/ui/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ void UICache::mouse_left_process() {
return;
}

// ignore selecting units when mouse is on bottom hud area
if (point_in_rect(io.MousePos.x, io.MousePos.y, gmb_bottom)) {
return;
}

bool select_area = multi_select;
multi_select = select_started = false;

Expand Down
3 changes: 1 addition & 2 deletions game/tests/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ TEST(Tcp, BindDummy) {
} catch (std::runtime_error&) {}
}

// FIXME find out why a.b.c.d works on linux
TEST_F(NoUnixFixture, TcpBindBadAddress) {
TEST(Tcp, TcpBindBadAddress) {
Net net;
TcpSocket tcp;
try {
Expand Down

0 comments on commit e7bff9d

Please sign in to comment.