From 2bbbe035ffbbc436f499af2a0c82e9ac867af120 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sun, 1 Mar 2009 15:47:50 +0000 Subject: [PATCH] Make the stuff compile for Wii, removed some cruft and correct the network key --- Src/Network.cpp | 7 ++++++- Src/NetworkUnix.h | 38 ++++---------------------------------- Src/NetworkWii.h | 42 +++++++----------------------------------- Src/Prefs.cpp | 3 +-- 4 files changed, 18 insertions(+), 72 deletions(-) diff --git a/Src/Network.cpp b/Src/Network.cpp index cf16314..1395a01 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -24,6 +24,10 @@ #include "Prefs.h" #include "menu.h" +#if defined(GEKKO) +# include +#endif + #define N_SQUARES_W 16 #define N_SQUARES_H 8 @@ -753,7 +757,7 @@ bool Network::ConnectToBroker() bool out; pi->is_master = this->is_master; - pi->key = random() % 0xffff; + pi->key = ThePrefs.NetworkKey; strcpy((char*)pi->name, ThePrefs.NetworkName); this->AddNetworkUpdate(ud); out = this->SendUpdate(); @@ -983,6 +987,7 @@ bool Network::Connect() SDL_Flip(real_screen); #if defined(GEKKO) WPADData *wpad, *wpad_other; + Uint32 remote_keys; WPAD_ScanPads(); diff --git a/Src/NetworkUnix.h b/Src/NetworkUnix.h index 0a8fa2e..3322c65 100644 --- a/Src/NetworkUnix.h +++ b/Src/NetworkUnix.h @@ -18,48 +18,18 @@ static int set_sock_opts(int sock) return setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, &d, sizeof(int)); } -/* From glibc docs */ -static int make_socket (uint16_t port) -{ - struct sockaddr_in name; - int sock; - - /* Create the socket. */ - sock = socket (PF_INET, SOCK_DGRAM, 0); - if (sock < 0) - { - perror ("socket"); - exit (EXIT_FAILURE); - } - - set_sock_opts(sock); - - /* Give the socket a name. */ - name.sin_family = AF_INET; - name.sin_port = htons (port); - name.sin_addr.s_addr = htonl (INADDR_ANY); - if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) - { - perror ("bind"); - exit (1); - } - - return sock; -} - bool Network::InitSockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port) { - struct hostent *hostinfo; - - name->sin_family = AF_INET; - name->sin_port = htons (port); - hostinfo = gethostbyname (hostname); + struct hostent *hostinfo = gethostbyname (hostname); if (hostinfo == NULL) { fprintf (stderr, "Unknown host %s.\n", hostname); return false; } + + name->sin_family = AF_INET; + name->sin_port = htons (port); name->sin_addr = *(struct in_addr *) hostinfo->h_addr; return true; diff --git a/Src/NetworkWii.h b/Src/NetworkWii.h index d14f2b1..4dfe6a4 100644 --- a/Src/NetworkWii.h +++ b/Src/NetworkWii.h @@ -16,50 +16,22 @@ static int set_sock_opts(int sock) return net_setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, &d, sizeof(int)); } -/* From glibc docs */ -static int make_socket (uint16_t port) -{ - struct sockaddr_in name; - int sock; - - /* Create the socket. */ - sock = net_socket (PF_INET, SOCK_STREAM, 0); - if (sock < 0) - { - perror ("socket"); - exit (EXIT_FAILURE); - } - - set_sock_opts(sock); - - /* Give the socket a name. */ - name.sin_family = AF_INET; - name.sin_port = htons (port); - name.sin_addr.s_addr = htonl (INADDR_ANY); - if (net_bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) - { - perror ("bind"); - exit (1); - } - - return sock; -} - bool Network::InitSockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port) { - struct hostent *hostinfo; + struct hostent *hostinfo = net_gethostbyname ((char*)hostname); - name->sin_family = AF_INET; - name->sin_port = htons (port); - hostinfo = net_gethostbyname ((char*)hostname); if (hostinfo == NULL) { fprintf (stderr, "Unknown host %s.\n", hostname); return false; } -#warning this need to be fixed - //name->sin_addr = *(struct in_addr *) hostinfo->h_addr; + + name->sin_family = AF_INET; + name->sin_port = htons (port); + name->sin_len = sizeof(struct sockaddr_in); + memcpy ((char *) &name->sin_addr, hostinfo->h_addr_list[0], + hostinfo->h_length); return true; } diff --git a/Src/Prefs.cpp b/Src/Prefs.cpp index 449daad..d829151 100644 --- a/Src/Prefs.cpp +++ b/Src/Prefs.cpp @@ -17,7 +17,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #include "sysdeps.h" #include "Prefs.h" @@ -102,7 +101,7 @@ Prefs::Prefs() this->DisplayOption = 0; this->MsPerFrame = 28; #endif - this->NetworkKey = random() % 0xffff; + this->NetworkKey = rand() % 0xffff; snprintf(this->NetworkName, 32, "Unset.%d", this->NetworkKey); }