DEADSOFTWARE

Cosmetic: Replace "goal" with "score" everywhere in game code
[d2df-sdl.git] / src / game / g_netmsg.pas
index 910a480a78d25b4073593853012ef1a7d8e6a5b4..1d63ec09505828e05b9ac9e6eeddf5c23bd5c01d 100644 (file)
@@ -400,9 +400,8 @@ begin
     B := M.ReadByte();
     T := M.ReadByte();
     WeapSwitch := M.ReadByte();
-    if (WeapSwitch = 2) then
-      for I := WP_FIRST to WP_LAST + 1 do
-        TmpPrefArray[I] := M.ReadByte();
+    for I := WP_FIRST to WP_LAST + 1 do
+      TmpPrefArray[I] := M.ReadByte();
     SwitchEmpty := M.ReadByte();
     SkipF := M.ReadByte();
   except
@@ -461,8 +460,7 @@ begin
   begin
     Name := PName;
     WeapSwitchMode := WeapSwitch;
-    if (WeapSwitch = 2) then
-      SetWeaponPrefs(TmpPrefArray);
+    SetWeaponPrefs(TmpPrefArray);
     SwitchToEmpty := SwitchEmpty;
     SkipFist := SkipF;
     Reset(True);
@@ -557,6 +555,14 @@ end;
 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
 begin
   //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
+
+  if C^.FullUpdateSent then
+  begin
+    // FullStateRequest spam?
+    g_Net_Penalize(C, 'duplicate full state request');
+    exit;
+  end;
+
   if gGameOn then
   begin
     MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
@@ -732,9 +738,8 @@ begin
     TmpColor.B := M.ReadByte();
     TmpTeam := M.ReadByte();
     TmpWeapSwitch := M.ReadByte();
-    if (TmpWeapSwitch = 2) then
-      for I := WP_FIRST to WP_LAST + 1 do
-        TmpPrefArray[I] := M.ReadByte();
+    for I := WP_FIRST to WP_LAST + 1 do
+      TmpPrefArray[I] := M.ReadByte();
     TmpSwEmpty := M.ReadByte();
     TmpSkipF := M.ReadByte();
   except
@@ -763,9 +768,7 @@ begin
   if (TmpWeapSwitch <> Pl.WeapSwitchMode) then
     Pl.WeapSwitchMode := TmpWeapSwitch;
 
-  if (TmpWeapSwitch = 2) then
-    Pl.SetWeaponPrefs(TmpPrefArray);
-
+  Pl.SetWeaponPrefs(TmpPrefArray);
   if (TmpSwEmpty <> Pl.SwitchToEmpty) then
     Pl.SwitchToEmpty := TmpSwEmpty;
 
@@ -899,11 +902,14 @@ procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NE
 var
   I: Integer;
 begin
-  if (ID >= 0) and (ID < length(NetClients)) then
-  begin
-    e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
-    MH_ProcessFirstSpawn(@NetClients[ID]);
-  end;
+  if (ID < 0) or (ID >= Length(NetClients)) then
+    exit; // bogus client, this shouldn't happen
+
+  NetClients[ID].FullUpdateSent := True;
+
+  e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
+
+  MH_ProcessFirstSpawn(@NetClients[ID]);
 
   if gPlayers <> nil then
   begin
@@ -976,7 +982,7 @@ begin
   NetOut.Write(g_ExtractFileName(gMapInfo.Map));
   NetOut.Write(gWADHash);
   NetOut.Write(gGameSettings.GameMode);
-  NetOut.Write(gGameSettings.GoalLimit);
+  NetOut.Write(gGameSettings.ScoreLimit);
   NetOut.Write(gGameSettings.TimeLimit);
   NetOut.Write(gGameSettings.MaxLives);
   NetOut.Write(gGameSettings.Options);
@@ -1130,8 +1136,8 @@ begin
   NetOut.Write(Byte(NET_MSG_SCORE));
   if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
   begin
-    NetOut.Write(gTeamStat[TEAM_RED].Goals);
-    NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
+    NetOut.Write(gTeamStat[TEAM_RED].Score);
+    NetOut.Write(gTeamStat[TEAM_BLUE].Score);
   end
   else
     if gGameSettings.GameMode = GM_COOP then
@@ -1206,7 +1212,7 @@ procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
 begin
   NetOut.Write(Byte(NET_MSG_GSET));
   NetOut.Write(gGameSettings.GameMode);
-  NetOut.Write(gGameSettings.GoalLimit);
+  NetOut.Write(gGameSettings.ScoreLimit);
   NetOut.Write(gGameSettings.TimeLimit);
   NetOut.Write(gGameSettings.MaxLives);
   NetOut.Write(gGameSettings.Options);
@@ -1893,8 +1899,8 @@ procedure MC_RECV_GameStats(var M: TMsg);
 begin
   if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
   begin
-    gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
-    gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
+    gTeamStat[TEAM_RED].Score := M.ReadSmallInt();
+    gTeamStat[TEAM_BLUE].Score := M.ReadSmallInt();
   end
   else
     if gGameSettings.GameMode = GM_COOP then
@@ -2359,7 +2365,7 @@ end;
 procedure MC_RECV_GameSettings(var M: TMsg);
 begin
   gGameSettings.GameMode := M.ReadByte();
-  gGameSettings.GoalLimit := M.ReadWord();
+  gGameSettings.ScoreLimit := M.ReadWord();
   gGameSettings.TimeLimit := M.ReadWord();
   gGameSettings.MaxLives := M.ReadByte();
   gGameSettings.Options := M.ReadLongWord();
@@ -2685,7 +2691,6 @@ var
   TmpModel: string;
   TmpColor: TRGB;
   TmpTeam: Byte;
-  i: Integer;
   Pl: TPlayer;
   PID: Word;
 begin
@@ -3164,9 +3169,8 @@ begin
   NetOut.Write(gPlayer1Settings.Color.B);
   NetOut.Write(gPlayer1Settings.Team);
   NetOut.Write(gPlayer1Settings.WeaponSwitch);
-  if (gPlayer1Settings.WeaponSwitch = 2) then
-    for i := WP_FIRST to WP_LAST + 1 do
-      NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
+  for i := WP_FIRST to WP_LAST + 1 do
+    NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
   NetOut.Write(gPlayer1Settings.SwitchToEmpty);
   NetOut.Write(gPlayer1Settings.SkipFist);
 
@@ -3318,9 +3322,8 @@ begin
   NetOut.Write(gPlayer1Settings.Color.B);
   NetOut.Write(gPlayer1Settings.Team);
   NetOut.Write(gPlayer1Settings.WeaponSwitch);
-  if (gPlayer1Settings.WeaponSwitch = 2) then
-    for i := WP_FIRST to WP_LAST + 1 do
-      NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
+  for i := WP_FIRST to WP_LAST + 1 do
+    NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
   NetOut.Write(gPlayer1Settings.SwitchToEmpty);
   NetOut.Write(gPlayer1Settings.SkipFist);