void NetworkInit (void) { int nPlayerSave = gameData.multiplayer.nLocalPlayer; GameDisableCheats (); gameStates.multi.bIWasKicked = 0; gameStates.gameplay.bFinalBossIsDead = 0; networkData.nNamesInfoSecurity = -1; #ifdef NETPROFILING OpenSendLog (); OpenReceiveLog (); #endif InitAddressFilter (); InitPacketHandlers (); memset (gameData.multiplayer.maxPowerupsAllowed, 0, sizeof (gameData.multiplayer.maxPowerupsAllowed)); memset (gameData.multiplayer.powerupsInMine, 0, sizeof (gameData.multiplayer.powerupsInMine)); networkData.nTotalMissedPackets = 0; networkData.nTotalPacketsGot = 0; memset (&netGame, 0, sizeof (tNetgameInfo)); memset (&netPlayers, 0, sizeof (tAllNetPlayersInfo)); networkData.thisPlayer.nType = PID_REQUEST; memcpy (networkData.thisPlayer.player.callsign, LOCALPLAYER.callsign, CALLSIGN_LEN+1); networkData.thisPlayer.player.versionMajor=D2X_MAJOR; networkData.thisPlayer.player.versionMinor=D2X_MINOR | (IS_D2_OEM ? NETWORK_OEM : 0); networkData.thisPlayer.player.rank=GetMyNetRanking (); if (gameStates.multi.nGameType >= IPX_GAME) { memcpy (networkData.thisPlayer.player.network.ipx.node, IpxGetMyLocalAddress (), 6); if (gameStates.multi.nGameType == UDP_GAME) * ((ushort *) (networkData.thisPlayer.player.network.ipx.node + 4)) = htons (* ((ushort *) (networkData.thisPlayer.player.network.ipx.node + 4))); // if (gameStates.multi.nGameType == UDP_GAME) // memcpy (networkData.thisPlayer.player.network.ipx.node, ipx_LocalAddress + 4, 4); memcpy (networkData.thisPlayer.player.network.ipx.server, IpxGetMyServerAddress (), 4); } networkData.thisPlayer.player.computerType = DOS; for (gameData.multiplayer.nLocalPlayer = 0; gameData.multiplayer.nLocalPlayer < MAX_NUM_NET_PLAYERS; gameData.multiplayer.nLocalPlayer++) InitPlayerStatsGame (); gameData.multiplayer.nLocalPlayer = nPlayerSave; MultiNewGame (); networkData.bNewGame = 1; gameData.reactor.bDestroyed = 0; NetworkFlush (); netGame.nPacketsPerSec = mpParams.nPPS; }
void DoShowNetGameHelp (void) { CMenu m (30); char szText [MENU_MAX_TEXTLEN]; int i, eff; #if DBG int pl; #endif //char *eff_strings[]={"trashing", "really hurting", "seriously affecting", "hurting", "affecting", "tarnishing"}; sprintf (szText, TXT_INFO_GAME, netGame.m_info.szGameName); m.AddText (szText); sprintf (szText, TXT_INFO_MISSION, netGame.m_info.szMissionTitle); m.AddText (szText); sprintf (szText, TXT_INFO_LEVEL, netGame.m_info.GetLevel ()); m.AddText (szText); sprintf (szText, TXT_INFO_SKILL, MENU_DIFFICULTY_TEXT (netGame.m_info.difficulty)); m.AddText (szText); sprintf (szText, TXT_INFO_MODE, GT (537 + netGame.m_info.gameMode)); m.AddText (szText); sprintf (szText, TXT_INFO_SERVER, gameData.multiplayer.players [NetworkWhoIsMaster()].callsign); m.AddText (szText); sprintf (szText, TXT_INFO_PLRNUM, NetworkHowManyConnected (), netGame.m_info.nMaxPlayers); m.AddText (szText); sprintf (szText, TXT_INFO_PPS, netGame.GetPacketsPerSec ()); m.AddText (szText); sprintf (szText, TXT_INFO_SHORTPKT, netGame.GetShortPackets () ? "Yes" : "No"); m.AddText (szText); #if DBG pl = (int) ((double (networkData.nTotalMissedPackets) / double (networkData.nTotalPacketsGot + networkData.nTotalMissedPackets)) * 100.0); if (pl < 0) pl = 0; sprintf (szText, TXT_INFO_LOSTPKT, networkData.nTotalMissedPackets, pl); m.AddText (szText); #endif if (netGame.GetScoreGoal ()) sprintf (szText, TXT_INFO_SCOREGOAL, netGame.GetScoreGoal () * 5); sprintf (szText, " "); sprintf (szText, TXT_INFO_PLRSCONN); netPlayers.m_info.players [gameData.multiplayer.nLocalPlayer].rank = GetMyNetRanking (); for (i = 0; i < gameData.multiplayer.nPlayers; i++) if (gameData.multiplayer.players [i].connected) { if (!gameOpts->multi.bNoRankings) { if (i == gameData.multiplayer.nLocalPlayer) sprintf (szText, "%s%s (%d/%d)", pszRankStrings [netPlayers.m_info.players [i].rank], gameData.multiplayer.players [i].callsign, networkData.nNetLifeKills, networkData.nNetLifeKilled); else sprintf (szText, "%s%s %d/%d", pszRankStrings[netPlayers.m_info.players [i].rank], gameData.multiplayer.players [i].callsign, gameData.multigame.kills.matrix[gameData.multiplayer.nLocalPlayer][i], gameData.multigame.kills.matrix[i][gameData.multiplayer.nLocalPlayer]); } else sprintf (szText, "%s", gameData.multiplayer.players [i].callsign); m.AddText (szText); } m.AddText (""); eff = (int)((double)((double) networkData.nNetLifeKills / ((double) networkData.nNetLifeKilled + (double) networkData.nNetLifeKills))*100.0); if (eff < 0) eff = 0; if (gameData.app.nGameMode & GM_HOARD) { if (gameData.score.nPhallicMan == -1) sprintf (szText, TXT_NO_RECORD2); else sprintf (szText, TXT_RECORD3, gameData.multiplayer.players [gameData.score.nPhallicMan].callsign, gameData.score.nPhallicLimit); } else if (!gameOpts->multi.bNoRankings) { sprintf (szText, TXT_EFF_LIFETIME, eff); m.AddText (szText); if (eff < 60) sprintf (szText, TXT_EFF_INFLUENCE, GT(546 + eff / 10)); else sprintf (szText, TXT_EFF_SERVEWELL); m.AddText (szText); } //paletteManager.SuspendEffect(); bPauseableMenu = 1; m.TinyMenu (NULL, "NetGame Information"); //paletteManager.ResumeEffect (); }
void NetworkReadSyncPacket (tNetgameInfo * sp, int rsinit) { int i, j; char szLocalCallSign [CALLSIGN_LEN+1]; tNetPlayerInfo *playerP; #if defined (WORDS_BIGENDIAN) || defined (__BIG_ENDIAN__) tNetgameInfo tmp_info; if ((gameStates.multi.nGameType >= IPX_GAME) && (sp != &netGame)) { // for macintosh -- get the values unpacked to our structure format ReceiveFullNetGamePacket (reinterpret_cast<ubyte*> (sp), &tmp_info); sp = &tmp_info; } #endif if (rsinit) playerInfoP = &netPlayers; // This function is now called by all people entering the netgame. if (sp != &netGame) { char *p = reinterpret_cast<char*> (sp); ushort h; int i, s; for (i = 0, h = -1; i < (int) sizeof (tNetgameInfo) - 1; i++, p++) { s = *reinterpret_cast<ushort*> (p); if (s == networkData.nSegmentCheckSum) { h = i; break; } else if (((s / 256) + (s % 256) * 256) == networkData.nSegmentCheckSum) { h = i; break; } } memcpy (&netGame, sp, sizeof (tNetgameInfo)); memcpy (&netPlayers, playerInfoP, sizeof (tAllNetPlayersInfo)); } gameData.multiplayer.nPlayers = sp->nNumPlayers; gameStates.app.nDifficultyLevel = sp->difficulty; networkData.nStatus = sp->gameStatus; //Assert (gameStates.app.nFunctionMode != FMODE_GAME); // New code, 11/27 #if 1 console.printf (1, "netGame.checksum = %d, calculated checksum = %d.\n", netGame.nSegmentCheckSum, networkData.nSegmentCheckSum); #endif if (netGame.nSegmentCheckSum != networkData.nSegmentCheckSum) { if (extraGameInfo [0].bAutoDownload) networkData.nStatus = NETSTAT_AUTODL; else { short nInMenu = gameStates.menus.nInMenu; gameStates.menus.nInMenu = 0; networkData.nStatus = NETSTAT_MENU; MsgBox (TXT_ERROR, NULL, 1, TXT_OK, TXT_NETLEVEL_MISMATCH); gameStates.menus.nInMenu = nInMenu; } #if 1//!DBG return; #endif } // Discover my CPlayerData number memcpy (szLocalCallSign, LOCALPLAYER.callsign, CALLSIGN_LEN+1); gameData.multiplayer.nLocalPlayer = -1; for (i = 0; i < MAX_NUM_NET_PLAYERS; i++) gameData.multiplayer.players [i].netKillsTotal = 0; for (i = 0, playerP = playerInfoP->players; i < gameData.multiplayer.nPlayers; i++, playerP++) { if (!CmpLocalPlayer (&playerP->network, playerP->callsign, szLocalCallSign)) { if (gameData.multiplayer.nLocalPlayer != -1) { Int3 (); // Hey, we've found ourselves twice MsgBox (TXT_ERROR, NULL, 1, TXT_OK, TXT_DUPLICATE_PLAYERS); console.printf (CON_DBG, TXT_FOUND_TWICE); networkData.nStatus = NETSTAT_MENU; return; } ChangePlayerNumTo (i); } memcpy (gameData.multiplayer.players [i].callsign, playerP->callsign, CALLSIGN_LEN+1); if (gameStates.multi.nGameType >= IPX_GAME) { #ifdef WORDS_NEED_ALIGNMENT uint server; memcpy (&server, playerP->network.ipx.server, 4); if (server != 0) IpxGetLocalTarget ( reinterpret_cast<ubyte*> (&server), playerInfoP->players [i].network.ipx.node, gameData.multiplayer.players [i].netAddress); #else // WORDS_NEED_ALIGNMENT if (*reinterpret_cast<uint*> (playerInfoP->players [i].network.ipx.server) != 0) IpxGetLocalTarget ( playerInfoP->players [i].network.ipx.server, playerInfoP->players [i].network.ipx.node, gameData.multiplayer.players [i].netAddress); #endif // WORDS_NEED_ALIGNMENT else memcpy (gameData.multiplayer.players [i].netAddress, playerInfoP->players [i].network.ipx.node, 6); } gameData.multiplayer.players [i].nPacketsGot = 0; // How many packets we got from them gameData.multiplayer.players [i].nPacketsSent = 0; // How many packets we sent to them gameData.multiplayer.players [i].connected = playerP->connected; gameData.multiplayer.players [i].netKillsTotal = sp->playerKills [i]; gameData.multiplayer.players [i].netKilledTotal = sp->killed [i]; if (networkData.nJoinState || (i != gameData.multiplayer.nLocalPlayer)) gameData.multiplayer.players [i].score = sp->playerScore [i]; for (j = 0; j < MAX_NUM_NET_PLAYERS; j++) gameData.multigame.kills.matrix [i][j] = sp->kills [i][j]; } if (gameData.multiplayer.nLocalPlayer < 0) { MsgBox (TXT_ERROR, NULL, 1, TXT_OK, TXT_PLAYER_REJECTED); networkData.nStatus = NETSTAT_MENU; return; } if (networkData.nJoinState) { for (i = 0; i < gameData.multiplayer.nPlayers; i++) gameData.multiplayer.players [i].netKilledTotal = sp->killed [i]; NetworkProcessMonitorVector (sp->monitorVector); LOCALPLAYER.timeLevel = sp->xLevelTime; } gameData.multigame.kills.nTeam [0] = sp->teamKills [0]; gameData.multigame.kills.nTeam [1] = sp->teamKills [1]; LOCALPLAYER.connected = 1; netPlayers.players [gameData.multiplayer.nLocalPlayer].connected = 1; netPlayers.players [gameData.multiplayer.nLocalPlayer].rank = GetMyNetRanking (); if (!networkData.nJoinState) { int j, bGotTeamSpawnPos = (IsTeamGame) && GotTeamSpawnPos (); for (i = 0; i < gameData.multiplayer.nPlayerPositions; i++) { if (bGotTeamSpawnPos) { j = TeamSpawnPos (i); if (j < 0) j = netGame.locations [i]; } else j = netGame.locations [i]; GetPlayerSpawn (j, OBJECTS + gameData.multiplayer.players [i].nObject); } } OBJECTS [LOCALPLAYER.nObject].SetType (OBJ_PLAYER); networkData.nStatus = (NetworkIAmMaster () || (networkData.nJoinState >= 4)) ? NETSTAT_PLAYING : NETSTAT_WAITING; SetFunctionMode (FMODE_GAME); networkData.bHaveSync = 1; MultiSortKillList (); }
void show_netplayerinfo() { int x=0, y=0, i=0, color=0, eff=0; static const char *const eff_strings[]={"trashing","really hurting","seriously affecting","hurting","affecting","tarnishing"}; gr_set_current_canvas(NULL); gr_set_curfont(GAME_FONT); gr_set_fontcolor(255,-1); x=(SWIDTH/2)-FSPACX(120); y=(SHEIGHT/2)-FSPACY(84); gr_settransblend(14, GR_BLEND_NORMAL); gr_setcolor( BM_XRGB(0,0,0) ); gr_rect((SWIDTH/2)-FSPACX(120),(SHEIGHT/2)-FSPACY(84),(SWIDTH/2)+FSPACX(120),(SHEIGHT/2)+FSPACY(84)); gr_settransblend(GR_FADE_OFF, GR_BLEND_NORMAL); // general game information y+=LINE_SPACING; gr_printf(0x8000,y,"%s",Netgame.game_name); #ifndef SHAREWARE y+=LINE_SPACING; gr_printf(0x8000,y,"%s - lvl: %i",Netgame.mission_title,Netgame.levelnum); #endif x+=FSPACX(8); y+=LINE_SPACING*2; unsigned gamemode = Netgame.gamemode; gr_printf(x,y,"game mode: %s",gamemode < (sizeof(GMNames) / sizeof(GMNames[0])) ? GMNames[gamemode] : "INVALID"); int base_flags_left = SWIDTH/2 - FSPACX(15); int flags_x = base_flags_left + FSPACX(30); int letter_spacing = FSPACX(7); int word_spacing = FSPACX(46); if(Netgame.RetroProtocol) { draw_flag("RetroP2P", 1, base_flags_left + word_spacing*0, y); } else if(Netgame.ShortPackets) { draw_flag("ShortPkt", 1, base_flags_left + word_spacing*0, y); } else { draw_flag("LongPkt", 1, base_flags_left + word_spacing*0, y); } char pps_string[16]; sprintf(pps_string, "PPS %d", Netgame.PacketsPerSec); draw_flag(pps_string, 1, base_flags_left + word_spacing*1, y); if(Netgame.SpawnStyle == SPAWN_STYLE_NO_INVUL ) { draw_flag("NoInvul", 1, base_flags_left + word_spacing*2, y); } else if (Netgame.SpawnStyle == SPAWN_STYLE_SHORT_INVUL ) { draw_flag("ShortInv", 1, base_flags_left + word_spacing*2, y); } else if (Netgame.SpawnStyle == SPAWN_STYLE_LONG_INVUL ) { draw_flag("LongInv", 1, base_flags_left + word_spacing*2, y); } else { draw_flag("Preview", 1, base_flags_left + word_spacing*2, y); } set_font_newline(); y+=LINE_SPACING; gr_printf(x,y,"difficulty: %s",MENU_DIFFICULTY_TEXT(Netgame.difficulty)); draw_flag("ColorLgt", Netgame.AllowColoredLighting, base_flags_left + word_spacing*0, y); draw_flag("BrtShips", Netgame.BrightPlayers, base_flags_left + word_spacing*1, y); draw_flag("ConcResp", Netgame.RespawnConcs, base_flags_left + word_spacing*2, y); set_font_newline(); y+=LINE_SPACING; gr_printf(x,y,"level time: %i:%02i:%02i",Players[Player_num].hours_level,f2i(Players[Player_num].time_level) / 60 % 60,f2i(Players[Player_num].time_level) % 60); char disp_string[16]; sprintf(disp_string, "Guns x%d", Netgame.PrimaryDupFactor == 0 ? 1 : Netgame.PrimaryDupFactor); draw_flag(disp_string, Netgame.PrimaryDupFactor > 1, base_flags_left + word_spacing*0, y); sprintf(disp_string, "Msls x%d", Netgame.SecondaryDupFactor == 0 ? 1 : Netgame.SecondaryDupFactor); draw_flag(disp_string, Netgame.SecondaryDupFactor > 1, base_flags_left + word_spacing*1, y); sprintf(disp_string, "Mcap %s", Netgame.SecondaryCapFactor == 0 ? "ALL" : (Netgame.SecondaryCapFactor == 1 ? "6" : "2")); draw_flag(disp_string, Netgame.SecondaryCapFactor > 0, base_flags_left + word_spacing*2, y); set_font_newline(); y+=LINE_SPACING; gr_printf(x,y,"total time: %i:%02i:%02i",Players[Player_num].hours_total,f2i(Players[Player_num].time_total) / 60 % 60,f2i(Players[Player_num].time_total) % 60); set_font_newline(); y+=LINE_SPACING; if (Netgame.KillGoal) gr_printf(x,y,"Kill goal: %d",Netgame.KillGoal*10); gr_printf(base_flags_left, y, "Items: "); draw_flag("L", Netgame.AllowedItems & NETFLAG_DOLASER, flags_x, y); flags_x += letter_spacing; draw_flag("Q", Netgame.AllowedItems & NETFLAG_DOQUAD, flags_x, y); flags_x += letter_spacing; draw_flag("V", Netgame.AllowedItems & NETFLAG_DOVULCAN, flags_x, y); flags_x += letter_spacing; draw_flag("A", Netgame.AllowedItems & NETFLAG_DOVULCANAMMO,flags_x, y); flags_x += letter_spacing; draw_flag("S", Netgame.AllowedItems & NETFLAG_DOSPREAD, flags_x, y); flags_x += letter_spacing; draw_flag("P", Netgame.AllowedItems & NETFLAG_DOPLASMA, flags_x, y); flags_x += letter_spacing; draw_flag("F", Netgame.AllowedItems & NETFLAG_DOFUSION, flags_x, y); flags_x += letter_spacing; draw_flag("C", 1, flags_x, y); flags_x += letter_spacing; draw_flag("H", Netgame.AllowedItems & NETFLAG_DOHOMING, flags_x, y); flags_x += letter_spacing; draw_flag("P", Netgame.AllowedItems & NETFLAG_DOPROXIM, flags_x, y); flags_x += letter_spacing; draw_flag("S", Netgame.AllowedItems & NETFLAG_DOSMART, flags_x, y); flags_x += letter_spacing; draw_flag("M", Netgame.AllowedItems & NETFLAG_DOMEGA, flags_x, y); flags_x += letter_spacing; draw_flag("C", Netgame.AllowedItems & NETFLAG_DOCLOAK, flags_x, y); flags_x += letter_spacing; draw_flag("I", Netgame.AllowedItems & NETFLAG_DOINVUL, flags_x, y); flags_x += letter_spacing; // player information (name, kills, ping, game efficiency) set_font_newline(); y+=LINE_SPACING*3; gr_printf(x,y,"player"); if (Game_mode & GM_MULTI_COOP) gr_printf(x+FSPACX(8)*7,y,"score"); else { gr_printf(x+FSPACX(8)*7,y,"kills"); gr_printf(x+FSPACX(8)*12,y,"deaths"); } gr_printf(x+FSPACX(8)*18,y,"ping"); gr_printf(x+FSPACX(8)*23,y,"efficiency"); if(Netgame.FairColors) selected_player_rgb = player_rgb_all_blue; else if(Netgame.BlackAndWhitePyros) selected_player_rgb = player_rgb_alt; else selected_player_rgb = player_rgb; // process players table for (i=0; i<MAX_PLAYERS; i++) { if (!Players[i].connected) continue; y+=LINE_SPACING; if (Game_mode & GM_TEAM) color=get_team(i); else color=Netgame.players[i].color;//i; gr_set_fontcolor( BM_XRGB(selected_player_rgb[color].r,selected_player_rgb[color].g,selected_player_rgb[color].b),-1 ); gr_printf(x,y,"%s\n",Players[i].callsign); if (Game_mode & GM_MULTI_COOP) gr_printf(x+FSPACX(8)*7,y,"%-6d",Players[i].score); else { gr_printf(x+FSPACX(8)*7,y,"%-6d",Players[i].net_kills_total); gr_printf(x+FSPACX(8)*12,y,"%-6d",Players[i].net_killed_total); } gr_printf(x+FSPACX(8)*18,y,"%-6d",Netgame.players[i].ping + Netgame.players[Player_num].ping); if (i != Player_num) gr_printf(x+FSPACX(8)*23,y,"%d/%d",kill_matrix[Player_num][i],kill_matrix[i][Player_num]); } y+=LINE_SPACING*2+(LINE_SPACING*(MAX_PLAYERS-N_players)); // printf team scores if (Game_mode & GM_TEAM) { gr_set_fontcolor(255,-1); gr_printf(x,y,"team"); gr_printf(x+FSPACX(8)*8,y,"score"); y+=LINE_SPACING; gr_set_fontcolor(BM_XRGB(selected_player_rgb[0].r,selected_player_rgb[0].g,selected_player_rgb[0].b),-1 ); gr_printf(x,y,"%s:",Netgame.team_name[0]); gr_printf(x+FSPACX(8)*8,y,"%i",team_kills[0]); y+=LINE_SPACING; gr_set_fontcolor(BM_XRGB(selected_player_rgb[1].r,selected_player_rgb[1].g,selected_player_rgb[1].b),-1 ); gr_printf(x,y,"%s:",Netgame.team_name[1]); gr_printf(x+FSPACX(8)*8,y,"%i",team_kills[1]); y+=LINE_SPACING*2; } else y+=LINE_SPACING*4; gr_set_fontcolor(255,-1); // additional information about game - ranking eff=(int)((float)((float)PlayerCfg.NetlifeKills/((float)PlayerCfg.NetlifeKilled+(float)PlayerCfg.NetlifeKills))*100.0); if (eff<0) eff=0; if (!PlayerCfg.NoRankings) { gr_printf(0x8000,y,"Your lifetime efficiency of %d%% (%d/%d)",eff,PlayerCfg.NetlifeKills,PlayerCfg.NetlifeKilled); y+=LINE_SPACING; if (eff<60) gr_printf(0x8000,y,"is %s your ranking.",eff_strings[eff/10]); else gr_printf(0x8000,y,"is serving you well."); y+=LINE_SPACING; gr_printf(0x8000,y,"your rank is: %s",RankStrings[GetMyNetRanking()]); } }