Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel Trade before handle disconnect #558

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/GameLogic/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace MUnique.OpenMU.GameLogic;
using MUnique.OpenMU.GameLogic.PlayerActions;
using MUnique.OpenMU.GameLogic.PlayerActions.Items;
using MUnique.OpenMU.GameLogic.PlayerActions.Skills;
using MUnique.OpenMU.GameLogic.PlayerActions.Trade;
using MUnique.OpenMU.GameLogic.PlugIns;
using MUnique.OpenMU.GameLogic.Views;
using MUnique.OpenMU.GameLogic.Views.Character;
Expand Down Expand Up @@ -1291,6 +1292,7 @@ public async Task RegenerateAsync()
/// </summary>
public async ValueTask DisconnectAsync()
{
await this.CloseTradeIfNeededAsync().ConfigureAwait(false);
if (await this.PlayerState.TryAdvanceToAsync(GameLogic.PlayerState.Disconnected).ConfigureAwait(false))
{
try
Expand Down Expand Up @@ -2408,6 +2410,16 @@ async ValueTask AddExpToPetAsync(Item pet, double experience)
}
}

private async ValueTask CloseTradeIfNeededAsync()
{
if (this.PlayerState.CurrentState == GameLogic.PlayerState.TradeButtonPressed
|| this.PlayerState.CurrentState == GameLogic.PlayerState.TradeOpened)
{
var cancelAction = new TradeCancelAction();
await cancelAction.CancelTradeAsync(this).ConfigureAwait(false);
}
}

private sealed class TemporaryItemStorage : ItemStorage
{
public TemporaryItemStorage()
Expand Down
4 changes: 4 additions & 0 deletions src/GameServer/GameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ private async ValueTask SaveSessionOfPlayerAsync(Player player)
this._logger.LogWarning($"Could not take fit items of player {player}");
}
}
else
{
// nothing else to restore.
}

if (!await player.PersistenceContext.SaveChangesAsync().ConfigureAwait(false))
{
Expand Down
Loading