diff --git a/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs b/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs index d75ee4a..92ce5a0 100644 --- a/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs +++ b/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs @@ -198,15 +198,24 @@ namespace DiIiS_NA.LoginServer.AccountsSystem { get { - bool staff = (DBAccount.UserLevel > UserLevels.Tester); + var bTag = DBAccount.BattleTagName; + //(controller as HandlerController).Client.Account.GameAccount.ProgramField.Value if(GameAccount.ProgramField.Value == "APP") - return string.Format("{0}", DBAccount.BattleTagName); - else if (GameAccount.ProgramField.Value == "D3") - //return string.Format("{0}", DBAccount.BattleTagName); - return string.Format(staff ? " {{icon:bnet}} {{c_legendary}}{0}{{/c}}" : ("{0}"), this.DBAccount.BattleTagName); - else - return string.Format("{0}", DBAccount.BattleTagName); + return bTag; + + if (GameAccount.ProgramField.Value == "D3") + { + return DBAccount.UserLevel switch + { + >= UserLevels.Owner => " {icon:bnet} {c_epic}" + bTag + "{/c}", + >= UserLevels.GM => " {icon:bnet} {c_legendary}" + bTag + "{/c}", + >= UserLevels.Tester => " {icon:bnet} {c_rare}" + bTag + "{/c}", + _ => " {icon:bnet} " + bTag + }; + } + + return bTag; //return (staff ? " {icon:bnet} " : (premium ? " {icon:gold} " : "")) + dbAcc.BattleTagName; } //{c_blue}{/c} private set diff --git a/src/DiIiS-NA/BGS-Server/AccountsSystem/AccountManager.cs b/src/DiIiS-NA/BGS-Server/AccountsSystem/AccountManager.cs index c809ee9..8776041 100644 --- a/src/DiIiS-NA/BGS-Server/AccountsSystem/AccountManager.cs +++ b/src/DiIiS-NA/BGS-Server/AccountsSystem/AccountManager.cs @@ -11,6 +11,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Spectre.Console; +using System.Text.RegularExpressions; namespace DiIiS_NA.LoginServer.AccountsSystem { @@ -18,10 +20,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem { private static readonly Logger Logger = LogManager.CreateLogger("DataBaseSystem"); - public static int TotalAccounts - { - get { return DBSessions.SessionQuery().Count(); } - } + public static int TotalAccounts => DBSessions.SessionQuery().Count(); public static readonly ConcurrentDictionary LoadedAccounts = new ConcurrentDictionary(); @@ -67,7 +66,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem { try { - if (DBSessions.SessionQueryWhere(dba => dba.DiscordId == discordId).Count() > 0) + if (DBSessions.SessionQueryWhere(dba => dba.DiscordId == discordId).Any()) return false; var account = GetAccountByEmail(email); @@ -131,18 +130,18 @@ namespace DiIiS_NA.LoginServer.AccountsSystem else { List dbAcc = DBSessions.SessionQueryWhere(dba => dba.Email == email); - if (dbAcc.Count() == 0) + if (dbAcc.Count == 0) { - Logger.Warn("GetAccountByEmail {0}: DBAccount is null!", email); + Logger.Warn($"$[olive]$GetAccountByEmail(\"{email}\")$[/]$: DBAccount is null!"); return null; } if (dbAcc.First() == null) { - Logger.Warn("GetAccountByEmail {0}: DBAccount id is null!", email); + Logger.Warn($"$[olive]$GetAccountByEmail(\"{email}\")$[/]$: DBAccount id is not null!"); return null; } else - Logger.MethodTrace("GetAccountByEmail id - \"{0}\"", dbAcc.First().Id); + Logger.MethodTrace($"$[olive]$GetAccountByEmail(\"{email}\")$[/]$: id - {dbAcc.First().Id}"); return GetAccountByDBAccount(dbAcc.First()); } } @@ -152,18 +151,22 @@ namespace DiIiS_NA.LoginServer.AccountsSystem string[] tagparts = battletag.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); int taghash = Convert.ToInt32(tagparts[1], 10); - if (tagparts[0].StartsWith(" {icon")) - tagparts[0] = tagparts[0].Substring(13); - //Logger.Debug("trying GetAccountByBattletag {0}", battletag); - if (tagparts[0].StartsWith("{c_legendary")) - { - tagparts[0] = tagparts[0].Substring(13); - tagparts[0] = tagparts[0].Split('{')[0]; - } + // remove everything inside the brackets and empty spaces in tagparts[0] using regex + tagparts[0] = Regex.Replace(tagparts[0], @"\s*?{[^}]+}\s*?", string.Empty).Trim(); + tagparts[0] = Regex.Replace(tagparts[0], @"\s*?", string.Empty).Trim(); + + // if (tagparts[0].StartsWith(" {icon")) + // tagparts[0] = tagparts[0].Substring(13); + // //Logger.Debug("trying GetAccountByBattletag {0}", battletag); + // if (tagparts[0].StartsWith("{c_legendary")) + // { + // tagparts[0] = tagparts[0].Substring(13); + // tagparts[0] = tagparts[0].Split('{')[0]; + // } List dbAcc = DBSessions.SessionQueryWhere(dba => dba.BattleTagName == tagparts[0] && dba.HashCode == taghash); - if (dbAcc.Count() == 0) + if (dbAcc.Count == 0) { - Logger.Warn("GetAccountByBattletag {0}: DBAccount is null!", battletag); + Logger.Warn($"$[olive]$GetAccountByBattleTag(\"{battletag})$[/]$ DBAccount is null!"); return null; } //else @@ -174,9 +177,9 @@ namespace DiIiS_NA.LoginServer.AccountsSystem public static Account GetAccountByName(string btname) //pretty bad to use it { List dbAcc = DBSessions.SessionQueryWhere(dba => dba.BattleTagName == btname); - if (dbAcc.Count() == 0) + if (dbAcc.Count == 0) { - Logger.Warn("GetAccountByName {0}: DBAccount is null!", btname); + Logger.Warn("$[olive]$GetAccountByName(\"{0}\")$[/]$: DBAccount is null!", btname); return null; } return GetAccountByDBAccount(dbAcc.First()); @@ -267,7 +270,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem public static Account GetAccountBySaltTicket(string ticket) { - if (DBSessions.SessionQueryWhere(dba => dba.SaltedTicket == ticket).Count() > 0) + if (DBSessions.SessionQueryWhere(dba => dba.SaltedTicket == ticket).Any()) return LoadedAccounts[LoadedAccounts.Single(a => a.Value.SaltedTicket == ticket).Key]; return null; } diff --git a/src/DiIiS-NA/Core/Logging/AnsiTarget.cs b/src/DiIiS-NA/Core/Logging/AnsiTarget.cs index b4866c8..e582a3a 100644 --- a/src/DiIiS-NA/Core/Logging/AnsiTarget.cs +++ b/src/DiIiS-NA/Core/Logging/AnsiTarget.cs @@ -61,10 +61,12 @@ public class AnsiTarget : LogTarget public static string Filter(string text) { return text - .Replace("Blizzless", "[dodgerblue1]Blizz[/][deepskyblue2]less[/]") - .Replace("Diablo III", "[red3_1]Diablo[/] [red]III[/]") + .Replace("Blizzless", "[dodgerblue1]Blizz[/][deepskyblue2]less[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("Diablo III", "[red3_1]Diablo[/] [red]III[/]", StringComparison.CurrentCultureIgnoreCase) .Replace("MPQ", "[underline yellow4]MPQ[/]") - .Replace("Discord", "[blue]Discord[/]"); + .Replace("Discord", "[blue]Discord[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("not null", "[green]is not null[/]", StringComparison.CurrentCultureIgnoreCase) + .Replace("null", "[red]is null[/]", StringComparison.CurrentCultureIgnoreCase); } diff --git a/src/DiIiS-NA/REST/JSON/Json.cs b/src/DiIiS-NA/REST/JSON/Json.cs index c871651..90ac3b8 100644 --- a/src/DiIiS-NA/REST/JSON/Json.cs +++ b/src/DiIiS-NA/REST/JSON/Json.cs @@ -5,12 +5,14 @@ using System.Runtime.Serialization.Json; using System.Linq; using System.Text; using System.Threading.Tasks; +using DiIiS_NA.Core.Logging; using DiIiS_NA.REST.Extensions; namespace DiIiS_NA.REST.JSON { public class Json { + private static readonly Logger _logger = LogManager.CreateLogger(nameof(Json)); public static string CreateString(T dataObject) { return Encoding.UTF8.GetString(CreateArray(dataObject)); @@ -28,9 +30,16 @@ namespace DiIiS_NA.REST.JSON public static T CreateObject(Stream jsonData) { - var serializer = new DataContractJsonSerializer(typeof(T)); - - return (T)serializer.ReadObject(jsonData); + try + { + var serializer = new DataContractJsonSerializer(typeof(T)); + return (T)serializer.ReadObject(jsonData); + } + catch (Exception ex) + { + _logger.FatalException(ex, "Could not deserialize JSON data"); + return default(T); + } } public static T CreateObject(string jsonData, bool split = false) diff --git a/src/DiIiS-NA/REST/RestSession.cs b/src/DiIiS-NA/REST/RestSession.cs index e0f5c40..33169b0 100644 --- a/src/DiIiS-NA/REST/RestSession.cs +++ b/src/DiIiS-NA/REST/RestSession.cs @@ -38,21 +38,12 @@ namespace DiIiS_NA.REST } else { + Logger.Info($"$[yellow]$REST Request: $[/]$ {httpRequest.Method} {httpRequest.Path}"); if (httpRequest.Path == "200") { } - else if (httpRequest.Path == "/client/alert?targetRegion=ruRU") - { - switch (httpRequest.Method) - { - case "GET": - default: - HandleInfoRequest(httpRequest); - break; - } - } - else if (httpRequest.Path == "/D3/ruRU/client/alert?targetRegion=127") + else if (httpRequest.Path.Contains("/client/alert")) { switch (httpRequest.Method) { @@ -117,7 +108,7 @@ namespace DiIiS_NA.REST { LogonData loginForm = Json.CreateObject(request.Content); LogonResult loginResult = new LogonResult(); - if (loginForm == null) + if (loginForm == default(LogonData)) { loginResult.AuthenticationState = "LOGIN"; loginResult.ErrorCode = "UNABLE_TO_DECODE";