Skip to content

Commit 71c0230

Browse files
committed
Fix some response class related things
1 parent f086822 commit 71c0230

File tree

8 files changed

+85
-40
lines changed

8 files changed

+85
-40
lines changed

ClientGUI/GameProcessLogic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void StartGameProcess(WindowManager windowManager)
7171
SafePath.DeleteFileIfExists(ProgramConstants.GamePath, "TI.LOG");
7272
SafePath.DeleteFileIfExists(ProgramConstants.GamePath, "TS.LOG");
7373

74-
GameProcessStarting?.Invoke();
74+
// GameProcessStarting?.Invoke();
7575

7676
if (UserINISettings.Instance.WindowedMode && UseQres && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
7777
{
@@ -139,7 +139,7 @@ public static void StartGameProcess(WindowManager windowManager)
139139
}
140140
}
141141

142-
GameProcessStarted?.Invoke();
142+
// GameProcessStarted?.Invoke();
143143

144144
Logger.Log("Waiting for qres.dat or " + gameExecutableName + " to exit.");
145145
}

DXMainClient/DXGUI/Multiplayer/QuickMatch/QuickMatchLobbyPanel.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,33 @@ public override void Initialize()
9090

9191
private void HandleQmEvent(object sender, QmEvent qmEvent)
9292
{
93-
switch (qmEvent)
93+
switch (true)
9494
{
95-
case QmLadderMapsEvent e:
95+
case true when qmEvent is QmLadderMapsEvent e:
9696
HandleLadderMapsEvent(e.LadderMaps);
9797
return;
98-
case QmLadderStatsEvent e:
98+
case true when qmEvent is QmLadderStatsEvent e:
9999
HandleLadderStatsEvent(e.LadderStats);
100100
return;
101-
case QmLoadingLadderStatsEvent:
101+
case true when qmEvent is QmLoadingLadderStatsEvent:
102102
HandleLoadingLadderStatsEvent();
103103
return;
104-
case QmLaddersAndUserAccountsEvent e:
104+
case true when qmEvent is QmLaddersAndUserAccountsEvent e:
105105
HandleLoadLadderAndUserAccountsEvent(e);
106106
return;
107-
case QmUserAccountSelectedEvent e:
107+
case true when qmEvent is QmUserAccountSelectedEvent e:
108108
HandleUserAccountSelected(e.UserAccount);
109109
return;
110-
case QmLoginEvent:
110+
case true when qmEvent is QmLoginEvent:
111111
Enable();
112112
return;
113-
case QmLogoutEvent:
113+
case true when qmEvent is QmLogoutEvent:
114114
HandleLogoutEvent();
115115
return;
116+
case true when qmEvent is QmResponseEvent e && e.Response.IsSuccess && e.Response.Request is QmReadyRequest:
117+
GameProcessLogic.GameProcessExited += () => { };
118+
GameProcessLogic.StartGameProcess(WindowManager);
119+
break;
116120
}
117121
}
118122

DXMainClient/DXGUI/Multiplayer/QuickMatch/QuickMatchStatusOverlay.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,19 @@ private void HandleSpawnResponseEvent(QmSpawnResponse spawnResponse)
155155
matchupFoundConfirmTimer.Start();
156156
}
157157

158-
private void AcceptMatchAsync(QmSpawn spawn) => qmService.AcceptMatchAsync(spawn);
158+
private void AcceptMatchAsync(QmSpawn spawn)
159+
{
160+
Disable();
161+
matchupFoundConfirmTimer.Stop();
162+
qmService.AcceptMatchAsync(spawn);
163+
}
159164

160-
private void RejectMatchAsync(QmSpawn spawn) => qmService.RejectMatchAsync(spawn);
165+
private void RejectMatchAsync(QmSpawn spawn)
166+
{
167+
Disable();
168+
matchupFoundConfirmTimer.Stop();
169+
qmService.RejectMatchAsync(spawn);
170+
}
161171

162172
private void HandleCancelingMatchRequest() => SetStatus(QmStrings.CancelingMatchRequestStatus);
163173

DXMainClient/Domain/Multiplayer/CnCNet/QuickMatch/Models/QmResponseMessage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Converters;
23
using DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Responses;
34
using DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Utilities;
45
using Newtonsoft.Json;
56

67
namespace DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Models;
78

9+
[JsonConverter(typeof(QmRequestResponseConverter))]
810
public class QmResponseMessage
911
{
1012
public const string TypeKey = "type";

DXMainClient/Domain/Multiplayer/CnCNet/QuickMatch/Models/QmSpawnOther.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Models;
44

55
public class QmSpawnOther
66
{
7+
private const string DEFAULT_IP = "127.0.0.1";
8+
79
[JsonProperty("Name")]
810
public string Name { get; set; }
911

@@ -14,7 +16,11 @@ public class QmSpawnOther
1416
public int Color { get; set; }
1517

1618
[JsonProperty("Ip")]
17-
public string Ip { get; set; }
19+
public string Ip
20+
{
21+
get => _ip ?? DEFAULT_IP;
22+
set => _ip = value;
23+
}
1824

1925
[JsonProperty("Port")]
2026
public int Port { get; set; }
@@ -26,8 +32,16 @@ public class QmSpawnOther
2632
public int PortV6 { get; set; }
2733

2834
[JsonProperty("LanIP")]
29-
public string LanIP { get; set; }
35+
public string LanIP
36+
{
37+
get => _lanIp ?? DEFAULT_IP;
38+
set => _lanIp = value;
39+
}
3040

3141
[JsonProperty("LanPort")]
3242
public int LanPort { get; set; }
43+
44+
private string _ip { get; set; }
45+
46+
private string _lanIp { get; set; }
3347
}

DXMainClient/Domain/Multiplayer/CnCNet/QuickMatch/Responses/QmResponse.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Responses;
1111

12-
[JsonConverter(typeof(QmRequestResponseConverter))]
1312
public class QmResponse<T>
1413
{
1514
public QmRequest Request { get; }
@@ -30,7 +29,7 @@ public QmResponse(QmRequest request = null, HttpResponseMessage response = null)
3029
Response = response;
3130
}
3231

33-
public bool IsSuccessStatusCode => Response?.IsSuccessStatusCode ?? false;
32+
public bool IsSuccess => Response?.IsSuccessStatusCode ?? false;
3433

3534
public string ReasonPhrase => Response?.ReasonPhrase;
3635

DXMainClient/Domain/Multiplayer/CnCNet/QuickMatch/Services/QmService.cs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Timers;
99
using ClientCore;
1010
using ClientCore.Exceptions;
11+
using ClientGUI;
1112
using DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Events;
1213
using DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Models;
1314
using DTAClient.Domain.Multiplayer.CnCNet.QuickMatch.Requests;
@@ -150,14 +151,14 @@ public void LoadLaddersAndUserAccountsAsync() =>
150151
await Task.WhenAll(loadLaddersTask, loadUserAccountsTask);
151152

152153
QmResponse<IEnumerable<QmLadder>> loadLaddersResponse = loadLaddersTask.Result;
153-
if (!loadLaddersResponse.IsSuccessStatusCode)
154+
if (!loadLaddersResponse.IsSuccess)
154155
{
155156
QmEvent?.Invoke(this, new QmErrorMessageEvent(string.Format(QmStrings.LoadingUserAccountsErrorFormat, loadLaddersResponse.ReasonPhrase)));
156157
return;
157158
}
158159

159160
QmResponse<IEnumerable<QmUserAccount>> loadUserAccountsReponse = loadUserAccountsTask.Result;
160-
if (!loadUserAccountsReponse.IsSuccessStatusCode)
161+
if (!loadUserAccountsReponse.IsSuccess)
161162
{
162163
QmEvent?.Invoke(this, new QmErrorMessageEvent(string.Format(QmStrings.LoadingUserAccountsErrorFormat, loadUserAccountsReponse.ReasonPhrase)));
163164
return;
@@ -190,7 +191,7 @@ public void LoadLadderMapsForAbbrAsync(string ladderAbbr) =>
190191
ExecuteLoadingRequest(new QmLoadingLadderMapsEvent(), async () =>
191192
{
192193
QmResponse<IEnumerable<QmLadderMap>> ladderMapsResponse = await apiService.LoadLadderMapsForAbbrAsync(ladderAbbr);
193-
if (!ladderMapsResponse.IsSuccessStatusCode)
194+
if (!ladderMapsResponse.IsSuccess)
194195
{
195196
QmEvent?.Invoke(this, new QmErrorMessageEvent(string.Format(QmStrings.LoadingLadderMapsErrorFormat, ladderMapsResponse.ReasonPhrase)));
196197
return;
@@ -204,7 +205,7 @@ public void LoadLadderStatsForAbbrAsync(string ladderAbbr) =>
204205
{
205206
QmResponse<QmLadderStats> ladderStatsResponse = await apiService.LoadLadderStatsForAbbrAsync(ladderAbbr);
206207

207-
if (!ladderStatsResponse.IsSuccessStatusCode)
208+
if (!ladderStatsResponse.IsSuccess)
208209
{
209210
QmEvent?.Invoke(this, new QmErrorMessageEvent(string.Format(QmStrings.LoadingLadderStatsErrorFormat, ladderStatsResponse.ReasonPhrase)));
210211
return;
@@ -230,6 +231,8 @@ public void AcceptMatchAsync(QmSpawn spawn)
230231
{
231232
ExecuteLoadingRequest(new QmReadyRequestMatchEvent(), async () =>
232233
{
234+
WriteSpawnIni(spawn);
235+
retryRequestmatchTimer.Stop();
233236
var readyRequest = new QmReadyRequest(spawn.Settings.Seed);
234237
QmResponse<QmResponseMessage> response = await apiService.QuickMatchRequestAsync(userAccount.Ladder.Abbreviation, userAccount.Username, readyRequest);
235238
HandleQuickMatchResponse(response);
@@ -243,55 +246,68 @@ public void RejectMatchAsync(QmSpawn spawn)
243246
{
244247
ExecuteLoadingRequest(new QmNotReadyRequestMatchEvent(), async () =>
245248
{
249+
retryRequestmatchTimer.Stop();
246250
var notReadyRequest = new QmNotReadyRequest(spawn.Settings.Seed);
247251
QmResponse<QmResponseMessage> response = await apiService.QuickMatchRequestAsync(userAccount.Ladder.Abbreviation, userAccount.Username, notReadyRequest);
248252
HandleQuickMatchResponse(response);
249253
});
250254
CancelRequestMatchAsync();
251255
}
252256

253-
public void WriteSpawnIni(QmSpawnResponse spawnResponse)
257+
public void WriteSpawnIni(QmSpawn spawn)
254258
{
255259
IniFile spawnIni = CreateSpawnIniFile();
256260

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+
{
258271
var settings = new IniSection("Settings");
259272
settings.SetStringValue("Scenario", "spawnmap.ini");
260273
settings.SetStringValue("QuickMatch", "Yes");
261274

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());
265277

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++)
268284
{
269285
// Headers for OTHER# sections are 1-based index
270286
var otherSection = new IniSection($"Other{i + 1}");
271-
QmSpawnOther other = spawnResponse.Spawn.Others[i];
287+
QmSpawnOther other = spawn.Others[i];
272288

273289
foreach (PropertyInfo otherProp in other.GetType().GetProperties())
274290
otherSection.SetStringValue(otherProp.Name, otherProp.GetValue(other).ToString());
275291

276292
spawnIni.AddSection(otherSection);
277293
}
278-
// End OTHER# sections
294+
}
279295

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)
283300
spawnLocationsSection.SetStringValue(spawnLocation.Key, spawnLocation.Value.ToString());
284301

285302
spawnIni.AddSection(spawnLocationsSection);
286-
// End SPAWNLOCATIONS section
303+
}
287304

288-
// TUNNEL section
305+
private static void AddSpawnTunnelSection(QmSpawn spawn, IniFile spawnIni)
306+
{
289307
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);
293310
spawnIni.AddSection(tunnel);
294-
// End TUNNEL section
295311
}
296312

297313
public IniFile CreateSpawnIniFile()
@@ -410,7 +426,7 @@ private void ExecuteLoadingRequest(QmEvent qmLoadingEvent, Func<Task> requestAct
410426

411427
private bool FinishLogin(QmResponse<QmAuthData> response, string email = null)
412428
{
413-
if (!response.IsSuccessStatusCode)
429+
if (!response.IsSuccess)
414430
{
415431
HandleFailedLogin(response);
416432
return false;

DXMainClient/Domain/Multiplayer/CnCNet/QuickMatch/Utilities/QmHttpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task<QmResponse<T>> GetAsync<T>(QmRequest qmRequest, T successDataV
2828
try
2929
{
3030
QmResponse<T> response = await GetAsync<T>(qmRequest);
31-
response.Data = response.IsSuccessStatusCode ? successDataValue : failedDataValue;
31+
response.Data = response.IsSuccess ? successDataValue : failedDataValue;
3232

3333
return response;
3434
}

0 commit comments

Comments
 (0)