This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
forked from new-frontiers-14/frontier-station-14
-
Notifications
You must be signed in to change notification settings - Fork 37
Новые команды setallbalance и setbalance #257
Open
user424242420
wants to merge
3
commits into
Corvax-Frontier:master
Choose a base branch
from
user424242420:new-command
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
Content.Server/Administration/Commands/CorvaxSetBalanceCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Content.Shared.Administration; | ||
using Robust.Shared.Console; | ||
using Content.Server.Database; | ||
using System.Threading; | ||
using Content.Shared.Preferences; | ||
using Content.Shared.Preferences.Loadouts; | ||
|
||
namespace Content.Server.Administration.Commands; | ||
|
||
[AdminCommand(AdminFlags.Host)] | ||
public sealed class SetAllBalanceCommand : IConsoleCommand | ||
{ | ||
[Dependency] private readonly IServerDbManager _dbManager = default!; | ||
|
||
public string Command => "setallbalance"; | ||
public string Description => Loc.GetString("set-all-balance-command-description"); | ||
public string Help => Loc.GetString("set-all-balance-command-help-text", ("command",Command)); | ||
|
||
public void Execute(IConsoleShell shell, string argStr, string[] args) | ||
{ | ||
var loc = IoCManager.Resolve<ILocalizationManager>(); | ||
|
||
if (args.Length == 1 && int.TryParse(args[0], out var set_balance)) | ||
{ | ||
_dbManager.SetAllBalance(set_balance); | ||
return; | ||
} | ||
else if (args.Length == 1) | ||
{ | ||
shell.WriteLine(Loc.GetString("shell-argument-number-invalid", ("index", "1"))); | ||
return; | ||
} | ||
else | ||
{ | ||
_dbManager.SetAllBalance(25000); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
[AdminCommand(AdminFlags.Host)] | ||
public sealed class SetBalanceCommand : IConsoleCommand | ||
{ | ||
[Dependency] private readonly IServerDbManager _dbManager = default!; | ||
|
||
public string Command => "setbalance"; | ||
public string Description => Loc.GetString("set-balance-command-description"); | ||
public string Help => Loc.GetString("set-balance-command-help-text", ("command", Command)); | ||
|
||
public async void Execute(IConsoleShell shell, string argStr, string[] args) | ||
{ | ||
var loc = IoCManager.Resolve<ILocalizationManager>(); | ||
var set_balance = 0; | ||
int.TryParse(args[1], out set_balance); | ||
if (args.Length == 1 || args.Length == 2) | ||
{ | ||
var _userId = await _dbManager.GetPlayerRecordByUserName(args[0], new CancellationToken()); | ||
if (_userId is not null) { | ||
var userId = _userId.UserId; | ||
var _profile = await _dbManager.GetPlayerPreferencesAsync(userId, new CancellationToken()); | ||
if (_profile is not null) { | ||
foreach (var item in _profile.Characters) | ||
{ | ||
if (item.Value is HumanoidCharacterProfile profile) | ||
{ | ||
var newProfile = new HumanoidCharacterProfile( | ||
profile.Name, | ||
profile.FlavorText, | ||
profile.Species, | ||
profile.Age, | ||
profile.Sex, | ||
profile.Gender, | ||
set_balance, | ||
profile.Appearance, | ||
profile.SpawnPriority, | ||
profile.JobPriorities, | ||
profile.PreferenceUnavailable, | ||
profile.AntagPreferences, | ||
profile.TraitPreferences, | ||
new Dictionary<string, RoleLoadout>(profile.Loadouts)); | ||
await _dbManager.SaveCharacterSlotAsync(userId, newProfile, item.Key); | ||
} | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
else | ||
{ | ||
shell.WriteLine(Loc.GetString("shell-need-between-arguments", ("lower", "1"), ("upper", "2"))); | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,6 +262,13 @@ private static HumanoidCharacterProfile ConvertProfiles(Profile profile) | |
); | ||
} | ||
|
||
public async Task SetAllBalance(int set_balance) | ||
{ | ||
await using var db = await GetDb(); | ||
await db.DbContext.Database.ExecuteSqlAsync($"""UPDATE profile SET bank_balance = {set_balance}"""); | ||
await db.DbContext.SaveChangesAsync(); | ||
Comment on lines
+267
to
+269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SQL инъекции привет передают There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. var parameters = new[]
{
new SqlParameter("@balance", setBalance),
};
await db.DbContext.Database.ExecuteSqlRawAsync(query, parameters); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JerryImMouse а ты видишь какие параметры передаются в функцию? Как ты строку в инт передашь? |
||
} | ||
|
||
private static Profile ConvertProfiles(HumanoidCharacterProfile humanoid, int slot, Profile? profile = null) | ||
{ | ||
profile ??= new Profile(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Resources/Locale/ru-RU/administration/commands/corvaxsetbalance.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
set-all-balance-command-description = Комманда которая ставит баланс у всех. | ||
set-all-balance-command-help-text = Записывает данные в базу данных напрямую. ИСПОЛЬЗОВАТЬ ТОЛЬКО В ЛОББИ И ПОСЛЕ ЧЕГО ПЕРЕЗАПУСТИТЬ СЕРВЕР. | ||
|
||
set-balance-command-description = Команда которая устанавливает баланс по ckey/username. | ||
set-balance-command-help-text = Записывает данные в базу данных напрямую. Первый аргумент - username, Второй не обязательный - значение баланса, если ничего нет ставит 0. ИСПОЛЬЗОВАТЬ ТОЛЬКО В ЛОББИ И ПОСЛЕ ЧЕГО ПЕРЕЗАПУСТИТЬ СЕРВЕР. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот этот мусор сделает всем плохо.