Fix creating and deleting character slots crashing the client and server (#2172)
* Fix creating a character slot crashing the client * a * Fix deleting character profiles
This commit is contained in:
@@ -41,11 +41,20 @@ namespace Content.Shared.Preferences
|
||||
/// </summary>
|
||||
public ICharacterProfile SelectedCharacter => Characters.ElementAtOrDefault(SelectedCharacterIndex);
|
||||
|
||||
public int FirstEmptySlot => IndexOfCharacter(null);
|
||||
public int FirstEmptySlot()
|
||||
{
|
||||
var firstEmpty = IndexOfCharacter(null);
|
||||
return firstEmpty == -1 ? _characters.Count : firstEmpty;
|
||||
}
|
||||
|
||||
public int IndexOfCharacter(ICharacterProfile profile)
|
||||
{
|
||||
return _characters.FindIndex(x => x == profile);
|
||||
}
|
||||
|
||||
public bool TryIndexOfCharacter(ICharacterProfile profile, out int index)
|
||||
{
|
||||
return (index = IndexOfCharacter(profile)) != -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,5 +128,32 @@ namespace Content.Shared.Preferences
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The client sends this to delete a character profile.
|
||||
/// </summary>
|
||||
protected class MsgDeleteCharacter : NetMessage
|
||||
{
|
||||
#region REQUIRED
|
||||
|
||||
public const MsgGroups GROUP = MsgGroups.Command;
|
||||
public const string NAME = nameof(MsgDeleteCharacter);
|
||||
|
||||
public MsgDeleteCharacter(INetChannel channel) : base(NAME, GROUP) { }
|
||||
|
||||
#endregion
|
||||
|
||||
public int Slot;
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
Slot = buffer.ReadInt32();
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
buffer.Write(Slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user