using Robust.Server.Player;
using Robust.Shared.Network;
namespace Content.Server.Players
{
///
/// Content side for all data that tracks a player session.
/// Use to retrieve this from an .
///
public sealed class PlayerData
{
///
/// The session ID of the player owning this data.
///
[ViewVariables]
public NetUserId UserId { get; }
///
/// This is a backup copy of the player name stored on connection.
/// This is useful in the event the player disconnects.
///
[ViewVariables]
public string Name { get; }
///
/// The currently occupied mind of the player owning this data.
/// DO NOT DIRECTLY SET THIS UNLESS YOU KNOW WHAT YOU'RE DOING.
///
[ViewVariables]
public Mind.Mind? Mind { get; private set; }
///
/// If true, the player is an admin and they explicitly de-adminned mid-game,
/// so they should not regain admin if they reconnect.
///
public bool ExplicitlyDeadminned { get; set; }
public void WipeMind()
{
Mind?.TransferTo(null);
// This will ensure Mind == null
Mind?.ChangeOwningPlayer(null);
}
///
/// Called from Mind.ChangeOwningPlayer *and nowhere else.*
///
public void UpdateMindFromMindChangeOwningPlayer(Mind.Mind? mind)
{
Mind = mind;
}
public PlayerData(NetUserId userId, string name)
{
UserId = userId;
Name = name;
}
}
public static class PlayerDataExt
{
///
/// Gets the correctly cast instance of content player data from an engine player data storage.
///
public static PlayerData? ContentData(this IPlayerData data)
{
return (PlayerData?) data.ContentDataUncast;
}
///
/// Gets the correctly cast instance of content player data from an engine player data storage.
///
public static PlayerData? ContentData(this IPlayerSession session)
{
return session.Data.ContentData();
}
}
}