Clean up non-game things

This commit is contained in:
Crypto137 2024-02-25 05:47:07 +03:00
parent 502acb4b54
commit d548ec9dee
12 changed files with 34 additions and 84 deletions

View file

@ -7,33 +7,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MHServerEmu", "src\MHServer
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibGazillion", "src\LibGazillion\LibGazillion.csproj", "{7D085437-F307-49D6-AF7A-C3B3DF4E4189}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8BA4E9E9-EB5F-4B6A-B9AB-7782E88B9598}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F7898A66-82D6-45C2-A20A-E4C390567C39}.Debug|Any CPU.ActiveCfg = Debug|x64
{F7898A66-82D6-45C2-A20A-E4C390567C39}.Debug|Any CPU.Build.0 = Debug|x64
{F7898A66-82D6-45C2-A20A-E4C390567C39}.Debug|x64.ActiveCfg = Debug|x64
{F7898A66-82D6-45C2-A20A-E4C390567C39}.Debug|x64.Build.0 = Debug|x64
{F7898A66-82D6-45C2-A20A-E4C390567C39}.Release|Any CPU.ActiveCfg = Release|x64
{F7898A66-82D6-45C2-A20A-E4C390567C39}.Release|Any CPU.Build.0 = Release|x64
{F7898A66-82D6-45C2-A20A-E4C390567C39}.Release|x64.ActiveCfg = Release|x64
{F7898A66-82D6-45C2-A20A-E4C390567C39}.Release|x64.Build.0 = Release|x64
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Debug|Any CPU.ActiveCfg = Debug|x64
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Debug|Any CPU.Build.0 = Debug|x64
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Debug|x64.ActiveCfg = Debug|x64
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Debug|x64.Build.0 = Debug|x64
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Release|Any CPU.ActiveCfg = Release|x64
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Release|Any CPU.Build.0 = Release|x64
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Release|x64.ActiveCfg = Release|x64
{7D085437-F307-49D6-AF7A-C3B3DF4E4189}.Release|x64.Build.0 = Release|x64
EndGlobalSection

View file

@ -99,16 +99,9 @@ namespace MHServerEmu.Auth
HandleMessage(request, response);
return;
}
// For Unit Tests
if (requestIsFromGameClient && request.Url.LocalPath == "/")
{
HandleMessage(request, response);
return;
}
// Web API post requests
if (requestIsFromGameClient == false && ConfigManager.Auth.EnableWebApi)
if (requestIsFromGameClient == false && ConfigManager.Auth.EnableWebApi)
{
HandleWebApiRequest(request, response);
return;

View file

@ -44,21 +44,14 @@ namespace MHServerEmu.Common
aesAlgorithm.Key = key;
aesAlgorithm.GenerateIV();
iv = aesAlgorithm.IV;
ICryptoTransform encryptor = aesAlgorithm.CreateEncryptor();
byte[] encryptedData;
using (MemoryStream memoryStream = new())
using (CryptoStream cryptoStream = new(memoryStream, encryptor, CryptoStreamMode.Write))
{
using (CryptoStream cryptoStream = new(memoryStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(tokenToEncrypt, 0, tokenToEncrypt.Length);
}
encryptedData = memoryStream.ToArray();
cryptoStream.Write(tokenToEncrypt, 0, tokenToEncrypt.Length);
return memoryStream.ToArray();
}
return encryptedData;
}
}

View file

@ -87,7 +87,7 @@ namespace MHServerEmu.Common.Extensions
return BitConverter.ToUInt64(bytes);
}
#endregion
#region Misc

View file

@ -178,7 +178,6 @@
{
return (max < min ? max : GetDouble() * (max - min) + min);
}
}
// More info on MWC random: https://en.wikipedia.org/wiki/Multiply-with-carry_pseudorandom_number_generator

Binary file not shown.

View file

@ -79,14 +79,9 @@ namespace MHServerEmu.Frontend
public void AssignSession(ClientSession session)
{
if (Session == null)
{
Session = session;
}
else
{
Logger.Warn($"Failed to assign sessionId {session.Id} to a client: sessionId {Session.Id} is already assigned to this client");
}
}
public void SendMuxDisconnect(ushort muxId)
@ -107,20 +102,5 @@ namespace MHServerEmu.Frontend
packet.AddMessages(messages);
Connection.Send(packet);
}
public void SendPacketFromFile(string fileName)
{
string path = Path.Combine(FileHelper.DataDirectory, "Packets", fileName);
if (File.Exists(path))
{
Logger.Info($"Sending {fileName}");
Connection.Send(File.ReadAllBytes(path));
}
else
{
Logger.Warn($"{fileName} not found");
}
}
}
}

View file

@ -108,13 +108,13 @@ namespace MHServerEmu.PlayerManagement.Accounts
if (client == null) return "You can only invoke this command from the game.";
StringBuilder sb = new();
sb.Append($"Account Info:\n");
sb.Append($"Email: {client.Session.Account.Email}\n");
sb.Append($"PlayerName: {client.Session.Account.PlayerName}\n");
sb.Append($"UserLevel: {client.Session.Account.UserLevel}\n");
sb.Append($"IsBanned: {client.Session.Account.IsArchived}\n");
sb.Append($"IsArchived: {client.Session.Account.IsArchived}\n");
sb.Append($"IsPasswordExpired: {client.Session.Account.IsPasswordExpired}\n");
sb.AppendLine($"Account Info:");
sb.AppendLine($"Email: {client.Session.Account.Email}");
sb.AppendLine($"PlayerName: {client.Session.Account.PlayerName}");
sb.AppendLine($"UserLevel: {client.Session.Account.UserLevel}");
sb.AppendLine($"IsBanned: {client.Session.Account.IsArchived}");
sb.AppendLine($"IsArchived: {client.Session.Account.IsArchived}");
sb.Append($"IsPasswordExpired: {client.Session.Account.IsPasswordExpired}");
return sb.ToString();
}
}

View file

@ -6,6 +6,9 @@ using MHServerEmu.PlayerManagement.Accounts.DBModels;
namespace MHServerEmu.PlayerManagement.Accounts
{
/// <summary>
/// Provides access to the account database.
/// </summary>
public static class DBManager
{
private static readonly Logger Logger = LogManager.CreateLogger();
@ -29,11 +32,8 @@ namespace MHServerEmu.PlayerManagement.Accounts
#region Queries
/// <summary>
/// Queries an account from the database by its email.
/// Queries a <see cref="DBAccount"/> from the database by its email.
/// </summary>
/// <param name="email">Email to query.</param>
/// <param name="account">Account or null.</param>
/// <returns>IsSuccess</returns>
public static bool TryQueryAccountByEmail(string email, out DBAccount account)
{
using (SQLiteConnection connection = new(ConnectionString))
@ -57,8 +57,6 @@ namespace MHServerEmu.PlayerManagement.Accounts
/// <summary>
/// Queries if the specified player name is already taken.
/// </summary>
/// <param name="playerName">Name to check.</param>
/// <returns>IsTaken</returns>
public static bool QueryIsPlayerNameTaken(string playerName)
{
using (SQLiteConnection connection = new(ConnectionString))
@ -74,10 +72,8 @@ namespace MHServerEmu.PlayerManagement.Accounts
#region Executes
/// <summary>
/// Inserts a new account with all of its data into the database.
/// Inserts a new <see cref="DBAccount"/> with all of its data into the database.
/// </summary>
/// <param name="account">Account to insert.</param>
/// <returns>IsSuccess</returns>
public static bool InsertAccount(DBAccount account)
{
using (SQLiteConnection connection = new(ConnectionString))
@ -92,8 +88,8 @@ namespace MHServerEmu.PlayerManagement.Accounts
connection.Execute(@"INSERT INTO Account (Id, Email, PlayerName, PasswordHash, Salt, UserLevel, IsBanned, IsArchived, IsPasswordExpired)
VALUES (@Id, @Email, @PlayerName, @PasswordHash, @Salt, @UserLevel, @IsBanned, @IsArchived, @IsPasswordExpired)", account, transaction);
connection.Execute(@"INSERT INTO Player (AccountId, RawRegion, RawAvatar, RawWaypoint, RawAOIVolume)
VALUES (@AccountId, @RawRegion, @RawAvatar, @RawWaypoint, @RawAOIVolume)", account.Player, transaction);
connection.Execute(@"INSERT INTO Player (AccountId, RawRegion, RawAvatar, RawWaypoint, AOIVolume)
VALUES (@AccountId, @RawRegion, @RawAvatar, @RawWaypoint, @AOIVolume)", account.Player, transaction);
connection.Execute(@"INSERT INTO Avatar (AccountId, RawPrototype, RawCostume)
VALUES (@AccountId, @RawPrototype, @RawCostume)", account.Avatars, transaction);
@ -112,10 +108,8 @@ namespace MHServerEmu.PlayerManagement.Accounts
}
/// <summary>
/// Updates the Account table in the database with the provided account.
/// Updates the Account table in the database with the provided <see cref="DBAccount"/>.
/// </summary>
/// <param name="account">Account to update.</param>
/// <returns>IsSuccess</returns>
public static bool UpdateAccount(DBAccount account)
{
using (SQLiteConnection connection = new(ConnectionString))
@ -135,10 +129,8 @@ namespace MHServerEmu.PlayerManagement.Accounts
}
/// <summary>
/// Updates the Player and Avatar tables in the database with the data from the provided account.
/// Updates the Player and Avatar tables in the database with the data from the provided <see cref="DBAccount"/>.
/// </summary>
/// <param name="account"></param>
/// <returns>IsSuccess</returns>
public static bool UpdateAccountData(DBAccount account)
{
using (SQLiteConnection connection = new(ConnectionString))
@ -150,7 +142,7 @@ namespace MHServerEmu.PlayerManagement.Accounts
{
try
{
connection.Execute(@"UPDATE Player SET RawRegion=@RawRegion, RawAvatar=@RawAvatar, RawWaypoint=@RawWaypoint, RawAOIVolume=@RawAOIVolume WHERE AccountId=@AccountId", account.Player, transaction);
connection.Execute(@"UPDATE Player SET RawRegion=@RawRegion, RawAvatar=@RawAvatar, RawWaypoint=@RawWaypoint, AOIVolume=@AOIVolume WHERE AccountId=@AccountId", account.Player, transaction);
connection.Execute(@"UPDATE Avatar SET RawCostume=@RawCostume WHERE AccountId=@AccountId AND RawPrototype=@RawPrototype", account.Avatars, transaction);
transaction.Commit();
@ -186,10 +178,8 @@ namespace MHServerEmu.PlayerManagement.Accounts
#endregion
/// <summary>
/// Loads account data for the specified account and maps relations.
/// Loads account data for the specified <see cref="DBAccount"/> and maps relations.
/// </summary>
/// <param name="connection">Database connection for querying.</param>
/// <param name="account">Account to get data for.</param>
private static void LoadAccountData(SQLiteConnection connection, DBAccount account)
{
var @params = new { AccountId = account.Id };

View file

@ -5,6 +5,9 @@ using MHServerEmu.Games.Regions;
namespace MHServerEmu.PlayerManagement.Accounts.DBModels
{
/// <summary>
/// Represents an account stored in the account database.
/// </summary>
public class DBAccount
{
public ulong Id { get; set; }

View file

@ -2,6 +2,9 @@
namespace MHServerEmu.PlayerManagement.Accounts.DBModels
{
/// <summary>
/// Represents an avatar entity stored in the account database.
/// </summary>
public class DBAvatar
{
// We are currently using System.Data.SQLite + Dapper for storing our persistent data.

View file

@ -4,6 +4,9 @@ using MHServerEmu.Games.Regions;
namespace MHServerEmu.PlayerManagement.Accounts.DBModels
{
/// <summary>
/// Represents a player entity stored in the account database.
/// </summary>
public class DBPlayer
{
// We are currently using System.Data.SQLite + Dapper for storing our persistent data.
@ -24,8 +27,9 @@ namespace MHServerEmu.PlayerManagement.Accounts.DBModels
public long RawAvatar { get => (long)Avatar; private set => Avatar = (AvatarPrototypeId)value; }
public PrototypeId Waypoint { get; set; }
public long RawWaypoint { get => (long)Waypoint; private set => Waypoint = (PrototypeId)value; }
public int AOIVolume { get; set; }
public int RawAOIVolume { get => AOIVolume; private set => AOIVolume = value; }
public DBPlayer(ulong accountId)
{
AccountId = accountId;