IW4M-Admin/WebfrontCore/Controllers/BaseController.cs
RaidMax 2952e307b2 tweaked rcon throttle rate/made async
increased cutoff for server overview messages
dont print message if timed out
2018-04-02 00:25:06 -05:00

55 lines
1.8 KiB
C#

using IW4MAdmin;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibrary;
using SharedLibrary.Database.Models;
using System.Collections.Generic;
namespace WebfrontCore.Controllers
{
public class BaseController : Controller
{
protected ApplicationManager Manager;
protected bool Authorized { get; private set; }
protected EFClient User { get; private set; }
public override void OnActionExecuting(ActionExecutingContext context)
{
Manager = IW4MAdmin.Program.ServerManager;
User = new EFClient()
{
ClientId = -1
};
try
{
var client = Manager.PrivilegedClients[context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()];
User.ClientId = client.ClientId;
User.Level = client.Level;
}
catch (KeyNotFoundException)
{
}
Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" ||
User.ClientId >= 0;
ViewBag.Authorized = Authorized;
ViewBag.Url = Startup.Configuration["Web:Address"];
ViewBag.User = User;
if (Manager.GetApplicationSettings().Configuration().EnableDiscordLink)
{
string inviteLink = Manager.GetApplicationSettings().Configuration().DiscordInviteCode;
if (inviteLink != null)
ViewBag.DiscordLink = inviteLink.Contains("https") ? inviteLink : $"https://discordapp.com/invite/{inviteLink}";
else
ViewBag.DiscordLink = "";
}
base.OnActionExecuting(context);
}
}
}