mirror of
https://github.com/BtbN/ClanServer.git
synced 2026-03-26 20:14:48 -05:00
Refactor ID storage a bit
This commit is contained in:
parent
81a3e6b8be
commit
f21f01fbb6
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -30,11 +30,23 @@ namespace ClanServer
|
|||
|
||||
var jbScoreEntity = modelBuilder.Entity<JubeatScore>();
|
||||
jbScoreEntity
|
||||
.HasIndex(score => new { score.ProfileID, score.MusicID, score.Seq })
|
||||
.IsUnique();
|
||||
.HasIndex(score => new { score.ProfileID, score.MusicID, score.Seq });
|
||||
jbScoreEntity
|
||||
.HasIndex(score => new { score.ProfileID, score.MusicID });
|
||||
jbScoreEntity
|
||||
.HasIndex(score => new { score.MusicID, score.Seq });
|
||||
jbScoreEntity
|
||||
.HasIndex(score => score.ProfileID);
|
||||
|
||||
var jbHighScoreEntity = modelBuilder.Entity<JubeatHighscore>();
|
||||
jbHighScoreEntity
|
||||
.HasIndex(score => new { score.ProfileID, score.MusicID, score.Seq })
|
||||
.IsUnique();
|
||||
jbHighScoreEntity
|
||||
.HasIndex(score => new { score.ProfileID, score.MusicID });
|
||||
jbHighScoreEntity
|
||||
.HasIndex(score => new { score.MusicID, score.Seq });
|
||||
jbHighScoreEntity
|
||||
.HasIndex(score => score.ProfileID);
|
||||
}
|
||||
|
||||
|
|
@ -44,5 +56,6 @@ namespace ClanServer
|
|||
public DbSet<JubeatClanProfileData> JubeatClanProfileData { get; set; }
|
||||
public DbSet<JubeatProfile> JubeatProfiles { get; set; }
|
||||
public DbSet<JubeatScore> JubeatScores { get; set; }
|
||||
public DbSet<JubeatHighscore> JubeatHighscores { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -27,21 +27,21 @@ namespace ClanServer.Controllers.Core
|
|||
{
|
||||
XElement cardmng = data.Document.Element("call").Element("cardmng");
|
||||
|
||||
byte[] cardId = cardmng.Attribute("cardid").Value.ToBytesFromHex();
|
||||
string cardId = cardmng.Attribute("cardid").Value.ToUpper();
|
||||
string cardType = cardmng.Attribute("cardtype").Value;
|
||||
string update = cardmng.Attribute("update").Value;
|
||||
|
||||
var card = ctx.Cards.SingleOrDefault(c => c.CardId.SequenceEqual(cardId));
|
||||
var card = ctx.Cards.SingleOrDefault(c => c.CardId == cardId);
|
||||
|
||||
if (card != null)
|
||||
{
|
||||
data.Document = new XDocument(new XElement("response", new XElement("cardmng",
|
||||
new XAttribute("binded", "1"),
|
||||
new XAttribute("dataid", card.DataIdStr),
|
||||
new XAttribute("dataid", card.DataId),
|
||||
new XAttribute("ecflag", "1"),
|
||||
new XAttribute("newflag", "0"),
|
||||
new XAttribute("expired", "0"),
|
||||
new XAttribute("refid", card.RefIdStr)
|
||||
new XAttribute("refid", card.RefId)
|
||||
)));
|
||||
}
|
||||
else
|
||||
|
|
@ -60,11 +60,11 @@ namespace ClanServer.Controllers.Core
|
|||
XElement cardmng = data.Document.Element("call").Element("cardmng");
|
||||
|
||||
string pass = cardmng.Attribute("pass").Value;
|
||||
byte[] refId = cardmng.Attribute("refid").Value.ToBytesFromHex();
|
||||
string refId = cardmng.Attribute("refid").Value.ToUpper();
|
||||
|
||||
Card card = await ctx.Cards
|
||||
.Include(c => c.Player)
|
||||
.SingleOrDefaultAsync(c => c.RefId.SequenceEqual(refId));
|
||||
.SingleOrDefaultAsync(c => c.RefId == refId);
|
||||
|
||||
int status;
|
||||
if (card != null && card.Player != null && card.Player.Passwd == pass)
|
||||
|
|
@ -84,11 +84,10 @@ namespace ClanServer.Controllers.Core
|
|||
{
|
||||
XElement cardmng = data.Document.Element("call").Element("cardmng");
|
||||
|
||||
string cardId = cardmng.Attribute("cardid").Value;
|
||||
byte[] cardIdBytes = cardId.ToBytesFromHex();
|
||||
string cardId = cardmng.Attribute("cardid").Value.ToUpper();
|
||||
string passwd = cardmng.Attribute("passwd").Value;
|
||||
|
||||
if (await ctx.Cards.AnyAsync(c => c.CardId.SequenceEqual(cardIdBytes)))
|
||||
if (await ctx.Cards.AnyAsync(c => c.CardId == cardId))
|
||||
{
|
||||
data.Document = new XDocument(new XElement("response", new XElement("cardmng")));
|
||||
return data;
|
||||
|
|
@ -109,9 +108,9 @@ namespace ClanServer.Controllers.Core
|
|||
|
||||
Card card = new Card()
|
||||
{
|
||||
CardId = cardIdBytes,
|
||||
DataId = dataId,
|
||||
RefId = refId,
|
||||
CardId = cardId,
|
||||
DataId = dataId.ToHexString(),
|
||||
RefId = refId.ToHexString(),
|
||||
Player = player
|
||||
};
|
||||
|
||||
|
|
@ -121,8 +120,8 @@ namespace ClanServer.Controllers.Core
|
|||
await ctx.SaveChangesAsync();
|
||||
|
||||
data.Document = new XDocument(new XElement("response", new XElement("cardmng",
|
||||
new XAttribute("dataid", card.DataIdStr),
|
||||
new XAttribute("refid", card.RefIdStr)
|
||||
new XAttribute("dataid", card.DataId),
|
||||
new XAttribute("refid", card.RefId)
|
||||
)));
|
||||
|
||||
return data;
|
||||
|
|
|
|||
|
|
@ -100,21 +100,12 @@ namespace ClanServer.Controllers.L44
|
|||
int musicId = int.Parse(tune.Element("music").Value);
|
||||
sbyte seq = sbyte.Parse(tuneScore.Attribute("seq").Value);
|
||||
|
||||
JubeatScore score = ctx.JubeatScores
|
||||
.Where(s => s.MusicID == musicId && s.Seq == seq && s.ProfileID == profile.ID)
|
||||
.SingleOrDefault();
|
||||
|
||||
if (score == null)
|
||||
JubeatScore score = new JubeatScore()
|
||||
{
|
||||
score = new JubeatScore()
|
||||
{
|
||||
ProfileID = profile.ID,
|
||||
MusicID = musicId,
|
||||
Seq = seq
|
||||
};
|
||||
|
||||
ctx.JubeatScores.Add(score);
|
||||
}
|
||||
ProfileID = profile.ID,
|
||||
MusicID = musicId,
|
||||
Seq = seq
|
||||
};
|
||||
|
||||
score.Timestamp = long.Parse(tune.Element("timestamp").Value);
|
||||
score.Score = int.Parse(tunePlayer.Element("score").Value);
|
||||
|
|
@ -126,15 +117,40 @@ namespace ClanServer.Controllers.L44
|
|||
score.NumGood = short.Parse(tunePlayer.Element("nr_good").Value);
|
||||
score.NumPoor = short.Parse(tunePlayer.Element("nr_poor").Value);
|
||||
score.NumMiss = short.Parse(tunePlayer.Element("nr_miss").Value);
|
||||
score.BestScore = int.Parse(tunePlayer.Element("best_score").Value);
|
||||
score.BestClear = int.Parse(tunePlayer.Element("best_clear").Value);
|
||||
score.PlayCount = int.Parse(tunePlayer.Element("play_cnt").Value);
|
||||
score.ClearCount = int.Parse(tunePlayer.Element("clear_cnt").Value);
|
||||
score.FcCount = int.Parse(tunePlayer.Element("fc_cnt").Value);
|
||||
score.ExcCount = int.Parse(tunePlayer.Element("ex_cnt").Value);
|
||||
|
||||
string[] mbarStrs = tunePlayer.Element("mbar").Value.Split(' ');
|
||||
score.MBar = Array.ConvertAll(mbarStrs, s => byte.Parse(s));
|
||||
string[] mbarStrs = tunePlayer.Element("play_mbar").Value.Split(' ');
|
||||
score.Bar = Array.ConvertAll(mbarStrs, s => byte.Parse(s));
|
||||
|
||||
ctx.JubeatScores.Add(score);
|
||||
|
||||
JubeatHighscore highscore = ctx.JubeatHighscores
|
||||
.Where(s => s.MusicID == musicId && s.Seq == seq && s.ProfileID == profile.ID)
|
||||
.SingleOrDefault();
|
||||
|
||||
if (highscore == null)
|
||||
{
|
||||
highscore = new JubeatHighscore()
|
||||
{
|
||||
ProfileID = profile.ID,
|
||||
MusicID = musicId,
|
||||
Seq = seq
|
||||
};
|
||||
|
||||
ctx.JubeatHighscores.Add(highscore);
|
||||
}
|
||||
|
||||
if (score.Score > highscore.Score)
|
||||
highscore.Timestamp = score.Timestamp;
|
||||
|
||||
highscore.Score = int.Parse(tunePlayer.Element("best_score").Value);
|
||||
highscore.Clear = sbyte.Parse(tunePlayer.Element("best_clear").Value);
|
||||
highscore.PlayCount = int.Parse(tunePlayer.Element("play_cnt").Value);
|
||||
highscore.ClearCount = int.Parse(tunePlayer.Element("clear_cnt").Value);
|
||||
highscore.FcCount = int.Parse(tunePlayer.Element("fc_cnt").Value);
|
||||
highscore.ExcCount = int.Parse(tunePlayer.Element("ex_cnt").Value);
|
||||
|
||||
mbarStrs = tunePlayer.Element("mbar").Value.Split(' ');
|
||||
highscore.Bar = Array.ConvertAll(mbarStrs, s => byte.Parse(s));
|
||||
}
|
||||
|
||||
XElement jubility = playerE.Element("jubility");
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace ClanServer.Controllers.L44
|
|||
{
|
||||
XElement gametop = data.Document.Element("call").Element("gametop");
|
||||
XElement player = gametop.Element("data").Element("player");
|
||||
byte[] refId = player.Element("refid").Value.ToBytesFromHex();
|
||||
string refId = player.Element("refid").Value.ToUpper();
|
||||
string name = player.Element("name").Value;
|
||||
|
||||
Card card = await ctx.Cards
|
||||
|
|
@ -50,7 +50,7 @@ namespace ClanServer.Controllers.L44
|
|||
.ThenInclude(p => p.Jubilitys)
|
||||
.Include(c => c.Player.JubeatProfile.ClanData)
|
||||
.Include(c => c.Player.JubeatProfile.ClanSettings)
|
||||
.SingleOrDefaultAsync(c => c.RefId.SequenceEqual(refId));
|
||||
.SingleOrDefaultAsync(c => c.RefId == refId);
|
||||
|
||||
if (card == null || card.Player == null)
|
||||
return NotFound();
|
||||
|
|
@ -86,14 +86,14 @@ namespace ClanServer.Controllers.L44
|
|||
var gametop = data.Document.Element("call").Element("gametop");
|
||||
var player = gametop.Element("data").Element("player");
|
||||
|
||||
byte[] refId = player.Element("refid").Value.ToBytesFromHex();
|
||||
string refId = player.Element("refid").Value.ToUpper();
|
||||
|
||||
Card card = await ctx.Cards
|
||||
.Include(c => c.Player.JubeatProfile)
|
||||
.ThenInclude(p => p.Jubilitys)
|
||||
.Include(c => c.Player.JubeatProfile.ClanData)
|
||||
.Include(c => c.Player.JubeatProfile.ClanSettings)
|
||||
.SingleOrDefaultAsync(c => c.RefId.SequenceEqual(refId));
|
||||
.SingleOrDefaultAsync(c => c.RefId == refId);
|
||||
|
||||
if (card == null || card.Player == null || card.Player.JubeatProfile == null)
|
||||
return NotFound();
|
||||
|
|
@ -473,10 +473,12 @@ namespace ClanServer.Controllers.L44
|
|||
if (profile == null)
|
||||
return NotFound();
|
||||
|
||||
var scoreGroups = ctx.JubeatScores
|
||||
var scoreGroups = ctx.JubeatHighscores
|
||||
.Where(s => s.ProfileID == profile.ID)
|
||||
.GroupBy(s => s.MusicID);
|
||||
|
||||
Console.WriteLine(scoreGroups.ToString());
|
||||
|
||||
XElement mdataList = new XElement("mdata_list");
|
||||
|
||||
foreach (var scoreGroup in scoreGroups)
|
||||
|
|
@ -489,17 +491,17 @@ namespace ClanServer.Controllers.L44
|
|||
var exCnt = new int[3];
|
||||
var bars = new[] { new byte[30], new byte[30], new byte[30] };
|
||||
|
||||
foreach (JubeatScore score in scoreGroup)
|
||||
foreach (JubeatHighscore highscore in scoreGroup)
|
||||
{
|
||||
int seq = score.Seq;
|
||||
int seq = highscore.Seq;
|
||||
|
||||
scoreRes[seq] = score.Score;
|
||||
clearRes[seq] = score.Clear;
|
||||
playCnt[seq] = score.PlayCount;
|
||||
clearCnt[seq] = score.ClearCount;
|
||||
fcCnt[seq] = score.FcCount;
|
||||
exCnt[seq] = score.ExcCount;
|
||||
bars[seq] = score.MBar;
|
||||
scoreRes[seq] = highscore.Score;
|
||||
clearRes[seq] = highscore.Clear;
|
||||
playCnt[seq] = highscore.PlayCount;
|
||||
clearCnt[seq] = highscore.ClearCount;
|
||||
fcCnt[seq] = highscore.FcCount;
|
||||
exCnt[seq] = highscore.ExcCount;
|
||||
bars[seq] = highscore.Bar;
|
||||
}
|
||||
|
||||
mdataList.Add(new XElement("music", new XAttribute("music_id", scoreGroup.Key),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
|
@ -15,36 +15,15 @@ namespace ClanServer.Models
|
|||
public int PlayerID { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(8), MinLength(8)]
|
||||
public byte[] CardId { get; set; }
|
||||
[MaxLength(16), MinLength(16)]
|
||||
public string CardId { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(8), MinLength(8)]
|
||||
public byte[] DataId { get; set; }
|
||||
[MaxLength(16), MinLength(16)]
|
||||
public string 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();
|
||||
}
|
||||
[MaxLength(16), MinLength(16)]
|
||||
public string RefId { get; set; }
|
||||
}
|
||||
}
|
||||
38
ClanServer/Models/JubeatHighscore.cs
Normal file
38
ClanServer/Models/JubeatHighscore.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ClanServer.Models
|
||||
{
|
||||
public class JubeatHighscore
|
||||
{
|
||||
public int ID { get; set; }
|
||||
|
||||
[Required]
|
||||
public JubeatProfile Profile { get; set; }
|
||||
public int ProfileID { get; set; }
|
||||
|
||||
public long Timestamp { get; set; }
|
||||
|
||||
public int MusicID { get; set; }
|
||||
|
||||
[Range(0, 2)]
|
||||
public sbyte Seq { get; set; }
|
||||
|
||||
public int Score { get; set; }
|
||||
|
||||
public sbyte Clear { get; set; }
|
||||
|
||||
public int PlayCount { get; set; }
|
||||
|
||||
public int ClearCount { get; set; }
|
||||
|
||||
public int FcCount { get; set; }
|
||||
|
||||
public int ExcCount { get; set; }
|
||||
|
||||
[MinLength(30), MaxLength(30)]
|
||||
public byte[] Bar { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
|
@ -22,5 +22,7 @@ namespace ClanServer.Models
|
|||
public ICollection<JubeatClanJubility> Jubilitys { get; set; }
|
||||
|
||||
public ICollection<JubeatScore> Scores { get; set; }
|
||||
|
||||
public ICollection<JubeatHighscore> Highscores { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
|
@ -17,6 +17,7 @@ namespace ClanServer.Models
|
|||
|
||||
public int MusicID { get; set; }
|
||||
|
||||
[Range(0, 2)]
|
||||
public sbyte Seq { get; set; }
|
||||
|
||||
public int Score { get; set; }
|
||||
|
|
@ -37,19 +38,7 @@ namespace ClanServer.Models
|
|||
|
||||
public bool IsHazardMode { get; set; }
|
||||
|
||||
public int BestScore { get; set; }
|
||||
|
||||
public int BestClear { get; set; }
|
||||
|
||||
public int PlayCount { get; set; }
|
||||
|
||||
public int ClearCount { get; set; }
|
||||
|
||||
public int FcCount { get; set; }
|
||||
|
||||
public int ExcCount { get; set; }
|
||||
|
||||
[MinLength(30), MaxLength(30)]
|
||||
public byte[] MBar { get; set; }
|
||||
public byte[] Bar { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Console;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ClanServer
|
||||
|
|
@ -17,8 +18,16 @@ namespace ClanServer
|
|||
{
|
||||
public const int Port = 9091;
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
#pragma warning disable CS0618
|
||||
public static readonly LoggerFactory LogFactory
|
||||
= new LoggerFactory(new[] { new ConsoleLoggerProvider((_, __) => true, true) });
|
||||
#pragma warning restore CS0618
|
||||
|
||||
private readonly IHostingEnvironment CurEnv;
|
||||
|
||||
public Startup(IHostingEnvironment env, IConfiguration configuration)
|
||||
{
|
||||
CurEnv = env;
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +40,9 @@ namespace ClanServer
|
|||
services
|
||||
.AddDbContext<ClanServerContext>(options =>
|
||||
{
|
||||
if (CurEnv.IsDevelopment())
|
||||
options.UseLoggerFactory(LogFactory);
|
||||
|
||||
options.UseSqlite("Data Source=clanserver.db");
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user