LobbyDB_PostgreSQLTest.cpp 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. // Common includes
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "Kbhit.h"
  14. #include "GetTime.h"
  15. #include "FunctionThread.h"
  16. #include "LobbyDB_PostgreSQL.h"
  17. #include "EpochTimeToString.h"
  18. #ifdef _WIN32
  19. #include <windows.h> // Sleep
  20. #else
  21. #include <unistd.h> // usleep
  22. #endif
  23. // localtime
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <time.h>
  27. // Database queries are asynchronous so the results are read in Functor::HandleResult. The default implementation passes it to a callback
  28. class DBResultHandler : public LobbyDBCBInterface
  29. {
  30. virtual void CreateUser_CB(CreateUser_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  31. {
  32. if (wasCancelled)
  33. printf("CreateUser call canceled:\n");
  34. else if (callResult->dbQuerySuccess==false)
  35. {
  36. printf("CreateUser call DB failure:\n");
  37. printf("%s", callResult->lobbyServer->GetLastError());
  38. }
  39. else
  40. {
  41. printf("CreateUser result:\n");
  42. RakNet::RakString queryResultString;
  43. printf("[out] queryOK=%i\n", callResult->queryOK);
  44. printf("[out] queryResultString=%s\n", callResult->queryResultString.C_String());
  45. }
  46. printf("\n");
  47. }
  48. virtual void GetUser_CB(GetUser_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  49. {
  50. if (wasCancelled)
  51. printf("GetUser call canceled:\n");
  52. else if (callResult->dbQuerySuccess==false)
  53. {
  54. printf("GetUser call DB failure:\n");
  55. printf("%s", callResult->lobbyServer->GetLastError());
  56. }
  57. else if (callResult->userFound==false)
  58. {
  59. printf("GetUser call did not find specified user.\n");
  60. }
  61. else
  62. {
  63. printf("GetUser result:\n");
  64. printf("[out] isBanned=%i\n", callResult->isBanned);
  65. printf("[out] isSuspended=%i\n", callResult->isSuspended);
  66. printf("[out] suspensionExpiration=%s\n", EpochTimeToString(callResult->suspensionExpiration));
  67. printf("[out] banOrSuspensionReason=%s\n", callResult->banOrSuspensionReason.C_String());
  68. printf("[out] creationTime=%s\n", EpochTimeToString(callResult->creationTime));
  69. printf("[out] id.userId=%i\n", callResult->id.databaseRowId);
  70. printf("[out] handle=%s\n", callResult->output.handle.C_String());
  71. printf("[out] firstName=%s\n", callResult->output.firstName.C_String());
  72. printf("[out] middleName=%s\n", callResult->output.middleName.C_String());
  73. printf("[out] lastName=%s\n", callResult->output.lastName.C_String());
  74. printf("[out] race=%s\n", callResult->output.race.C_String());
  75. printf("[out] sex=%s\n", callResult->output.sex.C_String());
  76. printf("[out] homeAddress1=%s\n", callResult->output.homeAddress1.C_String());
  77. printf("[out] homeAddress2=%s\n", callResult->output.homeAddress2.C_String());
  78. printf("[out] homeCity=%s\n", callResult->output.homeCity.C_String());
  79. printf("[out] homeState=%s\n", callResult->output.homeState.C_String());
  80. printf("[out] homeProvince=%s\n", callResult->output.homeProvince.C_String());
  81. printf("[out] homeCountry=%s\n", callResult->output.homeCountry.C_String());
  82. printf("[out] homeZipCode=%s\n", callResult->output.homeZipCode.C_String());
  83. printf("[out] billingAddress1=%s\n", callResult->output.billingAddress1.C_String());
  84. printf("[out] billingAddress2=%s\n", callResult->output.billingAddress2.C_String());
  85. printf("[out] billingCity=%s\n", callResult->output.billingCity.C_String());
  86. printf("[out] billingState=%s\n", callResult->output.billingState.C_String());
  87. printf("[out] billingProvince=%s\n", callResult->output.billingProvince.C_String());
  88. printf("[out] billingCountry=%s\n", callResult->output.billingCountry.C_String());
  89. printf("[out] billingZipCode=%s\n", callResult->output.billingZipCode.C_String());
  90. printf("[out] emailAddress=%s\n", callResult->output.emailAddress.C_String());
  91. printf("[out] password=%s\n", callResult->output.password.C_String());
  92. printf("[out] passwordRecoveryQuestion=%s\n", callResult->output.passwordRecoveryQuestion.C_String());
  93. printf("[out] passwordRecoveryAnswer=%s\n", callResult->output.passwordRecoveryAnswer.C_String());
  94. printf("[out] caption1=%s\n", callResult->output.caption1.C_String());
  95. printf("[out] caption2=%s\n", callResult->output.caption2.C_String());
  96. printf("[out] caption3=%s\n", callResult->output.caption3.C_String());
  97. printf("[out] dateOfBirth=%s\n", callResult->output.dateOfBirth.C_String());
  98. printf("[out] accountNumber=%i\n", callResult->output.accountNumber);
  99. printf("[out] creditCardNumber=%s\n", callResult->output.creditCardNumber.C_String());
  100. printf("[out] creditCardExpiration=%s\n", callResult->output.creditCardExpiration.C_String());
  101. printf("[out] creditCardCVV=%s\n", callResult->output.creditCardCVV.C_String());
  102. printf("[out] adminLevel=%s\n", callResult->output.adminLevel.C_String());
  103. printf("[out] permissions=%s\n", callResult->output.permissions.C_String());
  104. printf("[out] accountBalance=%f\n", callResult->output.accountBalance);
  105. printf("[out] sourceIPAddress=%s\n", callResult->output.sourceIPAddress.C_String());
  106. printf("[out] binaryDataLength=%i\n", callResult->output.binaryDataLength);
  107. }
  108. printf("\n");
  109. }
  110. virtual void UpdateUser_CB(UpdateUser_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  111. {
  112. if (wasCancelled)
  113. printf("UpdateUser call canceled:\n");
  114. else if (callResult->dbQuerySuccess==false)
  115. {
  116. printf("UpdateUser call DB failure:\n");
  117. printf("%s", callResult->lobbyServer->GetLastError());
  118. }
  119. else
  120. {
  121. printf("UpdateUser Done.");
  122. }
  123. printf("\n");
  124. }
  125. virtual void DeleteUser_CB(DeleteUser_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  126. {
  127. if (wasCancelled)
  128. printf("DeleteUser call canceled:\n");
  129. else if (callResult->dbQuerySuccess==false)
  130. {
  131. printf("DeleteUser call DB failure:\n");
  132. printf("%s", callResult->lobbyServer->GetLastError());
  133. }
  134. else
  135. {
  136. printf("DeleteUser Done.");
  137. }
  138. printf("\n");
  139. }
  140. virtual void ChangeUserHandle_CB(ChangeUserHandle_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  141. {
  142. if (wasCancelled)
  143. printf("ChangeUserHandle call canceled:\n");
  144. else if (callResult->dbQuerySuccess==false)
  145. {
  146. printf("ChangeUserHandle call DB failure:\n");
  147. printf("%s", callResult->lobbyServer->GetLastError());
  148. }
  149. else if (callResult->success==false)
  150. {
  151. printf("ChangeUserHandle failed: %s.", callResult->queryResult.C_String());
  152. }
  153. else
  154. {
  155. printf("ChangeUserHandle Done.");
  156. }
  157. printf("\n");
  158. }
  159. virtual void AddAccountNote_CB(AddAccountNote_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  160. {
  161. if (wasCancelled)
  162. printf("AddAccountNote call canceled:\n");
  163. else if (callResult->userFound==false)
  164. {
  165. printf("AddAccountNote call user not found:\n");
  166. }
  167. else if (callResult->dbQuerySuccess==false)
  168. {
  169. printf("AddAccountNote call DB failure:\n");
  170. printf("%s", callResult->lobbyServer->GetLastError());
  171. }
  172. else
  173. {
  174. printf("AddAccountNote Done.");
  175. }
  176. printf("\n");
  177. }
  178. virtual void GetAccountNotes_CB(GetAccountNotes_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  179. {
  180. if (wasCancelled)
  181. printf("GetAccountNotes call canceled:\n");
  182. else if (callResult->dbQuerySuccess==false)
  183. {
  184. printf("GetAccountNotes call DB failure:\n");
  185. printf("%s", callResult->lobbyServer->GetLastError());
  186. }
  187. else
  188. {
  189. if (callResult->accountNotes.Size()>0)
  190. {
  191. printf("GetAccountNotes Result:\n");
  192. unsigned i;
  193. for (i=0; i < callResult->accountNotes.Size(); i++)
  194. {
  195. printf("%i. moderatorId=%i\n", i+1, callResult->accountNotes[i]->moderatorId);
  196. printf("%i. moderatorUsername=%s\n", i+1, callResult->accountNotes[i]->moderatorUsername.C_String());
  197. printf("%i. type=%s\n", i+1, callResult->accountNotes[i]->type.C_String());
  198. printf("%i. subject=%s\n", i+1, callResult->accountNotes[i]->subject.C_String());
  199. printf("%i. body=%s\n", i+1, callResult->accountNotes[i]->body.C_String());
  200. printf("%i. creationTime=%s\n", i+1, EpochTimeToString(callResult->accountNotes[i]->time));
  201. }
  202. }
  203. else
  204. {
  205. printf("GetAccountNotes: No records found");
  206. }
  207. }
  208. printf("\n");
  209. }
  210. virtual void AddFriend_CB(AddFriend_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  211. {
  212. if (wasCancelled)
  213. printf("AddFriend call canceled:\n");
  214. else if (callResult->success==false)
  215. {
  216. printf("AddFriend failed: %s.\n", callResult->queryResult.C_String());
  217. }
  218. else if (callResult->dbQuerySuccess==false)
  219. {
  220. printf("AddFriend call DB failure:\n");
  221. printf("%s", callResult->lobbyServer->GetLastError());
  222. }
  223. else
  224. {
  225. printf("AddFriend success.\n");
  226. }
  227. printf("\n");
  228. }
  229. virtual void RemoveFriend_CB(RemoveFriend_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  230. {
  231. if (wasCancelled)
  232. printf("RemoveFriend call canceled:\n");
  233. else if (callResult->dbQuerySuccess==false)
  234. {
  235. printf("RemoveFriend call DB failure:\n");
  236. printf("%s", callResult->lobbyServer->GetLastError());
  237. }
  238. else
  239. {
  240. printf("RemoveFriend success.\n");
  241. }
  242. printf("\n");
  243. }
  244. virtual void GetFriends_CB(GetFriends_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  245. {
  246. if (wasCancelled)
  247. printf("GetFriends call canceled:\n");
  248. else if (callResult->dbQuerySuccess==false)
  249. {
  250. printf("GetFriends call DB failure:\n");
  251. printf("%s", callResult->lobbyServer->GetLastError());
  252. }
  253. else
  254. {
  255. if (callResult->friends.Size()>0)
  256. {
  257. printf("GetFriends Result:\n");
  258. unsigned i;
  259. for (i=0; i < callResult->friends.Size(); i++)
  260. {
  261. printf("%i. yourId=%i\n", i+1, callResult->friends[i]->id.databaseRowId);
  262. printf("%i. yourUsername=%s\n", i+1, callResult->friends[i]->id.handle.C_String());
  263. printf("%i. friendId=%i\n", i+1, callResult->friends[i]->friendId.databaseRowId);
  264. printf("%i. friendUsername=%s\n", i+1, callResult->friends[i]->friendId.handle.C_String());
  265. printf("%i. creationTime=%s\n", i+1, EpochTimeToString(callResult->friends[i]->creationTime));
  266. }
  267. }
  268. else
  269. {
  270. printf("GetFriends: No records found");
  271. }
  272. }
  273. printf("\n");
  274. }
  275. virtual void AddToIgnoreList_CB(AddToIgnoreList_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  276. {
  277. if (wasCancelled)
  278. {
  279. printf("AddToIgnoreList call canceled.");
  280. }
  281. else if (callResult->success==false)
  282. {
  283. printf("AddToIgnoreList failed: %s.\n", callResult->queryResult.C_String());
  284. }
  285. else if (callResult->dbQuerySuccess==false)
  286. {
  287. printf("AddToIgnoreList call DB failure.\n");
  288. printf("%s", callResult->lobbyServer->GetLastError());
  289. }
  290. else
  291. {
  292. printf("AddToIgnoreList success.");
  293. }
  294. printf("\n");
  295. }
  296. virtual void RemoveFromIgnoreList_CB(RemoveFromIgnoreList_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  297. {
  298. if (wasCancelled)
  299. printf("RemoveFromIgnoreList call canceled:\n");
  300. else if (callResult->dbQuerySuccess==false)
  301. {
  302. printf("RemoveFromIgnoreList call DB failure:\n");
  303. printf("%s", callResult->lobbyServer->GetLastError());
  304. }
  305. else
  306. {
  307. printf("RemoveFromIgnoreList success.\n");
  308. }
  309. printf("\n");
  310. }
  311. virtual void GetIgnoreList_CB(GetIgnoreList_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  312. {
  313. if (wasCancelled)
  314. printf("GetIgnoreList call canceled:\n");
  315. else if (callResult->dbQuerySuccess==false)
  316. {
  317. printf("GetIgnoreList call DB failure:\n");
  318. printf("%s", callResult->lobbyServer->GetLastError());
  319. }
  320. else
  321. {
  322. if (callResult->ignoredUsers.Size()>0)
  323. {
  324. printf("GetIgnoreList Result:\n");
  325. unsigned i;
  326. for (i=0; i < callResult->ignoredUsers.Size(); i++)
  327. {
  328. printf("%i. yourId=%i\n", i+1, callResult->ignoredUsers[i]->id.databaseRowId);
  329. printf("%i. yourUsername=%s\n", i+1, callResult->ignoredUsers[i]->id.handle.C_String());
  330. printf("%i. ignoredUser.id=%i\n", i+1, callResult->ignoredUsers[i]->ignoredUser.databaseRowId);
  331. printf("%i. ignoredUser.userHandle=%s\n", i+1, callResult->ignoredUsers[i]->ignoredUser.handle.C_String());
  332. printf("%i. creationTime=%s\n", i+1, EpochTimeToString(callResult->ignoredUsers[i]->creationTime));
  333. }
  334. }
  335. else
  336. {
  337. printf("GetIgnoreList: No records found");
  338. }
  339. }
  340. printf("\n");
  341. }
  342. virtual void SendEmail_CB(SendEmail_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  343. {
  344. if (wasCancelled)
  345. printf("SendEmail call canceled:\n");
  346. else if (callResult->validParameters==false)
  347. {
  348. printf("SendEmail invalid parameters:\n");
  349. printf("%s", callResult->failureMessage.C_String());
  350. }
  351. else if (callResult->dbQuerySuccess==false)
  352. {
  353. printf("SendEmail call DB failure:\n");
  354. printf("%s", callResult->lobbyServer->GetLastError());
  355. }
  356. else
  357. {
  358. printf("SendEmail success");
  359. }
  360. printf("\n");
  361. }
  362. virtual void GetEmails_CB(GetEmails_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  363. {
  364. if (wasCancelled)
  365. printf("GetEmails_CB call canceled:\n");
  366. else if (callResult->validParameters==false)
  367. {
  368. printf("GetEmails invalid parameters:\n");
  369. printf("%s", callResult->failureMessage.C_String());
  370. }
  371. else if (callResult->dbQuerySuccess==false)
  372. {
  373. printf("GetEmails_CB call DB failure:\n");
  374. printf("%s", callResult->lobbyServer->GetLastError());
  375. }
  376. else
  377. {
  378. printf("GetEmails success\n");
  379. printf("inbox=%i\n", callResult->inbox);
  380. unsigned i;
  381. for (i=0; i < callResult->emails.Size(); i++)
  382. {
  383. printf("%i. id.userId=%i\n", i+1, callResult->emails[i]->id.databaseRowId);
  384. printf("%i. id.userHandle=%s\n", i+1, callResult->emails[i]->id.handle.C_String());
  385. printf("%i. emailMessageID=%i\n", i+1, callResult->emails[i]->emailMessageID);
  386. printf("%i. subject=%s\n", i+1, callResult->emails[i]->subject.C_String());
  387. printf("%i. body=%s\n", i+1, callResult->emails[i]->body.C_String());
  388. printf("%i. creationTime=%s\n", i+1, EpochTimeToString(callResult->emails[i]->creationTime));
  389. printf("%i. status=%i\n", i+1, callResult->emails[i]->status);
  390. printf("%i. attachmentLength=%i\n", i+1, callResult->emails[i]->attachmentLength);
  391. }
  392. }
  393. printf("\n");
  394. }
  395. virtual void DeleteEmail_CB(DeleteEmail_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  396. {
  397. if (wasCancelled)
  398. printf("DeleteEmail_CB call canceled:\n");
  399. else if (callResult->dbQuerySuccess==false)
  400. {
  401. printf("DeleteEmail_CB call DB failure:\n");
  402. printf("%s", callResult->lobbyServer->GetLastError());
  403. }
  404. else
  405. {
  406. printf("DeleteEmail success\n");
  407. }
  408. printf("\n");
  409. }
  410. virtual void UpdateEmailStatus_CB(UpdateEmailStatus_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  411. {
  412. if (wasCancelled)
  413. printf("UpdateEmailStatus_CB call canceled:\n");
  414. else if (callResult->dbQuerySuccess==false)
  415. {
  416. printf("UpdateEmailStatus_CB call DB failure:\n");
  417. printf("%s", callResult->lobbyServer->GetLastError());
  418. }
  419. else
  420. {
  421. printf("UpdateEmailStatus success\n");
  422. }
  423. printf("\n");
  424. }
  425. virtual void GetHandleFromUserId_CB(GetHandleFromUserId_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  426. {
  427. if (wasCancelled)
  428. printf("GetHandleFromUserId_CB call canceled:\n");
  429. else if (callResult->dbQuerySuccess==false)
  430. {
  431. printf("GetHandleFromUserId_CB call DB failure:\n");
  432. printf("%s", callResult->lobbyServer->GetLastError());
  433. }
  434. else if (callResult->success==false)
  435. {
  436. printf("GetHandleFromUserId_CB lookup failure:\n");
  437. }
  438. else
  439. {
  440. printf("GetHandleFromUserId_CB success\n");
  441. printf("[in] userId=%i\n", callResult->userId);
  442. printf("[out] handle=%s", callResult->handle.C_String());
  443. }
  444. printf("\n");
  445. }
  446. virtual void GetUserIdFromHandle_CB(GetUserIdFromHandle_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  447. {
  448. if (wasCancelled)
  449. printf("GetUserIdFromHandle_CB call canceled.");
  450. else if (callResult->dbQuerySuccess==false)
  451. {
  452. printf("GetUserIdFromHandle_CB call DB failure.");
  453. printf("%s", callResult->lobbyServer->GetLastError());
  454. }
  455. else if (callResult->success==false)
  456. {
  457. printf("GetUserIdFromHandle_CB lookup failure.");
  458. }
  459. else
  460. {
  461. printf("GetUserIdFromHandle_CB success\n");
  462. printf("[in] handle=%s\n", callResult->handle.C_String());
  463. printf("[out] userId=%i", callResult->userId);
  464. }
  465. printf("\n");
  466. }
  467. virtual void AddDisallowedHandle_CB(AddDisallowedHandle_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  468. {
  469. if (wasCancelled)
  470. printf("AddDisallowedHandle_CB call canceled:\n");
  471. else if (callResult->dbQuerySuccess==false)
  472. {
  473. printf("AddDisallowedHandle_CB call DB failure:\n");
  474. printf("%s", callResult->lobbyServer->GetLastError());
  475. }
  476. else
  477. {
  478. printf("AddDisallowedHandle_CB Done.");
  479. }
  480. printf("\n");
  481. }
  482. virtual void RemoveDisallowedHandle_CB(RemoveDisallowedHandle_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  483. {
  484. if (wasCancelled)
  485. printf("RemoveDisallowedHandle_CB call canceled:\n");
  486. else if (callResult->dbQuerySuccess==false)
  487. {
  488. printf("RemoveDisallowedHandle_CB call DB failure:\n");
  489. printf("%s", callResult->lobbyServer->GetLastError());
  490. }
  491. else
  492. {
  493. printf("RemoveDisallowedHandle_CB Done.");
  494. }
  495. printf("\n");
  496. }
  497. virtual void IsDisallowedHandle_CB(IsDisallowedHandle_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  498. {
  499. if (wasCancelled)
  500. printf("IsDisallowedHandle_CB call canceled:\n");
  501. else if (callResult->dbQuerySuccess==false)
  502. {
  503. printf("IsDisallowedHandle_CB call DB failure:\n");
  504. printf("%s", callResult->lobbyServer->GetLastError());
  505. }
  506. else
  507. {
  508. printf("IsDisallowedHandle_CB Done.\n");
  509. printf("exists=%i", callResult->exists);
  510. }
  511. printf("\n");
  512. }
  513. virtual void AddToActionHistory_CB(AddToActionHistory_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  514. {
  515. if (wasCancelled)
  516. printf("AddToActionHistory_CB call canceled:\n");
  517. else if (callResult->dbQuerySuccess==false)
  518. {
  519. printf("AddToActionHistory_CB call DB failure:\n");
  520. printf("%s", callResult->lobbyServer->GetLastError());
  521. }
  522. else
  523. {
  524. printf("AddToActionHistory_CB Done.\n");
  525. }
  526. printf("\n");
  527. }
  528. virtual void GetActionHistory_CB(GetActionHistory_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  529. {
  530. if (wasCancelled)
  531. printf("GetActionHistory_CB call canceled:\n");
  532. else if (callResult->dbQuerySuccess==false)
  533. {
  534. printf("GetActionHistory_CB call DB failure:\n");
  535. printf("%s", callResult->lobbyServer->GetLastError());
  536. }
  537. else
  538. {
  539. printf("GetActionHistory_CB Done.\n");
  540. }
  541. printf("\n");
  542. unsigned i;
  543. for (i=0; i < callResult->history.Size(); i++)
  544. {
  545. printf("%i. id.userId=%i\n", i+1, callResult->history[i]->id.databaseRowId);
  546. printf("%i. id.userHandle=%s\n", i+1, callResult->history[i]->id.handle.C_String());
  547. printf("%i. actionTime=%s\n", i+1, callResult->history[i]->actionTime);
  548. printf("%i. actionTaken=%s\n", i+1, callResult->history[i]->actionTaken.C_String());
  549. printf("%i. description=%s\n", i+1, callResult->history[i]->description.C_String());
  550. printf("%i. sourceIpAddress=%s\n", i+1, callResult->history[i]->sourceIpAddress.C_String());
  551. printf("%i. creationTime=%s\n", i+1, EpochTimeToString(callResult->history[i]->creationTime));
  552. }
  553. }
  554. // CLANS
  555. virtual void UpdateClanMember_CB(UpdateClanMember_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  556. {
  557. if (wasCancelled)
  558. printf("UpdateClanMember_CB call canceled:\n");
  559. else if (callResult->dbQuerySuccess==false)
  560. {
  561. printf("UpdateClanMember_CB call DB failure:\n");
  562. printf("%s", callResult->lobbyServer->GetLastError());
  563. }
  564. else if (callResult->failureMessage.IsEmpty()==false)
  565. {
  566. printf("UpdateClanMember_CB general failure:\n");
  567. printf("%s", callResult->failureMessage.C_String());
  568. }
  569. else
  570. {
  571. printf("UpdateClanMember_CB Done.\n");
  572. }
  573. printf("\n");
  574. }
  575. virtual void UpdateClan_CB(UpdateClan_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  576. {
  577. if (wasCancelled)
  578. printf("UpdateClan_CB call canceled:\n");
  579. else if (callResult->dbQuerySuccess==false)
  580. {
  581. printf("UpdateClan_CB call DB failure:\n");
  582. printf("%s", callResult->lobbyServer->GetLastError());
  583. }
  584. else if (callResult->failureMessage.IsEmpty()==false)
  585. {
  586. printf("UpdateClan_CB general failure:\n");
  587. printf("%s", callResult->failureMessage.C_String());
  588. }
  589. else
  590. {
  591. printf("UpdateClan_CB Done.\n");
  592. }
  593. printf("\n");
  594. }
  595. virtual void CreateClan_CB(CreateClan_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  596. {
  597. if (wasCancelled)
  598. printf("CreateClan_CB call canceled:\n");
  599. else if (callResult->dbQuerySuccess==false)
  600. {
  601. printf("CreateClan_CB call DB failure:\n");
  602. printf("%s\n", callResult->lobbyServer->GetLastError());
  603. printf("%s\n", callResult->initialClanData.failureMessage.C_String());
  604. printf("%s", callResult->leaderData.failureMessage.C_String());
  605. }
  606. else if (callResult->initialClanData.failureMessage.IsEmpty()==false || callResult->leaderData.failureMessage.IsEmpty()==false )
  607. {
  608. printf("CreateClan_CB general failure:\n");
  609. printf("%s\n", callResult->initialClanData.failureMessage.C_String());
  610. printf("%s", callResult->leaderData.failureMessage.C_String());
  611. }
  612. else
  613. {
  614. printf("CreateClan_CB Done. New clan ID = %i\n", callResult->initialClanData.clanId.databaseRowId);
  615. }
  616. printf("\n");
  617. }
  618. virtual void ChangeClanHandle_CB(ChangeClanHandle_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  619. {
  620. if (wasCancelled)
  621. printf("ChangeClanHandle_CB call canceled:\n");
  622. else if (callResult->dbQuerySuccess==false)
  623. {
  624. printf("ChangeClanHandle_CB call DB failure:\n");
  625. printf("%s\n", callResult->lobbyServer->GetLastError());
  626. }
  627. else if (callResult->failureMessage.IsEmpty()==false)
  628. {
  629. printf("ChangeClanHandle_CB general failure:\n");
  630. printf("%s\n", callResult->failureMessage.C_String());
  631. }
  632. else
  633. {
  634. printf("ChangeClanHandle_CB Done.");
  635. }
  636. printf("\n");
  637. }
  638. virtual void DeleteClan_CB(DeleteClan_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  639. {
  640. if (wasCancelled)
  641. printf("DeleteClan_CB call canceled:\n");
  642. else if (callResult->dbQuerySuccess==false)
  643. {
  644. printf("DeleteClan_CB call DB failure:\n");
  645. printf("%s\n", callResult->lobbyServer->GetLastError());
  646. }
  647. else
  648. {
  649. printf("DeleteClan_CB Done.");
  650. }
  651. printf("\n");
  652. }
  653. virtual void GetClans_CB(GetClans_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  654. {
  655. if (wasCancelled)
  656. printf("GetClans_CB call canceled:\n");
  657. else if (callResult->dbQuerySuccess==false)
  658. {
  659. printf("GetClans_CB call DB failure:\n");
  660. printf("%s\n", callResult->lobbyServer->GetLastError());
  661. }
  662. else
  663. {
  664. unsigned clanIndex, memberIndex;
  665. LobbyDBSpec::UpdateClanMember_Data *member;
  666. LobbyDBSpec::UpdateClan_Data *clan;
  667. if (callResult->clans.Size()>0)
  668. {
  669. printf("%i CLANS FOUND for user %i\n", callResult->clans.Size(), callResult->userId.databaseRowId);
  670. for (clanIndex=0; clanIndex < callResult->clans.Size(); clanIndex++)
  671. {
  672. clan = callResult->clans[clanIndex];
  673. printf("(%i.) CLAN %s (ID=%i):\n", clanIndex+1, clan->handle.C_String(), clan->clanId.databaseRowId);
  674. printf("%i %i %i %i:\n", clan->integers[0], clan->integers[1],clan->integers[2],clan->integers[3]);
  675. printf("%.1f %.1f %.1f %.1f:\n", clan->floats[0], clan->floats[1],clan->floats[2],clan->floats[3]);
  676. printf("DESC1: %s\n", clan->descriptions[0].C_String());
  677. printf("DESC2: %s\n", clan->descriptions[1].C_String());
  678. printf("Requires invitations to join = ");
  679. if (clan->requiresInvitationsToJoin)
  680. printf("true\n");
  681. else
  682. printf("false\n");
  683. printf("Member list for clan %s:\n", clan->handle.C_String());
  684. for (memberIndex=0; memberIndex < callResult->clans[clanIndex]->members.Size(); memberIndex++)
  685. {
  686. member = clan->members[memberIndex];
  687. printf("(%i.) ", memberIndex+1);
  688. if (member->mEStatus1==LobbyDBSpec::CLAN_MEMBER_STATUS_LEADER)
  689. printf("<Leader>");
  690. else if (member->mEStatus1==LobbyDBSpec::CLAN_MEMBER_STATUS_SUBLEADER)
  691. printf("<Subleader>");
  692. else if (member->mEStatus1==LobbyDBSpec::CLAN_MEMBER_STATUS_MEMBER)
  693. printf("<Member>");
  694. else if (member->mEStatus1==LobbyDBSpec::CLAN_MEMBER_STATUS_REQUESTED_TO_JOIN)
  695. printf("<Requested>");
  696. else if (member->mEStatus1==LobbyDBSpec::CLAN_MEMBER_STATUS_INVITED_TO_JOIN)
  697. printf("<Invited>");
  698. else if (member->mEStatus1==LobbyDBSpec::CLAN_MEMBER_STATUS_BLACKLISTED)
  699. printf("<Blacklisted>");
  700. else
  701. printf("<Unknown>");
  702. printf(" %s (ID=%i)\n", member->userId.handle.C_String(), member->userId.databaseRowId);
  703. printf("%i %i %i %i:\n", member->integers[0], member->integers[1],member->integers[2],member->integers[3]);
  704. printf("%.1f %.1f %.1f %.1f:\n", member->floats[0], member->floats[1],member->floats[2],member->floats[3]);
  705. printf("DESC1: %s\n", member->descriptions[0].C_String());
  706. printf("DESC2: %s\n", member->descriptions[1].C_String());
  707. }
  708. }
  709. }
  710. else
  711. printf("No clans found");
  712. }
  713. printf("\n");
  714. }
  715. virtual void RemoveFromClan_CB(RemoveFromClan_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  716. {
  717. if (wasCancelled)
  718. printf("RemoveFromClan_CB call canceled:\n");
  719. else if (callResult->dbQuerySuccess==false)
  720. {
  721. printf("RemoveFromClan_CB call DB failure:\n");
  722. printf("%s\n", callResult->lobbyServer->GetLastError());
  723. }
  724. else
  725. {
  726. printf("RemoveFromClan_CB Done.");
  727. }
  728. printf("\n");
  729. }
  730. virtual void AddToClanBoard_CB(AddToClanBoard_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  731. {
  732. if (wasCancelled)
  733. printf("AddToClanBoard_CB call canceled:\n");
  734. else if (callResult->dbQuerySuccess==false)
  735. {
  736. printf("AddToClanBoard_CB call DB failure:\n");
  737. printf("%s\n", callResult->lobbyServer->GetLastError());
  738. }
  739. else
  740. {
  741. printf("AddToClanBoard_CB Done.");
  742. }
  743. printf("\n");
  744. }
  745. virtual void RemoveFromClanBoard_CB(RemoveFromClanBoard_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  746. {
  747. if (wasCancelled)
  748. printf("RemoveFromClanBoard_CB call canceled:\n");
  749. else if (callResult->dbQuerySuccess==false)
  750. {
  751. printf("RemoveFromClanBoard_CB call DB failure:\n");
  752. printf("%s\n", callResult->lobbyServer->GetLastError());
  753. }
  754. else
  755. {
  756. printf("RemoveFromClanBoard_CB Done.");
  757. }
  758. printf("\n");
  759. }
  760. virtual void GetClanBoard_CB(GetClanBoard_PostgreSQLImpl *callResult, bool wasCancelled, void *context)
  761. {
  762. if (wasCancelled)
  763. printf("GetClanBoard_CB call canceled:\n");
  764. else if (callResult->dbQuerySuccess==false)
  765. {
  766. printf("GetClanBoard_CB call DB failure:\n");
  767. printf("%s\n", callResult->lobbyServer->GetLastError());
  768. }
  769. else
  770. {
  771. unsigned index;
  772. LobbyDBSpec::AddToClanBoard_Data *post;
  773. if (callResult->board.Size()>0)
  774. {
  775. printf("%i POSTS FOUND\n", callResult->board.Size());
  776. for (index=0; index < callResult->board.Size(); index++)
  777. {
  778. post = callResult->board[index];
  779. printf("(%i.) Author=%s (ID=%i)\n", index+1, post->userId.handle.C_String(), post->userId.databaseRowId);
  780. printf("%i %i %i %i:\n", post->integers[0], post->integers[1],post->integers[2],post->integers[3]);
  781. printf("%.1f %.1f %.1f %.1f:\n", post->floats[0], post->floats[1],post->floats[2],post->floats[3]);
  782. printf("Subject: %s\n", post->subject.C_String());
  783. printf("Body: %s\n", post->body.C_String());
  784. }
  785. }
  786. else
  787. {
  788. printf("No posts found.");
  789. }
  790. }
  791. printf("\n");
  792. }
  793. };
  794. void main(int argc, char **argv)
  795. {
  796. printf("A sample on using the provided implementation\nof the Lobby Server specification based on PostgreSQL\n");
  797. printf("Unlike the other samples, this is a server-only\nprocess so does not involve networking with RakNet.\n");
  798. printf("The goal of this class is to allow you to save\nand retrieve users, emails, and transactions for a lobby service\n");
  799. printf("Difficulty: Intermediate\n\n");
  800. // A function thread is class that spawns a thread that operates on functors.
  801. // A functor is an instance of a class that has two pre-defined functions: One to perform processing, another to get the result.
  802. // One per application is enough to not block
  803. RakNet::FunctionThread ft;
  804. // Start one thread. Starting more than one may be advantageous for multi-core processors. However, in this scenario we are
  805. // blocking on database calls rather than processing.
  806. ft.StartThreads(1);
  807. // The real functionality of the LobbyServer is contained in the functors defined in LobbyDB_PostgreSQL.h/.cpp.
  808. // However, this class contains some utility functions and members, such as the functionThread and a pointer to
  809. // the postgreSQL interface.
  810. LobbyDB_PostgreSQL lobbyServer;
  811. // LobbyDB_PostgreSQL internally uses a functionThread so that database queries can happen asynchronously,
  812. // as opposed to blocking and slowing down the game.
  813. // If you don't assign one it will create one automatically and start it with one thread.
  814. lobbyServer.AssignFunctionThread(&ft);
  815. // The default implementation of the functors pass Functor::HandleResult through to a callback, instantiated here.
  816. // Alternatively, you could derive from the *_PostgreSQLImpl functors found in LobbyDB_PostgreSQL.h/.cpp
  817. // and override the behavior of Functor::HandleResult
  818. DBResultHandler resultHandler;
  819. lobbyServer.AssignCallback(&resultHandler);
  820. printf("Enter database password:\n");
  821. char connectionString[256],password[128];
  822. char username[256];
  823. strcpy(username, "postgres");
  824. gets(password);
  825. strcpy(connectionString, "user=");
  826. strcat(connectionString, username);
  827. strcat(connectionString, " password=");
  828. strcat(connectionString, password);
  829. // database=blah
  830. if (lobbyServer.Connect(connectionString)==false)
  831. {
  832. printf("Database connection failed.\n");
  833. return;
  834. }
  835. printf("Database connection succeeded.\n");
  836. printf("(A) Drop tables\n"
  837. "(B) Create tables.\n"
  838. "(C) Create user.\n"
  839. "(D) Get user.\n"
  840. "(E) Update user.\n"
  841. "(F) Add account note for a user.\n"
  842. "(G) Get account notes for a user.\n"
  843. "(H) Add friend.\n"
  844. "(I) Remove friend.\n"
  845. "(J) Get friends.\n"
  846. "(K) Add to ignore list.\n"
  847. "(L) Remove from ignore list.\n"
  848. "(M) Get ignore list.\n"
  849. "(O) Send email to recipient(s).\n"
  850. "(P) Get email(s).\n"
  851. "(Q) Delete email.\n"
  852. "(R) Update email status flags.\n"
  853. "(S) Get handle from user Id.\n"
  854. "(T) Get user Id from handle.\n"
  855. "(U) Delete user.\n"
  856. "(V) Change user handle.\n"
  857. "(W) Add Disallowed Handle.\n"
  858. "(X) Remove Disallowed Handle.\n"
  859. "(Y) Is Disallowed Handle.\n"
  860. "(Z) Add to user action history.\n"
  861. "(0) Get action history.\n"
  862. "(1) Add or update clan member.\n"
  863. "(2) Update clan.\n"
  864. "(3) Create clan.\n"
  865. "(4) Change clan handle.\n"
  866. "(5) Delete clan.\n"
  867. "(6) Get all clans.\n"
  868. "(7) Remove member from clan.\n"
  869. "(8) Add to clan bulletin board.\n"
  870. "(9) Remove from clan bulletin board.\n"
  871. "(!) Get clan bulletin board.\n"
  872. "(~) Quit\n");
  873. char inputStr[512];
  874. char ch;
  875. while (1)
  876. {
  877. if (kbhit())
  878. {
  879. ch=getch();
  880. if (ch=='~')
  881. break;
  882. else if (ch=='a')
  883. {
  884. if (lobbyServer.DestroyLobbyServerTables()==false)
  885. printf("%s", lobbyServer.GetLastError());
  886. else
  887. printf("Tables dropped.\n");
  888. }
  889. else if (ch=='b')
  890. {
  891. if (lobbyServer.CreateLobbyServerTables()==false)
  892. printf("%s", lobbyServer.GetLastError());
  893. else
  894. printf("Tables created.\n");
  895. }
  896. else if (ch=='c')
  897. {
  898. // We could do new and delete, but this ensures the class is allocated and deallocated in the same DLL, should we use one.
  899. // By default deallocation takes place in HandleResult()
  900. CreateUser_PostgreSQLImpl *functor = CreateUser_PostgreSQLImpl::Alloc();
  901. printf("Create a user and add him to the database\n");
  902. printf("Enter user handle: ");
  903. gets(inputStr);
  904. functor->handle = inputStr; // Test possibly blank handle
  905. // Put in test data for everything else, too many to ask the user
  906. functor->firstName = "Kevin";;
  907. functor->middleName = "M";
  908. functor->lastName = "Jenkins";
  909. functor->race = "Martian";
  910. functor->sex = "Lots";
  911. functor->homeAddress1 = "1234 Martian Lane.";
  912. functor->homeAddress2; // Test blank
  913. functor->homeCity = "Martian colony 5582";
  914. functor->homeState = "Galaxon State";
  915. functor->homeProvince;
  916. functor->homeCountry = "Galaxon Country";
  917. functor->homeZipCode = "123456";
  918. functor->billingAddress1;
  919. functor->billingAddress2;
  920. functor->billingCity;
  921. functor->billingState;
  922. functor->billingProvince;
  923. functor->billingCountry;
  924. functor->billingZipCode;
  925. functor->emailAddress = "rakkar@jenkinssoftware.com";
  926. functor->password = "123456";
  927. functor->passwordRecoveryQuestion = "What is your mom's occupation?"; // Test ' in a string
  928. functor->passwordRecoveryAnswer = "Unemployed";
  929. functor->caption1 = "caption1";
  930. functor->caption2;
  931. functor->caption3 = "%s"; // Test formatting chars
  932. functor->dateOfBirth = "01/01/0001";
  933. functor->accountNumber;
  934. functor->creditCardNumber;
  935. functor->creditCardExpiration;
  936. functor->creditCardCVV;
  937. functor->adminLevel = "God";
  938. functor->permissions = "Omniscient | MORE";
  939. functor->accountBalance;
  940. functor->sourceIPAddress = "127.0.0.1";
  941. functor->binaryData = CreateUser_PostgreSQLImpl::AllocBytes(3);
  942. functor->binaryData[0]='B';
  943. functor->binaryData[1]='D';
  944. functor->binaryData[2]=0;
  945. functor->binaryDataLength = 3;
  946. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  947. lobbyServer.PushFunctor(functor,0);
  948. }
  949. else if (ch=='d')
  950. {
  951. GetUser_PostgreSQLImpl *functor = GetUser_PostgreSQLImpl::Alloc();
  952. printf("Gets info on a user by ID (faster) or handle (slower).\n");
  953. printf("Enter user ID? (y/n): ");
  954. gets(inputStr);
  955. if (inputStr[0]=='y')
  956. {
  957. printf("Enter user ID (integer): ");
  958. gets(inputStr);
  959. functor->id.hasDatabaseRowId=true;
  960. functor->id.databaseRowId=atoi(inputStr);
  961. }
  962. else
  963. {
  964. printf("Enter user handle: ");
  965. gets(inputStr);
  966. functor->id.hasDatabaseRowId=false;
  967. functor->id.handle=inputStr;
  968. }
  969. functor->getCCInfo=true;
  970. functor->getBinaryData=true;
  971. functor->getPersonalInfo=true;
  972. functor->getEmailAddr=true;
  973. functor->getPassword=true;
  974. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  975. lobbyServer.PushFunctor(functor,0);
  976. }
  977. else if (ch=='e')
  978. {
  979. UpdateUser_PostgreSQLImpl *functor = UpdateUser_PostgreSQLImpl::Alloc();
  980. printf("Updates database info for part of all of a user.\nSpecify user by ID (faster) or handle (slower).\n");
  981. printf("Enter user ID? (y/n): ");
  982. gets(inputStr);
  983. if (inputStr[0]=='y')
  984. {
  985. printf("Enter user ID (integer): ");
  986. gets(inputStr);
  987. functor->id.hasDatabaseRowId=true;
  988. functor->id.databaseRowId=atoi(inputStr);
  989. }
  990. else
  991. {
  992. printf("Enter user handle: ");
  993. gets(inputStr);
  994. functor->id.hasDatabaseRowId=false;
  995. functor->id.handle=inputStr;
  996. }
  997. functor->updateCCInfo=true;
  998. functor->updateBinaryData=true;
  999. functor->updatePersonalInfo=true;
  1000. functor->updateEmailAddr=true;
  1001. functor->updatePassword=true;
  1002. functor->updateCaptions=true;
  1003. functor->updateOtherInfo=true;
  1004. // Put in test data for everything else, too many to ask the user
  1005. functor->input.firstName = "Kevin (updated)";;
  1006. functor->input.middleName = "M (updated)";
  1007. functor->input.lastName = "Jenkins (updated)";
  1008. functor->input.race = "Martian (updated)";
  1009. functor->input.sex = "Lots (updated)";
  1010. functor->input.homeAddress1 = "1234 Martian Lane. (updated)";
  1011. functor->input.homeCity = "Martian colony 5582 (updated)";
  1012. functor->input.homeState = "Galaxon State (updated)";
  1013. functor->input.homeCountry = "Galaxon Country (updated)";
  1014. functor->input.homeZipCode = "123456 (updated)";
  1015. functor->input.emailAddress = "rakkar@jenkinssoftware.com (updated)";
  1016. functor->input.password = "123456 (updated)";
  1017. functor->input.passwordRecoveryQuestion = "What is your mom's occupation? (updated)"; // Test ' in a string
  1018. functor->input.passwordRecoveryAnswer = "Unemployed (updated)";
  1019. functor->input.caption1 = "caption1 (updated)";
  1020. functor->input.caption3 = "%s (updated)"; // Test formatting chars
  1021. functor->input.dateOfBirth = "01/01/0001 (updated)";
  1022. functor->input.adminLevel = "God (updated)";
  1023. functor->input.permissions = "Omniscient | MORE (updated)";
  1024. functor->input.sourceIPAddress = "127.0.0.1 (updated)";
  1025. functor->input.binaryData = UpdateUser_PostgreSQLImpl::AllocBytes(3);
  1026. functor->input.binaryData[0]='U';
  1027. functor->input.binaryData[1]='P';
  1028. functor->input.binaryData[2]=0;
  1029. functor->input.binaryDataLength = 3;
  1030. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1031. lobbyServer.PushFunctor(functor,0);
  1032. }
  1033. else if (ch=='f')
  1034. {
  1035. AddAccountNote_PostgreSQLImpl *functor = AddAccountNote_PostgreSQLImpl::Alloc();
  1036. printf("Adds a note to a user's account.\nSpecify user by ID (faster) or handle (slower).\n");
  1037. printf("Enter user ID? (y/n): ");
  1038. gets(inputStr);
  1039. if (inputStr[0]=='y')
  1040. {
  1041. printf("Enter user ID (integer): ");
  1042. gets(inputStr);
  1043. functor->id.hasDatabaseRowId=true;
  1044. functor->id.databaseRowId=atoi(inputStr);
  1045. }
  1046. else
  1047. {
  1048. printf("Enter user handle: ");
  1049. gets(inputStr);
  1050. functor->id.hasDatabaseRowId=false;
  1051. functor->id.handle=inputStr;
  1052. }
  1053. functor->writeModeratorId=true;
  1054. functor->moderatorId=1234;
  1055. functor->moderatorUsername="moderator username";
  1056. functor->type="account note type";
  1057. functor->subject="account subject";
  1058. functor->body="account body";
  1059. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1060. lobbyServer.PushFunctor(functor,0);
  1061. }
  1062. else if (ch=='g')
  1063. {
  1064. GetAccountNotes_PostgreSQLImpl *functor = GetAccountNotes_PostgreSQLImpl::Alloc();
  1065. printf("Gets all notes for a user.\nSpecify user by ID (faster) or handle (slower).\n");
  1066. printf("Enter user ID? (y/n): ");
  1067. gets(inputStr);
  1068. if (inputStr[0]=='y')
  1069. {
  1070. printf("Enter user ID (integer): ");
  1071. gets(inputStr);
  1072. functor->id.hasDatabaseRowId=true;
  1073. functor->id.databaseRowId=atoi(inputStr);
  1074. }
  1075. else
  1076. {
  1077. printf("Enter user handle: ");
  1078. gets(inputStr);
  1079. functor->id.hasDatabaseRowId=false;
  1080. functor->id.handle=inputStr;
  1081. }
  1082. printf("Ascending sort? (y/n): ");
  1083. gets(inputStr);
  1084. if (inputStr[0]=='y')
  1085. functor->ascendingSort=true;
  1086. else
  1087. functor->ascendingSort=false;
  1088. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1089. lobbyServer.PushFunctor(functor,0);
  1090. }
  1091. else if (ch=='h')
  1092. {
  1093. AddFriend_PostgreSQLImpl *functor = AddFriend_PostgreSQLImpl::Alloc();
  1094. printf("Adds a friend for a user.\nSpecify user by ID (faster) or handle (slower).\n");
  1095. printf("Enter user ID? (y/n): ");
  1096. gets(inputStr);
  1097. if (inputStr[0]=='y')
  1098. {
  1099. printf("Enter user ID (integer): ");
  1100. gets(inputStr);
  1101. functor->id.hasDatabaseRowId=true;
  1102. functor->id.databaseRowId=atoi(inputStr);
  1103. }
  1104. else
  1105. {
  1106. printf("Enter user handle: ");
  1107. gets(inputStr);
  1108. functor->id.hasDatabaseRowId=false;
  1109. functor->id.handle=inputStr;
  1110. }
  1111. printf("Enter friend ID? (y/n): ");
  1112. gets(inputStr);
  1113. if (inputStr[0]=='y')
  1114. {
  1115. printf("Enter friend ID (integer): ");
  1116. gets(inputStr);
  1117. functor->friendId.hasDatabaseRowId=true;
  1118. functor->friendId.databaseRowId=atoi(inputStr);
  1119. }
  1120. else
  1121. {
  1122. printf("Enter friend handle: ");
  1123. gets(inputStr);
  1124. functor->friendId.hasDatabaseRowId=false;
  1125. functor->friendId.handle=inputStr;
  1126. }
  1127. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1128. lobbyServer.PushFunctor(functor,0);
  1129. }
  1130. else if (ch=='i')
  1131. {
  1132. RemoveFriend_PostgreSQLImpl *functor = RemoveFriend_PostgreSQLImpl::Alloc();
  1133. printf("Removes a friend for a user.\nSpecify user by ID (faster) or handle (slower).\n");
  1134. printf("Enter user ID? (y/n): ");
  1135. gets(inputStr);
  1136. if (inputStr[0]=='y')
  1137. {
  1138. printf("Enter user ID (integer): ");
  1139. gets(inputStr);
  1140. functor->removeFriendInput.id.hasDatabaseRowId=true;
  1141. functor->removeFriendInput.id.databaseRowId=atoi(inputStr);
  1142. }
  1143. else
  1144. {
  1145. printf("Enter user handle: ");
  1146. gets(inputStr);
  1147. functor->removeFriendInput.id.hasDatabaseRowId=false;
  1148. functor->removeFriendInput.id.handle=inputStr;
  1149. }
  1150. printf("Enter friend ID? (y/n): ");
  1151. gets(inputStr);
  1152. if (inputStr[0]=='y')
  1153. {
  1154. printf("Enter friend ID (integer): ");
  1155. gets(inputStr);
  1156. functor->removeFriendInput.friendId.hasDatabaseRowId=true;
  1157. functor->removeFriendInput.friendId.databaseRowId=atoi(inputStr);
  1158. }
  1159. else
  1160. {
  1161. printf("Enter friend handle: ");
  1162. gets(inputStr);
  1163. functor->removeFriendInput.friendId.hasDatabaseRowId=false;
  1164. functor->removeFriendInput.friendId.handle=inputStr;
  1165. }
  1166. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1167. lobbyServer.PushFunctor(functor,0);
  1168. }
  1169. else if (ch=='j')
  1170. {
  1171. GetFriends_PostgreSQLImpl *functor = GetFriends_PostgreSQLImpl::Alloc();
  1172. printf("Gets the list of friends for a user.\nSpecify user by ID (faster) or handle (slower).\n");
  1173. printf("Enter user ID? (y/n): ");
  1174. gets(inputStr);
  1175. if (inputStr[0]=='y')
  1176. {
  1177. printf("Enter user ID (integer): ");
  1178. gets(inputStr);
  1179. functor->id.hasDatabaseRowId=true;
  1180. functor->id.databaseRowId=atoi(inputStr);
  1181. }
  1182. else
  1183. {
  1184. printf("Enter user handle: ");
  1185. gets(inputStr);
  1186. functor->id.hasDatabaseRowId=false;
  1187. functor->id.handle=inputStr;
  1188. }
  1189. printf("Ascending sort? (y/n): ");
  1190. gets(inputStr);
  1191. if (inputStr[0]=='y')
  1192. functor->ascendingSort=true;
  1193. else
  1194. functor->ascendingSort=false;
  1195. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1196. lobbyServer.PushFunctor(functor,0);
  1197. }
  1198. else if (ch=='k')
  1199. {
  1200. AddToIgnoreList_PostgreSQLImpl *functor = AddToIgnoreList_PostgreSQLImpl::Alloc();
  1201. printf("Adds a user to the ignore list of another user.\nSpecify user by ID (faster) or handle (slower).\n");
  1202. printf("Enter user ID? (y/n): ");
  1203. gets(inputStr);
  1204. if (inputStr[0]=='y')
  1205. {
  1206. printf("Enter user ID (integer): ");
  1207. gets(inputStr);
  1208. functor->id.hasDatabaseRowId=true;
  1209. functor->id.databaseRowId=atoi(inputStr);
  1210. }
  1211. else
  1212. {
  1213. printf("Enter user handle: ");
  1214. gets(inputStr);
  1215. functor->id.hasDatabaseRowId=false;
  1216. functor->id.handle=inputStr;
  1217. }
  1218. printf("Enter ignored user ID? (y/n): ");
  1219. gets(inputStr);
  1220. if (inputStr[0]=='y')
  1221. {
  1222. printf("Enter ignored user ID (integer): ");
  1223. gets(inputStr);
  1224. functor->ignoredUser.hasDatabaseRowId=true;
  1225. functor->ignoredUser.databaseRowId=atoi(inputStr);
  1226. }
  1227. else
  1228. {
  1229. printf("Enter ignored user handle: ");
  1230. gets(inputStr);
  1231. functor->ignoredUser.hasDatabaseRowId=false;
  1232. functor->ignoredUser.handle=inputStr;
  1233. }
  1234. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1235. lobbyServer.PushFunctor(functor,0);
  1236. }
  1237. else if (ch=='l')
  1238. {
  1239. RemoveFromIgnoreList_PostgreSQLImpl *functor = RemoveFromIgnoreList_PostgreSQLImpl::Alloc();
  1240. printf("Stops ignoring a user.\nSpecify user by ID (faster) or handle (slower).\n");
  1241. printf("Enter user ID? (y/n): ");
  1242. gets(inputStr);
  1243. if (inputStr[0]=='y')
  1244. {
  1245. printf("Enter user ID (integer): ");
  1246. gets(inputStr);
  1247. functor->id.hasDatabaseRowId=true;
  1248. functor->id.databaseRowId=atoi(inputStr);
  1249. }
  1250. else
  1251. {
  1252. printf("Enter user handle: ");
  1253. gets(inputStr);
  1254. functor->id.hasDatabaseRowId=false;
  1255. functor->id.handle=inputStr;
  1256. }
  1257. printf("Enter friend ID? (y/n): ");
  1258. gets(inputStr);
  1259. if (inputStr[0]=='y')
  1260. {
  1261. printf("Enter ignored user ID (integer): ");
  1262. gets(inputStr);
  1263. functor->ignoredUser.hasDatabaseRowId=true;
  1264. functor->ignoredUser.databaseRowId=atoi(inputStr);
  1265. }
  1266. else
  1267. {
  1268. printf("Enter ignored user handle: ");
  1269. gets(inputStr);
  1270. functor->ignoredUser.hasDatabaseRowId=false;
  1271. functor->ignoredUser.handle=inputStr;
  1272. }
  1273. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1274. lobbyServer.PushFunctor(functor,0);
  1275. }
  1276. else if (ch=='m')
  1277. {
  1278. GetIgnoreList_PostgreSQLImpl *functor = GetIgnoreList_PostgreSQLImpl::Alloc();
  1279. printf("Gets the list of ignored users for a user.\nSpecify user by ID (faster) or handle (slower).\n");
  1280. printf("Enter user ID? (y/n): ");
  1281. gets(inputStr);
  1282. if (inputStr[0]=='y')
  1283. {
  1284. printf("Enter user ID (integer): ");
  1285. gets(inputStr);
  1286. functor->id.hasDatabaseRowId=true;
  1287. functor->id.databaseRowId=atoi(inputStr);
  1288. }
  1289. else
  1290. {
  1291. printf("Enter user handle: ");
  1292. gets(inputStr);
  1293. functor->id.hasDatabaseRowId=false;
  1294. functor->id.handle=inputStr;
  1295. }
  1296. printf("Ascending sort? (y/n): ");
  1297. gets(inputStr);
  1298. if (inputStr[0]=='y')
  1299. functor->ascendingSort=true;
  1300. else
  1301. functor->ascendingSort=false;
  1302. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1303. lobbyServer.PushFunctor(functor,0);
  1304. }
  1305. else if (ch=='o')
  1306. {
  1307. SendEmail_PostgreSQLImpl *functor = SendEmail_PostgreSQLImpl::Alloc();
  1308. printf("Send email to recipient(s).\n");
  1309. printf("Enter FROM: user ID? (y/n): ");
  1310. gets(inputStr);
  1311. if (inputStr[0]=='y')
  1312. {
  1313. printf("Enter FROM: user ID (integer): ");
  1314. gets(inputStr);
  1315. functor->id.hasDatabaseRowId=true;
  1316. functor->id.databaseRowId=atoi(inputStr);
  1317. }
  1318. else
  1319. {
  1320. printf("Enter FROM: user handle: ");
  1321. gets(inputStr);
  1322. functor->id.hasDatabaseRowId=false;
  1323. functor->id.handle=inputStr;
  1324. }
  1325. while (1)
  1326. {
  1327. LobbyDBSpec::RowIdOrHandle uioh;
  1328. printf("Enter TO: recipient ID? (Enter to stop) (y/n): ");
  1329. gets(inputStr);
  1330. if (inputStr[0]=='y')
  1331. {
  1332. printf("Enter TO: user ID (integer): ");
  1333. gets(inputStr);
  1334. uioh.hasDatabaseRowId=true;
  1335. uioh.databaseRowId=atoi(inputStr);
  1336. }
  1337. else if (inputStr[0]==0)
  1338. break;
  1339. else
  1340. {
  1341. printf("Enter TO: user handle: ");
  1342. gets(inputStr);
  1343. uioh.hasDatabaseRowId=false;
  1344. uioh.handle=inputStr;
  1345. }
  1346. functor->to.Insert(uioh);
  1347. }
  1348. printf("Enter subject: ");
  1349. gets(inputStr);
  1350. functor->subject=inputStr;
  1351. printf("Enter body: ");
  1352. gets(inputStr);
  1353. functor->body=inputStr;
  1354. // Test attachments
  1355. functor->attachment=SendEmail_PostgreSQLImpl::AllocBytes(2);
  1356. functor->attachmentLength=2;
  1357. functor->attachment[0]='Z';
  1358. functor->attachment[1]=0;
  1359. // Emails can be tagged with a status number. Can use for read, priority, etc.
  1360. functor->initialSenderStatus=63;
  1361. functor->initialRecipientStatus=64;
  1362. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1363. lobbyServer.PushFunctor(functor,0);
  1364. }
  1365. else if (ch=='p')
  1366. {
  1367. GetEmails_PostgreSQLImpl *functor = GetEmails_PostgreSQLImpl::Alloc();
  1368. printf("Get emails for a user.\n");
  1369. printf("Enter user ID? (y/n): ");
  1370. gets(inputStr);
  1371. if (inputStr[0]=='y')
  1372. {
  1373. printf("Enter user ID (integer): ");
  1374. gets(inputStr);
  1375. functor->id.hasDatabaseRowId=true;
  1376. functor->id.databaseRowId=atoi(inputStr);
  1377. }
  1378. else
  1379. {
  1380. printf("Enter user handle: ");
  1381. gets(inputStr);
  1382. functor->id.hasDatabaseRowId=false;
  1383. functor->id.handle=inputStr;
  1384. }
  1385. printf("Check inbox? (y/n): ");
  1386. gets(inputStr);
  1387. if (inputStr[0]=='y')
  1388. {
  1389. functor->inbox=true;
  1390. }
  1391. else
  1392. {
  1393. // Check sent items
  1394. functor->inbox=false;
  1395. }
  1396. printf("Ascending sort? (y/n): ");
  1397. gets(inputStr);
  1398. if (inputStr[0]=='y')
  1399. functor->ascendingSort=true;
  1400. else
  1401. functor->ascendingSort=false;
  1402. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1403. lobbyServer.PushFunctor(functor,0);
  1404. }
  1405. else if (ch=='q')
  1406. {
  1407. DeleteEmail_PostgreSQLImpl *functor = DeleteEmail_PostgreSQLImpl::Alloc();
  1408. printf("Delete email.\n");
  1409. printf("Enter email message ID (integer)\n");
  1410. printf("This is found by calling GetEmails and checking emails.emailMessageID\n");
  1411. gets(inputStr);
  1412. functor->emailMessageID=atoi(inputStr);
  1413. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1414. lobbyServer.PushFunctor(functor,0);
  1415. }
  1416. else if (ch=='r')
  1417. {
  1418. UpdateEmailStatus_PostgreSQLImpl *functor = UpdateEmailStatus_PostgreSQLImpl::Alloc();
  1419. printf("Update user-defined status flags for an email.\n");
  1420. printf("Enter email message ID (integer)\n");
  1421. printf("This is found by calling GetEmails and checking emails.emailMessageID\n");
  1422. gets(inputStr);
  1423. functor->emailMessageID=atoi(inputStr);
  1424. printf("Enter new status: ");
  1425. gets(inputStr);
  1426. functor->status=atoi(inputStr);
  1427. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1428. lobbyServer.PushFunctor(functor,0);
  1429. }
  1430. else if (ch=='s')
  1431. {
  1432. GetHandleFromUserId_PostgreSQLImpl *functor = GetHandleFromUserId_PostgreSQLImpl::Alloc();
  1433. printf("Gets the handle given a user Id.\n");
  1434. printf("Enter the user Id (integer): ");
  1435. gets(inputStr);
  1436. functor->userId=atoi(inputStr);
  1437. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1438. lobbyServer.PushFunctor(functor,0);
  1439. }
  1440. else if (ch=='t')
  1441. {
  1442. GetUserIdFromHandle_PostgreSQLImpl *functor = GetUserIdFromHandle_PostgreSQLImpl::Alloc();
  1443. printf("Gets the user Id given a handle.\n");
  1444. printf("Enter the handle (string): ");
  1445. gets(inputStr);
  1446. functor->handle=inputStr;
  1447. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1448. lobbyServer.PushFunctor(functor,0);
  1449. }
  1450. else if (ch=='u')
  1451. {
  1452. DeleteUser_PostgreSQLImpl *functor = DeleteUser_PostgreSQLImpl::Alloc();
  1453. printf("Deletes a user.\n");
  1454. printf("Enter user ID? (y/n): ");
  1455. gets(inputStr);
  1456. if (inputStr[0]=='y')
  1457. {
  1458. printf("Enter user ID (integer): ");
  1459. gets(inputStr);
  1460. functor->id.hasDatabaseRowId=true;
  1461. functor->id.databaseRowId=atoi(inputStr);
  1462. }
  1463. else
  1464. {
  1465. printf("Enter user handle: ");
  1466. gets(inputStr);
  1467. functor->id.hasDatabaseRowId=false;
  1468. functor->id.handle=inputStr;
  1469. }
  1470. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1471. lobbyServer.PushFunctor(functor,0);
  1472. }
  1473. else if (ch=='v')
  1474. {
  1475. ChangeUserHandle_PostgreSQLImpl *functor = ChangeUserHandle_PostgreSQLImpl::Alloc();
  1476. printf("Changes a user's handle.\n");
  1477. printf("Enter user ID? (y/n): ");
  1478. gets(inputStr);
  1479. if (inputStr[0]=='y')
  1480. {
  1481. printf("Enter user ID (integer): ");
  1482. gets(inputStr);
  1483. functor->id.hasDatabaseRowId=true;
  1484. functor->id.databaseRowId=atoi(inputStr);
  1485. }
  1486. else
  1487. {
  1488. printf("Enter user handle: ");
  1489. gets(inputStr);
  1490. functor->id.hasDatabaseRowId=false;
  1491. functor->id.handle=inputStr;
  1492. }
  1493. printf("Enter new handle: ");
  1494. gets(inputStr);
  1495. functor->newHandle=inputStr;
  1496. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1497. lobbyServer.PushFunctor(functor,0);
  1498. }
  1499. else if (ch=='w')
  1500. {
  1501. AddDisallowedHandle_PostgreSQLImpl *functor = AddDisallowedHandle_PostgreSQLImpl::Alloc();
  1502. printf("Add a disallowed handle.\n");
  1503. printf("Enter handle: ");
  1504. gets(inputStr);
  1505. functor->handle=inputStr;
  1506. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1507. lobbyServer.PushFunctor(functor,0);
  1508. }
  1509. else if (ch=='x')
  1510. {
  1511. RemoveDisallowedHandle_PostgreSQLImpl *functor = RemoveDisallowedHandle_PostgreSQLImpl::Alloc();
  1512. printf("Removes a disallowed handle.\n");
  1513. printf("Enter handle: ");
  1514. gets(inputStr);
  1515. functor->handle=inputStr;
  1516. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1517. lobbyServer.PushFunctor(functor,0);
  1518. }
  1519. else if (ch=='y')
  1520. {
  1521. IsDisallowedHandle_PostgreSQLImpl *functor = IsDisallowedHandle_PostgreSQLImpl::Alloc();
  1522. printf("Checks if a handle is disallowed.\n");
  1523. printf("Enter handle: ");
  1524. gets(inputStr);
  1525. functor->handle=inputStr;
  1526. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1527. lobbyServer.PushFunctor(functor,0);
  1528. }
  1529. else if (ch=='z')
  1530. {
  1531. AddToActionHistory_PostgreSQLImpl *functor = AddToActionHistory_PostgreSQLImpl::Alloc();
  1532. printf("Records an action this user has taken.\n");
  1533. printf("Enter user ID? (y/n): ");
  1534. gets(inputStr);
  1535. if (inputStr[0]=='y')
  1536. {
  1537. printf("Enter user ID (integer): ");
  1538. gets(inputStr);
  1539. functor->id.hasDatabaseRowId=true;
  1540. functor->id.databaseRowId=atoi(inputStr);
  1541. }
  1542. else
  1543. {
  1544. printf("Enter user handle: ");
  1545. gets(inputStr);
  1546. functor->id.hasDatabaseRowId=false;
  1547. functor->id.handle=inputStr;
  1548. }
  1549. printf("Enter actionTaken: ");
  1550. gets(inputStr);
  1551. functor->actionTaken=inputStr;
  1552. printf("Enter description: ");
  1553. gets(inputStr);
  1554. functor->description=inputStr;
  1555. functor->actionTime; // Leave blank
  1556. functor->sourceIpAddress="127.0.0.1";
  1557. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1558. lobbyServer.PushFunctor(functor,0);
  1559. }
  1560. else if (ch=='0')
  1561. {
  1562. GetActionHistory_PostgreSQLImpl *functor = GetActionHistory_PostgreSQLImpl::Alloc();
  1563. printf("Gets the actions this user has taken.\n");
  1564. printf("Enter user ID? (y/n): ");
  1565. gets(inputStr);
  1566. if (inputStr[0]=='y')
  1567. {
  1568. printf("Enter user ID (integer): ");
  1569. gets(inputStr);
  1570. functor->id.hasDatabaseRowId=true;
  1571. functor->id.databaseRowId=atoi(inputStr);
  1572. }
  1573. else
  1574. {
  1575. printf("Enter user handle: ");
  1576. gets(inputStr);
  1577. functor->id.hasDatabaseRowId=false;
  1578. functor->id.handle=inputStr;
  1579. }
  1580. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1581. lobbyServer.PushFunctor(functor,0);
  1582. }
  1583. else if (ch=='1')
  1584. {
  1585. UpdateClanMember_PostgreSQLImpl *functor = UpdateClanMember_PostgreSQLImpl::Alloc();
  1586. printf("Update or add a clan member.\n");
  1587. printf("Enter user ID? (y/n): ");
  1588. gets(inputStr);
  1589. if (inputStr[0]=='y')
  1590. {
  1591. printf("Enter user ID (integer): ");
  1592. gets(inputStr);
  1593. functor->userId.hasDatabaseRowId=true;
  1594. functor->userId.databaseRowId=atoi(inputStr);
  1595. }
  1596. else
  1597. {
  1598. printf("Enter user handle: ");
  1599. gets(inputStr);
  1600. functor->userId.hasDatabaseRowId=false;
  1601. functor->userId.handle=inputStr;
  1602. }
  1603. printf("Enter clan ID (0 to add new): ");
  1604. gets(inputStr);
  1605. functor->clanId.databaseRowId=atoi(inputStr);
  1606. functor->clanId.hasDatabaseRowId=true;
  1607. printf("Enter operation:\n(1) Member\n(2) Join request\n(3) Join invite\n(4) Blacklist\n");
  1608. gets(inputStr);
  1609. if (inputStr[0]=='1')
  1610. functor->mEStatus1=LobbyDBSpec::CLAN_MEMBER_STATUS_MEMBER;
  1611. else if (inputStr[0]=='2')
  1612. functor->mEStatus1=LobbyDBSpec::CLAN_MEMBER_STATUS_REQUESTED_TO_JOIN;
  1613. else if (inputStr[0]=='3')
  1614. functor->mEStatus1=LobbyDBSpec::CLAN_MEMBER_STATUS_INVITED_TO_JOIN;
  1615. else
  1616. functor->mEStatus1=LobbyDBSpec::CLAN_MEMBER_STATUS_BLACKLISTED;
  1617. functor->integers[0]=1;
  1618. functor->integers[1]=2;
  1619. functor->integers[2]=3;
  1620. functor->integers[3]=4;
  1621. functor->floats[0]=1;
  1622. functor->floats[1]=2;
  1623. functor->floats[2]=3;
  1624. functor->floats[3]=4;
  1625. printf("Enter member description 1: ");
  1626. gets(inputStr);
  1627. functor->descriptions[0]=inputStr;
  1628. printf("Enter member description 2: ");
  1629. gets(inputStr);
  1630. functor->descriptions[1]=inputStr;
  1631. functor->binaryData=0;
  1632. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1633. lobbyServer.PushFunctor(functor,0);
  1634. }
  1635. else if (ch=='2')
  1636. {
  1637. UpdateClan_PostgreSQLImpl *functor = UpdateClan_PostgreSQLImpl::Alloc();
  1638. printf("Update an existing clan, any values but the name.\n");
  1639. printf("Enter clan ID? (y/n): ");
  1640. gets(inputStr);
  1641. if (inputStr[0]=='y')
  1642. {
  1643. printf("Enter clan ID (integer): ");
  1644. gets(inputStr);
  1645. functor->clanId.hasDatabaseRowId=true;
  1646. functor->clanId.databaseRowId=atoi(inputStr);
  1647. }
  1648. else
  1649. {
  1650. printf("Enter clan handle: ");
  1651. gets(inputStr);
  1652. functor->clanId.hasDatabaseRowId=false;
  1653. functor->clanId.handle=inputStr;
  1654. }
  1655. functor->SetUpdateInts(true);
  1656. functor->integers[0]=111;
  1657. functor->integers[1]=112;
  1658. functor->integers[2]=113;
  1659. functor->integers[3]=114;
  1660. functor->SetUpdateFloats(false);
  1661. functor->updateDescriptions[0]=true;
  1662. functor->descriptions[0]="Updated clan description 1";
  1663. functor->updateDescriptions[1]=false;
  1664. functor->updateBinaryData=true;
  1665. functor->binaryData=0;
  1666. functor->updateRequiresInvitationsToJoin=false;
  1667. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1668. lobbyServer.PushFunctor(functor,0);
  1669. }
  1670. else if (ch=='3')
  1671. {
  1672. CreateClan_PostgreSQLImpl *functor = CreateClan_PostgreSQLImpl::Alloc();
  1673. printf("Create a new clan.\n");
  1674. printf("Enter user ID? (y/n): ");
  1675. gets(inputStr);
  1676. if (inputStr[0]=='y')
  1677. {
  1678. printf("Enter user ID (integer): ");
  1679. gets(inputStr);
  1680. functor->leaderData.userId.hasDatabaseRowId=true;
  1681. functor->leaderData.userId.databaseRowId=atoi(inputStr);
  1682. }
  1683. else
  1684. {
  1685. printf("Enter user handle: ");
  1686. gets(inputStr);
  1687. functor->leaderData.userId.hasDatabaseRowId=false;
  1688. functor->leaderData.userId.handle=inputStr;
  1689. }
  1690. printf("Enter clan name: ");
  1691. gets(inputStr);
  1692. functor->initialClanData.handle = inputStr;
  1693. functor->initialClanData.integers[0] = 1;
  1694. functor->initialClanData.integers[1] = 2;
  1695. functor->initialClanData.integers[2] = 3;
  1696. functor->initialClanData.integers[3] = 4;
  1697. functor->initialClanData.floats[0] = 11;
  1698. functor->initialClanData.floats[1] = 12;
  1699. functor->initialClanData.floats[2] = 13;
  1700. functor->initialClanData.floats[3] = 14;
  1701. functor->initialClanData.descriptions[0] = "CreateClan_PostgreSQLImpl Description 1";
  1702. functor->initialClanData.descriptions[1] = "CreateClan_PostgreSQLImpl Description 2";
  1703. functor->initialClanData.binaryData=0;
  1704. functor->initialClanData.requiresInvitationsToJoin=true;
  1705. functor->leaderData.integers[0] = 21;
  1706. functor->leaderData.integers[1] = 22;
  1707. functor->leaderData.integers[2] = 23;
  1708. functor->leaderData.integers[3] = 24;
  1709. functor->leaderData.floats[0] = 31;
  1710. functor->leaderData.floats[1] = 32;
  1711. functor->leaderData.floats[2] = 33;
  1712. functor->leaderData.floats[3] = 34;
  1713. functor->leaderData.descriptions[0]="Big clan boss";
  1714. functor->leaderData.binaryData=0;
  1715. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1716. lobbyServer.PushFunctor(functor,0);
  1717. }
  1718. else if (ch=='4')
  1719. {
  1720. ChangeClanHandle_PostgreSQLImpl *functor = ChangeClanHandle_PostgreSQLImpl::Alloc();
  1721. printf("Change your clan's handle.\n");
  1722. printf("Enter clan row ID? (y/n): ");
  1723. gets(inputStr);
  1724. if (inputStr[0]=='y')
  1725. {
  1726. printf("Enter clan ID (integer): ");
  1727. gets(inputStr);
  1728. functor->clanId.hasDatabaseRowId=true;
  1729. functor->clanId.databaseRowId=atoi(inputStr);
  1730. }
  1731. else
  1732. {
  1733. printf("Enter clan handle: ");
  1734. gets(inputStr);
  1735. functor->clanId.hasDatabaseRowId=false;
  1736. functor->clanId.handle=inputStr;
  1737. }
  1738. printf("Enter new handle: ");
  1739. gets(inputStr);
  1740. functor->newHandle=inputStr;
  1741. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1742. lobbyServer.PushFunctor(functor,0);
  1743. }
  1744. else if (ch=='5')
  1745. {
  1746. DeleteClan_PostgreSQLImpl *functor = DeleteClan_PostgreSQLImpl::Alloc();
  1747. printf("Delete a clan.\n");
  1748. printf("Enter clan row ID? (y/n): ");
  1749. gets(inputStr);
  1750. if (inputStr[0]=='y')
  1751. {
  1752. printf("Enter clan ID (integer): ");
  1753. gets(inputStr);
  1754. functor->clanId.hasDatabaseRowId=true;
  1755. functor->clanId.databaseRowId=atoi(inputStr);
  1756. }
  1757. else
  1758. {
  1759. printf("Enter clan handle: ");
  1760. gets(inputStr);
  1761. functor->clanId.hasDatabaseRowId=false;
  1762. functor->clanId.handle=inputStr;
  1763. }
  1764. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1765. lobbyServer.PushFunctor(functor,0);
  1766. }
  1767. else if (ch=='6')
  1768. {
  1769. GetClans_PostgreSQLImpl *functor = GetClans_PostgreSQLImpl::Alloc();
  1770. printf("Get all clans and clan members for a user.\n");
  1771. printf("Enter user ID? (y/n): ");
  1772. gets(inputStr);
  1773. if (inputStr[0]=='y')
  1774. {
  1775. printf("Enter user ID (integer): ");
  1776. gets(inputStr);
  1777. functor->userId.hasDatabaseRowId=true;
  1778. functor->userId.databaseRowId=atoi(inputStr);
  1779. }
  1780. else
  1781. {
  1782. printf("Enter user handle: ");
  1783. gets(inputStr);
  1784. functor->userId.hasDatabaseRowId=false;
  1785. functor->userId.handle=inputStr;
  1786. }
  1787. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1788. lobbyServer.PushFunctor(functor,0);
  1789. }
  1790. else if (ch=='7')
  1791. {
  1792. RemoveFromClan_PostgreSQLImpl *functor = RemoveFromClan_PostgreSQLImpl::Alloc();
  1793. printf("Remove member from clan.\n");
  1794. printf("Enter user ID? (y/n): ");
  1795. gets(inputStr);
  1796. if (inputStr[0]=='y')
  1797. {
  1798. printf("Enter user ID (integer): ");
  1799. gets(inputStr);
  1800. functor->userId.hasDatabaseRowId=true;
  1801. functor->userId.databaseRowId=atoi(inputStr);
  1802. }
  1803. else
  1804. {
  1805. printf("Enter user handle: ");
  1806. gets(inputStr);
  1807. functor->userId.hasDatabaseRowId=false;
  1808. functor->userId.handle=inputStr;
  1809. }
  1810. printf("Enter clan row ID? (y/n): ");
  1811. gets(inputStr);
  1812. if (inputStr[0]=='y')
  1813. {
  1814. printf("Enter clan ID (integer): ");
  1815. gets(inputStr);
  1816. functor->clanId.hasDatabaseRowId=true;
  1817. functor->clanId.databaseRowId=atoi(inputStr);
  1818. }
  1819. else
  1820. {
  1821. printf("Enter clan handle: ");
  1822. gets(inputStr);
  1823. functor->clanId.hasDatabaseRowId=false;
  1824. functor->clanId.handle=inputStr;
  1825. }
  1826. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1827. lobbyServer.PushFunctor(functor,0);
  1828. }
  1829. else if (ch=='8')
  1830. {
  1831. AddToClanBoard_PostgreSQLImpl *functor = AddToClanBoard_PostgreSQLImpl::Alloc();
  1832. printf("Write to clan bulletin board.\n");
  1833. printf("Enter user row ID? (y/n): ");
  1834. gets(inputStr);
  1835. if (inputStr[0]=='y')
  1836. {
  1837. printf("Enter user ID (integer): ");
  1838. gets(inputStr);
  1839. functor->userId.hasDatabaseRowId=true;
  1840. functor->userId.databaseRowId=atoi(inputStr);
  1841. }
  1842. else
  1843. {
  1844. printf("Enter user handle: ");
  1845. gets(inputStr);
  1846. functor->userId.hasDatabaseRowId=false;
  1847. functor->userId.handle=inputStr;
  1848. }
  1849. printf("Enter clan row ID? (y/n): ");
  1850. gets(inputStr);
  1851. if (inputStr[0]=='y')
  1852. {
  1853. printf("Enter clan ID (integer): ");
  1854. gets(inputStr);
  1855. functor->clanId.hasDatabaseRowId=true;
  1856. functor->clanId.databaseRowId=atoi(inputStr);
  1857. }
  1858. else
  1859. {
  1860. printf("Enter clan handle: ");
  1861. gets(inputStr);
  1862. functor->clanId.hasDatabaseRowId=false;
  1863. functor->clanId.handle=inputStr;
  1864. }
  1865. printf("Enter subject: ");
  1866. gets(inputStr);
  1867. functor->subject=inputStr;
  1868. printf("Enter body: ");
  1869. gets(inputStr);
  1870. functor->body=inputStr;
  1871. functor->integers[0]=0;
  1872. functor->integers[1]=0;
  1873. functor->integers[2]=0;
  1874. functor->integers[3]=0;
  1875. functor->floats[0]=0;
  1876. functor->floats[1]=0;
  1877. functor->floats[2]=0;
  1878. functor->floats[3]=0;
  1879. functor->binaryData=0;
  1880. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1881. lobbyServer.PushFunctor(functor,0);
  1882. }
  1883. else if (ch=='9')
  1884. {
  1885. RemoveFromClanBoard_PostgreSQLImpl *functor = RemoveFromClanBoard_PostgreSQLImpl::Alloc();
  1886. printf("Remove from clan bulletin board.\n");
  1887. printf("Enter post ID: ");
  1888. gets(inputStr);
  1889. functor->postId=atoi(inputStr);
  1890. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1891. lobbyServer.PushFunctor(functor,0);
  1892. }
  1893. else if (ch=='!')
  1894. {
  1895. GetClanBoard_PostgreSQLImpl *functor = GetClanBoard_PostgreSQLImpl::Alloc();
  1896. printf("Get clan bulletin board.\n");
  1897. printf("Enter clan row ID? (y/n): ");
  1898. gets(inputStr);
  1899. if (inputStr[0]=='y')
  1900. {
  1901. printf("Enter clan ID (integer): ");
  1902. gets(inputStr);
  1903. functor->clanId.hasDatabaseRowId=true;
  1904. functor->clanId.databaseRowId=atoi(inputStr);
  1905. }
  1906. else
  1907. {
  1908. printf("Enter clan handle: ");
  1909. gets(inputStr);
  1910. functor->clanId.hasDatabaseRowId=false;
  1911. functor->clanId.handle=inputStr;
  1912. }
  1913. printf("Ascending sort? (y/n): ");
  1914. gets(inputStr);
  1915. if (inputStr[0]=='y')
  1916. functor->ascendingSort=true;
  1917. else
  1918. functor->ascendingSort=false;
  1919. /// Puts this functor on the processing queue. It will process sometime later in a thread.
  1920. lobbyServer.PushFunctor(functor,0);
  1921. }
  1922. }
  1923. // Causes Functor::HandleResult calls. If this is forgotten you won't get processing result calls.
  1924. ft.CallResultHandlers();
  1925. Sleep(30);
  1926. }
  1927. }
粤ICP备19079148号