DlgQuickmatch.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * NAME
  21. * $Archive: /Commando/Code/Commando/DlgQuickmatch.cpp $
  22. *
  23. * DESCRIPTION
  24. * Quick match dialog
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 21 $
  32. * $Modtime: 1/16/02 5:06p $
  33. *
  34. ******************************************************************************/
  35. #include "DlgQuickMatch.h"
  36. #include "DlgWOLWait.h"
  37. #include "DlgMessageBox.h"
  38. #include "DlgMPWolQuickMatchOptions.h"
  39. #include "Resource.h"
  40. #include "DialogResource.h"
  41. #include "gameinitmgr.h"
  42. #include "WOLJoinGame.h"
  43. #include "String_IDs.h"
  44. #include <WWTranslateDB\TranslateDB.h>
  45. #include <WWOnline\WaitCondition.h>
  46. #include <WWUI\ListCtrl.h>
  47. #include <WWDebug\WWDebug.h>
  48. #ifdef _MSC_VER
  49. #pragma warning (push,3)
  50. #endif
  51. #include "systimer.h"
  52. #ifdef _MSC_VER
  53. #pragma warning (pop)
  54. #endif
  55. using namespace WWOnline;
  56. /******************************************************************************
  57. *
  58. * NAME
  59. * DlgQuickMatch::DoDialog
  60. *
  61. * DESCRIPTION
  62. *
  63. * INPUTS
  64. *
  65. * RESULT
  66. * Success - True if dialog successfully started.
  67. *
  68. ******************************************************************************/
  69. bool DlgQuickMatch::DoDialog(void)
  70. {
  71. DlgQuickMatch* dialog = new DlgQuickMatch;
  72. if (dialog)
  73. {
  74. if (dialog->FinalizeCreate())
  75. {
  76. dialog->Start_Dialog();
  77. }
  78. dialog->Release_Ref();
  79. }
  80. return (dialog != NULL);
  81. }
  82. /******************************************************************************
  83. *
  84. * NAME
  85. * DlgQuickMatch::DlgQuickMatch
  86. *
  87. * DESCRIPTION
  88. * Constructor
  89. *
  90. * INPUTS
  91. * NONE
  92. *
  93. * RESULT
  94. * NONE
  95. *
  96. ******************************************************************************/
  97. DlgQuickMatch::DlgQuickMatch() :
  98. MenuDialogClass(IDD_MP_WOL_QUICKMATCH_CONNECT),
  99. mTimeoutTime(0),
  100. mResendTime(0)
  101. {
  102. WWDEBUG_SAY(("DlgQuickMatch: Instantiating\n"));
  103. }
  104. /******************************************************************************
  105. *
  106. * NAME
  107. * DlgQuickMatch::~DlgQuickMatch
  108. *
  109. * DESCRIPTION
  110. * Destructor
  111. *
  112. * INPUTS
  113. * NONE
  114. *
  115. * RESULT
  116. * NONE
  117. *
  118. ******************************************************************************/
  119. DlgQuickMatch::~DlgQuickMatch()
  120. {
  121. WWDEBUG_SAY(("DlgQuickMatch: Destructing\n"));
  122. if (mQuickMatch)
  123. {
  124. mQuickMatch->Release_Ref();
  125. }
  126. }
  127. /******************************************************************************
  128. *
  129. * NAME
  130. * DlgQuickMatch::FinalizeCreate
  131. *
  132. * DESCRIPTION
  133. * Finalize the creation of this object (Initialize).
  134. *
  135. * INPUTS
  136. *
  137. * RESULT
  138. *
  139. ******************************************************************************/
  140. bool DlgQuickMatch::FinalizeCreate(void)
  141. {
  142. mQuickMatch = WOLQuickMatch::Create();
  143. if (!mQuickMatch)
  144. {
  145. return false;
  146. }
  147. Observer<QuickMatchEvent>::NotifyMe(*mQuickMatch);
  148. return true;
  149. }
  150. /******************************************************************************
  151. *
  152. * NAME
  153. * DlgQuickMatch::On_Init_Dialog
  154. *
  155. * DESCRIPTION
  156. *
  157. * INPUTS
  158. * NONE
  159. *
  160. * RESULT
  161. * NONE
  162. *
  163. ******************************************************************************/
  164. void DlgQuickMatch::On_Init_Dialog(void)
  165. {
  166. ListCtrlClass* output = (ListCtrlClass*)Get_Dlg_Item(IDC_OUTPUT);
  167. WWASSERT_PRINT(output, "IDC_OUTOUT list control missing from dialog!");
  168. if (output)
  169. {
  170. output->Add_Column(L"", 1.0F, Vector3 (1, 1, 1));
  171. }
  172. Connect();
  173. MenuDialogClass::On_Init_Dialog();
  174. }
  175. /******************************************************************************
  176. *
  177. * NAME
  178. * DlgQuickMatch::On_Frame_Update
  179. *
  180. * DESCRIPTION
  181. *
  182. * INPUTS
  183. * NONE
  184. *
  185. * RESULT
  186. * NONE
  187. *
  188. ******************************************************************************/
  189. void DlgQuickMatch::On_Frame_Update(void)
  190. {
  191. if (mConnectWait.IsValid())
  192. {
  193. WaitCondition::WaitResult waitStatus = mConnectWait->GetResult();
  194. if (waitStatus != WaitCondition::Waiting)
  195. {
  196. if (waitStatus == WaitCondition::ConditionMet)
  197. {
  198. SendMatchingInfo();
  199. }
  200. else
  201. {
  202. OutputMessage(mConnectWait->GetResultText());
  203. }
  204. mConnectWait.Release();
  205. }
  206. }
  207. unsigned long theTime = TIMEGETTIME();
  208. if ((mResendTime > 0) && (theTime >= mResendTime))
  209. {
  210. mQuickMatch->SendClientInfo();
  211. mResendTime = 0;
  212. }
  213. // Watch for timeout
  214. if ((mTimeoutTime > 0) && (theTime >= mTimeoutTime))
  215. {
  216. OutputMessage(TRANSLATE(IDS_WOL_TIMEDOUT));
  217. mTimeoutTime = 0;
  218. }
  219. MenuDialogClass::On_Frame_Update();
  220. }
  221. /******************************************************************************
  222. *
  223. * NAME
  224. * DlgQuickMatch::
  225. *
  226. * DESCRIPTION
  227. *
  228. * INPUTS
  229. * NONE
  230. *
  231. * RESULT
  232. * NONE
  233. *
  234. ******************************************************************************/
  235. void DlgQuickMatch::On_Command(int ctrl, int message, DWORD param)
  236. {
  237. if (ctrl == IDC_MENU_BACK_BUTTON)
  238. {
  239. OutputMessage(IDS_QM_DISCONNECT);
  240. RefPtr<WaitCondition> wait = mQuickMatch->Disconnect();
  241. if (wait.IsValid())
  242. {
  243. DlgWOLWait::DoDialog(IDS_QM_DISCONNECT, wait);
  244. }
  245. }
  246. MenuDialogClass::On_Command(ctrl, message, param);
  247. }
  248. /******************************************************************************
  249. *
  250. * NAME
  251. * DlgQuickMatch::Connect
  252. *
  253. * DESCRIPTION
  254. *
  255. * INPUTS
  256. * NONE
  257. *
  258. * RESULT
  259. * NONE
  260. *
  261. ******************************************************************************/
  262. void DlgQuickMatch::Connect(void)
  263. {
  264. OutputMessage(IDS_QM_CONNECTING);
  265. mConnectWait = mQuickMatch->ConnectClient();
  266. if (mConnectWait.IsValid())
  267. {
  268. mConnectWait->WaitBeginning();
  269. }
  270. mTimeoutTime = (TIMEGETTIME() + 60000);
  271. }
  272. /******************************************************************************
  273. *
  274. * NAME
  275. * DlgQuickMatch::SendMatchingInfo
  276. *
  277. * DESCRIPTION
  278. *
  279. * INPUTS
  280. * NONE
  281. *
  282. * RESULT
  283. * NONE
  284. *
  285. ******************************************************************************/
  286. void DlgQuickMatch::SendMatchingInfo(void)
  287. {
  288. OutputMessage(IDS_QM_SENDINGMATCHINFO);
  289. bool sent = mQuickMatch->SendClientInfo();
  290. if (sent)
  291. {
  292. OutputMessage(TRANSLATE (IDS_MENU_SEARCHING_FOR_MATCH));
  293. }
  294. else
  295. {
  296. OutputMessage(TRANSLATE (IDS_MENU_CANT_LOCATE_MATCH));
  297. }
  298. }
  299. /******************************************************************************
  300. *
  301. * NAME
  302. * DlgQuickMatch::OutputMessage
  303. *
  304. * DESCRIPTION
  305. *
  306. * INPUTS
  307. * Message - Message to add to output.
  308. *
  309. * RESULT
  310. * NONE
  311. *
  312. ******************************************************************************/
  313. void DlgQuickMatch::OutputMessage(int messageID)
  314. {
  315. const WCHAR* message = TranslateDBClass::Get_String(messageID);
  316. OutputMessage(message);
  317. }
  318. /******************************************************************************
  319. *
  320. * NAME
  321. * DlgQuickMatch::OutputMessage
  322. *
  323. * DESCRIPTION
  324. *
  325. * INPUTS
  326. * Message - Message to add to output.
  327. *
  328. * RESULT
  329. * NONE
  330. *
  331. ******************************************************************************/
  332. void DlgQuickMatch::OutputMessage(const WCHAR* message)
  333. {
  334. WWDEBUG_SAY(("QM: %S\n", message));
  335. ListCtrlClass* output = (ListCtrlClass*)Get_Dlg_Item(IDC_OUTPUT);
  336. if (output)
  337. {
  338. int entryCount = output->Get_Entry_Count();
  339. output->Insert_Entry(entryCount, message);
  340. // Limit message entries.
  341. if (entryCount > 100)
  342. {
  343. output->Delete_Entry(0);
  344. }
  345. }
  346. }
  347. /******************************************************************************
  348. *
  349. * NAME
  350. * DlgQuickMatch::HandleNotification(QuickMatchEvent)
  351. *
  352. * DESCRIPTION
  353. * Handle status information from quickmatch.
  354. *
  355. * INPUTS
  356. * Status -
  357. *
  358. * RESULT
  359. * NONE
  360. *
  361. ******************************************************************************/
  362. void DlgQuickMatch::HandleNotification(QuickMatchEvent& status)
  363. {
  364. QuickMatchEvent::Event event = status.GetEvent();
  365. const WCHAR* msg = (const WCHAR*)status.Subject();
  366. if (QuickMatchEvent::QMERROR == event)
  367. {
  368. const WideStringClass& statusMsg = status.Subject();
  369. // If no match then resend the request in 10 seconds.
  370. if (statusMsg.Compare_No_Case(L"QM:NoMatch") == 0)
  371. {
  372. msg = TRANSLATE(IDS_QM_NOMATCH);
  373. }
  374. else
  375. {
  376. #ifdef QUICKMATCH_OPTIONS
  377. // Unable to match user because preferred modes are all zero.
  378. if (statusMsg.Compare_No_Case(L"QM:NoModes") == 0)
  379. {
  380. DlgMsgBox::DoDialog(TRANSLATE (IDS_MENU_INVALID_QM_SETTINGS_TITLE), TRANSLATE (IDS_MENU_INVALID_QM_SETTINGS),
  381. DlgMsgBox::Okay, this);
  382. return;
  383. }
  384. #endif
  385. }
  386. }
  387. else if (QuickMatchEvent::QMMATCHED == event)
  388. {
  389. GameInitMgrClass::Set_WOL_Return_Dialog(RenegadeDialogMgrClass::LOC_INTERNET_MAIN);
  390. // Join the game
  391. const WCHAR* gameName = (const WCHAR*)status.Subject();
  392. WOLJoinGame::JoinTheGame(gameName, L"", false);
  393. return;
  394. }
  395. // Assume any other message is for the user.
  396. OutputMessage(msg);
  397. }
  398. /******************************************************************************
  399. *
  400. * NAME
  401. * DlgQuickMatch::HandleNotification(DlgMsgBoxEvent)
  402. *
  403. * DESCRIPTION
  404. *
  405. * INPUTS
  406. *
  407. * RESULT
  408. * NONE
  409. *
  410. ******************************************************************************/
  411. void DlgQuickMatch::HandleNotification(DlgMsgBoxEvent& msgbox)
  412. {
  413. #ifdef QUICKMATCH_OPTIONS
  414. Add_Ref();
  415. if (msgbox.Event() == DlgMsgBoxEvent::Okay)
  416. {
  417. End_Dialog();
  418. START_DIALOG(MPWolQuickMatchOptionsMenuClass);
  419. }
  420. Release_Ref();
  421. #endif // QUICKMATCH_OPTIONS
  422. }