diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs
index 59cccb76c..a35833d10 100644
--- a/Application/IW4MServer.cs
+++ b/Application/IW4MServer.cs
@@ -64,7 +64,11 @@ namespace IW4MAdmin
client.CurrentServer = this;
Clients[client.ClientNumber] = client;
- await client.OnJoin(clientFromLog.IPAddress);
+
+ if (clientFromLog.IPAddress != null)
+ {
+ await client.OnJoin(clientFromLog.IPAddress);
+ }
client.State = EFClient.ClientState.Connected;
#if DEBUG == true
@@ -441,7 +445,7 @@ namespace IW4MAdmin
client.Score = origin.Score;
// update their IP if it hasn't been set yet
- if (!client.IPAddress.HasValue)
+ if (client.IPAddress == null)
{
return client.OnJoin(origin.IPAddress);
}
@@ -463,7 +467,7 @@ namespace IW4MAdmin
#endif
var currentClients = GetClientsAsList();
var polledClients = (await this.GetStatusAsync()).AsEnumerable();
- if (this.Manager.GetApplicationSettings().Configuration().IgnoreBots)
+ if (Manager.GetApplicationSettings().Configuration().IgnoreBots)
{
polledClients = polledClients.Where(c => !c.IsBot);
}
diff --git a/Application/Main.cs b/Application/Main.cs
index 8f19df87a..d0c1269ed 100644
--- a/Application/Main.cs
+++ b/Application/Main.cs
@@ -22,8 +22,6 @@ namespace IW4MAdmin.Application
public static void Main(string[] args)
{
- AppDomain.CurrentDomain.SetData("DataDirectory", Utilities.OperatingDirectory);
-
Console.OutputEncoding = Encoding.UTF8;
Console.ForegroundColor = ConsoleColor.Gray;
diff --git a/SharedLibraryCore/Configuration/ServerConfiguration.cs b/SharedLibraryCore/Configuration/ServerConfiguration.cs
index 91134bdbc..302c867fb 100644
--- a/SharedLibraryCore/Configuration/ServerConfiguration.cs
+++ b/SharedLibraryCore/Configuration/ServerConfiguration.cs
@@ -47,7 +47,7 @@ namespace SharedLibraryCore.Configuration
if (UseIW5MParser)
ManualLogPath = Utilities.PromptString(loc["SETUP_SERVER_MANUALLOG"]);
- ReservedSlotNumber = loc["SETUP_SERVER_RESERVEDSLOT"].PromptInt(0, 32);
+ ReservedSlotNumber = loc["SETUP_SERVER_RESERVEDSLOT"].PromptInt(null, 0, 32);
return this;
}
diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs
index 7cfcfc85e..a7d82dde7 100644
--- a/SharedLibraryCore/Services/ClientService.cs
+++ b/SharedLibraryCore/Services/ClientService.cs
@@ -131,7 +131,9 @@ namespace SharedLibraryCore.Services
LinkId = aliasLink.AliasLinkId,
Name = name
};
+ context.Aliases.Add(entity.CurrentAlias);
entity.AliasLink.Children.Add(entity.CurrentAlias);
+
await context.SaveChangesAsync();
}
@@ -149,6 +151,7 @@ namespace SharedLibraryCore.Services
};
entity.AliasLink.Active = true;
+ context.Aliases.Add(entity.CurrentAlias);
entity.AliasLink.Children.Add(entity.CurrentAlias);
await context.SaveChangesAsync();
diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs
index 2fd465cf0..651ec1048 100644
--- a/SharedLibraryCore/Utilities.cs
+++ b/SharedLibraryCore/Utilities.cs
@@ -1,6 +1,8 @@
-using Microsoft.EntityFrameworkCore.Query;
+#if DEBUG
+using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Storage;
+#endif
using SharedLibraryCore.Database.Models;
using System;
using System.Collections.Generic;
@@ -281,9 +283,10 @@ namespace SharedLibraryCore
public static int? ConvertToIP(this string str)
{
- return System.Net.IPAddress.TryParse(str, out System.Net.IPAddress ip) ?
- BitConverter.ToInt32(ip.GetAddressBytes(), 0) :
- new int?();
+ bool success = System.Net.IPAddress.TryParse(str, out System.Net.IPAddress ip);
+ return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 ?
+ (int?)BitConverter.ToInt32(ip.GetAddressBytes(), 0) :
+ null;
}
public static string ConvertIPtoString(this int? ip)
@@ -470,10 +473,17 @@ namespace SharedLibraryCore
return p.Level > EFClient.Permission.User;
}
- public static bool PromptBool(string question)
+ ///
+ /// prompt user to answer a yes/no question
+ ///
+ /// question to prompt the user with
+ /// description of the question's value
+ /// default value to set if no input is entered
+ ///
+ public static bool PromptBool(string question, string description = null, char? defaultValue = 'y')
{
- Console.Write($"{question}? [y/n]: ");
- return (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
+ Console.Write($"{question}?{(string.IsNullOrEmpty(description) ? "" : $" ({description}) ")}[y/n]: ");
+ return (Console.ReadLine().ToLower().FirstOrDefault() as char? ?? defaultValue) == 'y';
}
///
@@ -482,13 +492,21 @@ namespace SharedLibraryCore
/// question to prompt with
/// maximum value to allow
/// minimum value to allow
+ /// default value to set the return value to
+ /// a description of the question's value
/// integer from user's input
- public static int PromptInt(this string question, int minValue = 0, int maxValue = int.MaxValue)
+ public static int PromptInt(this string question, string description = null, int minValue = 0, int maxValue = int.MaxValue, int? defaultValue = null)
{
- Console.Write($"{question}: ");
+ Console.Write($"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue.Value.ToString()}")}]: ");
int response;
- while (!int.TryParse(Console.ReadLine(), out response) ||
+ string inputOrDefault()
+ {
+ string input = Console.ReadLine();
+ return string.IsNullOrEmpty(input) && defaultValue != null ? defaultValue.ToString() : input;
+ }
+
+ while (!int.TryParse(inputOrDefault(), out response) ||
response < minValue ||
response > maxValue)
{
@@ -497,19 +515,32 @@ namespace SharedLibraryCore
{
range = $" [{minValue}-{maxValue}]";
}
- Console.Write($"Please enter a valid number{range}: ");
+ Console.Write($"{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_INT"]}{range}: ");
}
return response;
}
- public static string PromptString(string question)
+ ///
+ /// prompt use to enter a string response
+ ///
+ /// question to prompt with
+ /// description of the question's value
+ /// default value to set the return value to
+ ///
+ public static string PromptString(string question, string description = null, string defaultValue = null)
{
+ string inputOrDefault()
+ {
+ string input = Console.ReadLine();
+ return string.IsNullOrEmpty(input) && defaultValue != null ? defaultValue.ToString() : input;
+ }
+
string response;
do
{
- Console.Write($"{question}: ");
- response = Console.ReadLine();
+ Console.Write($"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue}]")}: ");
+ response = inputOrDefault();
} while (string.IsNullOrWhiteSpace(response));
return response;