1
0
mirror of synced 2025-01-31 12:23:44 +01:00

Update online matching logic

This commit is contained in:
asesidaa 2022-08-01 21:39:14 +08:00
parent 1ab148a50a
commit c185497502
3 changed files with 42 additions and 28 deletions

View File

@ -12,6 +12,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="CertificateManager" Version="1.0.8" /> <PackageReference Include="CertificateManager" Version="1.0.8" />
<PackageReference Include="ChoETL" Version="1.2.1.47" /> <PackageReference Include="ChoETL" Version="1.2.1.47" />
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
<PackageReference Include="Config.Net" Version="4.19.0" /> <PackageReference Include="Config.Net" Version="4.19.0" />
<PackageReference Include="Config.Net.Json" Version="4.19.0" /> <PackageReference Include="Config.Net.Json" Version="4.19.0" />
<PackageReference Include="EmbedIO" Version="3.5.0" /> <PackageReference Include="EmbedIO" Version="3.5.0" />

View File

@ -19,7 +19,12 @@ public class CardServiceController : WebApiController
private readonly SQLiteConnection cardSqLiteConnection; private readonly SQLiteConnection cardSqLiteConnection;
private readonly SQLiteConnection musicSqLiteConnection; private readonly SQLiteConnection musicSqLiteConnection;
private static readonly ConcurrentDictionary<long, OnlineMatchingEntry> OnlineMatchingEntries = new(); private static readonly ConcurrentDictionary<long, List<OnlineMatchingEntry>> OnlineMatchingEntries = new()
{
[0xDEADBEEF] = new List<OnlineMatchingEntry>(),
[0xCAFEBABE] = new List<OnlineMatchingEntry>(),
[0xD0D0CACA] = new List<OnlineMatchingEntry>()
};
public CardServiceController() public CardServiceController()
{ {
@ -620,23 +625,31 @@ public class CardServiceController : WebApiController
entry.CardId = cardId; entry.CardId = cardId;
entry.MatchingId = 0xDEADBEEF; entry.MatchingId = 0xDEADBEEF;
entry.EntryNo = OnlineMatchingEntries.Count; entry.EntryNo = OnlineMatchingEntries[0xDEADBEEF].Count;
entry.EntryStart = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); entry.EntryStart = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
entry.MatchingTimeout = 10; entry.MatchingTimeout = 20;
entry.MatchingRemainingTime = 3; entry.MatchingRemainingTime = 3;
entry.MatchingWaitTime = 3; entry.MatchingWaitTime = 10;
entry.Status = 1; entry.Status = 1;
entry.Dump().Info(); entry.Dump().Info();
OnlineMatchingEntries[cardId] = entry; var entries = OnlineMatchingEntries[0xDEADBEEF];
var existing = entries.Find(matchingEntry => matchingEntry.CardId == cardId);
if (existing is not null)
{
"Card id already exist in entry! Previous match is not cleaned up! Clearing now".Warn();
entries.Clear();
}
OnlineMatchingEntries[0xDEADBEEF].Add(entry);
return GenerateRecordsXml(OnlineMatchingEntries.Values.ToList(), Configs.ONLINE_MATCHING_XPATH); return GenerateRecordsXml(OnlineMatchingEntries[0xDEADBEEF], Configs.ONLINE_MATCHING_XPATH);
} }
private static string UpdateOnlineMatching(long cardId, string xmlData) private static string UpdateOnlineMatching(long cardId, string xmlData)
{ {
var reader = new ChoXmlReader<OnlineMatchingUpdateData>(new StringReader(xmlData)); var reader = new ChoXmlReader<OnlineMatchingUpdateData>(new StringReader(xmlData));
var data = reader.Read(); var data = reader.Read();
var entry = OnlineMatchingEntries.GetValueOrDefault(cardId); var entries = OnlineMatchingEntries[0xDEADBEEF];
var entry = entries.Find(matchingEntry => matchingEntry.CardId == cardId);
if (entry is null) if (entry is null)
{ {
throw new HttpException(400,"Entry for this card id does not exist!"); throw new HttpException(400,"Entry for this card id does not exist!");
@ -651,13 +664,13 @@ public class CardServiceController : WebApiController
{ {
entry.Status = 3; entry.Status = 3;
entry.Dump().Info(); entry.Dump().Info();
return GenerateRecordsXml(OnlineMatchingEntries.Values.ToList(), Configs.ONLINE_MATCHING_XPATH); return GenerateRecordsXml(OnlineMatchingEntries[0xDEADBEEF], Configs.ONLINE_MATCHING_XPATH);
} }
entry.MatchingRemainingTime--; entry.MatchingRemainingTime--;
entry.Dump().Info(); entry.Dump().Info();
return GenerateRecordsXml(OnlineMatchingEntries.Values.ToList(), Configs.ONLINE_MATCHING_XPATH); return GenerateRecordsXml(OnlineMatchingEntries[0xDEADBEEF], Configs.ONLINE_MATCHING_XPATH);
} }
private static string UploadOnlineMatchingResult(long cardId, string xmlData) private static string UploadOnlineMatchingResult(long cardId, string xmlData)
@ -665,7 +678,8 @@ public class CardServiceController : WebApiController
var reader = new ChoXmlReader<OnlineMatchingResultData>(new StringReader(xmlData)); var reader = new ChoXmlReader<OnlineMatchingResultData>(new StringReader(xmlData));
var data = reader.Read(); var data = reader.Read();
var entry = OnlineMatchingEntries.GetValueOrDefault(cardId); var entries = OnlineMatchingEntries[0xDEADBEEF];
var entry = entries.Find(matchingEntry => matchingEntry.CardId == cardId);
if (entry is null) if (entry is null)
{ {
throw new HttpException(400,"Entry for this card id does not exist!"); throw new HttpException(400,"Entry for this card id does not exist!");
@ -676,8 +690,7 @@ public class CardServiceController : WebApiController
throw new HttpException(400,"Matching Id mismatch!"); throw new HttpException(400,"Matching Id mismatch!");
} }
// Only one matching at a time OnlineMatchingEntries[0xDEADBEEF].Remove(entry);
OnlineMatchingEntries.Clear();
var result = new OnlineMatchingResult var result = new OnlineMatchingResult
{ {
Status = 1 Status = 1

View File

@ -6,51 +6,51 @@ namespace GCLocalServerRewrite.models;
public class OnlineMatchingResultData public class OnlineMatchingResultData
{ {
[ChoXmlElementRecordField(FieldName = "event_id")] [ChoXmlElementRecordField(FieldName = "event_id")]
public int EventId { get; set; } public long EventId { get; set; }
[ChoXmlElementRecordField(FieldName = "matching_id")] [ChoXmlElementRecordField(FieldName = "matching_id")]
public int MatchingId { get; set; } public long MatchingId { get; set; }
[ChoXmlElementRecordField(FieldName = "class_id")] [ChoXmlElementRecordField(FieldName = "class_id")]
public int ClassId { get; set; } public long ClassId { get; set; }
[ChoXmlElementRecordField(FieldName = "group_id")] [ChoXmlElementRecordField(FieldName = "group_id")]
public int GroupId { get; set; } public long GroupId { get; set; }
[ChoXmlElementRecordField(FieldName = "result_score")] [ChoXmlElementRecordField(FieldName = "result_score")]
public int ResultScore { get; set; } public long ResultScore { get; set; }
[ChoXmlElementRecordField(FieldName = "result_star")] [ChoXmlElementRecordField(FieldName = "result_star")]
public int ResultStar { get; set; } public long ResultStar { get; set; }
[ChoXmlElementRecordField(FieldName = "result_rank")] [ChoXmlElementRecordField(FieldName = "result_rank")]
public int ResultRank { get; set; } public long ResultRank { get; set; }
[ChoXmlElementRecordField(FieldName = "music_id_1st")] [ChoXmlElementRecordField(FieldName = "music_id_1st")]
public int MusicIdFirst { get; set; } public long MusicIdFirst { get; set; }
[ChoXmlElementRecordField(FieldName = "music_id_2nd")] [ChoXmlElementRecordField(FieldName = "music_id_2nd")]
public int MusicIdSecond { get; set; } public long MusicIdSecond { get; set; }
[ChoXmlElementRecordField(FieldName = "music_id_3rd")] [ChoXmlElementRecordField(FieldName = "music_id_3rd")]
public int MusicIdThird { get; set; } public long MusicIdThird { get; set; }
[ChoXmlElementRecordField(FieldName = "difficulty_lv_1st")] [ChoXmlElementRecordField(FieldName = "difficulty_lv_1st")]
public int DifficultyFirst { get; set; } public long DifficultyFirst { get; set; }
[ChoXmlElementRecordField(FieldName = "difficulty_lv_2nd")] [ChoXmlElementRecordField(FieldName = "difficulty_lv_2nd")]
public int DifficultySecond { get; set; } public long DifficultySecond { get; set; }
[ChoXmlElementRecordField(FieldName = "difficulty_lv_3rd")] [ChoXmlElementRecordField(FieldName = "difficulty_lv_3rd")]
public int DifficultyThird { get; set; } public long DifficultyThird { get; set; }
[ChoXmlElementRecordField(FieldName = "item_id_1st")] [ChoXmlElementRecordField(FieldName = "item_id_1st")]
public int ItemIdFirst { get; set; } public long ItemIdFirst { get; set; }
[ChoXmlElementRecordField(FieldName = "item_id_2nd")] [ChoXmlElementRecordField(FieldName = "item_id_2nd")]
public int ItemIdSecond { get; set; } public long ItemIdSecond { get; set; }
[ChoXmlElementRecordField(FieldName = "item_id_3rd")] [ChoXmlElementRecordField(FieldName = "item_id_3rd")]
public int ItemIdThird { get; set; } public long ItemIdThird { get; set; }
} }