2019-03-25 22:12:16 -04:00
using Microsoft.AspNetCore.Diagnostics ;
2018-02-21 20:29:23 -05:00
using Microsoft.AspNetCore.Mvc ;
2019-12-02 16:52:36 -05:00
using SharedLibraryCore ;
2019-07-24 11:36:37 -04:00
using SharedLibraryCore.Dtos ;
2019-12-02 16:52:36 -05:00
using SharedLibraryCore.Interfaces ;
2020-01-31 21:15:07 -05:00
using System.Collections.Generic ;
2019-07-24 11:36:37 -04:00
using System.Linq ;
using System.Threading.Tasks ;
2018-02-21 20:29:23 -05:00
namespace WebfrontCore.Controllers
{
2018-03-06 02:22:19 -05:00
public class HomeController : BaseController
2018-02-21 20:29:23 -05:00
{
2020-02-11 17:44:06 -05:00
public HomeController ( IManager manager ) : base ( manager )
2020-01-31 21:15:07 -05:00
{
2019-12-02 16:52:36 -05:00
}
2019-07-24 11:36:37 -04:00
public async Task < IActionResult > Index ( )
2018-02-21 20:29:23 -05:00
{
2018-03-13 17:30:22 -04:00
ViewBag . Description = "IW4MAdmin is a complete server administration tool for IW4x." ;
2018-05-05 18:52:04 -04:00
ViewBag . Title = Localization [ "WEBFRONT_HOME_TITLE" ] ;
2018-03-13 17:30:22 -04:00
ViewBag . Keywords = "IW4MAdmin, server, administration, IW4x, MW2, Modern Warfare 2" ;
2019-07-24 11:36:37 -04:00
var model = new IW4MAdminInfo ( )
{
TotalAvailableClientSlots = Manager . GetServers ( ) . Sum ( _server = > _server . MaxClients ) ,
TotalOccupiedClientSlots = Manager . GetActiveClients ( ) . Count ,
TotalClientCount = await Manager . GetClientService ( ) . GetTotalClientsAsync ( ) ,
RecentClientCount = await Manager . GetClientService ( ) . GetRecentClientCount ( )
} ;
return View ( model ) ;
2018-02-21 20:29:23 -05:00
}
public IActionResult Error ( )
{
2018-05-14 13:55:10 -04:00
var exceptionFeature = HttpContext . Features . Get < IExceptionHandlerPathFeature > ( ) ;
2018-10-06 12:47:14 -04:00
Manager . GetLogger ( 0 ) . WriteError ( $"[Webfront] {exceptionFeature.Error.Message}" ) ;
Manager . GetLogger ( 0 ) . WriteDebug ( exceptionFeature . Path ) ;
Manager . GetLogger ( 0 ) . WriteDebug ( exceptionFeature . Error . StackTrace ) ;
2018-05-14 13:55:10 -04:00
2018-05-05 18:52:04 -04:00
ViewBag . Description = Localization [ "WEBFRONT_ERROR_DESC" ] ;
ViewBag . Title = Localization [ "WEBFRONT_ERROR_TITLE" ] ;
2019-10-23 14:35:20 -04:00
return View ( exceptionFeature . Error ) ;
}
public IActionResult ResponseStatusCode ( int? statusCode = null )
{
return View ( statusCode ) ;
2018-02-21 20:29:23 -05:00
}
2019-12-28 21:44:39 -05:00
public IActionResult Help ( )
{
ViewBag . IsFluid = true ;
2019-12-29 12:32:36 -05:00
ViewBag . Title = Localization [ "WEBFRONT_NAV_HELP" ] ;
// we don't need to the name of the shared library assembly
2019-12-28 21:44:39 -05:00
var excludedAssembly = typeof ( BaseController ) . Assembly ;
var commands = Manager . GetCommands ( )
2019-12-29 12:32:36 -05:00
. Where ( _cmd = > _cmd . Permission < = Client . Level )
2019-12-28 21:44:39 -05:00
. OrderByDescending ( _cmd = > _cmd . Permission )
. GroupBy ( _cmd = >
{
2019-12-29 12:32:36 -05:00
// we need the plugin type the command is defined in
2019-12-28 21:44:39 -05:00
var pluginType = _cmd . GetType ( ) . Assembly . GetTypes ( ) . FirstOrDefault ( _type = > _type . Assembly ! = excludedAssembly & & typeof ( IPlugin ) . IsAssignableFrom ( _type ) ) ;
return pluginType = = null ?
2019-12-29 12:32:36 -05:00
Utilities . CurrentLocalization . LocalizationIndex [ "WEBFRONT_HELP_COMMAND_NATIVE" ] :
2020-02-11 17:44:06 -05:00
Manager . Plugins . First ( _plugin = > _plugin . GetType ( ) = = pluginType ) . Name ; // for now we're just returning the name of the plugin, maybe later we'll include more info
2019-12-28 21:44:39 -05:00
} )
. Select ( _grp = > ( _grp . Key , _grp . AsEnumerable ( ) ) ) ;
return View ( commands ) ;
}
2018-02-21 20:29:23 -05:00
}
}