1
1
using System . IO ;
2
- using System . Globalization ;
3
2
using System . Text ;
4
3
using System . Collections . Generic ;
5
4
using System ;
@@ -9,6 +8,8 @@ namespace WebAPIService.NDREAMS.Aurora
9
8
{
10
9
public class OrbrunnerScoreBoardData
11
10
{
11
+ private static bool _initiated = false ;
12
+
12
13
private static object _Lock = new object ( ) ;
13
14
14
15
public class ScoreboardEntry
@@ -19,6 +20,41 @@ public class ScoreboardEntry
19
20
20
21
private static List < ScoreboardEntry > scoreboard = new List < ScoreboardEntry > ( ) ;
21
22
23
+ private static void LoadScoreBoardFromText ( string text )
24
+ {
25
+ if ( string . IsNullOrWhiteSpace ( text ) )
26
+ {
27
+ _initiated = true ;
28
+ return ;
29
+ }
30
+
31
+ // Split the input text by commas into pairs
32
+ string [ ] parts = text . Split ( ',' ) ;
33
+
34
+ if ( parts . Length % 2 != 0 )
35
+ {
36
+ CustomLogger . LoggerAccessor . LogError ( "[ndreams] - Orbrunner - Invalid scoreboard input format." ) ;
37
+ _initiated = true ;
38
+ return ;
39
+ }
40
+
41
+ // Iterate over the pairs (psnid, score)
42
+ for ( int i = 0 ; i < parts . Length ; i += 2 )
43
+ {
44
+ string psnid = parts [ i ] ;
45
+ if ( ! int . TryParse ( parts [ i + 1 ] , out int score ) ) // Ensure valid score format
46
+ {
47
+ CustomLogger . LoggerAccessor . LogWarn ( "[ndreams] - Orbrunner - Invalid score for player {psnid}. Skipping this entry." ) ;
48
+ continue ;
49
+ }
50
+
51
+ // Update or add the score entry to the scoreboard
52
+ UpdateScoreBoard ( psnid , score ) ;
53
+ }
54
+
55
+ _initiated = true ;
56
+ }
57
+
22
58
public static void UpdateScoreBoard ( string psnid , int newScore )
23
59
{
24
60
// Check if the player already exists in the scoreboard
@@ -45,6 +81,23 @@ public static void UpdateScoreBoard(string psnid, int newScore)
45
81
scoreboard . RemoveRange ( 10 , scoreboard . Count - 10 ) ;
46
82
}
47
83
84
+ public static void CheckForInitiatedleaderboard ( string apiPath )
85
+ {
86
+ if ( ! _initiated )
87
+ {
88
+ lock ( _Lock )
89
+ {
90
+ string filePath = $ "{ apiPath } /NDREAMS/Aurora/Orbrunner/leaderboard.txt";
91
+ Directory . CreateDirectory ( $ "{ apiPath } /NDREAMS/Aurora/Orbrunner") ;
92
+ if ( File . Exists ( filePath ) )
93
+ LoadScoreBoardFromText ( File . ReadAllText ( filePath ) ) ;
94
+ else
95
+ _initiated = true ;
96
+ CustomLogger . LoggerAccessor . LogDebug ( $ "[ndreams] - Orbrunner - scoreboard initiated.") ;
97
+ }
98
+ }
99
+ }
100
+
48
101
public static ( string , int ) ? GetHighestScore ( )
49
102
{
50
103
if ( scoreboard . Count == 0 )
@@ -72,13 +125,14 @@ public static string ConvertScoreboardToText()
72
125
return sb . ToString ( ) ;
73
126
}
74
127
75
- public static void UpdateTodayScoreboardXml ( string apiPath , string date )
128
+ public static void UpdateScoreboardXml ( string apiPath )
76
129
{
77
130
lock ( _Lock )
78
131
{
132
+ string filePath = $ "{ apiPath } /NDREAMS/Aurora/Orbrunner/leaderboard.txt";
79
133
Directory . CreateDirectory ( $ "{ apiPath } /NDREAMS/Aurora/Orbrunner") ;
80
- File . WriteAllText ( $ " { apiPath } /NDREAMS/Aurora/Orbrunner/leaderboard_ { date } .txt" , ConvertScoreboardToText ( ) ) ;
81
- CustomLogger . LoggerAccessor . LogDebug ( $ "[ndreams] - Orbrunner - scoreboard { date } TEXT updated.") ;
134
+ File . WriteAllText ( filePath , ConvertScoreboardToText ( ) ) ;
135
+ CustomLogger . LoggerAccessor . LogDebug ( $ "[ndreams] - Orbrunner - scoreboard updated.") ;
82
136
}
83
137
}
84
138
}
0 commit comments