2018-03-06 02:22:19 -05:00
|
|
|
|
using IW4MAdmin;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
|
using SharedLibrary;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
using SharedLibrary.Database.Models;
|
2018-03-06 02:22:19 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class BaseController : Controller
|
|
|
|
|
{
|
|
|
|
|
protected ApplicationManager Manager;
|
|
|
|
|
protected bool Authorized { get; private set; }
|
2018-03-27 00:54:20 -04:00
|
|
|
|
protected EFClient User { get; private set; }
|
2018-03-06 02:22:19 -05:00
|
|
|
|
|
|
|
|
|
public override void OnActionExecuting(ActionExecutingContext context)
|
|
|
|
|
{
|
|
|
|
|
Manager = IW4MAdmin.Program.ServerManager;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
|
|
|
|
|
User = new EFClient()
|
|
|
|
|
{
|
|
|
|
|
ClientId = -1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-04-02 01:25:06 -04:00
|
|
|
|
var client = Manager.PrivilegedClients[context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()];
|
|
|
|
|
User.ClientId = client.ClientId;
|
|
|
|
|
User.Level = client.Level;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (KeyNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" ||
|
|
|
|
|
User.ClientId >= 0;
|
2018-03-09 03:01:12 -05:00
|
|
|
|
ViewBag.Authorized = Authorized;
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Url = Startup.Configuration["Web:Address"];
|
2018-04-02 01:25:06 -04:00
|
|
|
|
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 = "";
|
|
|
|
|
}
|
2018-03-06 02:22:19 -05:00
|
|
|
|
base.OnActionExecuting(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|