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
@@ -21,5 +21,40 @@ namespace Content.Shared
|
||||
|
||||
public static readonly CVarDef<bool>
|
||||
GameLobbyEnableWin = CVarDef.Create("game.enablewin", true, CVar.ARCHIVE);
|
||||
|
||||
public static readonly CVarDef<int>
|
||||
GameMaxCharacterSlots = CVarDef.Create("game.maxcharacterslots", 10, CVar.ARCHIVE | CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// When enabled, guests will be assigned permanent UIDs and will have their preferences stored.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool>
|
||||
GamePersistGuests = CVarDef.Create("game.persistguests", true, CVar.ARCHIVE | CVar.SERVERONLY);
|
||||
|
||||
|
||||
/*
|
||||
* Database stuff
|
||||
*/
|
||||
|
||||
public static readonly CVarDef<string> DatabaseEngine =
|
||||
CVarDef.Create("database.engine", "sqlite", CVar.SERVERONLY);
|
||||
|
||||
public static readonly CVarDef<string> DatabaseSqliteDbPath =
|
||||
CVarDef.Create("database.sqlite_dbpath", "preferences.db", CVar.SERVERONLY);
|
||||
|
||||
public static readonly CVarDef<string> DatabasePgHost =
|
||||
CVarDef.Create("database.pg_host", "localhost", CVar.SERVERONLY);
|
||||
|
||||
public static readonly CVarDef<int> DatabasePgPort =
|
||||
CVarDef.Create("database.pg_port", 5432, CVar.SERVERONLY);
|
||||
|
||||
public static readonly CVarDef<string> DatabasePgDatabase =
|
||||
CVarDef.Create("database.pg_database", "ss14", CVar.SERVERONLY);
|
||||
|
||||
public static readonly CVarDef<string> DatabasePgUsername =
|
||||
CVarDef.Create("database.pg_username", "", CVar.SERVERONLY);
|
||||
|
||||
public static readonly CVarDef<string> DatabasePgPassword =
|
||||
CVarDef.Create("database.pg_password", "", CVar.SERVERONLY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -193,23 +193,23 @@ namespace Content.Shared
|
||||
/// <summary>
|
||||
/// The Status of the Player in the lobby (ready, observer, ...)
|
||||
/// </summary>
|
||||
public Dictionary<NetSessionId, PlayerStatus> PlayerStatus { get; set; }
|
||||
public Dictionary<NetUserId, PlayerStatus> PlayerStatus { get; set; }
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
PlayerStatus = new Dictionary<NetSessionId, PlayerStatus>();
|
||||
PlayerStatus = new Dictionary<NetUserId, PlayerStatus>();
|
||||
var length = buffer.ReadInt32();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var serializer = IoCManager.Resolve<IRobustSerializer>();
|
||||
var byteLength = buffer.ReadVariableInt32();
|
||||
NetSessionId sessionID;
|
||||
NetUserId userId;
|
||||
using (var stream = buffer.ReadAsStream(byteLength))
|
||||
{
|
||||
serializer.DeserializeDirect(stream, out sessionID);
|
||||
serializer.DeserializeDirect(stream, out userId);
|
||||
}
|
||||
var status = (PlayerStatus)buffer.ReadByte();
|
||||
PlayerStatus.Add(sessionID, status);
|
||||
PlayerStatus.Add(userId, status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user