2024-12-12 08:43:54 +09:00
using Microsoft.AspNetCore.DataProtection.KeyManagement ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.Extensions.Logging ;
using System.Diagnostics ;
using System.Globalization ;
2024-12-13 14:33:15 +09:00
using System.Net.Sockets ;
2024-12-12 08:43:54 +09:00
using System.Timers ;
2024-12-13 14:33:15 +09:00
//using static Jobini;
2024-12-12 08:43:54 +09:00
var builder = WebApplication . CreateBuilder ( args ) ;
// Add services to the container.
builder . Services . AddRazorPages ( ) ;
var app = builder . Build ( ) ;
string filePath = "Setting.txt" ;
string scoreDbPath = "Score.txt" ;
2024-12-13 14:33:15 +09:00
//iniŬ<69> <C5AC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> س<EFBFBD> <D8B3> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> Ȯ<> <C8AE> <EFBFBD> ڴ<EFBFBD> txt<78> <74> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> Ѱ<EFBFBD> <20> <> <EFBFBD> ̾<EFBFBD> <CCBE> <EFBFBD>
2024-12-12 08:43:54 +09:00
Jobini settingini = new ( filePath ) ;
Jobini scoreDBini = new ( scoreDbPath ) ;
//Dictionary<string, string> settingValues = [];
2024-12-13 14:33:15 +09:00
Dictionary < string , string > scoreDB = [ ] ;
2024-12-12 08:43:54 +09:00
// Configure the HTTP request pipeline.
if ( ! app . Environment . IsDevelopment ( ) )
{
app . UseExceptionHandler ( "/Error" ) ;
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app . UseHsts ( ) ;
}
2024-12-13 14:33:15 +09:00
//csp<73> ̽<EFBFBD> <20> <> <EFBFBD> ľ<EFBFBD> <C4BE> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> csp<73> <70> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> ȣ <20> <> ü<EFBFBD> <C3BC> <20> Ⱥ<EFBFBD> <C8BA> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> Ƽ <EFBFBD> <C6BC> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> °<EFBFBD> <C2B0> <EFBFBD> cspüũ<C3BC> <C5A9> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ִµ<D6B4>
//<2F> <EFBFBD> <D7B7> <EFBFBD> <20> <EFBFBD> <EEB6BB> <20> <> ħ?
//<2F> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> Ʈ<EFBFBD> <C6AE> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> ϰ<EFBFBD> <20> <> <EFBFBD> ѱ<EFBFBD> <D1B1> <EFBFBD> ?
2024-12-12 08:43:54 +09:00
//app.Use(async (context, next) =>
//{
// context.Response.Headers.Append("Content-Security-Policy", "base-uri 'self'; default-src 'self'; img-src data: https:; object-src 'none'; script-src 'self'; style-src 'self'; upgrade-insecure-requests;");
// await next();
//});
2024-12-13 14:33:15 +09:00
//scoreDB = [];
2024-12-12 08:43:54 +09:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ϱ <EFBFBD>
app . MapPost ( "submit" , ( string name , int score ) = >
{
var dbKey = scoreDBini . IniRead ( name ) ;
2024-12-13 14:33:15 +09:00
if ( dbKey ! = null ) //scoreDB.ContainsKey(name))
2024-12-12 08:43:54 +09:00
{
int value = int . Parse ( dbKey ) ;
2024-12-13 14:33:15 +09:00
if ( value < score ) //scoreDB[name] < score)
2024-12-12 08:43:54 +09:00
{
2024-12-13 14:33:15 +09:00
//scoreDB[name ] = score;
2024-12-12 08:43:54 +09:00
scoreDBini . IniWrite ( name , score . ToString ( ) ) ;
}
return Results . Ok ( new { Message = "A" } ) ;
}
else
{
scoreDBini . IniWrite ( name , score . ToString ( ) ) ;
//scoreDB[name] = score;
return Results . Ok ( new { Message = "<22> " } ) ;
}
} ) ;
List < int > weekArrow = [ ] ;
//weekly Jobs (dbReset, WeekArrowGen...)
2024-12-24 19:18:37 +09:00
System . Timers . Timer resetTimer = new ( 43200000 ) ; // 10000ms = 10 seconds => 1week = ?ms mol ra si bal
2024-12-12 08:43:54 +09:00
resetTimer . Elapsed + = ( sender , e ) = >
{
2024-12-13 14:33:15 +09:00
//TimeOnly curTime = new(DateTime.Now.Hour, DateTime.Now.Minute);
//TimeOnly tarTime = new(0, 0); //<2F> Ƹ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> 12<31> <32> ?
//if (System.TimeOnly.Equals(curTime, tarTime))
//{
// weekArrow.Clear();
//}
2024-12-12 08:43:54 +09:00
//weekArrow.Clear();
// Log reset actio
var logger = app . Services . GetRequiredService < ILogger < Program > > ( ) ;
2024-12-24 19:18:37 +09:00
logger . LogInformation ( "do every 12hour Jobs" ) ;
2024-12-12 08:43:54 +09:00
// Clear the scoreDB
scoreDBini . Clear ( ) ;
2024-12-13 14:33:15 +09:00
weekArrow . Clear ( ) ;
2024-12-12 08:43:54 +09:00
Random random = new ( ) ;
2024-12-13 14:33:15 +09:00
for ( int i = 0 ; i < random . NextInt64 ( int . Parse ( settingini . NotNullableiniRead ( "minArrowNum" , "10" ) ) , int . Parse ( settingini . NotNullableiniRead ( "maxArrowNum" , "30" ) ) /*10,30*/ ) ; i + + )
2024-12-12 08:43:54 +09:00
{
int rngNum = ( int ) random . NextInt64 ( 0 , 4 ) ;
weekArrow . Add ( rngNum /*(int)random.NextInt64(0, 4)*/ ) ;
//logger.LogInformation(rngNum.ToString());
}
} ;
2024-12-13 14:33:15 +09:00
//Random random = new();
//for (int i = 0; i < random.NextInt64(10,30/*int.Parse(scoreDBini.NotNullableiniRead("minArrowNum")), int.Parse(scoreDBini.NotNullableiniRead("maxArrowNum"))*/); i++)
//{
// int rngNum = (int)random.NextInt64(0, 4);
// weekArrow.Add(rngNum/*(int)random.NextInt64(0, 4)*/);
// //logger.LogInformation(rngNum.ToString());
2024-12-24 19:18:37 +09:00
//}//<2F> ڱ<EFBFBD> <20> ڽ<EFBFBD> <DABD> <EFBFBD> <20> а <EFBFBD> <D0B0> ִٰ<D6B4> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <20> <> <20> <EFBFBD> <EEB6BB> <20> Ƶ鿩<C6B5> <E9BFA9> <EFBFBD> <EFBFBD> ? => resetTimer<65> <72> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> 尡 <20> ƴ<EFBFBD> <20> ٸ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> 忡<EFBFBD> <E5BFA1> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> Ѵ ٴ<D1B4> ī<> <C4AB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> => jobiniŬ<69> <C5AC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <EFBFBD> <DEBC> <EFBFBD> <20> ϳ <EFBFBD> <20> <> <EFBFBD> Ծ<EFBFBD> <D4BE> ٰ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ε<EFBFBD> ? <20> Ƹ<EFBFBD> <20> ذ<EFBFBD> <D8B0> <EFBFBD>
2024-12-12 08:43:54 +09:00
resetTimer . Start ( ) ;
//<2F> <> <EFBFBD> ϵ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
2024-12-13 14:33:15 +09:00
app . MapGet ( "/" , ( ) = > /*scoreDB);*/ scoreDB = scoreDBini . ReadDictionary ( ) ) ; //scoreDBini.ReadDictionary);
2024-12-12 08:43:54 +09:00
2024-12-24 19:18:37 +09:00
app . MapGet ( "WeekArrow" , ( ) = > weekArrow ) ;
2024-12-12 08:43:54 +09:00
//app.UseHttpsRedirection();
app . UseStaticFiles ( ) ;
//app.UseRouting();
app . UseAuthorization ( ) ;
app . UseRouting ( ) ;
app . MapRazorPages ( ) ;
2024-12-24 19:18:37 +09:00
//<2F> ̹<EFBFBD> minio<69> <6F> <EFBFBD> <EFBFBD> 8000~8001<30> <31> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> => <20> ٵ<EFBFBD> <20> <> 8004<30> <34> ? <20> ׳ <EFBFBD>
2024-12-13 14:33:15 +09:00
app . Run ( "http://localhost:8004" ) ;