WOL_LOGN.CPP 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. ** Command & Conquer Red Alert(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. #ifdef WOLAPI_INTEGRATION
  19. // Wol_Logn.cpp - WW online name/password dialog.
  20. // ajw 07/16/98
  21. #include "function.h"
  22. #include "IconList.h"
  23. #include "WolapiOb.h"
  24. #include "PassEdit.h"
  25. #include "WolStrng.h"
  26. #include "BigCheck.h"
  27. bool ReadSavedNicks( WolapiObject* pWO, IconListClass& NickList, char* szNameBuffer, char* szPassBuffer );
  28. bool bSaveNick( WolapiObject* pWO, const char* szNickToSave, const char* szPassToSave, bool bPassIsMangled );
  29. void DeleteNick( WolapiObject* pWO, int iOneBasedEntryToDelete );
  30. //char* LoadShpFile( const char* szShpFile );
  31. void DebugChatDef( HRESULT hRes );
  32. extern bool bTabKeyPressedHack;
  33. //#include "WolDebug.h"
  34. //***********************************************************************************************
  35. int WOL_Login_Dialog( WolapiObject* pWO )
  36. {
  37. // Return values: 0 = user cancels, 1 = success, -1 = force game exit
  38. if( pWO->bLoggedIn() )
  39. {
  40. pWO->bReturningAfterGame = true; // Set trigger for chat dialog.
  41. return 1; // We are already logged in, and have just come back from a game.
  42. }
  43. /*
  44. ** Dialog & button dimensions
  45. */
  46. #ifdef FRENCH
  47. int d_dialog_w = 160 * RESFACTOR; // dialog width
  48. #else
  49. int d_dialog_w = 150 * RESFACTOR; // dialog width
  50. #endif
  51. int d_dialog_h = 85 * RESFACTOR; // dialog height
  52. int d_dialog_x = (((320 * RESFACTOR) - d_dialog_w) / 2);
  53. int d_dialog_y = (((255 * RESFACTOR) - d_dialog_h) / 2);
  54. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // coord of x-center
  55. int d_txt8_h = 11 * RESFACTOR; // ht of 8-pt text
  56. int d_margin = 7 * RESFACTOR; // margin width/height
  57. int x_margin = 16 * RESFACTOR; // margin width/height
  58. int top_margin = 0;
  59. int d_name_w = 66 * RESFACTOR;
  60. int d_name_h = 10 * RESFACTOR;
  61. #ifdef FRENCH
  62. int d_name_x = d_dialog_x + 25 * RESFACTOR;
  63. #else
  64. int d_name_x = d_dialog_x + 20 * RESFACTOR;
  65. #endif
  66. int d_name_y = d_dialog_y + top_margin + 25 * RESFACTOR;
  67. int d_pass_w = 36 * RESFACTOR;
  68. int d_pass_h = d_name_h;
  69. int d_pass_x = d_name_x + d_name_w + 6 * RESFACTOR;
  70. int d_pass_y = d_name_y;
  71. int d_list_w = d_name_w;
  72. int d_list_h = 20 * RESFACTOR;
  73. int d_list_x = d_name_x;
  74. int d_list_y = d_dialog_y + top_margin + 40 * RESFACTOR;
  75. // int d_save_w = d_pass_w;
  76. int d_save_h = 9 * RESFACTOR;
  77. int d_save_x = d_pass_x + ( d_pass_w / 2 ) - ( d_pass_w / 2 );
  78. int d_save_y = d_list_y; // + ( d_list_h / 2 ) - ( d_save_h / 2 );
  79. int d_delete_w = d_pass_w;
  80. int d_delete_h = 10 * RESFACTOR;
  81. int d_delete_x = d_save_x;
  82. int d_delete_y = d_list_y + d_list_h - d_delete_h;
  83. #ifdef FRENCH
  84. int d_connect_w = 45 * RESFACTOR;
  85. #else
  86. int d_connect_w = 40 * RESFACTOR;
  87. #endif
  88. int d_connect_h = 13 * RESFACTOR;
  89. int d_connect_x = d_name_x + d_name_w/2 - d_connect_w/2;
  90. int d_connect_y = d_dialog_y + top_margin + 65 * RESFACTOR; //d_dialog_y + d_dialog_h - d_connect_h - d_margin;
  91. #if defined(GERMAN) || defined(FRENCH)
  92. int d_cancel_w = 40 * RESFACTOR;//BG:40
  93. #else
  94. int d_cancel_w = 40 * RESFACTOR;
  95. #endif
  96. int d_cancel_h = 13 * RESFACTOR;
  97. int d_cancel_x = d_pass_x + d_pass_w/2 - d_cancel_w/2; //d_dialog_cx + d_margin;
  98. int d_cancel_y = d_connect_y;
  99. /*
  100. ** Button enumerations
  101. */
  102. enum {
  103. BUTTON_CONNECT = 100,
  104. BUTTON_CANCEL,
  105. LISTBOX_NICKS,
  106. EDITBOX_NAME,
  107. EDITBOX_PASS,
  108. BUTTON_SAVECHECK,
  109. BUTTON_DELETE,
  110. };
  111. /*
  112. ** Redraw values: in order from "top" to "bottom" layer of the dialog
  113. */
  114. typedef enum {
  115. REDRAW_NONE = 0,
  116. REDRAW_BUTTONS,
  117. REDRAW_BACKGROUND,
  118. REDRAW_ALL = REDRAW_BACKGROUND
  119. } RedrawType;
  120. /*
  121. ** Dialog variables
  122. */
  123. int iReturn = 1; // 0 = user cancels, 1 = success, -1 = force game exit
  124. /*
  125. ** Other Variables
  126. */
  127. char szNameBuffer[ WOL_NAME_LEN_MAX ] = {0}; // User name.
  128. char szPassBuffer[ WOL_PASSWORD_LEN ] = {0}; // User password.
  129. /*
  130. ** Buttons
  131. */
  132. ControlClass* commands = NULL; // the button list
  133. TextButtonClass ConnectBtn( BUTTON_CONNECT, TXT_WOL_CONNECT, TPF_BUTTON, d_connect_x, d_connect_y, d_connect_w );
  134. TextButtonClass CancelBtn( BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w );
  135. IconListClass NickList( LISTBOX_NICKS, d_list_x, d_list_y, d_list_w, d_list_h, TPF_6PT_GRAD | TPF_NOSHADOW,
  136. MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"), true, 1, 0 );
  137. WOLEditClass NameEdit( EDITBOX_NAME, szNameBuffer, sizeof(szNameBuffer), TPF_6PT_GRAD|TPF_NOSHADOW,
  138. d_name_x, d_name_y, d_name_w, -1, EditClass::ALPHANUMERIC );
  139. PassEditClass PassEdit( EDITBOX_PASS, szPassBuffer, sizeof(szPassBuffer), TPF_6PT_GRAD|TPF_NOSHADOW,
  140. d_pass_x, d_pass_y, d_pass_w, -1, EditClass::ALPHANUMERIC );
  141. // Just making sure globals are set right before String_Pixel_Width() call... sigh
  142. Fancy_Text_Print( TXT_NONE, 0, 0, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_6PT_GRAD | TPF_NOSHADOW );
  143. int iSaveTextWidth = String_Pixel_Width( TXT_WOL_SAVELOGIN ) + BIGCHECK_OFFSETX;
  144. BigCheckBoxClass SaveCheckBox( BUTTON_SAVECHECK, d_save_x, d_save_y, iSaveTextWidth, d_save_h,
  145. TXT_WOL_SAVELOGIN, TPF_6PT_GRAD | TPF_NOSHADOW, true );
  146. TextButtonClass DeleteBtn( BUTTON_DELETE, TXT_DELETE_BUTTON, TPF_BUTTON, d_delete_x, d_delete_y, d_delete_w );
  147. /*
  148. ** Initialize.
  149. */
  150. Set_Logic_Page(SeenBuff);
  151. // Get saved nickname/passwords from the registry.
  152. if( ReadSavedNicks( pWO, NickList, szNameBuffer, szPassBuffer ) )
  153. {
  154. PassEdit.bClearOnNextSetFocus = true;
  155. }
  156. else
  157. {
  158. // Offer user the chance to go to web site now to get a nick.
  159. if( pWO->DoWebRegistration() )
  160. {
  161. // User chose to go to web page. Leave function so that we'll re-read nicks when they return.
  162. return 0;
  163. }
  164. }
  165. /*
  166. ** Create the button list.
  167. */
  168. commands = &ConnectBtn;
  169. CancelBtn.Add_Tail(*commands);
  170. NickList.Add_Tail(*commands);
  171. NameEdit.Add_Tail(*commands);
  172. PassEdit.Add_Tail(*commands);
  173. SaveCheckBox.Add_Tail(*commands);
  174. DeleteBtn.Add_Tail(*commands);
  175. NameEdit.Set_Focus();
  176. if( NickList.Count() == 0 )
  177. DeleteBtn.Disable();
  178. /*
  179. ** Main Processing Loop.
  180. */
  181. Keyboard->Clear();
  182. bool firsttime = true;
  183. bool display = true;
  184. bool process = true;
  185. while (process) {
  186. /*
  187. ** Invoke game callback.
  188. */
  189. Call_Back();
  190. #ifdef WIN32
  191. /*
  192. ** If we have just received input focus again after running in the background then
  193. ** we need to redraw.
  194. */
  195. if (AllSurfaces.SurfacesRestored) {
  196. AllSurfaces.SurfacesRestored=FALSE;
  197. display = true;
  198. }
  199. #endif
  200. /*
  201. ** Refresh display if needed.
  202. */
  203. if (display) {
  204. //------------------------------------------------------------------------
  205. // Clear screen
  206. //------------------------------------------------------------------------
  207. Hide_Mouse();
  208. Load_Title_Page(true);
  209. // Show_Mouse();
  210. /*
  211. ** Display the dialog box.
  212. */
  213. // Hide_Mouse();
  214. if (display) {
  215. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  216. Draw_Caption(TXT_WOL_LOGINDIALOG, d_dialog_x, d_dialog_y, d_dialog_w);
  217. }
  218. /*
  219. ** Redraw the buttons.
  220. */
  221. if (display) {
  222. Fancy_Text_Print( TXT_WOL_NAME, d_name_x + ( d_name_w / 2 ), d_name_y - 14,
  223. GadgetClass::Get_Color_Scheme(), TBLACK, TPF_TEXT | TPF_CENTER );
  224. Fancy_Text_Print( TXT_WOL_PASSWORD, d_pass_x + ( d_pass_w / 2 ), d_pass_y - 14,
  225. GadgetClass::Get_Color_Scheme(), TBLACK, TPF_TEXT | TPF_CENTER );
  226. commands->Flag_List_To_Redraw();
  227. }
  228. Show_Mouse();
  229. display = false;
  230. }
  231. // Force mouse visible, as some beta testers report unexplicable disappearing cursors.
  232. while( Get_Mouse_State() )
  233. Show_Mouse();
  234. // Be nice to other apps.
  235. Sleep( 50 );
  236. /*
  237. ** Get user input.
  238. */
  239. bTabKeyPressedHack = false;
  240. KeyNumType input = commands->Input();
  241. /*
  242. ** The first time through the processing loop, set the edit
  243. ** gadget to have the focus. The
  244. ** focus must be set here since the gadget list has changed
  245. ** and this change will cause any previous focus setting to be
  246. ** cleared by the input processing routine.
  247. */
  248. if (firsttime ) {
  249. firsttime = false;
  250. NameEdit.Set_Focus();
  251. NameEdit.Flag_To_Redraw();
  252. }
  253. // /*
  254. // ** If the <RETURN> key was pressed, then default to the appropriate
  255. // ** action button according to the style of this dialog box.
  256. // */
  257. /* if (input == KN_RETURN || input == (BUTTON_CONNECT|KN_BUTTON)) {
  258. ToggleClass * toggle = NULL;
  259. input = (KeyNumType)(BUTTON_CONNECT|KN_BUTTON);
  260. CancelBtn.Turn_Off();
  261. toggle = (ToggleClass*)commands->Extract_Gadget(BUTTON_CONNECT);
  262. if (toggle != NULL) {
  263. toggle->Turn_On();
  264. toggle->IsPressed = true;
  265. }
  266. Hide_Mouse();
  267. commands->Draw_All(true);
  268. Show_Mouse();
  269. }
  270. */
  271. /*
  272. ** Process input.
  273. */
  274. // if( input )
  275. // debugprint( "input: %i\n", input );
  276. if( bTabKeyPressedHack )
  277. {
  278. if( NameEdit.Has_Focus() )
  279. PassEdit.Set_Focus();
  280. else
  281. NameEdit.Set_Focus();
  282. NameEdit.Flag_To_Redraw();
  283. PassEdit.Flag_To_Redraw();
  284. }
  285. switch( input )
  286. {
  287. /*
  288. ** ESC/Cancel: break
  289. */
  290. case ( KN_ESC ):
  291. case ( BUTTON_CANCEL | KN_BUTTON ):
  292. iReturn = 0;
  293. process = false;
  294. break;
  295. case KN_RETURN:
  296. case ( EDITBOX_NAME | KN_BUTTON ):
  297. case ( EDITBOX_PASS | KN_BUTTON ):
  298. case ( BUTTON_CONNECT | KN_BUTTON ):
  299. {
  300. if( !strlen( szNameBuffer ) )
  301. {
  302. WWMessageBox().Process( TXT_WOL_MISSINGNAME );
  303. firsttime = true; // Bloody hack.
  304. NameEdit.Set_Focus();
  305. Keyboard->Clear();
  306. display = true;
  307. break;
  308. }
  309. if( !strlen( szPassBuffer ) )
  310. {
  311. WWMessageBox().Process( TXT_WOL_MISSINGPASSWORD );
  312. firsttime = true; // Bloody hack.
  313. PassEdit.Set_Focus();
  314. Keyboard->Clear();
  315. display = true;
  316. break;
  317. }
  318. // If we have not done RequestServerList() yet, do it now.
  319. if( !pWO->pChatSink->pServer )
  320. {
  321. bool bBreak = false;
  322. HRESULT hRes = pWO->GetChatServer();
  323. switch( hRes )
  324. {
  325. case E_FAIL:
  326. bBreak = true;
  327. WWMessageBox().Process( TXT_WOL_CANTCONNECT );
  328. firsttime = true; // Bloody hack.
  329. NameEdit.Set_Focus();
  330. Keyboard->Clear();
  331. display = true;
  332. break;
  333. case USERCANCELLED:
  334. bBreak = true;
  335. WWMessageBox().Process( TXT_WOL_LOGINCANCEL );
  336. firsttime = true; // Bloody hack.
  337. NameEdit.Set_Focus();
  338. Keyboard->Clear();
  339. display = true;
  340. break;
  341. case PATCHAVOIDED:
  342. bBreak = true;
  343. firsttime = true; // Bloody hack.
  344. NameEdit.Set_Focus();
  345. Keyboard->Clear();
  346. display = true;
  347. break;
  348. case PATCHDOWNLOADED:
  349. bBreak = true;
  350. process = false;
  351. iReturn = -1;
  352. break;
  353. }
  354. if( bBreak )
  355. break;
  356. }
  357. // RequestConnection()...
  358. HRESULT hRes = pWO->AttemptLogin( szNameBuffer, szPassBuffer, PassEdit.bClearOnNextSetFocus );
  359. if( hRes == S_OK )
  360. {
  361. if( SaveCheckBox.IsOn && !bSaveNick( pWO, szNameBuffer, szPassBuffer, PassEdit.bClearOnNextSetFocus ) )
  362. {
  363. // Nick/pass save failed.
  364. WWMessageBox().Process( TXT_WOL_CANTSAVENICK );
  365. }
  366. process = false;
  367. }
  368. else
  369. {
  370. switch( hRes )
  371. {
  372. case USERCANCELLED:
  373. WWMessageBox().Process( TXT_WOL_LOGINCANCEL );
  374. break;
  375. case CHAT_E_TIMEOUT:
  376. WWMessageBox().Process( TXT_WOL_TIMEOUT );
  377. break;
  378. case CHAT_E_BADPASS:
  379. WWMessageBox().Process( TXT_WOL_BADPASS );
  380. break;
  381. case CHAT_E_NICKINUSE:
  382. WWMessageBox().Process( TXT_WOL_NICKINUSE );
  383. break;
  384. case CHAT_E_CON_ERROR:
  385. // This error value I pass back myself, when the emergency timeout is hit.
  386. WWMessageBox().Process( TXT_WOL_TIMEOUT );
  387. break;
  388. }
  389. firsttime = true; // Bloody hack.
  390. NameEdit.Set_Focus();
  391. Keyboard->Clear();
  392. display = true;
  393. }
  394. break;
  395. }
  396. /*
  397. case( EDITBOX_PASS | KN_BUTTON ):
  398. {
  399. // Message with delay so that user has time to read it...
  400. CDTimerClass<SystemTimerClass> timer;
  401. timer = TICKS_PER_SECOND*4;
  402. WWMessageBox().Process(TXT_WOL_DEBUG2, TXT_NONE);
  403. while (timer > 0) {
  404. Call_Back();
  405. }
  406. Keyboard->Clear();
  407. display = true;
  408. break;
  409. }
  410. */
  411. case ( LISTBOX_NICKS | KN_BUTTON ):
  412. strcpy( szNameBuffer, NickList.Get_Item( NickList.Current_Index() ) );
  413. strcpy( szPassBuffer, NickList.Get_Item_ExtraDataString( NickList.Current_Index() ) );
  414. NameEdit.Flag_To_Redraw();
  415. PassEdit.Flag_To_Redraw();
  416. // Because the password is mangled, if the user begins to edit it now, we clear it.
  417. // Otherwise we could get a half-mangled, half-unmangled password field.
  418. // PassEdit.bClearOnNextSetFocus also acts as a flag telling us whether or not the
  419. // password field is mangled or not.
  420. PassEdit.bClearOnNextSetFocus = true;
  421. // display = true;
  422. break;
  423. case ( BUTTON_SAVECHECK | KN_BUTTON ):
  424. break;
  425. case ( BUTTON_DELETE | KN_BUTTON ):
  426. if( NickList.Count() > 0 )
  427. {
  428. DeleteNick( pWO, NickList.Current_Index() + 1 );
  429. NickList.Remove_Item( NickList.Current_Index() );
  430. NickList.Flag_To_Redraw();
  431. if( NickList.Count() == 0 )
  432. {
  433. DeleteBtn.Disable();
  434. DeleteBtn.Flag_To_Redraw();
  435. }
  436. }
  437. break;
  438. default:
  439. break;
  440. }
  441. }
  442. return iReturn;
  443. }
  444. //***********************************************************************************************
  445. bool ReadSavedNicks( WolapiObject* pWO, IconListClass& NickList, char* szNameBuffer, char* szPassBuffer )
  446. {
  447. // Read saved nickname/passwords from the registry.
  448. // Set up the list of nick/passwords.
  449. // Copy the first nick into the nick/password edits.
  450. // Returns true if edits are set with a default nick/pass because a nick was found.
  451. LPCSTR szNick;
  452. LPCSTR szPass;
  453. bool bReturn = false;
  454. for( int i = 1; i != 3; i++ )
  455. {
  456. if( pWO->pChat->GetNick( i, &szNick, &szPass ) == S_OK )
  457. {
  458. if( *szNick )
  459. {
  460. NickList.Add_Item( szNick, NULL, NULL, ICON_SHAPE, szPass );
  461. if( i == 1 )
  462. {
  463. strcpy( szNameBuffer, szNick );
  464. strcpy( szPassBuffer, szPass );
  465. bReturn = true;
  466. }
  467. }
  468. }
  469. }
  470. return bReturn;
  471. }
  472. //***********************************************************************************************
  473. bool bSaveNick( WolapiObject* pWO, const char* szNickToSave, const char* szPassToSave, bool bPassIsMangled )
  474. {
  475. // Saves specified nick and password in the registry, using SetNick.
  476. // Returns false if nick can't be saved.
  477. // If slot 1 empty, use slot 1.
  478. // Else push nick 1 down to second slot and save new nick in slot 1, unless
  479. // nick 1 name matches new entry.
  480. LPCSTR szNick;
  481. LPCSTR szPass;
  482. bool bPushSlot1 = true;
  483. switch( pWO->pChat->GetNick( 1, &szNick, &szPass ) )
  484. {
  485. case E_FAIL:
  486. // Assume that this is because there is no registry entry. We can use this slot.
  487. bPushSlot1 = false;
  488. break;
  489. case S_OK:
  490. if( *szNick == 0 )
  491. bPushSlot1 = false; // We can use this blank slot.
  492. else
  493. if( strcmp( szNick, szNickToSave ) == 0 )
  494. bPushSlot1 = false; // We can use this slot as the name is the same.
  495. break;
  496. }
  497. if( bPushSlot1 )
  498. {
  499. // Move nick in slot 1 to slot 2.
  500. pWO->pChat->SetNick( 2, szNick, szPass, false ); // (Already mangled.)
  501. }
  502. // Save new nick in slot 1.
  503. return ( pWO->pChat->SetNick( 1, szNickToSave, szPassToSave, !bPassIsMangled ) == S_OK );
  504. /*
  505. int iSlot;
  506. bool bStop = false;
  507. for( iSlot = 1; iSlot != 3; iSlot++ )
  508. {
  509. switch( pWO->pChat->GetNick( iSlot, &szNick, &szPass ) )
  510. {
  511. case E_FAIL:
  512. // Assume that this is because there is no registry entry. We can use this slot.
  513. bStop = true;
  514. break;
  515. case S_OK:
  516. if( *szNick == 0 )
  517. bStop = true; // We can use this blank slot.
  518. else
  519. if( strcmp( szNick, szNickToSave ) == 0 )
  520. bStop = true; // We can use this slot as the name is the same.
  521. break;
  522. }
  523. if( bStop )
  524. break;
  525. }
  526. if( iSlot == 3 )
  527. {
  528. // No open slots were found.
  529. // Get nick 1.
  530. pWO->pChat->GetNick( 1, &szNick, &szPass );
  531. // Save as nick 2.
  532. pWO->pChat->SetNick( 2, szNick, szPass, false ); // (Already mangled.)
  533. // Save new nick 1.
  534. return ( pWO->pChat->SetNick( 1, szNickToSave, szPassToSave, !bPassIsMangled ) == S_OK );
  535. }
  536. else
  537. {
  538. // iSlot points to an open slot.
  539. return ( pWO->pChat->SetNick( iSlot, szNickToSave, szPassToSave, !bPassIsMangled ) == S_OK );
  540. }
  541. */
  542. }
  543. //***********************************************************************************************
  544. void DeleteNick( WolapiObject* pWO, int iOneBasedEntryToDelete )
  545. {
  546. // Delete a nick from the registry via wolapi SetNick.
  547. // If nick to delete is in position one, and there is a second nick, move the second nick into position one.
  548. if( iOneBasedEntryToDelete == 1 )
  549. {
  550. // Check for nick 2.
  551. LPCSTR szNick;
  552. LPCSTR szPass;
  553. if( pWO->pChat->GetNick( 2, &szNick, &szPass ) == S_OK && *szNick != 0 )
  554. {
  555. // Copy nick in slot 2 to slot 1.
  556. pWO->pChat->SetNick( 1, szNick, szPass, false ); // (Already mangled.)
  557. // Delete slot 2.
  558. HRESULT hRes = pWO->pChat->SetNick( 2, "", "", false );
  559. DebugChatDef( hRes );
  560. }
  561. else
  562. {
  563. // No second nick.
  564. HRESULT hRes = pWO->pChat->SetNick( 1, "", "", false );
  565. DebugChatDef( hRes );
  566. }
  567. }
  568. else
  569. {
  570. HRESULT hRes = pWO->pChat->SetNick( 2, "", "", false );
  571. DebugChatDef( hRes );
  572. }
  573. }
  574. /*
  575. //***********************************************************************************************
  576. char* LoadShpFile( const char* szShpFile )
  577. {
  578. // Returns pointer to shp data that has been new'ed (and must be delete[]d), or NULL if failure.
  579. // ajw: No longer needed - I used this before putting new resources into a mix file.
  580. HANDLE hFile;
  581. hFile = CreateFile( szShpFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
  582. if( hFile == INVALID_HANDLE_VALUE )
  583. return NULL;
  584. DWORD dwFileSize = GetFileSize( hFile, NULL );
  585. char* pShp = new char[ dwFileSize ];
  586. DWORD dwBytesRead;
  587. ReadFile( hFile, pShp, dwFileSize, &dwBytesRead, NULL );
  588. // debugprint( "~~ LoadShpFile() - Read %i bytes out of %i from shp file.\n", dwBytesRead, dwFileSize );
  589. CloseHandle( hFile );
  590. return pShp;
  591. }
  592. */
  593. #endif