diff --git a/Application/Misc/Logger.cs b/Application/Misc/Logger.cs
index ba4e3f324..123c0bb2d 100644
--- a/Application/Misc/Logger.cs
+++ b/Application/Misc/Logger.cs
@@ -60,6 +60,7 @@ namespace IW4MAdmin.Application
await OnLogWriting.WaitAsync();
string stringType = type.ToString();
+ msg = msg.StripColors();
try
{
@@ -73,13 +74,13 @@ namespace IW4MAdmin.Application
{
#if DEBUG
// lets keep it simple and dispose of everything quickly as logging wont be that much (relatively)
- Console.WriteLine(LogLine.StripColors());
+ Console.WriteLine(LogLine);
await File.AppendAllTextAsync(FileName, $"{LogLine}{Environment.NewLine}");
//Debug.WriteLine(msg);
#else
if (type == LogType.Error || type == LogType.Verbose)
{
- Console.WriteLine(LogLine.StripColors());
+ Console.WriteLine(LogLine);
}
await File.AppendAllTextAsync(FileName, $"{LogLine}{Environment.NewLine}");
#endif
diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs
index f3d23735d..ca8003406 100644
--- a/SharedLibraryCore/Utilities.cs
+++ b/SharedLibraryCore/Utilities.cs
@@ -156,6 +156,14 @@ namespace SharedLibraryCore
///
public static string FixIW4ForwardSlash(this string str) => str.Replace("/", " /");
+ private static readonly IList _zmGameTypes = new[] { "zclassic", "zstandard", "zcleansed", "zgrief" };
+ ///
+ /// indicates if the given server is running a zombie game mode
+ ///
+ ///
+ ///
+ public static bool IsZombieServer(this Server server) => server.GameName == Game.T6 && _zmGameTypes.Contains(server.Gametype.ToLower());
+
///
/// Get the IW Engine color code corresponding to an admin level
///
diff --git a/WebfrontCore/Controllers/AccountController.cs b/WebfrontCore/Controllers/AccountController.cs
index 876841ff2..003d60033 100644
--- a/WebfrontCore/Controllers/AccountController.cs
+++ b/WebfrontCore/Controllers/AccountController.cs
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using System;
@@ -10,13 +11,9 @@ namespace WebfrontCore.Controllers
{
public class AccountController : BaseController
{
- ///
- /// life span in months
- ///
- private const int COOKIE_LIFESPAN = 3;
[HttpGet]
- public async Task LoginAsync(int clientId, string password, Microsoft.AspNetCore.Http.HttpContext ctx = null)
+ public async Task LoginAsync(int clientId, string password)
{
if (clientId == 0 || string.IsNullOrEmpty(password))
{
@@ -48,13 +45,7 @@ namespace WebfrontCore.Controllers
var claimsIdentity = new ClaimsIdentity(claims, "login");
var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
- await (ctx ?? HttpContext).SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrinciple, new AuthenticationProperties()
- {
- AllowRefresh = true,
- ExpiresUtc = DateTime.UtcNow.AddMonths(COOKIE_LIFESPAN),
- IsPersistent = true,
- IssuedUtc = DateTime.UtcNow
- });
+ await SignInAsync(claimsPrinciple);
return Ok();
}
diff --git a/WebfrontCore/Controllers/ActionController.cs b/WebfrontCore/Controllers/ActionController.cs
index 6fe30377a..7ad029131 100644
--- a/WebfrontCore/Controllers/ActionController.cs
+++ b/WebfrontCore/Controllers/ActionController.cs
@@ -238,6 +238,15 @@ namespace WebfrontCore.Controllers
{
var server = Manager.GetServers().First(_server => _server.EndPoint == id);
+ server.ChatHistory.Add(new SharedLibraryCore.Dtos.ChatInfo()
+ {
+ ClientId = Client.ClientId,
+ Message = message,
+ Name = Client.Name,
+ ServerGame = server.GameName,
+ Time = DateTime.Now
+ });
+
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.EndPoint,
diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs
index 2691ff0cc..7bdc68d82 100644
--- a/WebfrontCore/Controllers/BaseController.cs
+++ b/WebfrontCore/Controllers/BaseController.cs
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Authentication.Cookies;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibraryCore;
@@ -9,12 +11,18 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
+using System.Threading.Tasks;
using WebfrontCore.ViewModels;
namespace WebfrontCore.Controllers
{
public class BaseController : Controller
{
+ ///
+ /// life span in months
+ ///
+ private const int COOKIE_LIFESPAN = 3;
+
protected IManager Manager;
protected readonly DatabaseContext Context;
protected bool Authorized { get; set; }
@@ -55,6 +63,17 @@ namespace WebfrontCore.Controllers
ViewBag.EnableColorCodes = Manager.GetApplicationSettings().Configuration().EnableColorCodes;
}
+ protected async Task SignInAsync(ClaimsPrincipal claimsPrinciple)
+ {
+ await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrinciple, new AuthenticationProperties()
+ {
+ AllowRefresh = true,
+ ExpiresUtc = DateTime.UtcNow.AddMonths(COOKIE_LIFESPAN),
+ IsPersistent = true,
+ IssuedUtc = DateTime.UtcNow
+ });
+ }
+
public override void OnActionExecuting(ActionExecutingContext context)
{
Client = Client ?? new EFClient()
@@ -99,11 +118,15 @@ namespace WebfrontCore.Controllers
Client.Level = EFClient.Permission.Console;
Client.CurrentAlias = new EFAlias() { Name = "IW4MAdmin" };
Authorized = true;
- using (var controller = new AccountController())
+ var claims = new[]
{
- _ = controller.LoginAsync(1, "password", HttpContext).Result;
- }
-
+ new Claim(ClaimTypes.NameIdentifier, Client.CurrentAlias.Name),
+ new Claim(ClaimTypes.Role, Client.Level.ToString()),
+ new Claim(ClaimTypes.Sid, Client.ClientId.ToString()),
+ new Claim(ClaimTypes.PrimarySid, Client.NetworkId.ToString("X"))
+ };
+ var claimsIdentity = new ClaimsIdentity(claims, "login");
+ SignInAsync(new ClaimsPrincipal(claimsIdentity)).Wait();
}
ViewBag.Authorized = Authorized;
diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs
index 8e64dd8b2..53aad854a 100644
--- a/WebfrontCore/Startup.cs
+++ b/WebfrontCore/Startup.cs
@@ -73,6 +73,8 @@ namespace WebfrontCore
mvcBuilder.AddApplicationPart(asm);
}
+ services.AddHttpContextAccessor();
+
services.AddEntityFrameworkSqlite()
.AddDbContext();