Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions OutrunSharp/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
};
Expand Down Expand Up @@ -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
};
Expand Down
8 changes: 4 additions & 4 deletions OutrunSharp/Helpers/RunnersResponseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum StatusCode
NotAvailablePlayer = -10101,
MissingPlayer = -10102,
ExpirationSession = -10103,
PassWordError = -10104,
PasswordError = -10104,
InvalidSerialCode = -10105,
UsedSerialCode = -10106,
HspWebApiError = -10110,
Expand All @@ -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,
Expand Down
62 changes: 59 additions & 3 deletions OutrunSharp/Models/DbModels/OutrunDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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<List<Character>>(reader["characters"].ToString());
info.Chao = JsonConvert.DeserializeObject<List<Chao>>(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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion OutrunSharp/Models/DbModels/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion OutrunSharp/Models/Obj/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down