Fix issues with unsynced F and G messages being lost if current team which is supposed to convert them to synced f/g quits
authorunc0rr
Sun, 29 Jun 2014 22:50:21 +0400
changeset 10344 cceabf9628bb
parent 10343 fe9853dea6c4
child 10345 2b264d67fac3
Fix issues with unsynced F and G messages being lost if current team which is supposed to convert them to synced f/g quits
hedgewars/uTeams.pas
hedgewars/uTypes.pas
--- a/hedgewars/uTeams.pas	Sat Jun 28 14:51:45 2014 +0400
+++ b/hedgewars/uTeams.pas	Sun Jun 29 22:50:21 2014 +0400
@@ -629,7 +629,7 @@
 end;
 
 procedure chTeamGone(var s:shortstring);
-var t: LongInt;
+var t, i: LongInt;
     isSynced: boolean;
 begin
     isSynced:= s[1] = 's';
@@ -642,24 +642,31 @@
     if (t = cMaxTeams) or (TeamsArray[t] = nil) then
         exit;
 
+    TeamsArray[t]^.isGoneFlagPengingToBeSet:= true;
+
     if isSynced then
-        begin
-        with TeamsArray[t]^ do
-            if not hasGone then
+    begin
+    for i:= 0 to Pred(cMaxTeams) do
+        with TeamsArray[i]^ do
+            begin
+            if (not hasGone) and isGoneFlagPengingToBeSet then
                 begin
-                AddChatString('** '+ TeamName + ' is gone');
+                AddChatString('** '+ TeamName + ' is gone'); // TODO: localize
+                if not CurrentTeam^.ExtDriven then SendIPC(_S'f' + s);
                 hasGone:= true;
-
-                RecountTeamHealth(TeamsArray[t])
+                isGoneFlagPengingToBeSet:= false;
+                RecountTeamHealth(TeamsArray[i])
                 end;
-        end
+            if hasGone and isGoneFlagPengingToBeUnset then
+                ParseCommand('/teamback s' + s, true);
+            end;
+    end
     else
     begin
-        if not CurrentTeam^.ExtDriven then
-        begin
-            SendIPC(_S'f' + s);
+        TeamsArray[t]^.isGoneFlagPengingToBeSet:= true;
+
+        if (not CurrentTeam^.ExtDriven) or (CurrentTeam^.TeamName = s) then
             ParseCommand('/teamgone s' + s, true);
-        end;
     end;
 end;
 
@@ -683,7 +690,9 @@
             if hasGone then
                 begin
                 AddChatString('** '+ TeamName + ' is back');
+                if not CurrentTeam^.ExtDriven then SendIPC(_S'g' + s);
                 hasGone:= false;
+                isGoneFlagPengingToBeUnset:= false;
 
                 RecountTeamHealth(TeamsArray[t]);
 
@@ -693,11 +702,10 @@
         end
     else
     begin
+        TeamsArray[t]^.isGoneFlagPengingToBeUnset:= true;
+
         if not CurrentTeam^.ExtDriven then
-        begin
-            SendIPC(_S'g' + s);
             ParseCommand('/teamback s' + s, true);
-        end;
     end;
 end;
 
--- a/hedgewars/uTypes.pas	Sat Jun 28 14:51:45 2014 +0400
+++ b/hedgewars/uTypes.pas	Sun Jun 29 22:50:21 2014 +0400
@@ -403,6 +403,7 @@
             PlayerHash: shortstring;   // md5 hash of player name. For temporary enabling of hats as thank you. Hashed for privacy of players
             stats: TTeamStats;
             hasGone: boolean;
+            isGoneFlagPengingToBeSet, isGoneFlagPengingToBeUnset: boolean;
             end;
 
     TClan = record