1
0
mirror of synced 2024-11-24 06:20:12 +01:00

Add online matching testing code

Add event download code
This commit is contained in:
asesidaa 2022-07-16 16:03:56 +08:00
parent 80b69400d5
commit a5fea98d59
10 changed files with 186 additions and 48 deletions

View File

@ -4,4 +4,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fcol/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Fcol/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Incom/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Incom/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pcol/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Pcol/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Respone/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/UserDictionary/Words/=Respone/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tenpo/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -50,10 +50,6 @@
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content> </Content>
<None Remove="GC-local-server-rewrite.exe.config.xml" /> <None Remove="GC-local-server-rewrite.exe.config.xml" />
<None Include="GC-local-server-rewrite.exe.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
<None Remove="db\music4MAX.db3" /> <None Remove="db\music4MAX.db3" />
<Content Include="db\music4MAX.db3"> <Content Include="db\music4MAX.db3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="AvatarCount" value="323"/>
<add key="NavigatorCount" value="94"/>
<add key="ItemCount" value="21"/>
<add key="SkinCount" value="21"/>
<add key="SeCount" value="26"/>
<add key="TitleCount" value="5273"/>
<add key="MusicDBName" value="music4MAX465.db3"/>
<add key="ServerIp" value="127.0.0.1"/>
</appSettings>
</configuration>

View File

@ -32,7 +32,7 @@ internal class Program
Terminal.Flush(); Terminal.Flush();
Console.WriteLine("Press any key to exit."); Console.WriteLine("Press any key to exit.");
WaitForKeypress(); Console.ReadKey(true);
} }
private static void InitializeLogging() private static void InitializeLogging()
@ -67,7 +67,7 @@ internal class Program
// Be sure to run in parallel. // Be sure to run in parallel.
await Task.Yield(); await Task.Yield();
"Press any key to stop the web server.".Info(nameof(Program)); "Press x to stop the web server.".Info(nameof(Program));
WaitForKeypress(); WaitForKeypress();
"Stopping...".Info(nameof(Program)); "Stopping...".Info(nameof(Program));
cancel(); cancel();
@ -78,12 +78,17 @@ internal class Program
/// </summary> /// </summary>
private static void WaitForKeypress() private static void WaitForKeypress()
{ {
while (Console.KeyAvailable) ConsoleKeyInfo consoleKeyInfo;
do
{ {
Console.ReadKey(true); while (Console.KeyAvailable == false)
{
Thread.Sleep(250);
} }
Console.ReadKey(true); consoleKeyInfo = Console.ReadKey(true);
} while (consoleKeyInfo.Key != ConsoleKey.X);
} }
private static void LogConfigValues() private static void LogConfigValues()

View File

@ -4,7 +4,7 @@ namespace GCLocalServerRewrite.common;
public static class Configs public static class Configs
{ {
public const bool USE_FILE_CACHE = false; public const bool USE_FILE_CACHE = true;
public const string ROOT_CA_CN = "Taito Arcade Machine CA"; public const string ROOT_CA_CN = "Taito Arcade Machine CA";
@ -126,6 +126,8 @@ public static class Configs
public const string RANK_STATUS_XPATH = $"{ROOT_XPATH}/ranking_status"; public const string RANK_STATUS_XPATH = $"{ROOT_XPATH}/ranking_status";
public const string ONLINE_MATCHING_XPATH = $"{ROOT_XPATH}/online_matching/record";
public const int FIRST_CONFIG_PCOL1 = 0; public const int FIRST_CONFIG_PCOL1 = 0;
public const int SECOND_CONFIG_PCOL1 = 1; public const int SECOND_CONFIG_PCOL1 = 1;
public const int CONFIG_PCOL2 = 0; public const int CONFIG_PCOL2 = 0;
@ -159,6 +161,7 @@ public static class Configs
public const string DEFAULT_SERVER_IP = "127.0.0.1"; public const string DEFAULT_SERVER_IP = "127.0.0.1";
public const string DEFAULT_RELAY_SERVER = "127.0.0.1"; public const string DEFAULT_RELAY_SERVER = "127.0.0.1";
public const int DEFAULT_RELAY_PORT = 54321; public const int DEFAULT_RELAY_PORT = 54321;
public const string DEFAULT_EVENT_FOLDER = "event";
public static readonly IReadOnlyList<int> DEFAULT_UNLOCKABLE_SONGS = new[] public static readonly IReadOnlyList<int> DEFAULT_UNLOCKABLE_SONGS = new[]
{ {

View File

@ -31,6 +31,9 @@ public interface IAppSettings
[Option(DefaultValue = Configs.DEFAULT_SERVER_IP)] [Option(DefaultValue = Configs.DEFAULT_SERVER_IP)]
string ServerIp { get; } string ServerIp { get; }
[Option(DefaultValue = Configs.DEFAULT_EVENT_FOLDER)]
string EventFolder { get; }
[Option(DefaultValue = Configs.DEFAULT_RELAY_SERVER)] [Option(DefaultValue = Configs.DEFAULT_RELAY_SERVER)]
string RelayServer { get; } string RelayServer { get; }

View File

@ -6,9 +6,10 @@
"SeCount": 26, "SeCount": 26,
"TitleCount": 5530, "TitleCount": 5530,
"CardDbName": "card.db3", "CardDbName": "card.db3",
"MusicDbName": "music471.db3", "MusicDbName": "music471omni.db3",
"ServerIp": "127.0.0.1", "ServerIp": "127.0.0.1",
"RelayServer": "26.56.10.224", "EventFolder": "event",
"RelayServer": "127.0.0.1",
"RelayPort": 54321, "RelayPort": 54321,
"UnlockableSongIds": [ "UnlockableSongIds": [
11, 13, 149, 273, 291, 320, 321, 371, 378, 384, 464, 471, 474, 475, 492, 494, 498, 520, 11, 13, 149, 273, 291, 320, 321, 371, 378, 384, 464, 471, 474, 475, 492, 494, 498, 520,
@ -69,7 +70,7 @@
"FileName": "/event_unlock_20201125.cmp", "FileName": "/event_unlock_20201125.cmp",
"NotBeforeUnixTime": 1335677127, "NotBeforeUnixTime": 1335677127,
"NotAfterUnixTime": 1966397127, "NotAfterUnixTime": 1966397127,
"Md5": "623b0f10125cbe19c5394d992930ae8c", "Md5": "534a253e3de8360c2beff49a5f120105",
"Index": 8 "Index": 8
} }
] ]

View File

@ -18,6 +18,8 @@ public class CardServiceController : WebApiController
private readonly SQLiteConnection cardSqLiteConnection; private readonly SQLiteConnection cardSqLiteConnection;
private readonly SQLiteConnection musicSqLiteConnection; private readonly SQLiteConnection musicSqLiteConnection;
private static Dictionary<long, OnlineMatchingEntry> OnlineMatchingEntries = new();
public CardServiceController() public CardServiceController()
{ {
cardSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.SETTINGS.CardDbName); cardSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.SETTINGS.CardDbName);
@ -172,8 +174,8 @@ public class CardServiceController : WebApiController
{ {
return ConstructResponse(TotalTrophy(cardId)); return ConstructResponse(TotalTrophy(cardId));
} }
case CardRequestType.SessionStart: case CardRequestType.StartSession:
case CardRequestType.SessionGet: case CardRequestType.GetSession:
{ {
return ConstructResponse(GetSession(cardId, mac)); return ConstructResponse(GetSession(cardId, mac));
} }
@ -184,19 +186,19 @@ public class CardServiceController : WebApiController
case CardRequestType.WriteCard: case CardRequestType.WriteCard:
{ {
$"Card Request data is {xmlData}".Info(); $"Card Write data is {xmlData}".Info();
Write<Card>(cardId, xmlData); Write<Card>(cardId, xmlData);
return ConstructResponse(xmlData); return ConstructResponse(xmlData);
} }
case CardRequestType.WriteCardDetail: case CardRequestType.WriteCardDetail:
{ {
$"Card Request data is {xmlData}".Info(); $"Card Detail Write data is {xmlData}".Info();
WriteCardDetail(cardId, xmlData); WriteCardDetail(cardId, xmlData);
return ConstructResponse(xmlData); return ConstructResponse(xmlData);
} }
case CardRequestType.WriteCardBData: case CardRequestType.WriteCardBData:
{ {
$"Card Request data is {xmlData}".Info(); $"Card BData Write data is {xmlData}".Info();
Write<CardBData>(cardId, xmlData); Write<CardBData>(cardId, xmlData);
WriteCardPlayCount(cardId); WriteCardPlayCount(cardId);
return ConstructResponse(xmlData); return ConstructResponse(xmlData);
@ -212,10 +214,19 @@ public class CardServiceController : WebApiController
case CardRequestType.WriteUnlockKeynum: case CardRequestType.WriteUnlockKeynum:
case CardRequestType.WriteSoundEffect: case CardRequestType.WriteSoundEffect:
{ {
$"Card Request data is {xmlData}".Info(); $"Card Write data is {xmlData}".Info();
return ConstructResponse(xmlData); return ConstructResponse(xmlData);
} }
#endregion
#region OnlineMatching
case CardRequestType.StartOnlineMatching:
{
$"Start Online Matching, data is {xmlData}".Info();
return ConstructResponse(StartOnlineMatching(cardId, xmlData));
}
#endregion #endregion
default: default:
@ -588,6 +599,44 @@ public class CardServiceController : WebApiController
#endregion #endregion
#region OnlineMatchingImplementation
private static string StartOnlineMatching(long cardId, string xmlData)
{
var reader = new ChoXmlReader<OnlineMatchingEntry>(new StringReader(xmlData)).WithXPath(Configs.DATA_XPATH);
var entry = reader.Read();
/*var fake = entry.CopyPropertiesToNew<OnlineMatchingEntry>();
fake.MachineId--;
fake.MatchingId = 0xB16B00B5;
fake.EntryStart = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
fake.CardId = cardId - 1;
fake.AvatarId--;
fake.PlayerName = "FAKE";
fake.EntryNo = 0x4B1D;
fake.TitleId--;
fake.MatchingTimeout = 90;
fake.MatchingRemainingTime = 89;
fake.MatchingWaitTime = 1;
fake.Status = 1;
OnlineMatchingEntries[fake.CardId] = fake;*/
entry.CardId = cardId;
entry.MatchingId = 0xB16B00B5;
entry.EntryNo = 0;
entry.EntryStart = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
entry.MatchingTimeout = 90 * 1000;
entry.MatchingRemainingTime = 89 * 1000;
entry.MatchingWaitTime = 1;
entry.Status = 1;
entry.Dump().Info();
OnlineMatchingEntries[cardId] = entry;
return GenerateRecordsXml(OnlineMatchingEntries.Values.ToList(), Configs.ONLINE_MATCHING_XPATH);
}
#endregion
private enum CardRequestType private enum CardRequestType
{ {
// Read data // Read data
@ -613,8 +662,8 @@ public class CardServiceController : WebApiController
ReadTotalTrophy = 8468, ReadTotalTrophy = 8468,
// Sessions // Sessions
SessionGet = 401, GetSession = 401,
SessionStart = 402, StartSession = 402,
// Write data // Write data
WriteCard = 771, WriteCard = 771,
@ -628,7 +677,10 @@ public class CardServiceController : WebApiController
WriteCoin = 980, WriteCoin = 980,
WriteSkin = 933, WriteSkin = 933,
WriteUnlockKeynum = 1020, WriteUnlockKeynum = 1020,
WriteSoundEffect = 8969 WriteSoundEffect = 8969,
// Online matching
StartOnlineMatching = 8705
} }
private enum Command private enum Command

View File

@ -15,6 +15,8 @@ namespace GCLocalServerRewrite.controllers;
public class ServerController : WebApiController public class ServerController : WebApiController
{ {
private static readonly string DataUrl = $"https://{Configs.SETTINGS.ServerIp}/{Configs.STATIC_FOLDER}/{Configs.SETTINGS.EventFolder}";
[Route(HttpVerbs.Get, "/certify.php")] [Route(HttpVerbs.Get, "/certify.php")]
public string Certify([QueryData] NameValueCollection parameters) public string Certify([QueryData] NameValueCollection parameters)
{ {
@ -99,12 +101,13 @@ public class ServerController : WebApiController
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
var data = responseList[i]; var data = responseList[i];
dataString.Append($"{i},{data.FileName},{data.NotBeforeUnixTime},{data.NotAfterUnixTime},{data.Md5},{data.Index}"); var fileUrl = data.FileName.StartsWith("/") ? $"{DataUrl}{data.FileName}" : $"{DataUrl}/{data.FileName}";
dataString.Append($"{i},{fileUrl},{data.NotBeforeUnixTime},{data.NotAfterUnixTime},{data.Md5},{data.Index}");
dataString.Append('\n'); dataString.Append('\n');
} }
return $"count={count}\n" + return $"count={count}\n" +
"nexttime=0\n" + "nexttime=1\n" +
dataString.ToString().TrimEnd('\n'); dataString.ToString().TrimEnd('\n');
} }

View File

@ -0,0 +1,87 @@
using System.Xml.Serialization;
using ChoETL;
namespace GCLocalServerRewrite.models;
public class OnlineMatchingEntry: Record
{
[XmlElement(ElementName = "machine_id")]
[ChoXmlElementRecordField(FieldName = "machine_id")]
public long MachineId { get; set; }
[XmlElement(ElementName = "event_id")]
[ChoXmlElementRecordField(FieldName = "event_id")]
public long EventId { get; set; }
[XmlElement(ElementName = "matching_id")]
[ChoXmlElementRecordField(FieldName = "matching_id")]
public long MatchingId { get; set; }
[XmlElement(ElementName = "entry_no")]
[ChoXmlElementRecordField(FieldName = "entry_no")]
public long EntryNo { get; set; }
[XmlElement(ElementName = "entry_start")]
[ChoXmlElementRecordField(FieldName = "entry_start")]
public string EntryStart { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
[XmlElement(ElementName = "status")]
[ChoXmlElementRecordField(FieldName = "status")]
public long Status { get; set; } = 1;
[XmlElement(ElementName = "card_id")]
[ChoXmlElementRecordField(FieldName = "card_id")]
public long CardId { get; set; }
[XmlElement(ElementName = "player_name")]
[ChoXmlElementRecordField(FieldName = "player_name")]
public string PlayerName { get; set; } = string.Empty;
[XmlElement(ElementName = "avatar_id")]
[ChoXmlElementRecordField(FieldName = "avatar_id")]
public long AvatarId { get; set; }
[XmlElement(ElementName = "title_id")]
[ChoXmlElementRecordField(FieldName = "title_id")]
public long TitleId { get; set; }
[XmlElement(ElementName = "class_id")]
[ChoXmlElementRecordField(FieldName = "class_id")]
public long ClassId { get; set; }
[XmlElement(ElementName = "group_id")]
[ChoXmlElementRecordField(FieldName = "group_id")]
public long GroupId { get; set; }
[XmlElement(ElementName = "tenpo_id")]
[ChoXmlElementRecordField(FieldName = "tenpo_id")]
public long TenpoId { get; set; }
[XmlElement(ElementName = "tenpo_name")]
[ChoXmlElementRecordField(FieldName = "tenpo_name")]
public string TenpoName { get; set; } = "1337";
[XmlElement(ElementName = "pref_id")]
[ChoXmlElementRecordField(FieldName = "pref_id")]
public long PrefId { get; set; }
[XmlElement(ElementName = "pref")]
[ChoXmlElementRecordField(FieldName = "pref")]
public string Pref { get; set; } = "nesys";
[XmlElement(ElementName = "message_id")]
[ChoXmlElementRecordField(FieldName = "message_id")]
public long MessageId { get; set; }
[XmlElement(ElementName = "matching_timeout")]
[ChoXmlElementRecordField(FieldName = "matching_timeout")]
public long MatchingTimeout { get; set; } = 99;
[XmlElement(ElementName = "matching_wait_time")]
[ChoXmlElementRecordField(FieldName = "matching_wait_time")]
public long MatchingWaitTime { get; set; } = 10;
[XmlElement(ElementName = "matching_remaining_time")]
[ChoXmlElementRecordField(FieldName = "matching_remaining_time")]
public long MatchingRemainingTime { get; set; } = 89;
}