From 21d90a313eebfbda4d30b3e72ea38839c575ab34 Mon Sep 17 00:00:00 2001 From: Ramen2X <64166386+Ramen2X@users.noreply.github.com> Date: Tue, 14 Dec 2021 21:26:46 -0500 Subject: [PATCH] begin work on account creation --- OutrunSharp/Controllers/LoginController.cs | 14 ++--- OutrunSharp/Helpers/RunnersResponseHelper.cs | 8 +-- .../Models/DbModels/OutrunDbContext.cs | 62 ++++++++++++++++++- OutrunSharp/Models/DbModels/PlayerInfo.cs | 2 +- OutrunSharp/Models/Obj/Character.cs | 2 +- 5 files changed, 70 insertions(+), 18 deletions(-) diff --git a/OutrunSharp/Controllers/LoginController.cs b/OutrunSharp/Controllers/LoginController.cs index f2ca281..6bd28d0 100644 --- a/OutrunSharp/Controllers/LoginController.cs +++ b/OutrunSharp/Controllers/LoginController.cs @@ -64,16 +64,12 @@ public RunnersResponseMessage DoLogin(string key, string param, int secure) 0)); } - if(paramData.lineAuth.userId.Length == 0) + if (paramData.lineAuth.userId == "0") { // registration - create a new account and return its info _logger.LogDebug("Entering Registration"); - // TODO: add actual logic here - return RunnersResponseHelper.CraftResponse(true, - RunnersResponseHelper.CreateBaseResponse( - "Unimplemented operation", - RunnersResponseHelper.StatusCode.OtherError, - 0)); + context.CreatePlayer(); + } if (paramData.lineAuth.password.Length == 0) { @@ -83,7 +79,7 @@ public RunnersResponseMessage DoLogin(string key, string param, int secure) { Debug.Assert(context != null, nameof(context) + " != null"); var pkey = context.GetPlayerKey(paramData.lineAuth.userId); - LoginCheckKeyResponse response = new("Bad password", (int)RunnersResponseHelper.StatusCode.PassWordError) + LoginCheckKeyResponse response = new("Bad password", (int)RunnersResponseHelper.StatusCode.PasswordError) { key = pkey }; @@ -122,7 +118,7 @@ public RunnersResponseMessage DoLogin(string key, string param, int secure) { _logger.LogDebug("Auth failed!"); var pkey = context.GetPlayerKey(paramData.lineAuth.userId); - LoginCheckKeyResponse response = new("Bad password", (int)RunnersResponseHelper.StatusCode.PassWordError) + LoginCheckKeyResponse response = new("Bad password", (int)RunnersResponseHelper.StatusCode.PasswordError) { key = pkey }; diff --git a/OutrunSharp/Helpers/RunnersResponseHelper.cs b/OutrunSharp/Helpers/RunnersResponseHelper.cs index f0a7517..047a11c 100644 --- a/OutrunSharp/Helpers/RunnersResponseHelper.cs +++ b/OutrunSharp/Helpers/RunnersResponseHelper.cs @@ -23,7 +23,7 @@ public enum StatusCode NotAvailablePlayer = -10101, MissingPlayer = -10102, ExpirationSession = -10103, - PassWordError = -10104, + PasswordError = -10104, InvalidSerialCode = -10105, UsedSerialCode = -10106, HspWebApiError = -10110, @@ -48,9 +48,9 @@ public enum StatusCode EnergyLimitPurchaseTrigger = -21010, NotStartEvent = -10201, AlreadyEndEvent = -10202, - UsernameInvalidChars = -31000, // for 2.0.4 and later - UsernameTooLong = -31001, // for 2.0.4 and later - UsernameHasNGWord = -31002, // for 2.0.4 and later + UsernameInvalidChars = -31000, // for 2.1.0 and later + UsernameTooLong = -31001, // for 2.1.0 and later + UsernameHasNGWord = -31002, // for 2.1.0 and later VersionForApplication = -999002, TimeOut = -7, OtherError = -8, diff --git a/OutrunSharp/Models/DbModels/OutrunDbContext.cs b/OutrunSharp/Models/DbModels/OutrunDbContext.cs index b64f76b..b0e7f31 100644 --- a/OutrunSharp/Models/DbModels/OutrunDbContext.cs +++ b/OutrunSharp/Models/DbModels/OutrunDbContext.cs @@ -44,6 +44,21 @@ private static string GetRandomString(int length) return s; } + private static long GetRandomLong(int length) + { + long l = 0; + + int i; + + int pwr = 1; + for (i = 0; i < length; i++) + { + l += RandomNumberGenerator.GetInt32(9)*pwr; + pwr *= 10; + } + return l; + } + public PlayerInfo GetPlayerInfo(string id) { PlayerInfo info = new(); @@ -67,7 +82,7 @@ public PlayerInfo GetPlayerInfo(string id) } else { - info.Id = Convert.ToUInt64(reader["id"]); + info.Id = (long)Convert.ToUInt64(reader["id"]); info.Username = reader["username"].ToString(); info.Password = reader["password"].ToString(); info.MigratePassword = reader["migrate_password"].ToString(); @@ -89,6 +104,47 @@ public PlayerInfo GetPlayerInfo(string id) return info; } + public long CreatePlayerID() + { + int idLength = 10; + + long newID = GetRandomLong(idLength); + return newID; + } + + public string CreatePlayerKey(int length) + { + string newKey = GetRandomString(length); + return newKey; + } + + public void CreatePlayer() + { + int pwLength = 10; + int keyLength = 16; + + PlayerInfo info = new(); + + long newID = CreatePlayerID(); // TODO: Check if generated ID is already registered!! + + info.Id = newID; + info.Username = ""; + info.Password = CreatePlayerKey(pwLength); + info.MigratePassword = CreatePlayerKey(pwLength); + info.UserPassword = ""; + info.PlayerKey = CreatePlayerKey(keyLength); + /* + info.Characters = JsonConvert.DeserializeObject>(reader["characters"].ToString()); + info.Chao = JsonConvert.DeserializeObject>(reader["chao"].ToString()); + info.SuspendedUntil = Convert.ToInt64(reader["suspended_until"]); + info.SuspendReason = Convert.ToInt32(reader["suspend_reason"]); + info.LastLoginDevice = reader["last_login_device"].ToString(); + info.LastLoginPlatform = (Platform)Convert.ToInt32(reader["last_login_platform"]); + */ + + //TODO: Get this info into the db + } + public string GetPlayerKey(string id) { var key = string.Empty; @@ -118,9 +174,9 @@ public string GetPlayerKey(string id) } } } - if(key != null && key.Length != 16) + if (key != null && key.Length != 16) { - UpdatePlayerInfo(id, "player_key", GetRandomString(16)); + UpdatePlayerInfo(id, "player_key", CreatePlayerKey(16)); } return key; } diff --git a/OutrunSharp/Models/DbModels/PlayerInfo.cs b/OutrunSharp/Models/DbModels/PlayerInfo.cs index ef91676..2ea41f0 100644 --- a/OutrunSharp/Models/DbModels/PlayerInfo.cs +++ b/OutrunSharp/Models/DbModels/PlayerInfo.cs @@ -5,7 +5,7 @@ namespace OutrunSharp.Models.DbModels { public class PlayerInfo { - public ulong Id { get; set; } + public long Id { get; set; } public string Username { get; set; } public string Password { get; set; } // internal password stored with the ID in the save file public string MigratePassword { get; set; } // Transfer ID diff --git a/OutrunSharp/Models/Obj/Character.cs b/OutrunSharp/Models/Obj/Character.cs index f865716..449010f 100644 --- a/OutrunSharp/Models/Obj/Character.cs +++ b/OutrunSharp/Models/Obj/Character.cs @@ -72,7 +72,7 @@ public enum CharaIDs Tikal, // sonic adventure event Mephiles, // sonic wars/forces event? PSISilver, - Chara0021, // 2.0.4 launch event + Marine, // 2.1.0 launch event Chara0022, // ??? event Chara0023, // ??? event Chara0024, // ??? event