@@ -24,6 +24,7 @@ public static class CurrentWorldExtractor
24
24
private static IEnumerable < string > ? ids ;
25
25
26
26
public static bool IsCurrentWorldBlacklisted { get ; private set ; }
27
+ public static string ? CurrentWorldId { get ; private set ; }
27
28
28
29
public static async void UpdateCurrentWorld ( )
29
30
{
@@ -35,15 +36,19 @@ public static async void UpdateCurrentWorld()
35
36
return ;
36
37
}
37
38
38
- var currentWorldId = await getCurrentWorldId ( ) ;
39
+ var newCurrentWorldId = await getCurrentWorldId ( ) ;
40
+ if ( newCurrentWorldId == CurrentWorldId ) return ;
39
41
40
- if ( currentWorldId is null )
42
+ CurrentWorldId = newCurrentWorldId ;
43
+ Logger . Log ( $ "World change detected: { CurrentWorldId } ") ;
44
+
45
+ if ( CurrentWorldId is null )
41
46
{
42
47
IsCurrentWorldBlacklisted = false ;
43
48
return ;
44
49
}
45
50
46
- IsCurrentWorldBlacklisted = ids . Contains ( currentWorldId ) ;
51
+ IsCurrentWorldBlacklisted = ids . Contains ( CurrentWorldId ) ;
47
52
}
48
53
49
54
private static async Task requestBlacklist ( )
@@ -52,21 +57,15 @@ private static async Task requestBlacklist()
52
57
{
53
58
if ( blacklist is not null ) return ;
54
59
55
- Logger . Log ( "Updating world blacklist" ) ;
56
-
57
60
using var client = new HttpClient ( ) ;
58
61
59
62
var response = await client . GetAsync ( blacklist_url ) ;
60
63
response . EnsureSuccessStatusCode ( ) ;
61
64
62
- Logger . Log ( "Found blacklist file" ) ;
63
-
64
65
var content = await response . Content . ReadAsStringAsync ( ) ;
65
66
blacklist = JsonConvert . DeserializeObject < Blacklist > ( content ) ;
66
67
if ( blacklist is null ) return ;
67
68
68
- Logger . Log ( "Successfully extracted blacklist data" ) ;
69
-
70
69
ids = blacklist . Worlds . Select ( world => world . ID ) ;
71
70
}
72
71
catch ( Exception )
@@ -80,26 +79,19 @@ private static async Task requestBlacklist()
80
79
{
81
80
try
82
81
{
83
- Logger . Log ( $ "Attempting to find current world using log pattern { logfile_location } \\ { logfile_pattern } ") ;
84
-
85
82
var logFile = Directory . GetFiles ( logfile_location , logfile_pattern ) . MaxBy ( d => new FileInfo ( d ) . CreationTime ) ;
86
83
if ( logFile is null ) return null ;
87
84
88
- Logger . Log ( $ "Found latest log file at { logFile } ") ;
89
-
90
85
using var fileStream = new FileStream ( logFile , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) ;
91
86
using var textReader = new StreamReader ( fileStream ) ;
92
87
var content = await textReader . ReadToEndAsync ( ) ;
93
88
94
- Logger . Log ( "Successfully read latest log file" ) ;
95
-
96
89
var latestWorld = world_regex . Matches ( content ) . LastOrDefault ( ) ? . Groups . Values . LastOrDefault ( ) ;
97
90
if ( latestWorld is null ) return null ;
98
91
99
92
var latestWorldId = latestWorld . Captures . FirstOrDefault ( ) ;
100
93
if ( latestWorldId is null ) return null ;
101
94
102
- Logger . Log ( $ "Found current world: { latestWorldId . Value } ") ;
103
95
return latestWorldId . Value ;
104
96
}
105
97
catch ( Exception )
0 commit comments