Staff custom battle tag name;
Prevented unhandled exception by Json.cs; Some REST changes, AnsiTarget.cs, etc.
This commit is contained in:
parent
2bd03c532b
commit
f4938cf72a
@ -198,15 +198,24 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
bool staff = (DBAccount.UserLevel > UserLevels.Tester);
|
var bTag = DBAccount.BattleTagName;
|
||||||
|
|
||||||
//(controller as HandlerController).Client.Account.GameAccount.ProgramField.Value
|
//(controller as HandlerController).Client.Account.GameAccount.ProgramField.Value
|
||||||
if(GameAccount.ProgramField.Value == "APP")
|
if(GameAccount.ProgramField.Value == "APP")
|
||||||
return string.Format("{0}", DBAccount.BattleTagName);
|
return bTag;
|
||||||
else if (GameAccount.ProgramField.Value == "D3")
|
|
||||||
//return string.Format("{0}", DBAccount.BattleTagName);
|
if (GameAccount.ProgramField.Value == "D3")
|
||||||
return string.Format(staff ? " {{icon:bnet}} {{c_legendary}}{0}{{/c}}" : ("{0}"), this.DBAccount.BattleTagName);
|
{
|
||||||
else
|
return DBAccount.UserLevel switch
|
||||||
return string.Format("{0}", DBAccount.BattleTagName);
|
{
|
||||||
|
>= 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;
|
//return (staff ? " {icon:bnet} " : (premium ? " {icon:gold} " : "")) + dbAcc.BattleTagName;
|
||||||
} //{c_blue}{/c}
|
} //{c_blue}{/c}
|
||||||
private set
|
private set
|
||||||
|
|||||||
@ -11,6 +11,8 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Spectre.Console;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace DiIiS_NA.LoginServer.AccountsSystem
|
namespace DiIiS_NA.LoginServer.AccountsSystem
|
||||||
{
|
{
|
||||||
@ -18,10 +20,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
|
|||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.CreateLogger("DataBaseSystem");
|
private static readonly Logger Logger = LogManager.CreateLogger("DataBaseSystem");
|
||||||
|
|
||||||
public static int TotalAccounts
|
public static int TotalAccounts => DBSessions.SessionQuery<DBAccount>().Count();
|
||||||
{
|
|
||||||
get { return DBSessions.SessionQuery<DBAccount>().Count(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly ConcurrentDictionary<ulong, Account> LoadedAccounts = new ConcurrentDictionary<ulong, Account>();
|
public static readonly ConcurrentDictionary<ulong, Account> LoadedAccounts = new ConcurrentDictionary<ulong, Account>();
|
||||||
|
|
||||||
@ -67,7 +66,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (DBSessions.SessionQueryWhere<DBAccount>(dba => dba.DiscordId == discordId).Count() > 0)
|
if (DBSessions.SessionQueryWhere<DBAccount>(dba => dba.DiscordId == discordId).Any())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var account = GetAccountByEmail(email);
|
var account = GetAccountByEmail(email);
|
||||||
@ -131,18 +130,18 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<DBAccount> dbAcc = DBSessions.SessionQueryWhere<DBAccount>(dba => dba.Email == email);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
if (dbAcc.First() == 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;
|
return null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Logger.MethodTrace("GetAccountByEmail id - \"{0}\"", dbAcc.First().Id);
|
Logger.MethodTrace($"$[olive]$GetAccountByEmail(\"{email}\")$[/]$: id - {dbAcc.First().Id}");
|
||||||
return GetAccountByDBAccount(dbAcc.First());
|
return GetAccountByDBAccount(dbAcc.First());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,18 +151,22 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
|
|||||||
string[] tagparts = battletag.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
|
string[] tagparts = battletag.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
int taghash = Convert.ToInt32(tagparts[1], 10);
|
int taghash = Convert.ToInt32(tagparts[1], 10);
|
||||||
|
|
||||||
if (tagparts[0].StartsWith(" {icon"))
|
// remove everything inside the brackets and empty spaces in tagparts[0] using regex
|
||||||
tagparts[0] = tagparts[0].Substring(13);
|
tagparts[0] = Regex.Replace(tagparts[0], @"\s*?{[^}]+}\s*?", string.Empty).Trim();
|
||||||
//Logger.Debug("trying GetAccountByBattletag {0}", battletag);
|
tagparts[0] = Regex.Replace(tagparts[0], @"\s*?", string.Empty).Trim();
|
||||||
if (tagparts[0].StartsWith("{c_legendary"))
|
|
||||||
{
|
// if (tagparts[0].StartsWith(" {icon"))
|
||||||
tagparts[0] = tagparts[0].Substring(13);
|
// tagparts[0] = tagparts[0].Substring(13);
|
||||||
tagparts[0] = tagparts[0].Split('{')[0];
|
// //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);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
//else
|
//else
|
||||||
@ -174,9 +177,9 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
|
|||||||
public static Account GetAccountByName(string btname) //pretty bad to use it
|
public static Account GetAccountByName(string btname) //pretty bad to use it
|
||||||
{
|
{
|
||||||
List<DBAccount> dbAcc = DBSessions.SessionQueryWhere<DBAccount>(dba => dba.BattleTagName == btname);
|
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 null;
|
||||||
}
|
}
|
||||||
return GetAccountByDBAccount(dbAcc.First());
|
return GetAccountByDBAccount(dbAcc.First());
|
||||||
@ -267,7 +270,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
|
|||||||
|
|
||||||
public static Account GetAccountBySaltTicket(string ticket)
|
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 LoadedAccounts[LoadedAccounts.Single(a => a.Value.SaltedTicket == ticket).Key];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,10 +61,12 @@ public class AnsiTarget : LogTarget
|
|||||||
public static string Filter(string text)
|
public static string Filter(string text)
|
||||||
{
|
{
|
||||||
return text
|
return text
|
||||||
.Replace("Blizzless", "[dodgerblue1]Blizz[/][deepskyblue2]less[/]")
|
.Replace("Blizzless", "[dodgerblue1]Blizz[/][deepskyblue2]less[/]", StringComparison.CurrentCultureIgnoreCase)
|
||||||
.Replace("Diablo III", "[red3_1]Diablo[/] [red]III[/]")
|
.Replace("Diablo III", "[red3_1]Diablo[/] [red]III[/]", StringComparison.CurrentCultureIgnoreCase)
|
||||||
.Replace("MPQ", "[underline yellow4]MPQ[/]")
|
.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,12 +5,14 @@ using System.Runtime.Serialization.Json;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DiIiS_NA.Core.Logging;
|
||||||
using DiIiS_NA.REST.Extensions;
|
using DiIiS_NA.REST.Extensions;
|
||||||
|
|
||||||
namespace DiIiS_NA.REST.JSON
|
namespace DiIiS_NA.REST.JSON
|
||||||
{
|
{
|
||||||
public class Json
|
public class Json
|
||||||
{
|
{
|
||||||
|
private static readonly Logger _logger = LogManager.CreateLogger(nameof(Json));
|
||||||
public static string CreateString<T>(T dataObject)
|
public static string CreateString<T>(T dataObject)
|
||||||
{
|
{
|
||||||
return Encoding.UTF8.GetString(CreateArray(dataObject));
|
return Encoding.UTF8.GetString(CreateArray(dataObject));
|
||||||
@ -27,11 +29,18 @@ namespace DiIiS_NA.REST.JSON
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static T CreateObject<T>(Stream jsonData)
|
public static T CreateObject<T>(Stream jsonData)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var serializer = new DataContractJsonSerializer(typeof(T));
|
var serializer = new DataContractJsonSerializer(typeof(T));
|
||||||
|
|
||||||
return (T)serializer.ReadObject(jsonData);
|
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)
|
public static T CreateObject<T>(string jsonData, bool split = false)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -38,21 +38,12 @@ namespace DiIiS_NA.REST
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Logger.Info($"$[yellow]$REST Request: $[/]$ {httpRequest.Method} {httpRequest.Path}");
|
||||||
if (httpRequest.Path == "200")
|
if (httpRequest.Path == "200")
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (httpRequest.Path == "/client/alert?targetRegion=ruRU")
|
else if (httpRequest.Path.Contains("/client/alert"))
|
||||||
{
|
|
||||||
switch (httpRequest.Method)
|
|
||||||
{
|
|
||||||
case "GET":
|
|
||||||
default:
|
|
||||||
HandleInfoRequest(httpRequest);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (httpRequest.Path == "/D3/ruRU/client/alert?targetRegion=127")
|
|
||||||
{
|
{
|
||||||
switch (httpRequest.Method)
|
switch (httpRequest.Method)
|
||||||
{
|
{
|
||||||
@ -117,7 +108,7 @@ namespace DiIiS_NA.REST
|
|||||||
{
|
{
|
||||||
LogonData loginForm = Json.CreateObject<LogonData>(request.Content);
|
LogonData loginForm = Json.CreateObject<LogonData>(request.Content);
|
||||||
LogonResult loginResult = new LogonResult();
|
LogonResult loginResult = new LogonResult();
|
||||||
if (loginForm == null)
|
if (loginForm == default(LogonData))
|
||||||
{
|
{
|
||||||
loginResult.AuthenticationState = "LOGIN";
|
loginResult.AuthenticationState = "LOGIN";
|
||||||
loginResult.ErrorCode = "UNABLE_TO_DECODE";
|
loginResult.ErrorCode = "UNABLE_TO_DECODE";
|
||||||
|
|||||||
Loading…
Reference in New Issue
user.block.title