|
|
|
@ -20,6 +20,9 @@ struct _inpkg_index inpkg_index[PKG_IN_INDEX_NUM];
|
|
|
|
|
int inpkg_index_pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** help function to get the playernumber from the address.
|
|
|
|
|
***/
|
|
|
|
|
int
|
|
|
|
|
get_player_nr (char *host, char *port)
|
|
|
|
|
{
|
|
|
|
@ -27,15 +30,18 @@ get_player_nr (char *host, char *port)
|
|
|
|
|
res;
|
|
|
|
|
|
|
|
|
|
for (i = 0, res = -1; (i < MAX_PLAYERS && res == -1); i++) {
|
|
|
|
|
if (bman.players[i].net.addr.host[0] != 0)
|
|
|
|
|
if ((strcmp (bman.players[i].net.addr.host, host) == 0) &&
|
|
|
|
|
(strcmp (bman.players[i].net.addr.port, port) == 0))
|
|
|
|
|
if (players[i].net.addr.host[0] != 0)
|
|
|
|
|
if ((strcmp (players[i].net.addr.host, host) == 0) &&
|
|
|
|
|
(strcmp (players[i].net.addr.port, port) == 0))
|
|
|
|
|
res = i;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: error
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_error (_net_addr * addr, char *text)
|
|
|
|
|
{
|
|
|
|
@ -64,9 +70,10 @@ do_error (struct pkg_error *data, _net_addr * addr)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
update the playerinformations in the game
|
|
|
|
|
*/
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: pingack/pingreq
|
|
|
|
|
*** Update Playerinformation, add players into the current game
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -93,7 +100,7 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
|
|
|
|
|
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];
|
|
|
|
|
pl = &players[p_id->pl_nr];
|
|
|
|
|
|
|
|
|
|
pl->state = p_id->state;
|
|
|
|
|
if (p_id->pl_nr != bman.p_nr && PS_IS_used (pl->state))
|
|
|
|
@ -126,13 +133,13 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
|
|
|
|
|
|
|
|
|
|
/* find free player slot */
|
|
|
|
|
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 (players[i].state)); i++);
|
|
|
|
|
else
|
|
|
|
|
i = addr->pl_nr;
|
|
|
|
|
|
|
|
|
|
if ((i < MAX_PLAYERS) && (i < bman.maxplayer)) {
|
|
|
|
|
/* free in_pl slot ... fill in data */
|
|
|
|
|
pl = &bman.players[i];
|
|
|
|
|
pl = &players[i];
|
|
|
|
|
|
|
|
|
|
pl->state = PSF_used + PSF_net;
|
|
|
|
|
if (strncmp (pl->name, p_id->name, LEN_PLAYERNAME) == 0)
|
|
|
|
@ -164,15 +171,15 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
|
|
|
|
|
send_servermode (addr, i);
|
|
|
|
|
send_mapinfo (addr);
|
|
|
|
|
for (j = 0; j < MAX_PLAYERS; j++)
|
|
|
|
|
if (bman.players[j].net.addr.host[0] != 0 || bman.players[j].name[0] != 0)
|
|
|
|
|
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[i].net.flags);
|
|
|
|
|
if (players[j].net.addr.host[0] != 0 || players[j].name[0] != 0)
|
|
|
|
|
send_playerid (addr, players[j].name,
|
|
|
|
|
players[j].net.addr.host,
|
|
|
|
|
players[j].net.addr.port, j,
|
|
|
|
|
players[j].gfx_nr, players[i].net.flags);
|
|
|
|
|
|
|
|
|
|
addr->pl_nr = i;
|
|
|
|
|
for (j = 0, i = 0; i < bman.maxplayer; i++)
|
|
|
|
|
if (PS_IS_used (bman.players[i].state))
|
|
|
|
|
if (PS_IS_used (players[i].state))
|
|
|
|
|
j++;
|
|
|
|
|
if (bman.notifygamemaster)
|
|
|
|
|
gamesrv_sendmode (bman.maxplayer, j);
|
|
|
|
@ -235,9 +242,9 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport,
|
|
|
|
|
p_id.pl_nr = pl_nr;
|
|
|
|
|
p_id.gfx_nr = gfx_nr;
|
|
|
|
|
if (pl_nr != -1) {
|
|
|
|
|
p_id.points = HTON16 (bman.players[pl_nr].points);
|
|
|
|
|
p_id.wins = HTON16 (bman.players[pl_nr].wins);
|
|
|
|
|
p_id.state = bman.players[pl_nr].state;
|
|
|
|
|
p_id.points = HTON16 (players[pl_nr].points);
|
|
|
|
|
p_id.wins = HTON16 (players[pl_nr].wins);
|
|
|
|
|
p_id.state = players[pl_nr].state;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
p_id.points = 0;
|
|
|
|
@ -249,6 +256,9 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: servermode
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -259,19 +269,12 @@ do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
|
|
|
|
|
|
|
|
|
|
if (s_mod->pl_nr >= 0 && s_mod->pl_nr < MAX_PLAYERS) {
|
|
|
|
|
bman.p_nr = s_mod->pl_nr;
|
|
|
|
|
bman.players[bman.p_nr].state &= (0xFF - PSF_net);
|
|
|
|
|
strncpy (bman.players[s_mod->pl_nr].name, bman.playername, LEN_PLAYERNAME);
|
|
|
|
|
players[bman.p_nr].state &= (0xFF - PSF_net);
|
|
|
|
|
strncpy (players[s_mod->pl_nr].name, bman.playername, LEN_PLAYERNAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s_mod->type == GT_multi)
|
|
|
|
|
bman.gametype = GT_multi;
|
|
|
|
|
else
|
|
|
|
|
bman.gametype = GT_single;
|
|
|
|
|
|
|
|
|
|
bman.state = s_mod->state;
|
|
|
|
|
map.state = s_mod->mapstate;
|
|
|
|
|
if (s_mod->multitype == MT_ptpm)
|
|
|
|
|
bman.multitype = MT_ptps;
|
|
|
|
|
|
|
|
|
|
bman.players_nr_s = s_mod->players;
|
|
|
|
|
bman.lastwinner = s_mod->last_winner;
|
|
|
|
@ -314,6 +317,9 @@ send_servermode (_net_addr * addr, int pl_nr)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: field
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_field (_net_addr * addr, int x, int y, _field * field)
|
|
|
|
|
{
|
|
|
|
@ -330,11 +336,14 @@ send_field (_net_addr * addr, int x, int y, _field * field)
|
|
|
|
|
|
|
|
|
|
if (x < 0 || x >= map.size.x || y < 0 || y >= map.size.y)
|
|
|
|
|
return;
|
|
|
|
|
memcpy (&f_dat.field, &map.field[x][y], sizeof (_field));
|
|
|
|
|
|
|
|
|
|
f_dat.field.frame = HTON16 (f_dat.field.frame);
|
|
|
|
|
f_dat.field.frameto = HTON32 (f_dat.field.frameto);
|
|
|
|
|
f_dat.field.ex_nr = HTON32 (f_dat.field.ex_nr);
|
|
|
|
|
memcpy (&f_dat.ex, &map.field[x][y].ex, 4*sizeof (_ex_field));
|
|
|
|
|
|
|
|
|
|
f_dat.type = map.field[x][y].type;
|
|
|
|
|
f_dat.mixframe = map.field[x][y].mixframe;
|
|
|
|
|
f_dat.special = map.field[x][y].special;
|
|
|
|
|
f_dat.frame = HTON16 (FTOI16 (map.field[x][y].frame));
|
|
|
|
|
f_dat.ex_nr = HTON32 (map.field[x][y].ex_nr);
|
|
|
|
|
|
|
|
|
|
send_pkg ((struct pkg *) &f_dat, addr);
|
|
|
|
|
};
|
|
|
|
@ -348,23 +357,28 @@ do_field (struct pkg_field *f_dat, _net_addr * addr)
|
|
|
|
|
|
|
|
|
|
if (f_dat->x < map.size.x && f_dat->y < map.size.y) {
|
|
|
|
|
/* convert the fielddata */
|
|
|
|
|
memcpy (&map.field[f_dat->x][f_dat->y], &f_dat->field, sizeof (_field));
|
|
|
|
|
map.field[f_dat->x][f_dat->y].frame = NTOH16 (map.field[f_dat->x][f_dat->y].frame);
|
|
|
|
|
map.field[f_dat->x][f_dat->y].frameto = NTOH32 (map.field[f_dat->x][f_dat->y].frameto);
|
|
|
|
|
map.field[f_dat->x][f_dat->y].ex_nr = NTOH32 (map.field[f_dat->x][f_dat->y].ex_nr);
|
|
|
|
|
map.field[f_dat->x][f_dat->y].type = f_dat->type;
|
|
|
|
|
map.field[f_dat->x][f_dat->y].mixframe = f_dat->mixframe;
|
|
|
|
|
map.field[f_dat->x][f_dat->y].special = f_dat->special;
|
|
|
|
|
memcpy (&map.field[f_dat->x][f_dat->y].ex, &f_dat->ex, 4*sizeof (_ex_field));
|
|
|
|
|
map.field[f_dat->x][f_dat->y].frame = I16TOF (NTOH16 (f_dat->frame));
|
|
|
|
|
map.field[f_dat->x][f_dat->y].ex_nr = NTOH32 (f_dat->ex_nr);
|
|
|
|
|
}
|
|
|
|
|
if (bman.state == GS_running)
|
|
|
|
|
stonelist_add (f_dat->x, f_dat->y);
|
|
|
|
|
|
|
|
|
|
if (NTOH32 (f_dat->field.ex_nr) > bman.last_ex_nr)
|
|
|
|
|
bman.last_ex_nr = NTOH32 (f_dat->field.ex_nr);
|
|
|
|
|
if (NTOH32 (f_dat->ex_nr) > bman.last_ex_nr)
|
|
|
|
|
bman.last_ex_nr = NTOH32 (f_dat->ex_nr);
|
|
|
|
|
|
|
|
|
|
d_printf ("do_field (%d,%d) ex_nr = %d, special = %d, type = %d\n",
|
|
|
|
|
f_dat->x, f_dat->y, NTOH32 (f_dat->field.ex_nr),
|
|
|
|
|
f_dat->field.special, f_dat->field.type);
|
|
|
|
|
f_dat->x, f_dat->y, NTOH32 (f_dat->ex_nr),
|
|
|
|
|
f_dat->special, f_dat->type);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: pingack/pingreq
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_ping (struct pkg_ping *p_dat, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -373,18 +387,17 @@ do_ping (struct pkg_ping *p_dat, _net_addr * addr)
|
|
|
|
|
|
|
|
|
|
if (p_dat->h.typ == PKG_pingack)
|
|
|
|
|
/* ping was an answer */
|
|
|
|
|
bman.players[addr->pl_nr].net.pingack = NTOH32 (p_dat->data);
|
|
|
|
|
players[addr->pl_nr].net.pingack = NTOH32 (p_dat->data);
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
/* send the answer */
|
|
|
|
|
send_ping (addr, NTOH32 (p_dat->data), PKG_pingack);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
addr->host, addr->port, players[addr->pl_nr].net.pingreq,
|
|
|
|
|
players[addr->pl_nr].net.pingack);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
send_ping (_net_addr * addr, int data, unsigned char typ)
|
|
|
|
|
{
|
|
|
|
@ -409,14 +422,17 @@ send_ping (_net_addr * addr, int data, unsigned char typ)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
addr->host, addr->port, players[addr->pl_nr].net.pingreq,
|
|
|
|
|
players[addr->pl_nr].net.pingack);
|
|
|
|
|
|
|
|
|
|
bman.players[addr->pl_nr].net.timestamp = timestamp; /* we need to set it here, so we can check
|
|
|
|
|
players[addr->pl_nr].net.timestamp = timestamp; /* we need to set it here, so we can check
|
|
|
|
|
for the timeout again */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: playerdata
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_playerdata (_net_addr * addr, int p_nr, _player * pl)
|
|
|
|
|
{
|
|
|
|
@ -440,7 +456,7 @@ send_playerdata (_net_addr * addr, int p_nr, _player * pl)
|
|
|
|
|
p_dat.wins = HTON16 (pl->wins);
|
|
|
|
|
p_dat.points = HTON16 (pl->points);
|
|
|
|
|
p_dat.dead_by = pl->dead_by;
|
|
|
|
|
p_dat.frame = pl->frame;
|
|
|
|
|
p_dat.frame = HTON16 (FTOI16 (pl->frame));
|
|
|
|
|
p_dat.p_nr = p_nr;
|
|
|
|
|
|
|
|
|
|
send_pkg ((struct pkg *) &p_dat, addr);
|
|
|
|
@ -461,7 +477,7 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
|
|
|
|
|
d_printf ("do_playerdata (From: %d) p_nr: %d\n", addr->pl_nr, p_dat->p_nr);
|
|
|
|
|
bman.updatestatusbar = 1; // force an update
|
|
|
|
|
|
|
|
|
|
pl = &bman.players[p_dat->p_nr];
|
|
|
|
|
pl = &players[p_dat->p_nr];
|
|
|
|
|
player_set_gfx (pl, p_dat->gfx_nr);
|
|
|
|
|
|
|
|
|
|
if (bman.state == GS_running && bman.p_nr != p_dat->p_nr) {
|
|
|
|
@ -476,7 +492,7 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
|
|
|
|
|
pl->d = p_dat->d;
|
|
|
|
|
pl->bombs_n = p_dat->bombs_n;
|
|
|
|
|
pl->range = p_dat->range;
|
|
|
|
|
pl->frame = p_dat->frame;
|
|
|
|
|
pl->frame = I16TOF (NTOH16 (p_dat->frame));
|
|
|
|
|
pl->state = p_dat->state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -487,7 +503,7 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
|
|
|
|
|
if (PS_IS_alife (pl->state) && PS_IS_dead (p_dat->state)) {
|
|
|
|
|
/* player just died */
|
|
|
|
|
if (p_dat->p_nr != p_dat->dead_by) {
|
|
|
|
|
bman.players[p_dat->dead_by].points++;
|
|
|
|
|
players[p_dat->dead_by].points++;
|
|
|
|
|
net_game_send_player (p_dat->dead_by);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -506,32 +522,14 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
|
|
|
|
|
if (bman.state == GS_update && PS_IS_used (p_dat->state))
|
|
|
|
|
bman.players_nr_s++;
|
|
|
|
|
|
|
|
|
|
if (bman.state == GS_update && bman.players[bman.p_nr].net.net_istep == 1)
|
|
|
|
|
bman.players[bman.p_nr].net.net_status = p_dat->p_nr;
|
|
|
|
|
if (bman.state == GS_update && players[bman.p_nr].net.net_istep == 1)
|
|
|
|
|
players[bman.p_nr].net.net_status = p_dat->p_nr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
send_playermove (_net_addr * addr, int p_nr, _player * pl)
|
|
|
|
|
{
|
|
|
|
|
struct pkg_playermove p_dat;
|
|
|
|
|
|
|
|
|
|
p_dat.h.typ = PKG_playermove;
|
|
|
|
|
p_dat.h.len = HTON16 (sizeof (struct pkg_playermove));
|
|
|
|
|
p_dat.h.flags = 0;
|
|
|
|
|
|
|
|
|
|
p_dat.pos.x = HTON16 (FTOI16 (pl->pos.x));
|
|
|
|
|
p_dat.pos.y = HTON16 (FTOI16 (pl->pos.y));
|
|
|
|
|
p_dat.m = pl->m;
|
|
|
|
|
p_dat.d = pl->d;
|
|
|
|
|
p_dat.p_nr = p_nr;
|
|
|
|
|
p_dat.speed = pl->speed;
|
|
|
|
|
p_dat.tunnelto = HTON16 (pl->tunnelto);
|
|
|
|
|
|
|
|
|
|
send_pkg ((struct pkg *) &p_dat, addr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: ill
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_ill (struct pkg_ill *ill, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -545,11 +543,9 @@ do_ill (struct pkg_ill *ill, _net_addr * addr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < PI_max; i++)
|
|
|
|
|
bman.players[ill->pl_nr].ill[i].to = NTOH16 (ill->to[i]);
|
|
|
|
|
players[ill->pl_nr].ill[i].to = I16TOF (NTOH16 (ill->to[i]));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
send_ill (_net_addr * addr, int p_nr, _player * pl)
|
|
|
|
|
{
|
|
|
|
@ -562,11 +558,33 @@ send_ill (_net_addr * addr, int p_nr, _player * pl)
|
|
|
|
|
|
|
|
|
|
ill.pl_nr = p_nr;
|
|
|
|
|
for (i = 0; i < PI_max; i++)
|
|
|
|
|
ill.to[i] = HTON16 (pl->ill[i].to);
|
|
|
|
|
ill.to[i] = HTON16 (FTOI16 (pl->ill[i].to));
|
|
|
|
|
|
|
|
|
|
send_pkg ((struct pkg *) &ill, addr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: playermove
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_playermove (_net_addr * addr, int p_nr, _player * pl)
|
|
|
|
|
{
|
|
|
|
|
struct pkg_playermove p_dat;
|
|
|
|
|
|
|
|
|
|
p_dat.h.typ = PKG_playermove;
|
|
|
|
|
p_dat.h.len = HTON16 (sizeof (struct pkg_playermove));
|
|
|
|
|
p_dat.h.flags = 0;
|
|
|
|
|
|
|
|
|
|
p_dat.pos.x = HTON16 (FTOI16 (pl->pos.x));
|
|
|
|
|
p_dat.pos.y = HTON16 (FTOI16 (pl->pos.y));
|
|
|
|
|
p_dat.m = pl->m;
|
|
|
|
|
p_dat.d = pl->d;
|
|
|
|
|
p_dat.p_nr = p_nr;
|
|
|
|
|
p_dat.speed = pl->speed;
|
|
|
|
|
p_dat.tunnelto = HTON16 (pl->tunnelto);
|
|
|
|
|
|
|
|
|
|
send_pkg ((struct pkg *) &p_dat, addr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
do_playermove (struct pkg_playermove *p_dat, _net_addr * addr)
|
|
|
|
@ -580,7 +598,7 @@ do_playermove (struct pkg_playermove *p_dat, _net_addr * addr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* check if the right player is sending the information */
|
|
|
|
|
pl = &bman.players[p_dat->p_nr];
|
|
|
|
|
pl = &players[p_dat->p_nr];
|
|
|
|
|
if (addr->pl_nr != 0 && addr->pl_nr != p_dat->p_nr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
@ -589,10 +607,13 @@ do_playermove (struct pkg_playermove *p_dat, _net_addr * addr)
|
|
|
|
|
pl->speed = p_dat->speed;
|
|
|
|
|
pl->pos.x = I16TOF (HTON16 (p_dat->pos.x));
|
|
|
|
|
pl->pos.y = I16TOF (HTON16 (p_dat->pos.y));
|
|
|
|
|
pl->tunnelto = HTON16 (p_dat->tunnelto);
|
|
|
|
|
pl->tunnelto = I16TOF (HTON16 (p_dat->tunnelto));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: bombdata
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -613,7 +634,7 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
|
|
|
|
|
I16TOF(NTOH16 (b_dat->x)), I16TOF(NTOH16 (b_dat->y)), b_dat->p_nr,
|
|
|
|
|
b_dat->b_nr, NTOH32 (b_dat->ex_nr));
|
|
|
|
|
|
|
|
|
|
bomb = &bman.players[b_dat->p_nr].bombs[b_dat->b_nr];
|
|
|
|
|
bomb = &players[b_dat->p_nr].bombs[b_dat->b_nr];
|
|
|
|
|
if (bomb->state == BS_exploding) {
|
|
|
|
|
d_printf ("do_bombdata ---> bomb is already exploding\n");
|
|
|
|
|
return;
|
|
|
|
@ -636,9 +657,9 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
|
|
|
|
|
bomb->pos.y = I16TOF (NTOH16 (b_dat->y));
|
|
|
|
|
|
|
|
|
|
if (bomb->state != b_dat->state && bomb->state != BS_ticking)
|
|
|
|
|
bomb->to = NTOH32 (b_dat->to); /* only set if the bomb isn't already ticking
|
|
|
|
|
to make sure the timeout won't be resetted
|
|
|
|
|
by an old network packet */
|
|
|
|
|
bomb->to = I32TOF (NTOH32 (b_dat->to)); /* only set if the bomb isn't already ticking
|
|
|
|
|
to make sure the timeout won't be resetted
|
|
|
|
|
by an old network packet */
|
|
|
|
|
|
|
|
|
|
map.bfield[(int)bomb->pos.x][(int)bomb->pos.y] = 1; // keep the bfield up to date
|
|
|
|
|
|
|
|
|
@ -657,7 +678,6 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
|
|
|
|
|
bman.last_ex_nr = bomb->ex_nr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
send_bombdata (_net_addr * addr, int p, int b, _bomb * bomb)
|
|
|
|
|
{
|
|
|
|
@ -667,7 +687,7 @@ send_bombdata (_net_addr * addr, int p, int b, _bomb * bomb)
|
|
|
|
|
b_dat.h.len = HTON16 (sizeof (struct pkg_bombdata));
|
|
|
|
|
b_dat.x = HTON16 (FTOI16 (bomb->pos.x));
|
|
|
|
|
b_dat.y = HTON16 (FTOI16 (bomb->pos.y));
|
|
|
|
|
b_dat.to = HTON32 (bomb->to);
|
|
|
|
|
b_dat.to = HTON32 (FTOI32 (bomb->to));
|
|
|
|
|
b_dat.r = bomb->r;
|
|
|
|
|
b_dat.ex_nr = HTON32 (bomb->ex_nr);
|
|
|
|
|
b_dat.state = (bomb->mode << 4) | (bomb->state);
|
|
|
|
@ -681,7 +701,11 @@ send_bombdata (_net_addr * addr, int p, int b, _bomb * bomb)
|
|
|
|
|
send_pkg ((struct pkg *) &b_dat, addr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* recive a request for some tunneldata or receive tunneldata */
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: bombdata
|
|
|
|
|
*** recive a request for some tunneldata or receive tunneldata
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_tunneldata (struct pkg_tunneldata *tun_pkg, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -693,17 +717,16 @@ do_tunneldata (struct pkg_tunneldata *tun_pkg, _net_addr * addr)
|
|
|
|
|
&& NTOH16 (tun_pkg->target.x) == -1) {
|
|
|
|
|
send_tunneldata (addr, tun_pkg->tunnel_nr,
|
|
|
|
|
map.tunnel[tun_pkg->tunnel_nr].x, map.tunnel[tun_pkg->tunnel_nr].y);
|
|
|
|
|
bman.players[addr->pl_nr].net.net_status = tun_pkg->tunnel_nr;
|
|
|
|
|
bman.players[addr->pl_nr].net.net_istep = 3;
|
|
|
|
|
players[addr->pl_nr].net.net_status = tun_pkg->tunnel_nr;
|
|
|
|
|
players[addr->pl_nr].net.net_istep = 3;
|
|
|
|
|
}
|
|
|
|
|
else if (addr->pl_nr == 0 && tun_pkg->tunnel_nr < GAME_MAX_TUNNELS) {
|
|
|
|
|
map.tunnel[tun_pkg->tunnel_nr].x = NTOH16 (tun_pkg->target.x);
|
|
|
|
|
map.tunnel[tun_pkg->tunnel_nr].y = NTOH16 (tun_pkg->target.y);
|
|
|
|
|
bman.players[bman.p_nr].net.net_status = tun_pkg->tunnel_nr;
|
|
|
|
|
players[bman.p_nr].net.net_status = tun_pkg->tunnel_nr;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* send a tunneldata request (x && y == -1) or send tunneldata */
|
|
|
|
|
void
|
|
|
|
|
send_tunneldata (_net_addr * addr, int tunnelnr, int x, int y)
|
|
|
|
@ -726,6 +749,9 @@ send_tunneldata (_net_addr * addr, int tunnelnr, int x, int y)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: quit
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_quit (_net_addr * addr, char *plhost, char * plport)
|
|
|
|
|
{
|
|
|
|
@ -749,8 +775,6 @@ send_quit (_net_addr * addr, char *plhost, char * plport)
|
|
|
|
|
send_pkg ((struct pkg *) &q_dat, addr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
do_quit (struct pkg_quit *q_dat, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -773,6 +797,10 @@ do_quit (struct pkg_quit *q_dat, _net_addr * addr)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: getfield
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_getfield (_net_addr * addr, int line)
|
|
|
|
|
{
|
|
|
|
@ -797,14 +825,17 @@ do_getfield (struct pkg_getfield *gf_dat, _net_addr * addr)
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
players[addr->pl_nr].net.net_status = gf_dat->line;
|
|
|
|
|
players[addr->pl_nr].net.net_istep = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
send_fieldline (addr, gf_dat->line);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: fieldline
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_fieldline (_net_addr * addr, int line)
|
|
|
|
|
{
|
|
|
|
@ -823,8 +854,7 @@ send_fieldline (_net_addr * addr, int line)
|
|
|
|
|
for (i = 0; i < MAX_FIELDSIZE_X; i++) {
|
|
|
|
|
f_dat.type[i] = map.field[i][line].type;
|
|
|
|
|
f_dat.special[i] = map.field[i][line].special;
|
|
|
|
|
map.field[i][line].frame = 0;
|
|
|
|
|
map.field[i][line].frameto = 0;
|
|
|
|
|
map.field[i][line].frame = 0.0f;
|
|
|
|
|
map.field[i][line].ex_nr = 0;
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
|
map.field[i][line].ex[j].frame = map.field[i][line].ex[j].count = 0;
|
|
|
|
@ -853,20 +883,22 @@ do_fieldline (struct pkg_fieldline *f_dat, _net_addr * addr)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bman.state == GS_update && bman.players[bman.p_nr].net.net_istep == 2)
|
|
|
|
|
bman.players[bman.p_nr].net.net_status = f_dat->line;
|
|
|
|
|
if (bman.state == GS_update && players[bman.p_nr].net.net_istep == 2)
|
|
|
|
|
players[bman.p_nr].net.net_status = f_dat->line;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_FIELDSIZE_X; i++) {
|
|
|
|
|
map.field[i][f_dat->line].type = f_dat->type[i];
|
|
|
|
|
map.field[i][f_dat->line].special = f_dat->special[i];
|
|
|
|
|
map.field[i][f_dat->line].frameto = 0;
|
|
|
|
|
map.field[i][f_dat->line].frame = 0;
|
|
|
|
|
map.field[i][f_dat->line].frame = 0.0f;
|
|
|
|
|
for (d = 0; d < 4; d++)
|
|
|
|
|
map.field[i][f_dat->line].ex[d].frame = map.field[i][f_dat->line].ex[d].count = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: getplayerdata
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_getplayerdata (_net_addr * addr, int pl)
|
|
|
|
|
{
|
|
|
|
@ -891,14 +923,17 @@ do_getplayerdata (struct pkg_getplayerdata *gp_dat, _net_addr * addr)
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
players[addr->pl_nr].net.net_status = gp_dat->pl_nr;
|
|
|
|
|
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, &players[gp_dat->pl_nr]);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: playerstatus
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -917,16 +952,15 @@ do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bman.players[addr->pl_nr].net.net_status = stat->status;
|
|
|
|
|
bman.players[addr->pl_nr].net.net_istep = stat->net_istep;
|
|
|
|
|
players[addr->pl_nr].net.net_status = stat->status;
|
|
|
|
|
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)
|
|
|
|
|
send_playerstatus (&bman.players[i].net.addr, stat->pl_nr,
|
|
|
|
|
if (players[i].net.addr.host[0] != 0)
|
|
|
|
|
send_playerstatus (&players[i].net.addr, stat->pl_nr,
|
|
|
|
|
stat->net_istep, stat->status);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
send_playerstatus (_net_addr * addr, int pl_nr, int net_istep, int status)
|
|
|
|
|
{
|
|
|
|
@ -946,6 +980,9 @@ send_playerstatus (_net_addr * addr, int pl_nr, int net_istep, int status)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: chat
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_chat (struct pkg_chat *chat_pkg, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -974,6 +1011,9 @@ send_chat (_net_addr * addr, char *text)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: pkgack
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_pkgack (_net_addr * addr, unsigned char typ, short int id)
|
|
|
|
|
{
|
|
|
|
@ -999,8 +1039,11 @@ do_pkgack (struct pkg_pkgack *p_ack, _net_addr * addr)
|
|
|
|
|
rscache_del ();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Player Special
|
|
|
|
|
* moves/bombs... whatever will be send as we use it */
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: special
|
|
|
|
|
*** moves/bombs... whatever will be send as we use it
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_special (struct pkg_special *sp_pkg, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -1015,7 +1058,7 @@ do_special (struct pkg_special *sp_pkg, _net_addr * addr)
|
|
|
|
|
if (addr->pl_nr != 0 && addr->pl_nr != sp_pkg->pl_nr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bman.players[sp_pkg->pl_nr].special.type = sp_pkg->typ;
|
|
|
|
|
players[sp_pkg->pl_nr].special.type = sp_pkg->typ;
|
|
|
|
|
bman.last_ex_nr = NTOH32 (sp_pkg->ex_nr);
|
|
|
|
|
special_use (sp_pkg->pl_nr);
|
|
|
|
|
};
|
|
|
|
@ -1036,6 +1079,9 @@ send_special (_net_addr * addr, int p_nr, int typ, int ex_nr)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: bcmservchat
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
do_bcmservchat (struct pkg_bcmservchat *packet, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -1050,6 +1096,9 @@ do_bcmservchat (struct pkg_bcmservchat *packet, _net_addr * addr)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** Packettype: mapinfo
|
|
|
|
|
***/
|
|
|
|
|
void
|
|
|
|
|
send_mapinfo (_net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -1111,6 +1160,13 @@ do_mapinfo (struct pkg_mapinfo *map_pkg, _net_addr * addr)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** general packet handling, like check for double recived packets
|
|
|
|
|
*** network type. Autoreply on PKGF_ackreq and such things.
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
/* check incoming packet, if we have got the same already if so return != -1
|
|
|
|
|
if we haven't got it yet, Add to the incache and return -1 */
|
|
|
|
|
int
|
|
|
|
|
inpkg_check (unsigned char typ, short int id, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -1123,7 +1179,7 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
|
|
|
|
|
inpkg_index[i].typ == typ && inpkg_index[i].id == id)
|
|
|
|
|
pos = i;
|
|
|
|
|
if (pos == -1) {
|
|
|
|
|
/* packet unknown ... add to index */
|
|
|
|
|
/* add to index */
|
|
|
|
|
if (++inpkg_index_pos >= PKG_IN_INDEX_NUM)
|
|
|
|
|
inpkg_index_pos = 0;
|
|
|
|
|
|
|
|
|
@ -1135,7 +1191,7 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* sends the packet and if PKGF_ackreq is set add packet to the resendcache */
|
|
|
|
|
void
|
|
|
|
|
send_pkg (struct pkg *packet, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -1166,14 +1222,18 @@ fwd_pkg (struct pkg *packet, _net_addr * addr)
|
|
|
|
|
|| 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_netplayer (bman.players[pl].state)
|
|
|
|
|
&& ((bman.players[pl].net.flags & NETF_firewall) == NETF_firewall
|
|
|
|
|
|| (bman.players[addr->pl_nr].net.flags & NETF_firewall) ==
|
|
|
|
|
if (PS_IS_netplayer (players[pl].state)
|
|
|
|
|
&& ((players[pl].net.flags & NETF_firewall) == NETF_firewall
|
|
|
|
|
|| (players[addr->pl_nr].net.flags & NETF_firewall) ==
|
|
|
|
|
NETF_firewall) && pl != addr->pl_nr)
|
|
|
|
|
send_pkg (packet, &bman.players[pl].net.addr);
|
|
|
|
|
send_pkg (packet, &players[pl].net.addr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* entry point for all incoming network data. determinate packet type and
|
|
|
|
|
forward it to all needed functions, like inpkg_check()--> send answer if needed,
|
|
|
|
|
if we are the server then forward the packet if needed
|
|
|
|
|
and go into the do_PACKETTYP function */
|
|
|
|
|
int
|
|
|
|
|
do_pkg (struct pkg *packet, _net_addr * addr)
|
|
|
|
|
{
|
|
|
|
@ -1185,8 +1245,8 @@ do_pkg (struct pkg *packet, _net_addr * addr)
|
|
|
|
|
}
|
|
|
|
|
/* 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;
|
|
|
|
|
players[addr->pl_nr].net.timestamp = timestamp;
|
|
|
|
|
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 && packet->h.typ != PKG_bcmservchat)
|
|
|
|
@ -1197,7 +1257,7 @@ do_pkg (struct pkg *packet, _net_addr * addr)
|
|
|
|
|
/* we have got this packet already */
|
|
|
|
|
d_printf ("-----packet ignored\n");
|
|
|
|
|
if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
|
|
|
|
|
bman.players[addr->pl_nr].net.pkgopt.to_2sec++;
|
|
|
|
|
players[addr->pl_nr].net.pkgopt.to_2sec++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|