Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/nuget/src/Dapr/Common/OpenTelem…
Browse files Browse the repository at this point in the history
…etry.Instrumentation.AspNetCore-1.8.1
  • Loading branch information
sven-n authored Jun 15, 2024
2 parents 3da0520 + 72cb006 commit fc515ed
Show file tree
Hide file tree
Showing 109 changed files with 11,364 additions and 326 deletions.
2 changes: 1 addition & 1 deletion QuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If you just want to play around with the server, you can find the newest docker
all-in-one image on the Docker Hub: <https://hub.docker.com/r/munique/openmu>

To pull and run the latest docker image, run this command:
`docker run --name openmu -d -p 80:80 -p 44405:44405 -p 55901:55901 -p 55902:55902 -p 55903:55903 -p 55980:55980 munique/openmu:latest -demo`
`docker run --name openmu -d -p 80:8080 -p 44405:44405 -p 55901:55901 -p 55902:55902 -p 55903:55903 -p 55980:55980 munique/openmu:latest -demo`

The last argument is there to start the server in demo mode, without a
database. To use a postgres database, you can use docker-compose.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/ChatServer/ExDbConnector/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal static async Task Main(string[] args)
// To make the chat server use our configured encryption key, we need to trick a bit. We add an endpoint with a special client version which is defined in the plugin.
var configuration = new ChatServerSettings();
configuration.Endpoints.Add(new ChatServerEndpoint { ClientVersion = ConfigurableNetworkEncryptionPlugIn.Version, NetworkPort = chatServerListenerPort });
var pluginManager = new PlugInManager(null, loggerFactory, serviceContainer);
var pluginManager = new PlugInManager(null, loggerFactory, serviceContainer, null);
pluginManager.DiscoverAndRegisterPlugInsOf<INetworkEncryptionFactoryPlugIn>();
var chatServer = new ChatServer(addressResolver, loggerFactory, pluginManager);
chatServer.Initialize(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Dapr/Common/MUnique.OpenMU.Dapr.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="Dapr.Client" Version="1.10.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.10" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.14" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
Expand All @@ -31,7 +31,7 @@
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.2.0" />
<PackageReference Include="SharpAbp.Abp.OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="2.9.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/DataModel/Configuration/Items/ItemSetGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MUnique.OpenMU.DataModel.Configuration.Items;

using MUnique.OpenMU.Annotations;
using MUnique.OpenMU.DataModel.Entities;

/// <summary>
/// Defines an item set group. With (partial) completion of the set, additional options are getting applied.
Expand All @@ -28,8 +29,9 @@ public partial class ItemSetGroup
public string Name { get; set; } = string.Empty;

/// <summary>
/// Gets or sets a value indicating whether all of the options of this item set always apply.
/// If not, the minimum item count and the minimum set levels are respected.
/// Gets or sets a value indicating whether the options of this item set always apply to an item,
/// even if the group wasn't explicitly added to the <see cref="Item.ItemSetGroups"/>.
/// The minimum item count and the minimum set levels are respected.
/// </summary>
public bool AlwaysApplies { get; set; }

Expand Down Expand Up @@ -57,8 +59,7 @@ public partial class ItemSetGroup
/// <remarks>
/// The order is defined by <see cref="ItemOption.Number"/>.
/// </remarks>
[MemberOfAggregate]
public virtual ICollection<IncreasableItemOption> Options { get; protected set; } = null!;
public virtual ItemOptionDefinition? Options { get; set; } = null!;

/// <summary>
/// Gets or sets the items of this set.
Expand Down
1 change: 0 additions & 1 deletion src/DataModel/GameConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static class GameConfigurationHelper
{ typeof(ItemOptionDefinition), c => c.ItemOptions },
{
typeof(IncreasableItemOption), c => c.ItemOptions.SelectMany(o => o.PossibleOptions)
.Concat(c.ItemSetGroups.SelectMany(o => o.Options))
},
{ typeof(ItemSetGroup), c => c.ItemSetGroups },
{ typeof(ItemOfItemSet), c => c.ItemSetGroups.SelectMany(o => o.Items) },
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<ItemGroup Label="commom configuration code style.">

<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 5 additions & 0 deletions src/GameLogic/Attributes/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,11 @@ public class Stats
/// </summary>
public static AttributeDefinition IsVip { get; } = new(new Guid("195474D6-59A2-4033-9C30-8628ECC0097E"), "Is VIP", "The flag, if an account is a VIP.");

/// <summary>
/// Gets the attribute for the number of points this class will receive for reset, overwrites the default <see cref="Resets.ResetConfiguration.PointsPerReset"/> value.
/// </summary>
public static AttributeDefinition PointsPerReset { get; } = new(new Guid("a34f4f57-b364-4cdb-9989-64cedd2cd831"), "Points Per Reset", "The number of points the player will receive for reset, overwrites the default 'PointsPerReset' value of the reset configuration.");

/// <summary>
/// Gets the attributes which are regenerated in an interval.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/GameLogic/DefaultDropGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DefaultDropGenerator(GameConfiguration config, IRandomizer randomizer)
{
this._randomizer = randomizer;
this._droppableItems = config.Items.Where(i => i.DropsFromMonsters).ToList();
this._ancientItems = this._droppableItems.Where(i => i.PossibleItemSetGroups.Any(o => o.Options.Any(o => o.OptionType == ItemOptionTypes.AncientOption))).ToList();
this._ancientItems = this._droppableItems.Where(i => i.PossibleItemSetGroups.Any(o => o.Options?.PossibleOptions.Any(o => o.OptionType == ItemOptionTypes.AncientOption) ?? false)).ToList();
}

/// <inheritdoc/>
Expand Down Expand Up @@ -327,7 +327,7 @@ private static bool IsGroupRelevant(MonsterDefinition monsterDefinition, DropIte

private void ApplyRandomAncientOption(Item item)
{
var ancientSet = item.Definition?.PossibleItemSetGroups.Where(g => g!.Options.Any(o => o.OptionType == ItemOptionTypes.AncientOption)).SelectRandom(this._randomizer);
var ancientSet = item.Definition?.PossibleItemSetGroups.Where(g => g!.Options?.PossibleOptions.Any(o => o.OptionType == ItemOptionTypes.AncientOption) ?? false).SelectRandom(this._randomizer);
if (ancientSet is null)
{
return;
Expand Down
5 changes: 5 additions & 0 deletions src/GameLogic/DroppedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ private async ValueTask<bool> TryStackOnItemAsync(Player player, Item stackTarge

player.Logger.LogInformation("Item '{0}' got picked up by player '{1}'. Durability of available stack {2} increased to {3}", this, player, stackTarget, stackTarget.Durability);
this.DisposeAndDelete(null);
if (player.GameContext.PlugInManager.GetPlugInPoint<PlugIns.IItemStackedPlugIn>() is { } itemStackedPlugIn)
{
await itemStackedPlugIn.ItemStackedAsync(player, this.Item, stackTarget).ConfigureAwait(false);
}

return true;
}

Expand Down
29 changes: 17 additions & 12 deletions src/GameLogic/ItemPowerUpFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,14 @@ public IEnumerable<PowerUpWrapper> GetSetPowerUps(
.Distinct();

var result = Enumerable.Empty<PowerUpDefinition>();
foreach (var group in itemGroups)
{
if (group.AlwaysApplies)
{
result = result.Concat(group.Options.Select(o => o.PowerUpDefinition ?? throw Error.NotInitializedProperty(o, nameof(o.PowerUpDefinition))));

continue;
}
var alwaysGroups = activeItems.SelectMany(i => i.Definition!.PossibleItemSetGroups).Where(i => i.AlwaysApplies).Distinct();

var itemsOfGroup = activeItems.Where(i => i.ItemSetGroups.Any(ios => ios.ItemSetGroup == group)
&& (group.SetLevel == 0 || i.Level >= group.SetLevel));
foreach (var group in alwaysGroups.Concat(itemGroups).Distinct())
{
var itemsOfGroup = activeItems.Where(i =>
((group.AlwaysApplies && i.Definition!.PossibleItemSetGroups.Contains(group))
|| i.ItemSetGroups.Any(ios => ios.ItemSetGroup == group))
&& (group.SetLevel == 0 || i.Level >= group.SetLevel));
var setMustBeComplete = group.MinimumItemCount == group.Items.Count;
if (group.SetLevel > 0 && setMustBeComplete && itemsOfGroup.All(i => i.Level > group.SetLevel))
{
Expand All @@ -97,19 +94,27 @@ public IEnumerable<PowerUpWrapper> GetSetPowerUps(
continue;
}

if (group.Options is not { } options)
{
this._logger.LogWarning("Options of set {group} is not initialized", group);
continue;
}

var itemCount = group.CountDistinct ? itemsOfGroup.Select(item => item.Definition).Distinct().Count() : itemsOfGroup.Count();
var setIsComplete = itemCount == group.Items.Count;
if (setIsComplete)
{
// Take all options when the set is complete
result = result.Concat(group.Options.Select(o => o.PowerUpDefinition ?? throw Error.NotInitializedProperty(o, nameof(o.PowerUpDefinition))));
result = result.Concat(
options.PossibleOptions
.Select(o => o.PowerUpDefinition ?? throw Error.NotInitializedProperty(o, nameof(o.PowerUpDefinition))));
continue;
}

if (itemCount >= group.MinimumItemCount)
{
// Take the first n-1 options
result = result.Concat(group.Options.OrderBy(o => o.Number)
result = result.Concat(options.PossibleOptions.OrderBy(o => o.Number)
.Take(itemCount - 1)
.Select(o => o.PowerUpDefinition ?? throw Error.NotInitializedProperty(o, nameof(o.PowerUpDefinition))));
}
Expand Down
9 changes: 9 additions & 0 deletions src/GameLogic/LocateableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public static double GetDistanceTo(this ILocateable objectFrom, Point objectToPo
/// <returns><c>True</c>, if the specified coordinate is in the specified range of the object; Otherwise, <c>false</c>.</returns>
public static bool IsInRange(this ILocateable obj, Point point, int range) => obj.IsInRange(point.X, point.Y, range);

/// <summary>
/// Determines whether the specified coordinates are in the specified range of the object.
/// </summary>
/// <param name="obj">The object.</param>
/// <param name="obj2">The second object.</param>
/// <param name="range">The maximum range.</param>
/// <returns><c>True</c>, if the specified coordinate is in the specified range of the object; Otherwise, <c>false</c>.</returns>
public static bool IsInRange(this ILocateable obj, ILocateable obj2, int range) => obj.IsInRange(obj2.Position, range);

/// <summary>
/// Determines whether the specified coordinate is in the specified range of the object.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/GameLogic/MUnique.OpenMU.GameLogic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MathParser.org-mXparser" Version="5.2.1" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.6" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>
Expand Down
48 changes: 26 additions & 22 deletions src/GameLogic/MiniGames/MiniGameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MiniGameContext : AsyncDisposable, IEventStateProvider

private readonly CancellationTokenSource _gameEndedCts = new();

private readonly HashSet<byte> _currentSpawnWaves = new();
private readonly ConcurrentDictionary<byte, MiniGameSpawnWave> _currentSpawnWaves = new();
private readonly List<ChangeEventContext> _remainingEvents = new();

private Stopwatch? _elapsedTimeSinceStart;
Expand Down Expand Up @@ -177,7 +177,7 @@ public async ValueTask<EnterResult> TryEnterAsync(Player player)
/// <inheritdoc />
public bool IsSpawnWaveActive(byte waveNumber)
{
return this._currentSpawnWaves.Contains(waveNumber);
return this._currentSpawnWaves.ContainsKey(waveNumber);
}

/// <summary>
Expand Down Expand Up @@ -588,15 +588,13 @@ private async Task RunSpawnWavesAsync(CancellationToken cancellationToken)
{
try
{
foreach (var spawnWave in this.Definition.SpawnWaves.OrderBy(wave => wave.WaveNumber))
{
if (cancellationToken.IsCancellationRequested)
{
break;
}

await this.RunSpawnWaveAsync(spawnWave, cancellationToken).ConfigureAwait(false);
}
// We already need to start all tasks, because they may overlap.
// So it's not okay to run them one after another.
var waveTasks = this.Definition.SpawnWaves
.OrderBy(wave => wave.WaveNumber)
.Select(wave => this.RunSpawnWaveAsync(wave, cancellationToken))
.ToList();
await Task.WhenAll(waveTasks).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Expand All @@ -608,19 +606,20 @@ private async Task RunSpawnWavesAsync(CancellationToken cancellationToken)
}
}

private async ValueTask RunSpawnWaveAsync(MiniGameSpawnWave spawnWave, CancellationToken cancellationToken)
private async Task RunSpawnWaveAsync(MiniGameSpawnWave spawnWave, CancellationToken cancellationToken)
{
try
{
if (cancellationToken.IsCancellationRequested)
{
return;
}

var requiredDelay = spawnWave.StartTime - this._elapsedTimeSinceStart?.Elapsed;
if (requiredDelay > TimeSpan.Zero)
while (spawnWave.StartTime > this._elapsedTimeSinceStart?.Elapsed)
{
await Task.Delay(requiredDelay.Value, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();

// Wait at least a second (or half of the remaining time) to the next check
var timeUntilNextCheck = (spawnWave.StartTime - this._elapsedTimeSinceStart!.Elapsed) / 2;
var requiredDelay = timeUntilNextCheck > TimeSpan.FromSeconds(1)
? timeUntilNextCheck
: TimeSpan.FromSeconds(1);
await Task.Delay(requiredDelay, cancellationToken).ConfigureAwait(false);
}

this.Logger.LogDebug("{context}: Starting next wave: {wave}", this, spawnWave.Description);
Expand All @@ -629,22 +628,27 @@ private async ValueTask RunSpawnWaveAsync(MiniGameSpawnWave spawnWave, Cancellat
await this.ShowMessageAsync(message).ConfigureAwait(false);
}

this._currentSpawnWaves.Add(spawnWave.WaveNumber);
if (!this._currentSpawnWaves.TryAdd(spawnWave.WaveNumber, spawnWave))
{
this.Logger.LogWarning("{context}: Duplicate spawn wave number in event: {wave}. Check your configuration, every spawn wave needs a distinct number.", this, spawnWave.Description);
}

await this._mapInitializer.InitializeNpcsOnWaveStartAsync(this.Map, this, spawnWave.WaveNumber).ConfigureAwait(false);
await Task.Delay(spawnWave.EndTime - spawnWave.StartTime, cancellationToken).ConfigureAwait(false);
this.Logger.LogDebug("{context}: Wave ended: {wave}", this, spawnWave.Description);
}
catch (OperationCanceledException)
{
// do nothing, as it's expected when game ends ...
throw;
}
catch (Exception ex)
{
this.Logger.LogError(ex, "Unexpected error during spawn wave {0}: {1}", spawnWave.WaveNumber, ex.Message);
}
finally
{
this._currentSpawnWaves.Remove(spawnWave.WaveNumber);
this._currentSpawnWaves.Remove(spawnWave.WaveNumber, out _);
}
}

Expand Down
Loading

0 comments on commit fc515ed

Please sign in to comment.