fix duplicate bot welcomes

fix prompt bool incorrect default value
rename GameEvent.Remote to GameEvent.IsRemote
include NetworkId in webfront claims
fix non descript error message appearing when something fails and localization is not initialized
This commit is contained in:
RaidMax 2019-01-03 14:39:22 -06:00
parent aaf9eb09b6
commit 08c883e0ff
13 changed files with 62 additions and 46 deletions

View File

@ -6,7 +6,7 @@
<RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
<Version>2.2.3.1</Version>
<Version>2.2.3.2</Version>
<Authors>RaidMax</Authors>
<Company>Forever None</Company>
<Product>IW4MAdmin</Product>
@ -31,8 +31,8 @@
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<TieredCompilation>true</TieredCompilation>
<AssemblyVersion>2.2.3.1</AssemblyVersion>
<FileVersion>2.2.3.1</FileVersion>
<AssemblyVersion>2.2.3.2</AssemblyVersion>
<FileVersion>2.2.3.2</FileVersion>
</PropertyGroup>
<ItemGroup>

View File

@ -449,7 +449,7 @@ namespace IW4MAdmin
client.Score = origin.Score;
// update their IP if it hasn't been set yet
if (client.IPAddress == null)
if (client.IPAddress == null && !client.IsBot)
{
return client.OnJoin(origin.IPAddress);
}

View File

@ -12,7 +12,7 @@ namespace IW4MAdmin.Application.Localization
{
public class Configure
{
public static void Initialize(string customLocale)
public static void Initialize(string customLocale = null)
{
string currentLocale = string.IsNullOrEmpty(customLocale) ? CultureInfo.CurrentCulture.Name : customLocale;
string[] localizationFiles = Directory.GetFiles(Path.Join(Utilities.OperatingDirectory, "Localization"), $"*.{currentLocale}.json");

View File

@ -10,6 +10,7 @@ using System.Text;
using System.Threading;
using SharedLibraryCore.Localization;
using IW4MAdmin.Application.Migration;
using SharedLibraryCore.Exceptions;
namespace IW4MAdmin.Application
{
@ -38,7 +39,15 @@ namespace IW4MAdmin.Application
try
{
ServerManager = ApplicationManager.GetInstance();
Localization.Configure.Initialize(ServerManager.GetApplicationSettings().Configuration()?.CustomLocale);
try
{
Localization.Configure.Initialize(ServerManager.GetApplicationSettings().Configuration().CustomLocale);
}
catch (ServerException)
{
Localization.Configure.Initialize();
}
loc = Utilities.CurrentLocalization.LocalizationIndex;
Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKey);
@ -107,7 +116,7 @@ namespace IW4MAdmin.Application
var consoleTask = Task.Run(async () =>
{
String userInput;
string userInput;
var Origin = Utilities.IW4MAdminClient(ServerManager.Servers[0]);
do
@ -144,13 +153,16 @@ namespace IW4MAdmin.Application
catch (Exception e)
{
Console.WriteLine(loc["MANAGER_INIT_FAIL"]);
string failMessage = loc == null ? "Failed to initalize IW4MAdmin" : loc["MANAGER_INIT_FAIL"];
string exitMessage = loc == null ? "Press any key to exit..." : loc["MANAGER_EXIT"];
Console.WriteLine(failMessage);
while (e.InnerException != null)
{
e = e.InnerException;
}
Console.WriteLine(e.Message);
Console.WriteLine(loc["MANAGER_EXIT"]);
Console.WriteLine(exitMessage);
Console.ReadKey();
return;
}

View File

@ -204,7 +204,8 @@ namespace IW4MAdmin.Application
Running = true;
#region DATABASE
using (var db = new DatabaseContext(GetApplicationSettings().Configuration()?.ConnectionString, GetApplicationSettings().Configuration()?.DatabaseProvider))
using (var db = new DatabaseContext(GetApplicationSettings().Configuration()?.ConnectionString,
GetApplicationSettings().Configuration()?.DatabaseProvider))
{
await new ContextSeed(db).Seed();
}

View File

@ -6,7 +6,6 @@ using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Objects;
namespace IW4MAdmin.Plugins.Login
{
@ -23,7 +22,7 @@ namespace IW4MAdmin.Plugins.Login
public Task OnEventAsync(GameEvent E, Server S)
{
if (E.Remote || Config.RequirePrivilegedClientLogin == false)
if (E.IsRemote || Config.RequirePrivilegedClientLogin == false)
return Task.CompletedTask;
if (E.Type == GameEvent.EventType.Connect)

View File

@ -188,7 +188,7 @@ namespace SharedLibraryCore
public EFClient Origin;
public EFClient Target;
public Server Owner;
public Boolean Remote = false;
public bool IsRemote { get; set; } = false;
public object Extra { get; set; }
public ManualResetEventSlim OnProcessed { get; set; }
public DateTime Time { get; set; }

View File

@ -1,5 +1,6 @@
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
@ -40,7 +41,7 @@ namespace SharedLibraryCore.Configuration
return File.WriteAllTextAsync(Path.Join(Utilities.OperatingDirectory, "Configuration", $"{Filename}.json"), appConfigJSON);
}
public T Configuration() => _configuration;
public T Configuration() => _configuration == null ? throw new ServerException("Configuration is null") : _configuration;
public void Set(T config)
{

View File

@ -53,13 +53,6 @@ namespace SharedLibraryCore.Services
private async Task UpdateAlias(string name, int? ip, EFClient entity, DatabaseContext context)
{
// entity is the tracked db context item
// todo: move this out
#if DEBUG == false
if (entity.IsBot)
{
return;
}
#endif
// get all aliases by IP address and LinkId
var iqAliases = context.Aliases
.Include(a => a.Link)
@ -377,7 +370,8 @@ namespace SharedLibraryCore.Services
ClientId = client.ClientId,
Level = client.Level,
Password = client.Password,
PasswordSalt = client.PasswordSalt
PasswordSalt = client.PasswordSalt,
NetworkId = client.NetworkId
};
#if DEBUG == true

View File

@ -212,7 +212,7 @@ namespace SharedLibraryCore
/// </summary>
/// <param name="input">Shorthand gametype reported from server</param>
/// <returns></returns>
public static String GetLocalizedGametype(String input)
public static string GetLocalizedGametype(String input)
{
switch (input)
{
@ -284,7 +284,7 @@ namespace SharedLibraryCore
public static int? ConvertToIP(this string str)
{
bool success = System.Net.IPAddress.TryParse(str, out System.Net.IPAddress ip);
return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 ?
return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 ?
(int?)BitConverter.ToInt32(ip.GetAddressBytes(), 0) :
null;
}
@ -294,12 +294,12 @@ namespace SharedLibraryCore
return !ip.HasValue ? "" : new System.Net.IPAddress(BitConverter.GetBytes(ip.Value)).ToString();
}
public static String GetTimePassed(DateTime start)
public static string GetTimePassed(DateTime start)
{
return GetTimePassed(start, true);
}
public static String GetTimePassed(DateTime start, bool includeAgo)
public static string GetTimePassed(DateTime start, bool includeAgo)
{
TimeSpan Elapsed = DateTime.UtcNow - start;
string ago = includeAgo ? $" {CurrentLocalization.LocalizationIndex["WEBFRONT_PENALTY_TEMPLATE_AGO"]}" : "";
@ -480,10 +480,11 @@ namespace SharedLibraryCore
/// <param name="description">description of the question's value</param>
/// <param name="defaultValue">default value to set if no input is entered</param>
/// <returns></returns>
public static bool PromptBool(string question, string description = null, char? defaultValue = 'y')
public static bool PromptBool(string question, string description = null, bool defaultValue = true)
{
Console.Write($"{question}?{(string.IsNullOrEmpty(description) ? "" : $" ({description}) ")}[y/n]: ");
return (Console.ReadLine().ToLower().FirstOrDefault() as char? ?? defaultValue) == 'y';
char response = Console.ReadLine().ToLower().FirstOrDefault();
return response != 0 ? response == 'y' : defaultValue;
}
/// <summary>

View File

@ -28,7 +28,8 @@ namespace WebfrontCore.Controllers
{
new Claim(ClaimTypes.NameIdentifier, client.Name),
new Claim(ClaimTypes.Role, client.Level.ToString()),
new Claim(ClaimTypes.Sid, client.ClientId.ToString())
new Claim(ClaimTypes.Sid, client.ClientId.ToString()),
new Claim(ClaimTypes.PrimarySid, client.NetworkId.ToString())
};
var claimsIdentity = new ClaimsIdentity(claims, "login");

View File

@ -1,14 +1,14 @@
using System;
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibraryCore;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using WebfrontCore.ViewModels;
namespace WebfrontCore.Controllers
@ -23,14 +23,19 @@ namespace WebfrontCore.Controllers
private static readonly byte[] LocalHost = { 127, 0, 0, 1 };
private static string SocialLink;
private static string SocialTitle;
protected List<Page> Pages;
public BaseController()
{
if (Manager == null)
{
Manager = Program.Manager;
}
if (Localization == null)
Localization = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex;
{
Localization = Utilities.CurrentLocalization.LocalizationIndex;
}
if (Manager.GetApplicationSettings().Configuration().EnableSocialLink && SocialLink == null)
{
@ -38,6 +43,13 @@ namespace WebfrontCore.Controllers
SocialTitle = Manager.GetApplicationSettings().Configuration().SocialLinkTitle;
}
Pages = Manager.GetPageList().Pages
.Select(page => new Page
{
Name = page.Key,
Location = page.Value
}).ToList();
ViewBag.Version = Manager.Version;
}
@ -55,6 +67,7 @@ namespace WebfrontCore.Controllers
try
{
Client.ClientId = Convert.ToInt32(base.User.Claims.First(c => c.Type == ClaimTypes.Sid).Value);
Client.NetworkId = User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertLong();
Client.Level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), User.Claims.First(c => c.Type == ClaimTypes.Role).Value);
Client.CurrentAlias = new EFAlias() { Name = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value };
}
@ -82,18 +95,11 @@ namespace WebfrontCore.Controllers
Authorized = Client.ClientId >= 0;
ViewBag.Authorized = Authorized;
ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontBindUrl;
ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontUrl;
ViewBag.User = Client;
ViewBag.SocialLink = SocialLink ?? "";
ViewBag.SocialTitle = SocialTitle;
// grab the pages from plugins
ViewBag.Pages = Manager.GetPageList().Pages
.Select(page => new Page
{
Name = page.Key,
Location = page.Value
}).ToList();
ViewBag.Pages = Pages;
base.OnActionExecuting(context);
}

View File

@ -33,6 +33,7 @@ namespace WebfrontCore.Controllers
{
ClientId = Client.ClientId,
Level = Client.Level,
NetworkId = Client.NetworkId,
CurrentServer = server,
CurrentAlias = new EFAlias()
{
@ -46,7 +47,7 @@ namespace WebfrontCore.Controllers
Data = command,
Origin = client,
Owner = server,
Remote = true
IsRemote = true
};
Manager.GetEventHandler().AddEvent(remoteEvent);