Skip to content

Commit 06a05c8

Browse files
fix: disconnection error when returning to main menu (AscensionGameDev#2258)
(v2)
1 parent 26bd1e5 commit 06a05c8

File tree

8 files changed

+28
-23
lines changed

8 files changed

+28
-23
lines changed

Intersect (Core)/Network/Packets/Client/LogoutPacket.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ public LogoutPacket()
1010
{
1111
}
1212

13-
public LogoutPacket(bool returnToCharSelect, bool returnToMainMenu)
13+
public LogoutPacket(bool returnToCharSelect)
1414
{
1515
ReturningToCharSelect = returnToCharSelect;
16-
ReturningToMainMenu = returnToMainMenu;
1716
}
1817

1918
[Key(0)]
2019
public bool ReturningToCharSelect { get; set; }
2120

22-
[Key(1)]
23-
public bool ReturningToMainMenu { get; set; }
24-
2521
}
2622

2723
}

Intersect.Client/Core/Main.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private static void ProcessGame()
194194
{
195195
if (Globals.ConnectionLost)
196196
{
197-
Logout(false, true);
197+
Logout(false);
198198
Globals.ConnectionLost = false;
199199
return;
200200
}
@@ -325,7 +325,7 @@ public static void JoinGame()
325325
Audio.StopMusic(ClientConfiguration.Instance.MusicFadeTimer);
326326
}
327327

328-
public static void Logout(bool characterSelect, bool mainMenu, bool skipFade = false)
328+
public static void Logout(bool characterSelect, bool skipFade = false)
329329
{
330330
Audio.PlayMusic(ClientConfiguration.Instance.MenuMusic, ClientConfiguration.Instance.MusicFadeTimer, ClientConfiguration.Instance.MusicFadeTimer, true);
331331
if (skipFade)
@@ -339,7 +339,8 @@ public static void Logout(bool characterSelect, bool mainMenu, bool skipFade = f
339339

340340
if (!ClientContext.IsSinglePlayer)
341341
{
342-
PacketSender.SendLogout(characterSelect, mainMenu);
342+
Globals.SoftLogout = !characterSelect;
343+
PacketSender.SendLogout(characterSelect);
343344
}
344345

345346
Globals.LoggedIn = false;

Intersect.Client/General/Globals.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public static partial class Globals
3838

3939
public static bool ConnectionLost;
4040

41+
/// <summary>
42+
/// This is used to prevent the client from showing unnecessary disconnect messages
43+
/// </summary>
44+
public static bool SoftLogout;
45+
4146
//Game Systems
4247
public static GameContentManager ContentManager;
4348

Intersect.Client/Interface/Game/EscapeMenu.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private void LogoutToCharacterSelect(object sender, EventArgs e)
149149
Globals.Me.CombatTimer = 0;
150150
}
151151

152-
Main.Logout(true, false);
152+
Main.Logout(true);
153153
}
154154

155155
private void LogoutToMainMenu(object sender, EventArgs e)
@@ -159,7 +159,7 @@ private void LogoutToMainMenu(object sender, EventArgs e)
159159
Globals.Me.CombatTimer = 0;
160160
}
161161

162-
Main.Logout(false, true);
162+
Main.Logout(false);
163163
}
164164

165165
private void ExitToDesktop(object sender, EventArgs e)

Intersect.Client/Interface/Menu/SelectCharacterWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public void Hide()
343343

344344
private void mLogoutButton_Clicked(Base sender, ClickedEventArgs arguments)
345345
{
346-
Main.Logout(false, true, skipFade: true);
346+
Main.Logout(false, skipFade: true);
347347
mMainMenu.Reset();
348348
}
349349

Intersect.Client/Networking/Network.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
22
using Intersect.Client.Core;
33
using Intersect.Client.Framework.Network;
44
using Intersect.Client.General;
@@ -69,6 +69,7 @@ public static void DebounceClose(string reason)
6969
return;
7070
}
7171

72+
Globals.SoftLogout = true;
7273
_closeTask = default;
7374
Close(reason);
7475
}
@@ -99,6 +100,7 @@ public static bool InterruptDisconnectsIfConnected()
99100
private static void OnConnected(INetworkLayerInterface sender, ConnectionEventArgs connectionEventArgs)
100101
{
101102
Globals.WaitingOnServer = false;
103+
Globals.SoftLogout = false;
102104
}
103105

104106
private static void OnConnectionFailed(
@@ -125,10 +127,18 @@ private static void OnDisconnected(INetworkLayerInterface sender, ConnectionEven
125127
? Strings.Errors.LostConnection.ToString()
126128
: Strings.Errors.DisconnectionEvent.ToString(connectionEventArgs.EventId);
127129

128-
Interface.Interface.ShowError(message);
130+
// if we did a soft logout we don't want to show the error message
131+
if (Globals.SoftLogout)
132+
{
133+
Globals.SoftLogout = false;
134+
}
135+
else
136+
{
137+
Interface.Interface.ShowError(message);
138+
Fade.Cancel();
139+
}
129140

130141
Globals.WaitingOnServer = false;
131-
Fade.Cancel();
132142

133143
if (Globals.GameState != GameStates.InGame && Globals.GameState != GameStates.Loading)
134144
{

Intersect.Client/Networking/PacketSender.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public static void SendLogin(string username, string password)
2828
Network.SendPacket(new LoginPacket(username, password));
2929
}
3030

31-
public static void SendLogout(bool characterSelect = false, bool mainMenu = true)
31+
public static void SendLogout(bool characterSelect = false)
3232
{
33-
Network.SendPacket(new LogoutPacket(characterSelect, mainMenu));
33+
Network.SendPacket(new LogoutPacket(characterSelect));
3434
}
3535

3636
public static void SendNeedMap(params ObjectCacheKey<MapBase>[] cacheKeys)

Intersect.Server.Core/Networking/PacketHandler.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,6 @@ public void HandlePacket(Client client, LogoutPacket packet)
663663
client.Entity = default;
664664
PacketSender.SendPlayerCharacters(client, skipLoadingRelationships: true);
665665
}
666-
else if(packet.ReturningToMainMenu)
667-
{
668-
Log.Debug($"[{nameof(LogoutPacket)}] Returning to main menu from player {client.Entity?.Id} ({client.User?.Id})");
669-
client.Entity?.TryLogout(false, true);
670-
client.Entity = default;
671-
client.SetUser(null);
672-
}
673666
else
674667
{
675668
client.Logout();

0 commit comments

Comments
 (0)