mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-29 15:04:23 +01:00
Implement peer selection properly (though still untested)
This commit is contained in:
parent
eff65f446c
commit
7b3cd3555a
@ -90,7 +90,7 @@ Network::Network(const char *remote_host, int port)
|
|||||||
memset(this->screenshot, 0, sizeof(this->screenshot));
|
memset(this->screenshot, 0, sizeof(this->screenshot));
|
||||||
|
|
||||||
Network::networking_started = true;
|
Network::networking_started = true;
|
||||||
this->peer_selected = false;
|
this->peer_selected = -1;
|
||||||
/* Peer addresses, if it fails we are out of luck */
|
/* Peer addresses, if it fails we are out of luck */
|
||||||
if (this->InitSocket(remote_host, port) == false)
|
if (this->InitSocket(remote_host, port) == false)
|
||||||
{
|
{
|
||||||
@ -1016,7 +1016,7 @@ bool Network::ConnectToBroker()
|
|||||||
bool out;
|
bool out;
|
||||||
|
|
||||||
/* Reset peer selection */
|
/* Reset peer selection */
|
||||||
this->peer_selected = false;
|
this->peer_selected = -1;
|
||||||
|
|
||||||
pi->is_master = 0; /* Will be set later */
|
pi->is_master = 0; /* Will be set later */
|
||||||
pi->key = ThePrefs.NetworkKey;
|
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)
|
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->SelectPeer(server_id);
|
||||||
this->InitSockaddr(&this->connection_addr, hostname, port);
|
this->InitSockaddr(&this->connection_addr, hostname, port);
|
||||||
this->peer_selected = true;
|
this->peer_selected = 1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
network_connection_error_t Network::WaitForPeerSelection()
|
network_connection_error_t Network::WaitForPeerSelection()
|
||||||
{
|
{
|
||||||
if (!this->peer_selected)
|
if (this->peer_selected == 1)
|
||||||
return AGAIN_ERROR;
|
return AGAIN_ERROR;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -240,6 +240,11 @@ public:
|
|||||||
|
|
||||||
bool SelectPeer(const char *hostname, uint16_t port, uint32_t server_id);
|
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();
|
network_connection_error_t ConnectFSM();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -381,7 +386,7 @@ protected:
|
|||||||
Uint8 cur_joystick_data;
|
Uint8 cur_joystick_data;
|
||||||
|
|
||||||
/* Connection to the peer */
|
/* Connection to the peer */
|
||||||
bool peer_selected;
|
int peer_selected;
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_in connection_addr;
|
struct sockaddr_in connection_addr;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "network_user_menu.hh"
|
#include "network_user_menu.hh"
|
||||||
|
|
||||||
#include <Network.h>
|
#include <Network.h>
|
||||||
|
#include <C64.h>
|
||||||
|
|
||||||
class NetworkUserView;
|
class NetworkUserView;
|
||||||
|
|
||||||
@ -205,6 +206,15 @@ public:
|
|||||||
|
|
||||||
virtual void selectCallback(int which)
|
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();
|
Gui::gui->popView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +229,7 @@ public:
|
|||||||
|
|
||||||
virtual void escapeCallback(int which)
|
virtual void escapeCallback(int which)
|
||||||
{
|
{
|
||||||
|
TheC64->peer->CancelPeerSelection();
|
||||||
Gui::gui->popView();
|
Gui::gui->popView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user