diff --git a/Src/gui/network_menu.cpp b/Src/gui/network_menu.cpp index 457bd7d..454a2e5 100644 --- a/Src/gui/network_menu.cpp +++ b/Src/gui/network_menu.cpp @@ -76,6 +76,7 @@ public: TheC64->network_connection_type = CONNECT; TheC64->network->ConnectToBroker(); } + Gui::gui->exitMenu(); break; case 6: printf("Send message NYI\n"); // FIXME! Send message diff --git a/Src/gui/network_user_menu.cpp b/Src/gui/network_user_menu.cpp index e221580..1815232 100644 --- a/Src/gui/network_user_menu.cpp +++ b/Src/gui/network_user_menu.cpp @@ -10,29 +10,6 @@ class NetworkUserView; -const char *ip_to_str(uint8 *ip_in) -{ - char *out = (char *)xmalloc(24); - int ip[4]; - - for (int i = 0; i < 4; i++) - { - char tmp[3]; - char *endp; - - tmp[0] = ip_in[i * 2]; - tmp[1] = ip_in[i * 2 + 1]; - tmp[2] = '\0'; - ip[i] = strtoul(tmp, &endp, 16); - panic_if (endp == (const char*)tmp, - "Could not convert ip to str.\n"); - } - sprintf(out, "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); - - return out; -} - - class PeerInfo { public: @@ -53,6 +30,7 @@ public: { SDL_FreeSurface(this->scr); free((void*)this->name); + free((void*)this->hostname); } SDL_Surface *getScreenshot() @@ -193,14 +171,15 @@ public: this->freePeers(); this->n_peers = peerList->n_peers; - messages = (const char **)xmalloc( (peerList->n_peers + 1) * + messages = (const char **)xmalloc( (peerList->n_peers + 2) * sizeof(const char*)); this->peers = (PeerInfo**)xrealloc((void*)this->peers, peerList->n_peers * sizeof(PeerInfo*)); + messages[0] = (const char *)xstrdup("None"); for (unsigned i = 0; i < peerList->n_peers; i++) { - messages[i] = (const char*)xstrdup((char*)ps->name); + messages[i + 1] = (const char*)xstrdup((char*)ps->name); this->peers[i] = new PeerInfo(&peerList->peers[i]); } this->setText(messages); @@ -218,16 +197,15 @@ public: } else TheC64->network->CancelPeerSelection(); - Gui::gui->popView(); + Gui::gui->exitMenu(); } virtual void hoverCallback(int which) { - panic_if(which >= (int)this->n_peers, - "Which is impossibly large: %d vs %d\n", - which, this->n_peers); + if (which <= 0 || which > (int)this->n_peers) + return; - this->infoBox->setPeerInfo(this->peers[which]); + this->infoBox->setPeerInfo(this->peers[which - 1]); } virtual void escapeCallback(int which) diff --git a/Src/utils.cpp b/Src/utils.cpp index 7bc8da3..9267ce0 100644 --- a/Src/utils.cpp +++ b/Src/utils.cpp @@ -320,3 +320,25 @@ void highlight_background(SDL_Surface *where, Font *font, dst = (SDL_Rect){bg_x_end, bg_y_start, 0,0}; SDL_BlitSurface(bg_right, NULL, where, &dst); } + +const char *ip_to_str(uint8_t *ip_in) +{ + char *out = (char *)xmalloc(24); + int ip[4]; + + for (int i = 0; i < 4; i++) + { + char tmp[3]; + char *endp; + + tmp[0] = ip_in[i * 2]; + tmp[1] = ip_in[i * 2 + 1]; + tmp[2] = '\0'; + ip[i] = strtoul(tmp, &endp, 16); + panic_if (endp == (const char*)tmp, + "Could not convert ip to str.\n"); + } + sprintf(out, "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); + + return out; +} diff --git a/Src/utils.hh b/Src/utils.hh index 883c2a7..9db908d 100644 --- a/Src/utils.hh +++ b/Src/utils.hh @@ -84,4 +84,6 @@ void highlight_background(SDL_Surface *where, Font *font, SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right, int x, int y, int w, int h); +const char *ip_to_str(uint8_t *ip_in); + #endif /* __UTILS_H__ */