-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add new command AdminToggle #785
Changes from 11 commits
0ab9dd4
52617ac
d77b214
2e6014d
b8e8c63
d6c3040
228cf6c
b87c61a
137d5ec
47efd12
65057f3
64646ef
dbcf9d1
5fdac4a
5ace881
84d803a
acf1c0e
0d616e3
8b21ce9
b76814b
d107736
bddfb46
a89007d
b0c8960
fcf3fa3
a079231
06f9dc7
9c4f48b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Content.Server.Administration.Managers; | ||
using Content.Shared.Administration; | ||
using Robust.Shared.Console; | ||
using Content.Server.Administration; | ||
using Robust.Server.Player; | ||
using System.Linq; | ||
|
||
namespace Content.Server.ADT.Administration.Commands; | ||
|
||
|
||
[AdminCommand(AdminFlags.Permissions)] | ||
public sealed class AdminToggleCommand : LocalizedCommands | ||
{ | ||
[Dependency] private readonly IPlayerLocator _locator = default!; | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
public override string Command => "admin_toggle"; | ||
|
||
public override async void Execute(IConsoleShell shell, string argStr, string[] args) | ||
{ | ||
if (args.Length != 2) | ||
{ | ||
shell.WriteLine("Error: invalid arguments!"); | ||
return; | ||
} | ||
|
||
var target = args[0]; | ||
var located = await _locator.LookupIdByNameOrIdAsync(target); | ||
if (located == null) | ||
{ | ||
shell.WriteError(Loc.GetString("cmd-admin_toggle-error-args")); | ||
return; | ||
} | ||
|
||
if (!_playerManager.TryGetSessionById(located.UserId, out var targetSession)) | ||
{ | ||
shell.WriteLine("Not session it's player!"); | ||
return; | ||
} | ||
|
||
if (targetSession == null) | ||
return; | ||
|
||
var mgr = IoCManager.Resolve<IAdminManager>(); | ||
if (args[1] == "deadmin") | ||
{ | ||
mgr.DeAdmin(targetSession); | ||
} | ||
else if (args[1] == "readmin" && !(mgr.GetAdminData(targetSession, includeDeAdmin: true) == null)) | ||
{ | ||
mgr.ReAdmin(targetSession); | ||
} | ||
} | ||
Schrodinger71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) | ||
{ | ||
if (args.Length == 1) | ||
{ | ||
var options = _playerManager.Sessions.Select(c => c.Name).OrderBy(c => c).ToArray(); | ||
return CompletionResult.FromHintOptions( | ||
options, | ||
LocalizationManager.GetString("cmd-ban-hint")); | ||
} | ||
if (args.Length == 2) | ||
{ | ||
var durations = new CompletionOption[] | ||
{ | ||
new("deadmin", LocalizationManager.GetString("cmd-admin_toggle-deadmin")), | ||
new("readmin", LocalizationManager.GetString("cmd-admin_toggle-readmin")), | ||
}; | ||
return CompletionResult.FromHintOptions(durations, LocalizationManager.GetString("cmd-admin_toggle-hint-duration")); | ||
} | ||
return CompletionResult.Empty; | ||
} | ||
Schrodinger71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -112,10 +112,10 @@ public void Stealth(ICommonSession session) | |||||||||||||||||||||
var playerData = session.ContentData()!; | ||||||||||||||||||||||
playerData.Stealthed = true; | ||||||||||||||||||||||
reg.Data.Stealth = true; | ||||||||||||||||||||||
|
||||||||||||||||||||||
_chat.DispatchServerMessage(session, Loc.GetString("admin-manager-stealthed-message")); | ||||||||||||||||||||||
_chat.SendAdminAnnouncement(Loc.GetString("admin-manager-self-de-admin-message", ("exAdminName", session.Name)), AdminFlags.Stealth); | ||||||||||||||||||||||
_chat.SendAdminAnnouncement(Loc.GetString("admin-manager-self-enable-stealth", ("stealthAdminName", session.Name)), flagWhitelist: AdminFlags.Stealth); | ||||||||||||||||||||||
// ADT Tweak commented | ||||||||||||||||||||||
// _chat.DispatchServerMessage(session, Loc.GetString("admin-manager-stealthed-message")); | ||||||||||||||||||||||
// _chat.SendAdminAnnouncement(Loc.GetString("admin-manager-self-de-admin-message", ("exAdminName", session.Name)), AdminFlags.Stealth); | ||||||||||||||||||||||
// _chat.SendAdminAnnouncement(Loc.GetString("admin-manager-self-enable-stealth", ("stealthAdminName", session.Name)), flagWhitelist: AdminFlags.Stealth); | ||||||||||||||||||||||
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. Добавьте маркеры ADT-Tweak Согласно правилам кодирования, изменения вне папок ADT должны быть обрамлены маркерами ADT-Tweak. Примените следующие изменения: + // ADT-Tweak-Start
// ADT Tweak commented
// _chat.DispatchServerMessage(session, Loc.GetString("admin-manager-stealthed-message"));
// _chat.SendAdminAnnouncement(Loc.GetString("admin-manager-self-de-admin-message", ("exAdminName", session.Name)), AdminFlags.Stealth);
// _chat.SendAdminAnnouncement(Loc.GetString("admin-manager-self-enable-stealth", ("stealthAdminName", session.Name)), flagWhitelist: AdminFlags.Stealth);
+ // ADT-Tweak-End 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
public void UnStealth(ICommonSession session) | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,7 @@ | |||||||||||||||||||||||||||||||||||
using Robust.Shared.Player; | ||||||||||||||||||||||||||||||||||||
using Robust.Shared.Prototypes; | ||||||||||||||||||||||||||||||||||||
using Robust.Shared.Timing; | ||||||||||||||||||||||||||||||||||||
using Content.Shared.Administration; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
namespace Content.Server.Administration.Managers; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
@@ -39,6 +40,7 @@ public sealed partial class BanManager : IBanManager, IPostInjectInit | |||||||||||||||||||||||||||||||||||
[Dependency] private readonly IGameTiming _gameTiming = default!; | ||||||||||||||||||||||||||||||||||||
[Dependency] private readonly ITaskManager _taskManager = default!; | ||||||||||||||||||||||||||||||||||||
[Dependency] private readonly UserDbDataManager _userDbData = default!; | ||||||||||||||||||||||||||||||||||||
[Dependency] private readonly IAdminManager _adminManager = default!; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
private ISawmill _sawmill = default!; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
@@ -134,6 +136,13 @@ public void Restart() | |||||||||||||||||||||||||||||||||||
#region Server Bans | ||||||||||||||||||||||||||||||||||||
public async void CreateServerBan(NetUserId? target, string? targetUsername, NetUserId? banningAdmin, (IPAddress, int)? addressRange, ImmutableArray<byte>? hwid, uint? minutes, NoteSeverity severity, string reason) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
// ADT-Tweak-Start | ||||||||||||||||||||||||||||||||||||
if (targetUsername != null && _playerManager.TryGetSessionByUsername(targetUsername, out var player)) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
if (_adminManager.HasAdminFlag(player, AdminFlags.Permissions)) | ||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
// ADT-Tweak-End | ||||||||||||||||||||||||||||||||||||
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. 🛠️ Refactor suggestion Необходимо добавить логирование при попытке бана администратора Текущая реализация тихо прерывает выполнение при попытке забанить пользователя с флагом Предлагаемые изменения: // ADT-Tweak-Start
if (targetUsername != null && _playerManager.TryGetSessionByUsername(targetUsername, out var player))
{
if (_adminManager.HasAdminFlag(player, AdminFlags.Permissions))
+ {
+ _sawmill.Warning($"Attempted to ban user {targetUsername} with Permissions flag by {banningAdmin}");
return;
+ }
}
// ADT-Tweak-End 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
DateTimeOffset? expires = null; | ||||||||||||||||||||||||||||||||||||
if (minutes > 0) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,9 @@ | |||||||||||||||||||||
using Robust.Shared.Console; | ||||||||||||||||||||||
using Robust.Shared.Network; | ||||||||||||||||||||||
using Robust.Shared.Timing; | ||||||||||||||||||||||
using Content.Server.Administration.Managers; | ||||||||||||||||||||||
using Content.Server.Administration.Logs; | ||||||||||||||||||||||
using Content.Shared.Database; | ||||||||||||||||||||||
|
||||||||||||||||||||||
namespace Content.Server.GhostKick; | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -47,6 +50,8 @@ public void DoDisconnect(INetChannel channel, string reason) | |||||||||||||||||||||
[AdminCommand(AdminFlags.Moderator)] | ||||||||||||||||||||||
public sealed class GhostKickCommand : IConsoleCommand | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
[Dependency] private readonly IAdminManager _adminManager = default!; | ||||||||||||||||||||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!; | ||||||||||||||||||||||
public string Command => "ghostkick"; | ||||||||||||||||||||||
public string Description => "Kick a client from the server as if their network just dropped."; | ||||||||||||||||||||||
public string Help => "Usage: ghostkick <Player> [Reason]"; | ||||||||||||||||||||||
|
@@ -70,7 +75,18 @@ public void Execute(IConsoleShell shell, string argStr, string[] args) | |||||||||||||||||||||
shell.WriteError($"Unable to find player: '{playerName}'."); | ||||||||||||||||||||||
return; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// ADT-Tweak-start | ||||||||||||||||||||||
if (_adminManager.HasAdminFlag(player, AdminFlags.Permissions)) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
shell.WriteError($"You not permission for kick '{playerName}'."); | ||||||||||||||||||||||
Schrodinger71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
return; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
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. 🛠️ Refactor suggestion Исправьте грамматику в сообщении об ошибке Текущее сообщение содержит грамматические ошибки. Предлагаю следующие изменения: - shell.WriteError($"You not permission for kick '{playerName}'.");
+ shell.WriteError($"У вас нет прав для кика пользователя '{playerName}'."); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
_adminLogger.Add( | ||||||||||||||||||||||
LogType.AdminMessage, | ||||||||||||||||||||||
LogImpact.Low, | ||||||||||||||||||||||
$"[АДМИНАБУЗ] {shell.Player?.Name} used the command ghostkick on '{playerName}'." | ||||||||||||||||||||||
); | ||||||||||||||||||||||
// ADT-Tweak-end | ||||||||||||||||||||||
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. 💡 Codebase verification Обнаружено некорректное использование проверки прав Проверка
if (!_adminManager.HasAdminFlag(player, AdminFlags.Permissions))
{
shell.WriteError($"You not permission for kick '{playerName}'.");
return;
} 🔗 Analysis chainПроверьте согласованность проверок прав Необходимо убедиться, что аналогичные административные команды используют согласованный подход к проверке прав. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Поиск похожих административных команд и их проверок прав
ast-grep --pattern 'AdminCommand(AdminFlags.$_)
public sealed class $_Command : IConsoleCommand
{
$$$
_adminManager.HasAdminFlag($_, AdminFlags.$_)
$$$
}'
Length of output: 162 Script: #!/bin/bash
# Search for admin command classes and their permission checks
rg -U "AdminCommand.*AdminFlags\." -A 5
# Search for HasAdminFlag usage patterns
rg "_adminManager\.HasAdminFlag" -A 2 -B 2
# Search for other ghost-related commands
rg "class.*Command.*ghost" -A 5
Length of output: 139095 Script: #!/bin/bash
# Search for ghost-related commands and their permission checks
rg -U "class.*GhostKick.*Command" -A 10 -B 2
# Search for similar permission checks in admin commands
rg "HasAdminFlag.*Permissions" -A 2 -B 2
# Search for admin flag declarations
rg "AdminFlags\.Permissions" -A 2 -B 2
Length of output: 6731 |
||||||||||||||||||||||
ghostKick.DoDisconnect(player.Channel, reason); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} |
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.
🛠️ Refactor suggestion
Требуется добавить комментарии ADT-Tweak
Отключение команды "fuckrules" соответствует целям PR. Однако, согласно руководству по кодированию, изменения вне папок /ADT/ должны быть обрамлены специальными комментариями.
Примените следующие изменения:
📝 Committable suggestion