WOLSession.cpp 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * NAME
  21. * $Archive: /Commando/Code/WWOnline/WOLSession.cpp $
  22. *
  23. * DESCRIPTION
  24. * WOLSession is the entryway to Westwood Online. An object of this type
  25. * must exist in order to do anything WOL related. There should only be one
  26. * instance of this; retrieve it via GetInstance.
  27. *
  28. * PROGRAMMER
  29. * Steve Clinard & Denzil E. Long, Jr.
  30. * $Author: Steve_t $
  31. *
  32. * VERSION INFO
  33. * $Revision: 79 $
  34. * $Modtime: 2/08/02 11:31a $
  35. *
  36. ******************************************************************************/
  37. #include <atlbase.h>
  38. #include "WOLSession.h"
  39. #include "WOLChatObserver.h"
  40. #include "WOLNetUtilObserver.h"
  41. #include "WOLProduct.h"
  42. #include "WOLConnect.h"
  43. #include "WOLServer.h"
  44. #include "WaitCondition.h"
  45. #include "WOLErrorUtil.h"
  46. #include <WWDebug\WWDebug.h>
  47. #include <stdlib.h>
  48. #ifdef _MSC_VER
  49. #pragma warning (push,3)
  50. #endif
  51. #include "systimer.h"
  52. #ifdef _MSC_VER
  53. #pragma warning (pop)
  54. #endif
  55. namespace WWOnline {
  56. RefPtr<Session> Session::_mInstance;
  57. /******************************************************************************
  58. *
  59. * NAME
  60. * Session::GetInstance
  61. *
  62. * DESCRIPTION
  63. * Retrieve instance to Westwood Online session
  64. *
  65. * INPUTS
  66. * Create - True if session should be created.
  67. *
  68. * RESULT
  69. * Session - Session instance
  70. *
  71. ******************************************************************************/
  72. RefPtr<Session> Session::GetInstance(bool okToCreate)
  73. {
  74. if (okToCreate && !_mInstance.IsValid())
  75. {
  76. _mInstance = new Session;
  77. if (_mInstance->FinalizeCreate() == false)
  78. {
  79. _mInstance.Release();
  80. }
  81. }
  82. return _mInstance;
  83. }
  84. /******************************************************************************
  85. *
  86. * NAME
  87. * Session::Session
  88. *
  89. * DESCRIPTION
  90. * Default constructor
  91. *
  92. * INPUTS
  93. * NONE
  94. *
  95. * RESULT
  96. * NONE
  97. *
  98. ******************************************************************************/
  99. Session::Session() :
  100. mChatCookie(0),
  101. mNetUtilCookie(0),
  102. mCurrentConnectionStatus(ConnectionDisconnected),
  103. mAutoRequestFlags(0),
  104. mLadderPending(0),
  105. mPingsPending(0),
  106. mPingEnable(1),
  107. mLastUserDataRequestTime(0),
  108. mRequestedChannelType(-1),
  109. mRequestingServerList(false),
  110. mIgnoreServerLists(false),
  111. mIsInsider(false),
  112. mServerTime(0)
  113. {
  114. WWDEBUG_SAY(("WOL: Session instantiated\n"));
  115. // Initailize COM
  116. HRESULT hr = CoInitialize(NULL);
  117. if (FAILED(hr))
  118. {
  119. WWDEBUG_SAY(("WOLERROR: CoInitialize() failed!\n"));
  120. }
  121. WWASSERT(SUCCEEDED(hr) && "CoInitialize() failed!");
  122. }
  123. /******************************************************************************
  124. *
  125. * NAME
  126. * Session::FinalizeCreate
  127. *
  128. * DESCRIPTION
  129. * Finalize session creation
  130. *
  131. * INPUTS
  132. * NONE
  133. *
  134. * RESULT
  135. * Success - True if successful.
  136. *
  137. ******************************************************************************/
  138. bool Session::FinalizeCreate(void)
  139. {
  140. WWDEBUG_SAY(("WOL: Session Create\n"));
  141. Reset();
  142. //---------------------------------------------------------------------------
  143. // Create chat object
  144. //---------------------------------------------------------------------------
  145. WWDEBUG_SAY(("WOL: Creating IID_IChat object\n"));
  146. WOL::IChat* chatObject = NULL;
  147. HRESULT hr = CoCreateInstance(WOL::CLSID_Chat, NULL, CLSCTX_INPROC_SERVER,
  148. WOL::IID_IChat, (void**)&chatObject);
  149. if (FAILED(hr))
  150. {
  151. WWDEBUG_SAY(("WOLERROR: Failed to create IID_IChat\n"));
  152. return false;
  153. }
  154. if (chatObject)
  155. {
  156. mChat = chatObject;
  157. // Create chat events observer
  158. WWDEBUG_SAY(("WOL: Creating chat events observer\n"));
  159. CComPtr<ChatObserver> chatEvents;
  160. chatEvents.Attach(new ChatObserver);
  161. if (chatEvents == NULL)
  162. {
  163. WWDEBUG_SAY(("WOLERROR: Failed to create IChatEvents observer\n"));
  164. return false;
  165. }
  166. chatEvents->Init(*this);
  167. hr = mChat.Advise(chatEvents, WOL::IID_IChatEvent, &mChatCookie);
  168. if (FAILED(hr))
  169. {
  170. WWDEBUG_SAY(("WOLERROR: Failed to advise IChatEvents observer\n"));
  171. return false;
  172. }
  173. mChatEvents = chatEvents;
  174. }
  175. //---------------------------------------------------------------------------
  176. // Create netutil object
  177. //---------------------------------------------------------------------------
  178. WWDEBUG_SAY(("WOL: Creating IID_INetUtil object\n"));
  179. WOL::INetUtil* utilObject = NULL;
  180. hr = CoCreateInstance(WOL::CLSID_NetUtil, NULL, CLSCTX_INPROC_SERVER,
  181. WOL::IID_INetUtil, (void **)&utilObject);
  182. if (FAILED(hr))
  183. {
  184. WWDEBUG_SAY(("WOLERROR: Failed to create IID_INetUtil\n"));
  185. return false;
  186. }
  187. if (utilObject)
  188. {
  189. mNetUtil = utilObject;
  190. // Create net utility events observer
  191. WWDEBUG_SAY(("WOL: Creating netutil events observer\n"));
  192. CComPtr<NetUtilObserver> utilEvents;
  193. utilEvents.Attach(new NetUtilObserver);
  194. if (utilEvents == NULL)
  195. {
  196. WWDEBUG_SAY(("WOLERROR: Failed to create INetUtilEvents observer\n"));
  197. return false;
  198. }
  199. utilEvents->Init(*this);
  200. hr = mNetUtil.Advise(utilEvents, WOL::IID_INetUtilEvent, &mNetUtilCookie);
  201. if (FAILED(hr))
  202. {
  203. WWDEBUG_SAY(("WOLERROR: Failed to advise INetUtilEvents observer\n"));
  204. return false;
  205. }
  206. mNetUtilEvents = utilEvents;
  207. }
  208. //---------------------------------------------------------------------------
  209. // Setup for current product
  210. //---------------------------------------------------------------------------
  211. WWDEBUG_SAY(("WOL: Setting product SKU\n"));
  212. RefPtrConst<Product> product = Product::Current();
  213. if (!product.IsValid())
  214. {
  215. WWDEBUG_SAY(("WOLERROR: WOLProduct not initialized\n"));
  216. return false;
  217. }
  218. const char* regPath = product->GetRegistryPath();
  219. hr = mChat->SetAttributeValue("RegPath", regPath);
  220. if (FAILED(hr))
  221. {
  222. WWDEBUG_SAY(("WOLERROR: SetAttributeValue(RegPath) HRESULT = %s\n", GetChatErrorString(hr)));
  223. return false;
  224. }
  225. unsigned int sku = product->GetSKU();
  226. hr = mChat->SetProductSKU(sku);
  227. if (FAILED(hr))
  228. {
  229. WWDEBUG_SAY(("WOLERROR: SetProductSKU() HRESULT = %s\n", GetChatErrorString(hr)));
  230. return false;
  231. }
  232. // Enable OnChannelTopic() to be called after OnChannelJoin()
  233. hr = mChat->SetAttributeValue("AutoTopic", "true");
  234. if (FAILED(hr))
  235. {
  236. WWDEBUG_SAY(("WOLERROR: SetAttributeValue(AutoTopic) HRESULT = %s\n", GetChatErrorString(hr)));
  237. return false;
  238. }
  239. mPingRequests.reserve(8);
  240. mUsers.reserve(32);
  241. return true;
  242. }
  243. /******************************************************************************
  244. *
  245. * NAME
  246. * Session::~Session
  247. *
  248. * DESCRIPTION
  249. * Destructor
  250. *
  251. * INPUTS
  252. * NONE
  253. *
  254. * RESULT
  255. * NONE
  256. *
  257. ******************************************************************************/
  258. Session::~Session()
  259. {
  260. WWDEBUG_SAY(("WOL: Session destructing\n"));
  261. Reset();
  262. if (mIGRObject)
  263. {
  264. WWDEBUG_SAY(("WOL: Releasing IID_IIGROptions object\n"));
  265. mIGRObject.Release();
  266. }
  267. if (mNetUtil)
  268. {
  269. WWDEBUG_SAY(("WOL: Releasing IID_INetUtil object\n"));
  270. AtlUnadvise(mNetUtil, WOL::IID_INetUtilEvent, mNetUtilCookie);
  271. mNetUtil.Release();
  272. }
  273. if (mChat)
  274. {
  275. WWDEBUG_SAY(("WOL: Releasing IID_IChat object\n"));
  276. AtlUnadvise(mChat, WOL::IID_IChatEvent, mChatCookie);
  277. mChat.Release();
  278. }
  279. CoUninitialize();
  280. }
  281. /******************************************************************************
  282. *
  283. * NAME
  284. * Session::ReleaseReference
  285. *
  286. * DESCRIPTION
  287. * Release reference count
  288. *
  289. * INPUTS
  290. * NONE
  291. *
  292. * RESULT
  293. * NONE
  294. *
  295. ******************************************************************************/
  296. void Session::ReleaseReference(void)
  297. {
  298. RefCounted::ReleaseReference();
  299. // If there is only the singleton reference then release the object.
  300. if (ReferenceCount() == 1)
  301. {
  302. _mInstance.Release();
  303. }
  304. }
  305. /******************************************************************************
  306. *
  307. * NAME
  308. * Session::Reset
  309. *
  310. * DESCRIPTION
  311. * Reset the WWOnline session
  312. *
  313. * INPUTS
  314. *
  315. * RESULT
  316. * NONE
  317. *
  318. ******************************************************************************/
  319. void Session::Reset(void)
  320. {
  321. ClearServers();
  322. SquadData::Reset();
  323. mChatChannels.clear();
  324. mGameChannels.clear();
  325. mPatchFiles.clear();
  326. mUsers.clear();
  327. mBuddies.clear();
  328. mLocatePendingUsers.clear();
  329. mLocatingUser.Release();
  330. }
  331. /******************************************************************************
  332. *
  333. * NAME
  334. * Session::Process
  335. *
  336. * DESCRIPTION
  337. * Perform periodic processing
  338. *
  339. * INPUTS
  340. * NONE
  341. *
  342. * RESULT
  343. *
  344. ******************************************************************************/
  345. bool Session::Process(void)
  346. {
  347. if (mCurrentConnectionStatus == ConnectionConnected)
  348. {
  349. MakeLocateUserRequests();
  350. }
  351. DWORD theTime = TIMEGETTIME();
  352. if (theTime < mLastUserDataRequestTime)
  353. {
  354. mLastUserDataRequestTime = theTime;
  355. }
  356. if (theTime >= (mLastUserDataRequestTime + 1000))
  357. {
  358. mLastUserDataRequestTime = theTime;
  359. MakeSquadRequests();
  360. MakeLocaleRequests();
  361. MakeTeamRequests();
  362. MakeLadderRequests();
  363. }
  364. MakePingRequests();
  365. mChat->PumpMessages();
  366. mNetUtil->PumpMessages();
  367. return false;
  368. }
  369. /******************************************************************************
  370. *
  371. * NAME
  372. * Session::GetNewServerList
  373. *
  374. * DESCRIPTION
  375. * Get a new server list.
  376. *
  377. * INPUTS
  378. * NONE
  379. *
  380. * RESULT
  381. * Wait - Wait condition to process for serverlist.
  382. *
  383. ******************************************************************************/
  384. RefPtr<WaitCondition> Session::GetNewServerList(void)
  385. {
  386. return ServerListWait::Create(this);
  387. }
  388. /******************************************************************************
  389. *
  390. * NAME
  391. * Session::RequestServerList
  392. *
  393. * DESCRIPTION
  394. * Submit a request for server list.
  395. *
  396. * INPUTS
  397. * NONE
  398. *
  399. * RESULT
  400. * Success - True if request successful.
  401. *
  402. ******************************************************************************/
  403. bool Session::RequestServerList(bool ignore)
  404. {
  405. RefPtrConst<Product> product(Product::Current());
  406. if (!product.IsValid())
  407. {
  408. WWASSERT(product.IsValid() && "WOLERROR: Product not initialized.");
  409. return false;
  410. }
  411. mIgnoreServerLists = ignore;
  412. mRequestingServerList = !ignore;
  413. unsigned int sku = product->GetLanguageSKU();
  414. unsigned int version = product->GetVersion();
  415. HRESULT hr = mChat->RequestServerList(sku, version, "NoUser", "NoPass", 30000);
  416. if (FAILED(hr))
  417. {
  418. WWDEBUG_SAY(("WOLERROR: RequestServerList() HRESULT = %s\n", GetChatErrorString(hr)));
  419. }
  420. return SUCCEEDED(hr);
  421. }
  422. /******************************************************************************
  423. *
  424. * NAME
  425. * Session::LoginServer
  426. *
  427. * DESCRIPTION
  428. * Log user onto server.
  429. *
  430. * INPUTS
  431. * Server - Server to logon to.
  432. * Login - Login information
  433. *
  434. * RESULT
  435. * Wait - Wait condition to process for logging in.
  436. *
  437. ******************************************************************************/
  438. RefPtr<WaitCondition> Session::LoginServer(const RefPtr<IRCServerData>& server,
  439. const RefPtr<LoginInfo>& login)
  440. {
  441. if (server.IsValid())
  442. {
  443. WWDEBUG_SAY(("WOL: LoginServer connecting to '%s'\n", server->GetName()));
  444. }
  445. else
  446. {
  447. WWDEBUG_SAY(("WOL: LoginServer disconnecting\n"));
  448. }
  449. //---------------------------------------------------------------------------
  450. // If this is the current server, check state of connection
  451. //---------------------------------------------------------------------------
  452. if (mCurrentServer == server)
  453. {
  454. if (server.IsValid())
  455. {
  456. // If already connected to this server, just return with success.
  457. // If connecting then wait for connection to finish.
  458. if (ConnectionConnected == mCurrentConnectionStatus)
  459. {
  460. WWDEBUG_SAY(("WOL: LoginServer already connected.\n"));
  461. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CONNECTING"));
  462. wait->EndWait(WaitCondition::ConditionMet, WOLSTRING("WOL_CONNECTED"));
  463. return wait;
  464. }
  465. else if (ConnectionConnecting == mCurrentConnectionStatus)
  466. {
  467. WWDEBUG_SAY(("WOL: LoginServer already connecting.\n"));
  468. return EventValueWait<ConnectionStatus>::CreateAndObserve(*this, ConnectionConnected, WOLSTRING("WOL_CONNECTING"));
  469. }
  470. }
  471. else
  472. {
  473. // If already disconnected then just return with success. If disconnecting
  474. // then wait for disconnect to finish.
  475. if (ConnectionDisconnected == mCurrentConnectionStatus)
  476. {
  477. WWDEBUG_SAY(("WOL: LoginServer already disconnected.\n"));
  478. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_DISCONNECTING"));
  479. wait->EndWait(WaitCondition::ConditionMet, WOLSTRING("WOL_DISCONNECTED"));
  480. return wait;
  481. }
  482. else if (ConnectionDisconnecting == mCurrentConnectionStatus)
  483. {
  484. WWDEBUG_SAY(("WOL: LoginServer already disconnecting.\n"));
  485. return EventValueWait<ConnectionStatus>::CreateAndObserve(*this, ConnectionDisconnected, WOLSTRING("WOL_DISCONNECTING"));
  486. }
  487. }
  488. }
  489. // Clean up on server switch or disconnect
  490. if (ConnectionConnected == mCurrentConnectionStatus)
  491. {
  492. WWDEBUG_SAY(("WOL: LoginServer disconnect cleanup.\n"));
  493. mCurrentChannelStatus = ChannelLeft;
  494. ChannelEvent chanEvent(mCurrentChannelStatus, mCurrentChannel);
  495. NotifyObservers(chanEvent);
  496. mCurrentChannel.Release();
  497. mPendingChannel.Release();
  498. mChatChannels.clear();
  499. ChannelListEvent chatListEvent(ChannelListEvent::NewList, mChatChannels, 0);
  500. NotifyObservers(chatListEvent);
  501. RefPtrConst<Product> product = Product::Current();
  502. WWASSERT(product.IsValid());
  503. mGameChannels.clear();
  504. ChannelListEvent gameListEvent(ChannelListEvent::NewList, mGameChannels, product->GetGameCode());
  505. NotifyObservers(gameListEvent);
  506. }
  507. //---------------------------------------------------------------------------
  508. // Process change of server connection
  509. //---------------------------------------------------------------------------
  510. RefPtr<SerialWait> serverWait = SerialWait::Create();
  511. // If connecting or disconnecting, let that finish
  512. if (ConnectionDisconnecting == mCurrentConnectionStatus)
  513. {
  514. WWDEBUG_SAY(("WOL: LoginServer wait for disconnect to finish.\n"));
  515. RefPtr< EventValueWait<ConnectionStatus> > finish = EventValueWait<ConnectionStatus>::CreateAndObserve(*this, ConnectionDisconnected, WOLSTRING("WOL_DISCONNECTING"));
  516. serverWait->Add(finish);
  517. }
  518. else if (ConnectionConnecting == mCurrentConnectionStatus)
  519. {
  520. WWDEBUG_SAY(("WOL: LoginServer wait for connect to finish.\n"));
  521. RefPtr< EventValueWait<ConnectionStatus> > finish = EventValueWait<ConnectionStatus>::CreateAndObserve(*this, ConnectionConnected, WOLSTRING("WOL_DISCONNECTING"));
  522. serverWait->Add(finish);
  523. }
  524. // If connected or connecting to another server then disconnect from that server
  525. // before connecting to the new one.
  526. if (mCurrentServer.IsValid() || (mPendingServer.IsValid() && (mPendingServer != server)))
  527. {
  528. WWDEBUG_SAY(("WOL: LoginServer changing servers.\n"));
  529. if ((ConnectionConnected == mCurrentConnectionStatus) || (ConnectionConnecting == mCurrentConnectionStatus))
  530. {
  531. WWDEBUG_SAY(("WOL: LoginServer disconnect from current server.\n"));
  532. RefPtr<DisconnectWait> disconnect = DisconnectWait::Create(this);
  533. serverWait->Add(disconnect);
  534. }
  535. }
  536. mPendingServer = server;
  537. mPendingLogin = login;
  538. // Server == NULL is just a logout
  539. if (!server.IsValid())
  540. {
  541. return serverWait;
  542. }
  543. if (!login.IsValid())
  544. {
  545. WWASSERT(login.IsValid());
  546. return serverWait;
  547. }
  548. // Finally, connect to desired server. Request to connect is embedded in Wait_Beginning
  549. WWDEBUG_SAY(("WOL: LoginServer connect to new server.\n"));
  550. RefPtr<ConnectWait> connect = ConnectWait::Create(this, server, login);
  551. serverWait->Add(connect);
  552. return serverWait;
  553. }
  554. /******************************************************************************
  555. *
  556. * NAME
  557. * Session::Logout
  558. *
  559. * DESCRIPTION
  560. * Log current user off.
  561. *
  562. * INPUTS
  563. * NONE
  564. *
  565. * RESULT
  566. * Wait - Wait condition to process for logout.
  567. *
  568. ******************************************************************************/
  569. RefPtr<WaitCondition> Session::Logout(void)
  570. {
  571. WWDEBUG_SAY(("WOL: Logout\n"));
  572. return LoginServer(RefPtr<IRCServerData>(), RefPtr<LoginInfo>());
  573. }
  574. /******************************************************************************
  575. *
  576. * NAME
  577. * Session::ClearServers
  578. *
  579. * DESCRIPTION
  580. * Clear internal server lists
  581. *
  582. * INPUTS
  583. * NONE
  584. *
  585. * RESULT
  586. * NONE
  587. *
  588. ******************************************************************************/
  589. void Session::ClearServers(void)
  590. {
  591. mRequestingServerList = false;
  592. mIgnoreServerLists = false;
  593. mIRCServers.clear();
  594. mLadderServer.Release();
  595. mGameResultsServer.Release();
  596. mWDTServer.Release();
  597. mMGLServers.clear();
  598. mPingServers.clear();
  599. }
  600. /******************************************************************************
  601. *
  602. * NAME
  603. * Session::EnableProgressiveChannelList
  604. *
  605. * DESCRIPTION
  606. * Enable / Disable the receipt of progressive channel lists.
  607. *
  608. * INPUTS
  609. * Enable - True to enable; False to disable.
  610. *
  611. * RESULT
  612. * Success - True if operation is successful.
  613. *
  614. ******************************************************************************/
  615. bool Session::EnableProgressiveChannelList(bool enable)
  616. {
  617. const char* onoff = ((enable == true) ? "true" : "false");
  618. HRESULT hr = mChat->SetAttributeValue("IncrementalChannelLists", onoff);
  619. return SUCCEEDED(hr);
  620. }
  621. /******************************************************************************
  622. *
  623. * NAME
  624. * Session::RequestChannelList
  625. *
  626. * DESCRIPTION
  627. *
  628. * INPUTS
  629. * Type - Channel type to request.
  630. * AutoPing -
  631. *
  632. * RESULT
  633. * Success - True if request successful.
  634. *
  635. ******************************************************************************/
  636. bool Session::RequestChannelList(int channelType, bool autoPing)
  637. {
  638. WWDEBUG_SAY(("WOL: RequestChannelList %d\n", channelType));
  639. if (mRequestedChannelType != -1)
  640. {
  641. WWDEBUG_SAY(("WOLERROR: RequestChannelList already pending\n"));
  642. return false;
  643. }
  644. HRESULT hr = mChat->RequestChannelList(channelType, autoPing);
  645. if (SUCCEEDED(hr))
  646. {
  647. mRequestedChannelType = channelType;
  648. return true;
  649. }
  650. WWDEBUG_SAY(("WOLERROR: RequestChannelList() HRESULT = %s\n", GetChatErrorString(hr)));
  651. return false;
  652. }
  653. /******************************************************************************
  654. *
  655. * NAME
  656. * Session::FindChannel
  657. *
  658. * DESCRIPTION
  659. * Find a channel by name.
  660. *
  661. * INPUTS
  662. * Name - Name of channel to look for.
  663. *
  664. * RESULT
  665. * Channel -
  666. *
  667. ******************************************************************************/
  668. RefPtr<ChannelData> Session::FindChannel(const wchar_t* channelName)
  669. {
  670. if (channelName == NULL)
  671. {
  672. return NULL;
  673. }
  674. if (mCurrentChannel.IsValid())
  675. {
  676. const WideStringClass& name = mCurrentChannel->GetName();
  677. if (name.Compare_No_Case(channelName) == 0)
  678. {
  679. return mCurrentChannel;
  680. }
  681. }
  682. RefPtr<ChannelData> channel = FindChatChannel(channelName);
  683. if (!channel.IsValid())
  684. {
  685. channel = FindGameChannel(channelName);
  686. }
  687. return channel;
  688. }
  689. RefPtr<ChannelData> Session::FindChannel(const char* channelName)
  690. {
  691. if (channelName == NULL)
  692. {
  693. return NULL;
  694. }
  695. if (mCurrentChannel.IsValid())
  696. {
  697. WOL::Channel& wolChannel = mCurrentChannel->GetData();
  698. if (stricmp(channelName, (const char*)wolChannel.name) == 0)
  699. {
  700. return mCurrentChannel;
  701. }
  702. }
  703. RefPtr<ChannelData> channel = FindChatChannel(channelName);
  704. if (!channel.IsValid())
  705. {
  706. channel = FindGameChannel(channelName);
  707. }
  708. return channel;
  709. }
  710. /******************************************************************************
  711. *
  712. * NAME
  713. * Session::JoinChannel
  714. *
  715. * DESCRIPTION
  716. * Join the specified channel.
  717. *
  718. * INPUTS
  719. * Channel - Channel to join.
  720. *
  721. * RESULT
  722. * Wait - Wait condition to process for joining channel
  723. *
  724. ******************************************************************************/
  725. RefPtr<WaitCondition> Session::JoinChannel(const RefPtr<ChannelData>& channel,
  726. const wchar_t* password)
  727. {
  728. // If we are not connected then we cannot join a channel.
  729. if (mCurrentConnectionStatus != ConnectionConnected)
  730. {
  731. WWASSERT(mCurrentConnectionStatus == ConnectionConnected);
  732. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELJOIN"));
  733. wait->EndWait(WaitCondition::Error, WOLSTRING("WOL_NOTCONNECTED"));
  734. return wait;
  735. }
  736. // If we are already connected to the requested channel then done.
  737. if (mCurrentChannel == channel)
  738. {
  739. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELJOIN"));
  740. wait->EndWait(WaitCondition::ConditionMet, WOLSTRING("WOL_CONNECTED"));
  741. return wait;
  742. }
  743. // Use default product password if one is not provided
  744. if (password == NULL)
  745. {
  746. RefPtrConst<Product> product = Product::Current();
  747. WWASSERT(product.IsValid());
  748. password = product->GetChannelPassword();
  749. }
  750. // Set up wait condition for joining channel
  751. mPendingChannel = channel;
  752. RefPtr<SerialWait> wait = SerialWait::Create();
  753. if (wait.IsValid())
  754. {
  755. // Leave current channel
  756. if (mCurrentChannel.IsValid())
  757. {
  758. RefPtr<WaitCondition> leaveWait = LeaveChannelWait::Create(this);
  759. wait->Add(leaveWait);
  760. }
  761. // Join new channel
  762. if (channel.IsValid())
  763. {
  764. RefPtr<WaitCondition> joinWait = JoinChannelWait::Create(this, channel, password);
  765. wait->Add(joinWait);
  766. }
  767. }
  768. return wait;
  769. }
  770. RefPtr<WaitCondition> Session::JoinChannel(const wchar_t* chanName, const wchar_t* password, int type)
  771. {
  772. // If we are not connected then we cannot join a channel.
  773. if (mCurrentConnectionStatus != ConnectionConnected)
  774. {
  775. WWASSERT(mCurrentConnectionStatus == ConnectionConnected);
  776. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELJOIN"));
  777. wait->EndWait(WaitCondition::Error, WOLSTRING("WOL_NOTCONNECTED"));
  778. return wait;
  779. }
  780. // If we are already connected to the requested channel then done.
  781. if (mCurrentChannel.IsValid())
  782. {
  783. const WideStringClass& curChanName = mCurrentChannel->GetName();
  784. if (curChanName.Compare_No_Case(chanName) == 0)
  785. {
  786. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELJOIN"));
  787. wait->EndWait(WaitCondition::ConditionMet, WOLSTRING("WOL_CONNECTED"));
  788. return wait;
  789. }
  790. }
  791. // Use default product password if one is not provided
  792. if (password == NULL)
  793. {
  794. RefPtrConst<Product> product = Product::Current();
  795. WWASSERT(product.IsValid());
  796. password = product->GetChannelPassword();
  797. }
  798. // Set up wait condition for joining channel
  799. RefPtr<SerialWait> wait = SerialWait::Create();
  800. if (wait.IsValid())
  801. {
  802. // Leave current channel
  803. if (mCurrentChannel.IsValid())
  804. {
  805. RefPtr<WaitCondition> leaveWait = LeaveChannelWait::Create(this);
  806. wait->Add(leaveWait);
  807. }
  808. if (chanName)
  809. {
  810. // Join new channel
  811. RefPtr<WaitCondition> joinWait = JoinChannelWait::Create(this, chanName, password, type);
  812. wait->Add(joinWait);
  813. }
  814. }
  815. return wait;
  816. }
  817. /******************************************************************************
  818. *
  819. * NAME
  820. * Session::RequestChannelJoin
  821. *
  822. * DESCRIPTION
  823. *
  824. * INPUTS
  825. * NONE
  826. *
  827. * RESULT
  828. * Success - True if request successful.
  829. *
  830. ******************************************************************************/
  831. bool Session::RequestChannelJoin(const RefPtr<ChannelData>& channel, const wchar_t* password)
  832. {
  833. if (channel.IsValid() && password)
  834. {
  835. WWDEBUG_SAY(("WOL: RequestChannelJoin C:%S P:%S\n", (const WCHAR*)channel->GetName(), password));
  836. mPendingChannel = channel;
  837. WOL::Channel& wolChannel = channel->GetData();
  838. wcstombs((char*)wolChannel.key, password, sizeof(wolChannel.key));
  839. // If the channel is not in the channel list then mark it as hidden.
  840. RefPtr<ChannelData> inList = FindChannel(channel->GetName());
  841. wolChannel.hidden = (inList.IsValid() ? 0 : 1);
  842. HRESULT hr = mChat->RequestChannelJoin(&wolChannel);
  843. if (FAILED(hr))
  844. {
  845. WWDEBUG_SAY(("WOLERROR: RequestChannelJoin() HRESULT = %s\n", GetChatErrorString(hr)));
  846. }
  847. return SUCCEEDED(hr);
  848. }
  849. return false;
  850. }
  851. /******************************************************************************
  852. *
  853. * NAME
  854. * Session::LeaveChannel
  855. *
  856. * DESCRIPTION
  857. *
  858. * INPUTS
  859. * NONE
  860. *
  861. * RESULT
  862. * Wait - Wait condition to process for leaving channel
  863. *
  864. ******************************************************************************/
  865. RefPtr<WaitCondition> Session::LeaveChannel(void)
  866. {
  867. if (!mCurrentChannel.IsValid() || (ChannelJoined != mCurrentChannelStatus))
  868. {
  869. mCurrentChannel.Release();
  870. mCurrentChannelStatus = ChannelLeft;
  871. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELLEAVE"));
  872. wait->EndWait(WaitCondition::ConditionMet, WOLSTRING("WOL_CHANNELLEFT"));
  873. return wait;
  874. }
  875. return LeaveChannelWait::Create(this);
  876. }
  877. bool Session::RequestLeaveChannel(void)
  878. {
  879. if (ChannelJoined == mCurrentChannelStatus)
  880. {
  881. HRESULT hr = mChat->RequestChannelLeave();
  882. if (FAILED(hr))
  883. {
  884. WWDEBUG_SAY(("WOLERROR: RequestChannelLeave() failed HRESULT = %s\n", GetChatErrorString(hr)));
  885. return false;
  886. }
  887. mCurrentChannelStatus = ChannelLeaving;
  888. }
  889. return true;
  890. }
  891. /******************************************************************************
  892. *
  893. * NAME
  894. * Session::GetNewChatChannelList
  895. *
  896. * DESCRIPTION
  897. * Request a new chat channel list.
  898. *
  899. * INPUTS
  900. * NONE
  901. *
  902. * RESULT
  903. * Wait - Wait condition to process for chat channel list.
  904. *
  905. ******************************************************************************/
  906. RefPtr<WaitCondition> Session::GetNewChatChannelList(void)
  907. {
  908. return ChannelListWait::Create(this, 0);
  909. }
  910. /******************************************************************************
  911. *
  912. * NAME
  913. * Session::FindChatChannel
  914. *
  915. * DESCRIPTION
  916. * Find a chat channel.
  917. *
  918. * INPUTS
  919. * ChannelName - Name of channel to search for.
  920. *
  921. * RESULT
  922. * Channel -
  923. *
  924. ******************************************************************************/
  925. RefPtr<ChannelData> Session::FindChatChannel(const wchar_t* channelName)
  926. {
  927. return FindChannelInList(mChatChannels, channelName);
  928. }
  929. RefPtr<ChannelData> Session::FindChatChannel(const char* channelName)
  930. {
  931. return FindChannelInList(mChatChannels, channelName);
  932. }
  933. /******************************************************************************
  934. *
  935. * NAME
  936. * Session::GetNewGameChannelList
  937. *
  938. * DESCRIPTION
  939. * Get new game channel list.
  940. *
  941. * INPUTS
  942. * NONE
  943. *
  944. * RESULT
  945. * Wait - Wait condition to process for obtaining new channel list.
  946. *
  947. ******************************************************************************/
  948. RefPtr<WaitCondition> Session::GetNewGameChannelList(void)
  949. {
  950. RefPtrConst<Product> product = Product::Current();
  951. if (product.IsValid())
  952. {
  953. int channelType = product->GetGameCode();
  954. return ChannelListWait::Create(this, channelType);
  955. }
  956. return NULL;
  957. }
  958. /******************************************************************************
  959. *
  960. * NAME
  961. * Session::RequestGameChannelList
  962. *
  963. * DESCRIPTION
  964. * Submit request for game channel list.
  965. *
  966. * INPUTS
  967. * NONE
  968. *
  969. * RESULT
  970. * Success - True if request successful.
  971. *
  972. ******************************************************************************/
  973. bool Session::RequestGameChannelList(void)
  974. {
  975. RefPtrConst<Product> product = Product::Current();
  976. if (!product.IsValid())
  977. {
  978. WWASSERT(product.IsValid());
  979. return false;
  980. }
  981. int channelType = product->GetGameCode();
  982. return RequestChannelList(channelType, false);
  983. }
  984. /******************************************************************************
  985. *
  986. * NAME
  987. * Session::FindGameChannel
  988. *
  989. * DESCRIPTION
  990. * Find a game channel.
  991. *
  992. * INPUTS
  993. * ChannelName - Name of channel to search for.
  994. *
  995. * RESULT
  996. * Channel -
  997. *
  998. ******************************************************************************/
  999. RefPtr<ChannelData> Session::FindGameChannel(const wchar_t* channelName)
  1000. {
  1001. return FindChannelInList(mGameChannels, channelName);
  1002. }
  1003. RefPtr<ChannelData> Session::FindGameChannel(const char* channelName)
  1004. {
  1005. return FindChannelInList(mGameChannels, channelName);
  1006. }
  1007. /******************************************************************************
  1008. *
  1009. * NAME
  1010. * Session::CreateChannel
  1011. *
  1012. * DESCRIPTION
  1013. * Create a new channel.
  1014. *
  1015. * INPUTS
  1016. * Name - Name of new channel.
  1017. * Password - Password for channel.
  1018. *
  1019. * RESULT
  1020. * Wait - Wait condition to process for channel creation.
  1021. *
  1022. ******************************************************************************/
  1023. RefPtr<WaitCondition> Session::CreateChannel(const wchar_t* name, const wchar_t* password, int type)
  1024. {
  1025. WWDEBUG_SAY(("WOL: CreateChannel '%S' Type %ld\n", name, type));
  1026. if (mCurrentConnectionStatus != ConnectionConnected)
  1027. {
  1028. WWASSERT(mCurrentConnectionStatus == ConnectionConnected);
  1029. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELCREATE"));
  1030. wait->EndWait(WaitCondition::Error, WOLSTRING("WOL_NOTCONNECTED"));
  1031. return wait;
  1032. }
  1033. // If we are already connected to the requested channel then done.
  1034. if (mCurrentChannel.IsValid())
  1035. {
  1036. const WideStringClass& curChanName = mCurrentChannel->GetName();
  1037. if (curChanName.Compare_No_Case(name) == 0)
  1038. {
  1039. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELCREATE"));
  1040. wait->EndWait(WaitCondition::Error, WOLSTRING("WOL_CONNECTED"));
  1041. return wait;
  1042. }
  1043. }
  1044. RefPtr<ChannelData> channel = ChannelData::Create(name, password, type);
  1045. // Set up wait condition for creating channel
  1046. mPendingChannel = channel;
  1047. RefPtr<SerialWait> wait = SerialWait::Create();
  1048. // Leave current channel
  1049. if (mCurrentChannel.IsValid())
  1050. {
  1051. RefPtr<WaitCondition> leave = LeaveChannelWait::Create(this);
  1052. wait->Add(leave);
  1053. }
  1054. // Create & Join channel
  1055. RefPtr<WaitCondition> create = CreateChannelWait::Create(this, channel, password);
  1056. wait->Add(create);
  1057. return wait;
  1058. }
  1059. /******************************************************************************
  1060. *
  1061. * NAME
  1062. * Session::CreateChannel
  1063. *
  1064. * DESCRIPTION
  1065. * Create a new channel
  1066. *
  1067. * INPUTS
  1068. * Channel - Channel data to create from.
  1069. * Password - Password for joining channel
  1070. *
  1071. * RESULT
  1072. * Wait - Wait condition to process for creating channel
  1073. *
  1074. ******************************************************************************/
  1075. RefPtr<WaitCondition> Session::CreateChannel(const RefPtr<ChannelData>& channel,
  1076. const wchar_t* password)
  1077. {
  1078. WWASSERT(channel.IsValid());
  1079. WWDEBUG_SAY(("WOL: CreateChannel '%S'\n", (const WCHAR*)channel->GetName()));
  1080. if (mCurrentConnectionStatus != ConnectionConnected)
  1081. {
  1082. WWASSERT(mCurrentConnectionStatus == ConnectionConnected);
  1083. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELCREATE"));
  1084. wait->EndWait(WaitCondition::Error, WOLSTRING("WOL_NOTCONNECTED"));
  1085. return wait;
  1086. }
  1087. // If we are already connected to the requested channel then done.
  1088. if (mCurrentChannel.IsValid())
  1089. {
  1090. const WideStringClass& curChanName = mCurrentChannel->GetName();
  1091. if (curChanName.Compare_No_Case(channel->GetName()) == 0)
  1092. {
  1093. RefPtr<SingleWait> wait = SingleWait::Create(WOLSTRING("WOL_CHANNELCREATE"));
  1094. wait->EndWait(WaitCondition::Error, WOLSTRING("WOL_CONNECTED"));
  1095. return wait;
  1096. }
  1097. }
  1098. mPendingChannel = channel;
  1099. // Set up wait condition for creating channel
  1100. RefPtr<SerialWait> wait = SerialWait::Create();
  1101. // Leave current channel
  1102. if (mCurrentChannel.IsValid())
  1103. {
  1104. RefPtr<WaitCondition> leave = LeaveChannelWait::Create(this);
  1105. wait->Add(leave);
  1106. }
  1107. // Create & join channel
  1108. RefPtr<WaitCondition> create = CreateChannelWait::Create(this, channel, password);
  1109. wait->Add(create);
  1110. return wait;
  1111. }
  1112. /******************************************************************************
  1113. *
  1114. * NAME
  1115. * Session::GetChannelTopic
  1116. *
  1117. * DESCRIPTION
  1118. * Get the topic of the current channel
  1119. *
  1120. * INPUTS
  1121. * NONE
  1122. *
  1123. * RESULT
  1124. * Topic - Channel topic or NULL if no topic or not in channel.
  1125. *
  1126. ******************************************************************************/
  1127. const char* Session::GetChannelTopic(void) const
  1128. {
  1129. const RefPtr<ChannelData>& channel = GetCurrentChannel();
  1130. if (channel.IsValid())
  1131. {
  1132. return channel->GetTopic();
  1133. }
  1134. return NULL;
  1135. }
  1136. /******************************************************************************
  1137. *
  1138. * NAME
  1139. * Session::SendChannelTopic
  1140. *
  1141. * DESCRIPTION
  1142. * Send the topic of the current channel.
  1143. *
  1144. * INPUTS
  1145. * NONE
  1146. *
  1147. * RESULT
  1148. * True if request successful.
  1149. *
  1150. ******************************************************************************/
  1151. bool Session::SendChannelTopic(void)
  1152. {
  1153. const RefPtr<ChannelData>& channel = GetCurrentChannel();
  1154. if (channel.IsValid())
  1155. {
  1156. const char* topic = channel->GetTopic();
  1157. if (topic)
  1158. {
  1159. HRESULT hr = mChat->RequestChannelTopic(topic);
  1160. if (SUCCEEDED(hr))
  1161. {
  1162. return true;
  1163. }
  1164. WWDEBUG_SAY(("WOLERROR: SendChannelTopic() HRESULT = %s\n", GetChatErrorString(hr)));
  1165. }
  1166. }
  1167. return false;
  1168. }
  1169. /******************************************************************************
  1170. *
  1171. * NAME
  1172. * Session::SendChannelExtraInfo
  1173. *
  1174. * DESCRIPTION
  1175. * Send the extra info for the current channel.
  1176. *
  1177. * INPUTS
  1178. * NONE
  1179. *
  1180. * RESULT
  1181. * True if request successful.
  1182. *
  1183. ******************************************************************************/
  1184. bool Session::SendChannelExtraInfo(void)
  1185. {
  1186. const RefPtr<ChannelData>& channel = GetCurrentChannel();
  1187. if (channel.IsValid())
  1188. {
  1189. const char* exInfo = channel->GetExtraInfo();
  1190. if (exInfo)
  1191. {
  1192. HRESULT hr = mChat->SetChannelExInfo(exInfo);
  1193. if (SUCCEEDED(hr))
  1194. {
  1195. return true;
  1196. }
  1197. WWDEBUG_SAY(("WOLERROR: ChangeChannelExtraInfo() HRESULT = %s\n", GetChatErrorString(hr)));
  1198. }
  1199. }
  1200. return false;
  1201. }
  1202. /******************************************************************************
  1203. *
  1204. * NAME
  1205. * Session::RequestUserList
  1206. *
  1207. * DESCRIPTION
  1208. * Request a new user list for the current channel from the IRC server.
  1209. *
  1210. * INPUTS
  1211. * NONE
  1212. *
  1213. * RESULT
  1214. * Success - True if request successful.
  1215. *
  1216. ******************************************************************************/
  1217. bool Session::RequestUserList(void)
  1218. {
  1219. HRESULT hr = mChat->RequestUserList();
  1220. if (FAILED(hr))
  1221. {
  1222. WWDEBUG_SAY(("WOLERROR: RequestUserList() HRESULT = %s\n", GetChatErrorString(hr)));
  1223. }
  1224. return SUCCEEDED(hr);
  1225. }
  1226. /******************************************************************************
  1227. *
  1228. * NAME
  1229. * Session::FindUser
  1230. *
  1231. * DESCRIPTION
  1232. * Search for a user in the user list by name.
  1233. *
  1234. * INPUTS
  1235. * Nickname - Name of user to look for.
  1236. *
  1237. * RESULT
  1238. * User - User, if found.
  1239. *
  1240. ******************************************************************************/
  1241. RefPtr<UserData> Session::FindUser(const wchar_t* nickname)
  1242. {
  1243. // Check the current user first.
  1244. if (mCurrentUser.IsValid())
  1245. {
  1246. const WideStringClass& username = mCurrentUser->GetName();
  1247. if (username.Compare_No_Case(nickname) == 0)
  1248. {
  1249. return mCurrentUser;
  1250. }
  1251. }
  1252. // Check in channels user list
  1253. return FindUserInList(nickname, mUsers);
  1254. }
  1255. /******************************************************************************
  1256. *
  1257. * NAME
  1258. * Session::GetUserOrBuddy
  1259. *
  1260. * DESCRIPTION
  1261. * Search for a user in the user list by name.
  1262. *
  1263. * INPUTS
  1264. * Nickname - Name of user to look for.
  1265. *
  1266. * RESULT
  1267. * User - User, if found.
  1268. *
  1269. ******************************************************************************/
  1270. RefPtr<UserData> Session::GetUserOrBuddy(const wchar_t* name)
  1271. {
  1272. RefPtr<UserData> user = FindUser(name);
  1273. if (!user.IsValid())
  1274. {
  1275. user = FindBuddy(name);
  1276. }
  1277. return user;
  1278. }
  1279. /******************************************************************************
  1280. *
  1281. * NAME
  1282. * Session::IsCurrentUser
  1283. *
  1284. * DESCRIPTION
  1285. * Check if the specified user is the one logged in.
  1286. *
  1287. * INPUTS
  1288. * User - User to check.
  1289. *
  1290. * RESULT
  1291. * True if specified user is the current one.
  1292. *
  1293. ******************************************************************************/
  1294. bool Session::IsCurrentUser(const RefPtr<UserData>& user) const
  1295. {
  1296. return user.IsValid() && mCurrentUser.IsValid() &&
  1297. user->GetName() == mCurrentUser->GetName();
  1298. }
  1299. bool Session::IsCurrentUser(const wchar_t* username) const
  1300. {
  1301. if (username && mCurrentUser.IsValid())
  1302. {
  1303. const WideStringClass& name = mCurrentUser->GetName();
  1304. return (name.Compare_No_Case(username) == 0);
  1305. }
  1306. return false;
  1307. }
  1308. /******************************************************************************
  1309. *
  1310. * NAME
  1311. * Session::ChangeCurrentUserLocale
  1312. *
  1313. * DESCRIPTION
  1314. * Change the locale for the user currently logged in.
  1315. *
  1316. * INPUTS
  1317. * Locale - New locale
  1318. *
  1319. * RESULT
  1320. * True if successful.
  1321. *
  1322. ******************************************************************************/
  1323. bool Session::ChangeCurrentUserLocale(WOL::Locale locale)
  1324. {
  1325. if (mCurrentUser.IsValid() && (mCurrentUser->GetLocale() != locale))
  1326. {
  1327. HRESULT hr = mChat->RequestSetLocale(locale);
  1328. if (SUCCEEDED(hr))
  1329. {
  1330. return true;
  1331. }
  1332. WWDEBUG_SAY(("WOLERROR: RequestSetLocale() HRESULT = %s\n", GetChatErrorString(hr)));
  1333. }
  1334. return false;
  1335. }
  1336. /******************************************************************************
  1337. *
  1338. * NAME
  1339. * Session::SquelchUser
  1340. *
  1341. * DESCRIPTION
  1342. * Enable / disable squelching (ignoring) of other users.
  1343. *
  1344. * INPUTS
  1345. * User - User to squelch / unsquelch
  1346. * OnOff - True to squelch; False unsquelch
  1347. *
  1348. * RESULT
  1349. * True if operation successful.
  1350. *
  1351. ******************************************************************************/
  1352. bool Session::SquelchUser(const RefPtr<UserData>& user, bool onoff)
  1353. {
  1354. if (user.IsValid())
  1355. {
  1356. WWDEBUG_SAY(("WOL: SquelchUser '%S'\n", user->GetName()));
  1357. HRESULT hr = mChat->SetSquelch(&user->GetData(), onoff);
  1358. if (SUCCEEDED(hr))
  1359. {
  1360. user->Squelch(onoff);
  1361. return true;
  1362. }
  1363. WWDEBUG_SAY(("WOLERROR: SetSquelch() HRESULT = %s\n", GetChatErrorString(hr)));
  1364. }
  1365. return false;
  1366. }
  1367. /******************************************************************************
  1368. *
  1369. * NAME
  1370. * Session::KickUser
  1371. *
  1372. * DESCRIPTION
  1373. * Make a request to kick a user from the current channel. Kicking is only
  1374. * allowed for channel owners.
  1375. *
  1376. * INPUTS
  1377. * User - Name of user to kick from the channel
  1378. *
  1379. * RESULT
  1380. * True if operation successful.
  1381. *
  1382. ******************************************************************************/
  1383. bool Session::KickUser(const wchar_t* username)
  1384. {
  1385. if (username)
  1386. {
  1387. RefPtr<UserData> user = FindUserInList(username, mUsers);
  1388. if (user.IsValid())
  1389. {
  1390. WWDEBUG_SAY(("WOL: KickUser '%S'\n", user->GetName()));
  1391. HRESULT hr = mChat->RequestUserKick(&user->GetData());
  1392. if (SUCCEEDED(hr))
  1393. {
  1394. return true;
  1395. }
  1396. WWDEBUG_SAY(("WOLERROR: RequestUserKick() HRESULT = %s\n", GetChatErrorString(hr)));
  1397. }
  1398. }
  1399. return false;
  1400. }
  1401. /******************************************************************************
  1402. *
  1403. * NAME
  1404. * Session::BanUser
  1405. *
  1406. * DESCRIPTION
  1407. * Make a request to ban / unban a user from the current channel.
  1408. * Banning is only allowed for channel owners.
  1409. *
  1410. * INPUTS
  1411. * User - Name of user to ban / unban from the channel
  1412. * Ban - True to ban; False to remove ban
  1413. *
  1414. * RESULT
  1415. * True if operation successful.
  1416. *
  1417. ******************************************************************************/
  1418. bool Session::BanUser(const wchar_t* username, bool banned)
  1419. {
  1420. if (username)
  1421. {
  1422. WWDEBUG_SAY(("WOL: BanUser '%S'\n", username));
  1423. char ansiName[64];
  1424. wcstombs(ansiName, username, sizeof(ansiName));
  1425. HRESULT hr = mChat->RequestChannelBan(ansiName, banned);
  1426. if (SUCCEEDED(hr))
  1427. {
  1428. return true;
  1429. }
  1430. WWDEBUG_SAY(("WOLERROR: RequestChannelBan() HRESULT = %s\n", GetChatErrorString(hr)));
  1431. }
  1432. return false;
  1433. }
  1434. /******************************************************************************
  1435. *
  1436. * NAME
  1437. * Session::PageUser
  1438. *
  1439. * DESCRIPTION
  1440. * Send page message to the specified user.
  1441. *
  1442. * INPUTS
  1443. * User - User to page.
  1444. * Message - Message to send.
  1445. *
  1446. * RESULT
  1447. * True if operation successful.
  1448. *
  1449. ******************************************************************************/
  1450. bool Session::PageUser(const wchar_t* username, const wchar_t* message)
  1451. {
  1452. if ((username && wcslen(username)) && (message && wcslen(message)))
  1453. {
  1454. WOL::User wolUser;
  1455. memset((void*)&wolUser, 0, sizeof(wolUser));
  1456. wcstombs((char*)&wolUser.name, username, sizeof(wolUser.name));
  1457. wolUser.name[sizeof(wolUser.name) - 1] = 0;
  1458. if (IsAnsiText(message))
  1459. {
  1460. char ansiMessage[1024];
  1461. wcstombs(ansiMessage, message, sizeof(ansiMessage));
  1462. HRESULT hr = mChat->RequestPage(&wolUser, ansiMessage);
  1463. if (FAILED(hr))
  1464. {
  1465. WWDEBUG_SAY(("WOLERROR: RequestPage() HRESULT = %s\n", GetChatErrorString(hr)));
  1466. }
  1467. return SUCCEEDED(hr);
  1468. }
  1469. else
  1470. {
  1471. HRESULT hr = mChat->RequestUnicodePage(&wolUser, message);
  1472. if (FAILED(hr))
  1473. {
  1474. WWDEBUG_SAY(("WOLERROR: RequestUnicodePage() HRESULT = %s\n", GetChatErrorString(hr)));
  1475. }
  1476. return SUCCEEDED(hr);
  1477. }
  1478. }
  1479. return false;
  1480. }
  1481. /******************************************************************************
  1482. *
  1483. * NAME
  1484. * Session::RequestLocateUser
  1485. *
  1486. * DESCRIPTION
  1487. * Locate the user on Westwood Online.
  1488. *
  1489. * INPUTS
  1490. * Name - Login name of the user to locate.
  1491. *
  1492. * RESULT
  1493. * True if operation successful.
  1494. *
  1495. ******************************************************************************/
  1496. void Session::RequestLocateUser(const wchar_t* name)
  1497. {
  1498. if (name && wcslen(name))
  1499. {
  1500. // If we already have the user then submit it, otherwise create a new user entry.
  1501. RefPtr<UserData> user = GetUserOrBuddy(name);
  1502. if (!user.IsValid())
  1503. {
  1504. user = UserData::Create(name);
  1505. }
  1506. RequestLocateUser(user);
  1507. }
  1508. }
  1509. void Session::RequestLocateUser(const RefPtr<UserData>& user)
  1510. {
  1511. if (user.IsValid())
  1512. {
  1513. // If the user is already pending then do not add him again.
  1514. RefPtr<UserData> pending = FindUserInList(user->GetName(), mLocatePendingUsers);
  1515. if (pending.IsValid())
  1516. {
  1517. return;
  1518. }
  1519. // Is user currently being located then done
  1520. if (mLocatingUser.IsValid())
  1521. {
  1522. const WideStringClass& userName = user->GetName();
  1523. if (userName.Compare_No_Case(mLocatingUser->GetName()) == 0)
  1524. {
  1525. return;
  1526. }
  1527. }
  1528. // Add the user to the pending locate list
  1529. mLocatePendingUsers.push_back(user);
  1530. }
  1531. }
  1532. /******************************************************************************
  1533. *
  1534. * NAME
  1535. * Session::MakeLocateUserRequests
  1536. *
  1537. * DESCRIPTION
  1538. * Make a request to the server to locate users.
  1539. *
  1540. * INPUTS
  1541. * NONE
  1542. *
  1543. * RESULT
  1544. * NONE
  1545. *
  1546. ******************************************************************************/
  1547. void Session::MakeLocateUserRequests(void)
  1548. {
  1549. if (!mLocatePendingUsers.empty() && !mLocatingUser.IsValid())
  1550. {
  1551. mLocatingUser = mLocatePendingUsers[0];
  1552. mLocatePendingUsers.erase(mLocatePendingUsers.begin());
  1553. HRESULT hr = mChat->RequestFind(&mLocatingUser->GetData());
  1554. if (FAILED(hr))
  1555. {
  1556. WWDEBUG_SAY(("WOLERROR: RequestFind() HRESULT = %s\n", GetChatErrorString(hr)));
  1557. }
  1558. }
  1559. }
  1560. /******************************************************************************
  1561. *
  1562. * NAME
  1563. * Session::RequestUserLocale
  1564. *
  1565. * DESCRIPTION
  1566. * Make a request to query a users locale. (IE: US, Germany, Korea)
  1567. *
  1568. * INPUTS
  1569. * Name - Name of user to query locale for.
  1570. *
  1571. * RESULT
  1572. * NONE
  1573. *
  1574. ******************************************************************************/
  1575. void Session::RequestUserLocale(const wchar_t* username)
  1576. {
  1577. if (username && (wcslen(username) > 0))
  1578. {
  1579. // Make sure the user is not already in the list.
  1580. const unsigned int count = mLocaleRequests.size();
  1581. for (unsigned int index = 0; index < count; ++index)
  1582. {
  1583. if (mLocaleRequests[index].Compare_No_Case(username) == 0)
  1584. {
  1585. return;
  1586. }
  1587. }
  1588. mLocaleRequests.push_back(username);
  1589. }
  1590. }
  1591. /******************************************************************************
  1592. *
  1593. * NAME
  1594. * Session::MakeLocaleRequests
  1595. *
  1596. * DESCRIPTION
  1597. * Make request to server to query user locales.
  1598. *
  1599. * INPUTS
  1600. * NONE
  1601. *
  1602. * RESULT
  1603. * NONE
  1604. *
  1605. ******************************************************************************/
  1606. void Session::MakeLocaleRequests(void)
  1607. {
  1608. if (!mLocaleRequests.empty())
  1609. {
  1610. const unsigned int count = min<unsigned int>(10, mLocaleRequests.size());
  1611. WOL::User* users = new WOL::User[count];
  1612. WWASSERT(users && "Failed to create temporary users array");
  1613. if (users)
  1614. {
  1615. for (unsigned int index = 0; index < count; ++index)
  1616. {
  1617. WideStringClass& username = mLocaleRequests[index];
  1618. WWDEBUG_SAY(("WOL: Requesting locale for '%S'\n", (const WCHAR*)username));
  1619. WOL::User& user = users[index];
  1620. wcstombs((char*)user.name, username, sizeof(user.name));
  1621. user.name[sizeof(user.name) - 1] = 0;
  1622. if (index == (count - 1))
  1623. {
  1624. user.next = NULL;
  1625. }
  1626. else
  1627. {
  1628. user.next = &users[index + 1];
  1629. }
  1630. }
  1631. HRESULT hr = mChat->RequestUserLocale(users);
  1632. // If request was successful then remove from the pending list.
  1633. if (SUCCEEDED(hr))
  1634. {
  1635. LocaleRequestColl::iterator first = mLocaleRequests.begin();
  1636. mLocaleRequests.erase(first, first + count);
  1637. }
  1638. else
  1639. {
  1640. WWDEBUG_SAY(("WOLERROR: RequestUserLocale() HRESULT = %s\n", GetChatErrorString(hr)));
  1641. }
  1642. delete []users;
  1643. }
  1644. }
  1645. }
  1646. /******************************************************************************
  1647. *
  1648. * NAME
  1649. * Session::RequestSquadInfoByID
  1650. *
  1651. * DESCRIPTION
  1652. * Request information about a squad by Squad ID.
  1653. *
  1654. * INPUTS
  1655. * SquadID - Identifier of squad
  1656. *
  1657. * RESULT
  1658. * NONE
  1659. *
  1660. ******************************************************************************/
  1661. void Session::RequestSquadInfoByID(unsigned long squadID)
  1662. {
  1663. if (squadID != 0)
  1664. {
  1665. // MAGICK NUMBER -- itoa handles up to 33 digit numbers
  1666. wchar_t idString[34];
  1667. // MAGICK NUMBER - 10 - squadID is base 10.
  1668. _itow(squadID, idString, 10);
  1669. // Only add a request that is not already pending.
  1670. const unsigned int count = mSquadRequests.size();
  1671. for (unsigned int index = 0; index < count; ++index)
  1672. {
  1673. if (mSquadRequests[index] == idString)
  1674. {
  1675. return;
  1676. }
  1677. }
  1678. mSquadRequests.push_back(idString);
  1679. }
  1680. }
  1681. /******************************************************************************
  1682. *
  1683. * NAME
  1684. * Session::RequestSquadInfoByMemberName
  1685. *
  1686. * DESCRIPTION
  1687. * Request information about a squad by Member Name.
  1688. *
  1689. * INPUTS
  1690. * memberName - user name of a member
  1691. *
  1692. * RESULT
  1693. * NONE
  1694. *
  1695. ******************************************************************************/
  1696. void Session::RequestSquadInfoByMemberName(const wchar_t* memberName)
  1697. {
  1698. if (memberName && (wcslen(memberName) > 0))
  1699. {
  1700. // Only add a request that is not already pending.
  1701. for (unsigned int index = 0; index < mSquadRequests.size(); index++)
  1702. {
  1703. if (mSquadRequests[index].Compare_No_Case(memberName) == 0)
  1704. {
  1705. return;
  1706. }
  1707. }
  1708. mSquadRequests.push_back(memberName);
  1709. }
  1710. }
  1711. /******************************************************************************
  1712. *
  1713. * NAME
  1714. * Session::MakeSquadRequests
  1715. *
  1716. * DESCRIPTION
  1717. * Make request to server to query squad information.
  1718. *
  1719. * INPUTS
  1720. * NONE
  1721. *
  1722. * RESULT
  1723. * NONE
  1724. *
  1725. ******************************************************************************/
  1726. void Session::MakeSquadRequests(void)
  1727. {
  1728. if (!mSquadRequests.empty() && mSquadPending.empty())
  1729. {
  1730. // Send up to ten requests at a time.
  1731. unsigned int count = min<unsigned int>(10, mSquadRequests.size());
  1732. // Send each request in turn,
  1733. for (unsigned int index = 0; index < count; ++index)
  1734. {
  1735. const WideStringClass& request = mSquadRequests[index];
  1736. HRESULT hr = E_FAIL;
  1737. // Check to see if this is an ID or a name
  1738. // - names can't have the first character be a number so this works.
  1739. wchar_t firstChar = request[0];
  1740. if (iswdigit(firstChar))
  1741. {
  1742. unsigned int squadID = _wtoi(request);
  1743. WWDEBUG_SAY(("WOL: SquadInfo requested for ID %ld\n", squadID));
  1744. hr = mChat->RequestSquadInfo(squadID);
  1745. }
  1746. else
  1747. {
  1748. StringClass name(0, true);
  1749. request.Convert_To(name);
  1750. WWDEBUG_SAY(("WOL: SquadInfo requested for '%s'\n", (const char*)name));
  1751. hr = mChat->RequestSquadByName(name);
  1752. }
  1753. if (FAILED(hr))
  1754. {
  1755. WWDEBUG_SAY(("WOLERROR: RequestSquadInfo() HRESULT = %s\n", GetChatErrorString(hr)));
  1756. break;
  1757. }
  1758. mSquadPending.push_back(request);
  1759. }
  1760. SquadRequestColl::iterator first = mSquadRequests.begin();
  1761. mSquadRequests.erase(first, first + index);
  1762. }
  1763. }
  1764. /******************************************************************************
  1765. *
  1766. * NAME
  1767. * Session::RequestTeamInfo
  1768. *
  1769. * DESCRIPTION
  1770. * Make a request to query a users team information.
  1771. *
  1772. * INPUTS
  1773. * Name - Name of user to request team information for.
  1774. *
  1775. * RESULT
  1776. * NONE
  1777. *
  1778. ******************************************************************************/
  1779. void Session::RequestTeamInfo(const wchar_t* username)
  1780. {
  1781. if (username && (wcslen(username) > 0))
  1782. {
  1783. for (unsigned int index = 0; index < mTeamRequests.size(); index++)
  1784. {
  1785. if (mTeamRequests[index].Compare_No_Case(username) == 0)
  1786. {
  1787. return;
  1788. }
  1789. }
  1790. mTeamRequests.push_back(username);
  1791. }
  1792. }
  1793. /******************************************************************************
  1794. *
  1795. * NAME
  1796. * Session::MakeTeamRequests
  1797. *
  1798. * DESCRIPTION
  1799. * Send team requests to the server.
  1800. *
  1801. * INPUTS
  1802. * NONE
  1803. *
  1804. * RESULT
  1805. * NONE
  1806. *
  1807. ******************************************************************************/
  1808. void Session::MakeTeamRequests(void)
  1809. {
  1810. if (!mTeamRequests.empty())
  1811. {
  1812. WWDEBUG_SAY(("WOL: Requesting team information\n"));
  1813. unsigned int count = min<unsigned int>(10, mTeamRequests.size());
  1814. WOL::User* users = new WOL::User[count];
  1815. WWASSERT(users && "Failed to create temporary users array");
  1816. if (users)
  1817. {
  1818. for (unsigned int index = 0; index < count; index++)
  1819. {
  1820. WOL::User& user = users[index];
  1821. WideStringClass& username = mTeamRequests[index];
  1822. wcstombs((char*)user.name, username.Peek_Buffer(), sizeof(user.name));
  1823. user.name[sizeof(user.name) - 1] = 0;
  1824. if (index == count - 1)
  1825. {
  1826. user.next = NULL;
  1827. }
  1828. else
  1829. {
  1830. user.next = users + index + 1;
  1831. }
  1832. }
  1833. HRESULT hr = mChat->RequestUserTeam(users);
  1834. // If request was successful then remove from the pending list.
  1835. if (SUCCEEDED(hr))
  1836. {
  1837. TeamRequestColl::iterator first = mTeamRequests.begin();
  1838. mTeamRequests.erase(first, first + count);
  1839. }
  1840. else
  1841. {
  1842. WWDEBUG_SAY(("WOL: HRESULT = %s\n", GetChatErrorString(hr)));
  1843. }
  1844. delete []users;
  1845. }
  1846. }
  1847. }
  1848. /******************************************************************************
  1849. *
  1850. * NAME
  1851. * Session::RequestLadderInfo
  1852. *
  1853. * DESCRIPTION
  1854. * Request a users ladder information.
  1855. *
  1856. * INPUTS
  1857. * User - Name of user to request information for.
  1858. * Type - Type of ladder requesting
  1859. *
  1860. * RESULT
  1861. * NONE
  1862. *
  1863. ******************************************************************************/
  1864. void Session::RequestLadderInfo(const wchar_t* name, unsigned long type)
  1865. {
  1866. if (name && (wcslen(name) > 0) && (type & LADDERTYPE_MASK))
  1867. {
  1868. WideStringClass request(64, true);
  1869. request = L"itc:";
  1870. // Clan ladder requests are mutually exclusive to other ladder requests
  1871. // because it requires the name of the clan, while the other requests use
  1872. // the users login name.
  1873. if (type & LadderType_Clan)
  1874. {
  1875. WWASSERT((type & (LadderType_Individual | LadderType_Team)) == 0);
  1876. request[2] = L'C';
  1877. }
  1878. else
  1879. {
  1880. if (type & LadderType_Individual)
  1881. {
  1882. request[0] = L'I';
  1883. }
  1884. if (type & LadderType_Team)
  1885. {
  1886. request[1] = L'T';
  1887. }
  1888. }
  1889. // Append the name to the request
  1890. request += name;
  1891. // Check if the request is already in the list.
  1892. LadderRequestList::iterator pending = mLadderRequests.begin();
  1893. while (pending != mLadderRequests.end())
  1894. {
  1895. if (request.Compare_No_Case(*pending) == 0)
  1896. {
  1897. return;
  1898. }
  1899. pending++;
  1900. }
  1901. WWDEBUG_SAY(("WOL: LadderInfo request added '%S'.\n", request));
  1902. mLadderRequests.push_back(request);
  1903. }
  1904. }
  1905. /******************************************************************************
  1906. *
  1907. * NAME
  1908. * Session::MakeLadderRequests
  1909. *
  1910. * DESCRIPTION
  1911. * Send ladder requests to the server.
  1912. *
  1913. * INPUTS
  1914. * NONE
  1915. *
  1916. * RESULT
  1917. * NONE
  1918. *
  1919. ******************************************************************************/
  1920. void Session::MakeLadderRequests(void)
  1921. {
  1922. // If there are requests and nothing is pending then send the next request
  1923. if (!mLadderRequests.empty() && mLadderPending == 0)
  1924. {
  1925. RefPtrConst<Product> product = Product::Current();
  1926. if (mLadderServer.IsValid() && product.IsValid())
  1927. {
  1928. // Build a single key from up to 10 requests with the same request type.
  1929. char keys[256];
  1930. keys[0] = 0;
  1931. unsigned int count = 0;
  1932. LadderRequestList::iterator request = mLadderRequests.begin();
  1933. const WideStringClass& firstRequest = *request;
  1934. while ((count < 10) && (request != mLadderRequests.end()))
  1935. {
  1936. // Stop appending requests as soon as we encounter a different type.
  1937. if (wcsncmp(firstRequest, *request, 3) != 0)
  1938. {
  1939. break;
  1940. }
  1941. // Seperate key entries with a colon
  1942. if (count > 0)
  1943. {
  1944. strcat(keys, ":");
  1945. }
  1946. // The request name follows the type
  1947. WCHAR* widename = wcschr(*request, L':');
  1948. WWASSERT(widename != NULL && "Invalid Ladder Request");
  1949. widename++;
  1950. // Add the request
  1951. char name[64];
  1952. wcstombs(name, widename, 64);
  1953. strcat(keys, name);
  1954. // Next request
  1955. count++;
  1956. request++;
  1957. }
  1958. WWDEBUG_SAY(("WOL: LadderInfo requested for '%s'.\n", keys));
  1959. mLadderPending = count;
  1960. const char* hostAddr = mLadderServer->GetHostAddress();
  1961. unsigned int port = mLadderServer->GetPort();
  1962. unsigned long sku = product->GetLadderSKU();
  1963. // Request individual ladder
  1964. if (firstRequest[0] == L'I')
  1965. {
  1966. HRESULT hr = mNetUtil->RequestLadderList(hostAddr, port, keys, sku, -1, 0, 0);
  1967. if (FAILED(hr))
  1968. {
  1969. WWDEBUG_SAY(("WOLERROR: RequestLadderList (Individual) HRESULT = %s\n", GetNetUtilErrorString(hr)));
  1970. return;
  1971. }
  1972. mLadderPending |= LadderType_Individual;
  1973. }
  1974. // Request team ladder
  1975. if (firstRequest[1] == L'T')
  1976. {
  1977. HRESULT hr = mNetUtil->RequestLadderList(hostAddr, port, keys, (sku | LadderType_Team), -1, 0, 0);
  1978. if (FAILED(hr))
  1979. {
  1980. WWDEBUG_SAY(("WOLERROR: RequestLadderList (Team) HRESULT = %s\n", GetNetUtilErrorString(hr)));
  1981. return;
  1982. }
  1983. mLadderPending |= LadderType_Team;
  1984. }
  1985. // Request clan ladder
  1986. if (firstRequest[2] == L'C')
  1987. {
  1988. HRESULT hr = mNetUtil->RequestLadderList(hostAddr, port, keys, (sku | LadderType_Clan), -1, 0, 0);
  1989. if (FAILED(hr))
  1990. {
  1991. WWDEBUG_SAY(("WOLERROR: RequestLadderList (Clan) HRESULT = %s\n", GetNetUtilErrorString(hr)));
  1992. return;
  1993. }
  1994. mLadderPending |= LadderType_Clan;
  1995. }
  1996. }
  1997. }
  1998. }
  1999. /******************************************************************************
  2000. *
  2001. * NAME
  2002. * Session::RequestUserDetails
  2003. *
  2004. * DESCRIPTION
  2005. * Request detailed information about the user (Ladder, Clan, Team, etc...)
  2006. *
  2007. * INPUTS
  2008. * User - User to request details for.
  2009. * RequestFlags - Flags indicating the type of information to request.
  2010. *
  2011. * RESULT
  2012. * NONE
  2013. *
  2014. ******************************************************************************/
  2015. void Session::RequestUserDetails(const RefPtr<UserData>& user, unsigned long requestFlags)
  2016. {
  2017. if (user.IsValid())
  2018. {
  2019. if (requestFlags & REQUEST_SQUADINFO)
  2020. {
  2021. // Request squad information for the user.
  2022. unsigned int squadID = user->GetSquadID();
  2023. RefPtr<SquadData> squad = user->GetSquad();
  2024. bool requestSquad = (!squad.IsValid() && (squadID != 0));
  2025. bool changedSquad = (squad.IsValid() && (squadID != squad->GetID()));
  2026. if (requestSquad || changedSquad)
  2027. {
  2028. // Look for the squad in the local cache
  2029. squad = SquadData::FindByID(squadID);
  2030. user->SetSquad(squad);
  2031. // Request squad information if it is not in the local cache.
  2032. if (!squad.IsValid())
  2033. {
  2034. RequestSquadInfoByID(squadID);
  2035. }
  2036. else
  2037. {
  2038. UserEvent event(UserEvent::SquadInfo, user);
  2039. NotifyObservers(event);
  2040. }
  2041. }
  2042. }
  2043. // Request locale information for this user.
  2044. if ((requestFlags & REQUEST_LOCALE) && (user->GetLocale() == WOL::LOC_UNKNOWN))
  2045. {
  2046. RequestUserLocale(user->GetName());
  2047. }
  2048. // Request ladder information for this user.
  2049. if ((requestFlags & REQUEST_LADDERINFO) && !user->GetLadder().IsValid())
  2050. {
  2051. RequestLadderInfo(user->GetName(), LadderType_Team);
  2052. }
  2053. // Request team information for this user.
  2054. if ((requestFlags & REQUEST_TEAMINFO) && (user->GetTeam() == 0))
  2055. {
  2056. RequestTeamInfo(user->GetName());
  2057. }
  2058. }
  2059. }
  2060. /******************************************************************************
  2061. *
  2062. * NAME
  2063. * Session::AutoRequestUserDetails
  2064. *
  2065. * DESCRIPTION
  2066. *
  2067. * INPUTS
  2068. *
  2069. * RESULT
  2070. * NONE
  2071. *
  2072. ******************************************************************************/
  2073. void Session::AutoRequestUserDetails(const RefPtr<UserData>& user)
  2074. {
  2075. RequestUserDetails(user, mAutoRequestFlags);
  2076. }
  2077. /******************************************************************************
  2078. *
  2079. * NAME
  2080. * Session::RequestBuddyList
  2081. *
  2082. * DESCRIPTION
  2083. * Send a request to the server for our buddy list.
  2084. *
  2085. * INPUTS
  2086. * NONE
  2087. *
  2088. * RESULT
  2089. * Success - True if request successful
  2090. *
  2091. ******************************************************************************/
  2092. bool Session::RequestBuddyList(void)
  2093. {
  2094. HRESULT hr = mChat->RequestBuddyList();
  2095. if (FAILED(hr))
  2096. {
  2097. WWDEBUG_SAY(("WOLERROR: RequestBuddyList() failed HRESULT = %s\n", GetChatErrorString(hr)));
  2098. }
  2099. return SUCCEEDED(hr);
  2100. }
  2101. /******************************************************************************
  2102. *
  2103. * NAME
  2104. * Session::AddBuddy
  2105. *
  2106. * DESCRIPTION
  2107. * Send a request to the server to add a buddy to our buddy list.
  2108. *
  2109. * INPUTS
  2110. * Buddy - Name of buddy to add.
  2111. *
  2112. * RESULT
  2113. * True if request sent successfully
  2114. *
  2115. ******************************************************************************/
  2116. bool Session::AddBuddy(const wchar_t* buddyName)
  2117. {
  2118. WOL::User wolUser;
  2119. memset((void*)&wolUser, 0, sizeof(wolUser));
  2120. wcstombs((char*)&wolUser.name, buddyName, sizeof(wolUser.name));
  2121. wolUser.name[sizeof(wolUser.name) - 1] = 0;
  2122. HRESULT hr = mChat->RequestBuddyAdd(&wolUser);
  2123. if (FAILED(hr))
  2124. {
  2125. WWDEBUG_SAY(("WOLERROR: RequestBuddyAdd() failed HRESULT = %s\n", GetChatErrorString(hr)));
  2126. }
  2127. return SUCCEEDED(hr);
  2128. }
  2129. /******************************************************************************
  2130. *
  2131. * NAME
  2132. * Session::RemoveBuddy
  2133. *
  2134. * DESCRIPTION
  2135. * Send a request to the server to remove a buddy from our buddy list.
  2136. *
  2137. * INPUTS
  2138. * Buddy - Name of buddy to remove.
  2139. *
  2140. * RESULT
  2141. * True if request sent successfully
  2142. *
  2143. ******************************************************************************/
  2144. bool Session::RemoveBuddy(const wchar_t* buddyName)
  2145. {
  2146. WOL::User wolUser;
  2147. memset((void*)&wolUser, 0, sizeof(wolUser));
  2148. wcstombs((char*)&wolUser.name, buddyName, sizeof(wolUser.name));
  2149. wolUser.name[sizeof(wolUser.name) - 1] = 0;
  2150. HRESULT hr = mChat->RequestBuddyDelete(&wolUser);
  2151. if (FAILED(hr))
  2152. {
  2153. WWDEBUG_SAY(("WOLERROR: RequestBuddyDelete() failed HRESULT = %s\n", GetChatErrorString(hr)));
  2154. }
  2155. return SUCCEEDED(hr);
  2156. }
  2157. /******************************************************************************
  2158. *
  2159. * NAME
  2160. * Session::AllowFindPage
  2161. *
  2162. * DESCRIPTION
  2163. * Set flags to allow / disallow user from being found or paged.
  2164. *
  2165. * INPUTS
  2166. * AllowFind - True to allow user to be found; False to disallow.
  2167. * AllowPage - True to allow user to be paged; False to disallow.
  2168. *
  2169. * RESULT
  2170. * True if request successful
  2171. *
  2172. ******************************************************************************/
  2173. bool Session::AllowFindPage(bool allowFind, bool allowPage)
  2174. {
  2175. HRESULT hr = mChat->SetFindPage(allowFind, allowPage);
  2176. if (FAILED(hr))
  2177. {
  2178. WWDEBUG_SAY(("WOLERROR: SetFindPage() failed HRESULT = %s\n", GetChatErrorString(hr)));
  2179. }
  2180. return SUCCEEDED(hr);
  2181. }
  2182. /******************************************************************************
  2183. *
  2184. * NAME
  2185. * Session::SetBadLanguageFilter
  2186. *
  2187. * DESCRIPTION
  2188. * Enable / Disable filtering of bad language.
  2189. *
  2190. * INPUTS
  2191. * Filter - True to enable filtering, false to disable.
  2192. *
  2193. * RESULT
  2194. * True if request successful
  2195. *
  2196. ******************************************************************************/
  2197. bool Session::SetBadLanguageFilter(bool enabled)
  2198. {
  2199. HRESULT hr = mChat->SetLangFilter(enabled);
  2200. if (FAILED(hr))
  2201. {
  2202. WWDEBUG_SAY(("WOLERROR: SetLangFilter() failed HRESULT = %s\n", GetChatErrorString(hr)));
  2203. }
  2204. return SUCCEEDED(hr);
  2205. }
  2206. /******************************************************************************
  2207. *
  2208. * NAME
  2209. * Session::SendPublicMessage
  2210. *
  2211. * DESCRIPTION
  2212. * Send a public message to all users in our channel.
  2213. *
  2214. * INPUTS
  2215. * Message - Message to send
  2216. *
  2217. * RESULT
  2218. * True if request successful
  2219. *
  2220. ******************************************************************************/
  2221. bool Session::SendPublicMessage(const char* message)
  2222. {
  2223. if (message)
  2224. {
  2225. return SUCCEEDED(mChat->RequestPublicMessage(message));
  2226. }
  2227. return false;
  2228. }
  2229. bool Session::SendPublicMessage(const wchar_t* message)
  2230. {
  2231. if (message)
  2232. {
  2233. if (IsAnsiText(message))
  2234. {
  2235. char ansiMessage[1024];
  2236. wcstombs(ansiMessage, message, sizeof(ansiMessage));
  2237. return SUCCEEDED(mChat->RequestPublicMessage(ansiMessage));
  2238. }
  2239. else
  2240. {
  2241. return SUCCEEDED(mChat->RequestPublicUnicodeMessage(message));
  2242. }
  2243. }
  2244. return false;
  2245. }
  2246. /******************************************************************************
  2247. *
  2248. * NAME
  2249. * Session::SendPublicAction
  2250. *
  2251. * DESCRIPTION
  2252. * Send an actions to all users in our channel.
  2253. *
  2254. * INPUTS
  2255. * Action - Action message
  2256. *
  2257. * RESULT
  2258. * True if request successful
  2259. *
  2260. ******************************************************************************/
  2261. bool Session::SendPublicAction(const char* action)
  2262. {
  2263. if (action)
  2264. {
  2265. return SUCCEEDED(mChat->RequestPublicAction(action));
  2266. }
  2267. return false;
  2268. }
  2269. bool Session::SendPublicAction(const wchar_t* action)
  2270. {
  2271. if (action)
  2272. {
  2273. if (IsAnsiText(action))
  2274. {
  2275. char ansiAction[1024];
  2276. wcstombs(ansiAction, action, sizeof(ansiAction));
  2277. return SUCCEEDED(mChat->RequestPublicAction(ansiAction));
  2278. }
  2279. else
  2280. {
  2281. return SUCCEEDED(mChat->RequestPublicUnicodeAction(action));
  2282. }
  2283. }
  2284. return false;
  2285. }
  2286. /******************************************************************************
  2287. *
  2288. * NAME
  2289. * Session::SendPrivateMessage
  2290. *
  2291. * DESCRIPTION
  2292. * Send a private message to a single user.
  2293. *
  2294. * INPUTS
  2295. * Username - Name of user to send private message to.
  2296. * Message - Message to send.
  2297. *
  2298. * RESULT
  2299. * True if request successful
  2300. *
  2301. ******************************************************************************/
  2302. bool Session::SendPrivateMessage(const wchar_t* username, const wchar_t* message)
  2303. {
  2304. if (username && message)
  2305. {
  2306. WOL::User user;
  2307. memset(&user, 0, sizeof(user));
  2308. wcstombs((char*)user.name, username, sizeof(user.name));
  2309. user.name[sizeof(user.name) - 1] = 0;
  2310. if (IsAnsiText(message))
  2311. {
  2312. char ansiMessage[512];
  2313. wcstombs(ansiMessage, message, sizeof(ansiMessage));
  2314. return SUCCEEDED(mChat->RequestPrivateMessage(&user, ansiMessage));
  2315. }
  2316. return SUCCEEDED(mChat->RequestPrivateUnicodeMessage(&user, message));
  2317. }
  2318. return false;
  2319. }
  2320. /******************************************************************************
  2321. *
  2322. * NAME
  2323. * Session::SendPrivateMessage
  2324. *
  2325. * DESCRIPTION
  2326. * Send a private message to a set of users.
  2327. *
  2328. * INPUTS
  2329. * Users - List of users to send message
  2330. * Message - Message to send.
  2331. *
  2332. * RESULT
  2333. * True if request successful
  2334. *
  2335. ******************************************************************************/
  2336. bool Session::SendPrivateMessage(const UserList& users, const char* message)
  2337. {
  2338. if (!users.empty() && message)
  2339. {
  2340. NativeWOLUserList wolUsers(users);
  2341. return SUCCEEDED(mChat->RequestPrivateMessage(wolUsers, message));
  2342. }
  2343. return false;
  2344. }
  2345. bool Session::SendPrivateMessage(const UserList& users, const wchar_t* message)
  2346. {
  2347. if (!users.empty() && message)
  2348. {
  2349. NativeWOLUserList wolUsers(users);
  2350. if (IsAnsiText(message))
  2351. {
  2352. char ansiMessage[512];
  2353. wcstombs(ansiMessage, message, sizeof(ansiMessage));
  2354. return SUCCEEDED(mChat->RequestPrivateMessage(wolUsers, ansiMessage));
  2355. }
  2356. return SUCCEEDED(mChat->RequestPrivateUnicodeMessage(wolUsers, message));
  2357. }
  2358. return false;
  2359. }
  2360. /******************************************************************************
  2361. *
  2362. * NAME
  2363. * Session::SendPrivateAction
  2364. *
  2365. * DESCRIPTION
  2366. * Send a private action message to a set of users.
  2367. *
  2368. * INPUTS
  2369. * Users - List of users to send message to.
  2370. * Action - Action message to send.
  2371. *
  2372. * RESULT
  2373. * True if request successful
  2374. *
  2375. ******************************************************************************/
  2376. bool Session::SendPrivateAction(const UserList& users, const char* action)
  2377. {
  2378. if (!users.empty() && action)
  2379. {
  2380. NativeWOLUserList wolUsers(users);
  2381. return SUCCEEDED(mChat->RequestPrivateAction(wolUsers, action));
  2382. }
  2383. return false;
  2384. }
  2385. bool Session::SendPrivateAction(const UserList& users, const wchar_t* action)
  2386. {
  2387. if (!users.empty() && action)
  2388. {
  2389. NativeWOLUserList wolUsers(users);
  2390. if (IsAnsiText(action))
  2391. {
  2392. char ansiAction[1024];
  2393. wcstombs(ansiAction, action, sizeof(ansiAction));
  2394. return SUCCEEDED(mChat->RequestPrivateAction(wolUsers, ansiAction));
  2395. }
  2396. return SUCCEEDED(mChat->RequestPrivateUnicodeAction(wolUsers, action));
  2397. }
  2398. return false;
  2399. }
  2400. /******************************************************************************
  2401. *
  2402. * NAME
  2403. * Session::SendPublicGameOptions
  2404. *
  2405. * DESCRIPTION
  2406. * Send public game options
  2407. *
  2408. * INPUTS
  2409. * Options - Options to send to all users in the channel.
  2410. *
  2411. * RESULT
  2412. * True if request successful
  2413. *
  2414. ******************************************************************************/
  2415. bool Session::SendPublicGameOptions(const char* options)
  2416. {
  2417. if (options)
  2418. {
  2419. return SUCCEEDED(mChat->RequestPublicGameOptions(options));
  2420. }
  2421. return false;
  2422. }
  2423. /******************************************************************************
  2424. *
  2425. * NAME
  2426. * Session::SendPrivateGameOptions
  2427. *
  2428. * DESCRIPTION
  2429. *
  2430. * INPUTS
  2431. * Options - Options to send to specific users.
  2432. *
  2433. * RESULT
  2434. * True if request successful
  2435. *
  2436. ******************************************************************************/
  2437. bool Session::SendPrivateGameOptions(const UserList& users, const char* options)
  2438. {
  2439. if (options)
  2440. {
  2441. for (unsigned int index = 0; index < users.size(); index++)
  2442. {
  2443. NativeWOLUserList wolUsers(users);
  2444. HRESULT hr = mChat->RequestPrivateGameOptions(wolUsers, options);
  2445. if (FAILED(hr))
  2446. {
  2447. return false;
  2448. }
  2449. }
  2450. return true;
  2451. }
  2452. return false;
  2453. }
  2454. bool Session::SendPrivateGameOptions(const wchar_t* user, const char* options)
  2455. {
  2456. if (user && options)
  2457. {
  2458. WOL::User wolUser;
  2459. memset(&wolUser, 0, sizeof(WOL::User));
  2460. wcstombs((char*)wolUser.name, user, sizeof(wolUser.name));
  2461. wolUser.name[sizeof(wolUser.name) - 1] = 0;
  2462. return SUCCEEDED(mChat->RequestPrivateGameOptions(&wolUser, options));
  2463. }
  2464. return false;
  2465. }
  2466. /******************************************************************************
  2467. *
  2468. * NAME
  2469. * Session::GetLocaleStrings
  2470. *
  2471. * DESCRIPTION
  2472. * Get a list of the WWOnline locale strings.
  2473. *
  2474. * INPUTS
  2475. * Strings - List to fill with locale name strings.
  2476. *
  2477. * RESULT
  2478. * NONE
  2479. *
  2480. ******************************************************************************/
  2481. void Session::GetLocaleStrings(std::vector<WideStringClass>& localeStrings)
  2482. {
  2483. localeStrings.clear();
  2484. int numLocales = 0;
  2485. mChat->GetLocaleCount(&numLocales);
  2486. for (int index = 0; index < numLocales; index++)
  2487. {
  2488. const char* name = NULL;
  2489. mChat->GetLocaleString(&name, (WOL::Locale)index);
  2490. localeStrings.push_back(name);
  2491. }
  2492. }
  2493. /******************************************************************************
  2494. *
  2495. * NAME
  2496. * Session::SendGameResults
  2497. *
  2498. * DESCRIPTION
  2499. *
  2500. * INPUTS
  2501. * Packet - Game results packet to send.
  2502. * Length - Length of packet in bytes.
  2503. *
  2504. * RESULT
  2505. * True if request sent successfully
  2506. *
  2507. ******************************************************************************/
  2508. bool Session::SendGameResults(unsigned char* packet, unsigned long length)
  2509. {
  2510. if (packet && mGameResultsServer.IsValid())
  2511. {
  2512. mNetUtil->SetGameResMD5(true);
  2513. const char* host = mGameResultsServer->GetHostAddress();
  2514. unsigned int port = mGameResultsServer->GetPort();
  2515. HRESULT hr = mNetUtil->RequestLargeGameresSend(host, port, packet, length);
  2516. if (FAILED(hr))
  2517. {
  2518. WWDEBUG_SAY(("WOLERROR: RequestLargeGameresSend() failed HRESULT = %s\n", GetChatErrorString(hr)));
  2519. }
  2520. return SUCCEEDED(hr);
  2521. }
  2522. return false;
  2523. }
  2524. /******************************************************************************
  2525. *
  2526. * NAME
  2527. * Session::EnablePinging
  2528. *
  2529. * DESCRIPTION
  2530. *
  2531. * INPUTS
  2532. *
  2533. * RESULT
  2534. * NONE
  2535. *
  2536. ******************************************************************************/
  2537. void Session::EnablePinging(bool enable)
  2538. {
  2539. mPingEnable += ((enable == true) ? 1 : -1);
  2540. }
  2541. /******************************************************************************
  2542. *
  2543. * NAME
  2544. * Session::RequestPing
  2545. *
  2546. * DESCRIPTION
  2547. * Request a ping to the specified address.
  2548. *
  2549. * INPUTS
  2550. * Address - Address to ping (IE: irc.westwood.com)
  2551. * Timeout - Maximum time to allow for response.
  2552. *
  2553. * RESULT
  2554. * NONE
  2555. *
  2556. ******************************************************************************/
  2557. void Session::RequestPing(const char* address, int timeout)
  2558. {
  2559. if (address)
  2560. {
  2561. // If the address is already pending then do not add it again.
  2562. std::vector<RawPing>::iterator iter = mPingRequests.begin();
  2563. while (iter != mPingRequests.end())
  2564. {
  2565. if (stricmp(iter->GetHostAddress(), address) == 0)
  2566. {
  2567. // WWDEBUG_SAY(("WOLWARNING: Ping request already pending %s\n", address));
  2568. return;
  2569. }
  2570. iter++;
  2571. }
  2572. WWDEBUG_SAY(("WOL: Adding ping request %s\n", address));
  2573. RawPing ping(address, 0, timeout);
  2574. mPingRequests.push_back(ping);
  2575. }
  2576. }
  2577. /******************************************************************************
  2578. *
  2579. * NAME
  2580. * Session::MakePingRequests
  2581. *
  2582. * DESCRIPTION
  2583. * Send out ping requests
  2584. *
  2585. * INPUTS
  2586. * NONE
  2587. *
  2588. * RESULT
  2589. * NONE
  2590. *
  2591. ******************************************************************************/
  2592. void Session::MakePingRequests(void)
  2593. {
  2594. if (mPingEnable && (mPingRequests.size() > mPingsPending))
  2595. {
  2596. for (unsigned int index = 0; index < mPingRequests.size(); index++)
  2597. {
  2598. RawPing* ping = &mPingRequests[index];
  2599. if (ping->GetHandle() == -1)
  2600. {
  2601. int handle = 0;
  2602. HRESULT hr = mNetUtil->RequestPing(ping->GetHostAddress(), ping->GetTime(), &handle);
  2603. if (SUCCEEDED(hr))
  2604. {
  2605. WWDEBUG_SAY(("WOL: Pinging '%s' [%d]\n", ping->GetHostAddress(), handle));
  2606. ping->SetHandle(handle);
  2607. mPingsPending++;
  2608. }
  2609. }
  2610. }
  2611. }
  2612. }
  2613. /******************************************************************************
  2614. *
  2615. * NAME
  2616. * Session::UpdatePingServerTime
  2617. *
  2618. * DESCRIPTION
  2619. * Update the ping time of a ping server.
  2620. *
  2621. * INPUTS
  2622. * Name - Host adddress of server to update.
  2623. * Time - Ping time.
  2624. *
  2625. * RESULT
  2626. * NONE
  2627. *
  2628. ******************************************************************************/
  2629. void Session::UpdatePingServerTime(const char* name, int time)
  2630. {
  2631. if (name)
  2632. {
  2633. // Automatically update ping server times.
  2634. const PingServerList& pingers = GetPingServerList();
  2635. for (unsigned int index = 0; index < pingers.size(); index++)
  2636. {
  2637. const char* pinger = pingers[index]->GetHostAddress();
  2638. if (stricmp(name, pinger) == 0)
  2639. {
  2640. if (time < 0)
  2641. {
  2642. time = INT_MAX;
  2643. }
  2644. pingers[index]->SetPingTime(time);
  2645. break;
  2646. }
  2647. }
  2648. }
  2649. }
  2650. /******************************************************************************
  2651. *
  2652. * NAME
  2653. * Session::RequestUserIP
  2654. *
  2655. * DESCRIPTION
  2656. * Ask the chat server for a users IP address
  2657. *
  2658. * INPUTS
  2659. * Name of user
  2660. *
  2661. * RESULT
  2662. * NONE
  2663. *
  2664. ******************************************************************************/
  2665. bool Session::RequestUserIP(char *user_name)
  2666. {
  2667. if (user_name)
  2668. {
  2669. WOL::User wolUser;
  2670. memset(&wolUser, 0, sizeof(WOL::User));
  2671. strncpy((char*)wolUser.name, user_name, sizeof(wolUser.name));
  2672. wolUser.name[sizeof(wolUser.name) - 1] = 0;
  2673. return SUCCEEDED(mChat->RequestUserIP(&wolUser));
  2674. }
  2675. return false;
  2676. }
  2677. /******************************************************************************
  2678. *
  2679. * NAME
  2680. * Session::RequestInsiderStatus
  2681. *
  2682. * DESCRIPTION
  2683. * Used to ask the chat server for if the currently logged in user is
  2684. * an insider or not.
  2685. *
  2686. * INPUTS
  2687. * NONE
  2688. *
  2689. * RESULT
  2690. * NONE
  2691. *
  2692. ******************************************************************************/
  2693. void Session::RequestInsiderStatus(void)
  2694. {
  2695. if (mChat != NULL && mCurrentUser.IsValid ())
  2696. {
  2697. WOL::User &user = mCurrentUser->GetData();
  2698. mChat->RequestInsiderStatus(&user);
  2699. }
  2700. }
  2701. /******************************************************************************
  2702. *
  2703. * NAME
  2704. * Session::RequestServerTime
  2705. *
  2706. * DESCRIPTION
  2707. * Used to ask the chat server for its current time.
  2708. *
  2709. * INPUTS
  2710. * NONE
  2711. *
  2712. * RESULT
  2713. * NONE
  2714. *
  2715. ******************************************************************************/
  2716. void Session::RequestServerTime(void)
  2717. {
  2718. if (mChat != NULL)
  2719. {
  2720. mChat->RequestServerTime();
  2721. }
  2722. }
  2723. /******************************************************************************
  2724. *
  2725. * NAME
  2726. * Session::GetIGRObject
  2727. *
  2728. * DESCRIPTION
  2729. *
  2730. * INPUTS
  2731. * NONE
  2732. *
  2733. * RESULT
  2734. *
  2735. ******************************************************************************/
  2736. const CComPtr<WOL::IIGROptions>& Session::GetIGRObject(void)
  2737. {
  2738. if (mIGRObject == NULL)
  2739. {
  2740. WWDEBUG_SAY(("WOL: Creating IID_IIGROptions object\n"));
  2741. WOL::IIGROptions* igrObject = NULL;
  2742. HRESULT hr = CoCreateInstance(WOL::CLSID_IGROptions, NULL, CLSCTX_INPROC_SERVER,
  2743. WOL::IID_IIGROptions, (void**)&igrObject);
  2744. if (SUCCEEDED(hr))
  2745. {
  2746. HRESULT hr = igrObject->Init();
  2747. if (S_FALSE == hr)
  2748. {
  2749. WWDEBUG_SAY(("WOLWARNING: IGR settings not found\n"));
  2750. }
  2751. }
  2752. else
  2753. {
  2754. WWDEBUG_SAY(("WOLERROR: Failed to create IID_IIGROptions\n"));
  2755. }
  2756. mIGRObject = igrObject;
  2757. }
  2758. return mIGRObject;
  2759. }
  2760. /******************************************************************************
  2761. *
  2762. * NAME
  2763. * Session::IsStoreLoginAllowed
  2764. *
  2765. * DESCRIPTION
  2766. * Check if it is okay to save users login information.
  2767. *
  2768. * INPUTS
  2769. * NONE
  2770. *
  2771. * RESULT
  2772. * True if allowed to save login information.
  2773. *
  2774. ******************************************************************************/
  2775. bool Session::IsStoreLoginAllowed(void)
  2776. {
  2777. const CComPtr<WOL::IIGROptions>& igr = GetIGRObject();
  2778. if (igr)
  2779. {
  2780. HRESULT hr = igr->Is_Storing_Nicks_Allowed();
  2781. return (hr == S_OK);
  2782. }
  2783. return true;
  2784. }
  2785. /******************************************************************************
  2786. *
  2787. * NAME
  2788. * Session::IsAutoLoginAllowed
  2789. *
  2790. * DESCRIPTION
  2791. * Check if it is okay to automatically login users.
  2792. *
  2793. * INPUTS
  2794. * NONE
  2795. *
  2796. * RESULT
  2797. * True if allowed to auto login.
  2798. *
  2799. ******************************************************************************/
  2800. bool Session::IsAutoLoginAllowed(void)
  2801. {
  2802. const CComPtr<WOL::IIGROptions>& igr = GetIGRObject();
  2803. if (igr)
  2804. {
  2805. HRESULT hr = igr->Is_Auto_Login_Allowed();
  2806. return (hr == S_OK);
  2807. }
  2808. return true;
  2809. }
  2810. /******************************************************************************
  2811. *
  2812. * NAME
  2813. * Session::IsRunRegAppAllowed
  2814. *
  2815. * DESCRIPTION
  2816. *
  2817. * INPUTS
  2818. * NONE
  2819. *
  2820. * RESULT
  2821. * True if allowed to run registration applet.
  2822. *
  2823. ******************************************************************************/
  2824. bool Session::IsRunRegAppAllowed(void)
  2825. {
  2826. const CComPtr<WOL::IIGROptions>& igr = GetIGRObject();
  2827. if (igr)
  2828. {
  2829. HRESULT hr = igr->Is_Running_Reg_App_Allowed();
  2830. return (hr == S_OK);
  2831. }
  2832. return true;
  2833. }
  2834. /******************************************************************************
  2835. *
  2836. * NAME
  2837. * ChatAdvisement::Create
  2838. *
  2839. * DESCRIPTION
  2840. * Create a IChatEvents advisement
  2841. *
  2842. * INPUTS
  2843. * Chat - IChat object
  2844. * Sink - IChatEvents sink to advise.
  2845. *
  2846. * RESULT
  2847. * Advisement - Instance of advisement
  2848. *
  2849. ******************************************************************************/
  2850. RefPtr<ChatAdvisement> ChatAdvisement::Create(const CComPtr<WOL::IChat>& chat,
  2851. const CComPtr<WOL::IChatEvent>& sink)
  2852. {
  2853. return new ChatAdvisement(chat, sink);
  2854. }
  2855. /******************************************************************************
  2856. *
  2857. * NAME
  2858. * ChatAdvisement::ChatAdvisement
  2859. *
  2860. * DESCRIPTION
  2861. * Constructor
  2862. *
  2863. * INPUTS
  2864. * Chat - IChat object
  2865. * Sink - IChatEvents sink to advise.
  2866. *
  2867. * RESULT
  2868. * NONE
  2869. *
  2870. ******************************************************************************/
  2871. ChatAdvisement::ChatAdvisement(const CComPtr<WOL::IChat>& chat, const CComPtr<WOL::IChatEvent>& sink) :
  2872. mChat(chat),
  2873. mChatCookie(0)
  2874. {
  2875. if (mChat && sink)
  2876. {
  2877. AtlAdvise(mChat, sink, WOL::IID_IChatEvent, &mChatCookie);
  2878. }
  2879. }
  2880. /******************************************************************************
  2881. *
  2882. * NAME
  2883. * ChatAdvisement::~ChatAdvisement
  2884. *
  2885. * DESCRIPTION
  2886. * Destructor
  2887. *
  2888. * INPUTS
  2889. * NONE
  2890. *
  2891. * RESULT
  2892. * NONE
  2893. *
  2894. ******************************************************************************/
  2895. ChatAdvisement::~ChatAdvisement()
  2896. {
  2897. if (mChat)
  2898. {
  2899. AtlUnadvise(mChat, WOL::IID_IChatEvent, mChatCookie);
  2900. }
  2901. }
  2902. } // namespace WWOnline