IW4M-Admin/Plugins/IW4ScriptCommands/GscApiController.cs
RaidMax 02a784ad09 allow prompt string to have an empty/default value
upgrade some project dependencies
don't try to run events on parsers
update top players rank distribution
2020-02-17 10:05:31 -06:00

45 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Text;
namespace WebfrontCore.Controllers.API
{
[Route("api/gsc/[action]")]
public class GscApiController : BaseController
{
public GscApiController(IManager manager) : base(manager)
{
}
/// <summary>
/// grabs basic info about the client from IW4MAdmin
/// </summary>
/// <param name="networkId"></param>
/// <returns></returns>
[HttpGet("{networkId}")]
public IActionResult ClientInfo(string networkId)
{
long decimalNetworkId = networkId.ConvertGuidToLong(System.Globalization.NumberStyles.HexNumber);
var clientInfo = Manager.GetActiveClients()
.FirstOrDefault(c => c.NetworkId == decimalNetworkId);
if (clientInfo != null)
{
var sb = new StringBuilder();
sb.AppendLine($"admin={clientInfo.IsPrivileged()}");
sb.AppendLine($"level={(int)clientInfo.Level}");
sb.AppendLine($"levelstring={clientInfo.Level.ToLocalizedLevelName()}");
sb.AppendLine($"connections={clientInfo.Connections}");
sb.AppendLine($"authenticated={clientInfo.GetAdditionalProperty<bool>("IsLoggedIn") == true}");
return Content(sb.ToString());
}
return Content("");
}
}
}