rscache_del had a problem

origin
stpohle 19 years ago
parent fd75ec1558
commit 03a5ad2718

@ -1,4 +1,4 @@
/* $Id: packets.h,v 1.33 2006/08/13 21:26:50 stpohle Exp $ /* $Id: packets.h,v 1.34 2006/08/15 15:00:31 stpohle Exp $
* network packets.. */ * network packets.. */
#ifndef _PACKETS_H_ #ifndef _PACKETS_H_
@ -405,7 +405,8 @@ extern void inpkg_delplayer (int pl_nr);
/* this functions will be defined in pkgcache.c */ /* this functions will be defined in pkgcache.c */
extern void rscache_init (); extern void rscache_init ();
extern void rscache_add (_net_addr *addr, struct pkg *packet); extern void rscache_add (_net_addr *addr, struct pkg *packet);
extern void rscache_del (_net_addr *addr, unsigned char typ, short unsigned int id); extern void rscache_delnr (int nr);
extern int rscache_del (_net_addr *addr, unsigned char typ, short unsigned int id);
extern void rscache_loop (); extern void rscache_loop ();
extern struct _resend_cache rscache; extern struct _resend_cache rscache;

@ -1,4 +1,4 @@
/* $Id: pkgcache.c,v 1.11 2006/08/15 13:33:32 stpohle Exp $ /* $Id: pkgcache.c,v 1.12 2006/08/15 15:00:32 stpohle Exp $
* Resendcache work, We need this to resend lost packets over the network. * Resendcache work, We need this to resend lost packets over the network.
* we will keep every packet with the PKGF_ackreq flag as long as we haven't * we will keep every packet with the PKGF_ackreq flag as long as we haven't
* got any answer from the destination host. And resend the packet after a givin * got any answer from the destination host. And resend the packet after a givin
@ -38,25 +38,38 @@ void rscache_add (_net_addr *addr, struct pkg *packet) {
rscache.count ++; rscache.count ++;
}; };
/* delete the entry */
void rscache_delnr (int nr) {
int a;
/* delete the packet from the cache */ if (nr >= 0 && nr < PKG_RESENDCACHE_SIZE) {
void rscache_del (_net_addr *addr, unsigned char typ, short unsigned int id) { for (a = nr; a < rscache.count - 1; a++)
rscache.entry[nr] = rscache.entry[nr+1];
rscache.count--;
d_printf ("rscache_delnr: element %d deleted.\n", nr);
}
else
d_printf ("rscache_delnr: number is out of range (%d)\n", nr);
}
/* find and delete the givin packet.
* Return Value: 0 = nothing deleted, 1 one entry deleted */
int rscache_del (_net_addr *addr, unsigned char typ, short unsigned int id) {
int i; int i;
d_printf ("rscache_del: addr %p\n", addr); d_printf ("rscache_del: addr %p (pl_nr:%d, typ:%d, id:%d\n", addr, addr->pl_nr, typ, id);
for (i = 0; (i < rscache.count) && (i < PKG_RESENDCACHE_SIZE); i++) { for (i = 0; (i < rscache.count) && (i < PKG_RESENDCACHE_SIZE); i++) {
if (rscache.entry[i].addr.pl_nr == addr->pl_nr && if (rscache.entry[i].addr.pl_nr == addr->pl_nr &&
NTOH16(rscache.entry[i].packet.h.id) == id && NTOH16(rscache.entry[i].packet.h.id) == id &&
((struct pkg)rscache.entry[i].packet).h.typ == typ) { // found element rscache.entry[i].packet.h.typ == typ) { // found element
int a; rscache_delnr (i);
d_printf ("rscache_del: element %d deleted.\n", i);
for (a = i; a < rscache.count - 1; a++) return 1;
rscache.entry[i] = rscache.entry[i+1];
rscache.count--;
break;
} }
} }
return 0;
}; };
/* test for old packets where we haven't got a ackreq packet for. /* test for old packets where we haven't got a ackreq packet for.
@ -93,8 +106,7 @@ void rscache_loop () {
if (rscache.entry[i].addr.pl_nr >= 0 && rscache.entry[i].addr.pl_nr < MAX_PLAYERS) if (rscache.entry[i].addr.pl_nr >= 0 && rscache.entry[i].addr.pl_nr < MAX_PLAYERS)
players[rscache.entry[i].addr.pl_nr].net.pkgopt.to_2sec++; players[rscache.entry[i].addr.pl_nr].net.pkgopt.to_2sec++;
rscache_del (&rscache.entry[i].addr, rscache.entry[i].packet.h.typ, rscache_delnr (i);
NTOH16(rscache.entry[i].packet.h.id));
if (i > 0) i--; if (i > 0) i--;
} }
} }

Loading…
Cancel
Save