From 20d958890c4708633abec69b9032a9817ffaed1b Mon Sep 17 00:00:00 2001 From: BtbN Date: Sun, 2 Jun 2019 19:09:49 +0200 Subject: [PATCH] Initial DB schema --- ClanServer/ClanServer.csproj | 2 + ClanServer/ClanServerContext.cs | 37 + ClanServer/Controllers/L44/Gameend.cs | 888 ++++++++++++++++++++++ ClanServer/Controllers/L44/Jbox.cs | 34 + ClanServer/Helpers/ByteArrayHelper.cs | 104 +++ ClanServer/Models/Card.cs | 50 ++ ClanServer/Models/JubeatProfile.cs | 18 + ClanServer/Models/Player.cs | 16 + ClanServer/Properties/launchSettings.json | 1 + ClanServer/Startup.cs | 6 + 10 files changed, 1156 insertions(+) create mode 100644 ClanServer/ClanServerContext.cs create mode 100644 ClanServer/Controllers/L44/Gameend.cs create mode 100644 ClanServer/Controllers/L44/Jbox.cs create mode 100644 ClanServer/Helpers/ByteArrayHelper.cs create mode 100644 ClanServer/Models/Card.cs create mode 100644 ClanServer/Models/JubeatProfile.cs create mode 100644 ClanServer/Models/Player.cs diff --git a/ClanServer/ClanServer.csproj b/ClanServer/ClanServer.csproj index 8901368..62c44f2 100644 --- a/ClanServer/ClanServer.csproj +++ b/ClanServer/ClanServer.csproj @@ -4,11 +4,13 @@ netcoreapp2.2 InProcess ClanServer.Program + true + diff --git a/ClanServer/ClanServerContext.cs b/ClanServer/ClanServerContext.cs new file mode 100644 index 0000000..af81004 --- /dev/null +++ b/ClanServer/ClanServerContext.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +using ClanServer.Models; + +namespace ClanServer +{ + public class ClanServerContext : DbContext + { + public ClanServerContext(DbContextOptions options) + : base(options) + {} + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + var cardEntity = modelBuilder.Entity(); + cardEntity + .HasIndex(card => card.CardId) + .IsUnique(); + cardEntity + .HasIndex(card => card.RefId); + cardEntity + .HasIndex(card => card.DataId); + + var juProfEntity = modelBuilder.Entity(); + juProfEntity + .HasIndex(profile => profile.JID) + .IsUnique(); + } + + public DbSet Players { get; set; } + public DbSet Cards { get; set; } + + public DbSet JubeatProfiles { get; set; } + } +} diff --git a/ClanServer/Controllers/L44/Gameend.cs b/ClanServer/Controllers/L44/Gameend.cs new file mode 100644 index 0000000..1cbfbf9 --- /dev/null +++ b/ClanServer/Controllers/L44/Gameend.cs @@ -0,0 +1,888 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Xml.Linq; +using Microsoft.AspNetCore.Mvc; + +using eAmuseCore.KBinXML; + +using ClanServer.Formatters; +using ClanServer.Routing; + +namespace ClanServer.Controllers.L44 +{ + [ApiController, Route("L44")] + public class GameendController : ControllerBase + { + /* + + + 0 + + + + 1559483385853 + 1559483977121 + 573 + 1 + 0 + 1 + Oromit Arcade + JP-14 + + 01201000009FDCEA1A6C + 8C4E59A1 + + 3 + 2000 + + + + COIN + game.s.normal + 0 + 1 + + + COIN + game.s.free.normal + 0 + 1 + + + + + + 70000183 + 1832734206069547163 + 1559483541000 + + 917287 + 4 + 7 + 24 + 0 + 0 + 0 + 0 + 0 + 0 + 372 + 102 + 13 + 0 + 7 + 1 + 1 + 0 + 0 + 0 + 0 + 917287 + 3 + 1 + 1 + 0 + 0 + 239 191 234 175 190 171 175 186 255 191 190 254 255 255 255 255 155 169 191 233 191 251 127 187 218 251 171 170 250 255 + 239 191 234 175 190 171 175 186 255 191 190 254 255 255 255 255 155 169 191 233 191 251 127 187 218 251 171 170 250 255 + + + + + + + 60000043 + -8966206469043710946 + 1559483685000 + + 939690 + 4 + 7 + 24 + 0 + 0 + 0 + 0 + 0 + 0 + 384 + 95 + 5 + 0 + 1 + 1 + 1 + 0 + 0 + 0 + 0 + 939690 + 19 + 1 + 1 + 0 + 0 + 251 255 255 175 186 238 239 250 251 255 250 171 187 190 238 171 175 187 190 235 250 122 174 235 175 190 175 238 250 255 + 251 255 255 175 186 238 239 250 251 255 250 171 187 190 238 171 175 187 190 235 250 122 174 235 175 190 175 238 250 255 + + + + + + + 60001001 + 624634556024109711 + 1559483966000 + + 915413 + 4 + 7 + 24 + 0 + 0 + 0 + 0 + 0 + 0 + 304 + 76 + 10 + 3 + 6 + 1 + 1 + 0 + 0 + 0 + 0 + 915413 + 3 + 1 + 1 + 0 + 0 + 239 254 239 214 229 253 122 186 182 235 239 191 190 251 186 174 122 234 254 255 251 190 235 251 251 255 187 174 255 255 + 239 254 239 214 229 253 122 186 182 235 239 191 190 251 186 174 122 234 254 255 251 190 235 251 251 255 187 174 255 255 + + + + + + + + 1 + DD389C3FFB6F47BA + 612645048 + CLANTEST + 2 + 0 + + 994 + 949 + 40 + 0 + 0 + 0 + 0 + 45 + 2772390 + 740 + 1 + 7 + 0 + 0 + 844 + 300 + 844 + 0 + 0 + + + 0 + 3 + 24 + + 3 + 6 + 0 + 0 + 1 + 1 + 0 823 0 0 0 + 0 + 0 + 0 + + + + -2013265951 -102760493 1711275733 -1579088899 -108536 -227069 -33554401 16383 0 -1377473 -402653185 -2097153 -1231036417 -786433 -444727297 -1 980541439 -33357824 1077928957 133988323 1075838048 -32706 -234907777 -196609 33138687 -2097152 -907557381 -2 -134217841 -34734081 -524293 -1641628417 -1 -1 -2177 -7532097 -3 264241151 2080768 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + -2013265951 -102760493 1711275733 -1579088899 -108536 -227069 -33554401 16383 0 -1377473 -402653185 -2097153 -1231036417 -786433 -444727297 -1 980541439 -33357824 1077928957 133988323 1075838048 -32706 -234907777 -196609 33138687 -2097152 -907557381 -2 -134217841 -34734081 -524293 -1641628417 -1 -1 -2177 -7532097 -3 264241151 2080768 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 2047 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + -1 7167 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 0 0 0 65536 0 0 0 0 0 1024 1048576 0 0 0 0 0 0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 7167 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + + + + 0 + 0 + + + + + 0 + + + + + + + + + + 800 + + 0 + 0 + + + + + + + + 1559483966000 + 2018070901 + 1 + + + 612645048 + CLANTEST + 0 + 0 + 0 823 0 0 0 + 1 + + + Oromit Arcade + JP-14 + 915413 + 0 + 304 + 76 + 10 + 3 + 6 + 239 254 239 214 229 253 122 186 182 235 239 191 190 251 186 174 122 234 254 255 251 190 235 251 251 255 187 174 255 255 + + + + + 1559483685000 + 2018070901 + 1 + + + 612645048 + CLANTEST + 0 + 0 + 0 823 0 0 0 + 1 + + + Oromit Arcade + JP-14 + 939690 + 0 + 384 + 95 + 5 + 0 + 1 + 251 255 255 175 186 238 239 250 251 255 250 171 187 190 238 171 175 187 190 235 250 122 174 235 175 190 175 238 250 255 + + + + + 1559483541000 + 2018070901 + 1 + + + 612645048 + CLANTEST + 0 + 0 + 0 823 0 0 0 + 1 + + + Oromit Arcade + JP-14 + 917287 + 0 + 372 + 102 + 13 + 0 + 7 + 239 191 234 175 190 171 175 186 255 191 190 254 255 255 255 255 155 169 191 233 191 251 127 187 218 251 171 170 250 255 + + + + + + 2 + BBL31FY455J6TU2Z + 0 + 1 + + + 122 + + + + 3 + 2000 + + + + + 60000043 + 1 + 939690 + 704 + 0 + + + 60001001 + 1 + 915413 + 675 + 0 + + + 70000183 + 1 + 917287 + 664 + 0 + + + + +
4
+ 6 + 67 + 1 +
+ + + + 1 + + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + + + + 30 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 30 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 30 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 30 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 30 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + + + +
+
+
+
+ */ + [HttpPost, Route("8"), XrpcCall("gameend.regist")] + public ActionResult Register([FromBody] EamuseXrpcData data) + { + Console.WriteLine(data.Document); + //TODO: save data + + data.Document = new XDocument(new XElement("response", new XElement("gameend"))); + + return data; + } + + /* + + + 0 + + + + + 3 + 2000 + + + + + 0 + DD389C3FFB6F47BA + 612645048 + CLANTEST + + 1 0 0 0 0 0 0 16 0 0 0 0 0 536870916 0 0 65536 0 4194304 0 0 0 268435456 0 65536 8388624 0 0 0 0 0 0 0 147456 0 0 1073741824 4194312 33554432 205520896 0 0 2080 2 0 512 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + + + 400 + + 1 + 1182 + + + + 3 + 2000 + + + + + + + + + + 0 + + + + + 3 + 2000 + + + + + 0 + DD389C3FFB6F47BA + 612645048 + CLANTEST + + 1 0 0 0 0 0 0 16 0 0 0 0 0 536870916 0 0 65536 0 4194304 0 0 0 268435456 0 65536 8388624 0 0 0 0 0 0 0 147456 0 0 0 4194312 33554432 205520896 0 0 2080 2 0 512 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + + + 700 + + 0 + 0 + + + + 3 + 2000 + + + + + + + */ + + [HttpPost, Route("8"), XrpcCall("gameend.final")] + public ActionResult Final([FromBody] EamuseXrpcData data) + { + Console.WriteLine(data.Document); + //TODO: save data + + data.Document = new XDocument(new XElement("response", new XElement("gameend"))); + + return data; + } + } +} diff --git a/ClanServer/Controllers/L44/Jbox.cs b/ClanServer/Controllers/L44/Jbox.cs new file mode 100644 index 0000000..a7ff027 --- /dev/null +++ b/ClanServer/Controllers/L44/Jbox.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Xml.Linq; +using Microsoft.AspNetCore.Mvc; + +using eAmuseCore.KBinXML; + +using ClanServer.Formatters; +using ClanServer.Routing; + +namespace ClanServer.Controllers.L44 +{ + [ApiController, Route("L44")] + public class JboxController : ControllerBase + { + [HttpPost, Route("8"), XrpcCall("jbox.get_list")] + public ActionResult GetList([FromBody] EamuseXrpcData data) + { + data.Document = new XDocument(new XElement("response", new XElement("jbox"))); + + return data; + } + + [HttpPost, Route("8"), XrpcCall("jbox.get_agreement")] + public ActionResult GetAgreement([FromBody] EamuseXrpcData data) + { + data.Document = new XDocument(new XElement("response", new XElement("jbox"))); + + return data; + } + } +} diff --git a/ClanServer/Helpers/ByteArrayHelper.cs b/ClanServer/Helpers/ByteArrayHelper.cs new file mode 100644 index 0000000..6d0a732 --- /dev/null +++ b/ClanServer/Helpers/ByteArrayHelper.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +namespace ClanServer.Helpers +{ + public static class ByteArrayHelper + { + private static readonly uint[] toHexLookup; + private static unsafe readonly uint* toHexLookupP; + private static readonly byte[] fromHexLookupLo, fromHexLookupHi; + private static unsafe readonly byte* fromHexLookupLoP, fromHexLookupHiP; + + static unsafe ByteArrayHelper() + { + toHexLookup = new uint[256]; + fromHexLookupLo = new byte[256]; + fromHexLookupHi = new byte[256]; + + for (int i = 0; i < 256; ++i) + { + string s = i.ToString("X2"); + if (BitConverter.IsLittleEndian) + toHexLookup[i] = s[0] | ((uint)s[1] << 16); + else + toHexLookup[i] = s[1] | ((uint)s[0] << 16); + + fromHexLookupLo[i] = fromHexLookupHi[i] = 255; + } + + for (int i = 0; i < 16; ++i) + { + int ii = i | (i << 4); + string v = ii.ToString("X2"); + + fromHexLookupHi[v[0]] = (byte)(i << 4); + fromHexLookupLo[v[1]] = (byte)i; + + v = v.ToLower(); + + fromHexLookupHi[v[0]] = (byte)(i << 4); + fromHexLookupLo[v[1]] = (byte)i; + } + + toHexLookupP = (uint*)GCHandle.Alloc(toHexLookup, GCHandleType.Pinned).AddrOfPinnedObject(); + fromHexLookupLoP = (byte*)GCHandle.Alloc(fromHexLookupLo, GCHandleType.Pinned).AddrOfPinnedObject(); + fromHexLookupHiP = (byte*)GCHandle.Alloc(fromHexLookupHi, GCHandleType.Pinned).AddrOfPinnedObject(); + } + + public static unsafe string ToHexString(this byte[] bytes) + { + uint* lookupP = toHexLookupP; + string result = new string(' ', bytes.Length * 2); + + fixed (byte* bytesP = bytes) + fixed (char* resultP = result) + { + uint* resultP2 = (uint*)resultP; + + for (int i = 0; i < bytes.Length; i++) + { + resultP2[i] = lookupP[bytesP[i]]; + } + } + + return result; + } + + public static unsafe byte[] ToBytesFromHex(this string source) + { + if (string.IsNullOrEmpty(source)) + return new byte[0]; + if ((source.Length & 1) != 0) + throw new ArgumentException(); + + int len = source.Length >> 1; + byte[] result = new byte[len]; + + fixed (char* src = source) + fixed (byte* res = result) + { + for (int i = 0; i < len; ++i) + { + char c = src[i * 2]; + byte hi, lo; + + if (c > 255 || (hi = fromHexLookupHiP[c]) == 255) + throw new ArgumentException(); + + c = src[i * 2 + 1]; + + if (c > 255 || (lo = fromHexLookupLoP[c]) == 255) + throw new ArgumentException(); + + res[i] = (byte)(hi | lo); + } + } + + return result; + } + } +} diff --git a/ClanServer/Models/Card.cs b/ClanServer/Models/Card.cs new file mode 100644 index 0000000..7ee5510 --- /dev/null +++ b/ClanServer/Models/Card.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +using ClanServer.Helpers; + +namespace ClanServer.Models +{ + public class Card + { + public int ID { get; set; } + + [Required] + public Player Player { get; set; } + + [Required] + [MaxLength(8), MinLength(8)] + public byte[] CardId { get; set; } + + [Required] + [MaxLength(8), MinLength(8)] + public byte[] DataId { get; set; } + + [Required] + [MaxLength(8), MinLength(8)] + public byte[] RefId { get; set; } + + [NotMapped] + public string CardIdStr + { + get => CardId.ToHexString(); + set => CardId = value.ToBytesFromHex(); + } + + [NotMapped] + public string DataIdStr + { + get => DataId.ToHexString(); + set => DataId = value.ToBytesFromHex(); + } + + [NotMapped] + public string RefIdStr + { + get => RefId.ToHexString(); + set => RefId = value.ToBytesFromHex(); + } + } +} \ No newline at end of file diff --git a/ClanServer/Models/JubeatProfile.cs b/ClanServer/Models/JubeatProfile.cs new file mode 100644 index 0000000..5fb87b3 --- /dev/null +++ b/ClanServer/Models/JubeatProfile.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ClanServer.Models +{ + public class JubeatProfile + { + public int ID { get; set; } + + [Required] + public int JID { get; set; } + + [Required] + public string Name { get; set; } + } +} diff --git a/ClanServer/Models/Player.cs b/ClanServer/Models/Player.cs new file mode 100644 index 0000000..8270387 --- /dev/null +++ b/ClanServer/Models/Player.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ClanServer.Models +{ + public class Player + { + public int ID { get; set; } + + public ICollection Cards { get; set; } + + public JubeatProfile JubeatProfile { get; set; } + } +} diff --git a/ClanServer/Properties/launchSettings.json b/ClanServer/Properties/launchSettings.json index 734fe6f..386d537 100644 --- a/ClanServer/Properties/launchSettings.json +++ b/ClanServer/Properties/launchSettings.json @@ -2,6 +2,7 @@ "profiles": { "ClanServer": { "commandName": "Project", + "workingDirectory": ".", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/ClanServer/Startup.cs b/ClanServer/Startup.cs index b79f74c..8e9aaf9 100644 --- a/ClanServer/Startup.cs +++ b/ClanServer/Startup.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -25,6 +26,11 @@ namespace ClanServer public void ConfigureServices(IServiceCollection services) { + services.AddDbContext(options => + { + options.UseSqlite("Data Source=clanserver.db"); + }); + services .AddMvc(options => {