WOLConnect.cpp 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105
  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. * FILE
  21. * $Archive: /Commando/Code/WWOnline/WOLConnect.cpp $
  22. *
  23. * DESCRIPTION
  24. * Westwood Online wait conditions.
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 35 $
  32. * $Modtime: 1/29/02 1:47p $
  33. *
  34. ******************************************************************************/
  35. #include "WOLConnect.h"
  36. #include "WOLProduct.h"
  37. #include "WOLServer.h"
  38. #include "WOLChannel.h"
  39. #include "WOLErrorUtil.h"
  40. #include "WOLString.h"
  41. #include <WWDebug\WWDebug.h>
  42. namespace WOL
  43. {
  44. #include <WOLAPI\ChatDefs.h>
  45. }
  46. namespace WWOnline {
  47. /******************************************************************************
  48. *
  49. * NAME
  50. * ServerListWait::Create
  51. *
  52. * DESCRIPTION
  53. *
  54. * INPUTS
  55. *
  56. * RESULT
  57. * Wait - Wait condition to process.
  58. *
  59. ******************************************************************************/
  60. RefPtr<ServerListWait> ServerListWait::Create(const RefPtr<Session>& session)
  61. {
  62. WWASSERT(session.IsValid() && "ServerListWait");
  63. if (!session.IsValid())
  64. {
  65. WWDEBUG_SAY(("WOLERROR: WWOnline session not instantiated\n"));
  66. return NULL;
  67. }
  68. return new ServerListWait(session);
  69. }
  70. /******************************************************************************
  71. *
  72. * NAME
  73. * ServerListWait::ServerListWait
  74. *
  75. * DESCRIPTION
  76. * Constructor
  77. *
  78. * INPUTS
  79. *
  80. * RESULT
  81. * NONE
  82. *
  83. ******************************************************************************/
  84. ServerListWait::ServerListWait(const RefPtr<Session>& session) :
  85. SingleWait(WOLSTRING("WOL_SERVERLISTFETCH")),
  86. mSession(session)
  87. {
  88. WWDEBUG_SAY(("WOL: ServerListWait Create\n"));
  89. }
  90. /******************************************************************************
  91. *
  92. * NAME
  93. * ServerListWait::~ServerListWait
  94. *
  95. * DESCRIPTION
  96. * Destructor
  97. *
  98. * INPUTS
  99. * NONE
  100. *
  101. * RESULT
  102. * NONE
  103. *
  104. ******************************************************************************/
  105. ServerListWait::~ServerListWait()
  106. {
  107. WWDEBUG_SAY(("WOL: ServerListWait End '%S'\n", mEndText));
  108. }
  109. /******************************************************************************
  110. *
  111. * NAME
  112. * ServerListWait::WaitBeginning
  113. *
  114. * DESCRIPTION
  115. * Start server list wait condition
  116. *
  117. * INPUTS
  118. * NONE
  119. *
  120. * RESULT
  121. * NONE
  122. *
  123. ******************************************************************************/
  124. void ServerListWait::WaitBeginning(void)
  125. {
  126. WWDEBUG_SAY(("WOL: ServerListWait Begin\n"));
  127. WWASSERT(mSession.IsValid() && "ServerListWait");
  128. RefPtrConst<Product> product(Product::Current());
  129. WWASSERT(product.IsValid() && "ServerListWait");
  130. if (!product.IsValid())
  131. {
  132. WWDEBUG_SAY(("WOLERROR: WWOnline product not instantiated\n"));
  133. EndWait(WaitCondition::Error, WOLSTRING("WOL_SERVERLISTERROR"));
  134. return;
  135. }
  136. mSession->AddObserver(*static_cast< Observer<ServerError> *>(this));
  137. mSession->AddObserver(*static_cast< Observer<IRCServerList> *>(this));
  138. bool success = mSession->RequestServerList();
  139. if (!success)
  140. {
  141. WWDEBUG_SAY(("WOLERROR: ServerListWait request failed\n"));
  142. EndWait(Error, WOLSTRING("WOL_SERVERLISTERROR"));
  143. }
  144. }
  145. /******************************************************************************
  146. *
  147. * NAME
  148. * ServerListWait::HandleNotification(ServerError)
  149. *
  150. * DESCRIPTION
  151. * General error notificaiton
  152. *
  153. * INPUTS
  154. *
  155. * RESULT
  156. * NONE
  157. *
  158. ******************************************************************************/
  159. void ServerListWait::HandleNotification(ServerError& serverError)
  160. {
  161. if (mEndResult == Waiting)
  162. {
  163. const wchar_t* errorMsg = serverError.GetDescription();
  164. WWDEBUG_SAY(("WOLERROR: ServerListWait '%S'\n", errorMsg));
  165. EndWait(Error, errorMsg);
  166. }
  167. }
  168. /******************************************************************************
  169. *
  170. * NAME
  171. * ServerListWait::HandleNotification(IRCServerList)
  172. *
  173. * DESCRIPTION
  174. * Server list recieved notification.
  175. *
  176. * INPUTS
  177. *
  178. * RESULT
  179. * NONE
  180. *
  181. ******************************************************************************/
  182. void ServerListWait::HandleNotification(IRCServerList&)
  183. {
  184. if (mEndResult == Waiting)
  185. {
  186. WWDEBUG_SAY(("WOL: ServerListWait successful\n"));
  187. EndWait(ConditionMet, WOLSTRING("WOL_SERVERLISTRECEIVED"));
  188. }
  189. }
  190. //-----------------------------------------------------------------------------
  191. /******************************************************************************
  192. *
  193. * NAME
  194. * DisconnectWait::Create
  195. *
  196. * DESCRIPTION
  197. * Create a disconnect wait condition.
  198. *
  199. * INPUTS
  200. * Session - WWOnline session to initiate disconnect from.
  201. *
  202. * RESULT
  203. * Wait - Wait condition to process.
  204. *
  205. ******************************************************************************/
  206. RefPtr<DisconnectWait> DisconnectWait::Create(const RefPtr<Session>& session)
  207. {
  208. WWASSERT(session.IsValid() && "DisconnectWait");
  209. if (!session.IsValid())
  210. {
  211. WWDEBUG_SAY(("WOLERROR: WWOnline session not instantiated\n"));
  212. return NULL;
  213. }
  214. return new DisconnectWait(session);
  215. }
  216. /******************************************************************************
  217. *
  218. * NAME
  219. * DisconnectWait::DisconnectWait
  220. *
  221. * DESCRIPTION
  222. * Constructor
  223. *
  224. * INPUTS
  225. *
  226. * RESULT
  227. * NONE
  228. *
  229. ******************************************************************************/
  230. DisconnectWait::DisconnectWait(const RefPtr<Session>& session) :
  231. SingleWait(WOLSTRING("WOL_DISCONNECTING")),
  232. mSession(session)
  233. {
  234. WWDEBUG_SAY(("WOL: DisconnectWait Create\n"));
  235. }
  236. /******************************************************************************
  237. *
  238. * NAME
  239. * DisconnectWait::~DisconnectWait
  240. *
  241. * DESCRIPTION
  242. * Destructor
  243. *
  244. * INPUTS
  245. * NONE
  246. *
  247. * RESULT
  248. * NONE
  249. *
  250. ******************************************************************************/
  251. DisconnectWait::~DisconnectWait()
  252. {
  253. WWDEBUG_SAY(("WOL: DisconnectWait End '%S'\n", mEndText));
  254. }
  255. /******************************************************************************
  256. *
  257. * NAME
  258. * DisconnectWait::WaitBeginning
  259. *
  260. * DESCRIPTION
  261. * Start disconnect wait condition
  262. *
  263. * INPUTS
  264. * NONE
  265. *
  266. * RESULT
  267. * NONE
  268. *
  269. ******************************************************************************/
  270. void DisconnectWait::WaitBeginning(void)
  271. {
  272. WWDEBUG_SAY(("WOL: DisconnectWait Begin\n"));
  273. WWASSERT(mSession.IsValid() && "DisconnectWait");
  274. mSession->AddObserver(*static_cast<Observer<ServerError> *>(this));
  275. mSession->AddObserver(*static_cast<Observer<ConnectionStatus> *>(this));
  276. WWASSERT((mSession->GetChatObject() != NULL) && "DisconnectWait");
  277. HRESULT hr = mSession->GetChatObject()->RequestLogout();
  278. if (SUCCEEDED(hr))
  279. {
  280. mSession->mCurrentConnectionStatus = ConnectionDisconnecting;
  281. }
  282. else
  283. {
  284. WWDEBUG_SAY(("WOLERROR: DisconnectWait request failed\n"));
  285. EndWait(Error, WOLSTRING("WOL_DISCONNECTERROR"));
  286. }
  287. }
  288. /******************************************************************************
  289. *
  290. * NAME
  291. * DisconnectWait::EndWait
  292. *
  293. * DESCRIPTION
  294. *
  295. * INPUTS
  296. *
  297. * RESULT
  298. * NONE
  299. *
  300. ******************************************************************************/
  301. void DisconnectWait::EndWait(WaitResult result, const wchar_t* msg)
  302. {
  303. SingleWait::EndWait(result, msg);
  304. if (ConditionMet != result)
  305. {
  306. mSession->mCurrentConnectionStatus = ConnectionDisconnected;
  307. }
  308. }
  309. /******************************************************************************
  310. *
  311. * NAME
  312. * DisconnectWait::HandleNotification
  313. *
  314. * DESCRIPTION
  315. * General server error notification
  316. *
  317. * INPUTS
  318. *
  319. * RESULT
  320. * NONE
  321. *
  322. ******************************************************************************/
  323. void DisconnectWait::HandleNotification(ServerError& serverError)
  324. {
  325. if (mEndResult == Waiting)
  326. {
  327. const wchar_t* errorMsg = serverError.GetDescription();
  328. WWDEBUG_SAY(("WOLERROR: DisconnectWait server error '%S'\n", errorMsg));
  329. EndWait(Error, errorMsg);
  330. }
  331. }
  332. /******************************************************************************
  333. *
  334. * NAME
  335. * DisconnectWait::HandleNotification(ConnectionStatus)
  336. *
  337. * DESCRIPTION
  338. *
  339. * INPUTS
  340. *
  341. * RESULT
  342. * NONE
  343. *
  344. ******************************************************************************/
  345. void DisconnectWait::HandleNotification(ConnectionStatus& status)
  346. {
  347. if (mEndResult == Waiting)
  348. {
  349. if (status == ConnectionDisconnected)
  350. {
  351. WWDEBUG_SAY(("WOL: DisconnectWait successful\n"));
  352. EndWait(ConditionMet, WOLSTRING("WOL_DISCONNECTED"));
  353. }
  354. else
  355. {
  356. WWDEBUG_SAY(("WOLERROR: DisconnectWait did not receive disconnect\n"));
  357. EndWait(Error, WOLSTRING("WOL_DISCONNECTERROR"));
  358. }
  359. }
  360. }
  361. //-----------------------------------------------------------------------------
  362. /******************************************************************************
  363. *
  364. * NAME
  365. * ConnectWait::Create
  366. *
  367. * DESCRIPTION
  368. * Create a server connect wait condition.
  369. *
  370. * INPUTS
  371. * Session - WWOnline session
  372. * Server - Server to connect to.
  373. * Login - Login to connect with.
  374. *
  375. * RESULT
  376. * Wait - Wait condition to process.
  377. *
  378. ******************************************************************************/
  379. RefPtr<ConnectWait> ConnectWait::Create(const RefPtr<Session>& session,
  380. const RefPtr<ServerData>& server, const RefPtr<LoginInfo>& login)
  381. {
  382. WWASSERT(session.IsValid() && "ConnectWait");
  383. WWASSERT(server.IsValid() && "ConnectWait");
  384. WWASSERT(login.IsValid() && "ConnectWait");
  385. if (!session.IsValid() || !server.IsValid() || !login.IsValid())
  386. {
  387. return NULL;
  388. }
  389. return new ConnectWait(session, server, login);
  390. }
  391. /******************************************************************************
  392. *
  393. * NAME
  394. * ConnectWait::ConnectWait
  395. *
  396. * DESCRIPTION
  397. *
  398. * INPUTS
  399. *
  400. * RESULT
  401. * NONE
  402. *
  403. ******************************************************************************/
  404. ConnectWait::ConnectWait(const RefPtr<Session>& session, const RefPtr<ServerData>& server,
  405. const RefPtr<LoginInfo>& login) :
  406. SingleWait(WOLSTRING("WOL_CONNECTING")),
  407. mSession(session),
  408. mServer(server),
  409. mLogin(login)
  410. {
  411. WWDEBUG_SAY(("WOL: ConnectWait Create\n"));
  412. }
  413. /******************************************************************************
  414. *
  415. * NAME
  416. * ConnectWait::~ConnectWait
  417. *
  418. * DESCRIPTION
  419. * Destructor
  420. *
  421. * INPUTS
  422. * NONE
  423. *
  424. * RESULT
  425. * NONE
  426. *
  427. ******************************************************************************/
  428. ConnectWait::~ConnectWait()
  429. {
  430. WWDEBUG_SAY(("WOL: ConnectWait End %S\n", mEndText));
  431. }
  432. /******************************************************************************
  433. *
  434. * NAME
  435. * ConnectWait::WaitBeginning
  436. *
  437. * DESCRIPTION
  438. * Start connection wait condition.
  439. *
  440. * INPUTS
  441. * NONE
  442. *
  443. * RESULT
  444. * NONE
  445. *
  446. ******************************************************************************/
  447. void ConnectWait::WaitBeginning(void)
  448. {
  449. WWDEBUG_SAY(("WOL: ConnectWait Begin\n"));
  450. WWASSERT(mSession.IsValid() && "ConnectWait");
  451. mSession->AddObserver(*static_cast<Observer<ServerError> *>(this));
  452. mSession->AddObserver(*static_cast<Observer<ConnectionStatus> *>(this));
  453. WWASSERT(mServer.IsValid() && "ConnectWait");
  454. WOL::Server& server = mServer->GetData();
  455. WWASSERT(mLogin.IsValid() && "ConnectWait");
  456. wcstombs((char*)server.login, (const WCHAR*)mLogin->GetNickname(), sizeof(server.login));
  457. wcstombs((char*)server.password, (const WCHAR*)mLogin->GetPassword(), sizeof(server.password));
  458. WWASSERT((mSession->GetChatObject() != NULL) && "ConnectWait");
  459. HRESULT hr = mSession->GetChatObject()->RequestConnection(&server, 20, !mLogin->IsPasswordEncrypted());
  460. if (SUCCEEDED(hr))
  461. {
  462. mSession->mCurrentConnectionStatus = ConnectionConnecting;
  463. }
  464. else
  465. {
  466. WWDEBUG_SAY(("WOLERROR: ConnectWait request failed '%s'\n", GetChatErrorString(hr)));
  467. EndWait(Error, WOLSTRING("WOL_CONNECTERROR"));
  468. }
  469. }
  470. /******************************************************************************
  471. *
  472. * NAME
  473. * DisconnectWait::EndWait
  474. *
  475. * DESCRIPTION
  476. *
  477. * INPUTS
  478. *
  479. * RESULT
  480. * NONE
  481. *
  482. ******************************************************************************/
  483. void ConnectWait::EndWait(WaitResult result, const wchar_t* msg)
  484. {
  485. SingleWait::EndWait(result, msg);
  486. if (ConditionMet != result)
  487. {
  488. mSession->mCurrentConnectionStatus = ConnectionDisconnected;
  489. }
  490. }
  491. /******************************************************************************
  492. *
  493. * NAME
  494. * ConnectWait::HandleNotification(ServerError)
  495. *
  496. * DESCRIPTION
  497. *
  498. * INPUTS
  499. *
  500. * RESULT
  501. * NONE
  502. *
  503. ******************************************************************************/
  504. void ConnectWait::HandleNotification(ServerError& serverError)
  505. {
  506. if (mEndResult == Waiting)
  507. {
  508. mSession->mCurrentConnectionStatus = ConnectionDisconnected;
  509. const wchar_t* errorMsg = serverError.GetDescription();
  510. WWDEBUG_SAY(("WOLERROR: ConnectWait server error '%S'\n", errorMsg));
  511. EndWait(Error, errorMsg);
  512. }
  513. }
  514. /******************************************************************************
  515. *
  516. * NAME
  517. * ConnectWait::HandleNotification(ConnectionStatus)
  518. *
  519. * DESCRIPTION
  520. *
  521. * INPUTS
  522. *
  523. * RESULT
  524. * NONE
  525. *
  526. ******************************************************************************/
  527. void ConnectWait::HandleNotification(ConnectionStatus& status)
  528. {
  529. if (mEndResult == Waiting)
  530. {
  531. if (status == ConnectionConnected)
  532. {
  533. WWDEBUG_SAY(("WOL: ConnectWait successful\n"));
  534. EndWait(ConditionMet, WOLSTRING("WOL_CONNECTED"));
  535. }
  536. else
  537. {
  538. WWDEBUG_SAY(("WOLERROR: ConnectWait did not receive connect\n"));
  539. EndWait(Error, WOLSTRING("WOL_CONNECTERROR"));
  540. }
  541. }
  542. }
  543. //-----------------------------------------------------------------------------
  544. /******************************************************************************
  545. *
  546. * NAME
  547. * ChannelListWait::Create
  548. *
  549. * DESCRIPTION
  550. *
  551. * INPUTS
  552. *
  553. * RESULT
  554. *
  555. ******************************************************************************/
  556. RefPtr<ChannelListWait> ChannelListWait::Create(const RefPtr<Session>& session, int type)
  557. {
  558. WWASSERT(session.IsValid() && "ChannelListWait");
  559. if (!session.IsValid())
  560. {
  561. return NULL;
  562. }
  563. return new ChannelListWait(session, type);
  564. }
  565. /******************************************************************************
  566. *
  567. * NAME
  568. * ChannelListWait::ChannelListWait
  569. *
  570. * DESCRIPTION
  571. * Constructor
  572. *
  573. * INPUTS
  574. *
  575. * RESULT
  576. * NONE
  577. *
  578. ******************************************************************************/
  579. ChannelListWait::ChannelListWait(const RefPtr<Session>& session, int type) :
  580. SingleWait(WOLSTRING("WOL_CHANNELLISTFETCH")),
  581. mSession(session),
  582. mType(type)
  583. {
  584. WWDEBUG_SAY(("WOL: ChannelListWait Create\n"));
  585. }
  586. /******************************************************************************
  587. *
  588. * NAME
  589. * ChannelListWait::~ChannelListWait
  590. *
  591. * DESCRIPTION
  592. * Destructor
  593. *
  594. * INPUTS
  595. * NONE
  596. *
  597. * RESULT
  598. * NONE
  599. *
  600. ******************************************************************************/
  601. ChannelListWait::~ChannelListWait()
  602. {
  603. WWDEBUG_SAY(("WOL: ChannelListWait End %S\n", mEndText));
  604. }
  605. /******************************************************************************
  606. *
  607. * NAME
  608. * ChannelListWait::WaitBeginning
  609. *
  610. * DESCRIPTION
  611. * Start channel list request wait condition.
  612. *
  613. * INPUTS
  614. * NONE
  615. *
  616. * RESULT
  617. * NONE
  618. *
  619. ******************************************************************************/
  620. void ChannelListWait::WaitBeginning(void)
  621. {
  622. WWDEBUG_SAY(("WOL: ChannelListWait Begin\n"));
  623. WWASSERT(mSession.IsValid() && "ChannelListWait");
  624. mSession->AddObserver(*static_cast<Observer<ServerError> *>(this));
  625. mSession->AddObserver(*static_cast<Observer<ConnectionStatus> *>(this));
  626. mSession->AddObserver(*static_cast<Observer<ChannelListEvent> *>(this));
  627. bool success = mSession->RequestChannelList(mType, false);
  628. if (!success)
  629. {
  630. WWDEBUG_SAY(("WOLERROR: ChannelListWait request failed\n"));
  631. EndWait(Error, WOLSTRING("WOL_CHANNELLISTERROR"));
  632. }
  633. }
  634. /******************************************************************************
  635. *
  636. * NAME
  637. * ChannelListWait::HandleNotification(ServerError)
  638. *
  639. * DESCRIPTION
  640. *
  641. * INPUTS
  642. *
  643. * RESULT
  644. * NONE
  645. *
  646. ******************************************************************************/
  647. void ChannelListWait::HandleNotification(ServerError& serverError)
  648. {
  649. if (mEndResult == Waiting)
  650. {
  651. const wchar_t* errorMsg = serverError.GetDescription();
  652. WWDEBUG_SAY(("WOLERROR: ChannelListWait server error '%S'\n", errorMsg));
  653. EndWait(Error, errorMsg);
  654. }
  655. }
  656. /******************************************************************************
  657. *
  658. * NAME
  659. * ChannelListWait::HandleNotification(ConnectionStatus)
  660. *
  661. * DESCRIPTION
  662. *
  663. * INPUTS
  664. *
  665. * RESULT
  666. * NONE
  667. *
  668. ******************************************************************************/
  669. void ChannelListWait::HandleNotification(ConnectionStatus& status)
  670. {
  671. if (mEndResult == Waiting)
  672. {
  673. if (status != ConnectionConnected)
  674. {
  675. WWDEBUG_SAY(("WOLERROR: ChannelListWait not connected to server\n"));
  676. EndWait(Error, WOLSTRING("WOL_NOTCONNECTED"));
  677. }
  678. }
  679. }
  680. /******************************************************************************
  681. *
  682. * NAME
  683. * ChannelListWait::HandleNotification(ChannelListEvent)
  684. *
  685. * DESCRIPTION
  686. *
  687. * INPUTS
  688. *
  689. * RESULT
  690. * NONE
  691. *
  692. ******************************************************************************/
  693. void ChannelListWait::HandleNotification(ChannelListEvent& event)
  694. {
  695. if (mEndResult == Waiting)
  696. {
  697. if ((event.GetEvent() == ChannelListEvent::NewList) && (event.GetChannelType() == mType))
  698. {
  699. WWDEBUG_SAY(("WOL: ChannelListWait successful\n"));
  700. EndWait(ConditionMet, WOLSTRING("WOL_CHANNELLISTRECEIVED"));
  701. }
  702. }
  703. }
  704. //-----------------------------------------------------------------------------
  705. /******************************************************************************
  706. *
  707. * NAME
  708. * LeaveChannelWait::Create
  709. *
  710. * DESCRIPTION
  711. *
  712. * INPUTS
  713. *
  714. * RESULT
  715. *
  716. ******************************************************************************/
  717. RefPtr<LeaveChannelWait> LeaveChannelWait::Create(const RefPtr<Session>& session)
  718. {
  719. WWASSERT(session.IsValid() && "LeaveChannelWait");
  720. if (!session.IsValid())
  721. {
  722. return NULL;
  723. }
  724. return new LeaveChannelWait(session);
  725. }
  726. /******************************************************************************
  727. *
  728. * NAME
  729. * LeaveChannelWait::LeaveChannelWait
  730. *
  731. * DESCRIPTION
  732. * Constructor
  733. *
  734. * INPUTS
  735. *
  736. * RESULT
  737. * NONE
  738. *
  739. ******************************************************************************/
  740. LeaveChannelWait::LeaveChannelWait(const RefPtr<Session>& session) :
  741. SingleWait(WOLSTRING("WOL_CHANNELLEAVE")),
  742. mSession(session)
  743. {
  744. WWDEBUG_SAY(("WOL: LeaveChannelWait Create\n"));
  745. }
  746. /******************************************************************************
  747. *
  748. * NAME
  749. * LeaveChannelWait::~LeaveChannelWait
  750. *
  751. * DESCRIPTION
  752. *
  753. * INPUTS
  754. * NONE
  755. *
  756. * RESULT
  757. * NONE
  758. *
  759. ******************************************************************************/
  760. LeaveChannelWait::~LeaveChannelWait()
  761. {
  762. WWDEBUG_SAY(("WOL: LeaveChannelWait End %S\n", mEndText));
  763. }
  764. /******************************************************************************
  765. *
  766. * NAME
  767. * LeaveChannelWait::WaitBeginning
  768. *
  769. * DESCRIPTION
  770. * Start leave channel wait condition.
  771. *
  772. * INPUTS
  773. * NONE
  774. *
  775. * RESULT
  776. * NONE
  777. *
  778. ******************************************************************************/
  779. void LeaveChannelWait::WaitBeginning(void)
  780. {
  781. WWDEBUG_SAY(("WOL: LeaveChannelWait Begin\n"));
  782. WWASSERT(mSession.IsValid() && "LeaveChannelWait");
  783. ChannelStatus status = mSession->GetChannelStatus();
  784. // If we are not joined to a channel and not already leaving
  785. // a channel then we have successfully left a channel.
  786. if (ChannelJoined != status && ChannelLeaving != status)
  787. {
  788. EndWait(ConditionMet, WOLSTRING("WOL_CHANNELLEFT"));
  789. return;
  790. }
  791. // Listen for various events
  792. mSession->AddObserver(*static_cast<Observer<ServerError> *>(this));
  793. mSession->AddObserver(*static_cast<Observer<ConnectionStatus> *>(this));
  794. mSession->AddObserver(*static_cast<Observer<ChannelEvent> *>(this));
  795. // If we are currently joined the request to leave.
  796. if (ChannelJoined == status)
  797. {
  798. // Make the request to leave the channel
  799. bool success = mSession->RequestLeaveChannel();
  800. if (!success)
  801. {
  802. EndWait(Error, WOLSTRING("WOL_CHANNELLEAVEERROR"));
  803. }
  804. }
  805. }
  806. /******************************************************************************
  807. *
  808. * NAME
  809. * LeaveChannelWait::HandleNotification(ServerError)
  810. *
  811. * DESCRIPTION
  812. *
  813. * INPUTS
  814. *
  815. * RESULT
  816. * NONE
  817. *
  818. ******************************************************************************/
  819. void LeaveChannelWait::HandleNotification(ServerError& serverError)
  820. {
  821. // If we get a server error while leaving a channel then something is wrong.
  822. if (mEndResult == Waiting)
  823. {
  824. const wchar_t* errorMsg = serverError.GetDescription();
  825. WWDEBUG_SAY(("WOLERROR: LeaveChannelWait server error '%S'\n", errorMsg));
  826. EndWait(Error, errorMsg);
  827. }
  828. }
  829. /******************************************************************************
  830. *
  831. * NAME
  832. * LeaveChannelWait::HandleNotification(ConnectionStatus)
  833. *
  834. * DESCRIPTION
  835. *
  836. * INPUTS
  837. *
  838. * RESULT
  839. * NONE
  840. *
  841. ******************************************************************************/
  842. void LeaveChannelWait::HandleNotification(ConnectionStatus& status)
  843. {
  844. if (mEndResult == Waiting)
  845. {
  846. if (status != ConnectionConnected)
  847. {
  848. WWDEBUG_SAY(("WOLWARNING: LeaveChannelWait not connected to server\n"));
  849. EndWait(ConditionMet, WOLSTRING("WOL_NOTCONNECTED"));
  850. }
  851. }
  852. }
  853. /******************************************************************************
  854. *
  855. * NAME
  856. * LeaveChannelWait::HandleNotification(ChannelEvent)
  857. *
  858. * DESCRIPTION
  859. *
  860. * INPUTS
  861. *
  862. * RESULT
  863. * NONE
  864. *
  865. ******************************************************************************/
  866. void LeaveChannelWait::HandleNotification(ChannelEvent& event)
  867. {
  868. if (mEndResult == Waiting)
  869. {
  870. // If we left the channel then the condition is met.
  871. // Otherwise something went wrong.
  872. if (event.GetStatus() == ChannelLeft)
  873. {
  874. WWDEBUG_SAY(("WOL: LeaveChannelWait successful\n"));
  875. EndWait(ConditionMet, WOLSTRING("WOL_CHANNELLEFT"));
  876. }
  877. else
  878. {
  879. WWDEBUG_SAY(("WOLERROR: LeaveChannelWait channel not left\n"));
  880. EndWait(Error, WOLSTRING("WOL_CHANNELLEAVEERROR"));
  881. }
  882. }
  883. }
  884. //-----------------------------------------------------------------------------
  885. /******************************************************************************
  886. *
  887. * NAME
  888. * JoinChannelWait::Create
  889. *
  890. * DESCRIPTION
  891. *
  892. * INPUTS
  893. *
  894. * RESULT
  895. *
  896. ******************************************************************************/
  897. RefPtr<JoinChannelWait> JoinChannelWait::Create(const RefPtr<Session>& session,
  898. const RefPtr<ChannelData>& channel, const wchar_t* password)
  899. {
  900. WWASSERT(session.IsValid() && "JoinChannelWait");
  901. if (!session.IsValid())
  902. {
  903. return NULL;
  904. }
  905. return new JoinChannelWait(session, channel, password);
  906. }
  907. /******************************************************************************
  908. *
  909. * NAME
  910. * JoinChannelWait::Create
  911. *
  912. * DESCRIPTION
  913. *
  914. * INPUTS
  915. *
  916. * RESULT
  917. *
  918. ******************************************************************************/
  919. RefPtr<JoinChannelWait> JoinChannelWait::Create(const RefPtr<Session>& session,
  920. const wchar_t* channelName, const wchar_t* password, int type)
  921. {
  922. WWASSERT(session.IsValid() && "JoinChannelWait");
  923. WWASSERT(channelName && "JoinChannelWait");
  924. if (!session.IsValid() || (channelName == NULL))
  925. {
  926. return NULL;
  927. }
  928. return new JoinChannelWait(session, channelName, password, type);
  929. }
  930. /******************************************************************************
  931. *
  932. * NAME
  933. * JoinChannelWait::JoinChannelWait
  934. *
  935. * DESCRIPTION
  936. * Constructor
  937. *
  938. * INPUTS
  939. *
  940. * RESULT
  941. * NONE
  942. *
  943. ******************************************************************************/
  944. JoinChannelWait::JoinChannelWait(const RefPtr<Session>& session,
  945. const RefPtr<ChannelData>& channel, const wchar_t* password) :
  946. SingleWait(WOLSTRING("WOL_CHANNELJOIN")),
  947. mSession(session),
  948. mChannel(channel),
  949. mPassword(password),
  950. mType(0)
  951. {
  952. WWDEBUG_SAY(("WOL: JoinChannelWait Create\n"));
  953. }
  954. /******************************************************************************
  955. *
  956. * NAME
  957. * JoinChannelWait::JoinChannelWait
  958. *
  959. * DESCRIPTION
  960. * Constructor
  961. *
  962. * INPUTS
  963. *
  964. * RESULT
  965. * NONE
  966. *
  967. ******************************************************************************/
  968. JoinChannelWait::JoinChannelWait(const RefPtr<Session>& session,
  969. const wchar_t* channelName, const wchar_t* password, int type) :
  970. SingleWait(WOLSTRING("WOL_CHANNELJOIN")),
  971. mSession(session),
  972. mChannelName(channelName),
  973. mPassword(password),
  974. mType(type)
  975. {
  976. WWDEBUG_SAY(("WOL: JoinChannelWait Create\n"));
  977. }
  978. /******************************************************************************
  979. *
  980. * NAME
  981. * JoinChannelWait::~JoinChannelWait
  982. *
  983. * DESCRIPTION
  984. * Destructor
  985. *
  986. * INPUTS
  987. * NONE
  988. *
  989. * RESULT
  990. * NONE
  991. *
  992. ******************************************************************************/
  993. JoinChannelWait::~JoinChannelWait()
  994. {
  995. WWDEBUG_SAY(("WOL: JoinChannelWait End %S\n", mEndText));
  996. }
  997. /******************************************************************************
  998. *
  999. * NAME
  1000. * JoinChannelWait::WaitCondition
  1001. *
  1002. * DESCRIPTION
  1003. * Start channel join wait condition.
  1004. *
  1005. * INPUTS
  1006. * NONE
  1007. *
  1008. * RESULT
  1009. * NONE
  1010. *
  1011. ******************************************************************************/
  1012. void JoinChannelWait::WaitBeginning(void)
  1013. {
  1014. WWDEBUG_SAY(("WOL: JoinChannelWait Begin\n"));
  1015. WWASSERT(mSession.IsValid() && "JoinChannelWait");
  1016. // If a channel is not specified then search for the named channel
  1017. if (!mChannel.IsValid())
  1018. {
  1019. mChannel = mSession->FindChannel(mChannelName);
  1020. // If the channel cannot be found then create one
  1021. if (!mChannel.IsValid())
  1022. {
  1023. mChannel = ChannelData::Create(mChannelName, mPassword, mType);
  1024. }
  1025. }
  1026. if (!mChannel.IsValid())
  1027. {
  1028. WWDEBUG_SAY(("WOLERROR: JoinChanneWait Channel not found\n"));
  1029. EndWait(Error, WOLSTRING("WOL_CHANNELNOTFOUND"));
  1030. return;
  1031. }
  1032. mSession->AddObserver(*static_cast<Observer<ServerError> *>(this));
  1033. mSession->AddObserver(*static_cast<Observer<ConnectionStatus> *>(this));
  1034. mSession->AddObserver(*static_cast<Observer<ChannelEvent> *>(this));
  1035. bool success = mSession->RequestChannelJoin(mChannel, mPassword);
  1036. if (!success)
  1037. {
  1038. WWDEBUG_SAY(("WOLERROR: JoinChanneWait request failed\n"));
  1039. EndWait(Error, WOLSTRING("WOL_CHANNELJOINERROR"));
  1040. }
  1041. }
  1042. /******************************************************************************
  1043. *
  1044. * NAME
  1045. * JoinChannelWait::HandleNotification(ServerError)
  1046. *
  1047. * DESCRIPTION
  1048. *
  1049. * INPUTS
  1050. *
  1051. * RESULT
  1052. * NONE
  1053. *
  1054. ******************************************************************************/
  1055. void JoinChannelWait::HandleNotification(ServerError& serverError)
  1056. {
  1057. // Join failed if we get a server error.
  1058. if (mEndResult == Waiting)
  1059. {
  1060. const wchar_t* errorMsg = serverError.GetDescription();
  1061. WWDEBUG_SAY(("WOLERROR: JoinChannelWait server error '%S'\n", errorMsg));
  1062. EndWait(Error, errorMsg);
  1063. }
  1064. }
  1065. /******************************************************************************
  1066. *
  1067. * NAME
  1068. * JoinChannelWait::HandleNotification(ConnectionStatus)
  1069. *
  1070. * DESCRIPTION
  1071. *
  1072. * INPUTS
  1073. *
  1074. * RESULT
  1075. * NONE
  1076. *
  1077. ******************************************************************************/
  1078. void JoinChannelWait::HandleNotification(ConnectionStatus& status)
  1079. {
  1080. if (mEndResult == Waiting)
  1081. {
  1082. // Join failed if the connection is not present or lost.
  1083. if (status != ConnectionConnected)
  1084. {
  1085. WWDEBUG_SAY(("WOLERROR: JoinChanneWait not connected to server\n"));
  1086. EndWait(Error, WOLSTRING("WOL_NOTCONNECTED"));
  1087. }
  1088. }
  1089. }
  1090. /******************************************************************************
  1091. *
  1092. * NAME
  1093. * JoinChannelWait::HandleNotification(ChannelEvent)
  1094. *
  1095. * DESCRIPTION
  1096. *
  1097. * INPUTS
  1098. *
  1099. * RESULT
  1100. * NONE
  1101. *
  1102. ******************************************************************************/
  1103. void JoinChannelWait::HandleNotification(ChannelEvent& event)
  1104. {
  1105. if (mEndResult == Waiting)
  1106. {
  1107. // If we joined the channel the condition is met
  1108. if (ChannelJoined == event.GetStatus())
  1109. {
  1110. WWDEBUG_SAY(("WOL: JoinChanneWait successful\n"));
  1111. EndWait(ConditionMet, WOLSTRING("WOL_CHANNELJOINED"));
  1112. }
  1113. else
  1114. {
  1115. WWDEBUG_SAY(("WOLERROR: JoinChanneWait failed\n"));
  1116. EndWait(Error, GetChannelStatusDescription(event.GetStatus()));
  1117. }
  1118. }
  1119. }
  1120. //-----------------------------------------------------------------------------
  1121. /******************************************************************************
  1122. *
  1123. * NAME
  1124. * CreateChannelWait::Create
  1125. *
  1126. * DESCRIPTION
  1127. *
  1128. * INPUTS
  1129. *
  1130. * RESULT
  1131. *
  1132. ******************************************************************************/
  1133. RefPtr<CreateChannelWait> CreateChannelWait::Create(const RefPtr<Session>& session,
  1134. const RefPtr<ChannelData>& channel, const wchar_t* password)
  1135. {
  1136. WWASSERT(session.IsValid() && "CreateChannelWait");
  1137. if (!session.IsValid())
  1138. {
  1139. return NULL;
  1140. }
  1141. return new CreateChannelWait(session, channel, password);
  1142. }
  1143. /******************************************************************************
  1144. *
  1145. * NAME
  1146. * CreateChannelWait::CreateChannelWait
  1147. *
  1148. * DESCRIPTION
  1149. * Destructor
  1150. *
  1151. * INPUTS
  1152. *
  1153. * RESULT
  1154. * NONE
  1155. *
  1156. ******************************************************************************/
  1157. CreateChannelWait::CreateChannelWait(const RefPtr<Session>& session,
  1158. const RefPtr<ChannelData>& channel, const wchar_t* password) :
  1159. SingleWait(WOLSTRING("WOL_CHANNELCREATE")),
  1160. mSession(session),
  1161. mChannel(channel),
  1162. mPassword(password)
  1163. {
  1164. WWDEBUG_SAY(("WOL: CreateChannelWait Create\n"));
  1165. }
  1166. /******************************************************************************
  1167. *
  1168. * NAME
  1169. * CreateChannelWait::~CreateChannelWait
  1170. *
  1171. * DESCRIPTION
  1172. * Destructor
  1173. *
  1174. * INPUTS
  1175. * NONE
  1176. *
  1177. * RESULT
  1178. * NONE
  1179. *
  1180. ******************************************************************************/
  1181. CreateChannelWait::~CreateChannelWait()
  1182. {
  1183. WWDEBUG_SAY(("WOL: CreateChannelWait End %S\n", mEndText));
  1184. }
  1185. /******************************************************************************
  1186. *
  1187. * NAME
  1188. * CreateChannelWait::WaitBeginning
  1189. *
  1190. * DESCRIPTION
  1191. * Start channel creation wait condition
  1192. *
  1193. * INPUTS
  1194. * NONE
  1195. *
  1196. * RESULT
  1197. * NONE
  1198. *
  1199. ******************************************************************************/
  1200. void CreateChannelWait::WaitBeginning(void)
  1201. {
  1202. WWDEBUG_SAY(("WOL: CreateChannelWait Begin\n"));
  1203. WWASSERT(mSession.IsValid() && "CreateChannelWait");
  1204. mSession->AddObserver(*static_cast<Observer<ServerError> *>(this));
  1205. mSession->AddObserver(*static_cast<Observer<ConnectionStatus> *>(this));
  1206. mSession->AddObserver(*static_cast<Observer<ChannelEvent> *>(this));
  1207. WWASSERT(mChannel.IsValid() && "CreateChannelWait");
  1208. WOL::Channel& channel = mChannel->GetData();
  1209. wcstombs((char*)channel.key, (const WCHAR*)mPassword, sizeof(channel.key));
  1210. WWASSERT((mSession->GetChatObject() != NULL) && "CreateChannelWait");
  1211. HRESULT hr = mSession->GetChatObject()->RequestChannelCreate(&channel);
  1212. if (FAILED(hr))
  1213. {
  1214. WWDEBUG_SAY(("WOLERROR: CreateChanneWait request failed '%s'\n", GetChatErrorString(hr)));
  1215. EndWait(Error, WOLSTRING("WOL_CHANNELCREATEERROR"));
  1216. }
  1217. }
  1218. /******************************************************************************
  1219. *
  1220. * NAME
  1221. * CreateChannelWait::HandleNotification(ServerError)
  1222. *
  1223. * DESCRIPTION
  1224. *
  1225. * INPUTS
  1226. *
  1227. * RESULT
  1228. * NONE
  1229. *
  1230. ******************************************************************************/
  1231. void CreateChannelWait::HandleNotification(ServerError& serverError)
  1232. {
  1233. if (mEndResult == Waiting)
  1234. {
  1235. const wchar_t* errorMsg = serverError.GetDescription();
  1236. WWDEBUG_SAY(("WOLERROR: CreateChannelWait server error '%S'\n", errorMsg));
  1237. EndWait(Error, errorMsg);
  1238. }
  1239. }
  1240. /******************************************************************************
  1241. *
  1242. * NAME
  1243. * CreateChannelWait::HandleNotification(ConnectionStatus)
  1244. *
  1245. * DESCRIPTION
  1246. *
  1247. * INPUTS
  1248. *
  1249. * RESULT
  1250. * NONE
  1251. *
  1252. ******************************************************************************/
  1253. void CreateChannelWait::HandleNotification(ConnectionStatus& status)
  1254. {
  1255. if (mEndResult == Waiting)
  1256. {
  1257. if (status != ConnectionConnected)
  1258. {
  1259. WWDEBUG_SAY(("WOLERROR: CreateChannelWait not connected to server\n"));
  1260. EndWait(Error, WOLSTRING("WOL_NOTCONNECTED"));
  1261. }
  1262. }
  1263. }
  1264. /******************************************************************************
  1265. *
  1266. * NAME
  1267. * CreateChannelWait::HandleNotification(ChannelEvent)
  1268. *
  1269. * DESCRIPTION
  1270. *
  1271. * INPUTS
  1272. *
  1273. * RESULT
  1274. * NONE
  1275. *
  1276. ******************************************************************************/
  1277. void CreateChannelWait::HandleNotification(ChannelEvent& event)
  1278. {
  1279. if (mEndResult == Waiting)
  1280. {
  1281. ChannelStatus status = event.GetStatus();
  1282. if (ChannelCreated == status)
  1283. {
  1284. WWDEBUG_SAY(("WOL: CreateChannelWait successful\n"));
  1285. EndWait(ConditionMet, WOLSTRING("WOL_CHANNELJOINED"));
  1286. }
  1287. else
  1288. {
  1289. WWDEBUG_SAY(("WOLERROR: CreateChannelWait failed\n"));
  1290. EndWait(Error, GetChannelStatusDescription(status));
  1291. }
  1292. }
  1293. }
  1294. //-----------------------------------------------------------------------------
  1295. /******************************************************************************
  1296. *
  1297. * NAME
  1298. * UserListWait::Create
  1299. *
  1300. * DESCRIPTION
  1301. *
  1302. * INPUTS
  1303. *
  1304. * RESULT
  1305. *
  1306. ******************************************************************************/
  1307. RefPtr<UserListWait> UserListWait::Create(const RefPtr<Session>& session)
  1308. {
  1309. WWASSERT(session.IsValid() && "UserListWait");
  1310. if (!session.IsValid())
  1311. {
  1312. return NULL;
  1313. }
  1314. return new UserListWait(session);
  1315. }
  1316. /******************************************************************************
  1317. *
  1318. * NAME
  1319. * UserListWait::WaitBeginning
  1320. *
  1321. * DESCRIPTION
  1322. *
  1323. * INPUTS
  1324. * NONE
  1325. *
  1326. * RESULT
  1327. * NONE
  1328. *
  1329. ******************************************************************************/
  1330. void UserListWait::WaitBeginning(void)
  1331. {
  1332. WWDEBUG_SAY(("WOL: UserListWait Begin\n"));
  1333. WWASSERT(mSession.IsValid() && "UserListWait");
  1334. Observer<ServerError>::NotifyMe(*mSession);
  1335. Observer<UserList>::NotifyMe(*mSession);
  1336. }
  1337. /******************************************************************************
  1338. *
  1339. * NAME
  1340. * UserListWait::UserListWait
  1341. *
  1342. * DESCRIPTION
  1343. *
  1344. * INPUTS
  1345. *
  1346. * RESULT
  1347. * NONE
  1348. *
  1349. ******************************************************************************/
  1350. UserListWait::UserListWait(const RefPtr<Session>& session) :
  1351. mSession(session)
  1352. {
  1353. WWDEBUG_SAY(("WOL: UserListWait Create\n"));
  1354. }
  1355. /******************************************************************************
  1356. *
  1357. * NAME
  1358. * UserListWait::~UserListWait
  1359. *
  1360. * DESCRIPTION
  1361. *
  1362. * INPUTS
  1363. * NONE
  1364. *
  1365. * RESULT
  1366. * NONE
  1367. *
  1368. ******************************************************************************/
  1369. UserListWait::~UserListWait()
  1370. {
  1371. WWDEBUG_SAY(("WOL: UserListWait End %S\n", mEndText));
  1372. }
  1373. /******************************************************************************
  1374. *
  1375. * NAME
  1376. * UserListWait::HandleNotification(ServerError)
  1377. *
  1378. * DESCRIPTION
  1379. *
  1380. * INPUTS
  1381. *
  1382. * RESULT
  1383. * NONE
  1384. *
  1385. ******************************************************************************/
  1386. void UserListWait::HandleNotification(ServerError& error)
  1387. {
  1388. if (mEndResult == Waiting)
  1389. {
  1390. const wchar_t* errorMsg = error.GetDescription();
  1391. WWDEBUG_SAY(("WOLERROR: UserListWait server error '%S'\n", errorMsg));
  1392. EndWait(Error, errorMsg);
  1393. }
  1394. }
  1395. /******************************************************************************
  1396. *
  1397. * NAME
  1398. * UserListWait::HandleNotification(UserList)
  1399. *
  1400. * DESCRIPTION
  1401. *
  1402. * INPUTS
  1403. *
  1404. * RESULT
  1405. * NONE
  1406. *
  1407. ******************************************************************************/
  1408. void UserListWait::HandleNotification(UserList&)
  1409. {
  1410. if (mEndResult == Waiting)
  1411. {
  1412. WWDEBUG_SAY(("WOL: UserListWait successful\n"));
  1413. EndWait(ConditionMet, WOLSTRING("WOL_USERLISTRECEIVED"));
  1414. }
  1415. }
  1416. //-----------------------------------------------------------------------------
  1417. /******************************************************************************
  1418. *
  1419. * NAME
  1420. * GetUserWait::Create
  1421. *
  1422. * DESCRIPTION
  1423. *
  1424. * INPUTS
  1425. *
  1426. * RESULT
  1427. *
  1428. ******************************************************************************/
  1429. RefPtr<GetUserWait> GetUserWait::Create(const RefPtr<Session>& session,
  1430. const wchar_t* userName)
  1431. {
  1432. WWASSERT(session.IsValid() && "GetUserWait");
  1433. WWASSERT(userName && "GetUserWait");
  1434. if (!session.IsValid() || (userName == NULL))
  1435. {
  1436. return NULL;
  1437. }
  1438. return new GetUserWait(session, userName);
  1439. }
  1440. /******************************************************************************
  1441. *
  1442. * NAME
  1443. * GetUserWait::GetUserWait
  1444. *
  1445. * DESCRIPTION
  1446. * Constructor
  1447. *
  1448. * INPUTS
  1449. *
  1450. * RESULT
  1451. * NONE
  1452. *
  1453. ******************************************************************************/
  1454. GetUserWait::GetUserWait(const RefPtr<Session>& session, const wchar_t* userName) :
  1455. mSession(session),
  1456. mUserName(userName)
  1457. {
  1458. WWDEBUG_SAY(("WOL: GetUserWait Create\n"));
  1459. }
  1460. /******************************************************************************
  1461. *
  1462. * NAME
  1463. * GetUserWait::GetUserWait
  1464. *
  1465. * DESCRIPTION
  1466. * Destructor
  1467. *
  1468. * INPUTS
  1469. * NONE
  1470. *
  1471. * RESULT
  1472. * NONE
  1473. *
  1474. ******************************************************************************/
  1475. GetUserWait::~GetUserWait()
  1476. {
  1477. WWDEBUG_SAY(("WOL: GetUserWait End %S\n", mEndText));
  1478. }
  1479. /******************************************************************************
  1480. *
  1481. * NAME
  1482. * GetUserWait::WaitBeginning
  1483. *
  1484. * DESCRIPTION
  1485. *
  1486. * INPUTS
  1487. * NONE
  1488. *
  1489. * RESULT
  1490. * NONE
  1491. *
  1492. ******************************************************************************/
  1493. void GetUserWait::WaitBeginning(void)
  1494. {
  1495. WWDEBUG_SAY(("WOL: GetUserWait Begin\n"));
  1496. WWASSERT(mSession.IsValid() && "GetUserWait");
  1497. RefPtr<UserData> user = mSession->FindUser(mUserName);
  1498. if (user.IsValid())
  1499. {
  1500. WWDEBUG_SAY(("WOL: GetUserWait successful\n"));
  1501. EndWait(ConditionMet, WOLSTRING("WOL_USERFOUND"));
  1502. }
  1503. else
  1504. {
  1505. Add(UserListWait::Create(mSession));
  1506. }
  1507. }
  1508. /******************************************************************************
  1509. *
  1510. * NAME
  1511. * GetUserWait::GetResult
  1512. *
  1513. * DESCRIPTION
  1514. *
  1515. * INPUTS
  1516. * NONE
  1517. *
  1518. * RESULT
  1519. *
  1520. ******************************************************************************/
  1521. WaitCondition::WaitResult GetUserWait::GetResult(void)
  1522. {
  1523. WaitResult result = SerialWait::GetResult();
  1524. if (result == ConditionMet)
  1525. {
  1526. RefPtr<UserData> user = mSession->FindUser(mUserName);
  1527. if (user.IsValid())
  1528. {
  1529. WWDEBUG_SAY(("WOL: GetUserWait successful\n"));
  1530. mEndText = WOLSTRING("WOL_USERFOUND");
  1531. }
  1532. else
  1533. {
  1534. WWDEBUG_SAY(("WOL: GetUserWait failed\n"));
  1535. mEndResult = Error;
  1536. mEndText = WOLSTRING("WOL_USERNOTFOUND");
  1537. }
  1538. }
  1539. return mEndResult;
  1540. }
  1541. //-----------------------------------------------------------------------------
  1542. /******************************************************************************
  1543. *
  1544. * NAME
  1545. * LocateUserWait::Create
  1546. *
  1547. * DESCRIPTION
  1548. *
  1549. * INPUTS
  1550. *
  1551. * RESULT
  1552. *
  1553. ******************************************************************************/
  1554. RefPtr<LocateUserWait> LocateUserWait::Create(const RefPtr<Session>& session,
  1555. const wchar_t* userName)
  1556. {
  1557. WWASSERT(session.IsValid() && "LocateUserWait");
  1558. WWASSERT(userName && "LocateUserWait");
  1559. if (!session.IsValid() || (userName == NULL))
  1560. {
  1561. return NULL;
  1562. }
  1563. return new LocateUserWait(session, userName);
  1564. }
  1565. /******************************************************************************
  1566. *
  1567. * NAME
  1568. * LocateUserWait::LocateUserWait
  1569. *
  1570. * DESCRIPTION
  1571. * Constructor
  1572. *
  1573. * INPUTS
  1574. *
  1575. * RESULT
  1576. * NONE
  1577. *
  1578. ******************************************************************************/
  1579. LocateUserWait::LocateUserWait(const RefPtr<Session>& session, const wchar_t* userName) :
  1580. SingleWait(WOLSTRING("WOL_LOCATINGUSER")),
  1581. mSession(session),
  1582. mUserName(userName)
  1583. {
  1584. WWDEBUG_SAY(("WOL: LocateUserWait Create\n"));
  1585. }
  1586. /******************************************************************************
  1587. *
  1588. * NAME
  1589. * LocateUserWait::~LocateUserWait
  1590. *
  1591. * DESCRIPTION
  1592. * Destructor
  1593. *
  1594. * INPUTS
  1595. * NONE
  1596. *
  1597. * RESULT
  1598. * NONE
  1599. *
  1600. ******************************************************************************/
  1601. LocateUserWait::~LocateUserWait()
  1602. {
  1603. WWDEBUG_SAY(("WOL: LocateUserWait End '%S'\n", mEndText));
  1604. }
  1605. /******************************************************************************
  1606. *
  1607. * NAME
  1608. * LocateUserWait::WaitBeginning
  1609. *
  1610. * DESCRIPTION
  1611. *
  1612. * INPUTS
  1613. * NONE
  1614. *
  1615. * RESULT
  1616. * NONE
  1617. *
  1618. ******************************************************************************/
  1619. void LocateUserWait::WaitBeginning(void)
  1620. {
  1621. WWDEBUG_SAY(("WOL: LocateUserWait Begin '%S'\n", (const WCHAR*)mUserName));
  1622. WWASSERT(mSession.IsValid() && "LocateUserWait");
  1623. RefPtr<UserData> user = mSession->FindUser(mUserName);
  1624. if (user.IsValid())
  1625. {
  1626. WWDEBUG_SAY(("WOL: LocateUserWait successful\n"));
  1627. EndWait(ConditionMet, WOLSTRING("WOL_USERFOUND"));
  1628. }
  1629. mSession->AddObserver(*static_cast< Observer<ServerError> *>(this));
  1630. mSession->AddObserver(*static_cast< Observer<UserEvent> *>(this));
  1631. mSession->RequestLocateUser(mUserName);
  1632. }
  1633. /******************************************************************************
  1634. *
  1635. * NAME
  1636. * LocateUserWait::HandleNotification(ServerError)
  1637. *
  1638. * DESCRIPTION
  1639. *
  1640. * INPUTS
  1641. *
  1642. * RESULT
  1643. * NONE
  1644. *
  1645. ******************************************************************************/
  1646. void LocateUserWait::HandleNotification(ServerError& error)
  1647. {
  1648. if (mEndResult == Waiting)
  1649. {
  1650. const wchar_t* errorMsg = error.GetDescription();
  1651. WWDEBUG_SAY(("WOLERROR: LocateUserWait server error '%S'\n", errorMsg));
  1652. EndWait(Error, errorMsg);
  1653. }
  1654. }
  1655. /******************************************************************************
  1656. *
  1657. * NAME
  1658. * LocateUserWait::LocateUserWait
  1659. *
  1660. * DESCRIPTION
  1661. *
  1662. * INPUTS
  1663. *
  1664. * RESULT
  1665. * NONE
  1666. *
  1667. ******************************************************************************/
  1668. void LocateUserWait::HandleNotification(UserEvent& event)
  1669. {
  1670. if (mEndResult == Waiting)
  1671. {
  1672. const RefPtr<UserData>& user = event.Subject();
  1673. if (mUserName.Compare_No_Case(user->GetName()) == 0)
  1674. {
  1675. WWDEBUG_SAY(("WOL: LocateUserWait successful\n"));
  1676. EndWait(ConditionMet, WOLSTRING("WOL_USERFOUND"));
  1677. }
  1678. }
  1679. }
  1680. //-----------------------------------------------------------------------------
  1681. /******************************************************************************
  1682. *
  1683. * NAME
  1684. * SendMsgWait::Create
  1685. *
  1686. * DESCRIPTION
  1687. *
  1688. * INPUTS
  1689. *
  1690. * RESULT
  1691. *
  1692. ******************************************************************************/
  1693. RefPtr<SendMsgWait> SendMsgWait::Create(const RefPtr<Session>& session, ChatMessage& message)
  1694. {
  1695. WWASSERT(session.IsValid() && "SendMsgWait");
  1696. if (!session.IsValid())
  1697. {
  1698. return NULL;
  1699. }
  1700. return new SendMsgWait(session, message);
  1701. }
  1702. /******************************************************************************
  1703. *
  1704. * NAME
  1705. * SendMsgWait::SendMsgWait
  1706. *
  1707. * DESCRIPTION
  1708. * Constructor
  1709. *
  1710. * INPUTS
  1711. *
  1712. * RESULT
  1713. * NONE
  1714. *
  1715. ******************************************************************************/
  1716. SendMsgWait::SendMsgWait(const RefPtr<Session>& session, ChatMessage& message) :
  1717. SingleWait(WOLSTRING("WOL_SENDINGMSG")),
  1718. mSession(session),
  1719. mMessage(message)
  1720. {
  1721. WWDEBUG_SAY(("WOL: SendMsgWait Create\n"));
  1722. }
  1723. /******************************************************************************
  1724. *
  1725. * NAME
  1726. * SendMsgWait::~SendMsgWait
  1727. *
  1728. * DESCRIPTION
  1729. * Destructor
  1730. *
  1731. * INPUTS
  1732. * NONE
  1733. *
  1734. * RESULT
  1735. * NONE
  1736. *
  1737. ******************************************************************************/
  1738. SendMsgWait::~SendMsgWait()
  1739. {
  1740. WWDEBUG_SAY(("WOL: SendMsgWait End %S\n", mEndText));
  1741. }
  1742. /******************************************************************************
  1743. *
  1744. * NAME
  1745. * SendMsgWait::WaitBeginning
  1746. *
  1747. * DESCRIPTION
  1748. *
  1749. * INPUTS
  1750. * NONE
  1751. *
  1752. * RESULT
  1753. * NONE
  1754. *
  1755. ******************************************************************************/
  1756. void SendMsgWait::WaitBeginning(void)
  1757. {
  1758. WWDEBUG_SAY(("WOL: SendMsgWait Begin\n"));
  1759. WWASSERT(mSession.IsValid() && "SendMsgWait");
  1760. if (mMessage.IsPrivate())
  1761. {
  1762. RefPtr<UserData> user = mSession->FindUser(mMessage.GetSendersName());
  1763. if (!user.IsValid())
  1764. {
  1765. WWDEBUG_SAY(("WOLERROR: SendMsgWait user not found\n"));
  1766. EndWait(Error, WOLSTRING("WOL_USERNOTFOUND"));
  1767. return;
  1768. }
  1769. UserList userList;
  1770. userList.push_back(user);
  1771. if (mMessage.IsAction())
  1772. {
  1773. mSession->SendPrivateAction(userList, mMessage.GetMessage());
  1774. }
  1775. else
  1776. {
  1777. mSession->SendPrivateMessage(userList, mMessage.GetMessage());
  1778. }
  1779. }
  1780. else
  1781. {
  1782. if (mMessage.IsAction())
  1783. {
  1784. mSession->SendPublicAction(mMessage.GetMessage());
  1785. }
  1786. else
  1787. {
  1788. mSession->SendPublicMessage(mMessage.GetMessage());
  1789. }
  1790. }
  1791. WWDEBUG_SAY(("WOL: SendMsgWait successful\n"));
  1792. EndWait(ConditionMet, mMessage.GetMessage());
  1793. }
  1794. } // namespace WWOnline