2023-06-20 16:29:26 +12:00
|
|
|
using Content.Server.GameTicking;
|
2023-06-18 11:33:19 -07:00
|
|
|
using Content.Server.Mind;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Network;
|
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>
|
2023-06-20 16:29:26 +12:00
|
|
|
[ViewVariables, Access(typeof(MindSystem), typeof(GameTicker))]
|
|
|
|
|
public Mind.Mind? Mind { get; 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; }
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2023-06-21 13:04:07 +12:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the mind that is associated with this player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Mind.Mind? GetMind(this IPlayerSession session)
|
|
|
|
|
{
|
|
|
|
|
return session.Data.ContentData()?.Mind;
|
|
|
|
|
}
|
2018-08-21 00:59:04 +02:00
|
|
|
}
|
|
|
|
|
}
|