14
14
using DTAClient . Domain . Multiplayer . CnCNet . QuickMatch . Requests ;
15
15
using DTAClient . Domain . Multiplayer . CnCNet . QuickMatch . Responses ;
16
16
using DTAClient . Domain . Multiplayer . CnCNet . QuickMatch . Utilities ;
17
- using DTAClient . Domain . Multiplayer . CnCNet . Services ;
18
17
using DTAClient . Online ;
18
+ using DTAClient . Services ;
19
19
using JWT ;
20
20
using JWT . Algorithms ;
21
21
using JWT . Exceptions ;
@@ -30,6 +30,7 @@ public class QmService : IDisposable
30
30
31
31
private readonly QmUserSettingsService qmUserSettingsService ;
32
32
private readonly ApiService apiService ;
33
+ private readonly SpawnService spawnService ;
33
34
private readonly QmSettingsService qmSettingsService ;
34
35
35
36
private readonly QmUserSettings qmUserSettings ;
@@ -40,10 +41,16 @@ public class QmService : IDisposable
40
41
private QmUserAccount userAccount ;
41
42
private IEnumerable < int > mapSides ;
42
43
43
- public QmService ( QmSettingsService qmSettingsService , QmUserSettingsService qmUserSettingsService , ApiService apiService )
44
+ public QmService (
45
+ QmSettingsService qmSettingsService ,
46
+ QmUserSettingsService qmUserSettingsService ,
47
+ ApiService apiService ,
48
+ SpawnService spawnService
49
+ )
44
50
{
45
51
this . qmUserSettingsService = qmUserSettingsService ;
46
52
this . apiService = apiService ;
53
+ this . spawnService = spawnService ;
47
54
this . qmSettingsService = qmSettingsService ;
48
55
49
56
qmUserSettings = this . qmUserSettingsService . GetSettings ( ) ;
@@ -227,11 +234,12 @@ public void RequestMatchAsync() =>
227
234
/// <summary>
228
235
/// This is called when the user clicks the "I'm Ready" button in the match found dialog.
229
236
/// </summary>
237
+ /// <param name="spawn">Spawn settings from the API.</param>
230
238
public void AcceptMatchAsync ( QmSpawn spawn )
231
239
{
232
240
ExecuteLoadingRequest ( new QmReadyRequestMatchEvent ( ) , async ( ) =>
233
241
{
234
- WriteSpawnIni ( spawn ) ;
242
+ spawnService . WriteSpawnInfo ( spawn ) ;
235
243
retryRequestmatchTimer . Stop ( ) ;
236
244
var readyRequest = new QmReadyRequest ( spawn . Settings . Seed ) ;
237
245
QmResponse < QmResponseMessage > response = await apiService . QuickMatchRequestAsync ( userAccount . Ladder . Abbreviation , userAccount . Username , readyRequest ) ;
@@ -242,6 +250,7 @@ public void AcceptMatchAsync(QmSpawn spawn)
242
250
/// <summary>
243
251
/// This is called when the user clicks the "Cancel" button in the match found dialog.
244
252
/// </summary>
253
+ /// <param name="spawn">Spawn settings from the API.</param>
245
254
public void RejectMatchAsync ( QmSpawn spawn )
246
255
{
247
256
ExecuteLoadingRequest ( new QmNotReadyRequestMatchEvent ( ) , async ( ) =>
@@ -254,71 +263,6 @@ public void RejectMatchAsync(QmSpawn spawn)
254
263
CancelRequestMatchAsync ( ) ;
255
264
}
256
265
257
- public void WriteSpawnIni ( QmSpawn spawn )
258
- {
259
- IniFile spawnIni = CreateSpawnIniFile ( ) ;
260
-
261
- AddSpawnSettingsSection ( spawn , spawnIni ) ;
262
- AddSpawnOtherSections ( spawn , spawnIni ) ;
263
- AddSpawnLocationsSection ( spawn , spawnIni ) ;
264
- AddSpawnTunnelSection ( spawn , spawnIni ) ;
265
-
266
- spawnIni . WriteIniFile ( ) ;
267
- }
268
-
269
- private static void AddSpawnSettingsSection ( QmSpawn spawn , IniFile spawnIni )
270
- {
271
- var settings = new IniSection ( "Settings" ) ;
272
- settings . SetStringValue ( "Scenario" , "spawnmap.ini" ) ;
273
- settings . SetStringValue ( "QuickMatch" , "Yes" ) ;
274
-
275
- foreach ( PropertyInfo prop in spawn . Settings . GetType ( ) . GetProperties ( ) )
276
- settings . SetStringValue ( prop . Name , prop . GetValue ( spawn . Settings ) . ToString ( ) ) ;
277
-
278
- spawnIni . AddSection ( settings ) ;
279
- }
280
-
281
- private static void AddSpawnOtherSections ( QmSpawn spawn , IniFile spawnIni )
282
- {
283
- for ( int i = 0 ; i < spawn . Others . Count ; i ++ )
284
- {
285
- // Headers for OTHER# sections are 1-based index
286
- var otherSection = new IniSection ( $ "Other{ i + 1 } ") ;
287
- QmSpawnOther other = spawn . Others [ i ] ;
288
-
289
- foreach ( PropertyInfo otherProp in other . GetType ( ) . GetProperties ( ) )
290
- otherSection . SetStringValue ( otherProp . Name , otherProp . GetValue ( other ) . ToString ( ) ) ;
291
-
292
- spawnIni . AddSection ( otherSection ) ;
293
- }
294
- }
295
-
296
- private static void AddSpawnLocationsSection ( QmSpawn spawn , IniFile spawnIni )
297
- {
298
- var spawnLocationsSection = new IniSection ( "SpawnLocations" ) ;
299
- foreach ( KeyValuePair < string , int > spawnLocation in spawn . SpawnLocations )
300
- spawnLocationsSection . SetStringValue ( spawnLocation . Key , spawnLocation . Value . ToString ( ) ) ;
301
-
302
- spawnIni . AddSection ( spawnLocationsSection ) ;
303
- }
304
-
305
- private static void AddSpawnTunnelSection ( QmSpawn spawn , IniFile spawnIni )
306
- {
307
- var tunnel = new IniSection ( "Tunnel" ) ;
308
- tunnel . SetStringValue ( "Ip" , "52.232.96.199" ) ;
309
- tunnel . SetIntValue ( "Port" , 50001 ) ;
310
- spawnIni . AddSection ( tunnel ) ;
311
- }
312
-
313
- public IniFile CreateSpawnIniFile ( )
314
- {
315
- FileInfo spawnerSettingsFile = SafePath . GetFile ( ProgramConstants . GamePath , ProgramConstants . SPAWNER_SETTINGS ) ;
316
-
317
- spawnerSettingsFile . Delete ( ) ;
318
-
319
- return new IniFile ( spawnerSettingsFile . FullName ) ;
320
- }
321
-
322
266
public void Dispose ( )
323
267
{
324
268
apiService . Dispose ( ) ;
0 commit comments