oiegrjoergojeroigjoeirgjoer

This commit is contained in:
2024-12-13 14:33:15 +09:00
parent fc02fa11c3
commit cafabbdb38
4 changed files with 43 additions and 24 deletions
+7 -1
View File
@@ -22,6 +22,11 @@ public class Jobini
private readonly string filePath; private readonly string filePath;
//어떻게 이름이 ini ini t //어떻게 이름이 ini ini t
public Jobini(string filePath)
{
this.iniData = ReadSetting(filePath);
this.filePath = filePath;
}
/// <summary> /// <summary>
/// inijob클래스를 생성합니다. 생성전에 데이터를 전부 삭제합니다. /// inijob클래스를 생성합니다. 생성전에 데이터를 전부 삭제합니다.
/// </summary> /// </summary>
@@ -36,6 +41,7 @@ public class Jobini
//File.Delete(filePath); //File.Delete(filePath);
this.iniData = ReadSetting(filePath); this.iniData = ReadSetting(filePath);
this.filePath = filePath; this.filePath = filePath;
//file file = new();
} }
@@ -106,7 +112,7 @@ public class Jobini
return ivalue; return ivalue;
} }
this.IniWrite(key, value); this.IniWrite(key, value);
return "0"; return value;
} }
public int IniCount() public int IniCount()
+32 -23
View File
@@ -3,8 +3,9 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Net.Sockets;
using System.Timers; using System.Timers;
using static Jobini; //using static Jobini;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -16,11 +17,12 @@ var app = builder.Build();
string filePath = "Setting.txt"; string filePath = "Setting.txt";
string scoreDbPath = "Score.txt"; string scoreDbPath = "Score.txt";
//ini클래스라 해놓고 정작 파일 확장자는 txt로 설정한게 어이없네
Jobini settingini = new(filePath); Jobini settingini = new(filePath);
Jobini scoreDBini = new(scoreDbPath); Jobini scoreDBini = new(scoreDbPath);
//Dictionary<string, string> settingValues = []; //Dictionary<string, string> settingValues = [];
//Dictionary<string, int> scoreDB = []; Dictionary<string, string> scoreDB = [];
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
@@ -29,24 +31,29 @@ if (!app.Environment.IsDevelopment())
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // 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.UseHsts();
} }
//csp이슈 고쳐야함 브라우저에서 csp때문에 신호 자체를 안보냄 다행히 유니티에서 보내는것은 csp체크가 꺼져있는듯
//그래서 어떻게 고침?
//대충 프론트엔드 문제라 하고 떠넘기죠?
//app.Use(async (context, next) => //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;"); // 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(); // await next();
//}); //});
//Dictionary<string, int> scoreDB= []; //scoreDB = [];
//기록하기 //기록하기
app.MapPost("submit", (string name, int score) => app.MapPost("submit", (string name, int score) =>
{ {
var dbKey = scoreDBini.IniRead(name); var dbKey = scoreDBini.IniRead(name);
if (dbKey != null) if (dbKey != null)//scoreDB.ContainsKey(name))
{ {
int value = int.Parse(dbKey); int value = int.Parse(dbKey);
if (value < score)
if (value < score)//scoreDB[name] < score)
{ {
//scoreDB[name ] = score;
scoreDBini.IniWrite(name, score.ToString()); scoreDBini.IniWrite(name, score.ToString());
} }
return Results.Ok(new { Message = "A" }); return Results.Ok(new { Message = "A" });
@@ -62,24 +69,25 @@ app.MapPost("submit", (string name, int score) =>
List<int> weekArrow = []; List<int> weekArrow = [];
//weekly Jobs (dbReset, WeekArrowGen...) //weekly Jobs (dbReset, WeekArrowGen...)
System.Timers.Timer resetTimer = new System.Timers.Timer(1000); // 10000ms = 10 seconds => 1week = ?ms mol ra si bal System.Timers.Timer resetTimer = new(10000); // 10000ms = 10 seconds => 1week = ?ms mol ra si bal
resetTimer.Elapsed += (sender, e) => resetTimer.Elapsed += (sender, e) =>
{ {
TimeOnly curTime = new(DateTime.Now.Hour, DateTime.Now.Minute); //TimeOnly curTime = new(DateTime.Now.Hour, DateTime.Now.Minute);
TimeOnly tarTime = new(0, 0); //아마 오전 12시? //TimeOnly tarTime = new(0, 0); //아마 오전 12시?
if (System.TimeOnly.Equals(curTime, tarTime)) //if (System.TimeOnly.Equals(curTime, tarTime))
{ //{
weekArrow.Clear(); // weekArrow.Clear();
} //}
//weekArrow.Clear(); //weekArrow.Clear();
// Log reset actio // Log reset actio
var logger = app.Services.GetRequiredService<ILogger<Program>>(); var logger = app.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("doWeekJobs"); //logger.LogInformation("doWeekJobs");
// Clear the scoreDB // Clear the scoreDB
scoreDBini.Clear(); scoreDBini.Clear();
weekArrow.Clear();
Random random = new(); Random random = new();
for (int i = 0; i < random.NextInt64(int.Parse(scoreDBini.NotNullableiniRead("minArrowNum")), int.Parse(scoreDBini.NotNullableiniRead("maxArrowNum"))); i++) for (int i = 0; i < random.NextInt64(int.Parse(settingini.NotNullableiniRead("minArrowNum","10")), int.Parse(settingini.NotNullableiniRead("maxArrowNum","30"))/*10,30*/); i++)
{ {
int rngNum = (int)random.NextInt64(0, 4); int rngNum = (int)random.NextInt64(0, 4);
weekArrow.Add(rngNum/*(int)random.NextInt64(0, 4)*/); weekArrow.Add(rngNum/*(int)random.NextInt64(0, 4)*/);
@@ -87,16 +95,16 @@ resetTimer.Elapsed += (sender, e) =>
} }
}; };
Random random = new(); //Random random = new();
for (int i = 0; i < random.NextInt64(int.Parse(scoreDBini.NotNullableiniRead("minArrowNum")), int.Parse(scoreDBini.NotNullableiniRead("maxArrowNum"))); i++) //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); // int rngNum = (int)random.NextInt64(0, 4);
weekArrow.Add(rngNum/*(int)random.NextInt64(0, 4)*/); // weekArrow.Add(rngNum/*(int)random.NextInt64(0, 4)*/);
//logger.LogInformation(rngNum.ToString()); // //logger.LogInformation(rngNum.ToString());
}//자기 자신이 읽고있다고 못 읽으면 난 뭐 어떻게 받아들여야함? //}//자기 자신이 읽고있다고 못 읽으면 난 뭐 어떻게 받아들여야함? => resetTimer가 메인 스레드가 아닌 다른 스레드에서 동작한다는 카더라가 있음
resetTimer.Start(); resetTimer.Start();
//기록된 점수 얻기 //기록된 점수 얻기
app.MapGet("/", () => scoreDBini.ReadDictionary); app.MapGet("/", () => /*scoreDB);*/scoreDB = scoreDBini.ReadDictionary());//scoreDBini.ReadDictionary);
app.MapGet("WeekArrow", () => weekArrow app.MapGet("WeekArrow", () => weekArrow
); );
@@ -112,4 +120,5 @@ app.UseRouting();
app.MapRazorPages(); app.MapRazorPages();
app.Run("http://localhost:5000"); //이미minio에서 8000~8001사용중
app.Run("http://localhost:8004");
+2
View File
@@ -0,0 +1,2 @@
minArrowNum = 10
maxArrowNum = 304
+2
View File
@@ -5,6 +5,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Platforms>AnyCPU;ARM64</Platforms> <Platforms>AnyCPU;ARM64</Platforms>
<PublishAot>False</PublishAot>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">