Files
Unity_Score_Server/rtjiory/Program.cs

116 lines
3.3 KiB
C#
Raw Normal View History

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;
using System.Timers;
using static Jobini;
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";
Jobini settingini = new(filePath);
Jobini scoreDBini = new(scoreDbPath);
//Dictionary<string, string> settingValues = [];
//Dictionary<string, int> scoreDB = [];
// 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();
}
//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();
//});
//Dictionary<string, int> scoreDB= [];
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD>
app.MapPost("submit", (string name, int score) =>
{
var dbKey = scoreDBini.IniRead(name);
if (dbKey != null)
{
int value = int.Parse(dbKey);
if (value < score)
{
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...)
System.Timers.Timer resetTimer = new System.Timers.Timer(1000); // 10000ms = 10 seconds => 1week = ?ms mol ra si bal
resetTimer.Elapsed += (sender, e) =>
{
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();
}
//weekArrow.Clear();
// Log reset actio
var logger = app.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("doWeekJobs");
// Clear the scoreDB
scoreDBini.Clear();
Random random = new();
for (int i = 0; i < random.NextInt64(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());
}
};
Random random = new();
for (int i = 0; i < random.NextInt64(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());
}//<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.Start();
//<2F><><EFBFBD>ϵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
app.MapGet("/", () => scoreDBini.ReadDictionary);
app.MapGet("WeekArrow", () => weekArrow
);
//app.UseHttpsRedirection();
app.UseStaticFiles();
//app.UseRouting();
app.UseAuthorization();
app.UseRouting();
app.MapRazorPages();
app.Run("http://localhost:5000");