2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Network;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
2018-08-21 00:59:04 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Players
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Content side for all data that tracks a player session.
|
|
|
|
|
/// Use <see cref="PlayerDataExt.ContentData(IPlayerData)"/> to retrieve this from an <see cref="IPlayerData"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class PlayerData
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The session ID of the player owning this data.
|
|
|
|
|
/// </summary>
|
2018-09-09 15:34:43 +02:00
|
|
|
[ViewVariables]
|
2020-09-29 14:26:00 +02:00
|
|
|
public NetUserId UserId { get; }
|
2018-08-21 00:59:04 +02:00
|
|
|
|
2021-11-15 18:14:34 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// This is a backup copy of the player name stored on connection.
|
|
|
|
|
/// This is useful in the event the player disconnects.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public string Name { get; }
|
|
|
|
|
|
2018-08-21 00:59:04 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// The currently occupied mind of the player owning this data.
|
2018-11-24 19:12:22 +01:00
|
|
|
/// DO NOT DIRECTLY SET THIS UNLESS YOU KNOW WHAT YOU'RE DOING.
|
2018-08-21 00:59:04 +02:00
|
|
|
/// </summary>
|
2018-09-09 15:34:43 +02:00
|
|
|
[ViewVariables]
|
2021-11-15 18:14:34 +00:00
|
|
|
public Mind.Mind? Mind { get; private set; }
|
2018-08-21 00:59:04 +02:00
|
|
|
|
2020-10-30 16:06:48 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// If true, the player is an admin and they explicitly de-adminned mid-game,
|
|
|
|
|
/// so they should not regain admin if they reconnect.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ExplicitlyDeadminned { get; set; }
|
|
|
|
|
|
2018-11-24 19:12:22 +01:00
|
|
|
public void WipeMind()
|
|
|
|
|
{
|
2021-03-11 01:37:16 -08:00
|
|
|
Mind?.TransferTo(null);
|
2021-11-15 18:14:34 +00:00
|
|
|
// This will ensure Mind == null
|
|
|
|
|
Mind?.ChangeOwningPlayer(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called from Mind.ChangeOwningPlayer *and nowhere else.*
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void UpdateMindFromMindChangeOwningPlayer(Mind.Mind? mind)
|
|
|
|
|
{
|
|
|
|
|
Mind = mind;
|
2018-11-24 19:12:22 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-15 18:14:34 +00:00
|
|
|
public PlayerData(NetUserId userId, string name)
|
2018-08-21 00:59:04 +02:00
|
|
|
{
|
2020-09-29 14:26:00 +02:00
|
|
|
UserId = userId;
|
2021-11-15 18:14:34 +00:00
|
|
|
Name = name;
|
2018-08-21 00:59:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class PlayerDataExt
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the correctly cast instance of content player data from an engine player data storage.
|
|
|
|
|
/// </summary>
|
2020-08-22 15:18:04 +02:00
|
|
|
public static PlayerData? ContentData(this IPlayerData data)
|
2018-08-21 00:59:04 +02:00
|
|
|
{
|
2020-08-22 15:18:04 +02:00
|
|
|
return (PlayerData?) data.ContentDataUncast;
|
2018-08-21 00:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the correctly cast instance of content player data from an engine player data storage.
|
|
|
|
|
/// </summary>
|
2020-08-22 15:18:04 +02:00
|
|
|
public static PlayerData? ContentData(this IPlayerSession session)
|
2018-08-21 00:59:04 +02:00
|
|
|
{
|
|
|
|
|
return session.Data.ContentData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|