From caf71ca841dbc7d078ee46e75f3cdcd770623ee4 Mon Sep 17 00:00:00 2001 From: moux23333 <110985481+moux23333@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:28:52 +0800 Subject: [PATCH] remove database(no need mongodb anymore) --- FreeSR.Admin/AdminServer.cs | 51 --------- FreeSR.Admin/AdminServer.example.json | 7 -- FreeSR.Admin/AdminServerConfiguration.cs | 10 -- FreeSR.Admin/Command/AdminCommandContext.cs | 19 ---- .../Handlers/AccountCommandCategory.cs | 17 --- FreeSR.Admin/FreeSR.Admin.csproj | 27 ----- .../Handlers/ConsolePageRequestHandler.cs | 25 ----- .../Handlers/ExecuteCommandRequestHandler.cs | 23 ---- FreeSR.Admin/Service/HttpAdminService.cs | 43 -------- FreeSR.Admin/assets/console.html | 101 ------------------ FreeSR.Database.Account/AccountDatabase.cs | 59 ---------- .../FreeSR.Database.Account.csproj | 13 --- FreeSR.Database.Account/Model/AccountModel.cs | 14 --- .../Util/AccountTokenUtil.cs | 37 ------- .../Configuration/DatabaseConfiguration.cs | 9 -- .../Configuration/DatabaseEntry.cs | 8 -- .../DatabaseMisconfiguredException.cs | 12 --- FreeSR.Database/Configuration/DatabaseType.cs | 7 -- FreeSR.Database/DatabaseManager.cs | 55 ---------- FreeSR.Database/FreeSR.Database.csproj | 17 --- FreeSR.Database/ISRDatabase.cs | 18 ---- FreeSR.Database/Mongo/SRMongoDatabase.cs | 58 ---------- FreeSR.Dispatch/DispatchServer.cs | 8 -- FreeSR.Dispatch/DispatchServer.example.json | 10 -- .../DispatchServerConfiguration.cs | 2 - FreeSR.Dispatch/FreeSR.Dispatch.csproj | 1 - .../Handlers/LoginRequestHandler.cs | 20 +--- .../Handlers/TokenLoginRequestHandler.cs | 34 +----- .../Service/HttpDispatchService.cs | 4 +- FreeSR.Dispatch/Util/DispatchHelper.cs | 11 +- 30 files changed, 10 insertions(+), 710 deletions(-) delete mode 100644 FreeSR.Admin/AdminServer.cs delete mode 100644 FreeSR.Admin/AdminServer.example.json delete mode 100644 FreeSR.Admin/AdminServerConfiguration.cs delete mode 100644 FreeSR.Admin/Command/AdminCommandContext.cs delete mode 100644 FreeSR.Admin/Command/Handlers/AccountCommandCategory.cs delete mode 100644 FreeSR.Admin/FreeSR.Admin.csproj delete mode 100644 FreeSR.Admin/Handlers/ConsolePageRequestHandler.cs delete mode 100644 FreeSR.Admin/Handlers/ExecuteCommandRequestHandler.cs delete mode 100644 FreeSR.Admin/Service/HttpAdminService.cs delete mode 100644 FreeSR.Admin/assets/console.html delete mode 100644 FreeSR.Database.Account/AccountDatabase.cs delete mode 100644 FreeSR.Database.Account/FreeSR.Database.Account.csproj delete mode 100644 FreeSR.Database.Account/Model/AccountModel.cs delete mode 100644 FreeSR.Database.Account/Util/AccountTokenUtil.cs delete mode 100644 FreeSR.Database/Configuration/DatabaseConfiguration.cs delete mode 100644 FreeSR.Database/Configuration/DatabaseEntry.cs delete mode 100644 FreeSR.Database/Configuration/DatabaseMisconfiguredException.cs delete mode 100644 FreeSR.Database/Configuration/DatabaseType.cs delete mode 100644 FreeSR.Database/DatabaseManager.cs delete mode 100644 FreeSR.Database/FreeSR.Database.csproj delete mode 100644 FreeSR.Database/ISRDatabase.cs delete mode 100644 FreeSR.Database/Mongo/SRMongoDatabase.cs diff --git a/FreeSR.Admin/AdminServer.cs b/FreeSR.Admin/AdminServer.cs deleted file mode 100644 index 944c11b..0000000 --- a/FreeSR.Admin/AdminServer.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace FreeSR.Admin -{ - using FreeSR.Admin.Command.Handlers; - using FreeSR.Admin.Service; - using FreeSR.Shared.Command; - using FreeSR.Shared.Configuration; - using FreeSR.Shared.Exceptions; - using NLog; - - internal static class AdminServer - { - private static readonly Logger s_log = LogManager.GetCurrentClassLogger(); - - private static void Main(string[] args) - { - Directory.SetCurrentDirectory(AppContext.BaseDirectory); - AppDomain.CurrentDomain.UnhandledException += OnFatalException; - - Console.WriteLine("FreeSR is a free and open-source software, if you paid for this, you have been scammed!"); - Console.WriteLine("FreeSR是一个免费且开源的软件,如果你是花钱买来的,则说明你被骗了!"); - Console.WriteLine("https://git.xeondev.com/Moux23333/FreeSR"); - s_log.Info("Initializing..."); - - CommandManager.Instance.Initialize(typeof(AccountCommandCategory)); - ConfigurationManager.Instance.Initialize("AdminServer.json"); - var serverConfiguration = ConfigurationManager.Instance.Model; - - HttpAdminService.Initialize(serverConfiguration.Network); - - s_log.Info("Server is ready!"); - Thread.Sleep(-1); - } - - private static void OnFatalException(object sender, UnhandledExceptionEventArgs args) - { - if (args.ExceptionObject is ServerInitializationException initException) - { - Console.WriteLine("Server initialization failed, unhandled exception!"); - Console.WriteLine(initException); - } - else - { - Console.WriteLine("Unhandled exception in runtime!"); - Console.WriteLine(args.ExceptionObject); - } - - Console.WriteLine("Press enter to close this window..."); - Console.ReadLine(); - } - } -} \ No newline at end of file diff --git a/FreeSR.Admin/AdminServer.example.json b/FreeSR.Admin/AdminServer.example.json deleted file mode 100644 index e335144..0000000 --- a/FreeSR.Admin/AdminServer.example.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "Network": { - "Host": "0.0.0.0", - "Port": 1337 - }, - "DispatchUrl": "http://localhost:8888" -} \ No newline at end of file diff --git a/FreeSR.Admin/AdminServerConfiguration.cs b/FreeSR.Admin/AdminServerConfiguration.cs deleted file mode 100644 index 497eb1d..0000000 --- a/FreeSR.Admin/AdminServerConfiguration.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FreeSR.Admin -{ - using FreeSR.Shared.Configuration; - - internal class AdminServerConfiguration - { - public NetworkConfiguration Network { get; set; } - public string DispatchUrl { get; set; } - } -} diff --git a/FreeSR.Admin/Command/AdminCommandContext.cs b/FreeSR.Admin/Command/AdminCommandContext.cs deleted file mode 100644 index 823940f..0000000 --- a/FreeSR.Admin/Command/AdminCommandContext.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace FreeSR.Admin.Command -{ - using FreeSR.Shared.Command.Context; - - internal class AdminCommandContext : ICommandContext - { - public string Message { get; private set; } - - public void SendError(string message) - { - Message = "Error: " + message; - } - - public void SendMessage(string message) - { - Message = message; - } - } -} diff --git a/FreeSR.Admin/Command/Handlers/AccountCommandCategory.cs b/FreeSR.Admin/Command/Handlers/AccountCommandCategory.cs deleted file mode 100644 index 371c719..0000000 --- a/FreeSR.Admin/Command/Handlers/AccountCommandCategory.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace FreeSR.Admin.Command.Handlers -{ - using FreeSR.Shared.Command; - using FreeSR.Shared.Command.Context; - using FreeSR.Shared.Configuration; - - [Command("account")] - internal class AccountCommandCategory : CommandCategory - { - [Command("create")] - public void AccountCreateCommandHandler(ICommandContext context, string username, string password) - { - var config = ConfigurationManager.Instance.Model; - context.SendMessage($"dohttpreq={config.DispatchUrl}/sdk/createaccount?user={username}&pass={password}"); - } - } -} diff --git a/FreeSR.Admin/FreeSR.Admin.csproj b/FreeSR.Admin/FreeSR.Admin.csproj deleted file mode 100644 index 95ec97b..0000000 --- a/FreeSR.Admin/FreeSR.Admin.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - Exe - net7.0 - enable - disable - - - - - - - - - - - - - Always - - - Always - - - - diff --git a/FreeSR.Admin/Handlers/ConsolePageRequestHandler.cs b/FreeSR.Admin/Handlers/ConsolePageRequestHandler.cs deleted file mode 100644 index a02f572..0000000 --- a/FreeSR.Admin/Handlers/ConsolePageRequestHandler.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace FreeSR.Admin.Handlers -{ - using Ceen; - using FreeSR.Admin.Service; - - internal class ConsolePageRequestHandler : IHttpModule - { - public async Task HandleAsync(IHttpContext context) - { - context.Response.StatusCode = HttpStatusCode.OK; - await context.Response.WriteAllAsync(CreateHTMLDocument(), "text/html"); - - return true; - } - - private static string CreateHTMLDocument() - { - string baseString = HttpAdminService.ConsoleHTML; - - return baseString.Replace("%SERVER_VERSION%", "v0.1.0 dev - experimental open source") - .Replace("%GAME_VERSION%", "1.2.0"); - - } - } -} diff --git a/FreeSR.Admin/Handlers/ExecuteCommandRequestHandler.cs b/FreeSR.Admin/Handlers/ExecuteCommandRequestHandler.cs deleted file mode 100644 index aeac0ec..0000000 --- a/FreeSR.Admin/Handlers/ExecuteCommandRequestHandler.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace FreeSR.Admin.Handlers -{ - using Ceen; - using FreeSR.Admin.Command; - using FreeSR.Shared.Command; - - internal class ExecuteCommandRequestHandler : IHttpModule - { - public async Task HandleAsync(IHttpContext context) - { - var query = context.Request.QueryString; - string command = query["command"]; - - var ctx = new AdminCommandContext(); - CommandManager.Instance.Invoke(ctx, command); - - context.Response.StatusCode = HttpStatusCode.OK; - await context.Response.WriteAllAsync(ctx.Message, "text/plain"); - - return true; - } - } -} diff --git a/FreeSR.Admin/Service/HttpAdminService.cs b/FreeSR.Admin/Service/HttpAdminService.cs deleted file mode 100644 index d433fdb..0000000 --- a/FreeSR.Admin/Service/HttpAdminService.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace FreeSR.Admin.Service -{ - using Ceen.Httpd; - using Ceen.Httpd.Logging; - using FreeSR.Admin.Handlers; - using FreeSR.Shared.Configuration; - using System.Net; - - internal static class HttpAdminService - { - public static string ConsoleHTML { get; private set; } - - private static ServerConfig s_httpdConfiguration; - - public static void Initialize(NetworkConfiguration config) - { - LoadHtDocs(); - - s_httpdConfiguration = CreateConfiguration(); - _ = BootHttpAsync(config); - } - - private static void LoadHtDocs() - { - ConsoleHTML = File.ReadAllText("assets/console.html"); - } - - private static ServerConfig CreateConfiguration() - { - return new ServerConfig().AddLogger(new CLFStdOut()) - .AddRoute("/console", new ConsolePageRequestHandler()) - .AddRoute("/console/exec", new ExecuteCommandRequestHandler()); - } - - private static async Task BootHttpAsync(NetworkConfiguration config) - { - await HttpServer.ListenAsync(new IPEndPoint( - IPAddress.Parse(config.Host), - config.Port), - false, s_httpdConfiguration); - } - } -} diff --git a/FreeSR.Admin/assets/console.html b/FreeSR.Admin/assets/console.html deleted file mode 100644 index b5997fe..0000000 --- a/FreeSR.Admin/assets/console.html +++ /dev/null @@ -1,101 +0,0 @@ - - - - FreeSR - - - -

FreeSR Control Panel

-
-

Status:

-

Loading...

-
-
-

Server Statistics:

- -

Server build: %SERVER_VERSION%

-

Supported game version: %GAME_VERSION%

-
-
-

Admin Console:

- - - -
- - - - diff --git a/FreeSR.Database.Account/AccountDatabase.cs b/FreeSR.Database.Account/AccountDatabase.cs deleted file mode 100644 index 7ec5392..0000000 --- a/FreeSR.Database.Account/AccountDatabase.cs +++ /dev/null @@ -1,59 +0,0 @@ -namespace FreeSR.Database.Account -{ - using FreeSR.Database.Account.Model; - using FreeSR.Database.Account.Util; - using FreeSR.Database.Mongo; - using MongoDB.Driver; - - public class AccountDatabase : SRMongoDatabase - { - private int _maxUid; - - public AccountDatabase(IMongoDatabase database, string collectionName) : base(database, collectionName) - { - // AccountDatabase. - } - - public async Task Create(string name, string password) - { - if (_maxUid == 0) - _maxUid = await FetchMaxUid(); - - if (await GetByName(name) != null) - return null; - - var model = new AccountModel - { - Uid = Interlocked.Increment(ref _maxUid), - Name = name, - Password = password, - CreationDateUtc = DateTime.UtcNow, - Token = AccountTokenUtil.Generate() - }; - - await Insert(model); - return model; - } - - public async Task GetByUid(int uid) - { - return await FindOne(account => account.Uid == uid); - } - - public async Task GetByName(string name) - { - return await FindOne(account => account.Name == name); - } - - public async Task Update(AccountModel account) - { - await Update(model => model.Uid == account.Uid, account); - } - - private async Task FetchMaxUid() - { - var maxUidAccount = await FindMax(account => account.Uid); - return maxUidAccount?.Uid ?? 0; - } - } -} diff --git a/FreeSR.Database.Account/FreeSR.Database.Account.csproj b/FreeSR.Database.Account/FreeSR.Database.Account.csproj deleted file mode 100644 index abc070f..0000000 --- a/FreeSR.Database.Account/FreeSR.Database.Account.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net7.0 - enable - disable - - - - - - - diff --git a/FreeSR.Database.Account/Model/AccountModel.cs b/FreeSR.Database.Account/Model/AccountModel.cs deleted file mode 100644 index 48b3e2d..0000000 --- a/FreeSR.Database.Account/Model/AccountModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace FreeSR.Database.Account.Model -{ - using MongoDB.Bson.Serialization.Attributes; - - [BsonIgnoreExtraElements] - public class AccountModel - { - public int Uid { get; set; } - public string Name { get; set; } - public string Password { get; set; } - public string Token { get; set; } - public DateTime CreationDateUtc { get; set; } - } -} diff --git a/FreeSR.Database.Account/Util/AccountTokenUtil.cs b/FreeSR.Database.Account/Util/AccountTokenUtil.cs deleted file mode 100644 index b3b95df..0000000 --- a/FreeSR.Database.Account/Util/AccountTokenUtil.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace FreeSR.Database.Account.Util -{ - using FreeSR.Database.Account.Model; - - public static class AccountTokenUtil - { - private const int AccountTokenLength = 128; - private const string TokenCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - - private static Random s_random; - - static AccountTokenUtil() - { - s_random = new Random(); - } - - public static string Generate() - { - var token = ""; - - for (int i = 0; i < AccountTokenLength; i++) - { - token += TokenCharacters[s_random.Next(TokenCharacters.Length)]; - } - - return token; - } - - public static bool Verify(AccountModel accountModel, string clientToken) - { - if (accountModel == null) - return false; - - return string.Equals(accountModel.Token, clientToken); - } - } -} diff --git a/FreeSR.Database/Configuration/DatabaseConfiguration.cs b/FreeSR.Database/Configuration/DatabaseConfiguration.cs deleted file mode 100644 index 991d130..0000000 --- a/FreeSR.Database/Configuration/DatabaseConfiguration.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace FreeSR.Database.Configuration -{ - public class DatabaseConfiguration - { - public string ConnectionString { get; set; } - public string Name { get; set; } - public DatabaseEntry[] Entries { get; set; } - } -} diff --git a/FreeSR.Database/Configuration/DatabaseEntry.cs b/FreeSR.Database/Configuration/DatabaseEntry.cs deleted file mode 100644 index a70493a..0000000 --- a/FreeSR.Database/Configuration/DatabaseEntry.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace FreeSR.Database.Configuration -{ - public class DatabaseEntry - { - public string CollectionName { get; set; } - public DatabaseType Type { get; set; } - } -} diff --git a/FreeSR.Database/Configuration/DatabaseMisconfiguredException.cs b/FreeSR.Database/Configuration/DatabaseMisconfiguredException.cs deleted file mode 100644 index 780aada..0000000 --- a/FreeSR.Database/Configuration/DatabaseMisconfiguredException.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace FreeSR.Database.Configuration -{ - using FreeSR.Shared.Exceptions; - - internal class DatabaseMisconfiguredException : ServerInitializationException - { - public DatabaseMisconfiguredException(string message) : base(message) - { - // DatabaseMisconfiguredException. - } - } -} diff --git a/FreeSR.Database/Configuration/DatabaseType.cs b/FreeSR.Database/Configuration/DatabaseType.cs deleted file mode 100644 index 974723e..0000000 --- a/FreeSR.Database/Configuration/DatabaseType.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace FreeSR.Database.Configuration -{ - public enum DatabaseType - { - Account - } -} diff --git a/FreeSR.Database/DatabaseManager.cs b/FreeSR.Database/DatabaseManager.cs deleted file mode 100644 index 1542034..0000000 --- a/FreeSR.Database/DatabaseManager.cs +++ /dev/null @@ -1,55 +0,0 @@ -namespace FreeSR.Database -{ - using FreeSR.Database.Configuration; - using FreeSR.Shared; - using MongoDB.Driver; - using NLog; - - public sealed class DatabaseManager : Singleton - { - private static readonly Logger s_log = LogManager.GetCurrentClassLogger(); - - private DatabaseConfiguration _configuration; - private Dictionary _databases; - - public IMongoDatabase MongoDatabase { get; private set; } - - private DatabaseManager() - { - _databases = new Dictionary(); - } - - public void Initialize(DatabaseConfiguration configuration) - { - _configuration = configuration; - - var mongoClient = new MongoClient(configuration.ConnectionString); - MongoDatabase = mongoClient.GetDatabase(configuration.Name); - } - - public string GetCollectionName(DatabaseType databaseType) - { - foreach (var entry in _configuration.Entries) - { - if (entry.Type == databaseType) - return entry.CollectionName; - } - - throw new DatabaseMisconfiguredException($"Can not find database of type {databaseType} in provided configuration."); - } - - public DatabaseManager Add(ISRDatabase database) where T : class - { - _databases.Add(database.GetType(), database); - return this; - } - - public T Get() where T : class - { - if (_databases.TryGetValue(typeof(T), out var database)) - return database as T; - - return null; - } - } -} diff --git a/FreeSR.Database/FreeSR.Database.csproj b/FreeSR.Database/FreeSR.Database.csproj deleted file mode 100644 index 189e1b1..0000000 --- a/FreeSR.Database/FreeSR.Database.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net7.0 - enable - disable - - - - - - - - - - - diff --git a/FreeSR.Database/ISRDatabase.cs b/FreeSR.Database/ISRDatabase.cs deleted file mode 100644 index 029219d..0000000 --- a/FreeSR.Database/ISRDatabase.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace FreeSR.Database -{ - using System; - using System.Collections.Generic; - using System.Linq.Expressions; - - public interface ISRDatabase where T : class - { - Task Insert(T document); - Task InsertMany(IEnumerable documents); - Task> Find(Expression> filter); - Task FindOne(Expression> filter); - Task Update(Expression> filter, T updatedDocument); - Task Delete(Expression> filter); - Task Count(); - Task FindMax(Expression> fieldSelector); - } -} diff --git a/FreeSR.Database/Mongo/SRMongoDatabase.cs b/FreeSR.Database/Mongo/SRMongoDatabase.cs deleted file mode 100644 index 49de156..0000000 --- a/FreeSR.Database/Mongo/SRMongoDatabase.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace FreeSR.Database.Mongo -{ - using MongoDB.Driver; - using System.Linq.Expressions; - - public class SRMongoDatabase : ISRDatabase where T : class - { - protected readonly IMongoCollection _collection; - - public SRMongoDatabase(IMongoDatabase database, string collectionName) - { - _collection = database.GetCollection(collectionName); - } - - public async Task Insert(T document) - { - await _collection.InsertOneAsync(document); - } - - public async Task InsertMany(IEnumerable documents) - { - await _collection.InsertManyAsync(documents); - } - - public async Task> Find(Expression> filter) - { - var result = await _collection.FindAsync(filter); - return await result.ToListAsync(); - } - - public async Task FindOne(Expression> filter) - { - var result = await _collection.FindAsync(filter); - return await result.FirstOrDefaultAsync(); - } - - public async Task Update(Expression> filter, T updatedDocument) - { - await _collection.ReplaceOneAsync(filter, updatedDocument); - } - - public async Task Delete(Expression> filter) - { - await _collection.DeleteOneAsync(filter); - } - - public async Task Count() - { - return await _collection.CountDocumentsAsync(Builders.Filter.Empty); - } - - public async Task FindMax(Expression> fieldSelector) - { - var sortDefinition = Builders.Sort.Descending(fieldSelector); - return await _collection.Find(Builders.Filter.Empty).Sort(sortDefinition).FirstOrDefaultAsync(); - } - } -} diff --git a/FreeSR.Dispatch/DispatchServer.cs b/FreeSR.Dispatch/DispatchServer.cs index 522dea5..6e62f86 100644 --- a/FreeSR.Dispatch/DispatchServer.cs +++ b/FreeSR.Dispatch/DispatchServer.cs @@ -1,8 +1,5 @@ namespace FreeSR.Dispatch { - using FreeSR.Database; - using FreeSR.Database.Account; - using FreeSR.Database.Configuration; using FreeSR.Dispatch.Service; using FreeSR.Dispatch.Service.Manager; using FreeSR.Shared.Configuration; @@ -30,11 +27,6 @@ ConfigurationManager.Instance.Initialize("DispatchServer.json"); var serverConfiguration = ConfigurationManager.Instance.Model; - DatabaseManager.Instance.Initialize(serverConfiguration.Database); - - var mongoDatabase = DatabaseManager.Instance.MongoDatabase; - DatabaseManager.Instance.Add(new AccountDatabase(mongoDatabase, DatabaseManager.Instance.GetCollectionName(DatabaseType.Account))); - RegionManager.Initialize(serverConfiguration.Region); HttpDispatchService.Initialize(serverConfiguration.Network); diff --git a/FreeSR.Dispatch/DispatchServer.example.json b/FreeSR.Dispatch/DispatchServer.example.json index d4bb5f5..c681a85 100644 --- a/FreeSR.Dispatch/DispatchServer.example.json +++ b/FreeSR.Dispatch/DispatchServer.example.json @@ -3,16 +3,6 @@ "Host": "0.0.0.0", "Port": 8888 }, - "Database": { - "ConnectionString": "mongodb://127.0.0.1:27017/", - "Name": "FreeSR", - "Entries": [ - { - "CollectionName": "accounts", - "Type": "Account" - } - ] - }, "Region": { "Name": "FreeSR", "EnvType": "2", diff --git a/FreeSR.Dispatch/DispatchServerConfiguration.cs b/FreeSR.Dispatch/DispatchServerConfiguration.cs index 9101491..da52a23 100644 --- a/FreeSR.Dispatch/DispatchServerConfiguration.cs +++ b/FreeSR.Dispatch/DispatchServerConfiguration.cs @@ -1,13 +1,11 @@ namespace FreeSR.Dispatch { - using FreeSR.Database.Configuration; using FreeSR.Dispatch.Configuration; using FreeSR.Shared.Configuration; internal class DispatchServerConfiguration { public NetworkConfiguration Network { get; set; } - public DatabaseConfiguration Database { get; set; } public RegionConfiguration Region { get; set; } } } diff --git a/FreeSR.Dispatch/FreeSR.Dispatch.csproj b/FreeSR.Dispatch/FreeSR.Dispatch.csproj index 1a85570..2c2b9cb 100644 --- a/FreeSR.Dispatch/FreeSR.Dispatch.csproj +++ b/FreeSR.Dispatch/FreeSR.Dispatch.csproj @@ -13,7 +13,6 @@ - diff --git a/FreeSR.Dispatch/Handlers/LoginRequestHandler.cs b/FreeSR.Dispatch/Handlers/LoginRequestHandler.cs index 593e4af..25b3e4c 100644 --- a/FreeSR.Dispatch/Handlers/LoginRequestHandler.cs +++ b/FreeSR.Dispatch/Handlers/LoginRequestHandler.cs @@ -1,9 +1,6 @@ namespace FreeSR.Dispatch.Handlers { using Ceen; - using FreeSR.Database; - using FreeSR.Database.Account; - using FreeSR.Database.Account.Model; using FreeSR.Dispatch.Util; using FreeSR.Proto; using Newtonsoft.Json.Linq; @@ -19,30 +16,17 @@ string data = await context.Request.Body.ReadAllAsStringAsync(); JObject loginJson = JObject.Parse(data); - AccountDatabase accountDatabase = DatabaseManager.Instance.Get(); - string accountName = (string)loginJson["account"]; string password = (string)loginJson["password"]; - AccountModel account = await accountDatabase.GetByName(accountName); - if (account == null) - { - await context.Response.WriteAllJsonAsync(DispatchResponseBuilder.Create() - .Retcode((int)RetcodeStatus.RetFail) - .Message("Account not found.") - .Object("data", null) - .Build()); - return true; - } - - // no password check, because client patch is closed-source for now. + var accountData = DispatchHelper.ToLoginResponseData(); await context.Response.WriteAllJsonAsync(DispatchResponseBuilder.Create() .Retcode((int)RetcodeStatus.RetSucc) .Message("OK") .Object("data", new JObject { - {"account", account.ToLoginResponseData()}, + {"account", accountData}, {"device_grant_required", false}, {"safe_moblie_required", false}, {"realperson_required", false}, diff --git a/FreeSR.Dispatch/Handlers/TokenLoginRequestHandler.cs b/FreeSR.Dispatch/Handlers/TokenLoginRequestHandler.cs index 32fa38c..b3e8c75 100644 --- a/FreeSR.Dispatch/Handlers/TokenLoginRequestHandler.cs +++ b/FreeSR.Dispatch/Handlers/TokenLoginRequestHandler.cs @@ -1,9 +1,6 @@ namespace FreeSR.Dispatch.Handlers { using Ceen; - using FreeSR.Database; - using FreeSR.Database.Account; - using FreeSR.Database.Account.Model; using FreeSR.Dispatch.Util; using FreeSR.Proto; using Newtonsoft.Json.Linq; @@ -13,41 +10,14 @@ { public async Task HandleAsync(IHttpContext context) { - var data = await context.Request.Body.ReadAllAsStringAsync(); - var json = JObject.Parse(data); - - var uid = int.Parse((string)json["uid"]); - var token = (string)json["token"]; - - AccountDatabase accountDatabase = DatabaseManager.Instance.Get(); - AccountModel account = await accountDatabase.GetByUid(uid); - if (account == null) - { - await context.Response.WriteAllJsonAsync(DispatchResponseBuilder.Create() - .Retcode((int)RetcodeStatus.RetFail) - .Message("Account not found.") - .Object("data", null) - .Build()); - - return true; - } - else if (account.Token != token) - { - await context.Response.WriteAllJsonAsync(DispatchResponseBuilder.Create() - .Retcode((int)RetcodeStatus.RetFail) - .Message("Invalid user token.") - .Object("data", null) - .Build()); - - return true; - } + var accountData = DispatchHelper.ToLoginResponseData(); await context.Response.WriteAllJsonAsync(DispatchResponseBuilder.Create() .Retcode((int)RetcodeStatus.RetSucc) .Message("OK") .Object("data", new JObject { - {"account", account.ToLoginResponseData()}, + {"account", accountData}, {"device_grant_required", false}, {"safe_moblie_required", false}, {"realperson_required", false}, diff --git a/FreeSR.Dispatch/Service/HttpDispatchService.cs b/FreeSR.Dispatch/Service/HttpDispatchService.cs index 4fec933..780295c 100644 --- a/FreeSR.Dispatch/Service/HttpDispatchService.cs +++ b/FreeSR.Dispatch/Service/HttpDispatchService.cs @@ -3,7 +3,6 @@ using Ceen.Httpd; using Ceen.Httpd.Logging; using FreeSR.Dispatch.Handlers; - using FreeSR.Dispatch.Handlers.Sdk; using FreeSR.Shared.Configuration; using System.Net; @@ -30,8 +29,7 @@ .AddRoute("/account/risky/api/check", new RiskyApiCheckHandler()) .AddRoute("/hkrpg_global/mdk/agreement/api/getAgreementInfos", new GetAgreementInfosHandler()) .AddRoute("/data_abtest_api/config/experiment/list", new GetExperimentListHandler()) - .AddRoute("/hkrpg_global/combo/granter/api/getConfig", new ComboGranterApiGetConfigHandler()) - .AddRoute("/sdk/createaccount", new CreateAccountHandler()); + .AddRoute("/hkrpg_global/combo/granter/api/getConfig", new ComboGranterApiGetConfigHandler()); } private static async Task BootHttpAsync(NetworkConfiguration config) diff --git a/FreeSR.Dispatch/Util/DispatchHelper.cs b/FreeSR.Dispatch/Util/DispatchHelper.cs index e62556b..e2e39a0 100644 --- a/FreeSR.Dispatch/Util/DispatchHelper.cs +++ b/FreeSR.Dispatch/Util/DispatchHelper.cs @@ -1,17 +1,16 @@ namespace FreeSR.Dispatch.Util { - using FreeSR.Database.Account.Model; using Newtonsoft.Json.Linq; internal static class DispatchHelper { - public static JObject ToLoginResponseData(this AccountModel model) + public static JObject ToLoginResponseData() { return new JObject { - {"uid", model.Uid}, - {"name", model.Name}, - {"email", "reversedrooms"}, + {"uid", 1337}, + {"name", "reversedrooms"}, + {"email", "reversedrooms@mihomo.com"}, {"mobile", ""}, {"is_email_verify", "0"}, {"realname", ""}, @@ -31,7 +30,7 @@ {"steam_name", ""}, {"unmasked_email", ""}, {"unmasked_email_type", 0}, - {"token", model.Token} + {"token", "FreesrToken"} }; } }