Skip to content

Commit

Permalink
remove SDLNet_ResolveHost / SDLNet_ResolveIP (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
SheridanR authored Mar 3, 2022
1 parent 0ace426 commit 889709a
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/ui/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5300,7 +5300,15 @@ namespace MainMenu {

// open sockets
if (!(net_sock = SDLNet_UDP_Open(port))) {
printlog( "warning: SDLNet_UDP_open has failed: %s\n", SDLNet_GetError());
char buf[1024];
snprintf(buf, sizeof(buf), "Failed to open UDP socket.");
printlog(buf);
multiplayer = SINGLE;
disconnectFromLobby();
destroyMainMenu();
currentLobbyType = LobbyType::None;
createMainMenu(false);
connectionErrorPrompt(buf);
return false;
}

Expand Down Expand Up @@ -8600,7 +8608,9 @@ namespace MainMenu {
if (directConnect) {
memcpy(net_packet->data, "SCAN", 4);
net_packet->len = 4;
SDLNet_ResolveHost(&net_packet->address, "255.255.255.255", DEFAULT_PORT);
//SDLNet_ResolveHost(&net_packet->address, "255.255.255.255", DEFAULT_PORT);
net_packet->address.host = 0xffffffff;
SDLNet_Write16(DEFAULT_PORT, &net_packet->address.port);
sendPacket(net_sock, -1, net_packet, 0);
} else {
// TODO
Expand All @@ -8614,8 +8624,6 @@ namespace MainMenu {
Uint32 packetId = SDLNet_Read32(net_packet->data);
if (packetId == 'SCAN') {
if (net_packet->len > 4) {
printlog("got a SCAN packet!\n");

char hostname[256] = { '\0' };
Uint32 hostname_len;
hostname_len = SDLNet_Read32(&net_packet->data[4]);
Expand All @@ -8632,8 +8640,18 @@ namespace MainMenu {
info.players = players;
info.ping = ping;
info.locked = false;
info.address = SDLNet_ResolveIP(&net_packet->address);

Uint32 host = net_packet->address.host;
char buf[16];
snprintf(buf, sizeof(buf), "%hhu.%hhu.%hhu.%hhu",
(host & 0x000000ff) >> 0,
(host & 0x0000ff00) >> 8,
(host & 0x00ff0000) >> 16,
(host & 0xff000000) >> 24);
info.address = buf;
add_lobby(info);

printlog("got a SCAN packet from %s\n", buf);
}
}
}
Expand Down

0 comments on commit 889709a

Please sign in to comment.