Server can leave games.. These Games will continue with another new server, firewall flag will be set on it's own when a player joins a game

origin
stpohle 21 years ago
parent d9b2b4df2b
commit 1304e53d55

@ -1,5 +1,14 @@
$Id: ChangeLog,v 1.85 2004/10/18 20:20:18 stpohle Exp $
$Id: ChangeLog,v 1.86 2004/11/30 14:30:34 stpohle Exp $
2004-11-28
- the firewall flag will be enabled and disabled automaticly.
- only players who are in the game will be able to send
gamedata related packets to the game. (do_pkg updated)
* delete the joingame packet from the resend thing..
server thinks we rejoin.. only on a slow client
* FINISH TEAM MODE.

@ -1,4 +1,4 @@
/* $Id: packets.h,v 1.28 2004/11/07 04:13:09 stpohle Exp $
/* $Id: packets.h,v 1.29 2004/11/30 14:30:36 stpohle Exp $
* network packets.. */
#ifndef _PACKETS_H_
@ -15,6 +15,8 @@
enum _network_data {
PKG_error = 0,
PKG_joingame,
PKG_contest, // every packet below here will checked
// if it comes from a orginal player
PKG_playerid,
PKG_servermode,
PKG_pingreq,
@ -86,6 +88,13 @@ struct pkg_ping {
};
struct pkg_contest {
struct pkgheader h;
signed char from;
signed char to;
};
struct pkgdropitemelemt {
signed char x;
signed char y;
@ -152,7 +161,7 @@ struct pkg_joingame {
signed char ver_major; // Version
signed char ver_minor; // Version
signed char ver_sub; // Version
signed char netflags;
signed char secondplayer; // this is the second player
char name[LEN_PLAYERNAME];
char password[LEN_PASSWORD];
};
@ -169,7 +178,6 @@ struct pkg_playerid {
signed char netflags; // network flags
Sint16 points;
Sint16 wins;
signed char team_nr; // team number
Sint16 team_points; // team points
Sint16 team_wins; // team wins
@ -363,11 +371,12 @@ extern void do_mapinfo (struct pkg_mapinfo *map_pkg, _net_addr *addr);
extern void do_tunneldata (struct pkg_tunneldata *tun_pkg, _net_addr *addr);
extern void do_dropitems (struct pkg_dropitem *di_pkg, _net_addr *addr);
extern void do_respawn (struct pkg_respawn *r_pkg, _net_addr *addr);
extern void do_contest (struct pkg_contest *ct_pkg, _net_addr *addr);
extern void send_pkg (struct pkg *packet, _net_addr *addr);
extern void send_playerid (_net_addr *addr, char *name, char *pladdr, char *plport, int p_nr, int gfx_nr, int team_nr, signed char netflags);
extern void send_servermode (_net_addr *addr, int pl_nr);
extern void send_joingame (_net_addr * addr, char *name, int flags);
extern void send_joingame (_net_addr * addr, char *name, int secondplayer);
extern void send_error (_net_addr *addr, char *text);
extern void send_field (_net_addr *addr, int x, int y, _field * field);
extern void send_ping (_net_addr *addr, int data, unsigned char typ);
@ -388,6 +397,7 @@ extern void send_updateinfo(_net_addr *addr);
extern void send_tunneldata (_net_addr *addr, int tunnelnr, int x, int y);
extern void send_dropitems (_net_addr *addr, int pl_nr, _flyingitem **fitems, int cnt);
extern void send_respawn (_net_addr * addr, int plnr);
extern void send_contest (_net_addr * addr, int from, int to, int ackreq);
extern void fwd_pkg (struct pkg *packet, _net_addr *addr);

@ -1,4 +1,4 @@
/* $Id: configuration.c,v 1.67 2004/10/28 18:15:17 stpohle Exp $
/* $Id: configuration.c,v 1.68 2004/11/30 14:30:36 stpohle Exp $
* configuration */
#include <SDL.h>
@ -284,9 +284,6 @@ config_read ()
value[511] = 0;
strcpy (map.map, value);
}
if (!strcmp (keyword, "firewall")) {
bman.firewall = atoi (value);
}
if (!strcmp (keyword, "udpport")) {
if (strlen (value) > LEN_PORT) {
d_printf
@ -437,7 +434,6 @@ config_write ()
fprintf (config, "fullscreen=%d\n", gfx.fullscreen);
fprintf (config, "tileset=%s\n", map.tileset);
fprintf (config, "mapname=%s\n", map.map);
fprintf (config, "firewall=%d\n", bman.firewall);
fprintf (config, "udpport=%s\n", bman.port);
fprintf (config, "ai_players=%d\n", bman.ai_players);
fprintf (config, "fieldsizex=%d\n", map.size.x);
@ -649,9 +645,6 @@ ReadPrgArgs (int argc, char **argv)
printf (" (Def.: 11000)\n");
printf (" -ogcport PORT - set the local OGC Port (Def.: 11100)\n");
printf (" -ogc 0/1 - Enable/Disable OGC\n");
printf (" -firewall 0/1 - Enable/Disable the firewall settings\n");
printf (" Only set this if you get some problems\n");
printf (" with network games.\n");
printf (" -host - start a network game\n");
printf (" -join - go into the join menu\n");
printf (" -connect ADDRESS - connect to a server\n");
@ -662,8 +655,6 @@ ReadPrgArgs (int argc, char **argv)
strncpy (bman.port, argv[++i], LEN_PORT);
if (!strcmp (argv[i], "-ogcport"))
strncpy (bman.ogc_port, argv[++i], LEN_PORT);
if (!strcmp (argv[i], "-firewall"))
bman.firewall = atoi (argv[++i]);
if (!strcmp (argv[i], "-name"))
strncpy (bman.playername, argv[++i], LEN_PLAYERNAME);
if (!strcmp (argv[i], "-name2"))

@ -89,7 +89,7 @@ void d_fatal (char *fmt,...) {
void debug_ingameinfo() {
int i;
char text[255];
char text[2048];
for (i = 0; i < map.size.x; i++)
stonelist_add (i, map.size.y-1);
@ -99,13 +99,13 @@ void debug_ingameinfo() {
font_gfxdraw (0, gfx.res.y-font[0].size.y, text, 0, 0, (map.size.y*256)+10);
sprintf (text, "P:");
/* sprintf (text, "P:");
for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_playing (players[i].state)) {
sprintf (text, "%s Pos:%f,%f ", text, players[i].pos.x, players[i].pos.y);
}
font_gfxdraw (0, gfx.res.y-font[0].size.y*2, text, 0, 0, (map.size.y*256)+10);
font_gfxdraw (0, gfx.res.y-font[0].size.y*2, text, 0, 0, (map.size.y*256)+10); */
sprintf (text, "Pl_nr: %d TO: %3.2f", bman.players_nr, bman.timeout);
font_gfxdraw (350, gfx.res.y-font[0].size.y, text, 0, 0, (map.size.y*256)+10);
font_gfxdraw (100, gfx.res.y-font[0].size.y, text, 0, 0, (map.size.y*256)+10);
};

@ -1,4 +1,4 @@
/* $Id: game.c,v 1.101 2004/11/07 04:13:10 stpohle Exp $
/* $Id: game.c,v 1.102 2004/11/30 14:30:36 stpohle Exp $
game.c - procedures for the game. */
#include <string.h>
@ -543,7 +543,7 @@ game_start ()
#define SHOWRESULT_TEAMHEAD 24
#define SHOWRESULT_TEAMPLAYER 16
#define SHOWRESULT_TEAMPLAYERWIDTH 150
void game_showresultteam () {
void game_showresultteam (int pos_x, int pos_y, int pos_w, int pos_h) {
int i, t_nr, p_nr; // counter for teams and players
struct {
_team *team; // pointer to the team
@ -614,21 +614,21 @@ void game_showresultteam () {
p_y += ceil ((float)(((float) tdata[t_nr].cnt) / ((float)p_x)));
}
if (p_y == 0) p_y = 1;
dy = (gfx.res.y - 100 - (SHOWRESULT_TEAMHEAD * t_count)) / p_y;
dy = (pos_h - (SHOWRESULT_TEAMHEAD * t_count)) / p_y;
} while (dy < SHOWRESULT_TEAMPLAYER);
if (dy > 2*SHOWRESULT_TEAMPLAYER) dy = 2*SHOWRESULT_TEAMPLAYER;
/* draw everything */
sy = (gfx.res.y - (SHOWRESULT_TEAMHEAD * t_count + dy * p_y)) / 2;
sy = (pos_h - (SHOWRESULT_TEAMHEAD * t_count + dy * p_y)) / 2;
for (t_nr = 0; t_nr < t_count; t_nr++) {
sprintf (text, "%s Victorys %d (%d)", tdata[t_nr].team->name, tdata[t_nr].team->wins, tdata[t_nr].team->points);
sx = (gfx.res.y - strlen (text) * font[0].size.x) / 2;
font_gfxdrawbold (sx, sy+3, text, 0, COLOR_brown, 1, 1);
font_gfxdraw (sx, sy+3, text, 0, COLOR_yellow, 2);
sx = (pos_w - strlen (text) * font[0].size.x) / 2;
font_gfxdrawbold (pos_x + sx, pos_y + sy+3, text, 0, COLOR_brown, 1, 1);
font_gfxdraw (pos_x + sx, pos_y + sy+3, text, 0, COLOR_yellow, 2);
sy += SHOWRESULT_TEAMHEAD;
dx = (gfx.res.x - 40) / p_x;
sx = 20 + (dx - SHOWRESULT_TEAMPLAYERWIDTH)/2;
dx = pos_w / p_x;
sx = (dx - SHOWRESULT_TEAMPLAYERWIDTH)/2;
for (col = 0, p_nr = 0; p_nr < tdata[t_nr].cnt; p_nr++) {
if (col == 0 || col >= p_x) {
@ -638,8 +638,8 @@ void game_showresultteam () {
}
if (tdata[t_nr].pl[p_nr]->gfx != NULL) {
dest.x = x;
dest.y = sy;
dest.x = pos_x + x;
dest.y = pos_y + sy;
src.w = dest.w = tdata[t_nr].pl[p_nr]->gfx->small_image->w;
src.h = dest.h = tdata[t_nr].pl[p_nr]->gfx->small_image->h;
src.x = 0;
@ -647,7 +647,7 @@ void game_showresultteam () {
gfx_blit (tdata[t_nr].pl[p_nr]->gfx->small_image, &src, gfx.screen, &dest, 1);
}
sprintf (text, "%s(%d/%d)", tdata[t_nr].pl[p_nr]->name, tdata[t_nr].pl[p_nr]->wins, tdata[t_nr].pl[p_nr]->points);
font_gfxdraw (x + GFX_SMALLPLAYERIMGSIZE_X*2, sy + 2, text, 0, 0, 2);
font_gfxdraw (pos_x + x + GFX_SMALLPLAYERIMGSIZE_X*2, pos_y + sy + 2, text, 0, 0, 2);
x += dx;
col++;
}
@ -661,8 +661,8 @@ void game_showresultteam () {
/* Bomberman/Deathmatch Version Play */
#define SHOWRESULT_WIDTH 150
#define SHOWRESULT_HEIGHT 80
void game_showresultnormal () {
#define SHOWRESULT_HEIGHT 60
void game_showresultnormal (int pos_x, int pos_y, int pos_w, int pos_h) {
char text[255];
int i, p, x, y, pl_cnt = 0,
pl_x, pl_y, // player in a row/col
@ -689,17 +689,22 @@ void game_showresultnormal () {
pl_cnt++;
}
if (pl_cnt == 0) {
/* we still haven't joined the game */
}
/* calc the best view and start point */
pl_x = 0;
do {
pl_x++;
pl_y = ceil ((float)(((float) pl_cnt) / ((float)pl_x)));
dy = (gfx.res.y - 100) / pl_y;
if (pl_y == 0) pl_y++;
dy = pos_h / pl_y;
} while (dy < SHOWRESULT_HEIGHT);
dx = (gfx.res.x - 40) / pl_x;
dx = pos_w / pl_x;
x = sx = 20 + (dx - SHOWRESULT_WIDTH)/2;
y = sy = 60 + (dy - SHOWRESULT_HEIGHT)/2;
x = sx = (dx - SHOWRESULT_WIDTH)/2;
y = sy = (dy - SHOWRESULT_HEIGHT)/2;
px = 0;
d_printf ("game_showresultnormal: pl_x:%d, pl_y:%d, dx:%d, dy:%d\n", pl_x, pl_y, dx, dy);
@ -708,18 +713,18 @@ void game_showresultnormal () {
for (i = 1, p = 0; p < pl_cnt; p++) {
if (PS_IS_used (pl[p]->state)) {
if (PS_IS_alife (pl[p]->state)) {
font_gfxdrawbold (x + GFX_MENUPLAYERIMGSIZE_X, y - 10, pl[p]->name, 0, COLOR_brown, 1, 1);
font_gfxdraw (x + GFX_MENUPLAYERIMGSIZE_X, y - 10, pl[p]->name, 0, COLOR_yellow, 1);
font_gfxdrawbold (pos_x + x + GFX_MENUPLAYERIMGSIZE_X, pos_y + y - 10, pl[p]->name, 0, COLOR_brown, 1, 1);
font_gfxdraw (pos_x + x + GFX_MENUPLAYERIMGSIZE_X,pos_y + y - 10, pl[p]->name, 0, COLOR_yellow, 1);
}
else
font_gfxdraw (x + GFX_MENUPLAYERIMGSIZE_X, y - 10, pl[p]->name, 0, COLOR_gray, 1);
font_gfxdraw (pos_x + x + GFX_MENUPLAYERIMGSIZE_X,pos_y + y - 10, pl[p]->name, 0, COLOR_gray, 1);
sprintf (text, "%3d (%3d)", pl[p]->wins, pl[p]->points);
font_gfxdraw (x + GFX_MENUPLAYERIMGSIZE_X, y + 6, text, 0, 0, 1);
font_gfxdraw (pos_x + x + GFX_MENUPLAYERIMGSIZE_X, pos_y + y + 6, text, 0, 0, 1);
if (pl[p]->gfx != NULL) {
dest.x = x;
dest.y = y - 16;
dest.x = pos_x + x;
dest.y = pos_y + y - 16;
src.w = dest.w = pl[p]->gfx->menu_image->w;
src.h = dest.h = pl[p]->gfx->menu_image->h;
src.x = 0;
@ -769,9 +774,9 @@ void game_showresult () {
font_draw (x, gfx.res.y - font[0].size.y - 2, text, 0, COLOR_yellow);
if (bman.gametype == GT_team)
game_showresultteam ();
game_showresultteam (10,50,gfx.res.x-20,gfx.res.y-100);
else
game_showresultnormal ();
game_showresultnormal (10,50,gfx.res.x-20,gfx.res.y-100);
gfx_blitdraw ();
SDL_Flip (gfx.screen);
@ -867,8 +872,11 @@ void game_menu_loop (SDL_Event *event, int eventstate) {
bman.timeout = -GAME_OVERTIMEOUT;
}
else if (menu->focus->id == 3) /* End Game */
else if (menu->focus->id == 3) { /* End Game */
/* send network update */
net_game_send_delplayer (bman.p_nr);
bman.state = GS_quit;
}
else { /* Quit Menu */
menu_delete (menu);

@ -1,4 +1,4 @@
/* $Id: multiwait.c,v 1.51 2004/11/07 04:13:10 stpohle Exp $
/* $Id: multiwait.c,v 1.52 2004/11/30 14:30:36 stpohle Exp $
multiwait.c - this manages only the network screen where
everyone have to select it's players and where even the basic chat is inside
*/
@ -20,7 +20,7 @@ static void mw_keys_loop ();
static void mw_draw_all_player ();
static void mw_draw_all_teams ();
static int mw_team_is_used (int t_nr);
/* static int mw_team_is_used (int t_nr); */
static int mw_check_players ();
static int mw_check_screenredraw ();
@ -29,7 +29,7 @@ extern int blitdb_nr;
/* returns number of active players in a team */
/* returns number of active players in a team
static int mw_team_is_used (int t_nr) {
int i,j=0;
for(i=0;i<MAX_PLAYERS;i++)
@ -37,7 +37,7 @@ static int mw_team_is_used (int t_nr) {
d_printf("Team: %s : %d players\n",teams[t_nr].name,j);
return j;
}
*/
/* this will load some graphics and so other stuff */
static void mw_init ()
@ -49,6 +49,8 @@ static void mw_init ()
bman.updatestatusbar = 1;
d_playerdetail ("mw_init:\n");
SDL_Flip (gfx.screen);
chat_show (10, gfx.res.y / 2, gfx.res.x - 20, gfx.res.y / 2 - 10);
chat_setactive (1, 1);
};
@ -158,7 +160,8 @@ static int mw_check_screenredraw () {
* draw all player informations
*/
static void mw_draw_all_player () {
game_showresultnormal ();
game_showresultnormal (20, 30, gfx.res.x-40, (gfx.res.y / 2) - 60);
chat_draw ();
};
@ -166,7 +169,8 @@ static void mw_draw_all_player () {
* draw all team informations
*/
static void mw_draw_all_teams () {
game_showresultteam ();
game_showresultteam (20, 30, gfx.res.x-40, (gfx.res.y / 2) - 60);
chat_draw ();
};

@ -71,7 +71,6 @@ network_options ()
#ifndef _WIN32
menu_create_bool (menu, "IPV6", 260, 60, 100, &net_ai_typ, 4);
#endif
menu_create_bool (menu, "Firewall", 260, 100, 100, &bman.firewall, 5);
menu_create_bool (menu, "Private Game", 20, 220, 150, &bman.passwordenabled, 6);
menu_create_entry (menu, "Password:", 190, 220, 210, &bman.password, LEN_PASSWORD, MENU_entrytext, 7);
@ -217,7 +216,7 @@ void multiplayer_game () {
void
join_multiplayer_game ()
{
int i, old_ai_family;
int old_ai_family;
old_ai_family = bman.net_ai_family;
@ -253,13 +252,8 @@ join_multiplayer_game ()
LEN_PORT, bman.net_ai_family, &players[0].net.addr.sAddr);
/* and join the server */
if (bman.firewall)
i = NETF_firewall;
else
i = 0;
bman.p_nr = -1;
send_joingame (&players[0].net.addr, bman.playername, i);
send_joingame (&players[0].net.addr, bman.playername, 0);
/* go into the normal multiplayer loop */
multiplayer_game ();

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.68 2004/11/07 04:13:10 stpohle Exp $ */
/* $Id: network.c,v 1.69 2004/11/30 14:30:37 stpohle Exp $ */
/*
network routines.
*/
@ -423,6 +423,8 @@ net_change_playerid (int pl_nr)
{
int i;
d_printf ("net_change_playerid pl_nr:%d\n", pl_nr);
if (GT_MP_PTPM) {
/*
Send to all connected clients the update
@ -435,7 +437,7 @@ net_change_playerid (int pl_nr)
}
else {
/*
Send only to the Server the update and only if in_nr == bman.in_nr
Send only to the Server the update and only if pn_nr == bman.p_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,
@ -634,6 +636,10 @@ net_transmit_gamedata ()
};
/*
* send informations about a player too all connected players
* last_change: the player will not be send if (send_to_p_nr == p_nr)
*/
void
net_game_send_player (int p_nr)
{
@ -641,7 +647,7 @@ 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)
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) {
@ -732,8 +738,6 @@ net_game_send_delplayer (int pl_nr) {
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(i))
send_quit (&players[i].net.addr, pl_nr, new_server);
if (bman.notifygamemaster)
send_ogc_update ();
bman.updatestatusbar=1;
}

@ -128,8 +128,7 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
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->netflags == players[j].net.flags) i = j;
&& strncmp (players[j].net.addr.port, addr->port, LEN_PORT) == 0) i = j;
}
if (i == -1) i = freeslot;
@ -150,7 +149,9 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
team_choose (pl);
}
strncpy (pl->name, p_jg->name, LEN_PLAYERNAME);
player_set_gfx (pl, -1);
pl->gfx_nr = -1;
pl->gfx = NULL;
pl->state &= (0xFF - (PSF_alife + PSF_playing));
/* Reset the network data */
pl->net.timestamp = timestamp;
@ -163,7 +164,10 @@ 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);
pl->net.flags = p_jg->netflags;
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++;
@ -173,9 +177,9 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
addr->pl_nr = i;
/* Send all connected players the new PlayerID */
/* Send all connected players the new PlayerID, except to the new player */
for (i = 0; i < MAX_PLAYERS; i++)
if (NET_CANSEND(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);
@ -198,7 +202,7 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
void
send_joingame (_net_addr * addr, char *name, int flags)
send_joingame (_net_addr * addr, char *name, int secondplayer)
{
struct pkg_joingame p_jg;
int vmi,
@ -215,7 +219,7 @@ send_joingame (_net_addr * addr, char *name, int flags)
p_jg.ver_sub = vsu;
p_jg.ver_major = vma;
p_jg.ver_minor = vmi;
p_jg.netflags = flags;
p_jg.secondplayer = secondplayer;
strncpy (p_jg.name, name, LEN_PLAYERNAME);
strncpy (p_jg.password, bman.password, LEN_PASSWORD);
@ -223,6 +227,58 @@ send_joingame (_net_addr * addr, char *name, int flags)
};
/***
*** Packettype: contest
*** Test the connection from a new player for the firewall flag.
*** 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);
}
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;
ct_pkg.h.len = HTON16 (sizeof (struct pkg_contest));
ct_pkg.from = from;
ct_pkg.to = to;
send_pkg ((struct pkg *) &ct_pkg, addr);
}
/***
*** Packettype: playerid
*** Update Playerinformation, Teampoints of a Player, Points
@ -248,6 +304,7 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
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
*/
@ -256,17 +313,9 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
pl = &players[p_id->pl_nr];
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);
strncpy (pl->name, p_id->name, LEN_PLAYERNAME);
pl->net.timestamp = timestamp;
pl->net.pingreq = pl->net.pingack + 5;
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);
@ -282,6 +331,24 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
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 */
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) {
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);
strncpy (pl->name, p_id->name, LEN_PLAYERNAME);
if (GT_MP_PTPS) {
pl->points = NTOH16 (p_id->points);
pl->wins = NTOH16 (p_id->wins);
@ -297,7 +364,7 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
net_change_playerid (addr->pl_nr);
}
d_playerdetail ("*** PLAYER List ***");
// d_playerdetail ("*** PLAYER List ***");
team_update ();
bman.updatestatusbar = 1;
};
@ -308,13 +375,9 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport,
int pl_nr, int gfx_nr, int team_nr, signed char netflags)
{
struct pkg_playerid p_id;
int vmi,
vma,
vsu;
d_printf ("send_playerid SendTo: %s:%s (Name:%16s p_nr:%d)\n", addr->host,
addr->port, name, pl_nr);
sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu);
p_id.h.typ = PKG_playerid;
p_id.h.flags = PKGF_ackreq;
@ -375,22 +438,26 @@ 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, p_servnr: %d\n", s_mod->p_nr, s_mod->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[bman.p_servnr].net, &players[0].net, sizeof (_net_player));
}
/* 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) {
bman.p_nr = s_mod->p_nr;
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);
}
else if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p2_nr == -1 && s_mod->lplayer2 == 1) {
bman.p2_nr = s_mod->p_nr;
players[bman.p2_nr].net.flags = NETF_firewall + NETF_local2;
players[bman.p2_nr].state &= (0xFF - PSF_net);
strncpy (players[s_mod->p_nr].name, bman.player2name, LEN_PLAYERNAME);
}
@ -1576,8 +1643,15 @@ do_pkg (struct pkg *packet, _net_addr * addr)
return 0;
}
/* get the addr and set the ping timeout value */
/* 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 and PKG_contest */
addr->pl_nr = get_player_nr (addr->host, addr->port);
if ((addr->pl_nr < 0 || addr->pl_nr >= MAX_PLAYERS) && packet->h.typ > PKG_contest && 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;
@ -1622,6 +1696,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_pingreq):
do_ping ((struct pkg_ping *) packet, addr);
break;

@ -1,4 +1,4 @@
/* $Id: player.c,v 1.92 2004/11/07 04:13:10 stpohle Exp $
/* $Id: player.c,v 1.93 2004/11/30 14:30:37 stpohle Exp $
* player.c - everything what have to do with the player */
#include <SDL.h>
@ -826,6 +826,8 @@ player_clear_ilness (_player * p, int type)
void
player_set_gfx (_player * p, signed char gfx_nr)
{
d_printf ("player_set_gfx: name:%15s from gfx %d to gfx %d.\n", p->name, p->gfx_nr, gfx_nr);
p->gfx_nr = gfx_nr;
if (p->gfx_nr < 0 || p->gfx_nr >= MAX_PLAYERS)
p->gfx_nr = -1;
@ -1039,11 +1041,7 @@ void player2_join () {
}
}
else if (GT_MP_PTPS) { /* multiplayer client, send only the request */
int flags = NETF_local2;
if (bman.firewall)
flags |= NETF_firewall;
send_joingame (&players[bman.p_servnr].net.addr, bman.player2name, flags);
send_joingame (&players[bman.p_servnr].net.addr, bman.player2name, 1);
}
else { /* single mode */
for (i = 0; PS_IS_used (players[i].state) && i < MAX_PLAYERS; i++);

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.79 2004/11/07 04:13:10 stpohle Exp $ */
/* $Id: single.c,v 1.80 2004/11/30 14:30:37 stpohle Exp $ */
/* single player */
#include "basic.h"
@ -494,8 +494,8 @@ single_create_ai (int num_players)
for (count = 0; count < num_players; count++) {
/* find free players */
for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++)
if (!(PS_IS_used (players[p].state))) {
for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS);p++)
if (p < MAX_PLAYERS && !(PS_IS_used (players[p].state))) {
pl = &players[p];
sprintf (pl->name, "AI %d", p + 1);
pl->state |= PSF_used + PSF_alife + PSF_playing + PSF_ai;
@ -515,10 +515,17 @@ single_create_ai (int num_players)
team_choose (pl);
}
if (pl == NULL)
if (pl == NULL) {
d_printf ("single_create_ai: No free Player found.\n");
return -1;
}
return p;
else
d_printf ("single_create_ai: Player %d Created Name:%s\n", pl - players, pl->name);
}
if (pl != NULL)
return pl - players;
return -1;
};

Loading…
Cancel
Save