diff --git a/include/basic.h b/include/basic.h index a2de2a3..babf210 100644 --- a/include/basic.h +++ b/include/basic.h @@ -1,4 +1,4 @@ -/* $Id: basic.h,v 1.14 2004/01/05 22:17:48 stpohle Exp $ */ +/* $Id: basic.h,v 1.15 2004/01/06 19:52:02 stpohle Exp $ */ /* basic types which we need everywhere */ #ifndef _BC_BASIC_H_ @@ -73,7 +73,7 @@ #define UDP_TIMEOUT 15000 #define BUF_SIZE 1024 -#define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (players[__result].gfx_nr != __gfx_nr) && (__result >= 0); __result--); +#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 diff --git a/include/bomberclone.h b/include/bomberclone.h index dd3df3a..94e561c 100644 --- a/include/bomberclone.h +++ b/include/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.14 2004/01/06 02:19:56 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.15 2004/01/06 19:52:02 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -162,7 +162,7 @@ struct { extern _bomberclone bman; -extern _player players[MAX_PLAYERS]; +extern _player *players; extern Uint32 timestamp; extern float timefactor; extern float timediff; diff --git a/include/gfx.h b/include/gfx.h index ae0a691..c78b700 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -1,4 +1,4 @@ -/* $Id: gfx.h,v 1.4 2003/12/24 02:38:15 stpohle Exp $ */ +/* $Id: gfx.h,v 1.5 2004/01/06 19:52:02 stpohle Exp $ */ #ifndef _GFX_H_ #define _GFX_H_ @@ -93,6 +93,7 @@ extern void gfx_restorescreen (SDL_Surface *img, SDL_Rect *wnd); // gfxengine.c +extern void gfxengine_init (); extern void gfx_blitdraw (); extern void gfx_blit (SDL_Surface *srci, SDL_Rect *srcr, SDL_Surface *desti, SDL_Rect *destr, int y); extern void gfx_blitsort (); diff --git a/src/configuration.c b/src/configuration.c index 545a925..f99e114 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -439,10 +439,13 @@ ReadPrgArgs (int argc, char **argv) printf (" -name PLAYERNAME - set the Playername\n"); printf (" -port PORT - set the local BomberClone port (Def.: 11000)\n"); printf (" -ogcport PORT - set the local OGC Port (Def.: 11100)\n"); + printf (" -ogc 0/1 - Enable/Disable OGC\n"); printf (" -firewall - Client is behind a firewall\n"); printf (" Only set this if you get some problems\n"); printf (" with network games.\n"); exit (0); } + if (!strcmp (argv[i], "-ogc")) + bman.notifygamemaster = atoi (argv[++i]); } }; diff --git a/src/gfxengine.c b/src/gfxengine.c index f11e80e..ca7345b 100644 --- a/src/gfxengine.c +++ b/src/gfxengine.c @@ -1,12 +1,21 @@ -/* $Id: gfxengine.c,v 1.3 2003/12/24 02:38:15 stpohle Exp $ */ +/* $Id: gfxengine.c,v 1.4 2004/01/06 19:52:02 stpohle Exp $ */ /* GFX Game Engine */ #include "bomberclone.h" int blitdb_nr = 0, blitrects_nr = 0; -static _gfxblit blitdb[MAX_BLITRECTS]; /* unsorted list of blitdb's */ -static _gfxblit *sortblitdb[MAX_BLITRECTS]; /* sorted list of blitdb's */ -static SDL_Rect blitrects[MAX_BLITRECTS]; /* SDLUpdate Rects */ +static _gfxblit *blitdb; /* unsorted list of blitdb's */ +static _gfxblit **sortblitdb; /* sorted list of blitdb's */ +static SDL_Rect *blitrects; /* SDLUpdate Rects */ + + +/* alloc all needed space */ +void gfxengine_init () { + blitdb = malloc (sizeof (_gfxblit)* MAX_BLITRECTS); + sortblitdb = malloc (sizeof (_gfxblit *)* MAX_BLITRECTS); + blitrects = malloc (sizeof (SDL_Rect) * MAX_BLITRECTS); +}; + /* sort the list of blitting objects highest will be drawn at last */ void gfx_blitsort () { diff --git a/src/main.c b/src/main.c index e44375c..5b88c8e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.19 2004/01/04 00:24:21 stpohle Exp $ */ +/* $Id: main.c,v 1.20 2004/01/06 19:52:02 stpohle Exp $ */ #include "basic.h" #include "bomberclone.h" @@ -8,7 +8,7 @@ _bomberclone bman; // Holds GameData -_player players[MAX_PLAYERS]; // holds all Playerdata +_player *players; // holds all Playerdata Uint32 timestamp; // timestamp float timefactor = 0.0f; /* factor for the time time of the last loop @@ -22,6 +22,9 @@ main (int argc, char **argv) char text[255]; int menuselect = 0; + players = malloc (sizeof (_player) * MAX_PLAYERS); + gfxengine_init (); + if (SDL_Init (SDL_INIT_VIDEO) != 0) { d_printf ("Unable to init SDL: %s\n", SDL_GetError ()); return (1); @@ -57,6 +60,9 @@ main (int argc, char **argv) } } + network_init (); + network_shutdown (); + gfx_shutdown (); return 0; diff --git a/src/menu.c b/src/menu.c index 4f0e469..26bbc91 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.35 2004/01/04 19:45:56 stpohle Exp $ +/* $Id: menu.c,v 1.36 2004/01/06 19:52:02 stpohle Exp $ * Menuhandling */ #include "basic.h" @@ -373,6 +373,8 @@ int menu_loop () { network_loop (); if (bman.notifygamemaster) reorder = ogc_loop (); + else + reorder = 0; } eventstate = SDL_PollEvent (&event); diff --git a/src/multiwait.c b/src/multiwait.c index ecb0e3f..2647df8 100644 --- a/src/multiwait.c +++ b/src/multiwait.c @@ -10,6 +10,7 @@ #include "chat.h" extern int UpdateRects_nr; +extern int blitdb_nr; static int mw_player = 0, mw_chat = 0, @@ -132,6 +133,9 @@ mw_draw_status () }; + +/* draws all aviable players for selection, + * if the selgfx player is selected this player will not be animated */ void mw_draw_gfxselect (int selgfx) { @@ -142,7 +146,6 @@ mw_draw_gfxselect (int selgfx) dest; xstep = gfx.res.x / MAX_PLAYERS; - if (players[bman.p_nr].gfx_nr == -1) { /* draw selection */ for (i = 0; i < MAX_PLAYERS; i++) { @@ -176,7 +179,7 @@ mw_draw_gfxselect (int selgfx) mw_frameto = ANI_PLAYERTIMEOUT; mw_frame = 0; } - + gfx_blit (gfx.players[i].ani.image, &src, gfx.screen, &dest, 0xFFFF); } else @@ -218,7 +221,7 @@ mw_draw_gfxselect (int selgfx) dest.w = gfx.res.x; dest.h = 32 + gfx.players[0].ani.h; gfx_blitupdaterectadd (&dest); - + mw_chat = mw_player + gfx.players[0].ani.h; } @@ -285,7 +288,6 @@ wait_for_players () mw_draw_gfxselect (selgfx); mw_draw_chat (); } - gfx_blitdraw (); /* do the keyboard handling */ @@ -350,10 +352,10 @@ wait_for_players () if ((event.key.keysym.sym == SDLK_LCTRL || event.key.keysym.sym == SDLK_RCTRL) && event.type == SDL_KEYDOWN && (!keypressed)) { if (players[bman.p_nr].gfx_nr == -1) /* select player */ - players[bman.p_nr].gfx_nr = selgfx; + player_set_gfx (&players[bman.p_nr],selgfx); else /* deselect player */ - players[bman.p_nr].gfx_nr = -1; + player_set_gfx (&players[bman.p_nr],-1); net_change_playerid (bman.p_nr, 1); bman.updatestatusbar = 1; keypressed = 1; @@ -403,9 +405,11 @@ wait_for_players () else if (event.type == SDL_KEYDOWN && event.key.keysym.sym != SDLK_RSHIFT && event.key.keysym.sym != SDLK_LSHIFT) keypressed = 1; - s_delay (25); + s_delay (50); } - + + gfx_blitdraw (); // to clean the gfx blit data + draw_logo (); SDL_Flip (gfx.screen); diff --git a/src/netsrvlist.c b/src/netsrvlist.c index 8ca95a0..fece9a3 100644 --- a/src/netsrvlist.c +++ b/src/netsrvlist.c @@ -1,4 +1,4 @@ -/* $Id: netsrvlist.c,v 1.7 2004/01/04 19:45:56 stpohle Exp $ +/* $Id: netsrvlist.c,v 1.8 2004/01/06 19:52:02 stpohle Exp $ * netsrvlist.c - shows a list of possible servers.*/ #include "basic.h" @@ -43,7 +43,7 @@ void srvlist_rebuildlist () { /* add the OpenGameCache Entrys */ if (bman.notifygamemaster) { - for (ogclst = 0; ogclst < MAX_OGC_ENTRYS; ogclst++) + for (ogclst = 0; (ogclst < MAX_OGC_ENTRYS && srvlst_cnt < MAX_SRVLIST); ogclst++) if (ogc_array[ogclst].serial != -1) { srvlst_dat[srvlst_cnt].host[0] = 0; srvlst_dat[srvlst_cnt].port[0] = 0; @@ -56,6 +56,8 @@ void srvlist_rebuildlist () { srvlst_cnt++; } } + if (srvlst_cnt >= MAX_SRVLIST) + d_fatal ("srvlist_rebuildlist : srvlst_cnt >= MAX_SRVLIST\n"); /* add local server list * - this will have to be finished later -*/ @@ -88,7 +90,8 @@ void net_getserver () { d_printf ("net_getserver\n"); bman.servername[0] = 0; - ogc_browsestart (); + if (bman.notifygamemaster) + ogc_browsestart (); menu_new ("Join a Game", 500, 400); menu_create_list ("Host a Game", -1, 50, 475, 250, srvlst_text, &sel_entry, 1); @@ -119,6 +122,7 @@ void net_getserver () { } } - ogc_browsestop (); + if (bman.notifygamemaster) + ogc_browsestop (); menu_delete (); }; diff --git a/src/network.c b/src/network.c index 38dbc9c..5a6c040 100644 --- a/src/network.c +++ b/src/network.c @@ -1,4 +1,4 @@ -/* $Id: network.c,v 1.53 2004/01/06 04:49:36 stpohle Exp $ */ +/* $Id: network.c,v 1.54 2004/01/06 19:52:02 stpohle Exp $ */ /* network routines. */ @@ -160,7 +160,7 @@ network_shutdown () if (bman.notifygamemaster) { ogc_sendgamequit (bman.sock); ogc_shutdown (); - } + } udp_close (bman.sock); @@ -233,9 +233,8 @@ network_loop () &addr.sAddr); 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; @@ -249,14 +248,14 @@ network_loop () */ if (bman.state == GS_wait || bman.state == GS_ready || bman.state == GS_running) { if (GT_MP_PTPS) { - if (net_check_timeout (0)) { + if (net_check_timeout (bman.p_servnr)) { d_printf ("Server Timed Out\n"); bman.state = GS_startup; } } else if (GT_MP_PTPM) { for (i = 1; i < MAX_PLAYERS; i++) - if (net_check_timeout (i)) { + if (i != bman.p_nr && net_check_timeout (i)) { d_printf ("Player %d Timed Out\n", i); net_delplayer (i); } diff --git a/src/ogcache-client.c b/src/ogcache-client.c index 0330b40..04afca2 100644 --- a/src/ogcache-client.c +++ b/src/ogcache-client.c @@ -1,4 +1,4 @@ -/* $Id: ogcache-client.c,v 1.3 2004/01/06 04:49:36 stpohle Exp $ +/* $Id: ogcache-client.c,v 1.4 2004/01/06 19:52:02 stpohle Exp $ * OpenGameCache-Client: this file will hold the protocol for the gameserver communication */ @@ -9,9 +9,9 @@ int ogc_sock = -1; struct game_entry ogc_array[MAX_OGC_ENTRYS]; -char ogc_host[LEN_OGCHOST]; -char ogc_port[LEN_OGCPORT]; -char ogc_game[LEN_GAME]; +char ogc_host[LEN_OGCHOST+1]; +char ogc_port[LEN_OGCPORT+1]; +char ogc_game[LEN_GAME+1]; int ogc_ai_family; struct _sockaddr ogc_addr; int ogc_browsing = 0; @@ -165,19 +165,20 @@ static int ogc_do_inpacket (char *in, int len, struct _sockaddr *addr) { int ogc_init (char *localport, char *server, char *port, char *game, int ai_family) { int i; - /* check if the socket is still open, if so close it */ - if (ogc_sock != -1) ogc_shutdown (); - + ogc_sock = -1; + ogc_sock = udp_server (localport, ai_family); + d_printf ("ogc_init (Localport: %s, Server %s:%s Game %s socket=%d)\n", localport, server, port, game, ogc_sock); if (ogc_sock <= 0) return 0; strncpy (ogc_host, server, LEN_OGCHOST); - strncpy (ogc_port, port, LEN_OGCHOST); + strncpy (ogc_port, port, LEN_OGCPORT); strncpy (ogc_game, game, LEN_GAME); ogc_ai_family = ai_family; - dns_filladdr (ogc_host, LEN_OGCHOST, ogc_port, LEN_OGCPORT, ogc_ai_family, &ogc_addr); + d_printf ("ogc_host:%s ogc_port:%s ogc_game:%s ogc_ai_family:%d\n", ogc_host, ogc_port, ogc_game, ogc_ai_family); + dns_filladdr (ogc_host, LEN_OGCHOST, ogc_port, LEN_OGCPORT, ogc_ai_family, &ogc_addr); for (i = 0; i < MAX_OGC_ENTRYS; i++) ogc_array[i].serial = -1; @@ -224,7 +225,9 @@ void ogc_shutdown () { if (ogc_sock <= 0) return; - ogc_browsestop (); + d_printf ("ogc_shutdown\n"); + if (ogc_browsing) + ogc_browsestop (); udp_close (ogc_sock); ogc_sock = -1; @@ -261,6 +264,8 @@ int ogc_loop () { void ogc_browsestart () { char data[BUF_SIZE]; + d_printf ("ogc_browsestart\n"); + if (ogc_sock <= 0) return; @@ -277,6 +282,8 @@ void ogc_browsestart () { void ogc_browsestop () { char data[BUF_SIZE]; + d_printf ("ogc_browsestop\n"); + ogc_browsing = 0; if (ogc_sock <= 0) return; diff --git a/src/udp.c b/src/udp.c index f40403e..6172ea8 100644 --- a/src/udp.c +++ b/src/udp.c @@ -1,4 +1,4 @@ -/* $Id: udp.c,v 1.10 2003/09/11 19:32:01 stpohle Exp $ */ +/* $Id: udp.c,v 1.11 2004/01/06 19:52:02 stpohle Exp $ */ /* udp.c code for the network File Version 0.2 */ @@ -82,7 +82,6 @@ dns_filladdr (char *host, int hostlen, char *port, int portlen, int ai_family, } #else - struct addrinfo hints, *res; int err, i, @@ -90,7 +89,6 @@ dns_filladdr (char *host, int hostlen, char *port, int portlen, int ai_family, if (host[0] == 0 || port[0] == 0) { /* we have to complete server and port from the sAddr */ - if (ai_family == PF_INET) addrlen = sizeof (struct sockaddr_in); else @@ -102,7 +100,8 @@ dns_filladdr (char *host, int hostlen, char *port, int portlen, int ai_family, if ((err = getnameinfo ((struct sockaddr *) sAddr, addrlen, host, hostlen, port, portlen, NI_NUMERICHOST | NI_NUMERICSERV)) < 0) { - d_printf ("dns_filladdr (getnameinfo): %s\n", gai_strerror (err)); + + d_printf ("dns_filladdr (getnameinfo): %s\n", gai_strerror (err)); return -1; } @@ -114,7 +113,6 @@ dns_filladdr (char *host, int hostlen, char *port, int portlen, int ai_family, } else { /* we have to complete the sAddr struct */ - memset (&hints, '\0', sizeof (struct addrinfo)); hints.ai_family = ai_family; hints.ai_socktype = SOCK_DGRAM;