Lots of wii network fixes, updated changelog

This commit is contained in:
simon.kagstrom 2009-03-08 19:02:19 +00:00
parent ca77dcfb1d
commit 0298df2061
6 changed files with 55 additions and 22 deletions

View File

@ -8,6 +8,10 @@
TODO: Handle Run/Stop in virtual keyboard (?) TODO: Handle Run/Stop in virtual keyboard (?)
version 8: version 8:
* Lots of networking code which will not work yet
* Also add the analog part of the classic controller
* Make it possible to control the game with the Nunchuk (Aaron Morris) * Make it possible to control the game with the Nunchuk (Aaron Morris)
* Correct binding of shifted keys (thanks to Bob Forgan) * Correct binding of shifted keys (thanks to Bob Forgan)

View File

@ -46,6 +46,8 @@ Network::Network(const char *remote_host, int port, bool is_master)
{ {
const size_t size = NETWORK_UPDATE_SIZE; const size_t size = NETWORK_UPDATE_SIZE;
this->InitNetwork();
this->is_master = is_master; this->is_master = is_master;
this->connected = false; this->connected = false;
@ -814,6 +816,7 @@ bool Network::WaitForPeerAddress()
/* Not sure what to do if this fails */ /* Not sure what to do if this fails */
this->IpToStr(buf, pi->peers[0].public_ip); this->IpToStr(buf, pi->peers[0].public_ip);
printf("Converted ip to %s:%d\n", buf, pi->peers[0].public_port);
return this->InitSockaddr(&this->connection_addr, buf, return this->InitSockaddr(&this->connection_addr, buf,
pi->peers[0].public_port); pi->peers[0].public_port);
@ -867,6 +870,7 @@ bool Network::WaitForPeerList()
/* Not sure what to do if this fails */ /* Not sure what to do if this fails */
this->IpToStr(buf, pi->peers[sel].public_ip); this->IpToStr(buf, pi->peers[sel].public_ip);
printf("Converted ip to %s:%d\n", buf, port);
/* Finally tell the broker who we selected */ /* Finally tell the broker who we selected */
this->SelectPeer(pi->peers[sel].server_id); this->SelectPeer(pi->peers[sel].server_id);

View File

@ -185,6 +185,8 @@ public:
static void PushSound(uint8 vol); static void PushSound(uint8 vol);
protected: protected:
void InitNetwork();
size_t DecodeSoundUpdate(struct NetworkUpdate *src, char *buf); size_t DecodeSoundUpdate(struct NetworkUpdate *src, char *buf);
size_t EncodeSoundRLE(struct NetworkUpdate *dst, size_t EncodeSoundRLE(struct NetworkUpdate *dst,

View File

@ -125,3 +125,8 @@ void Network::CloseSocket()
{ {
close(this->sock); close(this->sock);
} }
void Network::InitNetwork()
{
/* Do nothing */
}

View File

@ -8,11 +8,13 @@ static int set_sock_opts(int sock)
int d = 1; int d = 1;
memset(&tv, 0, sizeof(tv)); memset(&tv, 0, sizeof(tv));
#if 0
tv.tv_sec = 2; tv.tv_sec = 2;
net_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, net_setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
&tv, sizeof(struct timeval)); &tv, sizeof(struct timeval));
net_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, net_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
&tv, sizeof(struct timeval)); &tv, sizeof(struct timeval));
#endif
return net_setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, &d, sizeof(int)); return net_setsockopt(sock,SOL_SOCKET,SO_REUSEADDR, &d, sizeof(int));
} }
@ -27,11 +29,11 @@ bool Network::InitSockaddr (struct sockaddr_in *name,
return false; return false;
} }
memset(name, 0, sizeof(name));
name->sin_family = AF_INET; name->sin_family = AF_INET;
name->sin_port = htons (port); name->sin_port = htons (port);
name->sin_len = sizeof(struct sockaddr_in); name->sin_len = 8; // sizeof(struct sockaddr_in);
memcpy ((char *) &name->sin_addr, hostinfo->h_addr_list[0], name->sin_addr.s_addr = *(uint32*)hostinfo->h_addr_list[0];
hostinfo->h_length);
return true; return true;
} }
@ -42,15 +44,20 @@ bool Network::InitSocket(const char *remote_host, int port)
this->sock = net_socket (PF_INET, SOCK_DGRAM, 0); this->sock = net_socket (PF_INET, SOCK_DGRAM, 0);
if (this->sock < 0) if (this->sock < 0)
{ {
perror ("socket (client)"); fprintf (stderr, "Could not init socket. Failed with %d\n", this->sock);
sleep(1);
return false; return false;
} }
int _true = false;
if (net_ioctl (this->sock, FIONBIO, (char *)(&_true)) < 0)
fprintf(stderr, "Could not set FIONBIO\n");
set_sock_opts(this->sock); set_sock_opts(this->sock);
/* Connect to the server. */ /* Connect to the server. */
this->InitSockaddr(&this->connection_addr, remote_host, port); this->InitSockaddr(&this->connection_addr, remote_host, port);
fprintf(stderr, "Bajning: %d\n",
net_bind(this->sock,(struct sockaddr *)&this->connection_addr,sizeof(struct sockaddr)));
return true; return true;
} }
@ -74,14 +81,12 @@ bool Network::ReceiveData(void *dst, int sock, size_t sz)
ssize_t Network::ReceiveFrom(void *dst, int sock, size_t sz, ssize_t Network::ReceiveFrom(void *dst, int sock, size_t sz,
struct sockaddr_in *from) struct sockaddr_in *from)
{ {
socklen_t from_sz = from ? sizeof(struct sockaddr_in) : 0; return net_recv(sock, dst, sz, 0);
return net_recvfrom(sock, dst, sz, 0, (struct sockaddr*)from, &from_sz);
} }
ssize_t Network::SendTo(void *src, int sock, size_t sz, struct sockaddr_in *to) ssize_t Network::SendTo(void *src, int sock, size_t sz, struct sockaddr_in *to)
{ {
socklen_t to_sz = sizeof(struct sockaddr_in); socklen_t to_sz = to->sin_len;
assert(to); assert(to);
return net_sendto(sock, src, sz, 0, (struct sockaddr*)to, to_sz); return net_sendto(sock, src, sz, 0, (struct sockaddr*)to, to_sz);
@ -105,24 +110,37 @@ bool Network::SendData(void *src, int sock, size_t sz)
bool Network::Select(int sock, struct timeval *tv) bool Network::Select(int sock, struct timeval *tv)
{ {
fd_set fds; unsigned long available;
int v;
FD_ZERO(&fds); return true;
FD_SET(sock, &fds); if (net_ioctl (sock, FIONREAD, &available) < 0)
fprintf(stderr, "UDP: ioctlsocket (FIONREAD) failed\n");
v = net_select(sock + 1, &fds, NULL, NULL, tv); if (available == 0 && tv)
if (v < 0)
{ {
fprintf(stderr, "Select failed\n"); /* OK, this really only "works" because we know that this is
return false; * called during init */
sleep(tv->tv_sec);
return this->Select(sock, NULL);
} }
return available > 0;
/* v is 0 if the sock is not ready */
return v > 0;
} }
void Network::CloseSocket() void Network::CloseSocket()
{ {
net_close(this->sock); net_close(this->sock);
} }
void Network::InitNetwork()
{
char myIP[16];
/* From Snes9x-gx */
while (net_init() == -EAGAIN);
if (if_config(myIP, NULL, NULL, true) < 0)
{
fprintf(stderr, "\n\n\nError getting IP address via DHCP.\n");
sleep(2);
exit(1);
}
}

View File

@ -61,7 +61,7 @@ extern "C" int main(int argc, char **argv)
the_app->ReadyToRun(); the_app->ReadyToRun();
delete the_app; delete the_app;
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); // SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
return 0; return 0;
} }