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:
committed by
GitHub
parent
8a33e0a9bd
commit
66c8a68891
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Content.Shared.Preferences.Appearance;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -72,6 +73,47 @@ namespace Content.Shared.Preferences
|
||||
);
|
||||
}
|
||||
|
||||
public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearance appearance)
|
||||
{
|
||||
string hairStyleName;
|
||||
if (!HairStyles.HairStylesMap.ContainsKey(appearance.HairStyleName))
|
||||
{
|
||||
hairStyleName = HairStyles.DefaultHairStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
hairStyleName = appearance.HairStyleName;
|
||||
}
|
||||
|
||||
string facialHairStyleName;
|
||||
if (!HairStyles.FacialHairStylesMap.ContainsKey(appearance.FacialHairStyleName))
|
||||
{
|
||||
facialHairStyleName = HairStyles.DefaultFacialHairStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
facialHairStyleName = appearance.FacialHairStyleName;
|
||||
}
|
||||
|
||||
var hairColor = ClampColor(appearance.HairColor);
|
||||
var facialHairColor = ClampColor(appearance.FacialHairColor);
|
||||
var eyeColor = ClampColor(appearance.EyeColor);
|
||||
var skinColor = ClampColor(appearance.SkinColor);
|
||||
|
||||
return new HumanoidCharacterAppearance(
|
||||
hairStyleName,
|
||||
hairColor,
|
||||
facialHairStyleName,
|
||||
facialHairColor,
|
||||
eyeColor,
|
||||
skinColor);
|
||||
|
||||
static Color ClampColor(Color color)
|
||||
{
|
||||
return new Color(color.RByte, color.GByte, color.BByte);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MemberwiseEquals(ICharacterAppearance maybeOther)
|
||||
{
|
||||
if (!(maybeOther is HumanoidCharacterAppearance other)) return false;
|
||||
|
||||
@@ -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.";
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ namespace Content.Shared.Preferences
|
||||
/// </summary>
|
||||
public IEnumerable<ICharacterProfile> Characters => _characters.AsEnumerable();
|
||||
|
||||
public ICharacterProfile GetProfile(int index)
|
||||
{
|
||||
return _characters[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index of the currently selected character.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user