Files
space-station-14/Content.Server/Players/PlayerData.cs
Pieter-Jan Briers 66c8a68891 Holy crap auth works (#2099)
* Holy crap auth works

* Fix some usages of UserID instead of UserName

* Refactor preferences.

They be non-async now. Also faster.

* Rename DbContext.

* Guest username assignment.

* Fix saving of profiles.

* Don't store data for guests.

* Fix generating invalid random colors.

* Don't allow dumb garbage for char preferences.

* Bans.

* Lol forgot to fill out the command description.

* Connection log.

* Rename all the tables and columns to be snake_case.

* Re-do migrations.

* Fixing tests and warnings.

* Update submodule
2020-09-29 14:26:00 +02:00

59 lines
1.7 KiB
C#

#nullable enable
using Content.Server.Mobs;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Network;
using Robust.Shared.ViewVariables;
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>
[ViewVariables]
public NetUserId UserId { get; }
/// <summary>
/// The currently occupied mind of the player owning this data.
/// DO NOT DIRECTLY SET THIS UNLESS YOU KNOW WHAT YOU'RE DOING.
/// </summary>
[ViewVariables]
public Mind? Mind { get; set; }
public void WipeMind()
{
Mind?.ChangeOwningPlayer(null);
Mind = null;
}
public PlayerData(NetUserId userId)
{
UserId = userId;
}
}
public static class PlayerDataExt
{
/// <summary>
/// Gets the correctly cast instance of content player data from an engine player data storage.
/// </summary>
public static PlayerData? ContentData(this IPlayerData data)
{
return (PlayerData?) data.ContentDataUncast;
}
/// <summary>
/// Gets the correctly cast instance of content player data from an engine player data storage.
/// </summary>
public static PlayerData? ContentData(this IPlayerSession session)
{
return session.Data.ContentData();
}
}
}