Code style fix, added return of ErrorCode.InvalidArgument to AddPlayerCharacter/RemovePlayerCharacter

This commit is contained in:
RisaDev
2025-04-18 22:14:19 +03:00
parent 2a0548e1b4
commit 31a192c6eb
2 changed files with 17 additions and 25 deletions

View File

@@ -107,28 +107,22 @@ public partial class CustomizePlusIpc
private int AddPlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId) private int AddPlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId)
{ {
if (uniqueId == Guid.Empty) if (uniqueId == Guid.Empty)
{
return (int)ErrorCode.ProfileNotFound; return (int)ErrorCode.ProfileNotFound;
}
var profile = this._profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary); var profile = _profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary);
if (profile == null) if (profile == null)
{
return (int)ErrorCode.ProfileNotFound; return (int)ErrorCode.ProfileNotFound;
}
if (!ByteString.FromString(name, out var byteString)) if (!ByteString.FromString(name, out var byteString))
{
return (int)ErrorCode.InvalidCharacter; return (int)ErrorCode.InvalidCharacter;
}
var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId); var playerIdentifier = _actorManager.CreatePlayer(byteString, worldId);
if (playerIdentifier == ActorIdentifier.Invalid) if (playerIdentifier == ActorIdentifier.Invalid)
{
return (int)ErrorCode.InvalidCharacter; return (int)ErrorCode.InvalidCharacter;
}
this._profileManager.AddCharacter(profile, playerIdentifier); if(!_profileManager.AddCharacter(profile, playerIdentifier))
return (int)ErrorCode.InvalidArgument; //Returned if character is already associated with provided profile
return (int)ErrorCode.Success; return (int)ErrorCode.Success;
} }
@@ -139,28 +133,22 @@ public partial class CustomizePlusIpc
private int RemovePlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId) private int RemovePlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId)
{ {
if (uniqueId == Guid.Empty) if (uniqueId == Guid.Empty)
{
return (int)ErrorCode.ProfileNotFound; return (int)ErrorCode.ProfileNotFound;
}
var profile = this._profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary); var profile = _profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary);
if (profile == null) if (profile == null)
{
return (int)ErrorCode.ProfileNotFound; return (int)ErrorCode.ProfileNotFound;
}
if (!ByteString.FromString(name, out var byteString)) if (!ByteString.FromString(name, out var byteString))
{
return (int)ErrorCode.InvalidCharacter; return (int)ErrorCode.InvalidCharacter;
}
var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId); var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId);
if (playerIdentifier == ActorIdentifier.Invalid) if (playerIdentifier == ActorIdentifier.Invalid)
{
return (int)ErrorCode.InvalidCharacter; return (int)ErrorCode.InvalidCharacter;
}
this._profileManager.DeleteCharacter(profile, playerIdentifier); if(!_profileManager.DeleteCharacter(profile, playerIdentifier))
return (int)ErrorCode.InvalidArgument; //Returned if character is not associated with provided profile
return (int)ErrorCode.Success; return (int)ErrorCode.Success;
} }

View File

@@ -178,10 +178,10 @@ public partial class ProfileManager : IDisposable
/// <summary> /// <summary>
/// Add character to profile /// Add character to profile
/// </summary> /// </summary>
public void AddCharacter(Profile profile, ActorIdentifier actorIdentifier) public bool AddCharacter(Profile profile, ActorIdentifier actorIdentifier)
{ {
if (!actorIdentifier.IsValid || profile.Characters.Any(x => actorIdentifier.MatchesIgnoringOwnership(x)) || profile.IsTemporary) if (!actorIdentifier.IsValid || profile.Characters.Any(x => actorIdentifier.MatchesIgnoringOwnership(x)) || profile.IsTemporary)
return; return false;
profile.Characters.Add(actorIdentifier); profile.Characters.Add(actorIdentifier);
@@ -189,15 +189,17 @@ public partial class ProfileManager : IDisposable
_logger.Debug($"Add character for profile {profile.UniqueId}."); _logger.Debug($"Add character for profile {profile.UniqueId}.");
_event.Invoke(ProfileChanged.Type.AddedCharacter, profile, actorIdentifier); _event.Invoke(ProfileChanged.Type.AddedCharacter, profile, actorIdentifier);
return true;
} }
/// <summary> /// <summary>
/// Delete character from profile /// Delete character from profile
/// </summary> /// </summary>
public void DeleteCharacter(Profile profile, ActorIdentifier actorIdentifier) public bool DeleteCharacter(Profile profile, ActorIdentifier actorIdentifier)
{ {
if (!actorIdentifier.IsValid || !profile.Characters.Any(x => actorIdentifier.MatchesIgnoringOwnership(x)) || profile.IsTemporary) if (!actorIdentifier.IsValid || !profile.Characters.Any(x => actorIdentifier.MatchesIgnoringOwnership(x)) || profile.IsTemporary)
return; return false;
profile.Characters.Remove(actorIdentifier); profile.Characters.Remove(actorIdentifier);
@@ -205,6 +207,8 @@ public partial class ProfileManager : IDisposable
_logger.Debug($"Removed character from profile {profile.UniqueId}."); _logger.Debug($"Removed character from profile {profile.UniqueId}.");
_event.Invoke(ProfileChanged.Type.RemovedCharacter, profile, actorIdentifier); _event.Invoke(ProfileChanged.Type.RemovedCharacter, profile, actorIdentifier);
return true;
} }
/// <summary> /// <summary>