major network packages problem fixed

origin
stpohle 22 years ago
parent 2bb83b37e2
commit 81ccc527ea

@ -1,4 +1,4 @@
$Id: ChangeLog,v 1.61 2004/02/01 01:15:03 stpohle Exp $ $Id: ChangeLog,v 1.62 2004/02/01 02:52:01 stpohle Exp $
- Added: Deathmatch mode. - Added: Deathmatch mode.
@ -42,6 +42,12 @@ $Id: ChangeLog,v 1.61 2004/02/01 01:15:03 stpohle Exp $
- Fixed: player_move had a problem with the speed of the player - Fixed: player_move had a problem with the speed of the player
on slow systems. on slow systems.
- Fixed: Major networking and packet handling problem. inpkg_check
fixed, strange crash fixed was reading from players[addr->pl_nr].*
where addr->pl_nr was set to -1. Function inpkg_delplayer added
so all inconig indexdata for double packets can be deleted. This
made a big problem when someone disconnected and tryed to rejoin
Version 0.11.0 Version 0.11.0
============== ==============

@ -1,4 +1,4 @@
/* $Id: network.h,v 1.13 2004/01/27 21:58:05 stpohle Exp $ /* $Id: network.h,v 1.14 2004/02/01 02:47:33 stpohle Exp $
* network.h file... for everything what have to do with the network stuff * network.h file... for everything what have to do with the network stuff
*/ */
@ -28,9 +28,6 @@
#define GS_WAITRUNNING (bman.state == GS_wait || bman.state == GS_ready || bman.state == GS_running) #define GS_WAITRUNNING (bman.state == GS_wait || bman.state == GS_ready || bman.state == GS_running)
#define GS_RUNNING (bman.state == GS_ready || bman.state == GS_running) #define GS_RUNNING (bman.state == GS_ready || bman.state == GS_running)
/* check if we can send to the player */
#define NET_CANSEND(__pl) ( __pl == bman.p_servnr || GT_MP_PTPM || (((players[__pl].net.flags & NETF_firewall) == 0) && !bman.firewall))
/* Little / Big Endian Convert */ /* Little / Big Endian Convert */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define NTOH16(__i) s_swap16(__i) #define NTOH16(__i) s_swap16(__i)
@ -136,5 +133,7 @@ extern void mw_draw_chat ();
extern void net_getserver (); extern void net_getserver ();
extern void srvlist_rebuildlist (); extern void srvlist_rebuildlist ();
/* check if we can send to the player */
#define NET_CANSEND(__pl) ( GT_MP_PTPM || __pl == bman.p_servnr || (((players[__pl].net.flags & NETF_firewall) == 0) && !bman.firewall))
#endif #endif

@ -9,7 +9,6 @@ enum _network_data {
PKG_playerid, PKG_playerid,
PKG_servermode, PKG_servermode,
PKG_joingame, PKG_joingame,
PKG_quit,
PKG_field, PKG_field,
PKG_playerdata, PKG_playerdata,
PKG_bombdata, PKG_bombdata,
@ -25,7 +24,8 @@ enum _network_data {
PKG_mapinfo, PKG_mapinfo,
PKG_tunneldata, PKG_tunneldata,
PKG_dropitem, PKG_dropitem,
PKG_respawn PKG_respawn,
PKG_quit // always the last known type
}; };
@ -363,7 +363,7 @@ extern void fwd_pkg (struct pkg *packet, _net_addr *addr);
extern int get_player_nr (char *host, char *port); extern int get_player_nr (char *host, char *port);
extern int inpkg_check (unsigned char typ, short int id, _net_addr *addr); extern int inpkg_check (unsigned char typ, short int id, _net_addr *addr);
extern void inpkg_delplayer (int pl_nr);
/* this functions will be defined in pkgcache.c */ /* this functions will be defined in pkgcache.c */
extern int rscache_add (_net_addr *addr, struct pkg *packet); extern int rscache_add (_net_addr *addr, struct pkg *packet);

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.58 2004/02/01 00:20:29 stpohle Exp $ */ /* $Id: network.c,v 1.59 2004/02/01 02:47:34 stpohle Exp $ */
/* /*
network routines. network routines.
*/ */
@ -652,13 +652,14 @@ net_delplayer (int pl_nr)
} }
} }
if (GT_MP_PTPS && pl_nr == 0) /* server quit */ if (GT_MP_PTPS && pl_nr == bman.p_servnr) /* server quit */
bman.state = GS_startup; bman.state = GS_startup;
if (GT_MP_PTPM && bman.notifygamemaster) if (GT_MP_PTPM && bman.notifygamemaster)
send_ogc_update (); send_ogc_update ();
d_playerdetail (" Player Left ... Playerlist\n"); d_playerdetail (" Player Left ... Playerlist\n");
inpkg_delplayer (pl_nr);
}; };

@ -11,8 +11,8 @@ extern _point debug_field;
extern int debug_lastping; extern int debug_lastping;
static short int pkg_lastid; /* the packet id, this will only counted static short int pkg_lastid; /* the packet id, this will only counted
up nothing more.. if we are at 0x10000 * up nothing more.. if we are at 0x10000
we will start at 0 */ * we will start at 0 */
struct _resend_cache resend_cache; struct _resend_cache resend_cache;
struct _inpkg_index inpkg_index[PKG_IN_INDEX_NUM]; struct _inpkg_index inpkg_index[PKG_IN_INDEX_NUM];
@ -1379,11 +1379,17 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
int i, int i,
pos; pos;
/* check if the player is still connected */
if (!PS_IS_used (players[addr->pl_nr].state))
return -1;
/* find packet */ /* find packet */
for (i = 0, pos = -1; (i < PKG_IN_INDEX_NUM && pos == -1); i++) for (i = 0, pos = -1; (i < PKG_IN_INDEX_NUM && pos == -1); i++)
if (inpkg_index[i].pl_nr == addr->pl_nr && if (inpkg_index[i].pl_nr == addr->pl_nr
inpkg_index[i].typ == typ && inpkg_index[i].id == id) && inpkg_index[i].typ == typ
&& inpkg_index[i].id == id)
pos = i; pos = i;
if (pos == -1) { if (pos == -1) {
/* add to index */ /* add to index */
if (++inpkg_index_pos >= PKG_IN_INDEX_NUM) if (++inpkg_index_pos >= PKG_IN_INDEX_NUM)
@ -1397,6 +1403,16 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
}; };
/* delete all old pkg indexes about a player */
void
inpkg_delplayer (int pl_nr) {
int i;
for (i = 0; i < PKG_IN_INDEX_NUM; i++)
if (inpkg_index[i].pl_nr == pl_nr) inpkg_index[i].pl_nr = -1;
}
/* sends the packet and if PKGF_ackreq is set add packet to the resendcache */ /* sends the packet and if PKGF_ackreq is set add packet to the resendcache */
void void
send_pkg (struct pkg *packet, _net_addr * addr) send_pkg (struct pkg *packet, _net_addr * addr)
@ -1427,15 +1443,11 @@ fwd_pkg (struct pkg *packet, _net_addr * addr)
if (GT_MP_PTPS) /* clients don't forward anything */ if (GT_MP_PTPS) /* clients don't forward anything */
return; return;
if (packet->h.typ == PKG_field || packet->h.typ == PKG_playerdata if (packet->h.typ <= PKG_quit)
|| packet->h.typ == PKG_playermove || packet->h.typ == PKG_ill for (pl = 0; pl < MAX_PLAYERS; pl++)
|| packet->h.typ == PKG_bombdata || packet->h.typ == PKG_chat
|| packet->h.typ == PKG_special)
for (pl = 1; pl < MAX_PLAYERS; pl++)
if ((!PS_IS_aiplayer (players[pl].state)) && PS_IS_netplayer (players[pl].state) if ((!PS_IS_aiplayer (players[pl].state)) && PS_IS_netplayer (players[pl].state)
&& ((players[pl].net.flags & NETF_firewall) == NETF_firewall && (players[addr->pl_nr].net.flags & NETF_firewall) == NETF_firewall
|| (players[addr->pl_nr].net.flags & NETF_firewall) == && pl != addr->pl_nr)
NETF_firewall) && pl != addr->pl_nr)
send_pkg (packet, &players[pl].net.addr); send_pkg (packet, &players[pl].net.addr);
}; };
@ -1452,8 +1464,10 @@ do_pkg (struct pkg *packet, _net_addr * addr)
d_printf ("do_pkg: packet comes from the wrong network type\n"); d_printf ("do_pkg: packet comes from the wrong network type\n");
return 0; return 0;
} }
/* get the addr and set the ping timeout value */ /* get the addr and set the ping timeout value */
addr->pl_nr = get_player_nr (addr->host, addr->port); addr->pl_nr = get_player_nr (addr->host, addr->port);
if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) {
players[addr->pl_nr].net.timestamp = timestamp; players[addr->pl_nr].net.timestamp = timestamp;
players[addr->pl_nr].net.pingreq = players[addr->pl_nr].net.pingack + 5; players[addr->pl_nr].net.pingreq = players[addr->pl_nr].net.pingack + 5;
@ -1464,19 +1478,16 @@ do_pkg (struct pkg *packet, _net_addr * addr)
/* check the packet with the index */ /* check the packet with the index */
if (inpkg_check (packet->h.typ, NTOH16 (packet->h.id), addr) != -1) { if (inpkg_check (packet->h.typ, NTOH16 (packet->h.id), addr) != -1) {
/* we have got this packet already */ /* we have got this packet already */
d_printf ("do_pkg: double packet ignoring\n"); 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) if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
players[addr->pl_nr].net.pkgopt.to_2sec++; players[addr->pl_nr].net.pkgopt.to_2sec++;
return 0; return 0;
} }
/* check if the incoming packet have the right size */
if (packet->h.typ == PKG_servermode && NTOH16 (packet->h.len) != sizeof (struct pkg_servermode))
send_error (addr, "pkg_servermode: packetsize incorrect.");
/* forward packet */ /* forward packet */
if (GT_MP_PTPM) if (GT_MP_PTPM)
fwd_pkg (packet, addr); fwd_pkg (packet, addr);
}
switch (packet->h.typ) { switch (packet->h.typ) {
case (PKG_error): case (PKG_error):

Loading…
Cancel
Save