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_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_RANGE 2
#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);
for (x = 0; x < bman.fieldsize.x; x++)
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);
if (chat.visible == 0) {

@ -8,9 +8,6 @@
#include "packets.h"
#include "gfx.h"
int _net_to_2sec = 0;
Uint32 _net_to_timestamp = 0;
int
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
net_dyn_pkgoption ()
{
if (_net_to_2sec > DYN_PKG_MAX_MISSING) {
if (bman.net_pkgsend_set < 10) {
bman.net_pkgsend_set++;
d_printf ("bman.netpkgsend is set to %d\n", bman.net_pkgsend_set);
}
else
d_printf ("WARNING: bman.netpkgsend is already at 10\n");
_net_to_2sec = 0;
_net_to_timestamp = timestamp;
}
int p;
_net_pkgopt *npkg;
for (p = 0; p < MAX_PLAYERS; p++)
if (PS_IS_netplayer (bman.players[p].state)) {
npkg = &bman.players[p].net.pkgopt;
if (npkg->to_2sec > DYN_PKG_MAX_MISSING) {
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 (bman.net_pkgsend_set > 2) {
bman.net_pkgsend_set--;
d_printf ("bman.netpkgsend is set to %d\n", bman.net_pkgsend_set);
if ((timestamp - npkg->to_timestamp > 2000) && npkg->to_2sec <= DYN_PKG_MIN_MISSING) {
if (npkg->send_set > PKG_SENDSETOPT)
npkg->send_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....
*/
rscache_loop ();
@ -295,12 +294,6 @@ network_loop ()
*/
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;
};
@ -528,7 +521,8 @@ net_new_gamedata ()
/* player is only watching so just go after we have got everything
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;
bman.state = GS_running;
}
@ -636,9 +630,9 @@ net_delplayer (int pl_nr)
}
}
if (GT_MP_PTPS && pl_nr == 0) /* masterserver quit */
bman.state = GS_startup;
if (GT_MP_PTPS && pl_nr == 0) /* masterserver quit */
bman.state = GS_startup;
if (GT_MP_PTPM && bman.notifygamemaster)
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 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 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_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 port[LEN_PORT];
struct _sockaddr sAddr;
signed char pl_nr; // pl_nr so we know it in the pkgcahce.
} 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 {
_net_addr addr; // holds the address
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
signed char net_istep;
signed char net_status;
_net_pkgopt pkgopt; // packet and network controll data
} typedef _net_player;
extern int _net_to_2sec;
extern Uint32 _net_to_timestamp;
// network menu
extern void netmenu();
extern void networkmenu_joingame ();

@ -7,10 +7,8 @@
#include "packets.h"
#include "chat.h"
extern int condata[MAX_PLAYERS][MAX_PLAYERS];
extern _point debug_field;
extern int debug_lastping;
extern void print_condata ();
struct _resend_cache resend_cache;
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;
int i,
pl_nr,
j,
vma,
vmi,
@ -78,18 +75,17 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
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) {
sprintf (text, "Version Error - Host/Server Version: %s", VERSION);
send_error (addr, text);
return;
}
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 */
if (((GT_MP_PTPM && (bman.state == GS_wait && 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
if (((GT_MP_PTPM && (bman.state == GS_wait && addr->pl_nr != -1)) || // PTPM change setting
(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];
@ -105,6 +101,7 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
pl->net.pingreq = pl->net.pingack + 5;
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.port, p_id->port, LEN_PORT);
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 */
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 */
if (pl_nr == -1)
if (addr->pl_nr == -1)
for (i = 0; (i < MAX_PLAYERS && PS_IS_used (bman.players[i].state)); i++);
else
i = pl_nr;
i = addr->pl_nr;
if ((i < MAX_PLAYERS) && (i < bman.maxplayer)) {
/* 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);
player_set_gfx (pl, p_id->gfx_nr);
/* Reset the network data */
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.port, 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);
pl->net.addr.pl_nr = i;
bman.players_nr_s++;
/* 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,
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++)
if (PS_IS_used (bman.players[i].state))
j++;
@ -173,8 +178,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
}
/* Send all connected players the new PlayerID */
if (GS_WAITRUNNING && pl_nr >= 0 && pl_nr < MAX_PLAYERS)
net_change_playerid (pl_nr, (GT_MP_PTPM));
if (GS_WAITRUNNING && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
net_change_playerid (addr->pl_nr, (GT_MP_PTPM));
d_playerdetail ("*** PLAYER List ***");
};
@ -230,15 +235,9 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport, int pl_
void
do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
{
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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);
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
do_field (struct pkg_field *f_dat, _net_addr * addr)
{
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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) {
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
do_ping (struct pkg_ping *p_dat, _net_addr * addr)
{
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1) /* Make sure we will never send to unknown players */
if (addr->pl_nr == -1)
return;
if (p_dat->h.typ == PKG_pingack)
/* ping was an answer */
bman.players[pl_nr].net.pingack = p_dat->data;
bman.players[addr->pl_nr].net.pingack = p_dat->data;
else
/* send the answer */
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,
addr->port, bman.players[pl_nr].net.pingreq, bman.players[pl_nr].net.pingack,
timestamp - bman.players[pl_nr].net.timestamp);
bman.players[pl_nr].net.timestamp = timestamp;
d_printf ("do_ping pl_nr[%d] (%s:%s) req=%d, ack=%d\n", addr->pl_nr, addr->host,
addr->port, bman.players[addr->pl_nr].net.pingreq, bman.players[addr->pl_nr].net.pingack);
};
@ -363,11 +352,8 @@ void
send_ping (_net_addr * addr, int data, unsigned char typ)
{
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;
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);
}
d_printf ("send_ping Player[%d] (%s:%s) req=%d, ack=%d\n", pl_nr, addr->host, addr->port,
bman.players[pl_nr].net.pingreq, bman.players[pl_nr].net.pingack);
bman.players[pl_nr].net.timestamp = timestamp;
d_printf ("send_ping Player[%d] (%s:%s) req=%d, ack=%d\n", addr->pl_nr, addr->host, addr->port,
bman.players[addr->pl_nr].net.pingreq, bman.players[addr->pl_nr].net.pingack);
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)
{
_player *pl;
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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)
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];
player_set_gfx (pl, p_dat->gfx_nr);
@ -512,16 +495,12 @@ send_playermove (_net_addr * addr, int p_nr, _player * pl)
void
do_ill (struct pkg_ill *ill, _net_addr * addr)
{
int pl_nr,
i;
int i;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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)
return;
@ -553,23 +532,18 @@ void
do_playermove (struct pkg_playermove *p_dat, _net_addr * addr)
{
_player *pl;
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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)
return;
/* check if the right player is sending the information */
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;
// pl->old = pl->pos;
pl->m = p_dat->m;
pl->d = p_dat->d;
pl->speed = p_dat->speed;
@ -582,13 +556,9 @@ void
do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
{
_bomb *bomb;
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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) {
d_printf ("Bomb Error\n");
@ -675,25 +645,19 @@ send_quit (_net_addr * addr, char *plhost, char *plport)
void
do_quit (struct pkg_quit *q_dat, _net_addr * addr)
{
int pl_nr;
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)
d_printf ("do_quit (%s:%s) pl_nr = %d\n", addr->host, addr->port, addr->pl_nr);
if (addr->pl_nr == -1)
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 */
net_delplayer (pl_nr);
}
net_delplayer (addr->pl_nr);
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)
return;
net_delplayer (pl_nr);
}
};
@ -715,21 +679,16 @@ send_getfield (_net_addr * addr, int line)
void
do_getfield (struct pkg_getfield *gf_dat, _net_addr * addr)
{
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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)
return;
if (pl_nr != -1 && bman.state == GS_update && GT_MP_PTPM) {
if (pl_nr > 0 && pl_nr < MAX_PLAYERS) {
bman.players[pl_nr].net.net_status = gf_dat->line;
bman.players[pl_nr].net.net_istep = 2;
if (addr->pl_nr != -1 && bman.state == GS_update && GT_MP_PTPM) {
if (addr->pl_nr > 0 && addr->pl_nr < MAX_PLAYERS) {
bman.players[addr->pl_nr].net.net_status = gf_dat->line;
bman.players[addr->pl_nr].net.net_istep = 2;
}
}
@ -769,16 +728,12 @@ send_fieldline (_net_addr * addr, int line)
void
do_fieldline (struct pkg_fieldline *f_dat, _net_addr * addr)
{
int pl_nr,
i;
int i;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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 */
d_printf ("do_fieldline: the data we have got are not from the server\n");
return;
@ -815,21 +770,16 @@ send_getplayerdata (_net_addr * addr, int pl)
void
do_getplayerdata (struct pkg_getplayerdata *gp_dat, _net_addr * addr)
{
int pl_nr;
pl_nr = get_player_nr (addr->host, addr->port);
if (pl_nr == -1)
if (addr->pl_nr == -1)
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)
return;
if (pl_nr != -1 && bman.state == GS_update && GT_MP_PTPM) {
if (pl_nr > 0 && pl_nr < MAX_PLAYERS) {
bman.players[pl_nr].net.net_status = gp_dat->pl_nr;
bman.players[pl_nr].net.net_istep = 1;
if (addr->pl_nr != -1 && bman.state == GS_update && GT_MP_PTPM) {
if (addr->pl_nr > 0 && addr->pl_nr < MAX_PLAYERS) {
bman.players[addr->pl_nr].net.net_status = gp_dat->pl_nr;
bman.players[addr->pl_nr].net.net_istep = 1;
}
}
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
do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr)
{
int pl_nr,
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;
int i;
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 */
d_printf ("do_playerstatus: the data we have got are not from the server\n");
return;
@ -860,8 +805,8 @@ do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr)
return;
}
bman.players[pl_nr].net.net_status = stat->status;
bman.players[pl_nr].net.net_istep = stat->net_istep;
bman.players[addr->pl_nr].net.net_status = stat->status;
bman.players[addr->pl_nr].net.net_istep = stat->net_istep;
if (GT_MP_PTPM)
for (i = 0; i < MAX_PLAYERS; i++)
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
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);
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
do_pkgack (struct pkg_pkgack *p_ack, _net_addr * addr)
{
int pl_nr;
d_printf ("do_pkgack (%s:%s)\n", addr->host, addr->port);
if (rscache_getpos (addr, p_ack->typ, p_ack->id) == -1)
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 ();
};
@ -971,11 +904,10 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
{
int i,
pos;
/* find packet */
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 &&
strncmp (inpkg_index[i].addr.port, addr->port, LEN_PORT) == 0 &&
if (inpkg_index[i].pl_nr == addr->pl_nr &&
inpkg_index[i].typ == typ && inpkg_index[i].id == id)
pos = i;
@ -983,7 +915,8 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
/* packet unknown ... add to index */
if (++inpkg_index_pos >= PKG_IN_INDEX_NUM)
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].id = id;
}
@ -1018,8 +951,13 @@ do_pkg (struct pkg *packet, _net_addr * addr)
packet->h.typ != PKG_bcmservchat) {
d_printf ("-----packet comes from the wrong network type\n");
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 */
if (packet->h.flags & PKGF_ackreq && packet->h.typ != PKG_bcmservchat)
send_pkgack (addr, packet->h.typ, packet->h.id);
@ -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) {
/* we have got this packet already */
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;
}

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

@ -141,7 +141,8 @@ rscache_loop ()
bman.net_ai_family);
resend_cache.entry->timestamp = timestamp;
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
@ -149,8 +150,10 @@ rscache_loop ()
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.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 ();
_net_to_2sec++;
}
else
pos = pos + len;

@ -255,11 +255,17 @@ move_player ()
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);
/* 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)
net_game_send_playermove (bman.p_nr);
@ -554,7 +560,7 @@ player_ilness_loop ()
break;
}
}
else if (type == PI_bomb)
else if (type == PI_bomb)
/* player is dropping bombs */
player_drop_bomb ();
}

Loading…
Cancel
Save