diff --git a/include/network.h b/include/network.h index 1c54289..526fc52 100644 --- a/include/network.h +++ b/include/network.h @@ -1,4 +1,4 @@ -/* $Id: network.h,v 1.16 2004/02/04 22:56:55 patty21 Exp $ +/* $Id: network.h,v 1.17 2004/02/08 22:49:42 stpohle Exp $ * network.h file... for everything what have to do with the network stuff */ @@ -10,7 +10,7 @@ #define MAX_UDPDATA 1024 #define PKG_RESENDCACHE_SIZE (64*1024) -#define PKG_IN_INDEX_NUM 256 +#define PKG_IN_INDEX_NUM 512 #define RESENDCACHE_TIMEOUT 400 #define RESENDCACHE_TIMEOUT_MENU 3000 #define RESENDCACHE_RETRY 10 diff --git a/src/packets.c b/src/packets.c index 5de72cc..60c99e0 100644 --- a/src/packets.c +++ b/src/packets.c @@ -1461,16 +1461,21 @@ inpkg_delplayer (int pl_nr) { void send_pkg (struct pkg *packet, _net_addr * addr) { - /* if the packet would be send to the ai player so ignore it */ - if (PS_IS_aiplayer (players[addr->pl_nr].state)) + /* check if the packet would be send to + * an AI_Player, so ignore it. */ + if ((addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) && PS_IS_aiplayer (players[addr->pl_nr].state)) return; + /* set the id for the packet and the network flags + * the id is needed for the inpkg index to check for + * double reached packets */ packet->h.id = HTON16 (pkg_lastid++); if (bman.net_ai_family != PF_INET) packet->h.flags = packet->h.flags | PKGF_ipv6; udp_send (bman.sock, (char *) packet, NTOH16 (packet->h.len), &addr->sAddr, bman.net_ai_family); - /* test if we have any important packet if so put it in the resend_cache */ + /* if PKGF_ackreq is set add the packet to the resendcache + * so we can resend it if no PKF_ackreq returned for the packet. */ if (packet->h.flags & PKGF_ackreq) { if (rscache_add (addr, packet) == -1) d_printf ("resend_cache overrun.... packet throw away.\n"); @@ -1521,18 +1526,26 @@ do_pkg (struct pkg *packet, _net_addr * addr) players[addr->pl_nr].net.pingreq = players[addr->pl_nr].net.pingack + 5; /* test if we have any important packet */ - if (packet->h.flags & PKGF_ackreq) + if (packet->h.flags & PKGF_ackreq) { + + /* we need to send an acknolege so the client + * knows we have got this packet and delete + * it from the resend cache. */ send_pkgack (addr, packet->h.typ, NTOH16 (packet->h.id)); + + /* check the packet with the index so we can + * ignore packets we already have got + * this is important to keep away from + * the bomb is dropped twice bug. */ + if (inpkg_check (packet->h.typ, NTOH16 (packet->h.id), addr) != -1) { + /* we have got this packet already */ + d_printf ("do_pkg: double packet ignoring addr->pl_nr=%d\n", addr->pl_nr); + if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) + players[addr->pl_nr].net.pkgopt.to_2sec++; + return 0; + } + } - /* check the packet with the index */ - if (inpkg_check (packet->h.typ, NTOH16 (packet->h.id), addr) != -1) { - /* we have got this packet already */ - d_printf ("do_pkg: double packet ignoring addr->pl_nr=%d\n", addr->pl_nr); - if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) - players[addr->pl_nr].net.pkgopt.to_2sec++; - return 0; - } - /* forward packet */ if (GT_MP_PTPM) fwd_pkg (packet, addr);