Skip to content
Draft
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
15 changes: 7 additions & 8 deletions src/ChatServer/ChatRoom.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="ChatRoom.cs" company="MUnique">
// <copyright file="ChatRoom.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

Expand Down Expand Up @@ -164,9 +164,7 @@ internal async ValueTask<bool> TryJoinAsync(IChatClient chatClient)
throw new ObjectDisposedException("Chat room is already disposed.");
}

this._logger.LogDebug(
"Client {ChatClientIndex} is trying to join the room {RoomId} with token '{AuthenticationToken}'",
chatClient.Index, this.RoomId, chatClient.AuthenticationToken);
this._logger.LogDebug("Client {ChatClientIndex} is trying to join the room {RoomId} with token '{AuthenticationToken}'", chatClient.Index, this.RoomId, chatClient.AuthenticationToken);

this._lockSlim?.EnterWriteLock();
try
Expand All @@ -178,7 +176,10 @@ internal async ValueTask<bool> TryJoinAsync(IChatClient chatClient)
{
this._logger.LogInformation(
"Client {ChatClientIndex} has tried to join the room {RoomId} with token '{AuthenticationToken}', but was too late. It was valid until {AuthenticationRequiredUntil}.",
chatClient.Index, this.RoomId, chatClient.AuthenticationToken, authenticationInformation.AuthenticationRequiredUntil);
chatClient.Index,
this.RoomId,
chatClient.AuthenticationToken,
authenticationInformation.AuthenticationRequiredUntil);
}
else
{
Expand All @@ -193,9 +194,7 @@ internal async ValueTask<bool> TryJoinAsync(IChatClient chatClient)
}
else
{
this._logger.LogInformation(
"Client {ChatClientIndex} has tried to join the room {RoomId} with token '{AuthenticationToken}', but was not registered.",
chatClient.Index, this.RoomId, chatClient.AuthenticationToken);
this._logger.LogInformation("Client {ChatClientIndex} has tried to join the room {RoomId} with token '{AuthenticationToken}', but was not registered.", chatClient.Index, this.RoomId, chatClient.AuthenticationToken);
}
}
finally
Expand Down
71 changes: 35 additions & 36 deletions src/ChatServer/ChatServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace MUnique.OpenMU.ChatServer;
using Timer = System.Timers.Timer;

/// <summary>
/// Chat Server Listener, accepts incoming connections.
/// Chat Server Listener that accepts incoming connections.
/// </summary>
public sealed class ChatServer : IChatServer, IDisposable
{
Expand Down Expand Up @@ -180,38 +180,6 @@ public void Initialize(ChatServerSettings settings)
this._settings = settings;
}

private void CreateCleanupTimers()
{
this._clientCleanupTimer = new Timer(this.Settings.ClientCleanUpInterval.TotalMilliseconds);
this._clientCleanupTimer.Elapsed += this.ClientCleanupInactiveClients;
this._clientCleanupTimer.Start();
this._roomCleanupTimer = new Timer(this.Settings.RoomCleanUpInterval.TotalMilliseconds);
this._roomCleanupTimer.Elapsed += this.ClientCleanupUnusedRooms;
this._roomCleanupTimer.Start();
}

private void RemoveCleanupTimers()
{
this._clientCleanupTimer?.Stop();
this._clientCleanupTimer?.Dispose();
this._clientCleanupTimer = null;

this._roomCleanupTimer?.Stop();
this._roomCleanupTimer?.Dispose();
this._roomCleanupTimer = null;
}

private void CreateListeners()
{
foreach (var endpoint in this.Settings.Endpoints)
{
var listener = new ChatServerListener(endpoint, this._plugInManager, this._loggerFactory);
listener.ClientAccepted += this.ChatClientAcceptedAsync;
listener.ClientAccepting += this.ChatClientAcceptingAsync;
this._listeners.Add(listener);
}
}

/// <inheritdoc/>
public async ValueTask ShutdownAsync()
{
Expand Down Expand Up @@ -262,11 +230,43 @@ public void Dispose()
}
}

private void CreateCleanupTimers()
{
this._clientCleanupTimer = new Timer(this.Settings.ClientCleanUpInterval.TotalMilliseconds);
this._clientCleanupTimer.Elapsed += this.ClientCleanupInactiveClients;
this._clientCleanupTimer.Start();
this._roomCleanupTimer = new Timer(this.Settings.RoomCleanUpInterval.TotalMilliseconds);
this._roomCleanupTimer.Elapsed += this.ClientCleanupUnusedRooms;
this._roomCleanupTimer.Start();
}

private void RemoveCleanupTimers()
{
this._clientCleanupTimer?.Stop();
this._clientCleanupTimer?.Dispose();
this._clientCleanupTimer = null;

this._roomCleanupTimer?.Stop();
this._roomCleanupTimer?.Dispose();
this._roomCleanupTimer = null;
}

private void CreateListeners()
{
foreach (var endpoint in this.Settings.Endpoints)
{
var listener = new ChatServerListener(endpoint, this._plugInManager, this._loggerFactory);
listener.ClientAccepted += this.ChatClientAcceptedAsync;
listener.ClientAccepting += this.ChatClientAcceptingAsync;
this._listeners.Add(listener);
}
}

/// <summary>
/// Gets a random authentication token.
/// </summary>
/// <param name="clientIndex">Index of the client.</param>
/// <returns>The random authentication token as string.</returns>
/// <returns>The random authentication token as a string.</returns>
/// <remarks>
/// This is the original way of generating the token - not especially secure, but to keep it simple, I leave it that way.
/// </remarks>
Expand Down Expand Up @@ -322,8 +322,7 @@ private async void ClientCleanupInactiveClients(object? sender, ElapsedEventArgs
}

this._logger.LogDebug(
"Disconnecting client {Client}, because of activity timeout. LastActivity: {ClientLastActivity}",
client, client.LastActivity);
"Disconnecting client {Client}, because of activity timeout. LastActivity: {ClientLastActivity}", client, client.LastActivity);

await client.LogOffAsync().ConfigureAwait(false);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ClientLauncher/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// <copyright file="MainForm.cs" company="MUnique">
// <copyright file="MainForm.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

#pragma warning disable CA1416 This project is compiled for windows
#pragma warning disable CA1416 // This project is compiled for windows
namespace MUnique.OpenMU.ClientLauncher;

using System.ComponentModel;
Expand Down
4 changes: 3 additions & 1 deletion src/ConnectServer/PacketHandler/ServerInfoRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public async ValueTask HandlePacketAsync(Client client, Memory<byte> packet)
var isGameServerOnSameMachineAsConnectServer = (serverItem?.EndPoint.Address).IsOnSameHost();
var isClientConnectedOnNonRegisteredAddress = !object.Equals(serverItem?.EndPoint.Address, localIpEndPoint?.Address);
bool.TryParse(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), out var isRunningOnDocker);

// Only if we can't use the cached data.
if (isGameServerOnSameMachineAsConnectServer
&& !isRunningOnDocker
&& isClientConnectedOnNonRegisteredAddress) // only if we can't use the cached data
&& isClientConnectedOnNonRegisteredAddress)
{
int WritePacket()
{
Expand Down
32 changes: 16 additions & 16 deletions src/Dapr/Common/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="Extensions.cs" company="MUnique">
// <copyright file="Extensions.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

Expand Down Expand Up @@ -34,9 +34,9 @@ public static class Extensions
/// <summary>
/// Adds the <see cref="PersistenceContextProvider"/>.
/// </summary>
/// <param name="services">The services.</param>
/// <param name="services">The service collection.</param>
/// <param name="publishConfigChanges">If set to <c>true</c>, configuration changes are published to other Dapr services.</param>
/// <returns>The services.</returns>
/// <returns>The modified service collection.</returns>
public static IServiceCollection AddPeristenceProvider(this IServiceCollection services, bool publishConfigChanges = false)
{
services.AddSingleton<IConfigurationChangeListener, ConfigurationChangeListener>();
Expand All @@ -59,9 +59,9 @@ public static IServiceCollection AddPeristenceProvider(this IServiceCollection s
/// <summary>
/// Adds the plug in manager.
/// </summary>
/// <param name="services">The services.</param>
/// <param name="services">The service collection.</param>
/// <param name="plugInConfigurations">The plug in configurations.</param>
/// <returns>The services.</returns>
/// <returns>The modified service collection.</returns>
public static IServiceCollection AddPlugInManager(this IServiceCollection services, ICollection<PlugInConfiguration> plugInConfigurations)
{
return services
Expand Down Expand Up @@ -114,9 +114,9 @@ public static async ValueTask TryLoadPlugInConfigurationsAsync(this IServiceProv
/// Adds a persistent object as singleton to the services.
/// </summary>
/// <typeparam name="T">The base type of the persistent object.</typeparam>
/// <param name="services">The services.</param>
/// <param name="services">The service collection.</param>
/// <param name="predicate">The predicate to select actual object.</param>
/// <returns>The services.</returns>
/// <returns>The modified service collection.</returns>
public static IServiceCollection AddPersistentSingleton<T>(this IServiceCollection services, Func<T, bool>? predicate = null)
where T : class
{
Expand All @@ -128,9 +128,9 @@ public static IServiceCollection AddPersistentSingleton<T>(this IServiceCollecti
/// </summary>
/// <typeparam name="TTarget">The target, exposed type of the persistent object, usually an interface.</typeparam>
/// <typeparam name="TActual">The actual base type of the persistent object.</typeparam>
/// <param name="services">The services.</param>
/// <param name="predicate">The predicate.</param>
/// <returns>The services.</returns>
/// <param name="services">The service collection.</param>
/// <param name="predicate">The predicate to select the actual object.</param>
/// <returns>The modified service collection.</returns>
public static IServiceCollection AddPersistentSingleton<TTarget, TActual>(this IServiceCollection services, Func<TActual, bool>? predicate = null)
where TActual : class, TTarget
where TTarget : class
Expand All @@ -150,8 +150,8 @@ public static IServiceCollection AddPersistentSingleton<TTarget, TActual>(this I
/// <summary>
/// Adds the <see cref="ManagableServerRegistry"/> to the services.
/// </summary>
/// <param name="services">The services.</param>
/// <returns>The services.</returns>
/// <param name="services">The service collection.</param>
/// <returns>The modified service collection.</returns>
public static IServiceCollection AddManageableServerRegistry(this IServiceCollection services)
{
services.AddSingleton<ManagableServerRegistry>()
Expand All @@ -163,8 +163,8 @@ public static IServiceCollection AddManageableServerRegistry(this IServiceCollec
/// Publishes the server to other daprized services by registering a <see cref="ManagableServerStatePublisher"/>.
/// </summary>
/// <typeparam name="TServer">The type of the server.</typeparam>
/// <param name="services">The services.</param>
/// <returns>The services.</returns>
/// <param name="services">The service collection.</param>
/// <returns>The modified service collection.</returns>
public static IServiceCollection PublishManageableServer<TServer>(this IServiceCollection services)
where TServer : IManageableServer
{
Expand All @@ -180,7 +180,7 @@ public static IServiceCollection PublishManageableServer<TServer>(this IServiceC
/// </summary>
/// <param name="builder">The web application builder.</param>
/// <param name="serviceName">Name of the service.</param>
/// <returns>The web application builder.</returns>
/// <returns>The configured web application builder.</returns>
public static WebApplicationBuilder UseLoki(this WebApplicationBuilder builder, string serviceName)
{
// We just want to transmit some static labels, as suggested in the best practice in the Loki documentation
Expand Down Expand Up @@ -211,7 +211,7 @@ public static WebApplicationBuilder UseLoki(this WebApplicationBuilder builder,
/// </summary>
/// <param name="builder">The web application builder.</param>
/// <param name="registry">The registry.</param>
/// <returns>The web application builder.</returns>
/// <returns>The configured web application builder.</returns>
public static WebApplicationBuilder AddOpenTelemetryMetrics(this WebApplicationBuilder builder, MetricsRegistry registry)
{
builder.Services.AddOpenTelemetry()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="ConnectionServerController.cs" company="MUnique">
// <copyright file="ConnectServerController.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

Expand All @@ -11,7 +11,7 @@ namespace MUnique.OpenMU.ConnectServer.Host;
using MUnique.OpenMU.ServerClients;

/// <summary>
/// API Controller which receives messages from other services.
/// API Controller that receives messages from other services.
/// </summary>
[ApiController]
[Route("")]
Expand Down
2 changes: 1 addition & 1 deletion src/Dapr/ConnectServer.Host/ServerInfoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public object GetCompleteInfo()
/// <summary>
/// Gets the connection count of all game servers.
/// </summary>
/// <returns></returns>
/// <returns>The overall count of current connections.</returns>
[HttpGet("playerCount")]
public int GetOverallConnectionCount()
{
Expand Down
1 change: 0 additions & 1 deletion src/Dapr/GameServer.Host/GameServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public GameServerController(GameServer gameServer)
/// <summary>
/// Shuts down the server gracefully.
/// </summary>
/// <returns></returns>
[HttpPost(nameof(IGameServer.ShutdownAsync))]
public async ValueTask ShutdownAsync()
{
Expand Down
1 change: 0 additions & 1 deletion src/Dapr/GameServer.Host/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using System.Net.Http

@using Blazored
@using Blazored.Modal
Expand Down
6 changes: 5 additions & 1 deletion src/DataModel/Entities/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ public override string ToString()
return stringBuilder.ToString();
}

/// <inheritdoc/>
/// <summary>
/// Returns a string that represents this item, using the specified culture for localization.
/// </summary>
/// <param name="culture">The culture to use for localization.</param>
/// <returns>The localized string.</returns>
public string ToString(CultureInfo culture)
{
using var cultureHelper = CultureHelper.SetTemporaryCulture(culture);
Expand Down
6 changes: 6 additions & 0 deletions src/DataModel/ModelResourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public static class ModelResourceProvider

private static readonly ConcurrentDictionary<Assembly, ResourceManager?> ResourceManagersByAssembly = new();

/// <summary>
/// Gets the localized caption for the specified model type <typeparamref name="TModel"/>.
/// </summary>
/// <param name="cultureInfo">Optional culture to use. If null, <see cref="CultureInfo.CurrentUICulture"/> is used.</param>
/// <typeparam name="TModel">The model type for which to get the caption.</typeparam>
/// <returns>The localized caption or a spaced fallback type name.</returns>
public static string GetTypeCaption<TModel>(CultureInfo? cultureInfo = null)
{
return typeof(TModel).GetTypeCaption(cultureInfo);
Expand Down
22 changes: 14 additions & 8 deletions src/GameLogic/AttackableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static async ValueTask<HitInfo> CalculateDamageAsync(this IAttacker attac

if (attacker.Attributes[Stats.HasDoubleWield] > 0)
{
// double wield => 110% dmg (55% + 55%)
// Double wield => 110% dmg (55% + 55%).
dmg += dmg;
}

Expand All @@ -136,7 +136,7 @@ public static async ValueTask<HitInfo> CalculateDamageAsync(this IAttacker attac
}
else
{
// Wizardry, Curse, and Fenrir
// Wizardry, Curse, and Fenrir.
if (isExcellentHit)
{
dmg = (int)((baseMaxDamage * duelDmgDec) - defense);
Expand Down Expand Up @@ -218,7 +218,8 @@ public static async ValueTask<HitInfo> CalculateDamageAsync(this IAttacker attac
{
multiplier = skillMultiplier;

if (skill.Skill!.Number == 265 && !isPvp) // DragonSlasher
// DragonSlasher.
if (skill.Skill!.Number == 265 && !isPvp)
{
multiplier *= 3;
}
Expand Down Expand Up @@ -806,7 +807,7 @@ private static void GetBaseDmg(this IAttacker attacker, SkillEntry? skill, out i
maximumBaseDamage = (int)attackerStats[Stats.FenrirBaseDmg] + skillMaximumDamage;
break;
default:
// the skill has some other damage type defined that is not applicable to this calculation
// The skill has some other damage type defined that is not applicable to this calculation.
break;
}

Expand Down Expand Up @@ -925,15 +926,20 @@ private static int GetMasterSkillTreePhysicalPassiveDamageBonus(IAttacker attack
{
int bonusDamage = 0;

if (attacker.Attributes[Stats.IsSpearEquipped] > 0) // always two-handed
// Always two-handed.
if (attacker.Attributes[Stats.IsSpearEquipped] > 0)
{
bonusDamage = (int)attacker.Attributes[Stats.SpearBonusDamage];
}
else if (attacker.Attributes[Stats.IsScepterEquipped] > 0) // impossible to double wield

// Impossible to double wield.
else if (attacker.Attributes[Stats.IsScepterEquipped] > 0)
{
bonusDamage = (int)attacker.Attributes[Stats.ScepterStrBonusDamage];
}
else if (attacker.Attributes[Stats.IsGloveWeaponEquipped] > 0) // impossible to double wield

// Impossible to double wield.
else if (attacker.Attributes[Stats.IsGloveWeaponEquipped] > 0)
{
bonusDamage = (int)attacker.Attributes[Stats.GloveWeaponBonusDamage];
}
Expand All @@ -946,7 +952,7 @@ private static int GetMasterSkillTreePhysicalPassiveDamageBonus(IAttacker attack

if (attacker.Attributes[Stats.IsMaceEquipped] > 0)
{
// In case of a double wield with different possible bonuses, take the average
// In case of a double wielding with different possible bonuses, take the average.
bonusDamage = (int)(bonusDamage == 0
? attacker.Attributes[Stats.MaceBonusDamage]
: (bonusDamage + attacker.Attributes[Stats.MaceBonusDamage]) / 2);
Expand Down
Loading