Skip to content

Commit 915b33f

Browse files
committed
Remove GameState from GameAd when they leave
1 parent df2ebc0 commit 915b33f

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/Atlasd/Battlenet/Protocols/Game/Messages/SID_LEAVEGAME.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ public override bool Invoke(MessageContext context)
3232
throw new GameProtocolViolationException(context.Client, $"{MessageName(Id)} buffer must be 0 bytes, got {Buffer.Length}");
3333

3434
GameState gs = context.Client.GameState;
35-
if (gs.GameAd != null && gs.GameAd.RemoveClient(gs)) gs.GameAd = null;
3635

36+
if (gs == null)
37+
throw new GameProtocolViolationException(context.Client, $"{MessageName(Id)} was received without an active GameState");
38+
39+
if (gs.GameAd == null)
40+
return true; // No game advertisement to stop. No action to do.
41+
42+
bool gameAdOwner = gs.GameAd != null && gs.GameAd.Owner == gs;
43+
if (gameAdOwner && gs.GameAd.Clients.Count == 1) Battlenet.Common.ActiveGameAds.Remove(gs.GameAd);
44+
45+
if (gs.GameAd != null && gs.GameAd.RemoveClient(gs)) gs.GameAd = null;
3746
return true;
3847
}
3948
}

src/Atlasd/Battlenet/Protocols/Game/Messages/SID_STOPADV.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ public override bool Invoke(MessageContext context)
3838
if (gs.GameAd == null)
3939
return true; // No game advertisement to stop. No action to do.
4040

41-
if (gs != gs.GameAd.Owner)
42-
{
41+
bool gameAdOwner = gs.GameAd != null && gs.GameAd.Owner == gs;
42+
43+
if (gs.GameAd != null && gs.GameAd.RemoveClient(gs)) gs.GameAd = null;
44+
45+
if (!gameAdOwner)
4346
Logging.WriteLine(Logging.LogLevel.Info, Logging.LogType.Client_Game, context.Client.RemoteEndPoint, $"{MessageName(Id)} was received but they are not the owner of the game advertisement");
44-
return true;
45-
}
47+
else
48+
Battlenet.Common.ActiveGameAds.Remove(gs.GameAd);
4649

47-
Battlenet.Common.ActiveGameAds.Remove(gs.GameAd);
4850
return true;
4951
}
5052
}

0 commit comments

Comments
 (0)