Little and Big Endian Support the First Try

origin
stpohle 22 years ago
parent 047ceda105
commit cb55044431

@ -65,6 +65,18 @@ project.menu.need.terminal=0
project.configure.options= project.configure.options=
anjuta.program.arguments= anjuta.program.arguments=
preferences.indent.automatic=1
preferences.use.tabs=1
preferences.indent.opening=0
preferences.indent.closing=0
preferences.tabsize=4
preferences.indent.size=4
preferences.autoformat.style=Custom style
preferences.autoformat.custom.style=-br -brs -l100 -lc100 -lp -hnl -bc -nip -nce -ncdw -bli1 -i4 -ts1-bad -bap
preferences.autoformat.disable=0
preferences.debugger.command=gdb
preferences.ui.designer=glade '$(project.name).glade'
preferences.help.browser=devhelp -s '$(current.file.selection)'
module.include.name=include module.include.name=include
module.include.type= module.include.type=

@ -1,4 +1,4 @@
/* $Id: basic.h,v 1.51 2003/09/04 20:18:21 stpohle Exp $ */ /* $Id: basic.h,v 1.52 2003/09/10 21:32:22 stpohle Exp $ */
/* basic types which we need everywhere */ /* basic types which we need everywhere */
#ifndef _BC_BASIC_H_ #ifndef _BC_BASIC_H_
@ -78,6 +78,8 @@
#define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (bman.players[__result].gfx_nr != __gfx_nr) && (__result >= 0); __result--); #define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (bman.players[__result].gfx_nr != __gfx_nr) && (__result >= 0); __result--);
#include <SDL.h>
enum _networkflags { enum _networkflags {
NETF_firewall = 1 NETF_firewall = 1
}; };
@ -236,8 +238,8 @@ enum _mstatus {
}; };
struct __point { struct __point {
short int x; Sint16 x;
short int y; Sint16 y;
} typedef _point; } typedef _point;
#endif #endif

@ -1,4 +1,4 @@
/* $Id: map.h,v 1.5 2003/08/29 22:04:19 stpohle Exp $ */ /* $Id: map.h,v 1.6 2003/09/10 21:32:22 stpohle Exp $ */
/* map.h */ /* map.h */
#ifndef _MAP_H_ #ifndef _MAP_H_
@ -13,11 +13,11 @@ struct __ex_field {
struct __field { struct __field {
unsigned char type; unsigned char type;
signed char mixframe; // data for the mixed frame signed char mixframe; // data for the mixed frame
short int frame; // frame (frame > 0 && FS_stone) Sint16 frame; // frame (frame > 0 && FS_stone)
int frameto; // frame to Sint32 frameto; // frame to
unsigned char special; // to save special stones, or the tunnel number unsigned char special; // to save special stones, or the tunnel number
_ex_field ex[4]; // count up every explosion there is on this field for ever direction _ex_field ex[4]; // count up every explosion there is on this field for ever direction
int ex_nr; // number to identify the explosion. Sint32 ex_nr; // number to identify the explosion.
} typedef _field; } typedef _field;

@ -2,6 +2,8 @@
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
*/ */
#include <SDL.h>
#ifndef _NETWORK_H_ #ifndef _NETWORK_H_
#define _NETWORK_H_ #define _NETWORK_H_
@ -24,6 +26,20 @@ network.h file... for everything what have to do with the network stuff
#define NET_CANSEND(__pl) (( __pl == 0 || GT_MP_PTPM || (bman.players[__pl].net.flags & NETF_firewall) == 0)) #define NET_CANSEND(__pl) (( __pl == 0 || GT_MP_PTPM || (bman.players[__pl].net.flags & NETF_firewall) == 0))
/* Little / Big Endian Convert */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define NTOH16(__i) s_swap16(__i)
#define HTON16(__i) s_swap16(__i)
#define NTOH32(__i) s_swap32(__i)
#define HTON32(__i) s_swap32(__i)
#else
/* intel system */
#define NTOH16(__i) (__i)
#define HTON16(__i) (__i)
#define NTOH32(__i) (__i)
#define HTON32(__i) (__i)
#endif
#ifdef _WIN32 #ifdef _WIN32
#define _sockaddr sockaddr #define _sockaddr sockaddr
#else #else

@ -45,7 +45,7 @@ send_error (_net_addr * addr, char *text)
strncpy (p_err.text, text, 127); strncpy (p_err.text, text, 127);
p_err.h.typ = PKG_error; p_err.h.typ = PKG_error;
p_err.h.flags = 0; p_err.h.flags = 0;
p_err.h.len = sizeof (struct pkg_error); p_err.h.len = HTON16 (sizeof (struct pkg_error));
p_err.nr = 0; p_err.nr = 0;
send_pkg ((struct pkg *) &p_err, addr); send_pkg ((struct pkg *) &p_err, addr);
@ -85,8 +85,9 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
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
addr->port, addr->pl_nr, p_id->name, p_id->host, p_id->port, p_id->pl_nr); ("do_playerid (From:%s:%s pl_nr=%d) Player(name:%s [%s:%s], pl_nr:%d)\n",
addr->host, 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 && addr->pl_nr != -1)) || // PTPM change setting if (((GT_MP_PTPM && (bman.state == GS_wait && addr->pl_nr != -1)) || // PTPM change setting
@ -115,8 +116,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
} }
if (GT_MP_PTPS) { if (GT_MP_PTPS) {
pl->points = p_id->points; pl->points = NTOH16 (p_id->points);
pl->wins = p_id->wins; pl->wins = NTOH16 (p_id->wins);
} }
} }
@ -153,8 +154,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
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,
bman.net_ai_family, &pl->net.addr.sAddr); LEN_PORT, bman.net_ai_family, &pl->net.addr.sAddr);
pl->net.flags = p_id->netflags; pl->net.flags = p_id->netflags;
pl->net.addr.pl_nr = i; pl->net.addr.pl_nr = i;
bman.players_nr_s++; bman.players_nr_s++;
@ -164,9 +165,10 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
send_mapinfo (addr); send_mapinfo (addr);
for (j = 0; j < MAX_PLAYERS; j++) for (j = 0; j < MAX_PLAYERS; j++)
if (bman.players[j].net.addr.host[0] != 0 || bman.players[j].name[0] != 0) 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, send_playerid (addr, bman.players[j].name,
bman.players[j].net.addr.port, j, bman.players[j].gfx_nr, bman.players[j].net.addr.host,
bman.players[i].net.flags); bman.players[j].net.addr.port, j,
bman.players[j].gfx_nr, bman.players[i].net.flags);
addr->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++)
@ -198,21 +200,21 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
void void
send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport, int pl_nr, int gfx_nr, send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport,
signed char netflags) int pl_nr, int gfx_nr, signed char netflags)
{ {
struct pkg_playerid p_id; struct pkg_playerid p_id;
int vmi, int vmi,
vma, vma,
vsu; vsu;
d_printf ("send_playerid SendTo: %s:%s (Name:%16s p_nr:%d)\n", addr->host, addr->port, name, d_printf ("send_playerid SendTo: %s:%s (Name:%16s p_nr:%d)\n", addr->host,
pl_nr); addr->port, name, pl_nr);
sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu); sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu);
p_id.h.typ = PKG_playerid; p_id.h.typ = PKG_playerid;
p_id.h.flags = PKGF_ackreq; p_id.h.flags = PKGF_ackreq;
p_id.h.len = sizeof (struct pkg_playerid); p_id.h.len = HTON16 (sizeof (struct pkg_playerid));
p_id.ver_sub = vsu; p_id.ver_sub = vsu;
p_id.ver_major = vma; p_id.ver_major = vma;
p_id.ver_minor = vmi; p_id.ver_minor = vmi;
@ -233,8 +235,8 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport, int pl_
p_id.pl_nr = pl_nr; p_id.pl_nr = pl_nr;
p_id.gfx_nr = gfx_nr; p_id.gfx_nr = gfx_nr;
if (pl_nr != -1) { if (pl_nr != -1) {
p_id.points = bman.players[pl_nr].points; p_id.points = HTON16 (bman.players[pl_nr].points);
p_id.wins = bman.players[pl_nr].wins; p_id.wins = HTON16 (bman.players[pl_nr].wins);
p_id.state = bman.players[pl_nr].state; p_id.state = bman.players[pl_nr].state;
} }
else { else {
@ -292,7 +294,7 @@ send_servermode (_net_addr * addr, int pl_nr)
d_printf ("Send ServerMode\n"); d_printf ("Send ServerMode\n");
s_mod.h.typ = PKG_servermode; s_mod.h.typ = PKG_servermode;
s_mod.h.len = sizeof (struct pkg_servermode); s_mod.h.len = HTON16 (sizeof (struct pkg_servermode));
s_mod.h.flags = PKGF_ackreq; s_mod.h.flags = PKGF_ackreq;
s_mod.type = bman.gametype; s_mod.type = bman.gametype;
s_mod.mapstate = map.state; s_mod.mapstate = map.state;
@ -320,7 +322,7 @@ send_field (_net_addr * addr, int x, int y, _field * field)
d_printf ("send_field [%d,%d]\n", x, y); d_printf ("send_field [%d,%d]\n", x, y);
f_dat.h.typ = PKG_field; f_dat.h.typ = PKG_field;
f_dat.h.len = sizeof (struct pkg_field); f_dat.h.len = HTON16 (sizeof (struct pkg_field));
f_dat.h.flags = PKGF_ackreq; f_dat.h.flags = PKGF_ackreq;
f_dat.x = x; f_dat.x = x;
@ -341,16 +343,21 @@ do_field (struct pkg_field *f_dat, _net_addr * addr)
return; return;
if (f_dat->x < map.size.x && f_dat->y < map.size.y) { 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)); 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);
} }
if (bman.state == GS_running) if (bman.state == GS_running)
stonelist_add (f_dat->x, f_dat->y); stonelist_add (f_dat->x, f_dat->y);
if (f_dat->field.ex_nr > bman.last_ex_nr) if (NTOH32 (f_dat->field.ex_nr) > bman.last_ex_nr)
bman.last_ex_nr = f_dat->field.ex_nr; bman.last_ex_nr = NTOH32 (f_dat->field.ex_nr);
d_printf ("do_field (%d,%d) ex_nr = %d, special = %d, type = %d\n", f_dat->x, f_dat->y, d_printf ("do_field (%d,%d) ex_nr = %d, special = %d, type = %d\n",
f_dat->field.ex_nr, f_dat->field.special, f_dat->field.type); f_dat->x, f_dat->y, NTOH32 (f_dat->field.ex_nr),
f_dat->field.special, f_dat->field.type);
}; };
@ -362,14 +369,14 @@ do_ping (struct pkg_ping *p_dat, _net_addr * addr)
if (p_dat->h.typ == PKG_pingack) if (p_dat->h.typ == PKG_pingack)
/* ping was an answer */ /* ping was an answer */
bman.players[addr->pl_nr].net.pingack = p_dat->data; bman.players[addr->pl_nr].net.pingack = NTOH32 (p_dat->data);
else else
/* send the answer */ /* send the answer */
send_ping (addr, p_dat->data, PKG_pingack); 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, d_printf ("do_ping pl_nr[%d] (%s:%s) req=%d, ack=%d\n", addr->pl_nr,
addr->port, bman.players[addr->pl_nr].net.pingreq, addr->host, addr->port, bman.players[addr->pl_nr].net.pingreq,
bman.players[addr->pl_nr].net.pingack); bman.players[addr->pl_nr].net.pingack);
}; };
@ -382,23 +389,23 @@ send_ping (_net_addr * addr, int data, unsigned char typ)
if (addr->pl_nr == -1) if (addr->pl_nr == -1)
return; return;
p_dat.h.len = sizeof (struct pkg_ping); p_dat.h.len = HTON16 (sizeof (struct pkg_ping));
p_dat.h.flags = 0; p_dat.h.flags = 0;
if (typ == PKG_pingack) { if (typ == PKG_pingack) {
p_dat.h.typ = typ; p_dat.h.typ = typ;
p_dat.data = data; p_dat.data = HTON32 (data);
send_pkg ((struct pkg *) &p_dat, addr); send_pkg ((struct pkg *) &p_dat, addr);
} }
else if (typ == PKG_pingreq) { else if (typ == PKG_pingreq) {
p_dat.h.typ = typ; p_dat.h.typ = typ;
p_dat.data = data; p_dat.data = HTON32 (data);
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", addr->pl_nr, addr->host, d_printf ("send_ping Player[%d] (%s:%s) req=%d, ack=%d\n", addr->pl_nr,
addr->port, bman.players[addr->pl_nr].net.pingreq, addr->host, addr->port, bman.players[addr->pl_nr].net.pingreq,
bman.players[addr->pl_nr].net.pingack); 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 bman.players[addr->pl_nr].net.timestamp = timestamp; /* we need to set it here, so we can check
@ -412,22 +419,22 @@ send_playerdata (_net_addr * addr, int p_nr, _player * pl)
struct pkg_playerdata p_dat; struct pkg_playerdata p_dat;
p_dat.h.typ = PKG_playerdata; p_dat.h.typ = PKG_playerdata;
p_dat.h.len = sizeof (struct pkg_playerdata); p_dat.h.len = HTON16 (sizeof (struct pkg_playerdata));
if (bman.state == GS_update) if (bman.state == GS_update)
p_dat.h.flags = 0; p_dat.h.flags = 0;
else else
p_dat.h.flags = PKGF_ackreq; p_dat.h.flags = PKGF_ackreq;
p_dat.pos.x = pl->pos.x; p_dat.pos.x = HTON16 (pl->pos.x);
p_dat.pos.y = pl->pos.y; p_dat.pos.y = HTON16 (pl->pos.y);
p_dat.bombs_n = pl->bombs_n; p_dat.bombs_n = pl->bombs_n;
p_dat.d = pl->d; p_dat.d = pl->d;
p_dat.range = pl->range; p_dat.range = pl->range;
p_dat.gfx_nr = pl->gfx_nr; p_dat.gfx_nr = pl->gfx_nr;
p_dat.state = pl->state; p_dat.state = pl->state;
p_dat.wins = pl->wins; p_dat.wins = HTON16 (pl->wins);
p_dat.points = pl->points; p_dat.points = HTON16 (pl->points);
p_dat.dead_by = pl->dead_by; p_dat.dead_by = pl->dead_by;
p_dat.frame = pl->frame; p_dat.frame = pl->frame;
p_dat.p_nr = p_nr; p_dat.p_nr = p_nr;
@ -454,14 +461,14 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
player_set_gfx (pl, p_dat->gfx_nr); player_set_gfx (pl, p_dat->gfx_nr);
if (bman.state == GS_running && bman.p_nr != p_dat->p_nr) { if (bman.state == GS_running && bman.p_nr != p_dat->p_nr) {
pl->points = p_dat->points; pl->points = NTOH16 (p_dat->points);
pl->dead_by = p_dat->dead_by; pl->dead_by = NTOH16 (p_dat->dead_by);
} }
else if (bman.state != GS_running || bman.p_nr != p_dat->p_nr) { else if (bman.state != GS_running || bman.p_nr != p_dat->p_nr) {
pl->pos.x = p_dat->pos.x; pl->pos.x = NTOH16 (p_dat->pos.x);
pl->pos.y = p_dat->pos.y; pl->pos.y = NTOH16 (p_dat->pos.y);
pl->dead_by = p_dat->dead_by; pl->dead_by = p_dat->dead_by;
pl->points = p_dat->points; pl->points = NTOH16 (p_dat->points);
pl->d = p_dat->d; pl->d = p_dat->d;
pl->bombs_n = p_dat->bombs_n; pl->bombs_n = p_dat->bombs_n;
pl->range = p_dat->range; pl->range = p_dat->range;
@ -506,16 +513,16 @@ send_playermove (_net_addr * addr, int p_nr, _player * pl)
struct pkg_playermove p_dat; struct pkg_playermove p_dat;
p_dat.h.typ = PKG_playermove; p_dat.h.typ = PKG_playermove;
p_dat.h.len = sizeof (struct pkg_playermove); p_dat.h.len = HTON16 (sizeof (struct pkg_playermove));
p_dat.h.flags = 0; p_dat.h.flags = 0;
p_dat.pos.x = pl->pos.x; p_dat.pos.x = HTON16 (pl->pos.x);
p_dat.pos.y = pl->pos.y; p_dat.pos.y = HTON16 (pl->pos.y);
p_dat.m = pl->m; p_dat.m = pl->m;
p_dat.d = pl->d; p_dat.d = pl->d;
p_dat.p_nr = p_nr; p_dat.p_nr = p_nr;
p_dat.speed = pl->speed; p_dat.speed = pl->speed;
p_dat.tunnelto = pl->tunnelto; p_dat.tunnelto = HTON16 (pl->tunnelto);
send_pkg ((struct pkg *) &p_dat, addr); send_pkg ((struct pkg *) &p_dat, addr);
}; };
@ -534,7 +541,7 @@ do_ill (struct pkg_ill *ill, _net_addr * addr)
return; return;
for (i = 0; i < PI_max; i++) for (i = 0; i < PI_max; i++)
bman.players[ill->pl_nr].ill[i].to = ill->to[i]; bman.players[ill->pl_nr].ill[i].to = NTOH16 (ill->to[i]);
}; };
@ -546,12 +553,12 @@ send_ill (_net_addr * addr, int p_nr, _player * pl)
int i; int i;
ill.h.typ = PKG_ill; ill.h.typ = PKG_ill;
ill.h.len = sizeof (struct pkg_ill); ill.h.len = HTON16 (sizeof (struct pkg_ill));
ill.h.flags = PKGF_ackreq; ill.h.flags = PKGF_ackreq;
ill.pl_nr = p_nr; ill.pl_nr = p_nr;
for (i = 0; i < PI_max; i++) for (i = 0; i < PI_max; i++)
ill.to[i] = pl->ill[i].to; ill.to[i] = HTON16 (pl->ill[i].to);
send_pkg ((struct pkg *) &ill, addr); send_pkg ((struct pkg *) &ill, addr);
}; };
@ -576,9 +583,9 @@ do_playermove (struct pkg_playermove *p_dat, _net_addr * addr)
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;
pl->pos.x = p_dat->pos.x; pl->pos.x = HTON16 (p_dat->pos.x);
pl->pos.y = p_dat->pos.y; pl->pos.y = HTON16 (p_dat->pos.y);
pl->tunnelto = p_dat->tunnelto; pl->tunnelto = HTON16 (p_dat->tunnelto);
} }
@ -598,8 +605,9 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
if (b_dat->state == BS_off) if (b_dat->state == BS_off)
return; // if there was a bomb let it explose don't delete the bomb return; // if there was a bomb let it explose don't delete the bomb
d_printf ("do_bombdata [%d,%d] Player: %d Bomb: %d, ex_nr:%d\n", b_dat->x, b_dat->y, d_printf ("do_bombdata [%d,%d] Player: %d Bomb: %d, ex_nr:%d\n",
b_dat->p_nr, b_dat->b_nr, b_dat->ex_nr); NTOH16 (b_dat->x) >> 8, NTOH16 (b_dat->y) >> 8, 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 = &bman.players[b_dat->p_nr].bombs[b_dat->b_nr];
if (bomb->state == BS_exploding) { if (bomb->state == BS_exploding) {
@ -607,8 +615,8 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
return; return;
} }
if ((bomb->pos.x != b_dat->x || bomb->pos.y != b_dat->y) && bomb->state == BS_exploding if ((bomb->pos.x != NTOH16 (b_dat->x) || bomb->pos.y != NTOH16 (b_dat->y))
&& b_dat->state != BS_exploding) && bomb->state == BS_exploding && b_dat->state != BS_exploding)
d_printf ("do_bombdata WARNING : bomb explosion haven't finished\n"); d_printf ("do_bombdata WARNING : bomb explosion haven't finished\n");
if (bomb->state != BS_off) { // handle push & kick special if (bomb->state != BS_off) { // handle push & kick special
@ -619,23 +627,23 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
if (bomb->state == BS_off && (b_dat->state == BS_ticking || b_dat->state == BS_trigger)) if (bomb->state == BS_off && (b_dat->state == BS_ticking || b_dat->state == BS_trigger))
snd_play (SND_bombdrop); snd_play (SND_bombdrop);
bomb->pos.x = b_dat->x; bomb->pos.x = NTOH16 (b_dat->x);
bomb->pos.y = b_dat->y; bomb->pos.y = NTOH16 (b_dat->y);
if (bomb->state != b_dat->state && bomb->state != BS_ticking) if (bomb->state != b_dat->state && bomb->state != BS_ticking)
bomb->to = b_dat->to; /* only set if the bomb isn't already 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 to make sure the timeout won't be resetted
by an old network packet */ by an old network packet */
map.bfield[bomb->pos.x >> 8][bomb->pos.y >> 8] = 1; // keep the bfield up to date map.bfield[bomb->pos.x >> 8][bomb->pos.y >> 8] = 1; // keep the bfield up to date
bomb->r = b_dat->r; bomb->r = b_dat->r;
bomb->ex_nr = b_dat->ex_nr; bomb->ex_nr = NTOH32 (b_dat->ex_nr);
bomb->state = b_dat->state & 0x0F; bomb->state = b_dat->state & 0x0F;
bomb->mode = b_dat->state >> 4; bomb->mode = b_dat->state >> 4;
bomb->speed = b_dat->speed; bomb->speed = NTOH16 (b_dat->speed);
bomb->dest.x = b_dat->destx; bomb->dest.x = NTOH16 (b_dat->destx);
bomb->dest.y = b_dat->desty; bomb->dest.y = NTOH16 (b_dat->desty);
if (bomb->state == BS_exploding) if (bomb->state == BS_exploding)
bomb_explode (b_dat->p_nr, b_dat->b_nr, 0); bomb_explode (b_dat->p_nr, b_dat->b_nr, 0);
@ -651,38 +659,46 @@ send_bombdata (_net_addr * addr, int p, int b, _bomb * bomb)
struct pkg_bombdata b_dat; struct pkg_bombdata b_dat;
b_dat.h.typ = PKG_bombdata; b_dat.h.typ = PKG_bombdata;
b_dat.h.len = sizeof (struct pkg_bombdata); b_dat.h.len = HTON16 (sizeof (struct pkg_bombdata));
b_dat.x = bomb->pos.x; b_dat.x = HTON16 (bomb->pos.x);
b_dat.y = bomb->pos.y; b_dat.y = HTON16 (bomb->pos.y);
b_dat.to = bomb->to; b_dat.to = HTON32 (bomb->to);
b_dat.r = bomb->r; b_dat.r = bomb->r;
b_dat.ex_nr = bomb->ex_nr; b_dat.ex_nr = HTON32 (bomb->ex_nr);
b_dat.state = (bomb->mode << 4) | (bomb->state); b_dat.state = (bomb->mode << 4) | (bomb->state);
b_dat.b_nr = b; b_dat.b_nr = b;
b_dat.p_nr = p; b_dat.p_nr = p;
b_dat.h.flags = PKGF_ackreq; b_dat.h.flags = PKGF_ackreq;
b_dat.speed = bomb->speed; b_dat.speed = HTON16 (bomb->speed);
b_dat.destx = bomb->dest.x; b_dat.destx = HTON16 (bomb->dest.x);
b_dat.desty = bomb->dest.y; b_dat.desty = HTON16 (bomb->dest.y);
send_pkg ((struct pkg *) &b_dat, addr); send_pkg ((struct pkg *) &b_dat, addr);
}; };
/* recive a request for some tunneldata or receive tunneldata */ /* recive a request for some tunneldata or receive tunneldata */
void do_tunneldata (struct pkg_tunneldata *tun_pkg, _net_addr *addr) { void
d_printf ("do_tunneldata: From %d [%s:%s] (Tunnel %d Target [%d,%d])\n", addr->pl_nr, addr->host, addr->port, tun_pkg->tunnel_nr, tun_pkg->target.x, tun_pkg->target.y); do_tunneldata (struct pkg_tunneldata *tun_pkg, _net_addr * addr)
{
if (addr->pl_nr != 0 && GT_MP_PTPM && tun_pkg->target.y == -1 && tun_pkg->target.x == -1) { d_printf ("do_tunneldata: From %d [%s:%s] (Tunnel %d Target [%d,%d])\n",
send_tunneldata (addr, tun_pkg->tunnel_nr, map.tunnel[tun_pkg->tunnel_nr].x, map.tunnel[tun_pkg->tunnel_nr].y); addr->pl_nr, addr->host, addr->port, tun_pkg->tunnel_nr,
NTOH16 (tun_pkg->target.x), NTOH16 (tun_pkg->target.y));
if (addr->pl_nr != 0 && GT_MP_PTPM && NTOH16 (tun_pkg->target.y) == -1
&& 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_status = tun_pkg->tunnel_nr;
bman.players[addr->pl_nr].net.net_istep = 3; bman.players[addr->pl_nr].net.net_istep = 3;
} }
else if (addr->pl_nr == 0 && tun_pkg->tunnel_nr < GAME_MAX_TUNNELS) { else if (addr->pl_nr == 0 && tun_pkg->tunnel_nr < GAME_MAX_TUNNELS) {
if (tun_pkg->target.x >= 0 && tun_pkg->target.x < map.size.x && tun_pkg->target.y >= 0 && tun_pkg->target.y < map.size.y) { if (NTOH16 (tun_pkg->target.x) >= 0 && NTOH16 (tun_pkg->target.x) < map.size.x
map.tunnel[tun_pkg->tunnel_nr].x = tun_pkg->target.x; && NTOH16 (tun_pkg->target.y) >= 0 && NTOH16 (tun_pkg->target.y) < map.size.y) {
map.tunnel[tun_pkg->tunnel_nr].y = tun_pkg->target.y; 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; bman.players[bman.p_nr].net.net_status = tun_pkg->tunnel_nr;
} }
else else
d_printf (" values out of range\n"); d_printf (" values out of range\n");
} }
@ -690,25 +706,27 @@ void do_tunneldata (struct pkg_tunneldata *tun_pkg, _net_addr *addr) {
/* send a tunneldata request (x && y == -1) or send tunneldata */ /* send a tunneldata request (x && y == -1) or send tunneldata */
void send_tunneldata (_net_addr *addr, int tunnelnr, int x, int y) { void
send_tunneldata (_net_addr * addr, int tunnelnr, int x, int y)
{
struct pkg_tunneldata tun_pkg; struct pkg_tunneldata tun_pkg;
d_printf ("send_tunneldata (Tunnel %d Target [%d,%d])\n", tunnelnr, x, y); d_printf ("send_tunneldata (Tunnel %d Target [%d,%d])\n", tunnelnr, x, y);
tun_pkg.h.typ = PKG_tunneldata; tun_pkg.h.typ = PKG_tunneldata;
tun_pkg.h.flags = PKGF_ackreq; tun_pkg.h.flags = PKGF_ackreq;
tun_pkg.h.len = sizeof (struct pkg_tunneldata); tun_pkg.h.len = HTON16 (sizeof (struct pkg_tunneldata));
if ((GT_MP_PTPM && x != -1 && y != -1) || (GT_MP_PTPS && x == -1 && y == -1)) { if ((GT_MP_PTPM && x != -1 && y != -1)
|| (GT_MP_PTPS && x == -1 && y == -1)) {
tun_pkg.tunnel_nr = tunnelnr; tun_pkg.tunnel_nr = tunnelnr;
tun_pkg.target.x = x; tun_pkg.target.x = HTON16 (x);
tun_pkg.target.y = y; tun_pkg.target.y = HTON16 (y);
send_pkg ((struct pkg *) &tun_pkg, addr); send_pkg ((struct pkg *) &tun_pkg, addr);
} }
}; };
void void
send_quit (_net_addr * addr, char *plhost, char * plport) send_quit (_net_addr * addr, char *plhost, char * plport)
{ {
@ -718,13 +736,12 @@ send_quit (_net_addr * addr, char *plhost, char *plport)
q_dat.h.typ = PKG_quit; q_dat.h.typ = PKG_quit;
q_dat.h.flags = 0; q_dat.h.flags = 0;
q_dat.h.len = sizeof (struct pkg_quit); q_dat.h.len = HTON16 (sizeof (struct pkg_quit));
if (plhost == NULL) { if (plhost == NULL) {
q_dat.host[0] = 0; q_dat.host[0] = 0;
q_dat.port[0] = 0; q_dat.port[0] = 0;
} }
else { else {
strncpy (q_dat.host, plhost, LEN_SERVERNAME); strncpy (q_dat.host, plhost, LEN_SERVERNAME);
strncpy (q_dat.port, plport, LEN_PORT); strncpy (q_dat.port, plport, LEN_PORT);
@ -734,10 +751,12 @@ 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)
{ {
d_printf ("do_quit (%s:%s) pl_nr = %d\n", addr->host, addr->port, addr->pl_nr); d_printf ("do_quit (%s:%s) pl_nr = %d\n", addr->host, addr->port, addr->pl_nr);
if (addr->pl_nr == -1) if (addr->pl_nr == -1)
return; return;
@ -747,6 +766,7 @@ do_quit (struct pkg_quit *q_dat, _net_addr * addr)
else { else {
/* delete the player with the giving address */ /* delete the player with the giving address */
int pl_nr = get_player_nr (q_dat->host, q_dat->port); int pl_nr = get_player_nr (q_dat->host, q_dat->port);
if (pl_nr == -1) if (pl_nr == -1)
return; return;
@ -754,14 +774,13 @@ do_quit (struct pkg_quit *q_dat, _net_addr * addr)
} }
}; };
void void
send_getfield (_net_addr * addr, int line) send_getfield (_net_addr * addr, int line)
{ {
struct pkg_getfield gf_dat; struct pkg_getfield gf_dat;
gf_dat.h.typ = PKG_getfield; gf_dat.h.typ = PKG_getfield;
gf_dat.h.len = sizeof (struct pkg_getfield); gf_dat.h.len = HTON16 (sizeof (struct pkg_getfield));
gf_dat.h.flags = 0; gf_dat.h.flags = 0;
gf_dat.line = line; gf_dat.line = line;
send_pkg ((struct pkg *) &gf_dat, addr); send_pkg ((struct pkg *) &gf_dat, addr);
@ -783,7 +802,6 @@ do_getfield (struct pkg_getfield *gf_dat, _net_addr * addr)
bman.players[addr->pl_nr].net.net_istep = 2; bman.players[addr->pl_nr].net.net_istep = 2;
} }
} }
send_fieldline (addr, gf_dat->line); send_fieldline (addr, gf_dat->line);
}; };
@ -796,7 +814,7 @@ send_fieldline (_net_addr * addr, int line)
struct pkg_fieldline f_dat; struct pkg_fieldline f_dat;
f_dat.h.typ = PKG_fieldline; f_dat.h.typ = PKG_fieldline;
f_dat.h.len = sizeof (struct pkg_fieldline); f_dat.h.len = HTON16 (sizeof (struct pkg_fieldline));
f_dat.h.flags = 0; f_dat.h.flags = 0;
f_dat.line = line; f_dat.line = line;
@ -830,7 +848,6 @@ do_fieldline (struct pkg_fieldline *f_dat, _net_addr * addr)
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;
} }
if (f_dat->line < 0 || f_dat->line >= MAX_FIELDSIZE_Y) { if (f_dat->line < 0 || f_dat->line >= MAX_FIELDSIZE_Y) {
/* the line number is wrong */ /* the line number is wrong */
d_printf ("do_fieldline: the line number is not correct\n"); d_printf ("do_fieldline: the line number is not correct\n");
@ -855,8 +872,9 @@ void
send_getplayerdata (_net_addr * addr, int pl) send_getplayerdata (_net_addr * addr, int pl)
{ {
struct pkg_getplayerdata gp_dat; struct pkg_getplayerdata gp_dat;
gp_dat.h.typ = PKG_getplayerdata; gp_dat.h.typ = PKG_getplayerdata;
gp_dat.h.len = sizeof (struct pkg_getplayerdata); gp_dat.h.len = HTON16 (sizeof (struct pkg_getplayerdata));
gp_dat.pl_nr = pl; gp_dat.pl_nr = pl;
gp_dat.h.flags = 0; gp_dat.h.flags = 0;
send_pkg ((struct pkg *) &gp_dat, addr); send_pkg ((struct pkg *) &gp_dat, addr);
@ -894,9 +912,8 @@ do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr)
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;
} }
if (stat->pl_nr < 0 || stat->pl_nr >= MAX_PLAYERS) { if (stat->pl_nr < 0 || stat->pl_nr >= MAX_PLAYERS) {
/* the line number is wrong */ /* the player number is wrong */
d_printf ("do_playerstatus: playernumber not correct\n"); d_printf ("do_playerstatus: playernumber not correct\n");
return; return;
} }
@ -906,8 +923,8 @@ do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr)
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)
send_playerstatus (&bman.players[i].net.addr, stat->pl_nr, stat->net_istep, send_playerstatus (&bman.players[i].net.addr, stat->pl_nr,
stat->status); stat->net_istep, stat->status);
}; };
@ -916,12 +933,12 @@ send_playerstatus (_net_addr * addr, int pl_nr, int net_istep, int status)
{ {
struct pkg_playerstatus stat; struct pkg_playerstatus stat;
d_printf ("send_playerstatus (%s,%s) %d, %d, %d\n", addr->host, addr->port, pl_nr, net_istep, d_printf ("send_playerstatus (%s,%s) %d, %d, %d\n", addr->host,
status); addr->port, pl_nr, net_istep, status);
stat.h.typ = PKG_playerstatus; stat.h.typ = PKG_playerstatus;
stat.h.flags = 0; stat.h.flags = 0;
stat.h.len = sizeof (struct pkg_playerstatus); stat.h.len = HTON16 (sizeof (struct pkg_playerstatus));
stat.pl_nr = pl_nr; stat.pl_nr = pl_nr;
stat.net_istep = net_istep; stat.net_istep = net_istep;
stat.status = status; stat.status = status;
@ -948,7 +965,7 @@ send_chat (_net_addr * addr, char *text)
chat_pkg.h.typ = PKG_chat; chat_pkg.h.typ = PKG_chat;
chat_pkg.h.flags = 0; chat_pkg.h.flags = 0;
chat_pkg.h.len = sizeof (struct pkg_chat); chat_pkg.h.len = HTON16 (sizeof (struct pkg_chat));
for (i = 0; i < sizeof (chat_pkg.text); i++) for (i = 0; i < sizeof (chat_pkg.text); i++)
chat_pkg.text[i] = 0; chat_pkg.text[i] = 0;
@ -965,8 +982,8 @@ send_pkgack (_net_addr * addr, unsigned char typ, short int id)
p_ack.h.typ = PKG_pkgack; p_ack.h.typ = PKG_pkgack;
p_ack.h.flags = 0; p_ack.h.flags = 0;
p_ack.h.len = sizeof (struct pkg_pkgack); p_ack.h.len = HTON16 (sizeof (struct pkg_pkgack));
p_ack.id = id; p_ack.id = HTON16 (id);
p_ack.typ = typ; p_ack.typ = typ;
send_pkg ((struct pkg *) &p_ack, addr); send_pkg ((struct pkg *) &p_ack, addr);
@ -977,7 +994,7 @@ void
do_pkgack (struct pkg_pkgack *p_ack, _net_addr * addr) do_pkgack (struct pkg_pkgack *p_ack, _net_addr * addr)
{ {
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, NTOH16 (p_ack->id)) == -1)
return; return;
rscache_del (); rscache_del ();
@ -1000,7 +1017,7 @@ do_special (struct pkg_special *sp_pkg, _net_addr * addr)
return; return;
bman.players[sp_pkg->pl_nr].special.type = sp_pkg->typ; bman.players[sp_pkg->pl_nr].special.type = sp_pkg->typ;
bman.last_ex_nr = sp_pkg->ex_nr; bman.last_ex_nr = NTOH32 (sp_pkg->ex_nr);
special_use (sp_pkg->pl_nr); special_use (sp_pkg->pl_nr);
}; };
@ -1011,11 +1028,11 @@ send_special (_net_addr * addr, int p_nr, int typ, int ex_nr)
struct pkg_special sp_dat; struct pkg_special sp_dat;
sp_dat.h.typ = PKG_special; sp_dat.h.typ = PKG_special;
sp_dat.h.len = sizeof (struct pkg_special); sp_dat.h.len = HTON16 (sizeof (struct pkg_special));
sp_dat.h.flags = PKGF_ackreq; sp_dat.h.flags = PKGF_ackreq;
sp_dat.pl_nr = p_nr; sp_dat.pl_nr = p_nr;
sp_dat.typ = typ; sp_dat.typ = typ;
sp_dat.ex_nr = ex_nr; sp_dat.ex_nr = HTON32 (ex_nr);
send_pkg ((struct pkg *) &sp_dat, addr); send_pkg ((struct pkg *) &sp_dat, addr);
}; };
@ -1040,7 +1057,7 @@ send_mapinfo (_net_addr * addr)
struct pkg_mapinfo map_pkg; struct pkg_mapinfo map_pkg;
map_pkg.h.typ = PKG_mapinfo; map_pkg.h.typ = PKG_mapinfo;
map_pkg.h.len = sizeof (struct pkg_mapinfo); map_pkg.h.len = HTON16 (sizeof (struct pkg_mapinfo));
map_pkg.h.flags = PKGF_ackreq; map_pkg.h.flags = PKGF_ackreq;
map_pkg.size_x = map.size.x; map_pkg.size_x = map.size.x;
map_pkg.size_y = map.size.y; map_pkg.size_y = map.size.y;
@ -1115,7 +1132,6 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
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;
} }
return pos; return pos;
}; };
@ -1124,10 +1140,10 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
void void
send_pkg (struct pkg *packet, _net_addr * addr) send_pkg (struct pkg *packet, _net_addr * addr)
{ {
packet->h.id = pkg_lastid++; packet->h.id = HTON16 (pkg_lastid++);
if (bman.net_ai_family != PF_INET) if (bman.net_ai_family != PF_INET)
packet->h.flags = packet->h.flags | PKGF_ipv6; packet->h.flags = packet->h.flags | PKGF_ipv6;
udp_send (bman.sock, (char *) packet, packet->h.len, &addr->sAddr, bman.net_ai_family); udp_send (bman.sock, (char *) packet, NTOH16 (packet->h.len), &addr->sAddr, bman.net_ai_family);
/* test if we have any important packet if so put it in the resend_cache */ /* test if we have any important packet if so put it in the resend_cache */
if (packet->h.flags & PKGF_ackreq) { if (packet->h.flags & PKGF_ackreq) {
@ -1136,6 +1152,7 @@ send_pkg (struct pkg *packet, _net_addr * addr)
} }
}; };
/* forward the packet to all who are behind a firewall */ /* forward the packet to all who are behind a firewall */
void void
fwd_pkg (struct pkg *packet, _net_addr * addr) fwd_pkg (struct pkg *packet, _net_addr * addr)
@ -1152,8 +1169,8 @@ fwd_pkg (struct pkg *packet, _net_addr * addr)
for (pl = 1; pl < MAX_PLAYERS; pl++) for (pl = 1; pl < MAX_PLAYERS; pl++)
if (PS_IS_netplayer (bman.players[pl].state) if (PS_IS_netplayer (bman.players[pl].state)
&& ((bman.players[pl].net.flags & NETF_firewall) == NETF_firewall && ((bman.players[pl].net.flags & NETF_firewall) == NETF_firewall
|| (bman.players[addr->pl_nr].net.flags & NETF_firewall) == NETF_firewall) || (bman.players[addr->pl_nr].net.flags & NETF_firewall) ==
&& pl != addr->pl_nr) NETF_firewall) && pl != addr->pl_nr)
send_pkg (packet, &bman.players[pl].net.addr); send_pkg (packet, &bman.players[pl].net.addr);
}; };
@ -1161,13 +1178,12 @@ fwd_pkg (struct pkg *packet, _net_addr * addr)
int int
do_pkg (struct pkg *packet, _net_addr * addr) do_pkg (struct pkg *packet, _net_addr * addr)
{ {
if ((((packet->h.flags & PKGF_ipv6) == 0 && bman.net_ai_family != PF_INET) || if ((((packet->h.flags & PKGF_ipv6) == 0 && bman.net_ai_family != PF_INET)
((packet->h.flags & PKGF_ipv6) != 0 && bman.net_ai_family == PF_INET)) && || ((packet->h.flags & PKGF_ipv6) != 0 && bman.net_ai_family == PF_INET))
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 */ /* 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);
bman.players[addr->pl_nr].net.timestamp = timestamp; bman.players[addr->pl_nr].net.timestamp = timestamp;
@ -1175,10 +1191,10 @@ do_pkg (struct pkg *packet, _net_addr * addr)
/* 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)
send_pkgack (addr, packet->h.typ, packet->h.id); send_pkgack (addr, packet->h.typ, NTOH16 (packet->h.id));
/* check the packet with the index */ /* check the packet with the index */
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, NTOH16 (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");
if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
@ -1187,7 +1203,7 @@ do_pkg (struct pkg *packet, _net_addr * addr)
} }
/* check if the incoming packet have the right size */ /* check if the incoming packet have the right size */
if (packet->h.typ == PKG_servermode && packet->h.len != sizeof (struct pkg_servermode)) if (packet->h.typ == PKG_servermode && NTOH16 (packet->h.len) != sizeof (struct pkg_servermode))
send_error (addr, "pkg_servermode: packetsize incorrect."); send_error (addr, "pkg_servermode: packetsize incorrect.");
/* forward packet */ /* forward packet */

@ -35,8 +35,8 @@ enum _pkgflags {
struct pkgheader { struct pkgheader {
unsigned char typ; unsigned char typ;
unsigned char flags; unsigned char flags;
short int id; Sint16 id;
short int len; Sint16 len;
}; };
@ -62,13 +62,13 @@ struct pkg_tunneldata {
struct pkg_pkgack { struct pkg_pkgack {
struct pkgheader h; struct pkgheader h;
char typ; char typ;
short int id; Sint16 id;
}; };
struct pkg_ping { struct pkg_ping {
struct pkgheader h; struct pkgheader h;
int data; Sint32 data;
}; };
@ -116,8 +116,8 @@ struct pkg_playerid {
signed char pl_nr; // Player Nummer signed char pl_nr; // Player Nummer
signed char gfx_nr; // number of the graphic signed char gfx_nr; // number of the graphic
signed char state; signed char state;
short int points; Sint16 points;
short int wins; Sint16 wins;
signed char netflags; signed char netflags;
}; };
@ -125,8 +125,8 @@ struct pkg_playerid {
struct pkg_playerdata { struct pkg_playerdata {
struct pkgheader h; struct pkgheader h;
signed char p_nr; // Playernumber signed char p_nr; // Playernumber
short int points; // points Sint16 points; // points
short int wins; // how many times we win Sint16 wins; // how many times we win
signed char gfx_nr; // the gfx number we want to use signed char gfx_nr; // the gfx number we want to use
_point pos; _point pos;
unsigned char bombs_n; unsigned char bombs_n;
@ -144,7 +144,7 @@ struct pkg_playermove {
signed char m; signed char m;
signed char d; signed char d;
signed char speed; signed char speed;
short int tunnelto; Sint16 tunnelto;
_point pos; _point pos;
}; };
@ -153,15 +153,15 @@ struct pkg_bombdata {
struct pkgheader h; struct pkgheader h;
unsigned char p_nr; unsigned char p_nr;
unsigned char b_nr; unsigned char b_nr;
unsigned short int x; Uint16 x;
unsigned short int y; Uint16 y;
unsigned char state; unsigned char state;
unsigned char r; unsigned char r;
int ex_nr; Sint32 ex_nr;
int to; Sint32 to;
unsigned short int destx; Uint16 destx;
unsigned short int desty; Uint16 desty;
signed short int speed; Sint16 speed;
}; };
@ -197,7 +197,7 @@ struct pkg_fieldline {
struct pkg_ill { struct pkg_ill {
struct pkgheader h; struct pkgheader h;
signed char pl_nr; signed char pl_nr;
short int to[PI_max]; Sint16 to[PI_max];
}; };
@ -216,7 +216,7 @@ struct pkg_chat {
struct pkg_special { struct pkg_special {
struct pkgheader h; struct pkgheader h;
signed char pl_nr; signed char pl_nr;
int ex_nr; Sint32 ex_nr;
unsigned char typ; unsigned char typ;
}; };
@ -241,7 +241,7 @@ struct pkg_mapinfo {
struct _rscache_entry { struct _rscache_entry {
signed char pl_nr; // playernumber to whom this data should go signed char pl_nr; // playernumber to whom this data should go
short int len; // size of the entry Sint16 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
_net_addr addr; // pointer to the address _net_addr addr; // pointer to the address
@ -252,14 +252,14 @@ struct _rscache_entry {
struct _resend_cache { struct _resend_cache {
char *data; // will hold the pointer to out cache char *data; // will hold the pointer to out cache
struct _rscache_entry *entry; // pointer to our data struct _rscache_entry *entry; // pointer to our data
int fill; // how much we have used Sint32 fill; // how much we have used
}; };
struct _inpkg_index { struct _inpkg_index {
signed char pl_nr; signed char pl_nr;
unsigned char typ; unsigned char typ;
short int id; Sint16 id;
}; };

@ -27,7 +27,7 @@ rscache_add (_net_addr * addr, struct pkg *packet)
resend_cache.entry->retry = 0; resend_cache.entry->retry = 0;
resend_cache.entry->timestamp = timestamp; resend_cache.entry->timestamp = timestamp;
memcpy (&resend_cache.entry->addr, addr, sizeof (_net_addr)); memcpy (&resend_cache.entry->addr, addr, sizeof (_net_addr));
memcpy (&resend_cache.entry->packet, packet, packet->h.len); memcpy (&resend_cache.entry->packet, packet, NTOH16 (packet->h.len));
newlen = resend_cache.fill + rscache_getcurlen (); newlen = resend_cache.fill + rscache_getcurlen ();
@ -90,7 +90,7 @@ rscache_getpos (_net_addr * addr, unsigned char typ, short int id)
if (strcmp (addr->host, resend_cache.entry->addr.host) == 0 && if (strcmp (addr->host, resend_cache.entry->addr.host) == 0 &&
strcmp (addr->port, resend_cache.entry->addr.port) == 0 && strcmp (addr->port, resend_cache.entry->addr.port) == 0 &&
typ == resend_cache.entry->packet.h.typ && id == resend_cache.entry->packet.h.id) typ == resend_cache.entry->packet.h.typ && id == NTOH16 (resend_cache.entry->packet.h.id))
done = 1; /* we have found the old packet */ done = 1; /* we have found the old packet */
else else
pos = pos + len; pos = pos + len;
@ -108,7 +108,7 @@ rscache_getcurlen ()
{ {
int len; int len;
len = sizeof (struct _rscache_entry) - sizeof (struct pkg) + resend_cache.entry->packet.h.len; len = sizeof (struct _rscache_entry) - sizeof (struct pkg) + NTOH16 (resend_cache.entry->packet.h.len);
return len; return len;
}; };
@ -137,7 +137,7 @@ rscache_loop ()
resend_cache.entry->addr.host, resend_cache.entry->addr.port, resend_cache.fill, resend_cache.entry->addr.host, resend_cache.entry->addr.port, resend_cache.fill,
pos); pos);
udp_send (bman.sock, (char *) &resend_cache.entry->packet, udp_send (bman.sock, (char *) &resend_cache.entry->packet,
resend_cache.entry->packet.h.len, &resend_cache.entry->addr.sAddr, NTOH16 (resend_cache.entry->packet.h.len), &resend_cache.entry->addr.sAddr,
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++;

@ -1,4 +1,4 @@
/* $Id: sysfunc.c,v 1.17 2003/07/15 11:43:09 stpohle Exp $ /* $Id: sysfunc.c,v 1.18 2003/09/10 21:32:22 stpohle Exp $
sysfunc.c - this file hold some routines for the system functions.. sysfunc.c - this file hold some routines for the system functions..
like d_delay like d_delay
*/ */
@ -193,3 +193,32 @@ char* getfilename(char* path)
return path+i+1; return path+i+1;
return path; return path;
} }
/* swap 16bit integers, needed for
little and big endian convert */
inline Sint16 s_swap16 (Sint16 i) {
Sint16 r;
char *z1 = (char *)&i;
char *z2 = (char *)&r;
*(z2+1) = *z1;
*z2 = *(z1+1);
return r;
};
/* swap 32bit integers, needed for
little and big endian convert */
inline Sint32 s_swap32 (Sint32 i) {
Sint32 r;
int j;
char *z1 = (char *) &i;
char *z2 = (char *) &r;
for (j = 0; j < 4; j++)
*(z2+j) = *(z1+(3-j));
return r;
};

@ -1,4 +1,4 @@
/* $Id: sysfunc.h,v 1.7 2003/07/15 11:43:09 stpohle Exp $ */ /* $Id: sysfunc.h,v 1.8 2003/09/10 21:32:22 stpohle Exp $ */
/* include some system near functions */ /* include some system near functions */
#ifndef _SYSFUNC_H_ #ifndef _SYSFUNC_H_
@ -23,6 +23,9 @@ extern char *s_gethomedir ();
extern int s_countbits (int nbomb, int nr); extern int s_countbits (int nbomb, int nr);
extern char* getfilename(char* path); extern char* getfilename(char* path);
extern inline Sint16 s_swap16 (Sint16 i);
extern inline Sint32 s_swap32 (Sint32 i);
extern _direntry *s_getdir (char *path); extern _direntry *s_getdir (char *path);
extern _direntry *s_dirfilter (_direntry *dirstart, signed char dirflags); extern _direntry *s_dirfilter (_direntry *dirstart, signed char dirflags);

Loading…
Cancel
Save