network changes, dynamic send_to is now set for everyplayer seperatly

origin
stpohle 23 years ago
parent 44fd59ac92
commit 00c7550014

@ -9,11 +9,6 @@
#define GAME_SPECIAL_ITEMSHOE 15 #define GAME_SPECIAL_ITEMSHOE 15
#define GAME_SPECIAL_ITEMDEATH 25 #define GAME_SPECIAL_ITEMDEATH 25
#define PKG_RESENDCACHE_SIZE (64*1024)
#define PKG_IN_INDEX_NUM 256
#define RESENDCACHE_TIMEOUT 500
#define RESENDCACHE_RETRY 10
#define START_BOMBS 1 #define START_BOMBS 1
#define START_RANGE 2 #define START_RANGE 2
#define START_SPEED 16 #define START_SPEED 16

@ -81,8 +81,12 @@ game_draw_info ()
redraw_logo (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.res.y); redraw_logo (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.res.y);
for (x = 0; x < bman.fieldsize.x; x++) for (x = 0; x < bman.fieldsize.x; x++)
draw_stone (x, bman.fieldsize.y-1); draw_stone (x, bman.fieldsize.y-1);
sprintf (text, "Net Option: %2d", bman.net_pkgsend_set);
draw_text (0, gfx.res.y - gfx.font.size.y, text, 1); sprintf (text, "Net Option: ");
for (i = 0 ; i < MAX_PLAYERS; i++)
sprintf (text, " %3d ", bman.players[i].net.pkgopt.send_set);
draw_text (0, gfx.res.y - gfx.font.size.y, text, 1);
gfx_AddUpdateRect (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.font.size.y); gfx_AddUpdateRect (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.font.size.y);
if (chat.visible == 0) { if (chat.visible == 0) {

@ -8,9 +8,6 @@
#include "packets.h" #include "packets.h"
#include "gfx.h" #include "gfx.h"
int _net_to_2sec = 0;
Uint32 _net_to_timestamp = 0;
int int
network_server_port (char *server, char *host, int hostlen, char *port, int portlen) network_server_port (char *server, char *host, int hostlen, char *port, int portlen)
{ {
@ -58,25 +55,27 @@ network_server_port (char *server, char *host, int hostlen, char *port, int port
void void
net_dyn_pkgoption () net_dyn_pkgoption ()
{ {
if (_net_to_2sec > DYN_PKG_MAX_MISSING) { int p;
if (bman.net_pkgsend_set < 10) { _net_pkgopt *npkg;
bman.net_pkgsend_set++;
d_printf ("bman.netpkgsend is set to %d\n", bman.net_pkgsend_set); for (p = 0; p < MAX_PLAYERS; p++)
} if (PS_IS_netplayer (bman.players[p].state)) {
else npkg = &bman.players[p].net.pkgopt;
d_printf ("WARNING: bman.netpkgsend is already at 10\n");
_net_to_2sec = 0; if (npkg->to_2sec > DYN_PKG_MAX_MISSING) {
_net_to_timestamp = timestamp; if (npkg->send_set < 10)
} npkg->send_set++;
npkg->to_2sec = 0;
npkg->to_timestamp = timestamp;
}
if ((timestamp - _net_to_timestamp > 2000) && _net_to_2sec == 0) { if ((timestamp - npkg->to_timestamp > 2000) && npkg->to_2sec <= DYN_PKG_MIN_MISSING) {
if (bman.net_pkgsend_set > 2) { if (npkg->send_set > PKG_SENDSETOPT)
bman.net_pkgsend_set--; npkg->send_set--;
d_printf ("bman.netpkgsend is set to %d\n", bman.net_pkgsend_set); npkg->to_2sec = 0;
npkg->to_timestamp = timestamp;
}
} }
_net_to_2sec = 0;
_net_to_timestamp = timestamp;
}
}; };
@ -285,7 +284,7 @@ network_loop ()
} }
} }
/* /*
resend_cache.... resend_cache....
*/ */
rscache_loop (); rscache_loop ();
@ -295,12 +294,6 @@ network_loop ()
*/ */
net_dyn_pkgoption (); net_dyn_pkgoption ();
/* what we need to do for the network packet send control */
if (bman.net_pkgsend_to <= 0 || bman.net_pkgsend_to > bman.net_pkgsend_set)
bman.net_pkgsend_to = bman.net_pkgsend_set;
bman.net_pkgsend_to--;
return 0; return 0;
}; };
@ -528,7 +521,8 @@ net_new_gamedata ()
/* player is only watching so just go after we have got everything /* player is only watching so just go after we have got everything
go to show the field */ go to show the field */
if (GT_MP_PTPS && bman.state == GS_update && net_istep == 0 && bman.players[bman.p_nr].gfx_nr == -1) { if (GT_MP_PTPS && bman.state == GS_update && net_istep == 0
&& bman.players[bman.p_nr].gfx_nr == -1) {
done = 1; done = 1;
bman.state = GS_running; bman.state = GS_running;
} }
@ -636,8 +630,8 @@ net_delplayer (int pl_nr)
} }
} }
if (GT_MP_PTPS && pl_nr == 0) /* masterserver quit */ if (GT_MP_PTPS && pl_nr == 0) /* masterserver quit */
bman.state = GS_startup; bman.state = GS_startup;
if (GT_MP_PTPM && bman.notifygamemaster) if (GT_MP_PTPM && bman.notifygamemaster)
gamesrv_sendmode (bman.maxplayer, bman.players_nr_s); gamesrv_sendmode (bman.maxplayer, bman.players_nr_s);

@ -6,8 +6,14 @@ network.h file... for everything what have to do with the network stuff
#define _NETWORK_H_ #define _NETWORK_H_
#define MAX_UDPDATA 1024 #define MAX_UDPDATA 1024
#define PKG_RESENDCACHE_SIZE (64*1024)
#define PKG_IN_INDEX_NUM 256
#define RESENDCACHE_TIMEOUT 500
#define RESENDCACHE_RETRY 10
#define DOWNLOAD_TIMEOUT 2000 #define DOWNLOAD_TIMEOUT 2000
#define DYN_PKG_MAX_MISSING 4 #define DYN_PKG_MAX_MISSING 4
#define DYN_PKG_MIN_MISSING 1
#define PKG_SENDSETOPT 2
#define GT_MP_PTPM (bman.multitype == MT_ptpm && bman.gametype == GT_multi) #define GT_MP_PTPM (bman.multitype == MT_ptpm && bman.gametype == GT_multi)
#define GT_MP_PTPS (bman.multitype == MT_ptps && bman.gametype == GT_multi) #define GT_MP_PTPS (bman.multitype == MT_ptps && bman.gametype == GT_multi)
@ -25,9 +31,18 @@ struct __net_addr { // this holds the network data
char host[LEN_SERVERNAME]; char host[LEN_SERVERNAME];
char port[LEN_PORT]; char port[LEN_PORT];
struct _sockaddr sAddr; struct _sockaddr sAddr;
signed char pl_nr; // pl_nr so we know it in the pkgcahce.
} typedef _net_addr; } typedef _net_addr;
struct __net_pkgopt { /* this will hold all needed data for the packet
timeout function */
signed char send_to; // sending packet data (playermove) on 0 it will be send
signed char send_set; // start value for the packet data option (dynamic set)
int to_2sec; // how many unreached packets was send
Uint32 to_timestamp;
} typedef _net_pkgopt;
struct __net_player { struct __net_player {
_net_addr addr; // holds the address _net_addr addr; // holds the address
int pingreq; // just to send a ping and to save the number in here int pingreq; // just to send a ping and to save the number in here
@ -35,12 +50,10 @@ struct __net_player {
Uint32 timestamp; // time of the last incoming package Uint32 timestamp; // time of the last incoming package
signed char net_istep; signed char net_istep;
signed char net_status; signed char net_status;
_net_pkgopt pkgopt; // packet and network controll data
} typedef _net_player; } typedef _net_player;
extern int _net_to_2sec;
extern Uint32 _net_to_timestamp;
// network menu // network menu
extern void netmenu(); extern void netmenu();
extern void networkmenu_joingame (); extern void networkmenu_joingame ();

@ -7,10 +7,8 @@
#include "packets.h" #include "packets.h"
#include "chat.h" #include "chat.h"
extern int condata[MAX_PLAYERS][MAX_PLAYERS];
extern _point debug_field; extern _point debug_field;
extern int debug_lastping; extern int debug_lastping;
extern void print_condata ();
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];
@ -69,7 +67,6 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
{ {
_player *pl; _player *pl;
int i, int i,
pl_nr,
j, j,
vma, vma,
vmi, vmi,
@ -78,18 +75,17 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu); sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu);
pl_nr = get_player_nr (addr->host, addr->port);
if (p_id->ver_sub != vsu || p_id->ver_major != vma || p_id->ver_minor != vmi) { if (p_id->ver_sub != vsu || p_id->ver_major != vma || p_id->ver_minor != vmi) {
sprintf (text, "Version Error - Host/Server Version: %s", VERSION); sprintf (text, "Version Error - Host/Server Version: %s", VERSION);
send_error (addr, text); send_error (addr, text);
return; return;
} }
d_printf ("do_playerid (From:%s:%s pl_nr=%d) Player(name:%s [%s:%s], pl_nr:%d)\n", addr->host, d_printf ("do_playerid (From:%s:%s pl_nr=%d) Player(name:%s [%s:%s], pl_nr:%d)\n", addr->host,
addr->port, pl_nr, p_id->name, p_id->host, p_id->port, p_id->pl_nr); addr->port, addr->pl_nr, p_id->name, p_id->host, p_id->port, p_id->pl_nr);
/* As Server/Master Only change settings, or do ignore them if we are not in GS_wait */ /* As Server/Master Only change settings, or do ignore them if we are not in GS_wait */
if (((GT_MP_PTPM && (bman.state == GS_wait && pl_nr != -1)) || // PTPM change setting if (((GT_MP_PTPM && (bman.state == GS_wait && addr->pl_nr != -1)) || // PTPM change setting
(GT_MP_PTPS && pl_nr == 0)) && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS) { // PTPS and information send by PTPM (GT_MP_PTPS && addr->pl_nr == 0)) && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS) { // PTPS and information send by PTPM
pl = &bman.players[p_id->pl_nr]; pl = &bman.players[p_id->pl_nr];
@ -105,6 +101,7 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
pl->net.pingreq = pl->net.pingack + 5; pl->net.pingreq = pl->net.pingack + 5;
if (p_id->host[0] != 0) { if (p_id->host[0] != 0) {
pl->net.addr.pl_nr = addr->pl_nr;
strncpy (pl->net.addr.host, p_id->host, LEN_SERVERNAME); strncpy (pl->net.addr.host, p_id->host, LEN_SERVERNAME);
strncpy (pl->net.addr.port, p_id->port, LEN_PORT); strncpy (pl->net.addr.port, p_id->port, LEN_PORT);
dns_filladdr (pl->net.addr.host, LEN_SERVERNAME, dns_filladdr (pl->net.addr.host, LEN_SERVERNAME,
@ -118,13 +115,13 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
} }
/* add player into the list if there is something free */ /* add player into the list if there is something free */
else if ((pl_nr == -1 || p_id->pl_nr == -1) && GS_WAITRUNNING && GT_MP_PTPM) { else if ((addr->pl_nr == -1 || p_id->pl_nr == -1) && GS_WAITRUNNING && GT_MP_PTPM) {
/* find free player slot */ /* find free player slot */
if (pl_nr == -1) if (addr->pl_nr == -1)
for (i = 0; (i < MAX_PLAYERS && PS_IS_used (bman.players[i].state)); i++); for (i = 0; (i < MAX_PLAYERS && PS_IS_used (bman.players[i].state)); i++);
else else
i = pl_nr; i = addr->pl_nr;
if ((i < MAX_PLAYERS) && (i < bman.maxplayer)) { if ((i < MAX_PLAYERS) && (i < bman.maxplayer)) {
/* free in_pl slot ... fill in data */ /* free in_pl slot ... fill in data */
@ -140,11 +137,19 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
} }
strncpy (pl->name, p_id->name, LEN_PLAYERNAME); strncpy (pl->name, p_id->name, LEN_PLAYERNAME);
player_set_gfx (pl, p_id->gfx_nr); player_set_gfx (pl, p_id->gfx_nr);
/* Reset the network data */
pl->net.timestamp = timestamp; pl->net.timestamp = timestamp;
pl->net.pkgopt.to_timestamp = timestamp;
pl->net.pkgopt.to_2sec = 0;
pl->net.pkgopt.send_to = 0;
pl->net.pkgopt.send_set = PKG_SENDSETOPT;
strncpy (pl->net.addr.host, addr->host, LEN_SERVERNAME); strncpy (pl->net.addr.host, addr->host, LEN_SERVERNAME);
strncpy (pl->net.addr.port, addr->port, LEN_PORT); strncpy (pl->net.addr.port, addr->port, LEN_PORT);
dns_filladdr (pl->net.addr.host, LEN_SERVERNAME, pl->net.addr.port, LEN_PORT, dns_filladdr (pl->net.addr.host, LEN_SERVERNAME, pl->net.addr.port, LEN_PORT,
bman.net_ai_family, &pl->net.addr.sAddr); bman.net_ai_family, &pl->net.addr.sAddr);
pl->net.addr.pl_nr = i;
bman.players_nr_s++; bman.players_nr_s++;
/* send to the new client the servermode and the complete playerlist */ /* send to the new client the servermode and the complete playerlist */
@ -154,7 +159,7 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
send_playerid (addr, bman.players[j].name, bman.players[j].net.addr.host, send_playerid (addr, bman.players[j].name, bman.players[j].net.addr.host,
bman.players[j].net.addr.port, j, bman.players[j].gfx_nr); bman.players[j].net.addr.port, j, bman.players[j].gfx_nr);
pl_nr = i; addr->pl_nr = i;
for (j = 0, i = 0; i < bman.maxplayer; i++) for (j = 0, i = 0; i < bman.maxplayer; i++)
if (PS_IS_used (bman.players[i].state)) if (PS_IS_used (bman.players[i].state))
j++; j++;
@ -173,8 +178,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
} }
/* Send all connected players the new PlayerID */ /* Send all connected players the new PlayerID */
if (GS_WAITRUNNING && pl_nr >= 0 && pl_nr < MAX_PLAYERS) if (GS_WAITRUNNING && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
net_change_playerid (pl_nr, (GT_MP_PTPM)); net_change_playerid (addr->pl_nr, (GT_MP_PTPM));
d_playerdetail ("*** PLAYER List ***"); d_playerdetail ("*** PLAYER List ***");
}; };
@ -230,15 +235,9 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport, int pl_
void void
do_servermode (struct pkg_servermode *s_mod, _net_addr * addr) do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
{ {
int pl_nr; if (addr->pl_nr == -1)
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
d_printf ("do_servermode (%s:%s) state = %d\n", addr->host, addr->port, s_mod->state); d_printf ("do_servermode (%s:%s) state = %d\n", addr->host, addr->port, s_mod->state);
if (s_mod->pl_nr >= 0 && s_mod->pl_nr < MAX_PLAYERS) { if (s_mod->pl_nr >= 0 && s_mod->pl_nr < MAX_PLAYERS) {
@ -313,13 +312,8 @@ send_field (_net_addr * addr, int x, int y, _field * field)
void void
do_field (struct pkg_field *f_dat, _net_addr * addr) do_field (struct pkg_field *f_dat, _net_addr * addr)
{ {
int pl_nr; if (addr->pl_nr == -1)
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
if (f_dat->x < bman.fieldsize.x && f_dat->y < bman.fieldsize.y) { if (f_dat->x < bman.fieldsize.x && f_dat->y < bman.fieldsize.y) {
memcpy (&bman.field[f_dat->x][f_dat->y], &f_dat->field, sizeof (_field)); memcpy (&bman.field[f_dat->x][f_dat->y], &f_dat->field, sizeof (_field));
@ -338,24 +332,19 @@ do_field (struct pkg_field *f_dat, _net_addr * addr)
void void
do_ping (struct pkg_ping *p_dat, _net_addr * addr) do_ping (struct pkg_ping *p_dat, _net_addr * addr)
{ {
int pl_nr; if (addr->pl_nr == -1)
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1) /* Make sure we will never send to unknown players */
return; return;
if (p_dat->h.typ == PKG_pingack) if (p_dat->h.typ == PKG_pingack)
/* ping was an answer */ /* ping was an answer */
bman.players[pl_nr].net.pingack = p_dat->data; bman.players[addr->pl_nr].net.pingack = p_dat->data;
else else
/* send the answer */ /* send the answer */
send_ping (addr, p_dat->data, PKG_pingack); send_ping (addr, p_dat->data, PKG_pingack);
d_printf ("do_ping pl_nr[%d] (%s:%s) req=%d, ack=%d, timediff=%d\n", pl_nr, addr->host, d_printf ("do_ping pl_nr[%d] (%s:%s) req=%d, ack=%d\n", addr->pl_nr, addr->host,
addr->port, bman.players[pl_nr].net.pingreq, bman.players[pl_nr].net.pingack, addr->port, bman.players[addr->pl_nr].net.pingreq, bman.players[addr->pl_nr].net.pingack);
timestamp - bman.players[pl_nr].net.timestamp);
bman.players[pl_nr].net.timestamp = timestamp;
}; };
@ -363,11 +352,8 @@ void
send_ping (_net_addr * addr, int data, unsigned char typ) send_ping (_net_addr * addr, int data, unsigned char typ)
{ {
struct pkg_ping p_dat; struct pkg_ping p_dat;
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1) if (addr->pl_nr == -1)
return; return;
p_dat.h.len = sizeof (struct pkg_ping); p_dat.h.len = sizeof (struct pkg_ping);
@ -385,9 +371,11 @@ send_ping (_net_addr * addr, int data, unsigned char typ)
send_pkg ((struct pkg *) &p_dat, addr); send_pkg ((struct pkg *) &p_dat, addr);
} }
d_printf ("send_ping Player[%d] (%s:%s) req=%d, ack=%d\n", pl_nr, addr->host, addr->port, d_printf ("send_ping Player[%d] (%s:%s) req=%d, ack=%d\n", addr->pl_nr, addr->host, addr->port,
bman.players[pl_nr].net.pingreq, bman.players[pl_nr].net.pingack); bman.players[addr->pl_nr].net.pingreq, bman.players[addr->pl_nr].net.pingack);
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[addr->pl_nr].net.timestamp = timestamp; /* we need to set it here, so we can check
for the timeout again */
}; };
@ -425,19 +413,14 @@ void
do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr) do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
{ {
_player *pl; _player *pl;
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port); if (addr->pl_nr == -1)
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
if (p_dat->p_nr < 0 || p_dat->p_nr >= MAX_PLAYERS) if (p_dat->p_nr < 0 || p_dat->p_nr >= MAX_PLAYERS)
return; return;
d_printf ("do_playerdata (From: %d) p_nr: %d\n", pl_nr, p_dat->p_nr); d_printf ("do_playerdata (From: %d) p_nr: %d\n", addr->pl_nr, p_dat->p_nr);
pl = &bman.players[p_dat->p_nr]; pl = &bman.players[p_dat->p_nr];
player_set_gfx (pl, p_dat->gfx_nr); player_set_gfx (pl, p_dat->gfx_nr);
@ -512,16 +495,12 @@ send_playermove (_net_addr * addr, int p_nr, _player * pl)
void void
do_ill (struct pkg_ill *ill, _net_addr * addr) do_ill (struct pkg_ill *ill, _net_addr * addr)
{ {
int pl_nr, int i;
i;
pl_nr = get_player_nr (addr->host, addr->port); if (addr->pl_nr == -1)
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
d_printf ("do_ill (From: %d) For Player %d\n", pl_nr, ill->pl_nr); d_printf ("do_ill (From: %d) For Player %d\n", addr->pl_nr, ill->pl_nr);
if (ill->pl_nr < 0 || ill->pl_nr >= MAX_PLAYERS || ill->pl_nr == bman.p_nr) if (ill->pl_nr < 0 || ill->pl_nr >= MAX_PLAYERS || ill->pl_nr == bman.p_nr)
return; return;
@ -553,23 +532,18 @@ void
do_playermove (struct pkg_playermove *p_dat, _net_addr * addr) do_playermove (struct pkg_playermove *p_dat, _net_addr * addr)
{ {
_player *pl; _player *pl;
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port); if (addr->pl_nr == -1)
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
if (p_dat->p_nr == -1) if (p_dat->p_nr == -1)
return; return;
/* check if the right player is sending the information */ /* check if the right player is sending the information */
pl = &bman.players[p_dat->p_nr]; pl = &bman.players[p_dat->p_nr];
if (pl_nr != 0 && pl_nr != p_dat->p_nr) if (addr->pl_nr != 0 && addr->pl_nr != p_dat->p_nr)
return; return;
// pl->old = pl->pos;
pl->m = p_dat->m; pl->m = p_dat->m;
pl->d = p_dat->d; pl->d = p_dat->d;
pl->speed = p_dat->speed; pl->speed = p_dat->speed;
@ -582,13 +556,9 @@ void
do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr) do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
{ {
_bomb *bomb; _bomb *bomb;
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port); if (addr->pl_nr == -1)
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
if (b_dat->p_nr >= MAX_PLAYERS || b_dat->b_nr >= MAX_BOMBS) { if (b_dat->p_nr >= MAX_PLAYERS || b_dat->b_nr >= MAX_BOMBS) {
d_printf ("Bomb Error\n"); d_printf ("Bomb Error\n");
@ -675,25 +645,19 @@ send_quit (_net_addr * addr, char *plhost, char *plport)
void void
do_quit (struct pkg_quit *q_dat, _net_addr * addr) do_quit (struct pkg_quit *q_dat, _net_addr * addr)
{ {
int pl_nr; d_printf ("do_quit (%s:%s) pl_nr = %d\n", addr->host, addr->port, addr->pl_nr);
if (addr->pl_nr == -1)
pl_nr = get_player_nr (addr->host, addr->port);
d_printf ("do_quit (%s:%s) pl_nr = %d\n", addr->host, addr->port, pl_nr);
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
if (q_dat->host[0] == 0)
if (q_dat->host[0] == 0) {
/* the player who send this quit */ /* the player who send this quit */
net_delplayer (pl_nr); net_delplayer (addr->pl_nr);
}
else { else {
pl_nr = get_player_nr (q_dat->host, q_dat->port); /* delete the player with the giving address */
int pl_nr = get_player_nr (q_dat->host, q_dat->port);
if (pl_nr == -1) if (pl_nr == -1)
return; return;
net_delplayer (pl_nr); net_delplayer (pl_nr);
} }
}; };
@ -715,21 +679,16 @@ send_getfield (_net_addr * addr, int line)
void void
do_getfield (struct pkg_getfield *gf_dat, _net_addr * addr) do_getfield (struct pkg_getfield *gf_dat, _net_addr * addr)
{ {
int pl_nr; if (addr->pl_nr == -1)
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
if (gf_dat->line < 0 || gf_dat->line >= MAX_FIELDSIZE_Y) if (gf_dat->line < 0 || gf_dat->line >= MAX_FIELDSIZE_Y)
return; return;
if (pl_nr != -1 && bman.state == GS_update && GT_MP_PTPM) { if (addr->pl_nr != -1 && bman.state == GS_update && GT_MP_PTPM) {
if (pl_nr > 0 && pl_nr < MAX_PLAYERS) { if (addr->pl_nr > 0 && addr->pl_nr < MAX_PLAYERS) {
bman.players[pl_nr].net.net_status = gf_dat->line; bman.players[addr->pl_nr].net.net_status = gf_dat->line;
bman.players[pl_nr].net.net_istep = 2; bman.players[addr->pl_nr].net.net_istep = 2;
} }
} }
@ -769,16 +728,12 @@ send_fieldline (_net_addr * addr, int line)
void void
do_fieldline (struct pkg_fieldline *f_dat, _net_addr * addr) do_fieldline (struct pkg_fieldline *f_dat, _net_addr * addr)
{ {
int pl_nr, int i;
i;
pl_nr = get_player_nr (addr->host, addr->port); if (addr->pl_nr == -1)
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
if (pl_nr != 0) { if (addr->pl_nr != 0) {
/* the data we have got are not from the server */ /* the data we have got are not from the server */
d_printf ("do_fieldline: the data we have got are not from the server\n"); d_printf ("do_fieldline: the data we have got are not from the server\n");
return; return;
@ -815,21 +770,16 @@ send_getplayerdata (_net_addr * addr, int pl)
void void
do_getplayerdata (struct pkg_getplayerdata *gp_dat, _net_addr * addr) do_getplayerdata (struct pkg_getplayerdata *gp_dat, _net_addr * addr)
{ {
int pl_nr; if (addr->pl_nr == -1)
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
return; return;
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
if (gp_dat->pl_nr < 0 || gp_dat->pl_nr >= MAX_PLAYERS) if (gp_dat->pl_nr < 0 || gp_dat->pl_nr >= MAX_PLAYERS)
return; return;
if (pl_nr != -1 && bman.state == GS_update && GT_MP_PTPM) { if (addr->pl_nr != -1 && bman.state == GS_update && GT_MP_PTPM) {
if (pl_nr > 0 && pl_nr < MAX_PLAYERS) { if (addr->pl_nr > 0 && addr->pl_nr < MAX_PLAYERS) {
bman.players[pl_nr].net.net_status = gp_dat->pl_nr; bman.players[addr->pl_nr].net.net_status = gp_dat->pl_nr;
bman.players[pl_nr].net.net_istep = 1; bman.players[addr->pl_nr].net.net_istep = 1;
} }
} }
send_playerdata (addr, gp_dat->pl_nr, &bman.players[gp_dat->pl_nr]); send_playerdata (addr, gp_dat->pl_nr, &bman.players[gp_dat->pl_nr]);
@ -839,16 +789,11 @@ do_getplayerdata (struct pkg_getplayerdata *gp_dat, _net_addr * addr)
void void
do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr) do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr)
{ {
int pl_nr, int i;
i;
pl_nr = get_player_nr (addr->host, addr->port);
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
d_printf ("do_playerstatus (%s,%s)\n", addr->host, addr->port); d_printf ("do_playerstatus (%s,%s)\n", addr->host, addr->port);
if (pl_nr != 0 && !(GT_MP_PTPM)) { if (addr->pl_nr != 0 && !(GT_MP_PTPM)) {
/* the data we have got are not from the server */ /* the data we have got are not from the server */
d_printf ("do_playerstatus: the data we have got are not from the server\n"); d_printf ("do_playerstatus: the data we have got are not from the server\n");
return; return;
@ -860,8 +805,8 @@ do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr)
return; return;
} }
bman.players[pl_nr].net.net_status = stat->status; bman.players[addr->pl_nr].net.net_status = stat->status;
bman.players[pl_nr].net.net_istep = stat->net_istep; bman.players[addr->pl_nr].net.net_istep = stat->net_istep;
if (GT_MP_PTPM) if (GT_MP_PTPM)
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
if (bman.players[i].net.addr.host[0] != 0) if (bman.players[i].net.addr.host[0] != 0)
@ -892,12 +837,6 @@ send_playerstatus (_net_addr * addr, int pl_nr, int net_istep, int status)
void void
do_chat (struct pkg_chat *chat_pkg, _net_addr * addr) do_chat (struct pkg_chat *chat_pkg, _net_addr * addr)
{ {
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
chat_addline (chat_pkg->text); chat_addline (chat_pkg->text);
if (GT_MP_PTPM && bman.notifygamemaster) /* send notification the the gamemaster */ if (GT_MP_PTPM && bman.notifygamemaster) /* send notification the the gamemaster */
@ -941,16 +880,10 @@ send_pkgack (_net_addr * addr, unsigned char typ, short int id)
void void
do_pkgack (struct pkg_pkgack *p_ack, _net_addr * addr) do_pkgack (struct pkg_pkgack *p_ack, _net_addr * addr)
{ {
int pl_nr;
d_printf ("do_pkgack (%s:%s)\n", addr->host, addr->port); d_printf ("do_pkgack (%s:%s)\n", addr->host, addr->port);
if (rscache_getpos (addr, p_ack->typ, p_ack->id) == -1) if (rscache_getpos (addr, p_ack->typ, p_ack->id) == -1)
return; return;
pl_nr = get_player_nr (addr->host, addr->port);
bman.players[pl_nr].net.timestamp = timestamp;
bman.players[pl_nr].net.pingreq = bman.players[pl_nr].net.pingack + 5;
rscache_del (); rscache_del ();
}; };
@ -974,8 +907,7 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
/* 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 (strncmp (inpkg_index[i].addr.host, addr->host, LEN_SERVERNAME) == 0 && if (inpkg_index[i].pl_nr == addr->pl_nr &&
strncmp (inpkg_index[i].addr.port, addr->port, LEN_PORT) == 0 &&
inpkg_index[i].typ == typ && inpkg_index[i].id == id) inpkg_index[i].typ == typ && inpkg_index[i].id == id)
pos = i; pos = i;
@ -983,7 +915,8 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
/* packet unknown ... add to index */ /* packet unknown ... add to index */
if (++inpkg_index_pos >= PKG_IN_INDEX_NUM) if (++inpkg_index_pos >= PKG_IN_INDEX_NUM)
inpkg_index_pos = 0; inpkg_index_pos = 0;
memcpy (&inpkg_index[inpkg_index_pos].addr, addr, sizeof (_net_addr));
inpkg_index[inpkg_index_pos].pl_nr = addr->pl_nr;
inpkg_index[inpkg_index_pos].typ = typ; inpkg_index[inpkg_index_pos].typ = typ;
inpkg_index[inpkg_index_pos].id = id; inpkg_index[inpkg_index_pos].id = id;
} }
@ -1018,7 +951,12 @@ do_pkg (struct pkg *packet, _net_addr * addr)
packet->h.typ != PKG_bcmservchat) { packet->h.typ != PKG_bcmservchat) {
d_printf ("-----packet comes from the wrong network type\n"); d_printf ("-----packet comes from the wrong network type\n");
return 0; return 0;
} }
/* get the addr and set the ping timeout value */
addr->pl_nr = get_player_nr (addr->host, addr->port);
bman.players[addr->pl_nr].net.timestamp = timestamp;
bman.players[addr->pl_nr].net.pingreq = bman.players[addr->pl_nr].net.pingack + 5;
/* test if we have any important packet */ /* test if we have any important packet */
if (packet->h.flags & PKGF_ackreq && packet->h.typ != PKG_bcmservchat) if (packet->h.flags & PKGF_ackreq && packet->h.typ != PKG_bcmservchat)
@ -1028,7 +966,8 @@ do_pkg (struct pkg *packet, _net_addr * addr)
if (packet->h.typ != PKG_bcmservchat && inpkg_check (packet->h.typ, packet->h.id, addr) != -1) { if (packet->h.typ != PKG_bcmservchat && inpkg_check (packet->h.typ, packet->h.id, addr) != -1) {
/* we have got this packet already */ /* we have got this packet already */
d_printf ("-----packet ignored\n"); d_printf ("-----packet ignored\n");
_net_to_2sec++; if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
bman.players[addr->pl_nr].net.pkgopt.to_2sec++;
return 0; return 0;
} }

@ -198,6 +198,7 @@ struct pkg_chat {
struct _rscache_entry { struct _rscache_entry {
signed char pl_nr; // playernumber to whom this data should go
short int len; // size of the entry short int len; // size of the entry
Uint32 timestamp; // pointer to the timestamp Uint32 timestamp; // pointer to the timestamp
signed char retry; // retry's how many times we tryed this signed char retry; // retry's how many times we tryed this
@ -214,7 +215,7 @@ struct _resend_cache {
struct _inpkg_index { struct _inpkg_index {
_net_addr addr; signed char pl_nr;
unsigned char typ; unsigned char typ;
short int id; short int id;
}; };

@ -141,7 +141,8 @@ rscache_loop ()
bman.net_ai_family); bman.net_ai_family);
resend_cache.entry->timestamp = timestamp; resend_cache.entry->timestamp = timestamp;
resend_cache.entry->retry++; resend_cache.entry->retry++;
_net_to_2sec++; if (resend_cache.entry->addr.pl_nr >= 0 && resend_cache.entry->addr.pl_nr < MAX_PLAYERS)
bman.players[resend_cache.entry->addr.pl_nr].net.pkgopt.to_2sec++;
} }
if (timestamp - resend_cache.entry->timestamp >= timeout if (timestamp - resend_cache.entry->timestamp >= timeout
@ -149,8 +150,10 @@ rscache_loop ()
d_printf ("Data Send Timeout (%s:%s) Delete now Package Fill %d, Pos %d\n", d_printf ("Data Send Timeout (%s:%s) Delete now Package Fill %d, Pos %d\n",
resend_cache.entry->addr.host, resend_cache.entry->addr.port, resend_cache.entry->addr.host, resend_cache.entry->addr.port,
resend_cache.fill, pos); resend_cache.fill, pos);
if (resend_cache.entry->addr.pl_nr >= 0 && resend_cache.entry->addr.pl_nr < MAX_PLAYERS)
bman.players[resend_cache.entry->addr.pl_nr].net.pkgopt.to_2sec++;
rscache_del (); rscache_del ();
_net_to_2sec++;
} }
else else
pos = pos + len; pos = pos + len;

@ -255,11 +255,17 @@ move_player ()
p->speed = speed; p->speed = speed;
} }
if (bman.gametype != GT_single && (bman.net_pkgsend_to == 0 || p->old_m == 0)) /* network packet send control - send data if it's time to send or if we need to */
if (bman.gametype != GT_single && (p->net.pkgopt.send_to == 0 || p->old_m == 0))
net_game_send_playermove (bman.p_nr); net_game_send_playermove (bman.p_nr);
/* network packet send control */
if (p->net.pkgopt.send_to <= 0 || p->net.pkgopt.send_to > p->net.pkgopt.send_set)
p->net.pkgopt.send_to = p->net.pkgopt.send_set;
p->net.pkgopt.send_to--;
} }
/* the player stopt moving so send data */ /* the player just stopt moving so send data */
if (bman.gametype != GT_single && p->m == 0 && p->old_m != 0) if (bman.gametype != GT_single && p->m == 0 && p->old_m != 0)
net_game_send_playermove (bman.p_nr); net_game_send_playermove (bman.p_nr);

Loading…
Cancel
Save