mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
add "stats" command which shows stats
This commit is contained in:
parent
65afa28d30
commit
779cbdbdaf
1 changed files with 33 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
using SanAndreasUnity.Behaviours;
|
||||
using SanAndreasUnity.Net;
|
||||
using SanAndreasUnity.Utilities;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SanAndreasUnity.Commands
|
||||
|
@ -13,6 +14,7 @@ namespace SanAndreasUnity.Commands
|
|||
{
|
||||
new CommandManager.CommandInfo("uptime", true),
|
||||
new CommandManager.CommandInfo("players", true),
|
||||
new CommandManager.CommandInfo("stats", "show statistics", false, false, 1f),
|
||||
new CommandManager.CommandInfo("kick", false),
|
||||
new CommandManager.CommandInfo("auth", null, true, true, 2f),
|
||||
new CommandManager.CommandInfo("startserver", false),
|
||||
|
@ -83,6 +85,37 @@ namespace SanAndreasUnity.Commands
|
|||
response += "\n";
|
||||
}
|
||||
}
|
||||
else if (words[0] == "stats")
|
||||
{
|
||||
string category = null;
|
||||
if (numWords > 1)
|
||||
category = words[1];
|
||||
|
||||
var entries = Utilities.Stats.Entries;
|
||||
if (category != null)
|
||||
entries = entries.Where(_ => _.Key == category);
|
||||
|
||||
var statsContext = new Utilities.Stats.GetStatsContext();
|
||||
|
||||
foreach (var entriesWithCategory in entries)
|
||||
{
|
||||
statsContext.AppendLine("--------------------------------");
|
||||
statsContext.AppendLine(entriesWithCategory.Key);
|
||||
statsContext.AppendLine("--------------------------------");
|
||||
statsContext.AppendLine();
|
||||
statsContext.AppendLine();
|
||||
|
||||
foreach (var entry in entriesWithCategory.Value)
|
||||
{
|
||||
entry.getStatsAction?.Invoke(statsContext);
|
||||
}
|
||||
|
||||
statsContext.AppendLine();
|
||||
}
|
||||
|
||||
response += statsContext.stringBuilder.ToString();
|
||||
|
||||
}
|
||||
else if (words[0] == "kick")
|
||||
{
|
||||
if (NetUtils.IsServer)
|
||||
|
|
Loading…
Reference in a new issue