mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
104 lines
3.2 KiB
C#
104 lines
3.2 KiB
C#
#if TOOLS
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Data.Sqlite;
|
|
using Robust.Client.Utility;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Network;
|
|
|
|
namespace Robust.Client.Console.Commands
|
|
{
|
|
internal sealed partial class LauncherAuthCommand : LocalizedCommands
|
|
{
|
|
[Dependency] private IAuthManager _auth = default!;
|
|
[Dependency] private IGameControllerInternal _gameController = default!;
|
|
|
|
public override string Command => "launchauth";
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
var wantName = args.Length > 0 ? args[0] : null;
|
|
|
|
using var con = GetDb();
|
|
using var cmd = con.CreateCommand();
|
|
cmd.CommandText = "SELECT UserId, UserName, Token FROM Login WHERE Expires > datetime('NOW')";
|
|
|
|
if (wantName != null)
|
|
{
|
|
cmd.CommandText += " AND UserName = @userName";
|
|
cmd.Parameters.AddWithValue("@userName", wantName);
|
|
}
|
|
|
|
cmd.CommandText += " LIMIT 1;";
|
|
|
|
using var reader = cmd.ExecuteReader();
|
|
|
|
if (!reader.Read())
|
|
{
|
|
shell.WriteLine("Unable to find a matching login");
|
|
return;
|
|
}
|
|
|
|
var userId = Guid.Parse(reader.GetString(0));
|
|
var userName = reader.GetString(1);
|
|
var token = reader.GetString(2);
|
|
|
|
_auth.Token = token;
|
|
_auth.UserId = new NetUserId(userId);
|
|
|
|
shell.WriteLine($"Logged into account {userName}");
|
|
}
|
|
|
|
public override async ValueTask<CompletionResult> GetCompletionAsync(
|
|
IConsoleShell shell,
|
|
string[] args,
|
|
string argStr,
|
|
CancellationToken cancel)
|
|
{
|
|
if (args.Length != 1)
|
|
return CompletionResult.Empty;
|
|
|
|
return await Task.Run(() =>
|
|
{
|
|
using var con = GetDb();
|
|
|
|
using var cmd = con.CreateCommand();
|
|
cmd.CommandText = "SELECT UserName FROM Login WHERE Expires > datetime('NOW')";
|
|
|
|
var options = new List<CompletionOption>();
|
|
|
|
using var reader = cmd.ExecuteReader();
|
|
while (reader.Read())
|
|
{
|
|
var name = reader.GetString(0);
|
|
options.Add(new CompletionOption(name));
|
|
}
|
|
|
|
return CompletionResult.FromOptions(options);
|
|
},
|
|
cancel);
|
|
}
|
|
|
|
private SqliteConnection GetDb()
|
|
{
|
|
var basePath = UserDataDir.GetRootUserDataDir(_gameController);
|
|
var launcherDirName = Environment.GetEnvironmentVariable("SS14_LAUNCHER_APPDATA_NAME") ?? "launcher";
|
|
var dbPath = Path.Combine(basePath, launcherDirName, "settings.db");
|
|
|
|
#if USE_SYSTEM_SQLITE
|
|
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
|
|
#endif
|
|
var con = new SqliteConnection($"Data Source={dbPath};Mode=ReadOnly");
|
|
con.Open();
|
|
|
|
return con;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|