From 2c43dfc8f0be2354be9b696a9370a84d8b511e52 Mon Sep 17 00:00:00 2001 From: stpohle Date: Sun, 10 Apr 2005 00:22:16 +0000 Subject: [PATCH] formated part of the source, fixed: send_quit --- include/basic.h | 154 ++++----- include/bomb.h | 60 ++-- src/configuration.c | 29 +- src/game.c | 20 +- src/network.c | 710 +++++++++++++++++++------------------ src/packets.c | 826 +++++++++++++++++++++++--------------------- 6 files changed, 940 insertions(+), 859 deletions(-) diff --git a/include/basic.h b/include/basic.h index 62302ce..b384ba6 100644 --- a/include/basic.h +++ b/include/basic.h @@ -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_ @@ -14,21 +14,21 @@ #define GAME_SPECIAL_ITEMSROW 3 #define GAME_SPECIAL_ITEMSPUSH 3 #define GAME_SPECIAL_ITEMSKICK 3 -#define GAME_MAX_TUNNELS 4 // number of tunnel entrys -#define GAME_TIMEOUT 600.0 // game timeout 10min) -#define GAME_OVERTIMEOUT 5.0 // second of remaining the last player -#define GAME_TUNNEL_TO 0.5 // wait 0.5 seconds +#define GAME_MAX_TUNNELS 4 // number of tunnel entrys +#define GAME_TIMEOUT 600.0 // game timeout 10min) +#define GAME_OVERTIMEOUT 5.0 // second of remaining the last player +#define GAME_TUNNEL_TO 0.5 // wait 0.5 seconds #define HURRYWARN_TO_BLINKING 0.10 #define EXPLOSION_SAVE_DISTANCE 0.25 #define EXPLOSION_GROW_SPEED 0.75f #define SPECIAL_TRIGGER_TIMEOUT 15 -#define SPECIAL_TRIGGER_NUMUSE 5 // 0=unlimited +#define SPECIAL_TRIGGER_NUMUSE 5 // 0=unlimited #define SPECIAL_TRIGGER_TIME 25 #define SPECIAL_ROW_TIME 30 #define SPECIAL_PUSH_TIME 50 #define SPECIAL_KICK_TIME 30 -#define SPECIAL_KICK_MAXDIST 8 // maximum distance allowed +#define SPECIAL_KICK_MAXDIST 8 // maximum distance allowed #define START_BOMBS 1 #define START_RANGE 2 @@ -47,8 +47,8 @@ #define MAX_FIELDSIZE_Y 31 #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*/ +#define MAX_FIELDANIMATION 2048 /* number of points on the field to be animated exploding + stoned or powerups */ #define EXPLOSIONTIMEOUT 0.5 #define ANI_FIRETIMEOUT 2 @@ -80,129 +80,129 @@ #define UDP_TIMEOUT 15000 #define BUF_SIZE 1024 -#define AUTOSTART 20 /* dedicated server autostart */ +#define AUTOSTART 20 /* dedicated server autostart */ #define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (__result >= 0) && (players[__result].gfx_nr != __gfx_nr); __result--); -#define CUTINT(__x) (__x-floorf(__x)) // cut the integer part off -#define postofield(__x) ((int)(rintf(__x))) // position to int with rounding +#define CUTINT(__x) (__x-floorf(__x)) // cut the integer part off +#define postofield(__x) ((int)(rintf(__x))) // position to int with rounding #define UINT16_HALF 32767 #include enum _backgound { // to load some diffrent logos.. - BG_start = 0, - BG_net, - BG_conf + BG_start = 0, + BG_net, + BG_conf }; enum _gametype { - GT_bomberman = 0, - GT_deathmatch, - GT_team + GT_bomberman = 0, + GT_deathmatch, + GT_team }; enum _gamestate { - GS_startup = 0, - GS_quit, - GS_wait, // waiting for players to join - GS_update, - GS_ready, - GS_running + GS_startup = 0, + GS_quit, + GS_wait, // waiting for players to join + GS_update, + GS_ready, + GS_running }; enum _maptype { - MAPT_random = -1, // random map - MAPT_normal = 0, // a normal map - MAPT_tunnel, // a map with tunnels - - MAPT_max + MAPT_random = -1, // random map + MAPT_normal = 0, // a normal map + MAPT_tunnel, // a map with tunnels + + MAPT_max }; enum _fieldtype { - FT_nothing = 0, // Nothing in here - FT_stone, // Stones you can bomb away - FT_block, // Stones which can't bomb away - FT_tunnel, // the tunnel item - FT_death, // The bad Powerup - FT_fire, // The fire Powerup - FT_bomb, // The bomb Powerup - FT_shoe, // The shoe Powerup - FT_mixed, // The mixed Powerup - FT_sp_trigger, // The Triggered bomb Special - FT_sp_row, // The bomb-row special - FT_sp_push, // The push-boms special - FT_sp_moved, // The moved-boms special - FT_sp_liquid, // The liquid-bomb special - FT_sp_kick, // The kick-bomb special - FT_max // just to know how many types there are + FT_nothing = 0, // Nothing in here + FT_stone, // Stones you can bomb away + FT_block, // Stones which can't bomb away + FT_tunnel, // the tunnel item + FT_death, // The bad Powerup + FT_fire, // The fire Powerup + FT_bomb, // The bomb Powerup + FT_shoe, // The shoe Powerup + FT_mixed, // The mixed Powerup + FT_sp_trigger, // The Triggered bomb Special + FT_sp_row, // The bomb-row special + FT_sp_push, // The push-boms special + FT_sp_moved, // The moved-boms special + FT_sp_liquid, // The liquid-bomb special + FT_sp_kick, // The kick-bomb special + FT_max // just to know how many types there are }; -extern const char *ft_filenames[]; // declared in tileset.c +extern const char *ft_filenames[]; // declared in tileset.c enum _poweruptypes { - PWUP_good = 0, - PWUP_bad, - PWUP_special, - PWUP_max + PWUP_good = 0, + PWUP_bad, + PWUP_special, + PWUP_max }; enum _direction { // to handle directions better - left = 0, - right, - up, - down + left = 0, + right, + up, + down }; enum _mapselection { - MAPS_select = 0, - MAPS_randmap, - MAPS_randgen + MAPS_select = 0, + MAPS_randmap, + MAPS_randgen }; enum _mstatus { - MS_normal = 0, - MS_hurrywarn, - MS_hurry, // mapsize will go down - MS_dropitems, // alot of items will be droppen randomly into the game - - MS_max + MS_normal = 0, + MS_hurrywarn, + MS_hurry, // mapsize will go down + MS_dropitems, // alot of items will be droppen randomly into the game + + MS_max }; enum _help_page { - HP_howto0 = 0, - HP_powerup0, - HP_powerup1, - HP_powerup2, - HP_keyboard0, - HP_credit0, - HP_credit1, - HP_max + HP_howto0 = 0, + HP_powerup0, + HP_powerup1, + HP_powerup2, + HP_keyboard0, + HP_credit0, + HP_credit1, + HP_max }; struct { - Sint16 x; - Sint16 y; + Sint16 x; + Sint16 y; } typedef _point; struct { - float x; - float y; + float x; + float y; } typedef _pointf; struct __charlist { - char text[LEN_CHARENTRY]; - struct __charlist *next; + char text[LEN_CHARENTRY]; + struct __charlist *next; } typedef _charlist; extern _point dir_change[]; diff --git a/include/bomb.h b/include/bomb.h index 69399a5..7d4c783 100644 --- a/include/bomb.h +++ b/include/bomb.h @@ -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 */ @@ -7,51 +7,51 @@ enum _bombstate { - BS_off = 0, - BS_ticking, - BS_exploding, - BS_trigger + BS_off = 0, + BS_ticking, + BS_exploding, + BS_trigger }; enum _bombmode { - BM_normal = 0, - BM_pushed, - BM_moving, - BM_liquid, - BM_kicked + BM_normal = 0, + BM_pushed, + BM_moving, + BM_liquid, + BM_kicked }; struct { - _pointf pos; // lower byte = _X Higher Byte = FX - struct __bomb_id { // save the bomb id - signed char p; // playernumber of this bomb - 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? - 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 - unsigned char state; // state of the bomb BS_* - unsigned char mode; // mode of the bomb BM_* - int ex_nr; // explosion number - _point dest; // destination to move the bomb to - float speed; // bomb moving speed + _pointf pos; // lower byte = _X Higher Byte = FX + struct __bomb_id { // save the bomb id + signed char p; // playernumber of this bomb + 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? + 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 + unsigned char state; // state of the bomb BS_* + unsigned char mode; // mode of the bomb BM_* + int ex_nr; // explosion number + _point dest; // destination to move the bomb to + float speed; // bomb moving speed } typedef _bomb; // 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 diff --git a/src/configuration.c b/src/configuration.c index cbaf098..0374071 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -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 @@ -134,9 +134,9 @@ config_init (int argc, char **argv) bman.start_speed = START_SPEED; bman.start_range = START_RANGE; bman.bomb_tickingtime = BOMB_TIMEOUT; - bman.dropitemsondeath = 0; - d_printf ("\n\n ***** Bomberclone Version %s \n\n", VERSION); - config_read (); + bman.dropitemsondeath = 0; + d_printf ("\n\n ***** Bomberclone Version %s \n\n", VERSION); + config_read (); ReadPrgArgs (argc, argv); @@ -686,22 +686,23 @@ ReadPrgArgs (int argc, char **argv) if (!strcmp (argv[i], "-name")) strncpy (bman.playername, argv[++i], LEN_PLAYERNAME); if (!strcmp (argv[i], "-name2")) - strncpy (bman.player2name, argv[++i], LEN_PLAYERNAME); - if (!strcmp (argv[i], "-gamename")) - strncpy (bman.gamename, argv[++i], LEN_GAMENAME); + strncpy (bman.player2name, argv[++i], LEN_PLAYERNAME); + if (!strcmp (argv[i], "-gamename")) + strncpy (bman.gamename, argv[++i], LEN_GAMENAME); if (!strcmp (argv[i], "-ogc")) bman.notifygamemaster = atoi (argv[++i]); if (!strcmp (argv[i], "-broadcast")) bman.broadcast = atoi (argv[++i]); if (!strcmp (argv[i], "-debug")) debug = atoi (argv[++i]); - if (!strcmp (argv[i], "-dedicated")) { - if (bman.minplayers <= 1) - bman.minplayers = 2; - bman.dedicated = 1; - } - if (!strcmp (argv[i], "-autostart")) - bman.autostart = atoi (argv[++i]); + if (!strcmp (argv[i], "-dedicated")) { + 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]); } }; diff --git a/src/game.c b/src/game.c index 1b66d72..d8e57bf 100644 --- a/src/game.c +++ b/src/game.c @@ -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 @@ -217,11 +217,12 @@ void game_keys_loop () { void game_loop () { - SDL_Event event; - int done = 0, eventstate; + SDL_Event event; + int done = 0, eventstate; + int ready_timestamp = 0; - if (GT_MP) - net_game_fillsockaddr (); + if (GT_MP) + net_game_fillsockaddr (); menu = NULL; bman.updatestatusbar = 1; // force an update @@ -281,10 +282,13 @@ 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; - net_send_servermode (); + if (ready && (timestamp - ready_timestamp) > 2500) { + bman.state = GS_running; + net_send_servermode (); + } } diff --git a/src/network.c b/src/network.c index 2d6aada..c688471 100644 --- a/src/network.c +++ b/src/network.c @@ -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; @@ -89,9 +90,9 @@ net_dyn_pkgoption () int network_init () { - char host[LEN_SERVERNAME]; - char port[LEN_PORT]; - + char host[LEN_SERVERNAME]; + char port[LEN_PORT]; + /* we need it for the windows winsock */ #ifdef _WIN32 WSADATA wsaData; @@ -102,15 +103,15 @@ network_init () } #endif - if (bman.net_ai_family == PF_INET) - sprintf (host, "IPv4"); + if (bman.net_ai_family == PF_INET) + sprintf (host, "IPv4"); #ifndef _WIN32 - else if (bman.net_ai_family == PF_INET6) - sprintf (host, "IPv6"); + else if (bman.net_ai_family == PF_INET6) + sprintf (host, "IPv6"); #endif - else - sprintf (host, "IPv (unknown)"); - d_printf ("Network Init with %s.\n", host); + else + sprintf (host, "IPv (unknown)"); + d_printf ("Network Init with %s.\n", host); bman.sock = -1; timestamp = SDL_GetTicks (); @@ -125,11 +126,11 @@ network_init () return -1; } - if (bman.notifygamemaster) { - network_server_port (bman.ogcserver, host, LEN_SERVERNAME, port, LEN_PORT); - if (ogc_init (bman.ogc_port, host, port, "BomberClone", bman.net_ai_family) == 0) - bman.notifygamemaster = 0; - } + if (bman.notifygamemaster) { + network_server_port (bman.ogcserver, host, LEN_SERVERNAME, port, LEN_PORT); + if (ogc_init (bman.ogc_port, host, port, "BomberClone", bman.net_ai_family) == 0) + bman.notifygamemaster = 0; + } // we have got our socket.. so now allocate the memory for the resend_cache resend_cache.data = (char *) malloc (PKG_RESENDCACHE_SIZE); @@ -146,35 +147,37 @@ void network_shutdown () { int i; - int new_server = bman.p_servnr; - d_printf ("network_shutdown\n"); + int new_server = bman.p_servnr; + d_printf ("network_shutdown\n"); if (GT_MP_PTPM) { - d_printf ("Server Quit Send information\n"); - - /* 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) - new_server = i; - } - - d_printf ("netword_shutdown: new server set to: %d\n", new_server); - + d_printf ("Server Quit Send information\n"); + + /* 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) + 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) { send_quit (&players[bman.p_servnr].net.addr, bman.p_nr, bman.p_servnr); - if (IS_LPLAYER2) - send_quit (&players[bman.p_servnr].net.addr, bman.p2_nr, bman.p_servnr); - } + if (IS_LPLAYER2) + send_quit (&players[bman.p_servnr].net.addr, bman.p2_nr, bman.p_servnr); + } - if (bman.notifygamemaster) { + if (bman.notifygamemaster) { ogc_sendgamequit (bman.sock); - ogc_shutdown (); - } - + ogc_shutdown (); + } + udp_close (bman.sock); if (resend_cache.data != NULL) @@ -184,7 +187,7 @@ network_shutdown () resend_cache.fill = -1; bman.p_nr = -1; - bman.sock = -1; + bman.sock = -1; #ifdef _WIN32 WSACleanup (); #endif @@ -197,7 +200,7 @@ net_check_timeout (int pl_nr) int timeout = UDP_TIMEOUT; if ((players[pl_nr].state & (PSF_net + PSF_used + PSF_ai)) == (PSF_used + PSF_net) - && ((players[pl_nr].net.flags & NETF_local2) == 0) + && ((players[pl_nr].net.flags & NETF_local2) == 0) && timestamp - players[pl_nr].net.timestamp > timeout && players[pl_nr].net.pingreq != players[pl_nr].net.pingack) { d_printf ("net_check_timeout pl_nr=%d, ack=%d, req=%d, timediff=%d\n", pl_nr, @@ -205,11 +208,10 @@ 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) + && ((players[pl_nr].net.flags & NETF_local2) == 0) && timestamp - players[pl_nr].net.timestamp > timeout && players[pl_nr].net.pingreq == players[pl_nr].net.pingack) { d_printf ("net_check_timeout pl_nr=%d, ack=%d, req=%d, timediff=%d\n", pl_nr, @@ -249,13 +251,13 @@ network_loop () while (inlen > 0) { do_pkg (packet, &addr); - + // printf ("Network : inlen (%d) typ (%d) Size (%d)\n", inlen, packet->typ, pkglen); 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); } /* @@ -298,121 +300,123 @@ void draw_netupdatestate (char st) { char text[255]; - unsigned char b; + unsigned char b; int y = 0, - b1, - z, - zx=200, - i, - j, - s=map.size.y+MAX_PLAYERS+GAME_MAX_TUNNELS; + b1, + z, + zx = 200, + i, + j, + s = map.size.y + MAX_PLAYERS + GAME_MAX_TUNNELS; SDL_Rect src, dest; - z=gfx.res.x-zx-30-8; - for (i = 0; i < MAX_PLAYERS; i++) + z = gfx.res.x - zx - 30 - 8; + for (i = 0; i < MAX_PLAYERS; i++) if (PS_IS_used (players[i].state)) { y += 50; if (st) { - redraw_logo (0, y, gfx.res.x, y + 50); - - if (players[i].gfx_nr != -1) { - dest.w = src.w = players[i].gfx->small_image->w; - dest.h = src.h = players[i].gfx->small_image->h; - src.x = players[i].gfx->small_image->w * down; - src.y = 0; - - dest.x = 50; - dest.y = y; - - SDL_BlitSurface (players[i].gfx->small_image, &src, gfx.screen, &dest); - gfx_blitupdaterectadd (&dest); - } - - dest.x = zx; - dest.y = y; - 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; - gfx_blit (menulistimages[1][2], NULL, gfx.screen, &dest, 10000); - // draw the bottom left and right of the list - 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;jsmall_image->w; + dest.h = src.h = players[i].gfx->small_image->h; + src.x = players[i].gfx->small_image->w * down; + src.y = 0; + + dest.x = 50; + dest.y = y; + + SDL_BlitSurface (players[i].gfx->small_image, &src, gfx.screen, &dest); + gfx_blitupdaterectadd (&dest); + } + + dest.x = zx; + dest.y = y; + 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; + gfx_blit (menulistimages[1][2], NULL, gfx.screen, &dest, 10000); + // draw the bottom left and right of the list + 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; + gfx_blit (menulistimages[1][1], NULL, gfx.screen, &dest, 10000); + 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; + gfx_blit (menulistimages[1][3], NULL, gfx.screen, &dest, 10000); + 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){ - case 3: - sprintf (text, "Getting Tunnel Data %d.", players[i].net.net_status); - 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; - 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; - break; - default: - sprintf (text, "Ready"); - b=255; - break; - } - - //draw bar - 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.xw; - 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) { - dest.w = menubuttonimages[2][1]->w; - dest.h = menubuttonimages[2][1]->h; - for(j=menubuttonimages[2][0]->w;jw; - j+=menubuttonimages[2][1]->w) { - dest.x=j+zx+4; - gfx_blit (menubuttonimages[2][1], NULL, gfx.screen, &dest, 10000); - } - } - } - // 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); - font_draw (80, y + 35, text, 0, 4); - } - } - gfx_blitdraw (); - return; + font_draw (80, y, text, 0, 4); + } + // calc percentage, this a range from 0 to 255) + 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; + 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; + 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; + break; + default: + sprintf (text, "Ready"); + b = 255; + break; + } + + //draw bar + 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.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) { + 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; + gfx_blit (menubuttonimages[2][1], NULL, gfx.screen, &dest, 10000); + } + } + } + // 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); + font_draw (80, y + 35, text, 0, 4); + } + } + gfx_blitdraw (); + return; } /* @@ -423,8 +427,8 @@ net_send_playerid (int pl_nr) { int i; - d_printf ("net_send_playerid pl_nr:%d\n", pl_nr); - + d_printf ("net_send_playerid pl_nr:%d\n", pl_nr); + if (GT_MP_PTPM) { /* Send to all connected clients the update @@ -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,11 +448,13 @@ 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)) - player_set_gfx (&players[pl_nr], players[pl_nr].gfx_nr); + 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); }; @@ -459,35 +467,36 @@ void net_transmit_gamedata () { int done = 0, - keypressed = 0, - x, - y, // network upload status for one step - p, - i, - net_istep; // network init step + keypressed = 0, + x, + y, // network upload status for one step + p, + i, + net_istep; // network init step SDL_Event event; Uint8 *keys; Uint32 downtimestamp = 0; - if (!bman.dedicated) { - draw_logo (); + if (!bman.dedicated) { + draw_logo (); + + if (GT_MP_PTPM) + font_draw (100, 0, "Waiting for the Clients", 1, 0); + else + font_draw (100, 0, "Downloading Data", 1, 0); + } - if (GT_MP_PTPM) - font_draw (100, 0, "Waiting for the Clients", 1, 0); - else - font_draw (100, 0, "Downloading Data", 1, 0); - } - /* prepare everything for the loop */ 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) - players[x].net.net_istep = 0; - else - players[x].net.net_istep = 3; + 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; } y = -1; @@ -495,13 +504,13 @@ net_transmit_gamedata () net_istep = 0; else net_istep = 3; - - if (!bman.dedicated) { - draw_netupdatestate (1); - SDL_Flip (gfx.screen); - } - - downtimestamp = timestamp; + + if (!bman.dedicated) { + draw_netupdatestate (1); + SDL_Flip (gfx.screen); + } + + downtimestamp = timestamp; while (!done && (bman.state == GS_update || (GT_MP_PTPS && net_istep != 0))) { /* the network thing */ @@ -509,12 +518,13 @@ net_transmit_gamedata () /* if PTPM check if all players are ready */ if (GT_MP_PTPM) { - if (timestamp - downtimestamp > TIME_UPDATEINFO) { - downtimestamp = timestamp; - 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) + if (timestamp - downtimestamp > TIME_UPDATEINFO) { + downtimestamp = timestamp; + net_send_updateinfo (); + } + 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; @@ -524,19 +534,20 @@ net_transmit_gamedata () /* if PTPS get all data */ if (GT_MP_PTPS) { - if (net_istep == 3) { - /* - get tunneldata - */ - if ((y < GAME_MAX_TUNNELS - 1 && y == players[bman.p_nr].net.net_status) - || y == -1) { - y++; - 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*/ + if (net_istep == 3) { + /* + get tunneldata + */ + if ((y < GAME_MAX_TUNNELS - 1 && y == players[bman.p_nr].net.net_status) + || y == -1) { + y++; + 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 */ y--; } else if (y == GAME_MAX_TUNNELS - 1 && players[bman.p_nr].net.net_status == y) { @@ -545,12 +556,12 @@ net_transmit_gamedata () players[bman.p_nr].net.net_istep = --net_istep; players[bman.p_nr].net.net_status = -1; } - } - + } + if (net_istep == 2) { - /* - get field data - */ + /* + get field data + */ if ((y < map.size.y - 1 && y == players[bman.p_nr].net.net_status) || y == -1) { /* send field data req */ @@ -572,17 +583,18 @@ net_transmit_gamedata () } if (net_istep == 1) { - /* - get player data - */ - if ((y < MAX_PLAYERS - 1 && y == players[bman.p_nr].net.net_status) || y == -1) { + /* + get player data + */ + 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--; } @@ -595,42 +607,42 @@ net_transmit_gamedata () send_playerstatus (&players[bman.p_servnr].net.addr, bman.p_nr, 0, 0); } } - + if (net_istep == 0 && players[bman.p_nr].net.net_status == -1 && timestamp - downtimestamp > DOWNLOAD_TIMEOUT) { /* server did not send informations back */ downtimestamp = timestamp; send_playerstatus (&players[bman.p_servnr].net.addr, bman.p_nr, 0, 0); } - } + } /* do the grafik work */ - if (!bman.dedicated) { - draw_netupdatestate (0); - - if (SDL_PollEvent (&event) != 0) - switch (event.type) { - case (SDL_QUIT): - bman.state = GS_quit; - bman.p_nr = -1; - done = 1; - } - - keys = SDL_GetKeyState (NULL); - - if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) { - done = 1; - bman.p_nr = -1; - keypressed = 1; - bman.state = GS_startup; - } - - if (event.type == SDL_KEYUP) - keypressed = 0; - } + if (!bman.dedicated) { + draw_netupdatestate (0); + + if (SDL_PollEvent (&event) != 0) + switch (event.type) { + case (SDL_QUIT): + bman.state = GS_quit; + bman.p_nr = -1; + done = 1; + } + + keys = SDL_GetKeyState (NULL); + + if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) { + done = 1; + bman.p_nr = -1; + keypressed = 1; + bman.state = GS_startup; + } + + if (event.type == SDL_KEYUP) + keypressed = 0; + } timestamp = SDL_GetTicks (); // needed for time sync. - SDL_Delay (1); // we don't need here anything better + SDL_Delay (1); // we don't need here anything better /* player is only watching so just go after we have got everything go to show the field */ @@ -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]); } }; @@ -669,17 +682,17 @@ void net_game_send_playermove (int p_nr, int mustsend) { int p; - _player *pl; - + _player *pl; + for (p = 0; p < MAX_PLAYERS; p++) - if (NET_CANSEND(p)) { - pl = &players[p_nr]; - + if (NET_CANSEND (p)) { + pl = &players[p_nr]; + pl->net.pkgopt.send_to--; - if ((pl->net.pkgopt.send_to <= 0 || mustsend)) - send_playermove (&players[p].net.addr, p_nr, pl); + if ((pl->net.pkgopt.send_to <= 0 || mustsend)) + send_playermove (&players[p].net.addr, p_nr, pl); - /* network packet send control */ + /* network packet send control */ if (pl->net.pkgopt.send_to <= 0 || pl->net.pkgopt.send_to > pl->net.pkgopt.send_set) pl->net.pkgopt.send_to = pl->net.pkgopt.send_set; } @@ -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,42 +739,45 @@ 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; + int new_server = bman.p_servnr; d_printf ("net_game_send_delplayer (%d)\n", pl_nr); if (GT_MP_PTPM && (GS_WAITRUNNING || bman.state == GS_update)) { - /* 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) - 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) - send_quit (&players[i].net.addr, pl_nr, new_server); - 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) { - send_quit (&players[bman.p_servnr].net.addr, pl_nr, -1); - } - - inpkg_delplayer (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) + 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) + send_quit (&players[i].net.addr, pl_nr, new_server); + 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) { + send_quit (&players[bman.p_servnr].net.addr, pl_nr, -1); + } + + inpkg_delplayer (pl_nr); if (GT_MP_PTPM) { - if (bman.notifygamemaster) - send_ogc_update (); - - if (new_server >= 0 && new_server < MAX_PLAYERS) - bman.p_servnr = new_server; - } + if (bman.notifygamemaster) + send_ogc_update (); + + if (new_server >= 0 && new_server < MAX_PLAYERS) + bman.p_servnr = new_server; + } }; @@ -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,11 +802,11 @@ 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) - send_ogc_update (); + if (bman.notifygamemaster && GT_MP_PTPM) + send_ogc_update (); }; @@ -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); }; @@ -816,12 +834,12 @@ net_send_teamdata (int team_nr) { int j; - if (GT_MP_PTPS) - return; - - for (j = 0; j < MAX_PLAYERS; j++) - if (NET_CANSEND (j)) - send_teamdata (&players[j].net.addr, team_nr); + if (GT_MP_PTPS) + return; + + for (j = 0; j < MAX_PLAYERS; j++) + if (NET_CANSEND (j)) + send_teamdata (&players[j].net.addr, team_nr); }; @@ -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); }; @@ -873,7 +893,7 @@ net_new_game () { int p; - /* set all multiplayer depending datas */ + /* set all multiplayer depending datas */ bman.players_nr = 0; bman.players_nr_s = 0; for (p = 0; p < MAX_PLAYERS; p++) { @@ -883,8 +903,8 @@ net_new_game () players[p].state = 0; } - if (bman.p_nr != -1) - players[bman.p_nr].state &= (0xFF - PSF_net); // we are the local player + if (bman.p_nr != -1) + players[bman.p_nr].state &= (0xFF - PSF_net); // we are the local player bman.last_ex_nr = 1; }; @@ -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); }; @@ -915,13 +935,13 @@ net_send_updateinfo () { int i; - if (GT_MP_PTPS) - return; + if (GT_MP_PTPS) + return; 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); }; @@ -932,53 +952,59 @@ net_send_mapinfo () { int i; - if (GT_MP_PTPS) - return; + if (GT_MP_PTPS) + return; 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; - char status[10]; - - if (!bman.notifygamemaster || GT_MP_PTPS) - return; - +void +send_ogc_update () +{ + int i, + j; + char status[10]; + + if (!bman.notifygamemaster || GT_MP_PTPS) + return; + for (j = 0, i = 0; i < bman.maxplayer; i++) - if (PS_IS_used (players[i].state)) - j++; - - switch (bman.state) { - case (GS_running): - sprintf (status, "running"); - break; - case (GS_ready): - sprintf (status, "ready"); - break; - case (GS_wait): - sprintf (status, "wait"); - break; - case (GS_update): - sprintf (status, "update"); - break; - default: - sprintf (status, "error"); - break; - } - ogc_sendgamestatus (bman.sock, "BomberClone", VERSION, bman.gamename, j, bman.maxplayer, status); + if (PS_IS_used (players[i].state)) + j++; + + switch (bman.state) { + case (GS_running): + sprintf (status, "running"); + break; + case (GS_ready): + sprintf (status, "ready"); + break; + case (GS_wait): + sprintf (status, "wait"); + break; + case (GS_update): + sprintf (status, "update"); + break; + default: + sprintf (status, "error"); + break; + } + 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)) - send_respawn (&players[pl].net.addr, pl_nr); + if (NET_CANSEND (pl)) + send_respawn (&players[pl].net.addr, pl_nr); }; diff --git a/src/packets.c b/src/packets.c index 59ae9f3..0a6376b 100644 --- a/src/packets.c +++ b/src/packets.c @@ -11,9 +11,9 @@ extern _point debug_field; extern int debug_lastping; -static short int pkg_lastid; /* the packet id, this will only counted - * up nothing more.. if we are at 0x10000 - * we will start at 0 */ +static short int pkg_lastid; /* the packet id, this will only counted + * up nothing more.. if we are at 0x10000 + * we will start at 0 */ struct _resend_cache resend_cache; struct _inpkg_index inpkg_index[PKG_IN_INDEX_NUM]; @@ -64,10 +64,11 @@ int do_error (struct pkg_error *data, _net_addr * addr) { d_printf ("Network Error from %s:%s : '%s'\n", addr->host, addr->port, data->text); - - network_shutdown (); - - menu_displaymessage ("Network Error", "Got Error from: %s:%s\nMessage:%s", addr->host, addr->port, data->text); + + network_shutdown (); + + menu_displaymessage ("Network Error", "Got Error from: %s:%s\nMessage:%s", addr->host, + addr->port, data->text); if (data->nr == 1) return -1; else @@ -100,41 +101,47 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu); - /* Do some basic checks befor we accept this data packet - * 1) check if we are a server */ + /* Do some basic checks befor we accept this data packet + * 1) check if we are a server */ if (GT_MP_PTPS) { sprintf (text, "Sorry this is a client and not a server."); send_error (addr, text); return; } - /* 2) check the version */ + /* 2) check the version */ if (p_jg->ver_sub != vsu || p_jg->ver_major != vma || p_jg->ver_minor != vmi) { sprintf (text, "Version Error - Host/Server Version: %s", VERSION); send_error (addr, text); return; } - - /* 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))) { + + /* 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))) { 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 (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; - } - - if (i == -1) i = freeslot; - + for (i = -1, freeslot = -1, j = 0; j < MAX_PLAYERS; 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; + } + + if (i == -1) + i = freeslot; + if ((i >= 0) && (i < MAX_PLAYERS) && (i < bman.maxplayer)) { /* free player slot found ... fill in data */ pl = &players[i]; @@ -146,17 +153,17 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) d_printf (" Player Added : Nr:[%d] Name:%10s\n", i, p_jg->name); pl->points = 0; pl->wins = 0; - pl->team_nr = -1; - - team_choose (pl); + pl->team_nr = -1; + + team_choose (pl); } strncpy (pl->name, p_jg->name, LEN_PLAYERNAME); - pl->gfx_nr = -1; - pl->gfx = NULL; - - pl->state &= (0xFF - (PSF_alife + PSF_playing)); + pl->gfx_nr = -1; + pl->gfx = NULL; + + pl->state &= (0xFF - (PSF_alife + PSF_playing)); /* Reset the network data */ pl->net.timestamp = timestamp; @@ -169,16 +176,16 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) strncpy (pl->net.addr.port, addr->port, LEN_PORT); dns_filladdr (pl->net.addr.host, LEN_SERVERNAME, pl->net.addr.port, LEN_PORT, bman.net_ai_family, &pl->net.addr.sAddr); - if (p_jg->secondplayer) - pl->net.flags = NETF_local2 + NETF_firewall; - else - pl->net.flags = NETF_firewall; + if (p_jg->secondplayer) + pl->net.flags = NETF_local2 + NETF_firewall; + else + pl->net.flags = NETF_firewall; pl->net.addr.pl_nr = i; bman.players_nr_s++; /* send to the new client the servermode and the complete playerlist */ - if ((!p_jg->secondplayer) && !(players[j].net.flags & NETF_local2)) - send_mapinfo (addr); + if ((!p_jg->secondplayer) && !(players[j].net.flags & NETF_local2)) + send_mapinfo (addr); send_servermode (addr, i); // with this packet the client know it'S pl_nr addr->pl_nr = i; @@ -218,11 +225,11 @@ send_joingame (_net_addr * addr, char *name, int secondplayer) p_jg.ver_sub = vsu; p_jg.ver_major = vma; p_jg.ver_minor = vmi; - p_jg.secondplayer = secondplayer; + p_jg.secondplayer = secondplayer; strncpy (p_jg.name, name, LEN_PLAYERNAME); strncpy (p_jg.password, bman.password, LEN_PASSWORD); - bman.firewall = 1; + bman.firewall = 1; send_pkg ((struct pkg *) &p_jg, addr); }; @@ -234,50 +241,56 @@ 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) { - 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))) { - d_printf (" addr->pl_nr out of range (0-MAX_PLAYERS)\n"); - return; - } - - /* master will have to change the firewall flag on a player */ - if (GT_MP_PTPM) { - if (ct_pkg->from < 0 || ct_pkg->from >= MAX_PLAYERS) { - if ((ct_pkg->to < 0 || ct_pkg->to >= MAX_PLAYERS) && addr->pl_nr != ct_pkg->from) - d_printf (" from or to value out of range (0-MAX_PLAYERS)\n"); - return; - } - - players[ct_pkg->to].net.flags &= (0xFF - NETF_firewall); - net_game_send_player (ct_pkg->to); - } - - /* if a client get this packet we send a packet - * to the server that we have got this packet. */ - else { - send_contest (&players[bman.p_servnr].net.addr, ct_pkg->from, bman.p_nr, 1); - bman.firewall = 0; - } +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))) { + d_printf (" addr->pl_nr out of range (0-MAX_PLAYERS)\n"); + return; + } + + /* master will have to change the firewall flag on a player */ + if (GT_MP_PTPM) { + if (ct_pkg->from < 0 || ct_pkg->from >= MAX_PLAYERS) { + if ((ct_pkg->to < 0 || ct_pkg->to >= MAX_PLAYERS) && addr->pl_nr != ct_pkg->from) + d_printf (" from or to value out of range (0-MAX_PLAYERS)\n"); + return; + } + + players[ct_pkg->to].net.flags &= (0xFF - NETF_firewall); + net_game_send_player (ct_pkg->to); + } + + /* if a client get this packet we send a packet + * to the server that we have got this packet. */ + else { + send_contest (&players[bman.p_servnr].net.addr, ct_pkg->from, bman.p_nr, 1); + bman.firewall = 0; + } } -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); +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; - ct_pkg.to = to; - - send_pkg ((struct pkg *) &ct_pkg, addr); + + ct_pkg.from = from; + ct_pkg.to = to; + + send_pkg ((struct pkg *) &ct_pkg, addr); } @@ -299,34 +312,37 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr) ("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); - /* - * check if we have to send the whole playerlist to a client - */ - if (GT_MP_PTPM && p_id->pl_nr == -1 && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) { - /* 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) + /* + * check if we have to send the whole playerlist to a client + */ + if (GT_MP_PTPM && p_id->pl_nr == -1 && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) { + /* 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) 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); - } - - /* - * check if we have to update someones data - */ - else if ((GT_MP_PTPM && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS && - p_id->pl_nr != bman.p_nr && p_id->pl_nr != bman.p2_nr && bman.state == GS_wait) - || (GT_MP_PTPS && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS)) { + + 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); + } + + /* + * check if we have to update someones data + */ + else if ((GT_MP_PTPM && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS && + p_id->pl_nr != bman.p_nr && p_id->pl_nr != bman.p2_nr && bman.state == GS_wait) + || (GT_MP_PTPS && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS)) { pl = &players[p_id->pl_nr]; - + 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); @@ -334,70 +350,72 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr) dns_filladdr (pl->net.addr.host, LEN_SERVERNAME, pl->net.addr.port, LEN_PORT, bman.net_ai_family, &pl->net.addr.sAddr); } - /* player is used, we need to check if it's the second player from the server - * to set it's host and port name */ - 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)); - } - - /* Check if we have to make a network test.. only client to client - * we won't check 2 players too because i't won't be possible to send - * something to them. - * - * Check only as long as pl->state is still not a network player */ - if (GT_MP_PTPS && !(PS_IS_netplayer (pl->state)) && (PS_IS_netplayer (p_id->state)) - && p_id->pl_nr != bman.p_servnr && p_id->pl_nr != bman.p_nr - && !(pl->net.flags & NETF_local2) && p_id->pl_nr != bman.p2_nr) { - - send_contest (&pl->net.addr, bman.p_nr, -1, 0); // send contest without ackreq. - /* make sure we still get messages from the server, this is a - * work around for some hardware routers */ - send_contest (&players[bman.p_servnr].net.addr, bman.p_nr, -1, 1); - } + /* player is used, we need to check if it's the second player from the server + * to set it's host and port name */ + 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)); + } + + /* Check if we have to make a network test.. only client to client + * we won't check 2 players too because i't won't be possible to send + * something to them. + * + * Check only as long as pl->state is still not a network player */ + if (GT_MP_PTPS && !(PS_IS_netplayer (pl->state)) && (PS_IS_netplayer (p_id->state)) + && p_id->pl_nr != bman.p_servnr && p_id->pl_nr != bman.p_nr + && !(pl->net.flags & NETF_local2) && p_id->pl_nr != bman.p2_nr) { + + send_contest (&pl->net.addr, bman.p_nr, -1, 0); // send contest without ackreq. + /* make sure we still get messages from the server, this is a + * work around for some hardware routers */ + send_contest (&players[bman.p_servnr].net.addr, bman.p_nr, -1, 1); + } pl->state = p_id->state; if (p_id->pl_nr != bman.p_nr && PS_IS_used (pl->state)) pl->state |= PSF_net; 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) { pl->points = NTOH16 (p_id->points); 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); - } + 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); + } } /* Send all connected players the new PlayerID */ if (GT_MP_PTPM && GS_WAITRUNNING && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) net_send_playerid (addr->pl_nr); - } - - /* - * if we are already in a game don't let the player change the gfx */ - else if (GT_MP_PTPM && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS && - p_id->pl_nr != bman.p_nr && p_id->pl_nr != bman.p2_nr && bman.state != GS_wait) { + } + + /* + * if we are already in a game don't let the player change the gfx */ + else if (GT_MP_PTPM && p_id->pl_nr >= 0 && p_id->pl_nr < MAX_PLAYERS && + p_id->pl_nr != bman.p_nr && p_id->pl_nr != bman.p2_nr && bman.state != GS_wait) { /* Send all connected players the new PlayerID */ if (GT_MP_PTPM && GS_WAITRUNNING && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) net_send_playerid (addr->pl_nr); - } - - // d_playerdetail ("*** PLAYER List ***"); - team_update (); + } + + // d_playerdetail ("*** PLAYER List ***"); + team_update (); bman.updatestatusbar = 1; }; void send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport, - int pl_nr, int gfx_nr, int team_nr, signed char netflags) + int pl_nr, int gfx_nr, int team_nr, signed char netflags) { struct pkg_playerid p_id; @@ -424,25 +442,25 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport, strncpy (p_id.port, plport, LEN_PORT); p_id.pl_nr = pl_nr; - p_id.netflags = netflags; + p_id.netflags = netflags; p_id.gfx_nr = gfx_nr; if (pl_nr != -1) { p_id.points = HTON16 (players[pl_nr].points); p_id.wins = HTON16 (players[pl_nr].wins); p_id.state = players[pl_nr].state; - p_id.team_nr = team_nr; - if (team_nr >= 0 && team_nr < MAX_TEAMS) { - p_id.team_points = teams[team_nr].points; - p_id.team_wins = teams[team_nr].wins; - } + p_id.team_nr = team_nr; + if (team_nr >= 0 && team_nr < MAX_TEAMS) { + p_id.team_points = teams[team_nr].points; + p_id.team_wins = teams[team_nr].wins; + } } else { p_id.points = 0; p_id.wins = 0; p_id.state = 0; - p_id.team_nr = -1; - p_id.team_points = 0; - p_id.team_wins = 0; + p_id.team_nr = -1; + p_id.team_points = 0; + p_id.team_wins = 0; } send_pkg ((struct pkg *) &p_id, addr); @@ -457,55 +475,60 @@ 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) { - int i; - +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); - - if (addr->pl_nr == bman.p_servnr) { /* packet comes from the server */ - if (td->team_nr >= 0 && td->team_nr < MAX_TEAMS) { - strncpy (teams[td->team_nr].name, td->name, LEN_PLAYERNAME); - teams[td->team_nr].col = td->col; - teams[td->team_nr].wins = td->wins; - bman.updatestatusbar = 1; - } - } - else { - if (td->team_nr < 0 || td->team_nr >= MAX_TEAMS) { - for (i = 0; i < MAX_TEAMS; i++) - send_teamdata (addr, i); - } - else { - send_teamdata (addr, td->team_nr); - } - } + + 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) { + strncpy (teams[td->team_nr].name, td->name, LEN_PLAYERNAME); + teams[td->team_nr].col = td->col; + teams[td->team_nr].wins = td->wins; + bman.updatestatusbar = 1; + } + } + else { + if (td->team_nr < 0 || td->team_nr >= MAX_TEAMS) { + for (i = 0; i < MAX_TEAMS; i++) + send_teamdata (addr, i); + } + else { + send_teamdata (addr, td->team_nr); + } + } } -void send_teamdata (_net_addr * addr, int team_nr) { - struct pkg_teamdata td; +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); - d_printf ("send_teamdata (%s:%s) team:%d\n", addr->host, addr->port, team_nr); - td.h.typ = PKG_teamdata; td.h.flags = PKGF_ackreq; td.h.len = HTON16 (sizeof (struct pkg_teamdata)); - td.team_nr = team_nr; - if (team_nr >= 0 && team_nr < MAX_PLAYERS) { - strncpy (td.name, teams[team_nr].name, LEN_PLAYERNAME); - td.wins = teams[team_nr].wins; - td.col = teams[team_nr].col; - } - else { - td.name[0] = 0; - td.wins = 0; - td.col = 0; - } - send_pkg ((struct pkg *) &td, addr); + td.team_nr = team_nr; + if (team_nr >= 0 && team_nr < MAX_PLAYERS) { + strncpy (td.name, teams[team_nr].name, LEN_PLAYERNAME); + td.wins = teams[team_nr].wins; + td.col = teams[team_nr].col; + } + else { + td.name[0] = 0; + td.wins = 0; + td.col = 0; + } + send_pkg ((struct pkg *) &td, addr); } @@ -523,31 +546,35 @@ 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)); - bzero (&players[bman.p_servnr], sizeof (_net_player)); - bman.p_servnr = s_mod->p_servnr; + 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; + bman.firewall = 1; + players[bman.p_nr].net.flags = NETF_firewall; players[bman.p_nr].state &= (0xFF - PSF_net); strncpy (players[s_mod->p_nr].name, bman.playername, LEN_PLAYERNAME); - /* send playerid with p_nr -1 so we get the whole playerlist - * do the same with the teamdata */ - send_playerid (addr, NULL, NULL, NULL, -1, -1, -1, 0); - send_teamdata (addr, -1); + /* send playerid with p_nr -1 so we get the whole playerlist + * do the same with the teamdata */ + 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].net.flags = NETF_firewall + NETF_local2; players[bman.p2_nr].state &= (0xFF - PSF_net); strncpy (players[s_mod->p_nr].name, bman.player2name, LEN_PLAYERNAME); } @@ -557,7 +584,7 @@ do_servermode (struct pkg_servermode *s_mod, _net_addr * addr) if (GT_MP_PTPS && addr->pl_nr == bman.p_servnr) { bman.state = s_mod->state; bman.gametype = s_mod->gametype; - bman.dropitemsondeath = s_mod->dropitemsondeath; + bman.dropitemsondeath = s_mod->dropitemsondeath; map.state = s_mod->mapstate; bman.players_nr_s = s_mod->players; @@ -597,15 +624,15 @@ send_servermode (_net_addr * addr, int pl_nr) case (GS_update): d_printf ("Send ServerMode : update\n"); break; - default: - d_printf ("Send ServerMode : mode %d\n", s_mod.state); + default: + d_printf ("Send ServerMode : mode %d\n", s_mod.state); } s_mod.h.typ = PKG_servermode; s_mod.h.len = HTON16 (sizeof (struct pkg_servermode)); s_mod.h.flags = PKGF_ackreq; s_mod.type = bman.gametype; - s_mod.dropitemsondeath = bman.dropitemsondeath; + s_mod.dropitemsondeath = bman.dropitemsondeath; s_mod.mapstate = map.state; if (bman.state == GS_quit) /* do not send GS_quit */ s_mod.state = GS_startup; @@ -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) - s_mod.lplayer2 = 1; - else s_mod.lplayer2 = 0; + 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; s_mod.p_servnr = bman.p_servnr; s_mod.last_winner = bman.lastwinner; s_mod.fieldsize_x = map.size.x; @@ -652,8 +681,8 @@ send_field (_net_addr * addr, int x, int y, _field * field) for (i = 0; i < 4; i++) { f_dat.ex[i].count = map.field[x][y].ex[i].count; f_dat.ex[i].frame = (int) map.field[x][y].ex[i].frame; - f_dat.ex[i].bomb_p = map.field[x][y].ex[i].bomb_p; - f_dat.ex[i].bomb_b = map.field[x][y].ex[i].bomb_b; + f_dat.ex[i].bomb_p = map.field[x][y].ex[i].bomb_p; + f_dat.ex[i].bomb_b = map.field[x][y].ex[i].bomb_b; } f_dat.type = map.field[x][y].type; f_dat.mixframe = map.field[x][y].mixframe; @@ -780,9 +809,9 @@ send_playerdata (_net_addr * addr, int p_nr, _player * pl) p_dat.dead_by = pl->dead_by; p_dat.frame = HTON16 (FTOI16 (pl->frame)); p_dat.p_nr = p_nr; - p_dat.ready = pl->ready; - p_dat.team_nr = pl->team_nr; - + p_dat.ready = pl->ready; + p_dat.team_nr = pl->team_nr; + send_pkg ((struct pkg *) &p_dat, addr); }; @@ -807,7 +836,7 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr) if (bman.state == GS_running && bman.p_nr != p_dat->p_nr) { pl->points = NTOH16 (p_dat->points); pl->dead_by = NTOH16 (p_dat->dead_by); - pl->team_nr = p_dat->team_nr; + pl->team_nr = p_dat->team_nr; } else if (bman.state != GS_running || bman.p_nr != p_dat->p_nr) { pl->pos.x = I16TOF (NTOH16 (p_dat->pos.x)); @@ -819,9 +848,9 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr) pl->range = p_dat->range; pl->frame = I16TOF (NTOH16 (p_dat->frame)); pl->state = p_dat->state; - pl->team_nr = p_dat->team_nr; - pl->ready = p_dat->ready; - team_update (); + pl->team_nr = p_dat->team_nr; + pl->ready = p_dat->ready; + team_update (); } if (p_dat->dead_by < 0 || p_dat->dead_by >= MAX_PLAYERS) /* set player state no matter what */ @@ -832,10 +861,11 @@ 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) - teams[players[p_dat->dead_by].team_nr].points++; + 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); + player_died (pl, p_dat->dead_by, 1); } } pl->state = p_dat->state; @@ -938,7 +968,7 @@ do_playermove (struct pkg_playermove *p_dat, _net_addr * addr) if (p_dat->p_nr == -1) return; - if (addr->pl_nr == -1) // unknown player + if (addr->pl_nr == -1) // unknown player return; /* check if the right player is sending the information */ @@ -1107,8 +1137,11 @@ 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)); - q_dat.pl_nr = pl_nr; - q_dat.new_server = new_server; + 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,33 +1149,35 @@ 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 */ - if (q_dat->pl_nr == bman.p_servnr && q_dat->new_server != bman.p_servnr) { - d_printf ("do_quit: new server is set to: %d\n", q_dat->new_server); - bman.p_servnr = q_dat->new_server; - - if (GT_MP_PTPM && bman.notifygamemaster) { - /* if there are any AI players delete the network flag from them */ - int i; - - for (i = 0; i < MAX_PLAYERS; i++) - if (PS_IS_aiplayer (players[i].state)) - players[i].state &= (0xFF - PSF_net); - - send_ogc_update (); - } - } - 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." - " Or the server could not find any other possible new server."); + if (q_dat->pl_nr == bman.p_servnr && q_dat->new_server != bman.p_servnr) { + d_printf ("do_quit: new server is set to: %d\n", q_dat->new_server); + bman.p_servnr = q_dat->new_server; + + if (GT_MP_PTPM && bman.notifygamemaster) { + /* if there are any AI players delete the network flag from them */ + int i; + + for (i = 0; i < MAX_PLAYERS; i++) + if (PS_IS_aiplayer (players[i].state)) + players[i].state &= (0xFF - PSF_net); + + send_ogc_update (); + } + } + 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." + " Or the server could not find any other possible new server."); }; @@ -1304,13 +1339,13 @@ do_playerstatus (struct pkg_playerstatus *stat, _net_addr * addr) 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 (players[i].net.addr.host[0] != 0) - send_playerstatus (addr, stat->pl_nr, - stat->net_istep, stat->status); - */ + /* + if (GT_MP_PTPM) + for (i = 0; i < MAX_PLAYERS; i++) + if (players[i].net.addr.host[0] != 0) + send_playerstatus (addr, stat->pl_nr, + stat->net_istep, stat->status); + */ }; void @@ -1346,26 +1381,26 @@ 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;istatus[i]; - players[i].net.net_istep = stat->step[i]; - } + 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]; + } }; void send_updateinfo (_net_addr * addr) { struct pkg_updateinfo stat; - int i; + int i; stat.h.typ = PKG_updateinfo; stat.h.flags = 0; stat.h.len = HTON16 (sizeof (struct pkg_updateinfo)); - for (i=0;ipl_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 */ - if (sp_pkg->typ < SP_max) { - 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); - } - - /* cleas special */ - else if (sp_pkg->typ == SP_clear) - special_clear (sp_pkg->pl_nr); + /* set or use special */ + if (sp_pkg->typ < SP_max) { + 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); + } + + /* cleas special */ + else if (sp_pkg->typ == SP_clear) + special_clear (sp_pkg->pl_nr); }; @@ -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; @@ -1619,20 +1660,20 @@ void do_respawn (struct pkg_respawn *r_pkg, _net_addr *addr) { if (addr->pl_nr != bman.p_servnr && r_pkg->pl_nr != addr->pl_nr) return; - if ((r_pkg->state & PSF_respawn) == PSF_respawn) { - players[r_pkg->pl_nr].pos.x = r_pkg->x; - players[r_pkg->pl_nr].pos.y = r_pkg->y; - players[r_pkg->pl_nr].state &= (0xFF - PSF_alife); - players[r_pkg->pl_nr].state |= PSF_respawn; - players[r_pkg->pl_nr].frame = 0.0f; - - } - else if (r_pkg->state & (PSF_respawn + PSF_alife)) { - players[r_pkg->pl_nr].pos.x = r_pkg->x; - players[r_pkg->pl_nr].pos.y = r_pkg->y; - players[r_pkg->pl_nr].state |= PSF_alife; - players[r_pkg->pl_nr].state &= (0xFF - PSF_respawn); - } + if ((r_pkg->state & PSF_respawn) == PSF_respawn) { + players[r_pkg->pl_nr].pos.x = r_pkg->x; + players[r_pkg->pl_nr].pos.y = r_pkg->y; + players[r_pkg->pl_nr].state &= (0xFF - PSF_alife); + players[r_pkg->pl_nr].state |= PSF_respawn; + players[r_pkg->pl_nr].frame = 0.0f; + + } + else if (r_pkg->state & (PSF_respawn + PSF_alife)) { + players[r_pkg->pl_nr].pos.x = r_pkg->x; + players[r_pkg->pl_nr].pos.y = r_pkg->y; + players[r_pkg->pl_nr].state |= PSF_alife; + players[r_pkg->pl_nr].state &= (0xFF - PSF_respawn); + } }; @@ -1641,42 +1682,49 @@ 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) { - if (GT_MP_PTPM && pgi->password == -1) { - 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); - } - 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); - +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); + + 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); + } + 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); + } -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; pgi.h.len = HTON16 (sizeof (struct pkg_gameinfo)); pgi.h.flags = 0; pgi.timestamp = timestamp; - pgi.gamename[0] = 0; - pgi.version[0] = 0; - pgi.password = -1; - pgi.broadcast = broadcast; - + pgi.gamename[0] = 0; + pgi.version[0] = 0; + pgi.password = -1; + pgi.broadcast = 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); - else - udp_send (sock, (char *) &pgi, NTOH16 (pgi.h.len), &addr->sAddr, bman.net_ai_family); + if (broadcast) + 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); }; @@ -1693,15 +1741,14 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr) int i, pos; - /* check if the player is still connected */ - if (!PS_IS_used (players[addr->pl_nr].state)) - return -1; - + /* check if the player is still connected */ + if (!PS_IS_used (players[addr->pl_nr].state)) + return -1; + /* find packet */ - for (i = 0, pos = -1; (i < PKG_IN_INDEX_NUM && pos == -1); i++) + for (i = 0, pos = -1; (i < PKG_IN_INDEX_NUM && pos == -1); i++) if (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,33 +1766,36 @@ 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) { - 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; +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; } - + /* sends the packet and if PKGF_ackreq is set add packet to the resendcache */ void 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)) + * an AI_Player, so ignore it. */ + 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 - * the id is needed for the inpkg index to check for - * double reached packets */ + /* set the id for the packet and the network flags + * the id is needed for the inpkg index to check for + * double reached packets */ packet->h.id = HTON16 (pkg_lastid++); if (bman.net_ai_family != PF_INET) packet->h.flags = packet->h.flags | PKGF_ipv6; udp_send (bman.sock, (char *) packet, NTOH16 (packet->h.len), &addr->sAddr, bman.net_ai_family); /* if PKGF_ackreq is set add the packet to the resendcache - * so we can resend it if no PKF_ackreq returned for the packet. */ + * so we can resend it if no PKF_ackreq returned for the packet. */ if (packet->h.flags & PKGF_ackreq) { if (rscache_add (addr, packet) == -1) d_printf ("resend_cache overrun.... packet throw away.\n"); @@ -1763,17 +1813,16 @@ fwd_pkg (struct pkg *packet, _net_addr * addr) return; if (packet->h.typ >= PKG_field && packet->h.typ < PKG_quit) { - for (pl = 0; pl < MAX_PLAYERS; pl++) + for (pl = 0; pl < MAX_PLAYERS; pl++) 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) + || (players[pl].net.flags & NETF_firewall) == NETF_firewall) + && 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) - d_fatal ("fwd_pkg: not forwarding unknown packet From Player:%d (%s) Typ:%d Len:%d\n", - addr->pl_nr, players[addr->pl_nr].name, packet->h.typ, NTOH16 (packet->h.len)); + } + else if (packet->h.typ > PKG_quit) + d_fatal ("fwd_pkg: not forwarding unknown packet From Player:%d (%s) Typ:%d Len:%d\n", + addr->pl_nr, players[addr->pl_nr].name, packet->h.typ, NTOH16 (packet->h.len)); }; @@ -1789,54 +1838,55 @@ do_pkg (struct pkg *packet, _net_addr * addr) d_printf ("do_pkg: packet comes from the wrong network type\n"); return 0; } - + /* get the addr and set the ping timeout value - * 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 */ + * 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)) { - d_printf ("do_pkg: error addr->pl_nr out of range\n"); - return 0; - } - - if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) { - 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) { - - /* we need to send an acknolege so the client - * knows we have got this packet and delete - * it from the resend cache. */ - send_pkgack (addr, packet->h.typ, NTOH16 (packet->h.id)); - - /* check the packet with the index so we can - * ignore packets we already have got - * this is important to keep away from - * the bomb is dropped twice bug. */ - if (inpkg_check (packet->h.typ, NTOH16 (packet->h.id), addr) != -1) { - /* we have got this packet already */ - d_printf ("do_pkg: double packet ignoring addr->pl_nr=%d\n", addr->pl_nr); - if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) - players[addr->pl_nr].net.pkgopt.to_2sec++; - return 0; - } - } - - /* forward packet */ - if (GT_MP_PTPM) - fwd_pkg (packet, addr); - } + 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; + } + + if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) { + 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) { + + /* we need to send an acknolege so the client + * knows we have got this packet and delete + * it from the resend cache. */ + send_pkgack (addr, packet->h.typ, NTOH16 (packet->h.id)); + + /* check the packet with the index so we can + * ignore packets we already have got + * this is important to keep away from + * the bomb is dropped twice bug. */ + if (inpkg_check (packet->h.typ, NTOH16 (packet->h.id), addr) != -1) { + /* we have got this packet already */ + d_printf ("do_pkg: double packet ignoring addr->pl_nr=%d\n", addr->pl_nr); + if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) + players[addr->pl_nr].net.pkgopt.to_2sec++; + return 0; + } + } + + /* forward packet */ + if (GT_MP_PTPM) + fwd_pkg (packet, addr); + } switch (packet->h.typ) { case (PKG_error): if (do_error ((struct pkg_error *) packet, addr) < 0) return -1; break; - case (PKG_gameinfo): - do_gameinfo ((struct pkg_gameinfo *) packet, addr); - break; + case (PKG_gameinfo): + do_gameinfo ((struct pkg_gameinfo *) packet, addr); + break; case (PKG_playerid): do_playerid ((struct pkg_playerid *) packet, addr); break; @@ -1846,9 +1896,9 @@ do_pkg (struct pkg *packet, _net_addr * addr) case (PKG_field): do_field ((struct pkg_field *) packet, addr); break; - case (PKG_contest): - do_contest ((struct pkg_contest *) packet, addr); - break; + case (PKG_contest): + do_contest ((struct pkg_contest *) packet, addr); + break; case (PKG_pingreq): do_ping ((struct pkg_ping *) packet, addr); break; @@ -1909,9 +1959,9 @@ do_pkg (struct pkg *packet, _net_addr * addr) case (PKG_updateinfo): do_updateinfo ((struct pkg_updateinfo *) packet, addr); break; - case (PKG_teamdata): - do_teamdata ((struct pkg_teamdata *) packet, addr); - break; + case (PKG_teamdata): + do_teamdata ((struct pkg_teamdata *) packet, addr); + break; default: send_error (addr, "BomberClone: unknown data packet"); break;