Login exception handling (JSON deserialize)
This commit is contained in:
parent
734f35d611
commit
16ae7fd2b6
@ -12,7 +12,7 @@ namespace DiIiS_NA.REST.JSON
|
||||
{
|
||||
public class Json
|
||||
{
|
||||
private static readonly Logger _logger = LogManager.CreateLogger(nameof(Json));
|
||||
private static readonly Logger Logger = LogManager.CreateLogger(nameof(Json));
|
||||
public static string CreateString<T>(T dataObject)
|
||||
{
|
||||
return Encoding.UTF8.GetString(CreateArray(dataObject));
|
||||
@ -37,15 +37,23 @@ namespace DiIiS_NA.REST.JSON
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.FatalException(ex, "Could not deserialize JSON data");
|
||||
return default(T);
|
||||
Logger.FatalException(ex, "Could not deserialize JSON data");
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public static T CreateObject<T>(string jsonData, bool split = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
return CreateObject<T>(Encoding.UTF8.GetBytes(split ? jsonData.Split(new[] { ':' }, 2)[1] : jsonData));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.FatalException(ex, "Could not deserialize JSON data");
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public static T CreateObject<T>(byte[] jsonData) => CreateObject<T>(new MemoryStream(jsonData));
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ using System.IO;
|
||||
using System.Net.Security;
|
||||
using System.Web;
|
||||
using DiIiS_NA.GameServer.MessageSystem;
|
||||
using DiIiS_NA.REST.Data.Forms;
|
||||
|
||||
namespace DiIiS_NA.REST
|
||||
{
|
||||
@ -110,7 +111,7 @@ namespace DiIiS_NA.REST
|
||||
{
|
||||
LogonData loginForm = Json.CreateObject<LogonData>(request.Content);
|
||||
LogonResult loginResult = new LogonResult();
|
||||
if (loginForm == default(LogonData))
|
||||
if (loginForm?.Inputs is null or {Count: 0})
|
||||
{
|
||||
loginResult.AuthenticationState = "LOGIN";
|
||||
loginResult.ErrorCode = "UNABLE_TO_DECODE";
|
||||
@ -122,15 +123,15 @@ namespace DiIiS_NA.REST
|
||||
string login = "";
|
||||
string password = "";
|
||||
|
||||
for (int i = 0; i < loginForm.Inputs.Count; ++i)
|
||||
foreach (var input in loginForm.Inputs)
|
||||
{
|
||||
switch (loginForm.Inputs[i].Id)
|
||||
switch (input.Id)
|
||||
{
|
||||
case "account_name":
|
||||
login = loginForm.Inputs[i].Value;
|
||||
login = input.Value;
|
||||
break;
|
||||
case "password":
|
||||
password = loginForm.Inputs[i].Value;
|
||||
password = input.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
user.block.title