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:
DrSmugleaf
2020-10-06 12:03:14 +02:00
committed by GitHub
parent f9bb3fed6f
commit f35625630b
5 changed files with 89 additions and 5 deletions

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}
}
}