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
This commit is contained in:
Pieter-Jan Briers
2020-09-29 14:26:00 +02:00
committed by GitHub
parent 8a33e0a9bd
commit 66c8a68891
72 changed files with 4144 additions and 2642 deletions

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Preferences
@@ -12,6 +14,7 @@ namespace Content.Shared.Preferences
private readonly List<string> _antagPreferences;
public static int MinimumAge = 18;
public static int MaximumAge = 120;
public static int MaxNameLength = 32;
private HumanoidCharacterProfile(
string name,
@@ -146,6 +149,69 @@ namespace Content.Shared.Preferences
return new HumanoidCharacterProfile(Name, Age, Sex, Appearance, _jobPriorities, PreferenceUnavailable, list);
}
/// <summary>
/// Makes this profile valid so there's no bad data like negative ages.
/// </summary>
public static HumanoidCharacterProfile EnsureValid(
HumanoidCharacterProfile profile,
IPrototypeManager prototypeManager)
{
var age = Math.Clamp(profile.Age, MinimumAge, MaximumAge);
var sex = profile.Sex switch
{
Sex.Male => Sex.Male,
Sex.Female => Sex.Female,
_ => Sex.Male // Invalid enum values.
};
string name;
if (string.IsNullOrEmpty(profile.Name))
{
name = "John Doe";
}
else if (profile.Name.Length > MaxNameLength)
{
name = profile.Name[..MaxNameLength];
}
else
{
name = profile.Name;
}
// TODO: Avoid Z̨͇̙͉͎̭͔̼̿͋A͚̖̞̗̞͈̓̾̀ͩͩ̔L̟ͮ̈͝G̙O͍͎̗̺̺ͫ̀̽͊̓͝ͅ tier shenanigans.
// And other stuff like RTL overrides and such.
// Probably also emojis...
name = name.Trim();
var appearance = HumanoidCharacterAppearance.EnsureValid(profile.Appearance);
var prefsUnavailableMode = profile.PreferenceUnavailable switch
{
PreferenceUnavailableMode.StayInLobby => PreferenceUnavailableMode.StayInLobby,
PreferenceUnavailableMode.SpawnAsOverflow => PreferenceUnavailableMode.SpawnAsOverflow,
_ => PreferenceUnavailableMode.StayInLobby // Invalid enum values.
};
var priorities = profile.JobPriorities
.Where(p => prototypeManager.HasIndex<JobPrototype>(p.Key) && p.Value switch
{
JobPriority.Never => false, // Drop never since that's assumed default.
JobPriority.Low => true,
JobPriority.Medium => true,
JobPriority.High => true,
_ => false
})
.ToDictionary(p => p.Key, p => p.Value);
var antags = profile.AntagPreferences
.Where(prototypeManager.HasIndex<AntagPrototype>)
.ToList();
return new HumanoidCharacterProfile(name, age, sex, appearance, priorities, prefsUnavailableMode, antags);
}
public string Summary =>
$"{Name}, {Age} years old {Sex.ToString().ToLower()} human.";