1
0
mirror of synced 2025-02-17 11:08:31 +01:00

Update to support event, change config to use json.

This commit is contained in:
Yuchen Ji 2022-04-26 22:35:09 +08:00
parent 7397102dc0
commit 5c6cc5228f
19 changed files with 145 additions and 125 deletions

View File

@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=ADDR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=BDATA/@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>

View File

@ -12,6 +12,8 @@
<ItemGroup>
<PackageReference Include="CertificateManager" Version="1.0.8" />
<PackageReference Include="ChoETL" Version="1.2.1.45" />
<PackageReference Include="Config.Net" Version="4.19.0" />
<PackageReference Include="Config.Net.Json" Version="4.19.0" />
<PackageReference Include="EmbedIO" Version="3.4.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="sqlite-net2" Version="2.0.7" />
@ -21,6 +23,7 @@
<ItemGroup>
<Folder Include="log" />
<Folder Include="event\" />
<None Remove="db\music.db3" />
<None Remove="db\music4MAX465.db3" />
<Content Include="db\music.db3">
@ -56,6 +59,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
</ItemGroup>
<ItemGroup>

View File

@ -13,10 +13,11 @@ internal class Program
Batteries_V2.Init();
InitializeLogging();
LogConfigValues();
var urlPrefixes = args.Length > 0 ? new List<string>(args) : new List<string> { "http://+:80", "https://+:443"};
var urlPrefixes =
args.Length > 0 ? new List<string>(args) : new List<string> { "http://+:80", "https://+:443" };
using (var cts = new CancellationTokenSource())
{
@ -87,22 +88,15 @@ internal class Program
private static void LogConfigValues()
{
var configs = $"Config values: {nameof(Configs.SE_COUNT)} : {Configs.SE_COUNT}\n" +
$"{nameof(Configs.ITEM_COUNT)} : {Configs.ITEM_COUNT}\n" +
$"{nameof(Configs.SKIN_COUNT)} : {Configs.SKIN_COUNT}\n" +
$"{nameof(Configs.TITLE_COUNT)} : {Configs.TITLE_COUNT}\n" +
$"{nameof(Configs.AVATAR_COUNT)} : {Configs.AVATAR_COUNT}\n" +
$"{nameof(Configs.NAVIGATOR_COUNT)} : {Configs.NAVIGATOR_COUNT}\n" +
$"{nameof(Configs.MUSIC_DB_NAME)} : {Configs.MUSIC_DB_NAME}\n" +
$"{nameof(Configs.SERVER_ADDR)} : {Configs.SERVER_ADDR}\n";
configs.Info();
var paths = $"Paths: {nameof(PathHelper.HtmlRootPath)}: {PathHelper.HtmlRootPath}\n" +
$"{nameof(PathHelper.LogRootPath)}: {PathHelper.LogRootPath}\n" +
$"{nameof(PathHelper.DataBaseRootPath)}: {PathHelper.DataBaseRootPath}\n" +
$"{nameof(PathHelper.ConfigFilePath)}: {PathHelper.ConfigFilePath}\n" +
$"{nameof(PathHelper.CertRootPath)}: {PathHelper.CertRootPath}\n";
paths.Info();
var paths = $"Paths: {nameof(PathHelper.HtmlRootPath)}: {PathHelper.HtmlRootPath}\n" +
$"{nameof(PathHelper.LogRootPath)}: {PathHelper.LogRootPath}\n" +
$"{nameof(PathHelper.DataBaseRootPath)}: {PathHelper.DataBaseRootPath}\n" +
$"{nameof(PathHelper.ConfigFilePath)}: {PathHelper.ConfigFilePath}\n" +
$"{nameof(PathHelper.CertRootPath)}: {PathHelper.CertRootPath}\n";
paths.Info();
var configs = "Config values: \n" +
$"{Configs.SETTINGS.Stringify()}";
configs.Info();
}
}

View File

@ -52,7 +52,7 @@ public static class CertificateHelper
private static readonly SubjectAlternativeName SUBJECT_ALTERNATIVE_NAME = new()
{
DnsName = Configs.DOMAINS,
IpAddress = System.Net.IPAddress.Parse(Configs.SERVER_ADDR)
IpAddress = System.Net.IPAddress.Parse(Configs.SETTINGS.ServerIp)
};
private static readonly ValidityPeriod VALIDITY_PERIOD = new()

View File

@ -1,6 +1,4 @@
using System.Configuration;
using Swan;
using Swan.Logging;
using Config.Net;
namespace GCLocalServerRewrite.common;
@ -20,6 +18,8 @@ public static class Configs
public const string LOG_BASE_NAME = "log";
public const string CONFIG_FILE_NAME = "config.json";
public const string STATIC_FOLDER = "static";
public const string API_BASE_ROUTE = "/api";
@ -42,8 +42,6 @@ public static class Configs
public const string STATIC_BASE_ROUTE = "/static";
public const string CARD_DB_NAME = "card.db3";
public const string ROOT_XPATH = "/root";
public const string DATA_XPATH = $"{ROOT_XPATH}/data";
@ -123,84 +121,25 @@ public static class Configs
public const string SESSION_XPATH = $"{ROOT_XPATH}/session";
public const string RANK_STATUS_XPATH = $"{ROOT_XPATH}/ranking_status";
public const int GC4_EX_GID = 303801;
public static readonly int AVATAR_COUNT;
public static readonly int NAVIGATOR_COUNT;
public static readonly int ITEM_COUNT;
public static readonly int TITLE_COUNT;
public static readonly int SKIN_COUNT;
public static readonly int SE_COUNT;
public static readonly string MUSIC_DB_NAME;
public static readonly string SERVER_ADDR;
public static readonly List<string> DOMAINS;
private static readonly Configuration CONFIG = ConfigurationManager.OpenExeConfiguration(PathHelper.ConfigFilePath);
private const string AVATAR_COUNT_CONFIG_NAME = "AvatarCount";
private const string NAVIGATOR_COUNT_CONFIG_NAME = "NavigatorCount";
private const string ITEM_COUNT_CONFIG_NAME = "ItemCount";
private const string TITLE_COUNT_CONFIG_NAME = "TitleCount";
private const string SKIN_COUNT_CONFIG_NAME = "SkinCount";
private const string SE_COUNT_CONFIG_NAME = "SeCount";
private const string MUSIC_DB_CONFIG_NAME = "MusicDBName";
private const string SERVER_IP_CONFIG_NAME = "ServerIp";
private const int DEFAULT_AVATAR_COUNT = 294;
private const int DEFAULT_NAVIGATOR_COUNT = 71;
private const int DEFAULT_ITEM_COUNT = 21;
private const int DEFAULT_TITLE_COUNT = 4942;
private const int DEFAULT_SKIN_COUNT = 21;
private const int DEFAULT_SE_COUNT = 25;
private const string DEFAULT_MUSIC_DB_NAME = "music.db3";
private const string DEFAULT_SERVER_IP = "127.0.0.1";
static Configs()
public static readonly List<string> DOMAINS = new()
{
static void GetIntValueFromConfig(string configFieldName, int defaultValue, out int field )
{
var success = int.TryParse(CONFIG.AppSettings.Settings[configFieldName].Value, out var count);
"localhost",
"cert.nesys.jp",
"nesys.taito.co.jp",
"fjm170920zero.nesica.net"
};
field = success ? count:defaultValue;
}
GetIntValueFromConfig(AVATAR_COUNT_CONFIG_NAME, DEFAULT_AVATAR_COUNT, out AVATAR_COUNT);
GetIntValueFromConfig(NAVIGATOR_COUNT_CONFIG_NAME, DEFAULT_NAVIGATOR_COUNT, out NAVIGATOR_COUNT);
GetIntValueFromConfig(ITEM_COUNT_CONFIG_NAME, DEFAULT_ITEM_COUNT, out ITEM_COUNT);
GetIntValueFromConfig(TITLE_COUNT_CONFIG_NAME, DEFAULT_TITLE_COUNT, out TITLE_COUNT);
GetIntValueFromConfig(SKIN_COUNT_CONFIG_NAME, DEFAULT_SKIN_COUNT, out SKIN_COUNT);
GetIntValueFromConfig(SE_COUNT_CONFIG_NAME, DEFAULT_SE_COUNT, out SE_COUNT);
public static readonly IAppSettings SETTINGS =
new ConfigurationBuilder<IAppSettings>().UseJsonFile(PathHelper.ConfigFilePath).Build();
MUSIC_DB_NAME = CONFIG.AppSettings.Settings[MUSIC_DB_CONFIG_NAME].Value;
if (string.IsNullOrWhiteSpace(MUSIC_DB_NAME))
{
MUSIC_DB_NAME = DEFAULT_MUSIC_DB_NAME;
}
SERVER_ADDR = CONFIG.AppSettings.Settings[SERVER_IP_CONFIG_NAME].Value;
if (string.IsNullOrWhiteSpace(SERVER_ADDR))
{
SERVER_ADDR = DEFAULT_SERVER_IP;
}
DOMAINS = new()
{
"localhost",
"cert.nesys.jp",
"nesys.taito.co.jp",
"fjm170920zero.nesica.net"
};
}
public const int DEFAULT_AVATAR_COUNT = 323;
public const int DEFAULT_NAVIGATOR_COUNT = 94;
public const int DEFAULT_ITEM_COUNT = 21;
public const int DEFAULT_TITLE_COUNT = 5273;
public const int DEFAULT_SKIN_COUNT = 21;
public const int DEFAULT_SE_COUNT = 26;
public const string DEFAULT_CARD_DB_NAME = "card.db3";
public const string DEFAULT_MUSIC_DB_NAME = "music4MAX465.db3";
public const string DEFAULT_SERVER_IP = "127.0.0.1";
}

View File

@ -0,0 +1,35 @@
using Config.Net;
namespace GCLocalServerRewrite.common;
public interface IAppSettings
{
[Option(DefaultValue = Configs.DEFAULT_AVATAR_COUNT)]
int AvatarCount { get; }
[Option(DefaultValue = Configs.DEFAULT_NAVIGATOR_COUNT)]
int NavigatorCount { get; }
[Option(DefaultValue = Configs.DEFAULT_ITEM_COUNT)]
int ItemCount { get; }
[Option(DefaultValue = Configs.DEFAULT_TITLE_COUNT)]
int TitleCount { get; }
[Option(DefaultValue = Configs.DEFAULT_SKIN_COUNT)]
int SkinCount { get; }
[Option(DefaultValue = Configs.DEFAULT_SE_COUNT)]
int SeCount { get; }
[Option(DefaultValue = Configs.DEFAULT_MUSIC_DB_NAME)]
string MusicDbName { get; }
[Option(DefaultValue = Configs.DEFAULT_CARD_DB_NAME)]
string CardDbName { get; }
[Option(DefaultValue = Configs.DEFAULT_SERVER_IP)]
string ServerIp { get; }
IEnumerable<IDataResponse> ResponseData { get; }
}

View File

@ -0,0 +1,12 @@
namespace GCLocalServerRewrite.common;
public interface IDataResponse
{
string FileName { get; }
long NotBeforeUnixTime { get; }
long NotAfterUnixTime { get; }
string Md5 { get; }
}

View File

@ -19,7 +19,7 @@ public static class PathHelper
public static string CertRootPath => Path.Combine(BasePath, Configs.CERT_FOLDER);
public static string ConfigFilePath => Environment.ProcessPath ?? string.Empty;
public static string ConfigFilePath => Path.Combine(BasePath, Configs.CONFIG_FILE_NAME);
private static string BasePath
{

View File

@ -0,0 +1,25 @@
{
"AvatarCount": 323,
"NavigatorCount": 94,
"ItemCount": 21,
"SkinCount": 21,
"SeCount": 26,
"TitleCount": 5273,
"CardDbName": "card.db3",
"MusicDbName": "music4MAX465.db3",
"ServerIp": "127.0.0.1",
"ResponseData": [
{
"FileName": "/event_031_20160112.evt",
"NotBeforeUnixTime": 1272260187,
"NotAfterUnixTime": 1903412187,
"Md5": "28a12ed884747db261b188bc2c97c555"
},
{
"FileName": "/telop_20201125.txt",
"NotBeforeUnixTime": 1272260187,
"NotAfterUnixTime": 1903412187,
"Md5": "86fb269d190d2c85f6e0468ceca42a20"
}
]
}

View File

@ -15,7 +15,7 @@ public class ApiController : WebApiController
public ApiController()
{
cardSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.CARD_DB_NAME);
cardSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.SETTINGS.CardDbName);
}
[Route(HttpVerbs.Get, "/PlayOption")]

View File

@ -19,8 +19,8 @@ public class CardServiceController : WebApiController
public CardServiceController()
{
cardSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.CARD_DB_NAME);
musicSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.MUSIC_DB_NAME);
cardSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.SETTINGS.CardDbName);
musicSqLiteConnection = DatabaseHelper.ConnectDatabase(Configs.SETTINGS.MusicDbName);
}
[Route(HttpVerbs.Post, "/cardn.cgi")]
@ -72,28 +72,28 @@ public class CardServiceController : WebApiController
$"Getting read request, type is {requestType}".Info();
return ConstructResponse(
GetStaticCount<Avatar>(cardId, Configs.AVATAR_COUNT, Configs.AVATAR_XPATH));
GetStaticCount<Avatar>(cardId, Configs.SETTINGS.AvatarCount, Configs.AVATAR_XPATH));
}
case CardRequestType.ReadItem:
{
$"Getting read request, type is {requestType}".Info();
return ConstructResponse(
GetStaticCount<Item>(cardId, Configs.ITEM_COUNT, Configs.ITEM_XPATH));
GetStaticCount<Item>(cardId, Configs.SETTINGS.ItemCount, Configs.ITEM_XPATH));
}
case CardRequestType.ReadSkin:
{
$"Getting read request, type is {requestType}".Info();
return ConstructResponse(
GetStaticCount<Skin>(cardId, Configs.SKIN_COUNT, Configs.SKIN_XPATH));
GetStaticCount<Skin>(cardId, Configs.SETTINGS.SkinCount, Configs.SKIN_XPATH));
}
case CardRequestType.ReadTitle:
{
$"Getting read request, type is {requestType}".Info();
return ConstructResponse(
GetStaticCount<Title>(cardId, Configs.TITLE_COUNT, Configs.TITLE_XPATH));
GetStaticCount<Title>(cardId, Configs.SETTINGS.TitleCount, Configs.TITLE_XPATH));
}
case CardRequestType.ReadMusic:
{
@ -113,7 +113,7 @@ public class CardServiceController : WebApiController
$"Getting read request, type is {requestType}".Info();
return ConstructResponse(
GetStaticCount<Navigator>(cardId, Configs.NAVIGATOR_COUNT, Configs.NAVIGATOR_XPATH));
GetStaticCount<Navigator>(cardId, Configs.SETTINGS.NavigatorCount, Configs.NAVIGATOR_XPATH));
}
case CardRequestType.ReadMusicExtra:
{
@ -150,7 +150,7 @@ public class CardServiceController : WebApiController
$"Getting read request, type is {requestType}".Info();
return ConstructResponse(
GetStaticCount<SoundEffect>(cardId, Configs.SE_COUNT, Configs.SE_XPATH));
GetStaticCount<SoundEffect>(cardId, Configs.SETTINGS.SeCount, Configs.SE_XPATH));
}
case CardRequestType.ReadGetMessage:
{

View File

@ -69,8 +69,8 @@ public class ServerController : WebApiController
"pref=nesys\n" +
"addr=nesys@home\n" +
"x-next-time=15\n" +
$"x-img=http://{Configs.SERVER_ADDR}{Configs.STATIC_BASE_ROUTE}/news.png\n" +
$"x-ranking=http://{Configs.SERVER_ADDR}{Configs.RANK_BASE_ROUTE}/ranking.php\n" +
$"x-img=http://{Configs.SETTINGS.ServerIp}{Configs.STATIC_BASE_ROUTE}/news.png\n" +
$"x-ranking=http://{Configs.SETTINGS.ServerIp}{Configs.RANK_BASE_ROUTE}/ranking.php\n" +
$"ticket={ticket}";
return response;
@ -93,8 +93,19 @@ public class ServerController : WebApiController
HttpContext.Response.ContentEncoding = new UTF8Encoding(false);
HttpContext.Response.KeepAlive = true;
return "count=1\n" +
"nexttime=0\n";
var responseList = Configs.SETTINGS.ResponseData.ToList();
var count = responseList.Count;
var dataString = new StringBuilder();
for (var i = 0; i < count; i++)
{
var data = responseList[i];
dataString.Append($"{i},{data.FileName},{data.NotBeforeUnixTime},{data.NotAfterUnixTime},{data.Md5},file");
dataString.Append('\n');
}
return $"count={count}\n" +
"nexttime=0\n" +
dataString.ToString().TrimEnd('\n');
}
[Route(HttpVerbs.Get, "/gameinfo.php")]

View File

@ -20,7 +20,7 @@ public class Item : Record, IIdModel, ICardIdModel
public string? Modified { get; set; } = "1";
[XmlElement("new_flag")]
public int NewFlag { get; set; } = 1;
public int NewFlag { get; set; }
[XmlElement("use_flag")]
public int UseFlag { get; set; } = 1;

View File

@ -17,7 +17,7 @@ public class Navigator : Record, IIdModel, ICardIdModel
public string? Modified { get; set; } = "1";
[XmlElement("new_flag")]
public int NewFlag { get; set; } = 1;
public int NewFlag { get; set; }
[XmlElement("use_flag")]
public int UseFlag { get; set; } = 1;

View File

@ -17,7 +17,7 @@ public class Skin : Record, IIdModel, ICardIdModel
public string? Modified { get; set; } = "1";
[XmlElement("new_flag")]
public int NewFlag { get; set; } = 1;
public int NewFlag { get; set; }
[XmlElement("use_flag")]
public int UseFlag { get; set; } = 1;

View File

@ -17,7 +17,7 @@ public class SoundEffect : Record, IIdModel, ICardIdModel
public string? Modified { get; set; } = "1";
[XmlElement("new_flag")]
public int NewFlag { get; set; } = 1;
public int NewFlag { get; set; }
[XmlElement("use_flag")]
public int UseFlag { get; set; } = 1;

View File

@ -17,7 +17,7 @@ public class Title : Record, IIdModel, ICardIdModel
public string? Modified { get; set; } = "1";
[XmlElement("new_flag")]
public int NewFlag { get; set; } = 1;
public int NewFlag { get; set; }
[XmlElement("use_flag")]
public int UseFlag { get; set; } = 1;

View File

@ -72,9 +72,9 @@ public class Server
private static void InitializeDatabase()
{
DatabaseHelper.InitializeLocalDatabase(Configs.CARD_DB_NAME,
DatabaseHelper.InitializeLocalDatabase(Configs.SETTINGS.CardDbName,
typeof(Card), typeof(CardBData), typeof(CardDetail));
DatabaseHelper.InitializeLocalDatabase(Configs.MUSIC_DB_NAME,
DatabaseHelper.InitializeLocalDatabase(Configs.SETTINGS.MusicDbName,
typeof(Music), typeof(MusicAou), typeof(MusicExtra));
}
}

View File

@ -7,8 +7,4 @@
<RootNamespace>SharedProject</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GenFu" Version="1.6.0" />
</ItemGroup>
</Project>