diff --git a/DatabaseMigrations/1.sql b/DatabaseMigrations/1.sql
index 94a0283d..596a411c 100644
--- a/DatabaseMigrations/1.sql
+++ b/DatabaseMigrations/1.sql
@@ -1,8 +1,8 @@
create table Locations
(
- Id int not null,
- X int not null,
- Y int not null
+ Id int not null,
+ X int not null,
+ Y int not null
);
create unique index Locations_UserId_uindex
@@ -15,3 +15,7 @@ alter table Locations
alter table Users
add LocationId int null;
+alter table Locations
+ modify Id int auto_increment;
+
+
diff --git a/DatabaseMigrations/4.sql b/DatabaseMigrations/4.sql
index 10c7ec2c..10281a40 100644
--- a/DatabaseMigrations/4.sql
+++ b/DatabaseMigrations/4.sql
@@ -1,5 +1,16 @@
create table Tokens
(
- UserId int not null,
+ TokenId int,
+ UserId int not null,
UserToken text not null
);
+
+create unique index Tokens_TokenId_uindex
+ on Tokens (TokenId);
+
+alter table Tokens
+ add constraint Tokens_pk
+ primary key (TokenId);
+
+alter table Tokens
+ modify TokenId int auto_increment;
diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings
index dcd254e2..7443a6e3 100644
--- a/ProjectLighthouse.sln.DotSettings
+++ b/ProjectLighthouse.sln.DotSettings
@@ -4,6 +4,7 @@
<Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
<Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
True
+ True
True
True
True
diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs
index 77bb334c..85312f66 100644
--- a/ProjectLighthouse/Database.cs
+++ b/ProjectLighthouse/Database.cs
@@ -2,6 +2,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
+using ProjectLighthouse.Helpers;
using ProjectLighthouse.Types;
namespace ProjectLighthouse {
@@ -38,8 +39,8 @@ namespace ProjectLighthouse {
public async Task AuthenticateUser(LoginData loginData) {
// TODO: don't use psn name to authenticate
- User user = await this.Users.FirstOrDefaultAsync(u => u.Username == loginData.Username + u.Username[-1])
- ?? await this.CreateUser(loginData.Username + "_");
+ User user = await this.Users.FirstOrDefaultAsync(u => u.Username == loginData.Username)
+ ?? await this.CreateUser(loginData.Username);
Token token = new() {
UserToken = HashHelper.GenerateAuthToken(),
diff --git a/ProjectLighthouse/Helpers/BinaryHelper.cs b/ProjectLighthouse/Helpers/BinaryHelper.cs
new file mode 100644
index 00000000..c62d14c8
--- /dev/null
+++ b/ProjectLighthouse/Helpers/BinaryHelper.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+namespace ProjectLighthouse.Helpers {
+ public static class BinaryHelper {
+ public static string ReadString(BinaryReader reader) {
+ List readBytes = new();
+
+ byte readByte;
+ do {
+ readBytes.Add(readByte = reader.ReadByte());
+ } while(readByte != 0x00);
+
+ return Encoding.UTF8.GetString(readBytes.ToArray());
+ }
+
+ public static void ReadUntilByte(BinaryReader reader, byte byteToReadTo) {
+ byte readByte;
+ do {
+ readByte = reader.ReadByte();
+ } while(readByte != byteToReadTo);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectLighthouse/HashHelper.cs b/ProjectLighthouse/Helpers/HashHelper.cs
similarity index 97%
rename from ProjectLighthouse/HashHelper.cs
rename to ProjectLighthouse/Helpers/HashHelper.cs
index 6d4470b7..d441d1c2 100644
--- a/ProjectLighthouse/HashHelper.cs
+++ b/ProjectLighthouse/Helpers/HashHelper.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
-namespace ProjectLighthouse {
+namespace ProjectLighthouse.Helpers {
public static class HashHelper {
// private static readonly SHA1 sha1 = SHA1.Create();
private static readonly SHA256 sha256 = SHA256.Create();
diff --git a/ProjectLighthouse/Types/LoginData.cs b/ProjectLighthouse/Types/LoginData.cs
index 84087d5f..eca52562 100644
--- a/ProjectLighthouse/Types/LoginData.cs
+++ b/ProjectLighthouse/Types/LoginData.cs
@@ -1,5 +1,6 @@
using System.IO;
using System.Text;
+using ProjectLighthouse.Helpers;
namespace ProjectLighthouse.Types {
// This is all the information I can understand for now. More testing is required.
@@ -14,28 +15,26 @@ namespace ProjectLighthouse.Types {
/// The data sent from POST /LOGIN.
///
public class LoginData {
- public string Username { get; set; } // Cut off by one for some strange reason
- public string GameVersion { get; set; }
- public int UnknownNumber { get; set; } // Seems to increment by 1000 every login attempt
+ public string Username { get; set; }
+// public string GameVersion { get; set; }
+// public int UnknownNumber { get; set; } // Seems to increment by 1000 every login attempt
public static LoginData CreateFromString(string str) {
+ do {
+ str = str.Replace("\b", "");
+ } while(str.Contains('\b'));
+
using MemoryStream ms = new(Encoding.ASCII.GetBytes(str));
using BinaryReader reader = new(ms);
LoginData loginData = new();
- reader.ReadBytes(4); // Perhaps a header of sorts?
-
- string number = Encoding.ASCII.GetString(reader.ReadBytes(7)); // Number is stored as text for some reason...
- loginData.UnknownNumber = int.Parse(number);
+ BinaryHelper.ReadUntilByte(reader, 0x20); // Skips to relevant part
- reader.ReadBytes(10); // No clue what this is.
-
- string end = Encoding.ASCII.GetString(reader.ReadBytes(int.MaxValue)); // ReadToEnd 2: Electric Boogaloo
- string[] split = end.Split("bru"); // No idea what it means, but it seems to split the gameversion and username apart
+// byte[] endBytes = reader.ReadBytes((int)(ms.Length - reader.BaseStream.Position));
+// string end = Encoding.ASCII.GetString(endBytes);
- loginData.Username = split[0];
- loginData.GameVersion = split[1];
+ loginData.Username = BinaryHelper.ReadString(reader);
return loginData;
}
diff --git a/ProjectLighthouse/Types/Token.cs b/ProjectLighthouse/Types/Token.cs
index 961a90eb..f17e99b0 100644
--- a/ProjectLighthouse/Types/Token.cs
+++ b/ProjectLighthouse/Types/Token.cs
@@ -1,8 +1,6 @@
-using Microsoft.EntityFrameworkCore;
-
namespace ProjectLighthouse.Types {
- [Keyless]
public class Token {
+ public int TokenId { get; set; }
public int UserId { get; set; }
public string UserToken { get; set; }
}