formated part of the source, fixed: send_quit

origin
stpohle 21 years ago
parent 8e8d381ddf
commit 2c43dfc8f0

@ -1,4 +1,4 @@
/* $Id: basic.h,v 1.31 2005/04/09 18:22:40 stpohle Exp $ */
/* $Id: basic.h,v 1.32 2005/04/10 00:22:16 stpohle Exp $ */
/* basic types which we need everywhere */
#ifndef _BC_BASIC_H_
@ -48,7 +48,7 @@
#define MIN_FIELDSIZE_X 15
#define MIN_FIELDSIZE_Y 9
#define MAX_FIELDANIMATION 2048 /* number of points on the field to be animated exploding
stoned or powerups*/
stoned or powerups */
#define EXPLOSIONTIMEOUT 0.5
#define ANI_FIRETIMEOUT 2

@ -1,4 +1,4 @@
/* $Id: bomb.h,v 1.4 2004/12/01 02:41:54 stpohle Exp $
/* $Id: bomb.h,v 1.5 2005/04/10 00:22:16 stpohle Exp $
* bomb include file
*/
@ -30,7 +30,7 @@ struct {
signed char b; // bombnumber of this bomb
} id;
float firer[4]; // range of the fire for the fire for each direction
int firemaxr [4]; // max range reached?
int firemaxr[4]; // max range reached?
float to; // timeout in ms after dropping the bomb. (loops * 0.0005sec)
float frame; // frame of the animation
unsigned char r; // range of the bomb
@ -45,13 +45,13 @@ struct {
// for the bomb..
extern void bomb_loop ();
extern void bomb_explode (_bomb *bomb, int net);
extern inline void bomb_action (_bomb *bomb);
extern void bomb_move (_bomb *bomb);
extern void bomb_explode (_bomb * bomb, int net);
extern inline void bomb_action (_bomb * bomb);
extern void bomb_move (_bomb * bomb);
extern void get_bomb_on (float x, float y, _point bombs[]);
extern void explosion_do (_bomb *bomb);
extern void explosion_do (_bomb * bomb);
extern void explosion_restore (_bomb * bomb);
extern int explosion_check_field (int x, int y, _bomb *bomb);
extern int explosion_check_field (int x, int y, _bomb * bomb);
#endif

@ -1,4 +1,4 @@
/* $Id: configuration.c,v 1.74 2005/04/09 18:22:40 stpohle Exp $
/* $Id: configuration.c,v 1.75 2005/04/10 00:22:17 stpohle Exp $
* configuration */
#include <SDL.h>
@ -699,6 +699,7 @@ ReadPrgArgs (int argc, char **argv)
if (bman.minplayers <= 1)
bman.minplayers = 2;
bman.dedicated = 1;
printf ("\nDedicated Bomberclone Server - Version " VERSION "\n\n");
}
if (!strcmp (argv[i], "-autostart"))
bman.autostart = atoi (argv[++i]);

@ -1,4 +1,4 @@
/* $Id: game.c,v 1.110 2005/04/09 19:44:08 stpohle Exp $
/* $Id: game.c,v 1.111 2005/04/10 00:22:17 stpohle Exp $
game.c - procedures for the game. */
#include <string.h>
@ -219,6 +219,7 @@ game_loop ()
{
SDL_Event event;
int done = 0, eventstate;
int ready_timestamp = 0;
if (GT_MP)
net_game_fillsockaddr ();
@ -281,11 +282,14 @@ game_loop ()
if (NET_CANSEND (i) && !players[i].ready)
ready = 0;
if (ready)
bman.state = GS_running;
if (ready && ready_timestamp == 0)
ready_timestamp = timestamp;
if (ready && (timestamp - ready_timestamp) > 2500) {
bman.state = GS_running;
net_send_servermode ();
}
}
player_check (bman.p_nr);

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.73 2005/04/09 18:22:41 stpohle Exp $ */
/* $Id: network.c,v 1.74 2005/04/10 00:22:17 stpohle Exp $ */
/*
network routines.
*/
@ -61,7 +61,7 @@ net_dyn_pkgoption ()
_net_pkgopt *npkg;
for (p = 0; p < MAX_PLAYERS; p++)
if (PS_IS_netplayer (players[p].state) && !PS_IS_aiplayer(players[p].state)) {
if (PS_IS_netplayer (players[p].state) && !PS_IS_aiplayer (players[p].state)) {
npkg = &players[p].net.pkgopt;
if (npkg->to_2sec > DYN_PKG_MAX_MISSING) {
@ -71,7 +71,8 @@ net_dyn_pkgoption ()
npkg->to_timestamp = timestamp;
}
if ((timestamp - npkg->to_timestamp > 2000) && npkg->to_2sec <= DYN_PKG_MIN_MISSING) {
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;
@ -154,14 +155,16 @@ network_shutdown ()
/* find new server */
for (i = 0; i < MAX_PLAYERS; i++) {
if (PS_IS_used(players[i].state) && PS_IS_netplayer(players[i].state) && i != bman.p_servnr && players[i].net.flags == 0)
if (PS_IS_used (players[i].state) && PS_IS_netplayer (players[i].state)
&& i != bman.p_servnr && players[i].net.flags == 0)
new_server = i;
}
d_printf ("netword_shutdown: new server set to: %d\n", new_server);
for (i = 0; i < MAX_PLAYERS; i++)
if (i != bman.p_servnr && PS_IS_netplayer (players[i].state) && !PS_IS_aiplayer (players[i].state))
if (i != bman.p_servnr && PS_IS_netplayer (players[i].state)
&& !PS_IS_aiplayer (players[i].state))
send_quit (&players[i].net.addr, bman.p_servnr, new_server);
}
else if (players[bman.p_servnr].net.addr.host[0] != 0) {
@ -205,8 +208,7 @@ net_check_timeout (int pl_nr)
timestamp - players[pl_nr].net.timestamp);
players[pl_nr].net.timestamp = timestamp;
players[pl_nr].net.pingack = players[pl_nr].net.pingreq;
send_ping (&players[pl_nr].net.addr, players[pl_nr].net.pingack + 100,
PKG_pingreq);
send_ping (&players[pl_nr].net.addr, players[pl_nr].net.pingack + 100, PKG_pingreq);
}
if ((players[pl_nr].state & (PSF_net + PSF_used + PSF_ai)) == (PSF_used + PSF_net)
&& ((players[pl_nr].net.flags & NETF_local2) == 0)
@ -254,8 +256,8 @@ network_loop ()
inlen = udp_get (bman.sock, data, MAX_UDPDATA, &addr.sAddr, bman.net_ai_family);
addr.port[0] = addr.host[0] = 0;
if (inlen > 0)
dns_filladdr (addr.host, LEN_SERVERNAME, addr.port, LEN_PORT, bman.net_ai_family,
&addr.sAddr);
dns_filladdr (addr.host, LEN_SERVERNAME, addr.port, LEN_PORT,
bman.net_ai_family, &addr.sAddr);
}
/*
@ -302,13 +304,13 @@ draw_netupdatestate (char st)
int y = 0,
b1,
z,
zx=200,
zx = 200,
i,
j,
s=map.size.y+MAX_PLAYERS+GAME_MAX_TUNNELS;
s = map.size.y + MAX_PLAYERS + GAME_MAX_TUNNELS;
SDL_Rect src,
dest;
z=gfx.res.x-zx-30-8;
z = gfx.res.x - zx - 30 - 8;
for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_used (players[i].state)) {
y += 50;
@ -333,71 +335,74 @@ draw_netupdatestate (char st)
dest.w = menulistimages[1][0]->w;
dest.h = menulistimages[1][0]->h;
gfx_blit (menulistimages[1][0], NULL, gfx.screen, &dest, 10000);
dest.x = z+zx+4;
dest.x = z + zx + 4;
gfx_blit (menulistimages[1][2], NULL, gfx.screen, &dest, 10000);
// draw the bottom left and right of the list
dest.y = y+29;
dest.y = y + 29;
gfx_blit (menulistimages[1][8], NULL, gfx.screen, &dest, 10000);
dest.x = zx;
gfx_blit (menulistimages[1][6], NULL, gfx.screen, &dest, 10000);
//top & bottom
for (j=4;j<z+4;j+=4) {
dest.x=j+zx;dest.y=y;
for (j = 4; j < z + 4; j += 4) {
dest.x = j + zx;
dest.y = y;
gfx_blit (menulistimages[1][1], NULL, gfx.screen, &dest, 10000);
dest.y = y+29;
dest.y = y + 29;
gfx_blit (menulistimages[1][7], NULL, gfx.screen, &dest, 10000);
}
//left &right
for (j=4;j<29;j+=4) {
dest.x=zx;dest.y=y+j;
for (j = 4; j < 29; j += 4) {
dest.x = zx;
dest.y = y + j;
gfx_blit (menulistimages[1][3], NULL, gfx.screen, &dest, 10000);
dest.x = z+zx+4;
dest.x = z + zx + 4;
gfx_blit (menulistimages[1][5], NULL, gfx.screen, &dest, 10000);
}
sprintf (text, "%s", players[i].name);
font_draw (80, y, text, 0, 4);
}
// calc percentage, this a range from 0 to 255)
switch(players[i].net.net_istep){
switch (players[i].net.net_istep) {
case 3:
sprintf (text, "Getting Tunnel Data %d.", players[i].net.net_status);
b=(players[i].net.net_status+1)*255/s;
b = (players[i].net.net_status + 1) * 255 / s;
break;
case 2:
sprintf (text, "Getting Field Data %d of %d.", players[i].net.net_status,
map.size.y);
b=(players[i].net.net_status+1+GAME_MAX_TUNNELS)*255/s;
sprintf (text, "Getting Field Data %d of %d.",
players[i].net.net_status, map.size.y);
b = (players[i].net.net_status + 1 + GAME_MAX_TUNNELS) * 255 / s;
break;
case 1:
sprintf (text, "Getting Player Data %d of %d.", players[i].net.net_status,
MAX_PLAYERS);
b=(players[i].net.net_status+1+GAME_MAX_TUNNELS+map.size.y)*255/s;
sprintf (text, "Getting Player Data %d of %d.",
players[i].net.net_status, MAX_PLAYERS);
b = (players[i].net.net_status + 1 + GAME_MAX_TUNNELS + map.size.y) * 255 / s;
break;
default:
sprintf (text, "Ready");
b=255;
b = 255;
break;
}
//draw bar
if (b>0) {
b1=b*z/255;
dest.x = zx+4;
dest.y = y+4;
if (b > 0) {
b1 = b * z / 255;
dest.x = zx + 4;
dest.y = y + 4;
dest.w = menubuttonimages[2][0]->w;
dest.h = menubuttonimages[2][0]->h;
gfx_blit (menubuttonimages[2][0], NULL, gfx.screen, &dest, 10000);
dest.x = zx+4+b1-menubuttonimages[1][2]->w;
if (dest.x<zx+4) dest.x=zx+4;
dest.x = zx + 4 + b1 - menubuttonimages[1][2]->w;
if (dest.x < zx + 4)
dest.x = zx + 4;
dest.w = menubuttonimages[2][2]->w;
dest.h = menubuttonimages[2][2]->h;
gfx_blit (menubuttonimages[2][2], NULL, gfx.screen, &dest, 10000);
if (b1>menubuttonimages[2][0]->w+menubuttonimages[2][2]->w) {
if (b1 > menubuttonimages[2][0]->w + menubuttonimages[2][2]->w) {
dest.w = menubuttonimages[2][1]->w;
dest.h = menubuttonimages[2][1]->h;
for(j=menubuttonimages[2][0]->w;j<b1-menubuttonimages[2][2]->w;
j+=menubuttonimages[2][1]->w) {
dest.x=j+zx+4;
for (j = menubuttonimages[2][0]->w;
j < b1 - menubuttonimages[2][2]->w; j += menubuttonimages[2][1]->w) {
dest.x = j + zx + 4;
gfx_blit (menubuttonimages[2][1], NULL, gfx.screen, &dest, 10000);
}
}
@ -405,9 +410,8 @@ draw_netupdatestate (char st)
// draw old status in case of debug
if (!players[i].net.net_istep)
font_draw (80, y + 20, text, 0, 4);
else
if (debug) {
redraw_logo (80, y+35, gfx.res.x-80, 15);
else if (debug) {
redraw_logo (80, y + 35, gfx.res.x - 80, 15);
font_draw (80, y + 35, text, 0, 4);
}
}
@ -432,8 +436,10 @@ net_send_playerid (int pl_nr)
for (i = 1; i < MAX_PLAYERS; i++)
if (NET_CANSEND (i))
send_playerid (&players[i].net.addr, players[pl_nr].name,
players[pl_nr].net.addr.host, players[pl_nr].net.addr.port,
pl_nr, players[pl_nr].gfx_nr, players[pl_nr].team_nr, players[pl_nr].net.flags);
players[pl_nr].net.addr.host,
players[pl_nr].net.addr.port, pl_nr,
players[pl_nr].gfx_nr, players[pl_nr].team_nr,
players[pl_nr].net.flags);
}
else {
/*
@ -442,10 +448,12 @@ net_send_playerid (int pl_nr)
if (pl_nr == bman.p_nr || (IS_LPLAYER2 && pl_nr == bman.p2_nr))
send_playerid (&players[bman.p_servnr].net.addr, players[pl_nr].name,
players[pl_nr].net.addr.host, players[pl_nr].net.addr.port,
pl_nr, players[pl_nr].gfx_nr, players[pl_nr].team_nr, players[pl_nr].net.flags);
pl_nr, players[pl_nr].gfx_nr, players[pl_nr].team_nr,
players[pl_nr].net.flags);
}
if ((players[pl_nr].gfx_nr >= 0 && players[pl_nr].gfx != &gfx.players[players[pl_nr].gfx_nr]) || (players[pl_nr].gfx_nr == -1 && players[pl_nr].gfx != NULL))
if ((players[pl_nr].gfx_nr >= 0 && players[pl_nr].gfx != &gfx.players[players[pl_nr].gfx_nr])
|| (players[pl_nr].gfx_nr == -1 && players[pl_nr].gfx != NULL))
player_set_gfx (&players[pl_nr], players[pl_nr].gfx_nr);
};
@ -484,7 +492,8 @@ net_transmit_gamedata ()
for (x = 0; x < MAX_PLAYERS; x++) {
players[x].net.timestamp = 0;
players[x].net.net_status = -1;
if ((PS_IS_aiplayer (players[x].state)) || (x==bman.p_servnr) || (x == bman.p2_nr) || (players[x].net.flags & NETF_local2) == NETF_local2)
if ((PS_IS_aiplayer (players[x].state)) || (x == bman.p_servnr) || (x == bman.p2_nr)
|| (players[x].net.flags & NETF_local2) == NETF_local2)
players[x].net.net_istep = 0;
else
players[x].net.net_istep = 3;
@ -511,10 +520,11 @@ net_transmit_gamedata ()
if (GT_MP_PTPM) {
if (timestamp - downtimestamp > TIME_UPDATEINFO) {
downtimestamp = timestamp;
net_send_updateinfo();
net_send_updateinfo ();
}
for (p = 1, i = 1; p < MAX_PLAYERS; p++)
if (PS_IS_playing (players[p].state) && players[p].net.net_istep != 0)
for (p = 0, i = 1; p < MAX_PLAYERS; p++)
if (PS_IS_playing (players[p].state)
&& players[p].net.net_istep != 0)
i = 0;
if (i == 1) { /* all players are ready */
done = 1;
@ -534,9 +544,10 @@ net_transmit_gamedata ()
downtimestamp = timestamp;
send_tunneldata (&players[bman.p_servnr].net.addr, y, -1, -1);
}
else if (y < GAME_MAX_TUNNELS && y != players[bman.p_nr].net.net_status
&& y >= 0 && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
/* we have got no tunnel data*/
else if (y < GAME_MAX_TUNNELS
&& y != players[bman.p_nr].net.net_status && y >= 0
&& timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
/* we have got no tunnel data */
y--;
}
else if (y == GAME_MAX_TUNNELS - 1 && players[bman.p_nr].net.net_status == y) {
@ -575,14 +586,15 @@ net_transmit_gamedata ()
/*
get player data
*/
if ((y < MAX_PLAYERS - 1 && y == players[bman.p_nr].net.net_status) || y == -1) {
if ((y < MAX_PLAYERS - 1 && y == players[bman.p_nr].net.net_status)
|| y == -1) {
/* send player date req */
y++;
downtimestamp = timestamp;
send_getplayerdata (&players[bman.p_servnr].net.addr, y);
}
if (y < MAX_PLAYERS && y != players[bman.p_nr].net.net_status && y >= 0
&& timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
if (y < MAX_PLAYERS && y != players[bman.p_nr].net.net_status
&& y >= 0 && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) {
/* we have got no player data */
y--;
}
@ -654,12 +666,13 @@ net_game_send_player (int p_nr)
if (GT_MP_PTPM) {
for (p = 0; p < MAX_PLAYERS; p++)
if (PS_IS_netplayer (players[p].state) && p != bman.p_nr && p != bman.p2_nr && p != p_nr)
if (PS_IS_netplayer (players[p].state) && p != bman.p_nr && p != bman.p2_nr
&& p != p_nr)
send_playerdata (&players[p].net.addr, p_nr, &players[p_nr]);
}
else if (p_nr == bman.p_nr || p_nr == bman.p2_nr) {
for (p = 0; p < MAX_PLAYERS; p++)
if (NET_CANSEND(p))
if (NET_CANSEND (p))
send_playerdata (&players[p].net.addr, p_nr, &players[p_nr]);
}
};
@ -672,7 +685,7 @@ net_game_send_playermove (int p_nr, int mustsend)
_player *pl;
for (p = 0; p < MAX_PLAYERS; p++)
if (NET_CANSEND(p)) {
if (NET_CANSEND (p)) {
pl = &players[p_nr];
pl->net.pkgopt.send_to--;
@ -691,7 +704,8 @@ net_game_send_bomb (int p, int b)
int pl;
/* check if we are slave and send something else as dropping a bomb */
if (GT_MP_PTPS && players[p].bombs[b].state != BS_ticking && players[p].bombs[b].state != BS_trigger)
if (GT_MP_PTPS && players[p].bombs[b].state != BS_ticking
&& players[p].bombs[b].state != BS_trigger)
return;
d_printf ("Send BombData %d, %d\n", p, b);
@ -700,7 +714,7 @@ net_game_send_bomb (int p, int b)
return;
for (pl = 0; pl < MAX_PLAYERS; pl++)
if (NET_CANSEND(pl))
if (NET_CANSEND (pl))
send_bombdata (&players[pl].net.addr, p, b, &players[p].bombs[b]);
};
@ -716,7 +730,7 @@ net_game_send_field (int x, int y)
return;
for (pl = 0; pl < MAX_PLAYERS; pl++)
if (NET_CANSEND(pl))
if (NET_CANSEND (pl))
send_field (&players[pl].net.addr, x, y, &map.field[x][y]);
};
@ -725,7 +739,8 @@ net_game_send_field (int x, int y)
* send the information about the deleted player to all clients
*/
void
net_game_send_delplayer (int pl_nr) {
net_game_send_delplayer (int pl_nr)
{
int i;
int new_server = bman.p_servnr;
@ -736,16 +751,18 @@ net_game_send_delplayer (int pl_nr) {
/* find new server, if needed */
if (pl_nr == bman.p_servnr) {
for (i = 0; i < MAX_PLAYERS; i++) {
if (PS_IS_used(players[i].state) && PS_IS_netplayer(players[i].state) && i != bman.p_servnr && players[i].net.flags == 0)
if (PS_IS_used (players[i].state)
&& PS_IS_netplayer (players[i].state) && i != bman.p_servnr
&& players[i].net.flags == 0)
new_server = i;
}
d_printf ("new_game_send_delplayer: new server set to: %d\n", new_server);
}
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i) && i != bman.p_nr)
if (NET_CANSEND (i) && i != bman.p_nr)
send_quit (&players[i].net.addr, pl_nr, new_server);
bman.updatestatusbar=1;
bman.updatestatusbar = 1;
}
/* we have to send that one if our own players quit */
else if (pl_nr == bman.p_nr || pl_nr == bman.p2_nr) {
@ -771,7 +788,8 @@ net_game_fillsockaddr ()
int i;
for (i = 0; i < MAX_PLAYERS; i++)
if (!PS_IS_aiplayer (players[i].state) && players[i].net.addr.host[0] != 0 && players[i].net.addr.host[0] != 0)
if (!PS_IS_aiplayer (players[i].state) && players[i].net.addr.host[0] != 0
&& players[i].net.addr.host[0] != 0)
dns_filladdr (players[i].net.addr.host, LEN_SERVERNAME,
players[i].net.addr.port, LEN_PORT, bman.net_ai_family,
&players[i].net.addr.sAddr);
@ -784,7 +802,7 @@ net_send_servermode ()
int i;
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i))
if (NET_CANSEND (i))
send_servermode (&players[i].net.addr, i);
if (bman.notifygamemaster && GT_MP_PTPM)
@ -803,8 +821,8 @@ net_send_players ()
if (NET_CANSEND (j))
for (i = 0; i < MAX_PLAYERS; i++)
send_playerid (&players[j].net.addr, players[i].name,
players[i].net.addr.host, players[i].net.addr.port, i,
players[i].gfx_nr, players[i].team_nr, players[i].net.flags);
players[i].net.addr.host, players[i].net.addr.port,
i, players[i].gfx_nr, players[i].team_nr, players[i].net.flags);
};
@ -832,7 +850,7 @@ net_send_chat (char *text, signed char notigamesrv)
int i;
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i))
if (NET_CANSEND (i))
send_chat (&players[i].net.addr, text);
};
@ -845,20 +863,22 @@ net_game_send_ill (int p_nr)
d_printf ("net_game_send_ill (%d)\n", p_nr);
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i))
if (NET_CANSEND (i))
send_ill (&players[i].net.addr, p_nr, &players[p_nr]);
};
/* send to all players the drop item list */
void net_game_send_dropitems (int pl_nr, _flyingitem **fiptr, int cnt) {
void
net_game_send_dropitems (int pl_nr, _flyingitem ** fiptr, int cnt)
{
int i;
d_printf ("net_game_send_dropitems (%d): %d items droppped\n", pl_nr, cnt);
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i))
if (NET_CANSEND (i))
send_dropitems (&players[i].net.addr, pl_nr, fiptr, cnt);
};
@ -904,7 +924,7 @@ net_game_send_special (int pl_nr, int ex_nr, int type)
return;
for (pl = 0; pl < MAX_PLAYERS; pl++)
if (NET_CANSEND(pl))
if (NET_CANSEND (pl))
send_special (&players[pl].net.addr, pl_nr, type, ex_nr);
};
@ -921,7 +941,7 @@ net_send_updateinfo ()
d_printf ("Send Updateinfo\n");
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i))
if (NET_CANSEND (i))
send_updateinfo (&players[i].net.addr);
};
@ -938,15 +958,18 @@ net_send_mapinfo ()
d_printf ("Send Mapinfo\n");
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i))
if (NET_CANSEND (i))
send_mapinfo (&players[i].net.addr);
};
/* send an update about the game to all clients */
void send_ogc_update () {
int i, j;
void
send_ogc_update ()
{
int i,
j;
char status[10];
if (!bman.notifygamemaster || GT_MP_PTPS)
@ -973,12 +996,15 @@ void send_ogc_update () {
sprintf (status, "error");
break;
}
ogc_sendgamestatus (bman.sock, "BomberClone", VERSION, bman.gamename, j, bman.maxplayer, status);
ogc_sendgamestatus (bman.sock, "BomberClone", VERSION, bman.gamename, j, bman.maxplayer,
status);
};
/* send the respawn data to all clients and with the new position of the player */
void net_game_send_respawn (int pl_nr) {
void
net_game_send_respawn (int pl_nr)
{
int pl;
d_printf ("Send Respawn Data %d New Position (%d,%d)\n", pl_nr);
@ -987,6 +1013,6 @@ void net_game_send_respawn (int pl_nr) {
return;
for (pl = 0; pl < MAX_PLAYERS; pl++)
if (NET_CANSEND(pl))
if (NET_CANSEND (pl))
send_respawn (&players[pl].net.addr, pl_nr);
};

@ -67,7 +67,8 @@ do_error (struct pkg_error *data, _net_addr * addr)
network_shutdown ();
menu_displaymessage ("Network Error", "Got Error from: %s:%s\nMessage:%s", addr->host, addr->port, data->text);
menu_displaymessage ("Network Error", "Got Error from: %s:%s\nMessage:%s", addr->host,
addr->port, data->text);
if (data->nr == 1)
return -1;
else
@ -115,25 +116,31 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
}
/* 3) check if we have a password */
d_printf ("Password Check Server:\"%s\" Client:\"%s\" %d, %d\n", bman.password, p_jg->password, strlen (bman.password), strlen (p_jg->password));
if (bman.passwordenabled && (strncmp (bman.password, p_jg->password, LEN_PASSWORD) || strlen (bman.password) != strlen (p_jg->password))) {
d_printf ("Password Check Server:\"%s\" Client:\"%s\" %d, %d\n", bman.password,
p_jg->password, strlen (bman.password), strlen (p_jg->password));
if (bman.passwordenabled && (strncmp (bman.password, p_jg->password, LEN_PASSWORD)
|| strlen (bman.password) != strlen (p_jg->password))) {
send_error (addr, "This game is Password protected. Your Password is wrong.");
return;
}
/* find a free place for the player and add the player to the game */
if (GS_WAITRUNNING && GT_MP_PTPM) {
int j, freeslot;
int j,
freeslot;
/* find a free playerslot and check if this player isn't already in the list */
for (i = -1, freeslot = -1, j = 0; j < MAX_PLAYERS; j++) {
if (!PS_IS_used (players[j].state) && freeslot == -1) freeslot = j;
if (!PS_IS_used (players[j].state) && freeslot == -1)
freeslot = j;
if (strncmp (players[j].net.addr.host, addr->host, LEN_SERVERNAME) == 0
&& strncmp (players[j].net.addr.port, addr->port, LEN_PORT) == 0
&& ((p_jg->secondplayer && (players[j].net.flags & NETF_local2) != 0)
|| (!p_jg->secondplayer && (players[j].net.flags & NETF_local2) == 0))) i = j;
|| (!p_jg->secondplayer && (players[j].net.flags & NETF_local2) == 0)))
i = j;
}
if (i == -1) i = freeslot;
if (i == -1)
i = freeslot;
if ((i >= 0) && (i < MAX_PLAYERS) && (i < bman.maxplayer)) {
/* free player slot found ... fill in data */
@ -234,11 +241,13 @@ send_joingame (_net_addr * addr, char *name, int secondplayer)
*** This packet will be send from one player to the other the
*** current server will only get this packet if a connection test was positive
***/
void do_contest (struct pkg_contest *ct_pkg, _net_addr *addr) {
void
do_contest (struct pkg_contest *ct_pkg, _net_addr * addr)
{
d_printf ("do_contest (pl_nr = %d) from=%d to=%d\n", addr->pl_nr, ct_pkg->from, ct_pkg->to);
if (addr->pl_nr >= MAX_PLAYERS
|| (addr->pl_nr == -1 && PS_IS_netplayer(players[ct_pkg->from].state))) {
|| (addr->pl_nr == -1 && PS_IS_netplayer (players[ct_pkg->from].state))) {
d_printf (" addr->pl_nr out of range (0-MAX_PLAYERS)\n");
return;
}
@ -264,14 +273,18 @@ void do_contest (struct pkg_contest *ct_pkg, _net_addr *addr) {
}
void send_contest (_net_addr * addr, int from, int to, int ackreq) {
void
send_contest (_net_addr * addr, int from, int to, int ackreq)
{
struct pkg_contest ct_pkg;
d_printf ("send_contest addr->id:%d, from:%d, to:%d\n", addr->pl_nr, from, to);
ct_pkg.h.typ = PKG_contest;
if (ackreq) ct_pkg.h.flags = PKGF_ackreq;
else ct_pkg.h.flags = 0;
if (ackreq)
ct_pkg.h.flags = PKGF_ackreq;
else
ct_pkg.h.flags = 0;
ct_pkg.h.len = HTON16 (sizeof (struct pkg_contest));
ct_pkg.from = from;
@ -306,13 +319,15 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
/* Send all connected players the new PlayerID, except to the new player */
pl = &players[addr->pl_nr];
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i) && addr->pl_nr != i)
if (NET_CANSEND (i) && addr->pl_nr != i)
send_playerid (&players[i].net.addr, pl->name, pl->net.addr.host,
pl->net.addr.port, pl->net.addr.pl_nr, pl->gfx_nr,
pl->team_nr, pl->net.flags);
for (i = 0; i < MAX_PLAYERS; i++)
send_playerid (addr, players[i].name, players[i].net.addr.host, players[i].net.addr.port, i, players[i].gfx_nr, players[i].team_nr, players[i].net.flags);
send_playerid (addr, players[i].name, players[i].net.addr.host,
players[i].net.addr.port, i, players[i].gfx_nr, players[i].team_nr,
players[i].net.flags);
}
/*
@ -326,7 +341,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
pl->net.timestamp = timestamp;
pl->net.pingreq = pl->net.pingack + 5;
if (GT_MP_PTPS) pl->net.flags = p_id->netflags;
if (GT_MP_PTPS)
pl->net.flags = p_id->netflags;
if (p_id->host[0] != 0) {
pl->net.addr.pl_nr = addr->pl_nr;
strncpy (pl->net.addr.host, p_id->host, LEN_SERVERNAME);
@ -339,7 +355,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
else if (PS_IS_used (p_id->state)) {
strncpy (pl->net.addr.host, players[bman.p_servnr].net.addr.host, LEN_SERVERNAME);
strncpy (pl->net.addr.port, players[bman.p_servnr].net.addr.port, LEN_PORT);
memcpy (&pl->net.addr.sAddr, &players[bman.p_servnr].net.addr.sAddr, sizeof (struct _sockaddr));
memcpy (&pl->net.addr.sAddr, &players[bman.p_servnr].net.addr.sAddr,
sizeof (struct _sockaddr));
}
/* Check if we have to make a network test.. only client to client
@ -362,7 +379,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
else
pl->state &= (0xff - PSF_net);
if (pl->gfx_nr != p_id->gfx_nr) player_set_gfx (pl, p_id->gfx_nr);
if (pl->gfx_nr != p_id->gfx_nr)
player_set_gfx (pl, p_id->gfx_nr);
strncpy (pl->name, p_id->name, LEN_PLAYERNAME);
if (GT_MP_PTPS) {
@ -370,8 +388,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
pl->wins = NTOH16 (p_id->wins);
pl->team_nr = p_id->team_nr;
if (pl->team_nr >= 0 && pl->team_nr < MAX_TEAMS) {
teams[pl->team_nr].points = NTOH16(p_id->team_points);
teams[pl->team_nr].wins = NTOH16(p_id->team_wins);
teams[pl->team_nr].points = NTOH16 (p_id->team_points);
teams[pl->team_nr].wins = NTOH16 (p_id->team_wins);
}
}
@ -457,13 +475,16 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport,
*** Client Side:
*** Get all Teamdata
***/
void do_teamdata (struct pkg_teamdata *td, _net_addr * addr) {
void
do_teamdata (struct pkg_teamdata *td, _net_addr * addr)
{
int i;
if (addr->pl_nr == -1)
return;
d_printf ("do_teamdata (addr->pl_nr: %d): team:%d col:%d wins:%d\n", addr->pl_nr, td->team_nr, td->col, td->wins);
d_printf ("do_teamdata (addr->pl_nr: %d): team:%d col:%d wins:%d\n", addr->pl_nr, td->team_nr,
td->col, td->wins);
if (addr->pl_nr == bman.p_servnr) { /* packet comes from the server */
if (td->team_nr >= 0 && td->team_nr < MAX_TEAMS) {
@ -485,7 +506,9 @@ void do_teamdata (struct pkg_teamdata *td, _net_addr * addr) {
}
void send_teamdata (_net_addr * addr, int team_nr) {
void
send_teamdata (_net_addr * addr, int team_nr)
{
struct pkg_teamdata td;
d_printf ("send_teamdata (%s:%s) team:%d\n", addr->host, addr->port, team_nr);
@ -523,17 +546,20 @@ do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
/* if we just have connected the bman.p_nr is still -1, so we handle the
servermode packet still alittle diffrent */
if ((!s_mod->lplayer2 && bman.p_nr == -1) || (s_mod->lplayer2 && bman.p2_nr == -1)) {
d_printf (" Server gave us: p_nr: %d(old:%d), p_servnr: %d(old:%d)\n", s_mod->p_nr,bman.p_nr, s_mod->p_servnr, bman.p_servnr);
d_printf (" Server gave us: p_nr: %d(old:%d), p_servnr: %d(old:%d)\n", s_mod->p_nr,
bman.p_nr, s_mod->p_servnr, bman.p_servnr);
/* set the p_servnr to the playerslot which is the server */
if (bman.p_servnr != s_mod->p_servnr) {
memcpy (&players[s_mod->p_servnr].net, &players[bman.p_servnr].net, sizeof (_net_player));
memcpy (&players[s_mod->p_servnr].net, &players[bman.p_servnr].net,
sizeof (_net_player));
bzero (&players[bman.p_servnr], sizeof (_net_player));
bman.p_servnr = s_mod->p_servnr;
}
/* set now the new p_nr number */
if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p_nr == -1 && s_mod->lplayer2 == 0) {
if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p_nr == -1
&& s_mod->lplayer2 == 0) {
bman.p_nr = s_mod->p_nr;
bman.firewall = 1;
players[bman.p_nr].net.flags = NETF_firewall;
@ -545,7 +571,8 @@ do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
send_playerid (addr, NULL, NULL, NULL, -1, -1, -1, 0);
send_teamdata (addr, -1);
}
else if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p2_nr == -1 && s_mod->lplayer2 == 1) {
else if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p2_nr == -1
&& s_mod->lplayer2 == 1) {
bman.p2_nr = s_mod->p_nr;
players[bman.p2_nr].net.flags = NETF_firewall + NETF_local2;
players[bman.p2_nr].state &= (0xFF - PSF_net);
@ -615,9 +642,11 @@ send_servermode (_net_addr * addr, int pl_nr)
s_mod.players = bman.players_nr_s;
s_mod.maxplayer = bman.maxplayer;
s_mod.p_nr = pl_nr;
if (pl_nr >= 0 && pl_nr < MAX_PLAYERS && (players[pl_nr].net.flags & NETF_local2) == NETF_local2)
if (pl_nr >= 0 && pl_nr < MAX_PLAYERS
&& (players[pl_nr].net.flags & NETF_local2) == NETF_local2)
s_mod.lplayer2 = 1;
else s_mod.lplayer2 = 0;
else
s_mod.lplayer2 = 0;
s_mod.p_servnr = bman.p_servnr;
s_mod.last_winner = bman.lastwinner;
s_mod.fieldsize_x = map.size.x;
@ -832,7 +861,8 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
/* player just died */
if (p_dat->p_nr != p_dat->dead_by) {
players[p_dat->dead_by].points++;
if (bman.gametype == GT_team && players[p_dat->dead_by].team_nr >= 0 && players[p_dat->dead_by].team_nr < MAX_TEAMS)
if (bman.gametype == GT_team && players[p_dat->dead_by].team_nr >= 0
&& players[p_dat->dead_by].team_nr < MAX_TEAMS)
teams[players[p_dat->dead_by].team_nr].points++;
net_game_send_player (p_dat->dead_by);
player_died (pl, p_dat->dead_by, 1);
@ -1107,6 +1137,9 @@ send_quit (_net_addr * addr, int pl_nr, int new_server)
q_dat.h.typ = PKG_quit;
q_dat.h.flags = 0;
q_dat.h.len = HTON16 (sizeof (struct pkg_quit));
if (pl_nr == -1)
q_dat.pl_nr = bman.p_nr;
else
q_dat.pl_nr = pl_nr;
q_dat.new_server = new_server;
send_pkg ((struct pkg *) &q_dat, addr);
@ -1116,12 +1149,13 @@ send_quit (_net_addr * addr, int pl_nr, int new_server)
void
do_quit (struct pkg_quit *q_dat, _net_addr * addr)
{
d_printf ("do_quit (%s:%s) pl_nr=%d new_server=%d\n", addr->host, addr->port, q_dat->pl_nr, q_dat->new_server);
d_printf ("do_quit (%s:%s) pl_nr=%d new_server=%d\n", addr->host, addr->port, q_dat->pl_nr,
q_dat->new_server);
if (addr->pl_nr == -1)
return;
bman.updatestatusbar=1;
bman.updatestatusbar = 1;
player_delete (q_dat->pl_nr);
/* the player who send this quit */
@ -1141,7 +1175,8 @@ do_quit (struct pkg_quit *q_dat, _net_addr * addr)
}
}
else if (q_dat->pl_nr == bman.p_servnr && q_dat->new_server == bman.p_servnr)
menu_displaymessage ("Server Quit", "The game closed because you are the only one who is left."
menu_displaymessage ("Server Quit",
"The game closed because you are the only one who is left."
" Or the server could not find any other possible new server.");
};
@ -1346,8 +1381,8 @@ do_updateinfo (struct pkg_updateinfo *stat, _net_addr * addr)
d_printf ("do_updateinfo: the data we have got are not from the server\n");
return;
}
for (i=0;i<MAX_PLAYERS;i++)
if ((i!=bman.p_servnr) && (i!=bman.p_nr)) {
for (i = 0; i < MAX_PLAYERS; i++)
if ((i != bman.p_servnr) && (i != bman.p_nr)) {
players[i].net.net_status = stat->status[i];
players[i].net.net_istep = stat->step[i];
}
@ -1361,7 +1396,7 @@ send_updateinfo (_net_addr * addr)
stat.h.typ = PKG_updateinfo;
stat.h.flags = 0;
stat.h.len = HTON16 (sizeof (struct pkg_updateinfo));
for (i=0;i<MAX_PLAYERS;i++) {
for (i = 0; i < MAX_PLAYERS; i++) {
stat.step[i] = players[i].net.net_istep;
stat.status[i] = players[i].net.net_status;
}
@ -1488,7 +1523,8 @@ void
do_special (struct pkg_special *sp_pkg, _net_addr * addr)
{
d_printf ("do_special (addr %d, pl_nr %d, typ %d)\n", addr->pl_nr, sp_pkg->pl_nr, sp_pkg->typ);
if (addr->pl_nr == -1 || sp_pkg->pl_nr == -1 || sp_pkg->pl_nr == bman.p_nr || sp_pkg->pl_nr == bman.p2_nr)
if (addr->pl_nr == -1 || sp_pkg->pl_nr == -1 || sp_pkg->pl_nr == bman.p_nr
|| sp_pkg->pl_nr == bman.p2_nr)
return;
/* set or use special */
@ -1596,7 +1632,9 @@ do_mapinfo (struct pkg_mapinfo *map_pkg, _net_addr * addr)
/***
*** Respawn Date Handling
***/
void send_respawn (_net_addr * addr, int plnr) {
void
send_respawn (_net_addr * addr, int plnr)
{
struct pkg_respawn r_dat;
r_dat.h.typ = PKG_respawn;
@ -1610,8 +1648,11 @@ void send_respawn (_net_addr * addr, int plnr) {
};
void do_respawn (struct pkg_respawn *r_pkg, _net_addr *addr) {
d_printf ("do_respawn (addr %d, pl_nr %d, pos %d,%d)\n", addr->pl_nr, r_pkg->pl_nr, r_pkg->x, r_pkg->y);
void
do_respawn (struct pkg_respawn *r_pkg, _net_addr * addr)
{
d_printf ("do_respawn (addr %d, pl_nr %d, pos %d,%d)\n", addr->pl_nr, r_pkg->pl_nr, r_pkg->x,
r_pkg->y);
if (addr->pl_nr == -1 || r_pkg->pl_nr == -1)
return;
@ -1641,25 +1682,31 @@ void do_respawn (struct pkg_respawn *r_pkg, _net_addr *addr) {
*** gameinfo packet is used to get some data from a running game
*** just fill in the informations we need and send this packet back.
***/
void do_gameinfo (struct pkg_gameinfo *pgi, _net_addr *addr) {
void
do_gameinfo (struct pkg_gameinfo *pgi, _net_addr * addr)
{
if (GT_MP_PTPM && pgi->password == -1) {
d_printf ("do_gameinfo (from: %s:%s) Broadcast Req: %d\n", addr->host, addr->port, pgi->broadcast);
d_printf ("do_gameinfo (from: %s:%s) Broadcast Req: %d\n", addr->host, addr->port,
pgi->broadcast);
strncpy (pgi->version, VERSION, LEN_VERSION);
pgi->maxplayers = bman.maxplayer;
pgi->curplayers = bman.players_nr_s;
strncpy (pgi->gamename, bman.gamename, LEN_GAMENAME);
send_pkg ((struct pkg*) pgi, addr);
send_pkg ((struct pkg *) pgi, addr);
}
else if (pgi->password != -1)
d_printf ("do_gameinfo (from: %s:%s) ** NO REQUEST **\n", addr->host, addr->port);
else
d_printf ("do_gameinfo (from: %s:%s) ** WE ARE NOT THE MASTER OF THIS GAME **\n", addr->host, addr->port);
d_printf ("do_gameinfo (from: %s:%s) ** WE ARE NOT THE MASTER OF THIS GAME **\n",
addr->host, addr->port);
}
void send_gameinfo (_net_addr * addr, int sock, int broadcast) {
void
send_gameinfo (_net_addr * addr, int sock, int broadcast)
{
struct pkg_gameinfo pgi;
pgi.h.typ = PKG_gameinfo;
@ -1674,7 +1721,8 @@ void send_gameinfo (_net_addr * addr, int sock, int broadcast) {
if (bman.net_ai_family != PF_INET)
pgi.h.flags = pgi.h.flags | PKGF_ipv6;
if (broadcast)
udp_sendbroadcast (sock, (char *) &pgi, NTOH16 (pgi.h.len), &addr->sAddr, bman.net_ai_family);
udp_sendbroadcast (sock, (char *) &pgi, NTOH16 (pgi.h.len), &addr->sAddr,
bman.net_ai_family);
else
udp_send (sock, (char *) &pgi, NTOH16 (pgi.h.len), &addr->sAddr, bman.net_ai_family);
};
@ -1700,8 +1748,7 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
/* find packet */
for (i = 0, pos = -1; (i < PKG_IN_INDEX_NUM && pos == -1); i++)
if (inpkg_index[i].pl_nr == addr->pl_nr
&& inpkg_index[i].typ == typ
&& inpkg_index[i].id == id)
&& inpkg_index[i].typ == typ && inpkg_index[i].id == id)
pos = i;
if (pos == -1) {
@ -1719,11 +1766,13 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
/* delete all old pkg indexes about a player */
void
inpkg_delplayer (int pl_nr) {
inpkg_delplayer (int pl_nr)
{
int i;
for (i = 0; i < PKG_IN_INDEX_NUM; i++)
if (inpkg_index[i].pl_nr == pl_nr) inpkg_index[i].pl_nr = -1;
if (inpkg_index[i].pl_nr == pl_nr)
inpkg_index[i].pl_nr = -1;
}
@ -1733,7 +1782,8 @@ send_pkg (struct pkg *packet, _net_addr * addr)
{
/* check if the packet would be send to
* an AI_Player, so ignore it. */
if ((addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) && PS_IS_aiplayer (players[addr->pl_nr].state))
if ((addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
&& PS_IS_aiplayer (players[addr->pl_nr].state))
return;
/* set the id for the packet and the network flags
@ -1767,8 +1817,7 @@ fwd_pkg (struct pkg *packet, _net_addr * addr)
if ((!PS_IS_aiplayer (players[pl].state)) && PS_IS_netplayer (players[pl].state)
&& ((players[addr->pl_nr].net.flags & NETF_firewall) == NETF_firewall
|| (players[pl].net.flags & NETF_firewall) == NETF_firewall)
&& pl != addr->pl_nr
&& (players[pl].net.flags & NETF_local2) == 0)
&& pl != addr->pl_nr && (players[pl].net.flags & NETF_local2) == 0)
send_pkg (packet, &players[pl].net.addr);
}
else if (packet->h.typ > PKG_quit)
@ -1794,7 +1843,8 @@ do_pkg (struct pkg *packet, _net_addr * addr)
* check if the packet is from a player in the game and not from someone else
* this exception is only for PKG_joingame, PKG_error */
addr->pl_nr = get_player_nr (addr->host, addr->port);
if ((addr->pl_nr < 0 || addr->pl_nr >= MAX_PLAYERS) && packet->h.typ > PKG_joingame && PS_IS_netplayer (players[addr->pl_nr].state)) {
if ((addr->pl_nr < 0 || addr->pl_nr >= MAX_PLAYERS) && packet->h.typ > PKG_joingame
&& PS_IS_netplayer (players[addr->pl_nr].state)) {
d_printf ("do_pkg: error addr->pl_nr out of range\n");
return 0;
}

Loading…
Cancel
Save