Code style fix, added return of ErrorCode.InvalidArgument to AddPlayerCharacter/RemovePlayerCharacter
This commit is contained in:
@@ -107,28 +107,22 @@ public partial class CustomizePlusIpc
|
||||
private int AddPlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId)
|
||||
{
|
||||
if (uniqueId == Guid.Empty)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return (int)ErrorCode.ProfileNotFound;
|
||||
}
|
||||
|
||||
if (!ByteString.FromString(name, out var byteString))
|
||||
{
|
||||
return (int)ErrorCode.InvalidCharacter;
|
||||
}
|
||||
|
||||
var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId);
|
||||
var playerIdentifier = _actorManager.CreatePlayer(byteString, worldId);
|
||||
if (playerIdentifier == ActorIdentifier.Invalid)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -139,28 +133,22 @@ public partial class CustomizePlusIpc
|
||||
private int RemovePlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId)
|
||||
{
|
||||
if (uniqueId == Guid.Empty)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return (int)ErrorCode.ProfileNotFound;
|
||||
}
|
||||
|
||||
if (!ByteString.FromString(name, out var byteString))
|
||||
{
|
||||
return (int)ErrorCode.InvalidCharacter;
|
||||
}
|
||||
|
||||
var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId);
|
||||
if (playerIdentifier == ActorIdentifier.Invalid)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -178,10 +178,10 @@ public partial class ProfileManager : IDisposable
|
||||
/// <summary>
|
||||
/// Add character to profile
|
||||
/// </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)
|
||||
return;
|
||||
return false;
|
||||
|
||||
profile.Characters.Add(actorIdentifier);
|
||||
|
||||
@@ -189,15 +189,17 @@ public partial class ProfileManager : IDisposable
|
||||
|
||||
_logger.Debug($"Add character for profile {profile.UniqueId}.");
|
||||
_event.Invoke(ProfileChanged.Type.AddedCharacter, profile, actorIdentifier);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete character from profile
|
||||
/// </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)
|
||||
return;
|
||||
return false;
|
||||
|
||||
profile.Characters.Remove(actorIdentifier);
|
||||
|
||||
@@ -205,6 +207,8 @@ public partial class ProfileManager : IDisposable
|
||||
|
||||
_logger.Debug($"Removed character from profile {profile.UniqueId}.");
|
||||
_event.Invoke(ProfileChanged.Type.RemovedCharacter, profile, actorIdentifier);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user