/* used to update settings at startup */ void net_send_playerid (int pl_nr) { int i; d_printf ("net_send_playerid pl_nr:%d\n", pl_nr); if (GT_MP_PTPM) { /* Send to all connected clients the update */ 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); } else { /* 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, 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); } 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); };
/* * keyboard handling for keys which have nothing to do with the playerkeys * before calling this function make sure keyb_loop (); was called. * * chat mode: the chatmode should only be disabled in the game mode * in the GS_wait mode the chat will always be active. */ void game_keys_loop () { if (menu != NULL) { /* delete all movement keys */ int i; for (i = 0; i < BCPK_max * 2; i++) keyb_gamekeys.state[i] = 0; } else { /* don't go into the game_keys if there is no menu displayed */ if (GT_MP_PTPM && bman.state == GS_ready && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) { /* Server is starting the game * check in multiplayer if all players are ready for the game */ int i, ready = 1; for (i = 0; i < MAX_PLAYERS; i++) if (NET_CANSEND (i) && !players[i].ready) ready = 0; if (ready) bman.state = GS_running; else d_printf ("game_keys_loop: not all players are ready\n"); net_send_servermode (); bman.updatestatusbar = 1; // force an update } if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) { /* Switch Fullscreen */ SDL_WM_ToggleFullScreen (gfx.screen); gfx.fullscreen = !gfx.fullscreen; bman.updatestatusbar = 1; // force an update } if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) { if (chat.active && (bman.state == GS_ready || bman.state == GS_running) && IS_LPLAYER2) { chat.active = 0; d_printf ("Chatmode Disabled\n"); } else game_menu_create (); } if ((GT_MP_PTPM || GT_MP_PTPS) && keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) { chat_setactive (1, 0); chat.changed = 1; d_printf ("Chatmode Enabled\n"); } } };
void net_send_chat (char *text, signed char notigamesrv) { int i; for (i = 0; i < MAX_PLAYERS; i++) if (NET_CANSEND (i)) send_chat (&players[i].net.addr, text); };
/* send to all players the drop item list */ 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)) send_dropitems (&players[i].net.addr, pl_nr, fiptr, cnt); };
void net_game_send_ill (int p_nr) { int i; d_printf ("net_game_send_ill (%d)\n", p_nr); for (i = 0; i < MAX_PLAYERS; i++) if (NET_CANSEND (i)) send_ill (&players[i].net.addr, p_nr, &players[p_nr]); };
/* send special use elements into the network, to make sure nothing bad happens with explosions we send the ex_nr number too */ void net_game_send_special (int pl_nr, int ex_nr, int type) { int pl; d_printf ("Send Special Data pl_nr:%d ex_nr:%d type:%d\n", pl_nr, ex_nr, type); if (pl_nr < 0 || pl_nr >= MAX_PLAYERS) return; for (pl = 0; pl < MAX_PLAYERS; pl++) if (NET_CANSEND (pl)) send_special (&players[pl].net.addr, pl_nr, type, ex_nr); };
/* sends to everyone the teamdata */ void 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); };
void net_send_servermode () { int i; for (i = 0; i < MAX_PLAYERS; i++) if (NET_CANSEND (i)) send_servermode (&players[i].net.addr, i); if (bman.notifygamemaster && GT_MP_PTPM) send_ogc_update (); };
/* send the respawn data to all clients and with the new position of the player */ void net_game_send_respawn (int pl_nr) { int pl; d_printf ("Send Respawn Data %d New Position (%d,%d)\n", pl_nr); if (pl_nr < 0 || pl_nr >= MAX_PLAYERS) return; for (pl = 0; pl < MAX_PLAYERS; pl++) if (NET_CANSEND (pl)) send_respawn (&players[pl].net.addr, pl_nr); };
/* Send mapinformations to all clients */ void net_send_mapinfo () { int i; if (GT_MP_PTPS) return; d_printf ("Send Mapinfo\n"); for (i = 0; i < MAX_PLAYERS; i++) if (NET_CANSEND (i)) send_mapinfo (&players[i].net.addr); };
/* sends to everyone an up to date playerlist*/ void net_send_players () { int i, j; for (j = 0; j < MAX_PLAYERS; j++) 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); };
void net_game_send_field (int x, int y) { int pl; d_printf ("Send FieldData %d, %d\n", x, y); if (x < 0 || x >= MAX_FIELDSIZE_X || y < 0 || y >= MAX_FIELDSIZE_Y) return; for (pl = 0; pl < MAX_PLAYERS; pl++) if (NET_CANSEND (pl)) send_field (&players[pl].net.addr, x, y, &map.field[x][y]); };
/* * send informations about a player too all connected players * last_change: the player will not be send if (send_to_p_nr == bman.p_nr) */ void net_game_send_player (int p_nr) { int p; 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) 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)) send_playerdata (&players[p].net.addr, p_nr, &players[p_nr]); } };
void 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) return; d_printf ("Send BombData %d, %d\n", p, b); if (p < 0 || p >= MAX_PLAYERS || b < 0 || b >= MAX_BOMBS) return; for (pl = 0; pl < MAX_PLAYERS; pl++) if (NET_CANSEND (pl)) send_bombdata (&players[pl].net.addr, p, b, &players[p].bombs[b]); };
void net_game_send_playermove (int p_nr, int mustsend) { int p; _player *pl; for (p = 0; p < MAX_PLAYERS; p++) 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); /* 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; } };
/* * send the information about the deleted player to all clients */ void net_game_send_delplayer (int pl_nr) { int i; 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); if (GT_MP_PTPM) { if (bman.notifygamemaster) send_ogc_update (); if (new_server >= 0 && new_server < MAX_PLAYERS) bman.p_servnr = new_server; } };