MPConnectionType.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. #define MPCONNECTIONTYPE_CPP
  2. /*************************************************************************************************\
  3. MPConnectionType.cpp : Implementation of the MPConnectionType component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "MPConnectionType.h"
  9. #include "prefs.h"
  10. #include "IniFile.h"
  11. #include "../MCLib/UserInput.h"
  12. #include "..\resource.h"
  13. #include "Multplyr.h"
  14. #include "Mechbayscreen.h"
  15. #ifndef GAMESOUND_H
  16. #include "gamesound.h"
  17. #endif
  18. #define CHECK_BUTTON 200
  19. static int connectionType = 0;
  20. static const int FIRST_BUTTON_ID = 1000010;
  21. static const int OK_BUTTON_ID = 1000001;
  22. static const int CANCEL_BUTTON_ID = 1000002;
  23. extern bool quitGame;
  24. MPConnectionType::MPConnectionType() : lanPanel(*this), tcpipPanel(*this)
  25. {
  26. bDone = 0;
  27. connectionType = 0;
  28. pPanel = 0;
  29. ppConnectionScreen = 0;
  30. pLocalBrowserScreen = 0;
  31. pDirectTcpipScreen = 0;
  32. pMPPlaceHolderScreen = 0;
  33. status = RUNNING;
  34. LogisticsScreen::helpTextArrayID = 2;
  35. bHosting = 0;
  36. }
  37. MPConnectionType::~MPConnectionType()
  38. {
  39. tcpipPanel.destroy();
  40. }
  41. int MPConnectionType::indexOfButtonWithID(int id)
  42. {
  43. int i;
  44. for (i = 0; i < buttonCount; i++)
  45. {
  46. if (buttons[i].getID() == id)
  47. {
  48. return i;
  49. }
  50. }
  51. return -1;
  52. }
  53. void MPConnectionType::init(FitIniFile* file)
  54. {
  55. LogisticsScreen::init( *file, "Static", "Text", "Rect", "Button" );
  56. if ( buttonCount )
  57. {
  58. for ( int i = 0; i < buttonCount; i++ )
  59. {
  60. buttons[i].setMessageOnRelease();
  61. if (buttons[i].getID() == 0)
  62. {
  63. buttons[i].setID(FIRST_BUTTON_ID + i);
  64. }
  65. if ( buttons[i].getID() != MB_MSG_MAINMENU )
  66. {
  67. buttons[i].setPressFX( LOG_VIDEOBUTTONS );
  68. buttons[i].setHighlightFX( LOG_DIGITALHIGHLIGHT );
  69. buttons[i].setDisabledFX( LOG_WRONGBUTTON );
  70. }
  71. }
  72. }
  73. {
  74. char path[256];
  75. strcpy( path, artPath );
  76. strcat( path, "mcl_mp_contype_zone.fit" );
  77. FitIniFile PNfile;
  78. if ( NO_ERR != PNfile.open( path ) )
  79. {
  80. char error[256];
  81. sprintf( error, "couldn't open file %s", path );
  82. Assert( 0, 0, error );
  83. return;
  84. }
  85. zonePanel.init(&PNfile, this);
  86. }
  87. {
  88. char path[256];
  89. strcpy( path, artPath );
  90. strcat( path, "mcl_mp_contype_lan.fit" );
  91. FitIniFile PNfile;
  92. if ( NO_ERR != PNfile.open( path ) )
  93. {
  94. char error[256];
  95. sprintf( error, "couldn't open file %s", path );
  96. Assert( 0, 0, error );
  97. return;
  98. }
  99. lanPanel.init(&PNfile);
  100. }
  101. {
  102. char path[256];
  103. strcpy( path, artPath );
  104. strcat( path, "mcl_mp_contype_tcpip.fit" );
  105. FitIniFile PNfile;
  106. if ( NO_ERR != PNfile.open( path ) )
  107. {
  108. char error[256];
  109. sprintf( error, "couldn't open file %s", path );
  110. Assert( 0, 0, error );
  111. return;
  112. }
  113. tcpipPanel.init(&PNfile);
  114. }
  115. connectionType = 0;
  116. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+1)].press(!((1 == connectionType) || (2 == connectionType) || (3 == connectionType)));
  117. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+2)].press(1 == connectionType);
  118. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+3)].press(2 == connectionType);
  119. switch (connectionType)
  120. {
  121. case 1:
  122. pPanel = &lanPanel;
  123. break;
  124. case 2:
  125. pPanel = &tcpipPanel;
  126. break;
  127. default:
  128. pPanel = &zonePanel;
  129. break;
  130. }
  131. hostDlg.init();
  132. }
  133. void MPConnectionType::begin()
  134. {
  135. status = RUNNING;
  136. beginFadeIn( 1.0 );
  137. bHosting = 0;
  138. if ( MPlayer )
  139. {
  140. MPlayer->closeSession();
  141. if ( !MPlayer->getOnLAN() )
  142. {
  143. getButton( FIRST_BUTTON_ID+2 )->disable( true );
  144. }
  145. else
  146. {
  147. getButton( FIRST_BUTTON_ID+2 )->disable( false );
  148. }
  149. }
  150. tcpipPanel.begin();
  151. }
  152. void MPConnectionType::end()
  153. {
  154. }
  155. void MPConnectionType::render(int xOffset, int yOffset )
  156. {
  157. LogisticsScreen::render(xOffset, yOffset);
  158. if ((0 == xOffset) && (0 == yOffset))
  159. {
  160. if (pPanel)
  161. {
  162. pPanel->render(xOffset, yOffset);
  163. }
  164. }
  165. else // if scrolling, make sure we don't fade
  166. beginFadeIn( 0 );
  167. if ( bHosting )
  168. hostDlg.render();
  169. }
  170. void MPConnectionType::render()
  171. {
  172. render(0, 0);
  173. }
  174. int MPConnectionType::handleMessage( unsigned long message, unsigned long who)
  175. {
  176. if ( RUNNING == status )
  177. {
  178. switch ( who )
  179. {
  180. case 57/*MB_MSG_MAINMENU*/:
  181. {
  182. getButton( 57/*MB_MSG_MAINMENU*/ )->press( 0 );
  183. status = MAINMENU;
  184. }
  185. break;
  186. case 51/*MB_MSG_PREV*/:
  187. {
  188. getButton( 51/*MB_MSG_PREV*/ )->press( 0 );
  189. status = UP;
  190. }
  191. break;
  192. case 50/*MB_MSG_NEXT*/:
  193. {
  194. switch (connectionType)
  195. {
  196. case 0/*internet*/:
  197. {
  198. (*ppConnectionScreen) = pLocalBrowserScreen;
  199. }
  200. break;
  201. case 1/*local browser*/:
  202. {
  203. (*ppConnectionScreen) = pLocalBrowserScreen;
  204. }
  205. break;
  206. case 2/*direct tcp/ip*/:
  207. {
  208. (*ppConnectionScreen) = pDirectTcpipScreen;
  209. }
  210. break;
  211. case 3/*modem2modem*/:
  212. {
  213. (*ppConnectionScreen) = pLocalBrowserScreen;
  214. }
  215. break;
  216. }
  217. getButton( 50/*MB_MSG_NEXT*/ )->press( 0 );
  218. status = NEXT;
  219. }
  220. break;
  221. case FIRST_BUTTON_ID+1:
  222. {
  223. connectionType = 0;
  224. pPanel = &zonePanel;
  225. }
  226. break;
  227. case FIRST_BUTTON_ID+2:
  228. {
  229. connectionType = 1;
  230. pPanel = &lanPanel;
  231. }
  232. break;
  233. case FIRST_BUTTON_ID+3:
  234. {
  235. connectionType = 2;
  236. pPanel = &tcpipPanel;
  237. }
  238. break;
  239. case LAN_PANEL_FIRST_BUTTON_ID:
  240. {
  241. (*ppConnectionScreen) = pLocalBrowserScreen;
  242. status = NEXT;
  243. }
  244. break;
  245. case LAN_PANEL_FIRST_BUTTON_ID + 1:
  246. {
  247. bHosting = true;
  248. hostDlg.begin();
  249. }
  250. break;
  251. case TCPIP_PANEL_FIRST_BUTTON_ID:
  252. {
  253. (*ppConnectionScreen) = pMPPlaceHolderScreen;
  254. // now I need to pop a connecting dialog...
  255. status = NEXT;
  256. }
  257. break;
  258. case TCPIP_PANEL_FIRST_BUTTON_ID + 1:
  259. {
  260. bHosting = true;
  261. hostDlg.begin();
  262. }
  263. break;
  264. case ZONE_PANEL_FIRST_BUTTON_ID:
  265. {
  266. MPlayer->launchBrowser( NULL );
  267. (*ppConnectionScreen) = pMPPlaceHolderScreen;
  268. // now I need to pop a connecting dialog...
  269. status = NEXT;
  270. quitGame = true;
  271. }
  272. break;
  273. }
  274. switch ( who )
  275. {
  276. case FIRST_BUTTON_ID+1:
  277. case FIRST_BUTTON_ID+2:
  278. case FIRST_BUTTON_ID+3:
  279. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+1)].press(!((1 == connectionType) || (2 == connectionType) || (3 == connectionType)));
  280. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+2)].press(1 == connectionType);
  281. buttons[indexOfButtonWithID(FIRST_BUTTON_ID+3)].press(2 == connectionType);
  282. return 1;
  283. break;
  284. }
  285. }
  286. return 0;
  287. }
  288. bool MPConnectionType::isDone()
  289. {
  290. return bDone;
  291. }
  292. void MPConnectionType::update()
  293. {
  294. if ( bHosting )
  295. {
  296. hostDlg.update();
  297. if ( hostDlg.isDone() )
  298. {
  299. if ( hostDlg.getStatus() == YES )
  300. {
  301. bHosting = 0;
  302. hostDlg.end();
  303. (*ppConnectionScreen) = pMPPlaceHolderScreen;
  304. status = NEXT;
  305. }
  306. else if ( hostDlg.getStatus() == NO )
  307. bHosting = 0;
  308. }
  309. return;
  310. }
  311. LogisticsScreen::update();
  312. if (pPanel)
  313. {
  314. pPanel->update();
  315. }
  316. //helpTextID = 0;
  317. //helpTextHeaderID = 0;
  318. /*
  319. for ( int i = 0; i < buttonCount; i++ )
  320. {
  321. buttons[i].update();
  322. if ( buttons[i].pointInside( userInput->getMouseX(), userInput->getMouseY() )
  323. && userInput->isLeftClick() )
  324. {
  325. handleMessage( buttons[i].getID(), buttons[i].getID() );
  326. }
  327. }
  328. */
  329. }
  330. void aZonePanel::init(FitIniFile* pFile, LogisticsScreen* pParent)
  331. {
  332. FitIniFile &file = (*pFile);
  333. button.init( file, "Button0" );
  334. button.setMessageOnRelease();
  335. button.setPressFX( LOG_VIDEOBUTTONS );
  336. button.setHighlightFX( LOG_DIGITALHIGHLIGHT );
  337. button.setDisabledFX( LOG_WRONGBUTTON );
  338. if (button.getID() == 0)
  339. {
  340. button.setID(ZONE_PANEL_FIRST_BUTTON_ID);
  341. }
  342. addChild(&button);
  343. text.init( &file, "Text0" );
  344. addChild(&text);
  345. pParentScreen = pParent;
  346. bShowWarning = 0;
  347. }
  348. void aZonePanel::update()
  349. {
  350. if ( bShowWarning )
  351. {
  352. LogisticsOKDialog::instance()->update();
  353. if ( LogisticsOKDialog::instance()->isDone() )
  354. {
  355. if ( LogisticsOKDialog::instance()->getStatus() == LogisticsScreen::YES )
  356. {
  357. pParentScreen->handleMessage( ZONE_PANEL_FIRST_BUTTON_ID, ZONE_PANEL_FIRST_BUTTON_ID );
  358. quitGame = true;
  359. }
  360. LogisticsOKDialog::instance()->end();
  361. bShowWarning = 0;
  362. }
  363. }
  364. else
  365. aObject::update();
  366. }
  367. void aZonePanel::render()
  368. {
  369. aObject::render();
  370. if ( bShowWarning )
  371. {
  372. LogisticsOKDialog::instance()->render();
  373. }
  374. }
  375. int aZonePanel::handleMessage( unsigned long, unsigned long )
  376. {
  377. bShowWarning = true;
  378. LogisticsOKDialog::instance()->begin();
  379. LogisticsOKDialog::instance()->setText( IDS_MP_CON_ZONE_WARNING, IDS_PM_CANCEL, IDS_MP_CON_ZONE_WARNING_NEXT );
  380. return 1;
  381. }
  382. void aLanPanel::update()
  383. {
  384. aObject::update();
  385. }
  386. void aLanPanel::init(FitIniFile* pFile)
  387. {
  388. FitIniFile &file = (*pFile);
  389. button0.init( file, "Button0" );
  390. button0.setMessageOnRelease();
  391. if (button0.getID() == 0)
  392. {
  393. button0.setID(LAN_PANEL_FIRST_BUTTON_ID);
  394. }
  395. button0.setPressFX( LOG_VIDEOBUTTONS );
  396. button0.setHighlightFX( LOG_DIGITALHIGHLIGHT );
  397. button0.setDisabledFX( LOG_WRONGBUTTON );
  398. addChild(&button0);
  399. button1.init( file, "Button1" );
  400. button1.setMessageOnRelease();
  401. if (button1.getID() == 0)
  402. {
  403. button1.setID(LAN_PANEL_FIRST_BUTTON_ID + 1);
  404. }
  405. addChild(&button1);
  406. button1.setPressFX( LOG_VIDEOBUTTONS );
  407. button1.setHighlightFX( LOG_DIGITALHIGHLIGHT );
  408. button1.setDisabledFX( LOG_WRONGBUTTON );
  409. text.init( &file, "Text0" );
  410. addChild(&text);
  411. }
  412. int aLanPanel::handleMessage( unsigned long message, unsigned long who)
  413. {
  414. switch ( who )
  415. {
  416. case LAN_PANEL_FIRST_BUTTON_ID:
  417. case LAN_PANEL_FIRST_BUTTON_ID + 1:
  418. if (pParentScreen)
  419. {
  420. pParentScreen->handleMessage(message, who);
  421. }
  422. break;
  423. }
  424. return 0;
  425. }
  426. void aTcpipPanel::begin()
  427. {
  428. comboBox.ListBox().removeAllItems(true);
  429. for ( int i = 0; i < 10; i++ )
  430. {
  431. if ( !strlen( prefs.ipAddresses[i] ) )
  432. break;
  433. comboBox.AddItem( prefs.ipAddresses[i], 0xffffffff );
  434. }
  435. bExpanded = 0;
  436. bFoundConnection = 0;
  437. bConnectingDlg = 0;
  438. bErrorDlg = 0;
  439. }
  440. void aTcpipPanel::destroy()
  441. {
  442. comboBox.destroy();
  443. }
  444. void aTcpipPanel::init(FitIniFile* pFile)
  445. {
  446. FitIniFile &file = (*pFile);
  447. bConnectingDlg = 0;
  448. helpRect.init( pFile, "Rect0" );
  449. button0.init( file, "Button0" );
  450. button0.setMessageOnRelease();
  451. if (button0.getID() == 0)
  452. {
  453. button0.setID(TCPIP_PANEL_FIRST_BUTTON_ID);
  454. }
  455. addChild(&button0);
  456. button0.setPressFX( LOG_VIDEOBUTTONS );
  457. button0.setHighlightFX( LOG_DIGITALHIGHLIGHT );
  458. button0.setDisabledFX( LOG_WRONGBUTTON );
  459. button1.init( file, "Button1" );
  460. button1.setMessageOnRelease();
  461. if (button1.getID() == 0)
  462. {
  463. button1.setID(TCPIP_PANEL_FIRST_BUTTON_ID + 1);
  464. }
  465. addChild(&button1);
  466. button1.setPressFX( LOG_VIDEOBUTTONS );
  467. button1.setHighlightFX( LOG_DIGITALHIGHLIGHT );
  468. button1.setDisabledFX( LOG_WRONGBUTTON );
  469. text0.init( &file, "Text0" );
  470. addChild(&text0);
  471. text1.init( &file, "Text1" );
  472. addChild(&text1);
  473. FitIniFile tmpFile;
  474. FullPathFileName path;
  475. path.init( artPath, "mcl_mp_tcpip_combobox0", ".fit" );
  476. if ( NO_ERR != tmpFile.open( path ) )
  477. {
  478. char errorStr[256];
  479. sprintf( errorStr, "couldn't open file %s", path );
  480. Assert( 0, 0, errorStr );
  481. }
  482. comboBox.init(&tmpFile, "TCPIPAddressComboBox");
  483. comboBox.EditBox().setNumeric(true);
  484. comboBox.EditBox().limitEntry(15);
  485. comboBox.EditBox().setNoBlank( true );
  486. comboBox.EditBox().allowIME( false );
  487. addChild( &comboBox );
  488. for ( int i = 0; i < 10; i++ )
  489. {
  490. if ( !strlen( prefs.ipAddresses[i] ) )
  491. break;
  492. comboBox.AddItem( prefs.ipAddresses[i], 0xffffffff );
  493. }
  494. addChild( &helpRect );
  495. connectingTime = 0;
  496. bFoundConnection = 0;
  497. // need to initialize old addresses
  498. }
  499. void aTcpipPanel::update()
  500. {
  501. long retVal = 0;
  502. if ( bConnectingDlg || bErrorDlg )
  503. {
  504. LogisticsOneButtonDialog::instance()->update();
  505. if ( LogisticsOneButtonDialog::instance()->isDone() )
  506. {
  507. if ( !bErrorDlg )
  508. {
  509. if ( bFoundConnection )
  510. {
  511. long sessionCount;
  512. MC2Session* pSessions = MPlayer->getSessions( sessionCount );
  513. if ( sessionCount )
  514. {
  515. bConnectingDlg = 0;
  516. retVal = MPlayer->joinSession( &pSessions[0], prefs.playerName[0] );
  517. if ( !retVal )
  518. {
  519. pParentScreen->handleMessage( 1, TCPIP_PANEL_FIRST_BUTTON_ID );
  520. MPlayer->endSessionScan();
  521. EString ipAddress;
  522. comboBox.EditBox().getEntry( ipAddress );
  523. prefs.setNewIP( ipAddress );
  524. prefs.save();
  525. connectingTime = 0.f;
  526. }
  527. }
  528. bFoundConnection = 0;
  529. bConnectingDlg = 0;
  530. }
  531. //they cancelled
  532. MPlayer->endSessionScan();
  533. bConnectingDlg = 0;
  534. }
  535. else
  536. {
  537. LogisticsOneButtonDialog::instance()->end();
  538. bErrorDlg = 0;
  539. }
  540. }
  541. else if ( !bErrorDlg && !bFoundConnection )
  542. {
  543. connectingTime += frameLength;
  544. long sessionCount;
  545. MC2Session* pSessions = MPlayer->getSessions( sessionCount );
  546. if ( sessionCount )
  547. {
  548. bFoundConnection = true;
  549. LogisticsOneButtonDialog::instance()->end();
  550. }
  551. else
  552. {
  553. bFoundConnection = false;
  554. if ( connectingTime > 20 )
  555. {
  556. retVal = MPLAYER_ERR_NO_CONNECTION;
  557. connectingTime = 0.f;
  558. }
  559. }
  560. }
  561. if ( retVal )
  562. {
  563. int errorID = IDS_MP_CONNECT_NO_SESSION;
  564. int fontID = IDS_MP_CONNECT_ERROR_NO_SESSION_FONT;
  565. // display a dialog about why this can't happen....
  566. switch ( retVal )
  567. {
  568. case MPLAYER_ERR_HOST_NOT_FOUND:
  569. errorID = IDS_MP_CONNECT_ERROR_NO_HOST;
  570. fontID = IDS_MP_CONNECT_ERROR_NO_HOST_FONT;
  571. break;
  572. case MPLAYER_ERR_NO_CONNECTION:
  573. errorID = IDS_MP_CONNECT_ERROR_NO_CONNECTION;
  574. fontID = IDS_MP_CONNECT_ERROR_NO_CONNECTION_FONT;
  575. break;
  576. case MPLAYER_ERR_SESSION_IN_PROGRESS:
  577. errorID = IDS_MP_CONNECT_ERROR_IN_PROGRESS;
  578. fontID = IDS_MP_CONNECT_ERROR_IN_PROGRESS_FONT;
  579. break;
  580. case MPLAYER_ERR_SESSION_LOCKED:
  581. errorID = IDS_MP_CONNECT_ERROR_LOCKED;
  582. fontID = IDS_MP_CONNECT_ERROR_LOCKED_FONT;
  583. break;
  584. case MPLAYER_ERR_BAD_VERSION:
  585. errorID = IDS_MP_CONNECTION_ERROR_WRONG_VERSION;
  586. fontID = IDS_MP_CONNECTION_ERROR_WRONG_VERSION_FONT;
  587. break;
  588. case MPLAYER_ERR_SESSION_FULL:
  589. errorID = IDS_MP_CONNECTION_ERROR_FULL;
  590. fontID = IDS_MP_CONNECTION_ERROR_FULL_FONT;
  591. break;
  592. }
  593. LogisticsOneButtonDialog::instance()->end();
  594. LogisticsOneButtonDialog::instance()->setText( errorID, IDS_DIALOG_OK, IDS_DIALOG_OK );
  595. LogisticsOneButtonDialog::instance()->setFont( fontID );
  596. LogisticsOneButtonDialog::instance()->begin();
  597. bConnectingDlg = 0;
  598. bErrorDlg = 1;
  599. }
  600. return;
  601. }
  602. if ( comboBox.ListBox().isShowing() )
  603. {
  604. bExpanded = true;
  605. comboBox.update();
  606. }
  607. else
  608. {
  609. if ( !bExpanded )
  610. aObject::update();
  611. if ( userInput->leftMouseReleased() )
  612. bExpanded = 0;
  613. }
  614. // grey out button if inavlid...
  615. EString str;
  616. comboBox.EditBox().getEntry(str);
  617. bool bValid = 1;
  618. if ( str.Length() )
  619. {
  620. // now look for 3 periods
  621. int dotIndex[5];
  622. for ( int i = 0; i < 5; i++ )
  623. dotIndex[i] = -1;
  624. dotIndex[4] = str.Length();
  625. int tmp = -1;
  626. while ( tmp )
  627. {
  628. tmp = str.Find( '.', tmp+1 );
  629. if ( tmp == -1 )
  630. {
  631. break;
  632. }
  633. else
  634. {
  635. for ( i = 0; i < 3; i++ )
  636. {
  637. if ( dotIndex[i+1] == -1 )
  638. {
  639. dotIndex[i+1] = tmp;
  640. break;
  641. }
  642. }
  643. if ( i == 3 ) // to many decimals
  644. {
  645. bValid = 0;
  646. break;
  647. }
  648. }
  649. }
  650. if ( dotIndex[3] == -1 || !bValid )
  651. bValid = 0;
  652. else if ( dotIndex[3] < str.Length() - 1 )
  653. {
  654. bValid = 1;
  655. char tmp[256];
  656. strcpy( tmp, str );
  657. for ( int i = 0; i < 4; i++ )
  658. {
  659. long num = getNum( tmp, dotIndex[i]+1, dotIndex[i+1] );
  660. if ( num < 0 || num > 255 )
  661. {
  662. bValid = 0;
  663. }
  664. }
  665. }
  666. else
  667. bValid = 0;
  668. }
  669. else
  670. bValid = 0;
  671. if ( bValid )
  672. {
  673. button0.disable( 0 );
  674. }
  675. else
  676. button0.disable( 1 );
  677. if ( bValid && gos_GetKeyStatus( KEY_RETURN ) == KEY_RELEASED )
  678. {
  679. handleMessage( TCPIP_PANEL_FIRST_BUTTON_ID, TCPIP_PANEL_FIRST_BUTTON_ID);
  680. }
  681. }
  682. void aTcpipPanel::render()
  683. {
  684. aObject::render();
  685. if ( bConnectingDlg || bErrorDlg )
  686. {
  687. LogisticsOneButtonDialog::instance()->render();
  688. }
  689. }
  690. long aTcpipPanel::getNum( char* pStr, long index1, long index2 )
  691. {
  692. char tmp = pStr[index2];
  693. pStr[index2] = 0;
  694. return atoi( &pStr[index1] );
  695. }
  696. int aTcpipPanel::handleMessage( unsigned long message, unsigned long who)
  697. {
  698. switch ( who )
  699. {
  700. case TCPIP_PANEL_FIRST_BUTTON_ID:
  701. {
  702. bConnectingDlg = true;
  703. bFoundConnection = 0;
  704. LogisticsOneButtonDialog::instance()->setText( IDS_MP_CON_MODEM_CONNECTING, IDS_PM_CANCEL, IDS_PM_CANCEL );
  705. char text[256];
  706. char Display[256];
  707. cLoadString( IDS_MP_CON_MODEM_CONNECTING, text, 255 );
  708. EString str;
  709. comboBox.EditBox().getEntry( str );
  710. sprintf( Display, text, (const char*)str );
  711. LogisticsOneButtonDialog::instance()->setText( Display );
  712. LogisticsOneButtonDialog::instance()->begin();
  713. if ( MPlayer->beginSessionScan ( (char*)(const char*)str) )
  714. {
  715. LogisticsOneButtonDialog::instance()->setText( IDS_MP_CONNECT_ERROR_NO_CONNECTION, IDS_DIALOG_OK, IDS_DIALOG_OK );
  716. }
  717. connectingTime = 0.f;
  718. break;
  719. }
  720. case TCPIP_PANEL_FIRST_BUTTON_ID + 1:
  721. if (pParentScreen)
  722. {
  723. pParentScreen->handleMessage(message, who);
  724. }
  725. break;
  726. }
  727. return 0;
  728. }
  729. //////////////////////////////////////////////
  730. //*************************************************************************************************
  731. // end of file ( MPConnectionType.cpp )