From d548ec9dee0bbcd748ecb6f6ef0d547310bce081 Mon Sep 17 00:00:00 2001 From: Crypto137 Date: Sun, 25 Feb 2024 05:47:07 +0300 Subject: [PATCH] Clean up non-game things --- MHServerEmu.sln | 15 -------- src/MHServerEmu/Auth/AuthServer.cs | 9 +---- src/MHServerEmu/Common/Cryptography.cs | 13 ++----- .../Common/Extensions/ArrayExtensions.cs | 2 +- src/MHServerEmu/Common/GRandom.cs | 1 - src/MHServerEmu/Data/Account.db | Bin 77824 -> 77824 bytes src/MHServerEmu/Frontend/FrontendClient.cs | 20 ----------- .../Accounts/AccountCommands.cs | 14 ++++---- .../PlayerManagement/Accounts/DBManager.cs | 32 ++++++------------ .../Accounts/DBModels/DBAccount.cs | 3 ++ .../Accounts/DBModels/DBAvatar.cs | 3 ++ .../Accounts/DBModels/DBPlayer.cs | 6 +++- 12 files changed, 34 insertions(+), 84 deletions(-) diff --git a/MHServerEmu.sln b/MHServerEmu.sln index 0c0d0bb4..3df9624a 100644 --- a/MHServerEmu.sln +++ b/MHServerEmu.sln @@ -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 diff --git a/src/MHServerEmu/Auth/AuthServer.cs b/src/MHServerEmu/Auth/AuthServer.cs index 1075afcf..97b06553 100644 --- a/src/MHServerEmu/Auth/AuthServer.cs +++ b/src/MHServerEmu/Auth/AuthServer.cs @@ -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; diff --git a/src/MHServerEmu/Common/Cryptography.cs b/src/MHServerEmu/Common/Cryptography.cs index 68d9c764..107dd3c2 100644 --- a/src/MHServerEmu/Common/Cryptography.cs +++ b/src/MHServerEmu/Common/Cryptography.cs @@ -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; } } diff --git a/src/MHServerEmu/Common/Extensions/ArrayExtensions.cs b/src/MHServerEmu/Common/Extensions/ArrayExtensions.cs index dc51a7fd..f86b871a 100644 --- a/src/MHServerEmu/Common/Extensions/ArrayExtensions.cs +++ b/src/MHServerEmu/Common/Extensions/ArrayExtensions.cs @@ -87,7 +87,7 @@ namespace MHServerEmu.Common.Extensions return BitConverter.ToUInt64(bytes); } - + #endregion #region Misc diff --git a/src/MHServerEmu/Common/GRandom.cs b/src/MHServerEmu/Common/GRandom.cs index 32017097..461329ff 100644 --- a/src/MHServerEmu/Common/GRandom.cs +++ b/src/MHServerEmu/Common/GRandom.cs @@ -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 diff --git a/src/MHServerEmu/Data/Account.db b/src/MHServerEmu/Data/Account.db index 8977160367cd22f9f3abf9d5dd015e349e749ca4..2fa5383e366eba44887d720840b5c577b72faddf 100644 GIT binary patch delta 277 zcmZp8z|!!5WrDPzCj$e6Fc5P9F&hvUPt-A1^kmTUujS>L!ob1h!ouaklgeYp!_KpZ z`xf6z?zMc&_?B&K=;09MUdw19uCLG7B3S}t>VlcflMisHPrlCE!l<3dl`c^Z{y)$WMb5ve1P{En`1DWc&Ps52iy{q5AmsRvo?tYv5QMe zGPW>J{>V3(nTu0t@>$Muc3z;<7z7wLvkUy?=VRs9W8lBWzlOhwKZ0Lxv!a3wKbJzo zfu4&O)}L!&o%}#vVX~h*=j5&O-XNNh2`Zws$$&**GfTi9{z(BWn^_$G@NY^G7hnbX LnrX94!IS*}^KMMc delta 447 zcmZp8z|!!5WrDPz2Ll6xFc5P9F&hx)Pt-A1^kC4-y1>gbg@J=pi-pUDCzZ#Hhn;5+ z_bpB>?zMbN_?B#J=;5$p7uVNkY>_W%(hYzxIZG0ga#D*6bCTjqQk%qqqLPw~EfCRw zoW#o1A_&Pe*^{${IViDw^I6V^jEsSk*K=zzvuXPRX_?7Cxc4#!Y~IGh!N|nqGWh`S zGZr@SQ2ogdxFseZ;ZxxTx{*;5Y%crcW4x336qJDGIQn~r<>!> + /// Provides access to the account database. + /// public static class DBManager { private static readonly Logger Logger = LogManager.CreateLogger(); @@ -29,11 +32,8 @@ namespace MHServerEmu.PlayerManagement.Accounts #region Queries /// - /// Queries an account from the database by its email. + /// Queries a from the database by its email. /// - /// Email to query. - /// Account or null. - /// IsSuccess public static bool TryQueryAccountByEmail(string email, out DBAccount account) { using (SQLiteConnection connection = new(ConnectionString)) @@ -57,8 +57,6 @@ namespace MHServerEmu.PlayerManagement.Accounts /// /// Queries if the specified player name is already taken. /// - /// Name to check. - /// IsTaken public static bool QueryIsPlayerNameTaken(string playerName) { using (SQLiteConnection connection = new(ConnectionString)) @@ -74,10 +72,8 @@ namespace MHServerEmu.PlayerManagement.Accounts #region Executes /// - /// Inserts a new account with all of its data into the database. + /// Inserts a new with all of its data into the database. /// - /// Account to insert. - /// IsSuccess 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 } /// - /// Updates the Account table in the database with the provided account. + /// Updates the Account table in the database with the provided . /// - /// Account to update. - /// IsSuccess public static bool UpdateAccount(DBAccount account) { using (SQLiteConnection connection = new(ConnectionString)) @@ -135,10 +129,8 @@ namespace MHServerEmu.PlayerManagement.Accounts } /// - /// 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 . /// - /// - /// IsSuccess 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 /// - /// Loads account data for the specified account and maps relations. + /// Loads account data for the specified and maps relations. /// - /// Database connection for querying. - /// Account to get data for. private static void LoadAccountData(SQLiteConnection connection, DBAccount account) { var @params = new { AccountId = account.Id }; diff --git a/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBAccount.cs b/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBAccount.cs index 9bdb1b4a..fc727ab6 100644 --- a/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBAccount.cs +++ b/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBAccount.cs @@ -5,6 +5,9 @@ using MHServerEmu.Games.Regions; namespace MHServerEmu.PlayerManagement.Accounts.DBModels { + /// + /// Represents an account stored in the account database. + /// public class DBAccount { public ulong Id { get; set; } diff --git a/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBAvatar.cs b/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBAvatar.cs index 4cbaea04..974542c5 100644 --- a/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBAvatar.cs +++ b/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBAvatar.cs @@ -2,6 +2,9 @@ namespace MHServerEmu.PlayerManagement.Accounts.DBModels { + /// + /// Represents an avatar entity stored in the account database. + /// public class DBAvatar { // We are currently using System.Data.SQLite + Dapper for storing our persistent data. diff --git a/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBPlayer.cs b/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBPlayer.cs index e68ad9e3..2d16349b 100644 --- a/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBPlayer.cs +++ b/src/MHServerEmu/PlayerManagement/Accounts/DBModels/DBPlayer.cs @@ -4,6 +4,9 @@ using MHServerEmu.Games.Regions; namespace MHServerEmu.PlayerManagement.Accounts.DBModels { + /// + /// Represents a player entity stored in the account database. + /// 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;