Staff custom battle tag name;

Prevented unhandled exception by Json.cs;
Some REST changes, AnsiTarget.cs, etc.
This commit is contained in:
Lucca Faria Ferri 2023-01-27 22:44:04 -08:00
parent 2bd03c532b
commit f4938cf72a
5 changed files with 61 additions and 47 deletions

View File

@ -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

View File

@ -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<DBAccount>().Count(); }
}
public static int TotalAccounts => DBSessions.SessionQuery<DBAccount>().Count();
public static readonly ConcurrentDictionary<ulong, Account> LoadedAccounts = new ConcurrentDictionary<ulong, Account>();
@ -67,7 +66,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
{
try
{
if (DBSessions.SessionQueryWhere<DBAccount>(dba => dba.DiscordId == discordId).Count() > 0)
if (DBSessions.SessionQueryWhere<DBAccount>(dba => dba.DiscordId == discordId).Any())
return false;
var account = GetAccountByEmail(email);
@ -131,18 +130,18 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
else
{
List<DBAccount> dbAcc = DBSessions.SessionQueryWhere<DBAccount>(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<DBAccount> dbAcc = DBSessions.SessionQueryWhere<DBAccount>(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<DBAccount> dbAcc = DBSessions.SessionQueryWhere<DBAccount>(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<DBAccount>(dba => dba.SaltedTicket == ticket).Count() > 0)
if (DBSessions.SessionQueryWhere<DBAccount>(dba => dba.SaltedTicket == ticket).Any())
return LoadedAccounts[LoadedAccounts.Single(a => a.Value.SaltedTicket == ticket).Key];
return null;
}

View File

@ -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);
}

View File

@ -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>(T dataObject)
{
return Encoding.UTF8.GetString(CreateArray(dataObject));
@ -28,9 +30,16 @@ namespace DiIiS_NA.REST.JSON
public static T CreateObject<T>(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<T>(string jsonData, bool split = false)

View File

@ -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<LogonData>(request.Content);
LogonResult loginResult = new LogonResult();
if (loginForm == null)
if (loginForm == default(LogonData))
{
loginResult.AuthenticationState = "LOGIN";
loginResult.ErrorCode = "UNABLE_TO_DECODE";