From 7b3cd3555a2716ed4c0f2fe50d544da03463bb64 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sun, 14 Feb 2010 08:05:08 +0000 Subject: [PATCH] Implement peer selection properly (though still untested) --- Src/Network.cpp | 14 ++++++++++---- Src/Network.h | 7 ++++++- Src/gui/network_user_menu.cpp | 11 +++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Src/Network.cpp b/Src/Network.cpp index d86efe7..ceec6a7 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -90,7 +90,7 @@ Network::Network(const char *remote_host, int port) memset(this->screenshot, 0, sizeof(this->screenshot)); Network::networking_started = true; - this->peer_selected = false; + this->peer_selected = -1; /* Peer addresses, if it fails we are out of luck */ if (this->InitSocket(remote_host, port) == false) { @@ -1016,7 +1016,7 @@ bool Network::ConnectToBroker() bool out; /* Reset peer selection */ - this->peer_selected = false; + this->peer_selected = -1; pi->is_master = 0; /* Will be set later */ pi->key = ThePrefs.NetworkKey; @@ -1130,16 +1130,22 @@ network_connection_error_t Network::WaitForPeerList() bool Network::SelectPeer(const char *hostname, uint16_t port, uint32_t server_id) { + if (!hostname) + { + this->peer_selected = 0; + return true; + } + this->SelectPeer(server_id); this->InitSockaddr(&this->connection_addr, hostname, port); - this->peer_selected = true; + this->peer_selected = 1; return true; } network_connection_error_t Network::WaitForPeerSelection() { - if (!this->peer_selected) + if (this->peer_selected == 1) return AGAIN_ERROR; return OK; diff --git a/Src/Network.h b/Src/Network.h index 5ef8616..9700797 100644 --- a/Src/Network.h +++ b/Src/Network.h @@ -240,6 +240,11 @@ public: bool SelectPeer(const char *hostname, uint16_t port, uint32_t server_id); + bool CancelPeerSelection() + { + return this->SelectPeer(NULL,0,0); + } + network_connection_error_t ConnectFSM(); /** @@ -381,7 +386,7 @@ protected: Uint8 cur_joystick_data; /* Connection to the peer */ - bool peer_selected; + int peer_selected; int sock; struct sockaddr_in connection_addr; diff --git a/Src/gui/network_user_menu.cpp b/Src/gui/network_user_menu.cpp index ce460eb..3bd0b19 100644 --- a/Src/gui/network_user_menu.cpp +++ b/Src/gui/network_user_menu.cpp @@ -6,6 +6,7 @@ #include "network_user_menu.hh" #include +#include class NetworkUserView; @@ -205,6 +206,15 @@ public: virtual void selectCallback(int which) { + if (which > 0) + { + PeerInfo *peer = this->peers[which - 1]; + + TheC64->peer->SelectPeer(peer->hostname, + peer->public_port, peer->server_id); + } + else + TheC64->peer->CancelPeerSelection(); Gui::gui->popView(); } @@ -219,6 +229,7 @@ public: virtual void escapeCallback(int which) { + TheC64->peer->CancelPeerSelection(); Gui::gui->popView(); }