8
8
using System . Timers ;
9
9
using ClientCore ;
10
10
using ClientCore . Exceptions ;
11
+ using ClientGUI ;
11
12
using DTAClient . Domain . Multiplayer . CnCNet . QuickMatch . Events ;
12
13
using DTAClient . Domain . Multiplayer . CnCNet . QuickMatch . Models ;
13
14
using DTAClient . Domain . Multiplayer . CnCNet . QuickMatch . Requests ;
@@ -150,14 +151,14 @@ public void LoadLaddersAndUserAccountsAsync() =>
150
151
await Task . WhenAll ( loadLaddersTask , loadUserAccountsTask ) ;
151
152
152
153
QmResponse < IEnumerable < QmLadder > > loadLaddersResponse = loadLaddersTask . Result ;
153
- if ( ! loadLaddersResponse . IsSuccessStatusCode )
154
+ if ( ! loadLaddersResponse . IsSuccess )
154
155
{
155
156
QmEvent ? . Invoke ( this , new QmErrorMessageEvent ( string . Format ( QmStrings . LoadingUserAccountsErrorFormat , loadLaddersResponse . ReasonPhrase ) ) ) ;
156
157
return ;
157
158
}
158
159
159
160
QmResponse < IEnumerable < QmUserAccount > > loadUserAccountsReponse = loadUserAccountsTask . Result ;
160
- if ( ! loadUserAccountsReponse . IsSuccessStatusCode )
161
+ if ( ! loadUserAccountsReponse . IsSuccess )
161
162
{
162
163
QmEvent ? . Invoke ( this , new QmErrorMessageEvent ( string . Format ( QmStrings . LoadingUserAccountsErrorFormat , loadUserAccountsReponse . ReasonPhrase ) ) ) ;
163
164
return ;
@@ -190,7 +191,7 @@ public void LoadLadderMapsForAbbrAsync(string ladderAbbr) =>
190
191
ExecuteLoadingRequest ( new QmLoadingLadderMapsEvent ( ) , async ( ) =>
191
192
{
192
193
QmResponse < IEnumerable < QmLadderMap > > ladderMapsResponse = await apiService . LoadLadderMapsForAbbrAsync ( ladderAbbr ) ;
193
- if ( ! ladderMapsResponse . IsSuccessStatusCode )
194
+ if ( ! ladderMapsResponse . IsSuccess )
194
195
{
195
196
QmEvent ? . Invoke ( this , new QmErrorMessageEvent ( string . Format ( QmStrings . LoadingLadderMapsErrorFormat , ladderMapsResponse . ReasonPhrase ) ) ) ;
196
197
return ;
@@ -204,7 +205,7 @@ public void LoadLadderStatsForAbbrAsync(string ladderAbbr) =>
204
205
{
205
206
QmResponse < QmLadderStats > ladderStatsResponse = await apiService . LoadLadderStatsForAbbrAsync ( ladderAbbr ) ;
206
207
207
- if ( ! ladderStatsResponse . IsSuccessStatusCode )
208
+ if ( ! ladderStatsResponse . IsSuccess )
208
209
{
209
210
QmEvent ? . Invoke ( this , new QmErrorMessageEvent ( string . Format ( QmStrings . LoadingLadderStatsErrorFormat , ladderStatsResponse . ReasonPhrase ) ) ) ;
210
211
return ;
@@ -230,6 +231,8 @@ public void AcceptMatchAsync(QmSpawn spawn)
230
231
{
231
232
ExecuteLoadingRequest ( new QmReadyRequestMatchEvent ( ) , async ( ) =>
232
233
{
234
+ WriteSpawnIni ( spawn ) ;
235
+ retryRequestmatchTimer . Stop ( ) ;
233
236
var readyRequest = new QmReadyRequest ( spawn . Settings . Seed ) ;
234
237
QmResponse < QmResponseMessage > response = await apiService . QuickMatchRequestAsync ( userAccount . Ladder . Abbreviation , userAccount . Username , readyRequest ) ;
235
238
HandleQuickMatchResponse ( response ) ;
@@ -243,55 +246,68 @@ public void RejectMatchAsync(QmSpawn spawn)
243
246
{
244
247
ExecuteLoadingRequest ( new QmNotReadyRequestMatchEvent ( ) , async ( ) =>
245
248
{
249
+ retryRequestmatchTimer . Stop ( ) ;
246
250
var notReadyRequest = new QmNotReadyRequest ( spawn . Settings . Seed ) ;
247
251
QmResponse < QmResponseMessage > response = await apiService . QuickMatchRequestAsync ( userAccount . Ladder . Abbreviation , userAccount . Username , notReadyRequest ) ;
248
252
HandleQuickMatchResponse ( response ) ;
249
253
} ) ;
250
254
CancelRequestMatchAsync ( ) ;
251
255
}
252
256
253
- public void WriteSpawnIni ( QmSpawnResponse spawnResponse )
257
+ public void WriteSpawnIni ( QmSpawn spawn )
254
258
{
255
259
IniFile spawnIni = CreateSpawnIniFile ( ) ;
256
260
257
- // SETTINGS section
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
+ {
258
271
var settings = new IniSection ( "Settings" ) ;
259
272
settings . SetStringValue ( "Scenario" , "spawnmap.ini" ) ;
260
273
settings . SetStringValue ( "QuickMatch" , "Yes" ) ;
261
274
262
- foreach ( PropertyInfo prop in spawnResponse . Spawn . Settings . GetType ( ) . GetProperties ( ) )
263
- settings . SetStringValue ( prop . Name , prop . GetValue ( spawnResponse . Spawn . Settings ) . ToString ( ) ) ;
264
- // End SETTINGS sections
275
+ foreach ( PropertyInfo prop in spawn . Settings . GetType ( ) . GetProperties ( ) )
276
+ settings . SetStringValue ( prop . Name , prop . GetValue ( spawn . Settings ) . ToString ( ) ) ;
265
277
266
- // OTHER# sections
267
- for ( int i = 0 ; i < spawnResponse . Spawn . Others . Count ; i ++ )
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 ++ )
268
284
{
269
285
// Headers for OTHER# sections are 1-based index
270
286
var otherSection = new IniSection ( $ "Other{ i + 1 } ") ;
271
- QmSpawnOther other = spawnResponse . Spawn . Others [ i ] ;
287
+ QmSpawnOther other = spawn . Others [ i ] ;
272
288
273
289
foreach ( PropertyInfo otherProp in other . GetType ( ) . GetProperties ( ) )
274
290
otherSection . SetStringValue ( otherProp . Name , otherProp . GetValue ( other ) . ToString ( ) ) ;
275
291
276
292
spawnIni . AddSection ( otherSection ) ;
277
293
}
278
- // End OTHER# sections
294
+ }
279
295
280
- // SPAWNLOCATIONS section
281
- var spawnLocationsSection = new IniSection ( "SpawnLocation" ) ;
282
- foreach ( KeyValuePair < string , int > spawnLocation in spawnResponse . Spawn . SpawnLocations )
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 )
283
300
spawnLocationsSection . SetStringValue ( spawnLocation . Key , spawnLocation . Value . ToString ( ) ) ;
284
301
285
302
spawnIni . AddSection ( spawnLocationsSection ) ;
286
- // End SPAWNLOCATIONS section
303
+ }
287
304
288
- // TUNNEL section
305
+ private static void AddSpawnTunnelSection ( QmSpawn spawn , IniFile spawnIni )
306
+ {
289
307
var tunnel = new IniSection ( "Tunnel" ) ;
290
- // TODO IP and port information
291
- // tunnel.SetStringValue("Ip", spawnResponse.Spawn.Settings.);
292
- // tunnel.SetIntValue("Port", tunnelHandler.CurrentTunnel.Port);
308
+ tunnel . SetStringValue ( "Ip" , "52.232.96.199" ) ;
309
+ tunnel . SetIntValue ( "Port" , 50001 ) ;
293
310
spawnIni . AddSection ( tunnel ) ;
294
- // End TUNNEL section
295
311
}
296
312
297
313
public IniFile CreateSpawnIniFile ( )
@@ -410,7 +426,7 @@ private void ExecuteLoadingRequest(QmEvent qmLoadingEvent, Func<Task> requestAct
410
426
411
427
private bool FinishLogin ( QmResponse < QmAuthData > response , string email = null )
412
428
{
413
- if ( ! response . IsSuccessStatusCode )
429
+ if ( ! response . IsSuccess )
414
430
{
415
431
HandleFailedLogin ( response ) ;
416
432
return false ;
0 commit comments