Network Packet Forwarding added for people behind a firewall

origin
stpohle 23 years ago
parent 418de30c29
commit 22de75c69a

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.26 2003/05/29 20:49:53 stpohle Exp $ */ /* $Id: network.c,v 1.27 2003/05/29 21:35:03 stpohle Exp $ */
/* /*
network routines. network routines.
*/ */
@ -546,7 +546,7 @@ net_game_send_player (int p_nr)
} }
else if (p_nr == bman.p_nr) { else if (p_nr == bman.p_nr) {
for (p = 0; p < MAX_PLAYERS; p++) for (p = 0; p < MAX_PLAYERS; p++)
if (PS_IS_netplayer (bman.players[p].state) && p != bman.p_nr && (bman.players[p].net.flags & NETF_firewall) == 0) if (PS_IS_netplayer (bman.players[p].state) && p != bman.p_nr && NET_CANSEND(p))
send_playerdata (&bman.players[p].net.addr, p_nr, &bman.players[p_nr]); send_playerdata (&bman.players[p].net.addr, p_nr, &bman.players[p_nr]);
} }
}; };
@ -563,7 +563,7 @@ net_game_send_playermove (int p_nr, int mustsend)
pl = &bman.players[p_nr]; pl = &bman.players[p_nr];
pl->net.pkgopt.send_to--; pl->net.pkgopt.send_to--;
if ((pl->net.pkgopt.send_to <= 0 || mustsend) && ( GT_MP_PTPM || (bman.players[p].net.flags & NETF_firewall) == 0)) if ((pl->net.pkgopt.send_to <= 0 || mustsend) && NET_CANSEND(p))
send_playermove (&bman.players[p].net.addr, p_nr, pl); send_playermove (&bman.players[p].net.addr, p_nr, pl);
/* network packet send control */ /* network packet send control */
@ -587,7 +587,7 @@ net_game_send_bomb (int p, int b)
return; return;
for (pl = 0; pl < MAX_PLAYERS; pl++) for (pl = 0; pl < MAX_PLAYERS; pl++)
if (PS_IS_netplayer (bman.players[pl].state) && pl != bman.p_nr && ( GT_MP_PTPM || (bman.players[p].net.flags & NETF_firewall) == 0)) if (PS_IS_netplayer (bman.players[pl].state) && pl != bman.p_nr && NET_CANSEND(pl))
send_bombdata (&bman.players[pl].net.addr, p, b, &bman.players[p].bombs[b]); send_bombdata (&bman.players[pl].net.addr, p, b, &bman.players[p].bombs[b]);
}; };
@ -603,7 +603,7 @@ net_game_send_field (int x, int y)
return; return;
for (pl = 0; pl < MAX_PLAYERS; pl++) for (pl = 0; pl < MAX_PLAYERS; pl++)
if (PS_IS_netplayer (bman.players[pl].state) && pl != bman.p_nr && ( GT_MP_PTPM || (bman.players[pl].net.flags & NETF_firewall) == 0)) if (PS_IS_netplayer (bman.players[pl].state) && pl != bman.p_nr && NET_CANSEND(pl))
send_field (&bman.players[pl].net.addr, x, y, &bman.field[x][y]); send_field (&bman.players[pl].net.addr, x, y, &bman.field[x][y]);
}; };
@ -674,7 +674,7 @@ net_send_servermode ()
int i; int i;
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_netplayer (bman.players[i].state) && i != bman.p_nr && ( GT_MP_PTPM || (bman.players[i].net.flags & NETF_firewall) == 0)) if (PS_IS_netplayer (bman.players[i].state) && i != bman.p_nr && NET_CANSEND(i))
send_servermode (&bman.players[i].net.addr, i); send_servermode (&bman.players[i].net.addr, i);
if (GT_MP_PTPM && bman.notifygamemaster) /* send notification the the gamemaster */ if (GT_MP_PTPM && bman.notifygamemaster) /* send notification the the gamemaster */
@ -707,7 +707,7 @@ net_send_chat (char *text, signed char notigamesrv)
int i; int i;
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_netplayer (bman.players[i].state) && i != bman.p_nr && ( GT_MP_PTPM || (bman.players[i].net.flags & NETF_firewall) == 0)) if (PS_IS_netplayer (bman.players[i].state) && i != bman.p_nr && NET_CANSEND(i))
send_chat (&bman.players[i].net.addr, text); send_chat (&bman.players[i].net.addr, text);
if (GT_MP_PTPM && bman.notifygamemaster && notigamesrv == 1) /* send notification the the gamemaster */ if (GT_MP_PTPM && bman.notifygamemaster && notigamesrv == 1) /* send notification the the gamemaster */
@ -723,7 +723,7 @@ net_game_send_ill (int p_nr)
d_printf ("net_game_send_ill (%d)\n", p_nr); d_printf ("net_game_send_ill (%d)\n", p_nr);
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_netplayer (bman.players[i].state) && i != bman.p_nr && ( GT_MP_PTPM || (bman.players[i].net.flags & NETF_firewall) == 0)) if (PS_IS_netplayer (bman.players[i].state) && i != bman.p_nr && NET_CANSEND(i))
send_ill (&bman.players[i].net.addr, p_nr, &bman.players[p_nr]); send_ill (&bman.players[i].net.addr, p_nr, &bman.players[p_nr]);
}; };
@ -801,6 +801,6 @@ net_game_send_special (int pl_nr, int ex_nr)
return; return;
for (pl = 0; pl < MAX_PLAYERS; pl++) for (pl = 0; pl < MAX_PLAYERS; pl++)
if (PS_IS_netplayer (bman.players[pl].state) && pl != pl_nr && ( GT_MP_PTPM || (bman.players[pl].net.flags & NETF_firewall) == 0)) if (PS_IS_netplayer (bman.players[pl].state) && pl != pl_nr && NET_CANSEND(pl))
send_special (&bman.players[pl].net.addr, pl_nr, bman.players[pl_nr].special, ex_nr); send_special (&bman.players[pl].net.addr, pl_nr, bman.players[pl_nr].special, ex_nr);
}; };

@ -21,6 +21,8 @@ network.h file... for everything what have to do with the network stuff
#define GS_WAITRUNNING (bman.state == GS_wait || bman.state == GS_ready || bman.state == GS_running) #define GS_WAITRUNNING (bman.state == GS_wait || bman.state == GS_ready || bman.state == GS_running)
#define NET_CANSEND(__pl) (( __pl == 0 || GT_MP_PTPM || (bman.players[__pl].net.flags & NETF_firewall) == 0))
#ifdef _WIN32 #ifdef _WIN32
#define _sockaddr sockaddr #define _sockaddr sockaddr
#else #else

@ -1012,7 +1012,7 @@ send_pkg (struct pkg *packet, _net_addr * addr)
/* forward the packet to all who are behind a firewall */ /* forward the packet to all who are behind a firewall */
void void
fwd_pkg (struct pkg *packet) fwd_pkg (struct pkg *packet, _net_addr * addr)
{ {
int pl; int pl;
@ -1025,12 +1025,17 @@ fwd_pkg (struct pkg *packet)
|| packet->h.typ == PKG_special) || packet->h.typ == PKG_special)
for (pl = 1; pl < MAX_PLAYERS; pl++) for (pl = 1; pl < MAX_PLAYERS; pl++)
if (PS_IS_netplayer (bman.players[pl].state) if (PS_IS_netplayer (bman.players[pl].state)
&& (bman.players[pl].net.flags & NETF_firewall) == NETF_firewall) && (bman.players[pl].net.flags & NETF_firewall) == NETF_firewall
&& ((strncmp (bman.players[pl].net.addr.host, addr->host, LEN_SERVERNAME) != 0)
|| (strncmp (bman.players[pl].net.addr.port, addr->port, LEN_PORT) != 0))) {
d_printf ("fwd_pkg %s:%s --> %s:%s\n", addr->host, addr->port, bman.players[pl].net.addr.host, bman.players[pl].net.addr.port);
send_pkg (packet, &bman.players[pl].net.addr); send_pkg (packet, &bman.players[pl].net.addr);
}
}; };
int int
do_pkg (struct pkg *packet, _net_addr * addr) { do_pkg (struct pkg *packet, _net_addr * addr)
{
if ((((packet->h.flags & PKGF_ipv6) == 0 && bman.net_ai_family != PF_INET) || if ((((packet->h.flags & PKGF_ipv6) == 0 && bman.net_ai_family != PF_INET) ||
((packet->h.flags & PKGF_ipv6) != 0 && bman.net_ai_family == PF_INET)) && ((packet->h.flags & PKGF_ipv6) != 0 && bman.net_ai_family == PF_INET)) &&
packet->h.typ != PKG_bcmservchat) { packet->h.typ != PKG_bcmservchat) {
@ -1048,8 +1053,7 @@ fwd_pkg (struct pkg *packet)
send_pkgack (addr, packet->h.typ, packet->h.id); send_pkgack (addr, packet->h.typ, packet->h.id);
/* check the packet with the index */ /* check the packet with the index */
if (packet->h.typ != PKG_bcmservchat if (packet->h.typ != PKG_bcmservchat && inpkg_check (packet->h.typ, packet->h.id, addr) != -1) {
&& inpkg_check (packet->h.typ, packet->h.id, addr) != -1) {
/* we have got this packet already */ /* we have got this packet already */
d_printf ("-----packet ignored\n"); d_printf ("-----packet ignored\n");
if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) if (addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
@ -1061,10 +1065,9 @@ fwd_pkg (struct pkg *packet)
if (packet->h.typ == PKG_servermode && packet->h.len != sizeof (struct pkg_servermode)) if (packet->h.typ == PKG_servermode && packet->h.len != sizeof (struct pkg_servermode))
send_error (addr, "pkg_servermode: packetsize incorrect."); send_error (addr, "pkg_servermode: packetsize incorrect.");
/* forward packet */ /* forward packet */
if (GT_MP_PTPM) if (GT_MP_PTPM)
fwd_pkg (packet); fwd_pkg (packet, addr);
switch (packet->h.typ) { switch (packet->h.typ) {
case (PKG_error): case (PKG_error):
@ -1131,4 +1134,4 @@ fwd_pkg (struct pkg *packet)
} }
return 0; return 0;
}; };

@ -272,7 +272,7 @@ extern void send_chat (_net_addr *addr, char *text);
extern void send_ill (_net_addr *addr, int p_nr, _player *pl); extern void send_ill (_net_addr *addr, int p_nr, _player *pl);
extern void send_special (_net_addr *addr, int p_nr, int typ, int ex_nr); extern void send_special (_net_addr *addr, int p_nr, int typ, int ex_nr);
extern void fwd_pkg (struct pkg *packet); extern void fwd_pkg (struct pkg *packet, _net_addr *addr);
extern int get_player_nr (char *host, char *port); extern int get_player_nr (char *host, char *port);
extern int inpkg_check (unsigned char typ, short int id, _net_addr *addr); extern int inpkg_check (unsigned char typ, short int id, _net_addr *addr);

@ -1,4 +1,4 @@
/* $Id: udp.c,v 1.8 2003/05/12 12:36:34 stpohle Exp $ */ /* $Id: udp.c,v 1.9 2003/05/29 21:35:04 stpohle Exp $ */
/* udp.c code for the network /* udp.c code for the network
File Version 0.2 File Version 0.2
*/ */
@ -141,11 +141,11 @@ dns_filladdr (char *host, int hostlen, char *port, int portlen, int ai_family,
void void
udp_send (int sock, char *text, int len, struct _sockaddr *sAddr, int ai_family) udp_send (int sock, char *text, int len, struct _sockaddr *sAddr, int ai_family)
{ {
int addrlen; int addrlen = sizeof (struct sockaddr_in);
#ifndef _WIN32
if (ai_family == PF_INET) if (ai_family == PF_INET)
addrlen = sizeof (struct sockaddr_in); addrlen = sizeof (struct sockaddr_in);
#ifndef _WIN32
else else
addrlen = sizeof (struct sockaddr_in6); addrlen = sizeof (struct sockaddr_in6);
#endif #endif

Loading…
Cancel
Save