ClubClient.cpp 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190
  1. /*-------------------------------------------------------------------------
  2. ClubClient.cpp
  3. Per client stuff, including site for Clients session
  4. Owner:
  5. Copyright 1986-2000 Microsoft Corporation, All Rights Reserved
  6. *-----------------------------------------------------------------------*/
  7. #include "pch.h"
  8. #include "ClubQueries.h"
  9. const DWORD CFLClient::c_dwID = 19680815;
  10. const char * szNotMemberMessage = "Your request could not be completed because you are not currently signed up as an Allegiance Zone Member.";
  11. namespace
  12. {
  13. // The most play time we want to ever show is 9999 hours, or 599940 minutes
  14. int MaxMinutes(int minutes)
  15. {
  16. const int cMinutesMax = 599940;
  17. if (minutes < cMinutesMax)
  18. return minutes;
  19. return cMinutesMax;
  20. }
  21. // remove trailing whitespaces from a string
  22. void RemoveTrailingSpaces(char* sz)
  23. {
  24. for (int nIndex = strlen(sz); nIndex > 0 && sz[nIndex - 1] == ' '; --nIndex)
  25. {
  26. sz[nIndex - 1] = '\0';
  27. }
  28. };
  29. // map character name to character ID (and fix capitialization of character name)
  30. int FindCharacterIDAndCapitalization(char* szName)
  31. {
  32. strncpy((char*)CharIDAndCapitalization_Name, szName, c_cbName - 1);
  33. CharID_CharacterName[c_cbName - 1] = '\0';
  34. SQL_GO(CharIDAndCapitalization);
  35. if (SQL_SUCCEEDED(SQL_GETROW(CharIDAndCapitalization)))
  36. {
  37. strcpy(szName, (char*)CharIDAndCapitalization_ProperName);
  38. return CharIDAndCapitalization_CharacterId;
  39. }
  40. else
  41. {
  42. return -1;
  43. }
  44. }
  45. // map character ID to character name
  46. const char* FindCharacterName(int id)
  47. {
  48. CharInfoGeneral_CharacterID = id;
  49. SQL_GO(CharInfoGeneral);
  50. if (SQL_SUCCEEDED(SQL_GETROW(CharInfoGeneral)))
  51. {
  52. return (const char*)CharInfoGeneral_Name;
  53. }
  54. else
  55. {
  56. return "";
  57. }
  58. }
  59. // is there a player in the results list with the given name?
  60. bool HasPlayerNamed(const char* szName, LeaderBoardEntry* vResult, int cResults)
  61. {
  62. for (int i = 0; i < cResults; i++)
  63. {
  64. if (_strnicmp(szName, vResult[i].CharacterName, c_cbName) == 0)
  65. return true;
  66. }
  67. return false;
  68. }
  69. // is there a player in the results list with the given character id?
  70. bool HasCharacterID(int charID, LeaderBoardEntry* vResult, int cResults)
  71. {
  72. // HACK: always return true for id -1
  73. if (charID == -1)
  74. return true;
  75. for (int i = 0; i < cResults; i++)
  76. {
  77. if (charID == vResult[i].idCharacter)
  78. return true;
  79. }
  80. return false;
  81. }
  82. // create an entry for the given character - you can pass in either name or id, but
  83. // the other one must be "" or -1 respectively.
  84. void ForgeResultEntry(LeaderBoardEntry& entry, const char* szName, int id, int nPosition)
  85. {
  86. if (szName[0] != '\0')
  87. {
  88. assert(id = -1);
  89. strncpy(entry.CharacterName, szName, c_cbName);
  90. id = FindCharacterIDAndCapitalization(entry.CharacterName);
  91. }
  92. else
  93. {
  94. strncpy(entry.CharacterName, FindCharacterName(id), c_cbName);
  95. }
  96. RemoveTrailingSpaces(entry.CharacterName);
  97. entry.idCharacter = id;
  98. entry.nPosition = nPosition;
  99. entry.fTotalScore = 0;
  100. entry.nMinutesPlayed = 0;
  101. entry.cTotalBaseKills = 0;
  102. entry.cTotalBaseCaptures = 0;
  103. entry.cTotalKills = 0;
  104. entry.cTotalDeaths = 0;
  105. entry.rank = 0;
  106. entry.rating = 0;
  107. entry.cTotalWins = 0;
  108. entry.cTotalLosses = 0;
  109. entry.cTotalGamesPlayed = 0;
  110. entry.cTotalCommanderWins = 0;
  111. }
  112. /*
  113. int GetResultsByXXX(const char* szName, int characterId, CivID civID,
  114. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  115. {
  116. // get the top player by XXX in this civ
  117. GetTopXXX_CivIDIn = civID;
  118. GetTopXXX_CivIDIn2 = civID;
  119. SQL_GO(GetTopXXX);
  120. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopXXX)))
  121. {
  122. return 0;
  123. }
  124. else
  125. {
  126. strcpy(topPlayer.CharacterName, (char*)GetTopXXX_CharacterName);
  127. RemoveTrailingSpaces(topPlayer.CharacterName);
  128. topPlayer.idCharacter = GetTopXXX_CharacterID;
  129. topPlayer.nPosition = 1;
  130. topPlayer.fTotalScore = GetTopXXX_Score;
  131. topPlayer.nMinutesPlayed = MaxMinutes(GetTopXXX_MinutesPlayed);
  132. topPlayer.cTotalBaseKills = GetTopXXX_BaseKills;
  133. topPlayer.cTotalBaseCaptures = GetTopXXX_BaseCaptures;
  134. topPlayer.cTotalKills = GetTopXXX_Kills;
  135. topPlayer.cTotalDeaths = GetTopXXX_Deaths;
  136. topPlayer.rank = GetTopXXX_Rank;
  137. topPlayer.rating = GetTopXXX_Rating;
  138. topPlayer.cTotalWins = GetTopXXX_Wins;
  139. topPlayer.cTotalLosses = GetTopXXX_Losses;
  140. topPlayer.cTotalCommanderWins = GetTopXXX_CommanderWins;
  141. topPlayer.cTotalGamesPlayed = GetTopXXX_GamesPlayed;
  142. }
  143. // get the players near the character in question
  144. GetNearXXX_CharacterIDIn = characterId;
  145. GetNearXXX_CivIDIn = civID;
  146. strcpy((char*)GetNearXXX_CharacterNameIn, szName);
  147. int cResults = 0;
  148. SQL_GO(GetNearXXX);
  149. while (SQL_SUCCEEDED(SQL_GETROW(GetNearXXX)) && cResults < nMaxResults)
  150. {
  151. strcpy(vResults[cResults].CharacterName, (char*)GetNearXXX_CharacterName);
  152. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  153. vResults[cResults].idCharacter = GetNearXXX_CharacterID;
  154. vResults[cResults].nPosition = GetNearXXX_FirstOrdinal + cResults;
  155. vResults[cResults].fTotalScore = GetNearXXX_Score;
  156. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearXXX_MinutesPlayed);
  157. vResults[cResults].cTotalBaseKills = GetNearXXX_BaseKills;
  158. vResults[cResults].cTotalBaseCaptures = GetNearXXX_BaseCaptures;
  159. vResults[cResults].cTotalKills = GetNearXXX_Kills;
  160. vResults[cResults].cTotalDeaths = GetNearXXX_Deaths;
  161. vResults[cResults].rank = GetNearXXX_Rank;
  162. vResults[cResults].rating = GetNearXXX_Rating;
  163. vResults[cResults].cTotalWins = GetNearXXX_Wins;
  164. vResults[cResults].cTotalLosses = GetNearXXX_Losses;
  165. vResults[cResults].cTotalCommanderWins = GetNearXXX_CommanderWins;
  166. vResults[cResults].cTotalGamesPlayed = GetNearXXX_GamesPlayed;
  167. cResults++;
  168. assert(cResults <= nMaxResults);
  169. }
  170. return cResults;
  171. }
  172. */
  173. int GetResultsByName(const char* szName, int characterId, CivID civID,
  174. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  175. {
  176. // get the top player by Name in this civ
  177. GetTopName_CivIDIn = civID;
  178. GetTopName_CivIDIn2 = civID;
  179. SQL_GO(GetTopName);
  180. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopName)))
  181. {
  182. return 0;
  183. }
  184. else
  185. {
  186. strcpy(topPlayer.CharacterName, (char*)GetTopName_CharacterName);
  187. RemoveTrailingSpaces(topPlayer.CharacterName);
  188. topPlayer.idCharacter = GetTopName_CharacterID;
  189. topPlayer.nPosition = 1;
  190. topPlayer.fTotalScore = GetTopName_Score;
  191. topPlayer.nMinutesPlayed = MaxMinutes(GetTopName_MinutesPlayed);
  192. topPlayer.cTotalBaseKills = GetTopName_BaseKills;
  193. topPlayer.cTotalBaseCaptures = GetTopName_BaseCaptures;
  194. topPlayer.cTotalKills = GetTopName_Kills;
  195. topPlayer.cTotalDeaths = GetTopName_Deaths;
  196. topPlayer.rank = GetTopName_Rank;
  197. topPlayer.rating = RATING_EXT2DISP(GetTopName_Rating);
  198. topPlayer.cTotalWins = GetTopName_Wins;
  199. topPlayer.cTotalLosses = GetTopName_Losses;
  200. topPlayer.cTotalCommanderWins = GetTopName_CommanderWins;
  201. topPlayer.cTotalGamesPlayed = GetTopName_GamesPlayed;
  202. }
  203. // get the players near the character in question
  204. GetNearName_CharacterIDIn = characterId;
  205. GetNearName_CivIDIn = civID;
  206. strcpy((char*)GetNearName_CharacterNameIn, szName);
  207. int cResults = 0;
  208. SQL_GO(GetNearName);
  209. while (SQL_SUCCEEDED(SQL_GETROW(GetNearName)) && cResults < nMaxResults)
  210. {
  211. strcpy(vResults[cResults].CharacterName, (char*)GetNearName_CharacterName);
  212. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  213. vResults[cResults].idCharacter = GetNearName_CharacterID;
  214. vResults[cResults].nPosition = GetNearName_FirstOrdinal + cResults;
  215. vResults[cResults].fTotalScore = GetNearName_Score;
  216. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearName_MinutesPlayed);
  217. vResults[cResults].cTotalBaseKills = GetNearName_BaseKills;
  218. vResults[cResults].cTotalBaseCaptures = GetNearName_BaseCaptures;
  219. vResults[cResults].cTotalKills = GetNearName_Kills;
  220. vResults[cResults].cTotalDeaths = GetNearName_Deaths;
  221. vResults[cResults].rank = GetNearName_Rank;
  222. vResults[cResults].rating = RATING_EXT2DISP(GetNearName_Rating);
  223. vResults[cResults].cTotalWins = GetNearName_Wins;
  224. vResults[cResults].cTotalLosses = GetNearName_Losses;
  225. vResults[cResults].cTotalCommanderWins = GetNearName_CommanderWins;
  226. vResults[cResults].cTotalGamesPlayed = GetNearName_GamesPlayed;
  227. cResults++;
  228. assert(cResults <= nMaxResults);
  229. }
  230. return cResults;
  231. }
  232. int GetResultsByRank(const char* szName, int characterId, CivID civID,
  233. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  234. {
  235. // get the top player by Rank in this civ
  236. GetTopRank_CivIDIn = civID;
  237. GetTopRank_CivIDIn2 = civID;
  238. SQL_GO(GetTopRank);
  239. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopRank)))
  240. {
  241. return 0;
  242. }
  243. else
  244. {
  245. strcpy(topPlayer.CharacterName, (char*)GetTopRank_CharacterName);
  246. RemoveTrailingSpaces(topPlayer.CharacterName);
  247. topPlayer.idCharacter = GetTopRank_CharacterID;
  248. topPlayer.nPosition = 1;
  249. topPlayer.fTotalScore = GetTopRank_Score;
  250. topPlayer.nMinutesPlayed = MaxMinutes(GetTopRank_MinutesPlayed);
  251. topPlayer.cTotalBaseKills = GetTopRank_BaseKills;
  252. topPlayer.cTotalBaseCaptures = GetTopRank_BaseCaptures;
  253. topPlayer.cTotalKills = GetTopRank_Kills;
  254. topPlayer.cTotalDeaths = GetTopRank_Deaths;
  255. topPlayer.rank = GetTopRank_Rank;
  256. topPlayer.rating = RATING_EXT2DISP(GetTopRank_Rating);
  257. topPlayer.cTotalWins = GetTopRank_Wins;
  258. topPlayer.cTotalLosses = GetTopRank_Losses;
  259. topPlayer.cTotalCommanderWins = GetTopRank_CommanderWins;
  260. topPlayer.cTotalGamesPlayed = GetTopRank_GamesPlayed;
  261. }
  262. // get the players near the character in question
  263. GetNearRank_CharacterIDIn = characterId;
  264. GetNearRank_CivIDIn = civID;
  265. strcpy((char*)GetNearRank_CharacterNameIn, szName);
  266. int cResults = 0;
  267. SQL_GO(GetNearRank);
  268. while (SQL_SUCCEEDED(SQL_GETROW(GetNearRank)) && cResults < nMaxResults)
  269. {
  270. strcpy(vResults[cResults].CharacterName, (char*)GetNearRank_CharacterName);
  271. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  272. vResults[cResults].idCharacter = GetNearRank_CharacterID;
  273. vResults[cResults].nPosition = GetNearRank_FirstOrdinal + cResults;
  274. vResults[cResults].fTotalScore = GetNearRank_Score;
  275. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearRank_MinutesPlayed);
  276. vResults[cResults].cTotalBaseKills = GetNearRank_BaseKills;
  277. vResults[cResults].cTotalBaseCaptures = GetNearRank_BaseCaptures;
  278. vResults[cResults].cTotalKills = GetNearRank_Kills;
  279. vResults[cResults].cTotalDeaths = GetNearRank_Deaths;
  280. vResults[cResults].rank = GetNearRank_Rank;
  281. vResults[cResults].rating = RATING_EXT2DISP(GetNearRank_Rating);
  282. vResults[cResults].cTotalWins = GetNearRank_Wins;
  283. vResults[cResults].cTotalLosses = GetNearRank_Losses;
  284. vResults[cResults].cTotalCommanderWins = GetNearRank_CommanderWins;
  285. vResults[cResults].cTotalGamesPlayed = GetNearRank_GamesPlayed;
  286. cResults++;
  287. assert(cResults <= nMaxResults);
  288. }
  289. return cResults;
  290. }
  291. int GetResultsByRating(const char* szName, int characterId, CivID civID,
  292. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  293. {
  294. // get the top player by Rating in this civ
  295. GetTopRating_CivIDIn = civID;
  296. GetTopRating_CivIDIn2 = civID;
  297. SQL_GO(GetTopRating);
  298. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopRating)))
  299. {
  300. return 0;
  301. }
  302. else
  303. {
  304. strcpy(topPlayer.CharacterName, (char*)GetTopRating_CharacterName);
  305. RemoveTrailingSpaces(topPlayer.CharacterName);
  306. topPlayer.idCharacter = GetTopRating_CharacterID;
  307. topPlayer.nPosition = 1;
  308. topPlayer.fTotalScore = GetTopRating_Score;
  309. topPlayer.nMinutesPlayed = MaxMinutes(GetTopRating_MinutesPlayed);
  310. topPlayer.cTotalBaseKills = GetTopRating_BaseKills;
  311. topPlayer.cTotalBaseCaptures = GetTopRating_BaseCaptures;
  312. topPlayer.cTotalKills = GetTopRating_Kills;
  313. topPlayer.cTotalDeaths = GetTopRating_Deaths;
  314. topPlayer.rank = GetTopRating_Rank;
  315. topPlayer.rating = RATING_EXT2DISP(GetTopRating_Rating);
  316. topPlayer.cTotalWins = GetTopRating_Wins;
  317. topPlayer.cTotalLosses = GetTopRating_Losses;
  318. topPlayer.cTotalCommanderWins = GetTopRating_CommanderWins;
  319. topPlayer.cTotalGamesPlayed = GetTopRating_GamesPlayed;
  320. }
  321. // get the players near the character in question
  322. GetNearRating_CharacterIDIn = characterId;
  323. GetNearRating_CivIDIn = civID;
  324. strcpy((char*)GetNearRating_CharacterNameIn, szName);
  325. int cResults = 0;
  326. SQL_GO(GetNearRating);
  327. while (SQL_SUCCEEDED(SQL_GETROW(GetNearRating)) && cResults < nMaxResults)
  328. {
  329. strcpy(vResults[cResults].CharacterName, (char*)GetNearRating_CharacterName);
  330. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  331. vResults[cResults].idCharacter = GetNearRating_CharacterID;
  332. vResults[cResults].nPosition = GetNearRating_FirstOrdinal + cResults;
  333. vResults[cResults].fTotalScore = GetNearRating_Score;
  334. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearRating_MinutesPlayed);
  335. vResults[cResults].cTotalBaseKills = GetNearRating_BaseKills;
  336. vResults[cResults].cTotalBaseCaptures = GetNearRating_BaseCaptures;
  337. vResults[cResults].cTotalKills = GetNearRating_Kills;
  338. vResults[cResults].cTotalDeaths = GetNearRating_Deaths;
  339. vResults[cResults].rank = GetNearRating_Rank;
  340. vResults[cResults].rating = RATING_EXT2DISP(GetNearRating_Rating);
  341. vResults[cResults].cTotalWins = GetNearRating_Wins;
  342. vResults[cResults].cTotalLosses = GetNearRating_Losses;
  343. vResults[cResults].cTotalCommanderWins = GetNearRating_CommanderWins;
  344. vResults[cResults].cTotalGamesPlayed = GetNearRating_GamesPlayed;
  345. cResults++;
  346. assert(cResults <= nMaxResults);
  347. }
  348. return cResults;
  349. }
  350. int GetResultsByScore(const char* szName, int characterId, CivID civID,
  351. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  352. {
  353. // get the top player by Score in this civ
  354. GetTopScore_CivIDIn = civID;
  355. GetTopScore_CivIDIn2 = civID;
  356. SQL_GO(GetTopScore);
  357. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopScore)))
  358. {
  359. return 0;
  360. }
  361. else
  362. {
  363. strcpy(topPlayer.CharacterName, (char*)GetTopScore_CharacterName);
  364. RemoveTrailingSpaces(topPlayer.CharacterName);
  365. topPlayer.idCharacter = GetTopScore_CharacterID;
  366. topPlayer.nPosition = 1;
  367. topPlayer.fTotalScore = GetTopScore_Score;
  368. topPlayer.nMinutesPlayed = MaxMinutes(GetTopScore_MinutesPlayed);
  369. topPlayer.cTotalBaseKills = GetTopScore_BaseKills;
  370. topPlayer.cTotalBaseCaptures = GetTopScore_BaseCaptures;
  371. topPlayer.cTotalKills = GetTopScore_Kills;
  372. topPlayer.cTotalDeaths = GetTopScore_Deaths;
  373. topPlayer.rank = GetTopScore_Rank;
  374. topPlayer.rating = RATING_EXT2DISP(GetTopScore_Rating);
  375. topPlayer.cTotalWins = GetTopScore_Wins;
  376. topPlayer.cTotalLosses = GetTopScore_Losses;
  377. topPlayer.cTotalCommanderWins = GetTopScore_CommanderWins;
  378. topPlayer.cTotalGamesPlayed = GetTopScore_GamesPlayed;
  379. }
  380. // get the players near the character in question
  381. GetNearScore_CharacterIDIn = characterId;
  382. GetNearScore_CivIDIn = civID;
  383. strcpy((char*)GetNearScore_CharacterNameIn, szName);
  384. int cResults = 0;
  385. SQL_GO(GetNearScore);
  386. while (SQL_SUCCEEDED(SQL_GETROW(GetNearScore)) && cResults < nMaxResults)
  387. {
  388. strcpy(vResults[cResults].CharacterName, (char*)GetNearScore_CharacterName);
  389. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  390. vResults[cResults].idCharacter = GetNearScore_CharacterID;
  391. vResults[cResults].nPosition = GetNearScore_FirstOrdinal + cResults;
  392. vResults[cResults].fTotalScore = GetNearScore_Score;
  393. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearScore_MinutesPlayed);
  394. vResults[cResults].cTotalBaseKills = GetNearScore_BaseKills;
  395. vResults[cResults].cTotalBaseCaptures = GetNearScore_BaseCaptures;
  396. vResults[cResults].cTotalKills = GetNearScore_Kills;
  397. vResults[cResults].cTotalDeaths = GetNearScore_Deaths;
  398. vResults[cResults].rank = GetNearScore_Rank;
  399. vResults[cResults].rating = RATING_EXT2DISP(GetNearScore_Rating);
  400. vResults[cResults].cTotalWins = GetNearScore_Wins;
  401. vResults[cResults].cTotalLosses = GetNearScore_Losses;
  402. vResults[cResults].cTotalCommanderWins = GetNearScore_CommanderWins;
  403. vResults[cResults].cTotalGamesPlayed = GetNearScore_GamesPlayed;
  404. cResults++;
  405. assert(cResults <= nMaxResults);
  406. }
  407. return cResults;
  408. }
  409. int GetResultsByTimePlayed(const char* szName, int characterId, CivID civID,
  410. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  411. {
  412. // get the top player by TimePlayed in this civ
  413. GetTopTimePlayed_CivIDIn = civID;
  414. GetTopTimePlayed_CivIDIn2 = civID;
  415. SQL_GO(GetTopTimePlayed);
  416. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopTimePlayed)))
  417. {
  418. return 0;
  419. }
  420. else
  421. {
  422. strcpy(topPlayer.CharacterName, (char*)GetTopTimePlayed_CharacterName);
  423. RemoveTrailingSpaces(topPlayer.CharacterName);
  424. topPlayer.idCharacter = GetTopTimePlayed_CharacterID;
  425. topPlayer.nPosition = 1;
  426. topPlayer.fTotalScore = GetTopTimePlayed_Score;
  427. topPlayer.nMinutesPlayed = MaxMinutes(GetTopTimePlayed_MinutesPlayed);
  428. topPlayer.cTotalBaseKills = GetTopTimePlayed_BaseKills;
  429. topPlayer.cTotalBaseCaptures = GetTopTimePlayed_BaseCaptures;
  430. topPlayer.cTotalKills = GetTopTimePlayed_Kills;
  431. topPlayer.cTotalDeaths = GetTopTimePlayed_Deaths;
  432. topPlayer.rank = GetTopTimePlayed_Rank;
  433. topPlayer.rating = RATING_EXT2DISP(GetTopTimePlayed_Rating);
  434. topPlayer.cTotalWins = GetTopTimePlayed_Wins;
  435. topPlayer.cTotalLosses = GetTopTimePlayed_Losses;
  436. topPlayer.cTotalCommanderWins = GetTopTimePlayed_CommanderWins;
  437. topPlayer.cTotalGamesPlayed = GetTopTimePlayed_GamesPlayed;
  438. }
  439. // get the players near the character in question
  440. GetNearTimePlayed_CharacterIDIn = characterId;
  441. GetNearTimePlayed_CivIDIn = civID;
  442. strcpy((char*)GetNearTimePlayed_CharacterNameIn, szName);
  443. int cResults = 0;
  444. SQL_GO(GetNearTimePlayed);
  445. while (SQL_SUCCEEDED(SQL_GETROW(GetNearTimePlayed)) && cResults < nMaxResults)
  446. {
  447. strcpy(vResults[cResults].CharacterName, (char*)GetNearTimePlayed_CharacterName);
  448. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  449. vResults[cResults].idCharacter = GetNearTimePlayed_CharacterID;
  450. vResults[cResults].nPosition = GetNearTimePlayed_FirstOrdinal + cResults;
  451. vResults[cResults].fTotalScore = GetNearTimePlayed_Score;
  452. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearTimePlayed_MinutesPlayed);
  453. vResults[cResults].cTotalBaseKills = GetNearTimePlayed_BaseKills;
  454. vResults[cResults].cTotalBaseCaptures = GetNearTimePlayed_BaseCaptures;
  455. vResults[cResults].cTotalKills = GetNearTimePlayed_Kills;
  456. vResults[cResults].cTotalDeaths = GetNearTimePlayed_Deaths;
  457. vResults[cResults].rank = GetNearTimePlayed_Rank;
  458. vResults[cResults].rating = RATING_EXT2DISP(GetNearTimePlayed_Rating);
  459. vResults[cResults].cTotalWins = GetNearTimePlayed_Wins;
  460. vResults[cResults].cTotalLosses = GetNearTimePlayed_Losses;
  461. vResults[cResults].cTotalCommanderWins = GetNearTimePlayed_CommanderWins;
  462. vResults[cResults].cTotalGamesPlayed = GetNearTimePlayed_GamesPlayed;
  463. cResults++;
  464. assert(cResults <= nMaxResults);
  465. }
  466. return cResults;
  467. }
  468. int GetResultsByBaseKills(const char* szName, int characterId, CivID civID,
  469. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  470. {
  471. // get the top player by BaseKills in this civ
  472. GetTopBaseKills_CivIDIn = civID;
  473. GetTopBaseKills_CivIDIn2 = civID;
  474. SQL_GO(GetTopBaseKills);
  475. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopBaseKills)))
  476. {
  477. return 0;
  478. }
  479. else
  480. {
  481. strcpy(topPlayer.CharacterName, (char*)GetTopBaseKills_CharacterName);
  482. RemoveTrailingSpaces(topPlayer.CharacterName);
  483. topPlayer.idCharacter = GetTopBaseKills_CharacterID;
  484. topPlayer.nPosition = 1;
  485. topPlayer.fTotalScore = GetTopBaseKills_Score;
  486. topPlayer.nMinutesPlayed = MaxMinutes(GetTopBaseKills_MinutesPlayed);
  487. topPlayer.cTotalBaseKills = GetTopBaseKills_BaseKills;
  488. topPlayer.cTotalBaseCaptures = GetTopBaseKills_BaseCaptures;
  489. topPlayer.cTotalKills = GetTopBaseKills_Kills;
  490. topPlayer.cTotalDeaths = GetTopBaseKills_Deaths;
  491. topPlayer.rank = GetTopBaseKills_Rank;
  492. topPlayer.rating = RATING_EXT2DISP(GetTopBaseKills_Rating);
  493. topPlayer.cTotalWins = GetTopBaseKills_Wins;
  494. topPlayer.cTotalLosses = GetTopBaseKills_Losses;
  495. topPlayer.cTotalCommanderWins = GetTopBaseKills_CommanderWins;
  496. topPlayer.cTotalGamesPlayed = GetTopBaseKills_GamesPlayed;
  497. }
  498. // get the players near the character in question
  499. GetNearBaseKills_CharacterIDIn = characterId;
  500. GetNearBaseKills_CivIDIn = civID;
  501. strcpy((char*)GetNearBaseKills_CharacterNameIn, szName);
  502. int cResults = 0;
  503. SQL_GO(GetNearBaseKills);
  504. while (SQL_SUCCEEDED(SQL_GETROW(GetNearBaseKills)) && cResults < nMaxResults)
  505. {
  506. strcpy(vResults[cResults].CharacterName, (char*)GetNearBaseKills_CharacterName);
  507. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  508. vResults[cResults].idCharacter = GetNearBaseKills_CharacterID;
  509. vResults[cResults].nPosition = GetNearBaseKills_FirstOrdinal + cResults;
  510. vResults[cResults].fTotalScore = GetNearBaseKills_Score;
  511. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearBaseKills_MinutesPlayed);
  512. vResults[cResults].cTotalBaseKills = GetNearBaseKills_BaseKills;
  513. vResults[cResults].cTotalBaseCaptures = GetNearBaseKills_BaseCaptures;
  514. vResults[cResults].cTotalKills = GetNearBaseKills_Kills;
  515. vResults[cResults].cTotalDeaths = GetNearBaseKills_Deaths;
  516. vResults[cResults].rank = GetNearBaseKills_Rank;
  517. vResults[cResults].rating = RATING_EXT2DISP(GetNearBaseKills_Rating);
  518. vResults[cResults].cTotalWins = GetNearBaseKills_Wins;
  519. vResults[cResults].cTotalLosses = GetNearBaseKills_Losses;
  520. vResults[cResults].cTotalCommanderWins = GetNearBaseKills_CommanderWins;
  521. vResults[cResults].cTotalGamesPlayed = GetNearBaseKills_GamesPlayed;
  522. cResults++;
  523. assert(cResults <= nMaxResults);
  524. }
  525. return cResults;
  526. }
  527. int GetResultsByBaseCaptures(const char* szName, int characterId, CivID civID,
  528. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  529. {
  530. // get the top player by BaseCaptures in this civ
  531. GetTopBaseCaptures_CivIDIn = civID;
  532. GetTopBaseCaptures_CivIDIn2 = civID;
  533. SQL_GO(GetTopBaseCaptures);
  534. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopBaseCaptures)))
  535. {
  536. return 0;
  537. }
  538. else
  539. {
  540. strcpy(topPlayer.CharacterName, (char*)GetTopBaseCaptures_CharacterName);
  541. RemoveTrailingSpaces(topPlayer.CharacterName);
  542. topPlayer.idCharacter = GetTopBaseCaptures_CharacterID;
  543. topPlayer.nPosition = 1;
  544. topPlayer.fTotalScore = GetTopBaseCaptures_Score;
  545. topPlayer.nMinutesPlayed = MaxMinutes(GetTopBaseCaptures_MinutesPlayed);
  546. topPlayer.cTotalBaseKills = GetTopBaseCaptures_BaseKills;
  547. topPlayer.cTotalBaseCaptures = GetTopBaseCaptures_BaseCaptures;
  548. topPlayer.cTotalKills = GetTopBaseCaptures_Kills;
  549. topPlayer.cTotalDeaths = GetTopBaseCaptures_Deaths;
  550. topPlayer.rank = GetTopBaseCaptures_Rank;
  551. topPlayer.rating = RATING_EXT2DISP(GetTopBaseCaptures_Rating);
  552. topPlayer.cTotalWins = GetTopBaseCaptures_Wins;
  553. topPlayer.cTotalLosses = GetTopBaseCaptures_Losses;
  554. topPlayer.cTotalCommanderWins = GetTopBaseCaptures_CommanderWins;
  555. topPlayer.cTotalGamesPlayed = GetTopBaseCaptures_GamesPlayed;
  556. }
  557. // get the players near the character in question
  558. GetNearBaseCaptures_CharacterIDIn = characterId;
  559. GetNearBaseCaptures_CivIDIn = civID;
  560. strcpy((char*)GetNearBaseCaptures_CharacterNameIn, szName);
  561. int cResults = 0;
  562. SQL_GO(GetNearBaseCaptures);
  563. while (SQL_SUCCEEDED(SQL_GETROW(GetNearBaseCaptures)) && cResults < nMaxResults)
  564. {
  565. strcpy(vResults[cResults].CharacterName, (char*)GetNearBaseCaptures_CharacterName);
  566. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  567. vResults[cResults].idCharacter = GetNearBaseCaptures_CharacterID;
  568. vResults[cResults].nPosition = GetNearBaseCaptures_FirstOrdinal + cResults;
  569. vResults[cResults].fTotalScore = GetNearBaseCaptures_Score;
  570. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearBaseCaptures_MinutesPlayed);
  571. vResults[cResults].cTotalBaseKills = GetNearBaseCaptures_BaseKills;
  572. vResults[cResults].cTotalBaseCaptures = GetNearBaseCaptures_BaseCaptures;
  573. vResults[cResults].cTotalKills = GetNearBaseCaptures_Kills;
  574. vResults[cResults].cTotalDeaths = GetNearBaseCaptures_Deaths;
  575. vResults[cResults].rank = GetNearBaseCaptures_Rank;
  576. vResults[cResults].rating = RATING_EXT2DISP(GetNearBaseCaptures_Rating);
  577. vResults[cResults].cTotalWins = GetNearBaseCaptures_Wins;
  578. vResults[cResults].cTotalLosses = GetNearBaseCaptures_Losses;
  579. vResults[cResults].cTotalCommanderWins = GetNearBaseCaptures_CommanderWins;
  580. vResults[cResults].cTotalGamesPlayed = GetNearBaseCaptures_GamesPlayed;
  581. cResults++;
  582. assert(cResults <= nMaxResults);
  583. }
  584. return cResults;
  585. }
  586. int GetResultsByKills(const char* szName, int characterId, CivID civID,
  587. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  588. {
  589. // get the top player by Kills in this civ
  590. GetTopKills_CivIDIn = civID;
  591. GetTopKills_CivIDIn2 = civID;
  592. SQL_GO(GetTopKills);
  593. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopKills)))
  594. {
  595. return 0;
  596. }
  597. else
  598. {
  599. strcpy(topPlayer.CharacterName, (char*)GetTopKills_CharacterName);
  600. RemoveTrailingSpaces(topPlayer.CharacterName);
  601. topPlayer.idCharacter = GetTopKills_CharacterID;
  602. topPlayer.nPosition = 1;
  603. topPlayer.fTotalScore = GetTopKills_Score;
  604. topPlayer.nMinutesPlayed = MaxMinutes(GetTopKills_MinutesPlayed);
  605. topPlayer.cTotalBaseKills = GetTopKills_BaseKills;
  606. topPlayer.cTotalBaseCaptures = GetTopKills_BaseCaptures;
  607. topPlayer.cTotalKills = GetTopKills_Kills;
  608. topPlayer.cTotalDeaths = GetTopKills_Deaths;
  609. topPlayer.rank = GetTopKills_Rank;
  610. topPlayer.rating = RATING_EXT2DISP(GetTopKills_Rating);
  611. topPlayer.cTotalWins = GetTopKills_Wins;
  612. topPlayer.cTotalLosses = GetTopKills_Losses;
  613. topPlayer.cTotalCommanderWins = GetTopKills_CommanderWins;
  614. topPlayer.cTotalGamesPlayed = GetTopKills_GamesPlayed;
  615. }
  616. // get the players near the character in question
  617. GetNearKills_CharacterIDIn = characterId;
  618. GetNearKills_CivIDIn = civID;
  619. strcpy((char*)GetNearKills_CharacterNameIn, szName);
  620. int cResults = 0;
  621. SQL_GO(GetNearKills);
  622. while (SQL_SUCCEEDED(SQL_GETROW(GetNearKills)) && cResults < nMaxResults)
  623. {
  624. strcpy(vResults[cResults].CharacterName, (char*)GetNearKills_CharacterName);
  625. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  626. vResults[cResults].idCharacter = GetNearKills_CharacterID;
  627. vResults[cResults].nPosition = GetNearKills_FirstOrdinal + cResults;
  628. vResults[cResults].fTotalScore = GetNearKills_Score;
  629. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearKills_MinutesPlayed);
  630. vResults[cResults].cTotalBaseKills = GetNearKills_BaseKills;
  631. vResults[cResults].cTotalBaseCaptures = GetNearKills_BaseCaptures;
  632. vResults[cResults].cTotalKills = GetNearKills_Kills;
  633. vResults[cResults].cTotalDeaths = GetNearKills_Deaths;
  634. vResults[cResults].rank = GetNearKills_Rank;
  635. vResults[cResults].rating = RATING_EXT2DISP(GetNearKills_Rating);
  636. vResults[cResults].cTotalWins = GetNearKills_Wins;
  637. vResults[cResults].cTotalLosses = GetNearKills_Losses;
  638. vResults[cResults].cTotalCommanderWins = GetNearKills_CommanderWins;
  639. vResults[cResults].cTotalGamesPlayed = GetNearKills_GamesPlayed;
  640. cResults++;
  641. assert(cResults <= nMaxResults);
  642. }
  643. return cResults;
  644. }
  645. int GetResultsByDeaths(const char* szName, int characterId, CivID civID,
  646. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  647. {
  648. // get the top player by Deaths in this civ
  649. GetTopDeaths_CivIDIn = civID;
  650. GetTopDeaths_CivIDIn2 = civID;
  651. SQL_GO(GetTopDeaths);
  652. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopDeaths)))
  653. {
  654. return 0;
  655. }
  656. else
  657. {
  658. strcpy(topPlayer.CharacterName, (char*)GetTopDeaths_CharacterName);
  659. RemoveTrailingSpaces(topPlayer.CharacterName);
  660. topPlayer.idCharacter = GetTopDeaths_CharacterID;
  661. topPlayer.nPosition = 1;
  662. topPlayer.fTotalScore = GetTopDeaths_Score;
  663. topPlayer.nMinutesPlayed = MaxMinutes(GetTopDeaths_MinutesPlayed);
  664. topPlayer.cTotalBaseKills = GetTopDeaths_BaseKills;
  665. topPlayer.cTotalBaseCaptures = GetTopDeaths_BaseCaptures;
  666. topPlayer.cTotalKills = GetTopDeaths_Kills;
  667. topPlayer.cTotalDeaths = GetTopDeaths_Deaths;
  668. topPlayer.rank = GetTopDeaths_Rank;
  669. topPlayer.rating = RATING_EXT2DISP(GetTopDeaths_Rating);
  670. topPlayer.cTotalWins = GetTopDeaths_Wins;
  671. topPlayer.cTotalLosses = GetTopDeaths_Losses;
  672. topPlayer.cTotalCommanderWins = GetTopDeaths_CommanderWins;
  673. topPlayer.cTotalGamesPlayed = GetTopDeaths_GamesPlayed;
  674. }
  675. // get the players near the character in question
  676. GetNearDeaths_CharacterIDIn = characterId;
  677. GetNearDeaths_CivIDIn = civID;
  678. strcpy((char*)GetNearDeaths_CharacterNameIn, szName);
  679. int cResults = 0;
  680. SQL_GO(GetNearDeaths);
  681. while (SQL_SUCCEEDED(SQL_GETROW(GetNearDeaths)) && cResults < nMaxResults)
  682. {
  683. strcpy(vResults[cResults].CharacterName, (char*)GetNearDeaths_CharacterName);
  684. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  685. vResults[cResults].idCharacter = GetNearDeaths_CharacterID;
  686. vResults[cResults].nPosition = GetNearDeaths_FirstOrdinal + cResults;
  687. vResults[cResults].fTotalScore = GetNearDeaths_Score;
  688. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearDeaths_MinutesPlayed);
  689. vResults[cResults].cTotalBaseKills = GetNearDeaths_BaseKills;
  690. vResults[cResults].cTotalBaseCaptures = GetNearDeaths_BaseCaptures;
  691. vResults[cResults].cTotalKills = GetNearDeaths_Kills;
  692. vResults[cResults].cTotalDeaths = GetNearDeaths_Deaths;
  693. vResults[cResults].rank = GetNearDeaths_Rank;
  694. vResults[cResults].rating = RATING_EXT2DISP(GetNearDeaths_Rating);
  695. vResults[cResults].cTotalWins = GetNearDeaths_Wins;
  696. vResults[cResults].cTotalLosses = GetNearDeaths_Losses;
  697. vResults[cResults].cTotalCommanderWins = GetNearDeaths_CommanderWins;
  698. vResults[cResults].cTotalGamesPlayed = GetNearDeaths_GamesPlayed;
  699. cResults++;
  700. assert(cResults <= nMaxResults);
  701. }
  702. return cResults;
  703. }
  704. int GetResultsByGamesPlayed(const char* szName, int characterId, CivID civID,
  705. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  706. {
  707. // get the top player by GamesPlayed in this civ
  708. GetTopGamesPlayed_CivIDIn = civID;
  709. GetTopGamesPlayed_CivIDIn2 = civID;
  710. SQL_GO(GetTopGamesPlayed);
  711. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopGamesPlayed)))
  712. {
  713. return 0;
  714. }
  715. else
  716. {
  717. strcpy(topPlayer.CharacterName, (char*)GetTopGamesPlayed_CharacterName);
  718. RemoveTrailingSpaces(topPlayer.CharacterName);
  719. topPlayer.idCharacter = GetTopGamesPlayed_CharacterID;
  720. topPlayer.nPosition = 1;
  721. topPlayer.fTotalScore = GetTopGamesPlayed_Score;
  722. topPlayer.nMinutesPlayed = MaxMinutes(GetTopGamesPlayed_MinutesPlayed);
  723. topPlayer.cTotalBaseKills = GetTopGamesPlayed_BaseKills;
  724. topPlayer.cTotalBaseCaptures = GetTopGamesPlayed_BaseCaptures;
  725. topPlayer.cTotalKills = GetTopGamesPlayed_Kills;
  726. topPlayer.cTotalDeaths = GetTopGamesPlayed_Deaths;
  727. topPlayer.rank = GetTopGamesPlayed_Rank;
  728. topPlayer.rating = RATING_EXT2DISP(GetTopGamesPlayed_Rating);
  729. topPlayer.cTotalWins = GetTopGamesPlayed_Wins;
  730. topPlayer.cTotalLosses = GetTopGamesPlayed_Losses;
  731. topPlayer.cTotalCommanderWins = GetTopGamesPlayed_CommanderWins;
  732. topPlayer.cTotalGamesPlayed = GetTopGamesPlayed_GamesPlayed;
  733. }
  734. // get the players near the character in question
  735. GetNearGamesPlayed_CharacterIDIn = characterId;
  736. GetNearGamesPlayed_CivIDIn = civID;
  737. strcpy((char*)GetNearGamesPlayed_CharacterNameIn, szName);
  738. int cResults = 0;
  739. SQL_GO(GetNearGamesPlayed);
  740. while (SQL_SUCCEEDED(SQL_GETROW(GetNearGamesPlayed)) && cResults < nMaxResults)
  741. {
  742. strcpy(vResults[cResults].CharacterName, (char*)GetNearGamesPlayed_CharacterName);
  743. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  744. vResults[cResults].idCharacter = GetNearGamesPlayed_CharacterID;
  745. vResults[cResults].nPosition = GetNearGamesPlayed_FirstOrdinal + cResults;
  746. vResults[cResults].fTotalScore = GetNearGamesPlayed_Score;
  747. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearGamesPlayed_MinutesPlayed);
  748. vResults[cResults].cTotalBaseKills = GetNearGamesPlayed_BaseKills;
  749. vResults[cResults].cTotalBaseCaptures = GetNearGamesPlayed_BaseCaptures;
  750. vResults[cResults].cTotalKills = GetNearGamesPlayed_Kills;
  751. vResults[cResults].cTotalDeaths = GetNearGamesPlayed_Deaths;
  752. vResults[cResults].rank = GetNearGamesPlayed_Rank;
  753. vResults[cResults].rating = RATING_EXT2DISP(GetNearGamesPlayed_Rating);
  754. vResults[cResults].cTotalWins = GetNearGamesPlayed_Wins;
  755. vResults[cResults].cTotalLosses = GetNearGamesPlayed_Losses;
  756. vResults[cResults].cTotalCommanderWins = GetNearGamesPlayed_CommanderWins;
  757. vResults[cResults].cTotalGamesPlayed = GetNearGamesPlayed_GamesPlayed;
  758. cResults++;
  759. assert(cResults <= nMaxResults);
  760. }
  761. return cResults;
  762. }
  763. int GetResultsByWins(const char* szName, int characterId, CivID civID,
  764. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  765. {
  766. // get the top player by Wins in this civ
  767. GetTopWins_CivIDIn = civID;
  768. GetTopWins_CivIDIn2 = civID;
  769. SQL_GO(GetTopWins);
  770. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopWins)))
  771. {
  772. return 0;
  773. }
  774. else
  775. {
  776. strcpy(topPlayer.CharacterName, (char*)GetTopWins_CharacterName);
  777. RemoveTrailingSpaces(topPlayer.CharacterName);
  778. topPlayer.idCharacter = GetTopWins_CharacterID;
  779. topPlayer.nPosition = 1;
  780. topPlayer.fTotalScore = GetTopWins_Score;
  781. topPlayer.nMinutesPlayed = MaxMinutes(GetTopWins_MinutesPlayed);
  782. topPlayer.cTotalBaseKills = GetTopWins_BaseKills;
  783. topPlayer.cTotalBaseCaptures = GetTopWins_BaseCaptures;
  784. topPlayer.cTotalKills = GetTopWins_Kills;
  785. topPlayer.cTotalDeaths = GetTopWins_Deaths;
  786. topPlayer.rank = GetTopWins_Rank;
  787. topPlayer.rating = RATING_EXT2DISP(GetTopWins_Rating);
  788. topPlayer.cTotalWins = GetTopWins_Wins;
  789. topPlayer.cTotalLosses = GetTopWins_Losses;
  790. topPlayer.cTotalCommanderWins = GetTopWins_CommanderWins;
  791. topPlayer.cTotalGamesPlayed = GetTopWins_GamesPlayed;
  792. }
  793. // get the players near the character in question
  794. GetNearWins_CharacterIDIn = characterId;
  795. GetNearWins_CivIDIn = civID;
  796. strcpy((char*)GetNearWins_CharacterNameIn, szName);
  797. int cResults = 0;
  798. SQL_GO(GetNearWins);
  799. while (SQL_SUCCEEDED(SQL_GETROW(GetNearWins)) && cResults < nMaxResults)
  800. {
  801. strcpy(vResults[cResults].CharacterName, (char*)GetNearWins_CharacterName);
  802. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  803. vResults[cResults].idCharacter = GetNearWins_CharacterID;
  804. vResults[cResults].nPosition = GetNearWins_FirstOrdinal + cResults;
  805. vResults[cResults].fTotalScore = GetNearWins_Score;
  806. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearWins_MinutesPlayed);
  807. vResults[cResults].cTotalBaseKills = GetNearWins_BaseKills;
  808. vResults[cResults].cTotalBaseCaptures = GetNearWins_BaseCaptures;
  809. vResults[cResults].cTotalKills = GetNearWins_Kills;
  810. vResults[cResults].cTotalDeaths = GetNearWins_Deaths;
  811. vResults[cResults].rank = GetNearWins_Rank;
  812. vResults[cResults].rating = RATING_EXT2DISP(GetNearWins_Rating);
  813. vResults[cResults].cTotalWins = GetNearWins_Wins;
  814. vResults[cResults].cTotalLosses = GetNearWins_Losses;
  815. vResults[cResults].cTotalCommanderWins = GetNearWins_CommanderWins;
  816. vResults[cResults].cTotalGamesPlayed = GetNearWins_GamesPlayed;
  817. cResults++;
  818. assert(cResults <= nMaxResults);
  819. }
  820. return cResults;
  821. }
  822. int GetResultsByLosses(const char* szName, int characterId, CivID civID,
  823. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  824. {
  825. // get the top player by Losses in this civ
  826. GetTopLosses_CivIDIn = civID;
  827. GetTopLosses_CivIDIn2 = civID;
  828. SQL_GO(GetTopLosses);
  829. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopLosses)))
  830. {
  831. return 0;
  832. }
  833. else
  834. {
  835. strcpy(topPlayer.CharacterName, (char*)GetTopLosses_CharacterName);
  836. RemoveTrailingSpaces(topPlayer.CharacterName);
  837. topPlayer.idCharacter = GetTopLosses_CharacterID;
  838. topPlayer.nPosition = 1;
  839. topPlayer.fTotalScore = GetTopLosses_Score;
  840. topPlayer.nMinutesPlayed = MaxMinutes(GetTopLosses_MinutesPlayed);
  841. topPlayer.cTotalBaseKills = GetTopLosses_BaseKills;
  842. topPlayer.cTotalBaseCaptures = GetTopLosses_BaseCaptures;
  843. topPlayer.cTotalKills = GetTopLosses_Kills;
  844. topPlayer.cTotalDeaths = GetTopLosses_Deaths;
  845. topPlayer.rank = GetTopLosses_Rank;
  846. topPlayer.rating = RATING_EXT2DISP(GetTopLosses_Rating);
  847. topPlayer.cTotalWins = GetTopLosses_Wins;
  848. topPlayer.cTotalLosses = GetTopLosses_Losses;
  849. topPlayer.cTotalCommanderWins = GetTopLosses_CommanderWins;
  850. topPlayer.cTotalGamesPlayed = GetTopLosses_GamesPlayed;
  851. }
  852. // get the players near the character in question
  853. GetNearLosses_CharacterIDIn = characterId;
  854. GetNearLosses_CivIDIn = civID;
  855. strcpy((char*)GetNearLosses_CharacterNameIn, szName);
  856. int cResults = 0;
  857. SQL_GO(GetNearLosses);
  858. while (SQL_SUCCEEDED(SQL_GETROW(GetNearLosses)) && cResults < nMaxResults)
  859. {
  860. strcpy(vResults[cResults].CharacterName, (char*)GetNearLosses_CharacterName);
  861. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  862. vResults[cResults].idCharacter = GetNearLosses_CharacterID;
  863. vResults[cResults].nPosition = GetNearLosses_FirstOrdinal + cResults;
  864. vResults[cResults].fTotalScore = GetNearLosses_Score;
  865. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearLosses_MinutesPlayed);
  866. vResults[cResults].cTotalBaseKills = GetNearLosses_BaseKills;
  867. vResults[cResults].cTotalBaseCaptures = GetNearLosses_BaseCaptures;
  868. vResults[cResults].cTotalKills = GetNearLosses_Kills;
  869. vResults[cResults].cTotalDeaths = GetNearLosses_Deaths;
  870. vResults[cResults].rank = GetNearLosses_Rank;
  871. vResults[cResults].rating = RATING_EXT2DISP(GetNearLosses_Rating);
  872. vResults[cResults].cTotalWins = GetNearLosses_Wins;
  873. vResults[cResults].cTotalLosses = GetNearLosses_Losses;
  874. vResults[cResults].cTotalCommanderWins = GetNearLosses_CommanderWins;
  875. vResults[cResults].cTotalGamesPlayed = GetNearLosses_GamesPlayed;
  876. cResults++;
  877. assert(cResults <= nMaxResults);
  878. }
  879. return cResults;
  880. }
  881. int GetResultsByCommanderWins(const char* szName, int characterId, CivID civID,
  882. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  883. {
  884. // get the top player by CommanderWins in this civ
  885. GetTopCommanderWins_CivIDIn = civID;
  886. GetTopCommanderWins_CivIDIn2 = civID;
  887. SQL_GO(GetTopCommanderWins);
  888. if (!SQL_SUCCEEDED(SQL_GETROW(GetTopCommanderWins)))
  889. {
  890. return 0;
  891. }
  892. else
  893. {
  894. strcpy(topPlayer.CharacterName, (char*)GetTopCommanderWins_CharacterName);
  895. RemoveTrailingSpaces(topPlayer.CharacterName);
  896. topPlayer.idCharacter = GetTopCommanderWins_CharacterID;
  897. topPlayer.nPosition = 1;
  898. topPlayer.fTotalScore = GetTopCommanderWins_Score;
  899. topPlayer.nMinutesPlayed = MaxMinutes(GetTopCommanderWins_MinutesPlayed);
  900. topPlayer.cTotalBaseKills = GetTopCommanderWins_BaseKills;
  901. topPlayer.cTotalBaseCaptures = GetTopCommanderWins_BaseCaptures;
  902. topPlayer.cTotalKills = GetTopCommanderWins_Kills;
  903. topPlayer.cTotalDeaths = GetTopCommanderWins_Deaths;
  904. topPlayer.rank = GetTopCommanderWins_Rank;
  905. topPlayer.rating = RATING_EXT2DISP(GetTopCommanderWins_Rating);
  906. topPlayer.cTotalWins = GetTopCommanderWins_Wins;
  907. topPlayer.cTotalLosses = GetTopCommanderWins_Losses;
  908. topPlayer.cTotalCommanderWins = GetTopCommanderWins_CommanderWins;
  909. topPlayer.cTotalGamesPlayed = GetTopCommanderWins_GamesPlayed;
  910. }
  911. // get the players near the character in question
  912. GetNearCommanderWins_CharacterIDIn = characterId;
  913. GetNearCommanderWins_CivIDIn = civID;
  914. strcpy((char*)GetNearCommanderWins_CharacterNameIn, szName);
  915. int cResults = 0;
  916. SQL_GO(GetNearCommanderWins);
  917. while (SQL_SUCCEEDED(SQL_GETROW(GetNearCommanderWins)) && cResults < nMaxResults)
  918. {
  919. strcpy(vResults[cResults].CharacterName, (char*)GetNearCommanderWins_CharacterName);
  920. RemoveTrailingSpaces(vResults[cResults].CharacterName);
  921. vResults[cResults].idCharacter = GetNearCommanderWins_CharacterID;
  922. vResults[cResults].nPosition = GetNearCommanderWins_FirstOrdinal + cResults;
  923. vResults[cResults].fTotalScore = GetNearCommanderWins_Score;
  924. vResults[cResults].nMinutesPlayed = MaxMinutes(GetNearCommanderWins_MinutesPlayed);
  925. vResults[cResults].cTotalBaseKills = GetNearCommanderWins_BaseKills;
  926. vResults[cResults].cTotalBaseCaptures = GetNearCommanderWins_BaseCaptures;
  927. vResults[cResults].cTotalKills = GetNearCommanderWins_Kills;
  928. vResults[cResults].cTotalDeaths = GetNearCommanderWins_Deaths;
  929. vResults[cResults].rank = GetNearCommanderWins_Rank;
  930. vResults[cResults].rating = RATING_EXT2DISP(GetNearCommanderWins_Rating);
  931. vResults[cResults].cTotalWins = GetNearCommanderWins_Wins;
  932. vResults[cResults].cTotalLosses = GetNearCommanderWins_Losses;
  933. vResults[cResults].cTotalCommanderWins = GetNearCommanderWins_CommanderWins;
  934. vResults[cResults].cTotalGamesPlayed = GetNearCommanderWins_GamesPlayed;
  935. cResults++;
  936. assert(cResults <= nMaxResults);
  937. }
  938. return cResults;
  939. }
  940. int GetResults(LeaderBoardSort sort, const char* szName, int characterId, CivID civID,
  941. LeaderBoardEntry& topPlayer, LeaderBoardEntry* vResults, int nMaxResults)
  942. {
  943. switch (sort)
  944. {
  945. default:
  946. assert(false);
  947. return 0;
  948. case lbSortName:
  949. return GetResultsByName(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  950. case lbSortRank:
  951. return GetResultsByRank(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  952. case lbSortRating:
  953. return GetResultsByRating(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  954. case lbSortScore:
  955. return GetResultsByScore(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  956. case lbSortTimePlayed:
  957. return GetResultsByTimePlayed(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  958. case lbSortBaseKills:
  959. return GetResultsByBaseKills(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  960. case lbSortBaseCaptures:
  961. return GetResultsByBaseCaptures(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  962. case lbSortKills:
  963. return GetResultsByKills(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  964. case lbSortGamesPlayed:
  965. return GetResultsByGamesPlayed(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  966. case lbSortDeaths:
  967. return GetResultsByDeaths(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  968. case lbSortWins:
  969. return GetResultsByWins(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  970. case lbSortLosses:
  971. return GetResultsByLosses(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  972. case lbSortCommanderWins:
  973. return GetResultsByCommanderWins(szName, characterId, civID, topPlayer, vResults, nMaxResults);
  974. }
  975. }
  976. void CheckRankInfo()
  977. {
  978. if (!g_pClubApp->GetRankInfo())
  979. {
  980. // Load the ranking info
  981. SQL_GO(GetRankCount);
  982. SQL_GETROW(GetRankCount);
  983. RankInfo* vRankInfo = NULL;
  984. if (GetRankCount_Count > 0)
  985. {
  986. vRankInfo = new RankInfo[GetRankCount_Count];
  987. SQL_GO(GetRanks);
  988. for (int i = 0; i < GetRankCount_Count; i++)
  989. {
  990. ZVerify(SQL_SUCCEEDED(SQL_GETROW(GetRanks)));
  991. vRankInfo[i].civ = GetRanks_CivID;
  992. vRankInfo[i].rank = GetRanks_Rank;
  993. vRankInfo[i].requiredRanking = GetRanks_Requirement;
  994. strcpy(vRankInfo[i].RankName, (char*)GetRanks_Name);
  995. }
  996. }
  997. g_pClubApp->SetRankInfo(vRankInfo, GetRankCount_Count);
  998. }
  999. }
  1000. int GetNextPromotion(CivID civID, float fScore)
  1001. {
  1002. // search through the rank table to find the first rank with a score requirement greater than
  1003. // the current score.
  1004. for (int nRankIndex = 0; nRankIndex < g_pClubApp->GetRankInfoCount(); ++nRankIndex)
  1005. {
  1006. RankInfo& rankinfo = g_pClubApp->GetRankInfo()[nRankIndex];
  1007. if (rankinfo.civ == civID && rankinfo.requiredRanking > fScore)
  1008. return rankinfo.requiredRanking;
  1009. }
  1010. return 0;
  1011. }
  1012. };
  1013. //////////////////////////////////////////////////////////////////////////////////////////
  1014. //
  1015. // SendSquadPage()
  1016. //
  1017. //////////////////////////////////////////////////////////////////////////////////////////
  1018. void SendSquadPage(FedMessaging * pthis, CFMConnection & cnxnFrom, SQUAD_SORT_COLUMN column, int nSquadID)
  1019. {
  1020. // let's not crash the server
  1021. if (column <= SSC_UNKNOWN || column >= SSC_MAX-1) // TODO: remove -1 once Hours sort works
  1022. return;
  1023. // setup query
  1024. SquadGetNear_INPUT_Column = column;
  1025. SquadGetNear_INPUT_SquadID = nSquadID;
  1026. int i = 0;
  1027. SQL_GO(SquadGetNear);
  1028. while(SQL_SUCCEEDED(SQL_GETROW(SquadGetNear)))
  1029. {
  1030. {
  1031. BEGIN_PFM_CREATE(*pthis, pfmInfo, S, SQUAD_INFO)
  1032. FM_VAR_PARM(SquadGetNear_Name, CB_ZTS)
  1033. END_PFM_CREATE
  1034. pfmInfo->bSearchResult= false;
  1035. pfmInfo->nSquadID = SquadGetNear_SquadID;
  1036. pfmInfo->nRanking = SquadGetNear_Ranking + i++;
  1037. pfmInfo->column = (char)column;
  1038. pfmInfo->nScore = SquadGetNear_Score;
  1039. pfmInfo->cWins = SquadGetNear_Wins;
  1040. pfmInfo->cLosses = SquadGetNear_Losses;
  1041. // pfmInfo->fHours = 0.0f; // TODO
  1042. }
  1043. }
  1044. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1045. }
  1046. //////////////////////////////////////////////////////////////////////////////////////////
  1047. //
  1048. // SendSquadPageDudeX()
  1049. //
  1050. //
  1051. //////////////////////////////////////////////////////////////////////////////////////////
  1052. void SendSquadPageDudeX(FedMessaging * pthis, CFMConnection & cnxnFrom, int nCharacterID, bool bMyTab)
  1053. {
  1054. // setup query
  1055. SquadGetNearDudeX_INPUT_CharacterID = nCharacterID;
  1056. SQL_GO(SquadGetNearDudeX);
  1057. while(SQL_SUCCEEDED(SQL_GETROW(SquadGetNearDudeX)))
  1058. {
  1059. {
  1060. BEGIN_PFM_CREATE(*pthis, pfmInfo, S, SQUAD_INFO_DUDEX)
  1061. FM_VAR_PARM(SquadGetNearDudeX_Name, CB_ZTS)
  1062. END_PFM_CREATE
  1063. pfmInfo->nSquadID = SquadGetNearDudeX_SquadID;
  1064. pfmInfo->nScore = SquadGetNearDudeX_Score;
  1065. pfmInfo->cWins = SquadGetNearDudeX_Wins;
  1066. pfmInfo->cLosses = SquadGetNearDudeX_Losses;
  1067. pfmInfo->bMyTab = bMyTab;
  1068. // pfmInfo->fHours = 0.0f; // TODO
  1069. }
  1070. }
  1071. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1072. }
  1073. //////////////////////////////////////////////////////////////////////////////////////////
  1074. //
  1075. // SendSquadPage_FromFind():
  1076. //
  1077. // szName: partial name to search for
  1078. //
  1079. //////////////////////////////////////////////////////////////////////////////////////////
  1080. void SendSquadPage_FromFind(FedMessaging * pthis, CFMConnection & cnxnFrom, char * szName)
  1081. {
  1082. if (!szName)
  1083. return;
  1084. if (strlen(szName) > c_cbNameDB) // keep hackers from crashing server
  1085. return;
  1086. // setup query
  1087. lstrcpy((char*)SquadGetNearFromFind_INPUT_Name, szName);
  1088. int i = 0;
  1089. SQL_GO(SquadGetNearFromFind);
  1090. while(SQL_SUCCEEDED(SQL_GETROW(SquadGetNearFromFind)))
  1091. {
  1092. {
  1093. RemoveTrailingSpaces((char*)SquadGetNearFromFind_Name);
  1094. BEGIN_PFM_CREATE(*pthis, pfmInfo, S, SQUAD_INFO)
  1095. FM_VAR_PARM(SquadGetNearFromFind_Name, CB_ZTS)
  1096. END_PFM_CREATE
  1097. pfmInfo->bSearchResult= true;
  1098. pfmInfo->nSquadID = SquadGetNearFromFind_SquadID;
  1099. pfmInfo->nRanking = SquadGetNearFromFind_Ranking + i++;
  1100. pfmInfo->column = 1;
  1101. pfmInfo->nScore = SquadGetNearFromFind_Score;
  1102. pfmInfo->cWins = SquadGetNearFromFind_Wins;
  1103. pfmInfo->cLosses = SquadGetNearFromFind_Losses;
  1104. // pfmInfo->fHours = 0.0f; // TODO
  1105. }
  1106. }
  1107. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1108. }
  1109. //////////////////////////////////////////////////////////////////////////////////////////
  1110. //
  1111. // SendSquadDetails(): sends most the details about a squad to the client
  1112. //
  1113. //////////////////////////////////////////////////////////////////////////////////////////
  1114. void SendSquadDetails(FedMessaging * pthis, CFMConnection & cnxnFrom, int nSquadID)
  1115. {
  1116. char szDate[9];
  1117. SquadDetails_INPUT_SquadID = nSquadID;
  1118. SquadDetailsPlayers_INPUT_SquadID = nSquadID;
  1119. SquadDetails_CivID = -1;
  1120. SQL_GO(SquadDetails);
  1121. if(SQL_SUCCEEDED(SQL_GETROW(SquadDetails)))
  1122. {
  1123. {
  1124. wsprintf(szDate, "%2d/%2d/%02d", SquadDetails_InceptionDate.month,
  1125. SquadDetails_InceptionDate.day,
  1126. SquadDetails_InceptionDate.year%100);
  1127. //int SquadDetails_Rank = 0; // temp
  1128. BEGIN_PFM_CREATE(*pthis, pfmInfo, S, SQUAD_DETAILS)
  1129. FM_VAR_PARM(SquadDetails_Description, CB_ZTS)
  1130. FM_VAR_PARM(SquadDetails_URL, CB_ZTS)
  1131. FM_VAR_PARM(szDate, CB_ZTS)
  1132. END_PFM_CREATE
  1133. // pfmInfo->sqRank = (ISquadBase::Rank) SquadDetails_Rank;
  1134. pfmInfo->nSquadID = SquadDetails_INPUT_SquadID;
  1135. pfmInfo->civid = SquadDetails_CivID;
  1136. }
  1137. SquadDetailsPlayers_Status2 = 0; // set to zero incase result of null
  1138. SquadDetailsPlayers_Status = 1;
  1139. SQL_GO(SquadDetailsPlayers);
  1140. while(SQL_SUCCEEDED(SQL_GETROW(SquadDetailsPlayers)))
  1141. {
  1142. {
  1143. wsprintf(szDate, "%2d/%2d/%02d", SquadDetailsPlayers_Granted.month,
  1144. SquadDetailsPlayers_Granted.day,
  1145. SquadDetailsPlayers_Granted.year%100);
  1146. BEGIN_PFM_CREATE(*pthis, pfmInfo, S, SQUAD_DETAILS_PLAYER)
  1147. FM_VAR_PARM(SquadDetailsPlayers_MemberName, CB_ZTS)
  1148. FM_VAR_PARM(szDate, CB_ZTS)
  1149. END_PFM_CREATE
  1150. pfmInfo->nMemberID = SquadDetailsPlayers_MemberID;
  1151. pfmInfo->sqRank = (IMemberBase::Rank) SquadDetailsPlayers_Rank;
  1152. if (SquadDetailsPlayers_Status == 0) // 0 == leader
  1153. {
  1154. pfmInfo->detailedstatus = IMemberBase::DSTAT_LEADER;
  1155. }
  1156. else
  1157. if (SquadDetailsPlayers_Status == 2) // 2 == pending
  1158. {
  1159. pfmInfo->detailedstatus = IMemberBase::DSTAT_PENDING;
  1160. }
  1161. else // (SquadDetailsPlayers_Status == 1)
  1162. {
  1163. if (SquadDetailsPlayers_Status2 == 1)
  1164. pfmInfo->detailedstatus = IMemberBase::DSTAT_ASL;
  1165. else
  1166. pfmInfo->detailedstatus = IMemberBase::DSTAT_MEMBER;
  1167. }
  1168. SquadDetailsPlayers_Status2 = 0; // set to zero incase result of null
  1169. SquadDetailsPlayers_Status = 1;
  1170. }
  1171. }
  1172. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1173. }
  1174. else
  1175. {
  1176. // let client know that the squad has ve 86-ed; this sometimes happens
  1177. // if our database is not in sync with theirs. The SquadDetails should
  1178. // have updated our database (that is deleted this squad from it).
  1179. BEGIN_PFM_CREATE(*pthis, pfmDeleted, S, SQUAD_DELETED)
  1180. END_PFM_CREATE
  1181. pfmDeleted->nSquadID = nSquadID;
  1182. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1183. }
  1184. }
  1185. //////////////////////////////////////////////////////////////////////////////////////////
  1186. //
  1187. // SendSquadTextMessage(): sends a text message to the user at the squads screen.
  1188. // this msg, which is usually an error, is displayed on the user's
  1189. // end as a dialog text box.
  1190. //
  1191. //////////////////////////////////////////////////////////////////////////////////////////
  1192. void SendSquadTextMessage(FedMessaging * pthis, CFMConnection & cnxnFrom, const char* format, ...)
  1193. {
  1194. const size_t size = 256;
  1195. char bfr[size];
  1196. va_list vl;
  1197. va_start(vl, format);
  1198. _vsnprintf(bfr, size, format, vl);
  1199. va_end(vl);
  1200. BEGIN_PFM_CREATE(*pthis, pfmSquadTextMessage, S, SQUAD_TEXT_MESSAGE)
  1201. FM_VAR_PARM(bfr, CB_ZTS)
  1202. END_PFM_CREATE
  1203. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1204. }
  1205. HRESULT IClubClientSite::OnAppMessage(FedMessaging * pthis, CFMConnection & cnxnFrom, FEDMESSAGE * pfm)
  1206. {
  1207. CFLClient * pClient = CFLClient::FromConnection(cnxnFrom);
  1208. assert(pClient);
  1209. char szBuffer[128];
  1210. debugf("Client: %s from <%s> at time %u\n", g_rgszMsgNames[pfm->fmid], cnxnFrom.GetName(), Time::Now());
  1211. switch (pfm->fmid)
  1212. {
  1213. case FM_C_LOGON_CLUB:
  1214. {
  1215. CASTPFM(pfmLogon, C, LOGON_CLUB, pfm);
  1216. bool fValid = false; // whether we have a valid logon
  1217. bool fRetry = false; // whether or not the client should retry the login
  1218. char * szReason = NULL; // when fValid==false
  1219. //
  1220. // TODO: If a new person logs on and they are not in the database, we need to add a record for them (or maybe report error).
  1221. //
  1222. // verify messaging version
  1223. if(pfmLogon->verClub != ALLCLUBVER)
  1224. {
  1225. // tell client that his version is wrong
  1226. sprintf(szBuffer, "AllClub Server's 'ClubMessaging' version (%i) is different than Client's version (%i)", ALLCLUBVER, pfmLogon->verClub);
  1227. szReason = szBuffer;
  1228. }
  1229. else
  1230. {
  1231. LPBYTE pZoneTicket = (LPBYTE) FM_VAR_REF(pfmLogon, ZoneTicket);
  1232. if (pZoneTicket) // it's all in the Zone Ticket
  1233. {
  1234. TRef<IZoneAuthServer> pzas = g_pClubApp->GetZoneAuthServer();
  1235. HRESULT hr = pzas->DecryptTicket(pZoneTicket, pfmLogon->cbZoneTicket);
  1236. switch (hr)
  1237. {
  1238. case ZT_NO_ERROR:
  1239. {
  1240. if (lstrcmp(g_pClubApp->GetAuthServer(), pzas->GetAuthServer())) // you MUST use the auth server that we expect
  1241. {
  1242. szReason = "Your account authentication did not go through the expected server.";
  1243. }
  1244. else
  1245. {
  1246. bool fValidNow = false;
  1247. pClient->SetClubMember(pzas->HasToken(g_pClubApp->GetToken(), &fValidNow) && fValidNow); // Note: relies on left to right eval
  1248. // Bell & whistle: Give them a message if their subscription has expired, that they won't be able to change anything
  1249. fValid = true;
  1250. pClient->SetZoneID(pzas->GetAccountID());
  1251. }
  1252. }
  1253. break;
  1254. case ZT_E_BUFFER_TOO_SMALL:
  1255. g_pClubApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, "Club: Need to increase size of token buffer.");
  1256. szReason = "Internal error.";
  1257. break;
  1258. case ZT_E_AUTH_INVALID_TICKET:
  1259. g_pClubApp->GetSite()->LogEvent(EVENTLOG_WARNING_TYPE, "Club: Invalid ticket received.");
  1260. szReason = "Could not validate Zone ID.";
  1261. break;
  1262. default:
  1263. g_pClubApp->GetSite()->LogEvent(EVENTLOG_WARNING_TYPE, "Unexpected error from zoneauth Decrypt.");
  1264. szReason = "Internal error.";
  1265. }
  1266. }
  1267. else
  1268. {
  1269. #ifdef MARKCU
  1270. // let mark run his little squads app on his machine
  1271. strncpy((char*)CharID_CharacterName, FM_VAR_REF(pfmLogon, CharacterName), sizeof(CharID_CharacterName));
  1272. SQL_GO(CharID);
  1273. if(!SQL_SUCCEEDED(SQL_GETROW(CharID)))
  1274. {
  1275. assert(0);
  1276. }
  1277. pClient->SetZoneID(CharID_CharacterId);
  1278. pClient->SetClubMember(true);
  1279. fValid = true;
  1280. #else
  1281. g_pClubApp->GetSite()->LogEvent(EVENTLOG_WARNING_TYPE, "Club: No ticket on logon.");
  1282. szReason = "No login credentials found.";
  1283. #endif
  1284. }
  1285. }
  1286. if (fValid)
  1287. {
  1288. // Allow client to logon
  1289. pthis->SetDefaultRecipient(&cnxnFrom, FM_GUARANTEED);
  1290. BEGIN_PFM_CREATE(*pthis, pfmLogonAck, S, LOGON_CLUB_ACK)
  1291. END_PFM_CREATE
  1292. pfmLogonAck->nMemberID = pClient->GetZoneID();
  1293. debugf("Zone ID: %d\n", pfmLogonAck->nMemberID);
  1294. // Send them the ranking info
  1295. CheckRankInfo();
  1296. BEGIN_PFM_CREATE(*pthis, pfmRankInfo, S, CLUB_RANK_INFO)
  1297. FM_VAR_PARM(g_pClubApp->GetRankInfo(), sizeof(RankInfo) * g_pClubApp->GetRankInfoCount())
  1298. END_PFM_CREATE
  1299. pfmRankInfo->cRanks = g_pClubApp->GetRankInfoCount();
  1300. }
  1301. else
  1302. {
  1303. BEGIN_PFM_CREATE(*pthis, pfmLogonNack, S, LOGON_CLUB_NACK)
  1304. FM_VAR_PARM(szReason, CB_ZTS)
  1305. END_PFM_CREATE
  1306. pfmLogonNack->fRetry = fRetry;
  1307. }
  1308. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1309. }
  1310. break;
  1311. case FM_C_LOGOFF_CLUB:
  1312. {
  1313. // TODO: mark 'em so we know they weren't dropped
  1314. }
  1315. break;
  1316. // This message is sent when a zone character requests info about himself.
  1317. // Server responds with CHARACTER_INFO_GENERAL
  1318. // along with CHARACTER_INFO_BY_CIV messages.
  1319. //
  1320. case FM_C_REQ_CHARACTER_INFO:
  1321. {
  1322. CASTPFM(pfmReq, C, REQ_CHARACTER_INFO, pfm);
  1323. if (pfmReq->nMemberID == -1)
  1324. CharInfoGeneral_CharacterID = pClient->GetZoneID();
  1325. else
  1326. CharInfoGeneral_CharacterID = pfmReq->nMemberID;
  1327. //
  1328. // First, we send civ-independent info
  1329. //
  1330. debugf("Sending Character Info for %d.\n", CharInfoGeneral_CharacterID);
  1331. // do query
  1332. SQL_GO(CharInfoGeneral);
  1333. if(SQL_SUCCEEDED(SQL_GETROW(CharInfoGeneral)))
  1334. {
  1335. pthis->SetDefaultRecipient(&cnxnFrom, FM_GUARANTEED);
  1336. RemoveTrailingSpaces((char*) CharInfoGeneral_Name);
  1337. RemoveTrailingSpaces((char*) CharInfoGeneral_Description);
  1338. BEGIN_PFM_CREATE(*pthis, pfmCharInfoGeneral, S, CHARACTER_INFO_GENERAL)
  1339. FM_VAR_PARM(CharInfoGeneral_Name, CB_ZTS)
  1340. FM_VAR_PARM(CharInfoGeneral_Description, CB_ZTS)
  1341. END_PFM_CREATE
  1342. }
  1343. else
  1344. {
  1345. // review: consider uncommenting this:
  1346. // g_pClubApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, "Database is messsed up; failed to get info for Player with ID=%d ", CharInfoGeneral_CharacterID);
  1347. }
  1348. //
  1349. // Next, send civ specific info
  1350. //
  1351. // This message is sent when a zone character requests info about himself
  1352. // specific to a CIV.
  1353. int cCivs = g_pStaticData->GetCivCount();
  1354. CharInfoByCiv_CharacterID = CharInfoGeneral_CharacterID; // setup input for CharInfoByCiv queries
  1355. SQL_GO(CharInfoByCiv);
  1356. while(SQL_SUCCEEDED(SQL_GETROW(CharInfoByCiv)))
  1357. {
  1358. // utilize query output in the response fedmsg
  1359. {
  1360. char szDate[11];
  1361. wsprintf(szDate, "%2d/%2d/%4d", CharInfoByCiv_LastPlayed.month,
  1362. CharInfoByCiv_LastPlayed.day,
  1363. CharInfoByCiv_LastPlayed.year);
  1364. BEGIN_PFM_CREATE(*pthis, pfmCharInfoByCiv, S, CHARACTER_INFO_BY_CIV)
  1365. FM_VAR_PARM(szDate, CB_ZTS)
  1366. END_PFM_CREATE
  1367. pfmCharInfoByCiv->civid = CharInfoByCiv_Civid;
  1368. pfmCharInfoByCiv->nRank = CharInfoByCiv_Rank;
  1369. pfmCharInfoByCiv->fScore = CharInfoByCiv_Score;
  1370. pfmCharInfoByCiv->cMinutesPlayed = MaxMinutes(CharInfoByCiv_MinutesPlayed);
  1371. pfmCharInfoByCiv->cBaseKills = CharInfoByCiv_BaseKills;
  1372. pfmCharInfoByCiv->cBaseCaptures = CharInfoByCiv_BaseCaptures;
  1373. pfmCharInfoByCiv->nRating = RATING_EXT2DISP(CharInfoByCiv_Rating);
  1374. pfmCharInfoByCiv->cKills = CharInfoByCiv_Kills;
  1375. pfmCharInfoByCiv->cDeaths = CharInfoByCiv_Deaths;
  1376. pfmCharInfoByCiv->cWins = CharInfoByCiv_Wins;
  1377. pfmCharInfoByCiv->cLosses = CharInfoByCiv_Losses;
  1378. pfmCharInfoByCiv->nPromotionAt = GetNextPromotion(
  1379. pfmCharInfoByCiv->civid,
  1380. pfmCharInfoByCiv->fScore
  1381. );
  1382. }
  1383. }
  1384. //
  1385. // Send medal info for this character
  1386. //
  1387. MedalInfo_CharacterID = CharInfoGeneral_CharacterID;
  1388. SQL_GO(CharMedal);
  1389. while (SQL_SUCCEEDED(SQL_GETROW(CharMedal)))
  1390. {
  1391. RemoveTrailingSpaces((char*)MedalInfo_Name);
  1392. RemoveTrailingSpaces((char*)MedalInfo_Description);
  1393. RemoveTrailingSpaces((char*)MedalInfo_SpecificInfo);
  1394. RemoveTrailingSpaces((char*)MedalInfo_Bitmap);
  1395. {
  1396. BEGIN_PFM_CREATE(*pthis, pfmMedal, S, CHARACTER_INFO_MEDAL)
  1397. FM_VAR_PARM(MedalInfo_Name, CB_ZTS)
  1398. FM_VAR_PARM(MedalInfo_Description, CB_ZTS)
  1399. FM_VAR_PARM(MedalInfo_SpecificInfo, CB_ZTS)
  1400. FM_VAR_PARM(MedalInfo_Bitmap, CB_ZTS)
  1401. END_PFM_CREATE
  1402. pfmMedal->civid = MedalInfo_Civid;
  1403. }
  1404. }
  1405. //
  1406. // Send out queued messages to character
  1407. //
  1408. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1409. }
  1410. break;
  1411. case FM_C_CHARACTER_INFO_EDIT_DESCRIPTION:
  1412. {
  1413. CASTPFM(pfmEdit, C, CHARACTER_INFO_EDIT_DESCRIPTION, pfm);
  1414. char * szDesc = FM_VAR_REF(pfmEdit, szDescription);
  1415. if (szDesc)
  1416. lstrcpy((char *) UpdateDescription_Description, szDesc);
  1417. else
  1418. lstrcpy((char *) UpdateDescription_Description, "");
  1419. UpdateDescription_CharacterId = pClient->GetZoneID();
  1420. SQL_GO(UpdateDescription);
  1421. }
  1422. break;
  1423. case FM_C_SQUAD_CREATE:
  1424. {
  1425. CASTPFM(pfmCreate, C, SQUAD_CREATE, pfm);
  1426. char * szName = FM_VAR_REF(pfmCreate, szName);
  1427. char * szDesc = FM_VAR_REF(pfmCreate, szDescription);
  1428. char * szURL = FM_VAR_REF(pfmCreate, szURL);
  1429. //
  1430. // setup input for query
  1431. //
  1432. if(szName)
  1433. strncpy((char *) CreateSquad_Name, szName, min(sizeof(CreateSquad_Name)-1, c_cbNameDB));
  1434. else
  1435. *((char *)CreateSquad_Name) = 0;
  1436. if (szDesc)
  1437. strncpy((char *) CreateSquad_Description, szDesc, sizeof(CreateSquad_Description)-1);
  1438. else
  1439. *((char *)CreateSquad_Description) = 0;
  1440. if(szURL)
  1441. strncpy((char *) CreateSquad_URL, szURL, sizeof(CreateSquad_URL)-1);
  1442. else
  1443. *((char *)CreateSquad_URL) = 0;
  1444. CreateSquad_CivID = pfmCreate->civid;
  1445. CreateSquad_Owner = pClient->GetZoneID();
  1446. CreateSquad_ErrorCode = -1;
  1447. if (pClient->GetClubMember())
  1448. {
  1449. //
  1450. // do query
  1451. //
  1452. SQL_GO(CreateSquad);
  1453. if (!SQL_SUCCEEDED(SQL_GETROW(CreateSquad)))
  1454. {
  1455. lstrcpy((char *) CreateSquad_ErrorMsg, "Server Error; try again later.");
  1456. g_pClubApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, "Error while trying to create squad.");
  1457. }
  1458. if (CreateSquad_ErrorCode != 0)
  1459. {
  1460. //
  1461. // Scan the CreateSquad_ErrorMsg string, replace the word "Team" with "Squad";
  1462. // then send the message to the user
  1463. //
  1464. char szErrorMsg[c_cbErrorMsg + 20];
  1465. UTL::SearchAndReplace(szErrorMsg, (char*)CreateSquad_ErrorMsg, "Squad", "Team");
  1466. SendSquadTextMessage(pthis, cnxnFrom, "Cannot create %s Squad.\n%s", szName, szErrorMsg);
  1467. }
  1468. }
  1469. else
  1470. {
  1471. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1472. }
  1473. BEGIN_PFM_CREATE(*pthis, pfmAck, S, SQUAD_CREATE_ACK)
  1474. END_PFM_CREATE
  1475. pfmAck->nClientSquadID = pfmCreate->nClientSquadID;
  1476. pfmAck->nSquadID = CreateSquad_SquadID;
  1477. pfmAck->bSuccessful = (CreateSquad_ErrorCode == 0);
  1478. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1479. }
  1480. break;
  1481. case FM_C_SQUAD_EDIT:
  1482. {
  1483. CASTPFM(pfmEdit, C, SQUAD_EDIT, pfm);
  1484. if (!pClient->GetClubMember())
  1485. {
  1486. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1487. SendSquadDetails(pthis, cnxnFrom, pfmEdit->nSquadID); // update client with the truth
  1488. break;
  1489. }
  1490. char * szDesc = FM_VAR_REF(pfmEdit, szDescription);
  1491. char * szURL = FM_VAR_REF(pfmEdit, szURL);
  1492. if(szDesc)
  1493. strncpy((char *) EditSquad_Description, szDesc, sizeof(EditSquad_Description)-1);
  1494. else
  1495. *((char *)EditSquad_Description) = 0;
  1496. if(szURL)
  1497. strncpy((char *) EditSquad_URL, szURL, sizeof(EditSquad_URL)-1);
  1498. else
  1499. *((char *)EditSquad_URL) = 0;
  1500. EditSquad_SquadID = pfmEdit->nSquadID;
  1501. EditSquad_CivID = pfmEdit->civid;
  1502. EditSquad_ErrorCode = 0;
  1503. //
  1504. // do query
  1505. //
  1506. SQL_GO(EditSquad);
  1507. if (!SQL_SUCCEEDED(SQL_GETROW(EditSquad)))
  1508. {
  1509. EditSquad_ErrorCode = -1;
  1510. lstrcpy((char *) EditSquad_ErrorMsg, "Server Error; try again later.");
  1511. g_pClubApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, "Error while trying to edit squad: id = %d", EditSquad_SquadID);
  1512. }
  1513. if (EditSquad_ErrorCode != 0)
  1514. {
  1515. SendSquadTextMessage(pthis, cnxnFrom, "Server cannot edit squad (%d); Reason (%d) %s ", EditSquad_SquadID, EditSquad_ErrorCode, EditSquad_ErrorMsg);
  1516. }
  1517. SendSquadDetails(pthis, cnxnFrom, pfmEdit->nSquadID); // update client with the truth
  1518. }
  1519. break;
  1520. case FM_C_SQUAD_NEXT_PAGE_ALL:
  1521. {
  1522. CASTPFM(pfmPage, C, SQUAD_NEXT_PAGE_ALL, pfm);
  1523. SendSquadPage(pthis, cnxnFrom, pfmPage->column, pfmPage->nSquadID);
  1524. }
  1525. break;
  1526. case FM_C_SQUAD_NEXT_PAGE_DUDEX:
  1527. {
  1528. CASTPFM(pfmPage, C, SQUAD_NEXT_PAGE_DUDEX, pfm);
  1529. SendSquadPageDudeX(pthis, cnxnFrom, pfmPage->nMemberID, false);
  1530. }
  1531. break;
  1532. case FM_C_SQUAD_NEXT_PAGE_MY:
  1533. {
  1534. SendSquadPageDudeX(pthis, cnxnFrom, pClient->GetZoneID(), true);
  1535. }
  1536. break;
  1537. case FM_C_SQUAD_DETAILS_REQ:
  1538. {
  1539. CASTPFM(pfmReq, C, SQUAD_DETAILS_REQ, pfm);
  1540. SendSquadDetails(pthis, cnxnFrom, pfmReq->nSquadID);
  1541. }
  1542. break;
  1543. case FM_C_SQUAD_PAGE_FIND:
  1544. {
  1545. CASTPFM(pfmPage, C, SQUAD_PAGE_FIND, pfm);
  1546. SendSquadPage_FromFind(pthis, cnxnFrom, FM_VAR_REF(pfmPage, szPartialName));
  1547. }
  1548. break;
  1549. case FM_C_SQUAD_LOG_REQ:
  1550. {
  1551. CASTPFM(pfmLog, C, SQUAD_LOG_REQ, pfm);
  1552. GetOwnershipLog_SquadID = pfmLog->nSquadID;
  1553. // do query
  1554. SQL_GO(GetOwnershipLog);
  1555. if (SQL_SUCCEEDED(SQL_GETROW(GetOwnershipLog)))
  1556. {
  1557. // Send SQL response
  1558. BEGIN_PFM_CREATE(*pthis, pfmAck, S, SQUAD_LOG_INFO)
  1559. FM_VAR_PARM(GetOwnershipLog_Output, CB_ZTS)
  1560. END_PFM_CREATE
  1561. pfmAck->nSquadID = GetOwnershipLog_SquadID;
  1562. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1563. }
  1564. }
  1565. break;
  1566. case FM_C_SQUAD_MAKE_JOIN_REQUEST:
  1567. {
  1568. CASTPFM(pfmSquad, C, SQUAD_MAKE_JOIN_REQUEST, pfm);
  1569. if (!pClient->GetClubMember())
  1570. {
  1571. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1572. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1573. break;
  1574. }
  1575. MakeJoinRequest_MemberID = pClient->GetZoneID();
  1576. MakeJoinRequest_SquadID = pfmSquad->nSquadID;
  1577. MakeJoinRequest_ErrorCode = 0;
  1578. // do query
  1579. SQL_GO(MakeJoinRequest);
  1580. if (SQL_SUCCEEDED(SQL_GETROW(MakeJoinRequest)))
  1581. {
  1582. if (MakeJoinRequest_ErrorCode != 0)
  1583. {
  1584. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1585. }
  1586. }
  1587. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1588. }
  1589. break;
  1590. case FM_C_SQUAD_CANCEL_JOIN_REQUEST:
  1591. {
  1592. CASTPFM(pfmSquad, C, SQUAD_CANCEL_JOIN_REQUEST, pfm);
  1593. if (!pClient->GetClubMember())
  1594. {
  1595. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1596. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1597. break;
  1598. }
  1599. CancelJoinRequest_MemberID = pClient->GetZoneID();
  1600. CancelJoinRequest_SquadID = pfmSquad->nSquadID;
  1601. CancelJoinRequest_ErrorCode = 0;
  1602. // do query
  1603. SQL_GO(CancelJoinRequest);
  1604. if (SQL_SUCCEEDED(SQL_GETROW(CancelJoinRequest)))
  1605. {
  1606. if (CancelJoinRequest_ErrorCode != 0)
  1607. {
  1608. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1609. }
  1610. }
  1611. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1612. }
  1613. break;
  1614. case FM_C_SQUAD_REJECT_JOIN_REQUEST:
  1615. {
  1616. CASTPFM(pfmSquad, C, SQUAD_REJECT_JOIN_REQUEST, pfm);
  1617. if (!pClient->GetClubMember())
  1618. {
  1619. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1620. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1621. break;
  1622. }
  1623. RejectJoinRequest_MemberID = pfmSquad->nMemberID;
  1624. RejectJoinRequest_SquadID = pfmSquad->nSquadID;
  1625. RejectJoinRequest_ErrorCode = 0;
  1626. // do query
  1627. SQL_GO(RejectJoinRequest);
  1628. if (SQL_SUCCEEDED(SQL_GETROW(RejectJoinRequest)))
  1629. {
  1630. if (RejectJoinRequest_ErrorCode != 0)
  1631. {
  1632. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1633. }
  1634. }
  1635. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1636. }
  1637. break;
  1638. case FM_C_SQUAD_ACCEPT_JOIN_REQUEST:
  1639. {
  1640. CASTPFM(pfmSquad, C, SQUAD_ACCEPT_JOIN_REQUEST, pfm);
  1641. if (!pClient->GetClubMember())
  1642. {
  1643. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1644. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1645. break;
  1646. }
  1647. AcceptJoinRequest_MemberID = pfmSquad->nMemberID;
  1648. AcceptJoinRequest_SquadID = pfmSquad->nSquadID;
  1649. AcceptJoinRequest_ErrorCode = 0;
  1650. // do query
  1651. SQL_GO(AcceptJoinRequest);
  1652. if (SQL_SUCCEEDED(SQL_GETROW(AcceptJoinRequest)))
  1653. {
  1654. if (AcceptJoinRequest_ErrorCode != 0)
  1655. {
  1656. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1657. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1658. }
  1659. }
  1660. }
  1661. break;
  1662. case FM_C_SQUAD_BOOT_MEMBER:
  1663. {
  1664. CASTPFM(pfmSquad, C, SQUAD_BOOT_MEMBER, pfm);
  1665. if (!pClient->GetClubMember())
  1666. {
  1667. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1668. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1669. break;
  1670. }
  1671. BootMember_MemberID = pfmSquad->nMemberID;
  1672. BootMember_SquadID = pfmSquad->nSquadID;
  1673. BootMember_ErrorCode = 0;
  1674. // do query
  1675. SQL_GO(BootMember);
  1676. if (SQL_SUCCEEDED(SQL_GETROW(BootMember)))
  1677. {
  1678. if (BootMember_ErrorCode != 0)
  1679. {
  1680. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1681. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1682. }
  1683. else
  1684. {
  1685. if (BootMember_Status == -1)
  1686. {
  1687. BEGIN_PFM_CREATE(*pthis, pfmDeleted, S, SQUAD_DELETED)
  1688. END_PFM_CREATE
  1689. pfmDeleted->nSquadID = BootMember_SquadID;
  1690. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1691. }
  1692. else SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update incase of new owner
  1693. }
  1694. }
  1695. else SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1696. }
  1697. break;
  1698. case FM_C_SQUAD_QUIT:
  1699. {
  1700. CASTPFM(pfmSquad, C, SQUAD_QUIT, pfm);
  1701. /*
  1702. Let's let people at least be able to quit; so if a leader forgot to pay his dues, the
  1703. squad can continue without him.
  1704. if (!pClient->GetClubMember())
  1705. {
  1706. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1707. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1708. break;
  1709. }
  1710. */
  1711. QuitSquad_MemberID = pClient->GetZoneID();
  1712. QuitSquad_SquadID = pfmSquad->nSquadID;
  1713. QuitSquad_ErrorCode = 0;
  1714. // do query
  1715. SQL_GO(QuitSquad);
  1716. if (SQL_SUCCEEDED(SQL_GETROW(QuitSquad)))
  1717. {
  1718. if (QuitSquad_ErrorCode != 0)
  1719. {
  1720. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1721. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1722. }
  1723. else
  1724. {
  1725. if (QuitSquad_Status == -1)
  1726. {
  1727. BEGIN_PFM_CREATE(*pthis, pfmDeleted, S, SQUAD_DELETED)
  1728. END_PFM_CREATE
  1729. pfmDeleted->nSquadID = QuitSquad_SquadID;
  1730. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1731. }
  1732. else SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update incase of new owner
  1733. }
  1734. }
  1735. else SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1736. }
  1737. break;
  1738. case FM_C_SQUAD_PROMOTE_TO_ASL:
  1739. {
  1740. CASTPFM(pfmSquad, C, SQUAD_PROMOTE_TO_ASL, pfm);
  1741. if (!pClient->GetClubMember())
  1742. {
  1743. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1744. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1745. break;
  1746. }
  1747. PromoteToASL_MemberID = pfmSquad->nMemberID;
  1748. PromoteToASL_SquadID = pfmSquad->nSquadID;
  1749. PromoteToASL_ErrorCode = 0;
  1750. // do query
  1751. SQL_GO(PromoteToASL);
  1752. if (SQL_SUCCEEDED(SQL_GETROW(PromoteToASL)))
  1753. {
  1754. if (PromoteToASL_ErrorCode != 0)
  1755. {
  1756. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1757. }
  1758. }
  1759. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1760. }
  1761. break;
  1762. case FM_C_SQUAD_DEMOTE_TO_MEMBER:
  1763. {
  1764. CASTPFM(pfmSquad, C, SQUAD_DEMOTE_TO_MEMBER, pfm);
  1765. if (!pClient->GetClubMember())
  1766. {
  1767. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1768. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1769. break;
  1770. }
  1771. DemoteToMember_MemberID = pfmSquad->nMemberID;
  1772. DemoteToMember_SquadID = pfmSquad->nSquadID;
  1773. DemoteToMember_ErrorCode = 0;
  1774. // do query
  1775. SQL_GO(DemoteToMember);
  1776. if (SQL_SUCCEEDED(SQL_GETROW(DemoteToMember)))
  1777. {
  1778. if (DemoteToMember_ErrorCode != 0)
  1779. {
  1780. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1781. }
  1782. else
  1783. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1784. }
  1785. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1786. }
  1787. break;
  1788. case FM_C_SQUAD_TRANSFER_CONTROL:
  1789. {
  1790. CASTPFM(pfmSquad, C, SQUAD_TRANSFER_CONTROL, pfm);
  1791. /*
  1792. At least allow him to transfer control, so that if a leader doesn't pay, he can at least step down as leader.
  1793. if (!pClient->GetClubMember())
  1794. {
  1795. SendSquadTextMessage(pthis, cnxnFrom, szNotMemberMessage);
  1796. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1797. break;
  1798. }
  1799. */
  1800. TransferControl_MemberID = pfmSquad->nMemberID;
  1801. TransferControl_SquadID = pfmSquad->nSquadID;
  1802. TransferControl_ErrorCode = 0;
  1803. // do query
  1804. SQL_GO(TransferControl);
  1805. if (SQL_SUCCEEDED(SQL_GETROW(TransferControl)))
  1806. {
  1807. if (TransferControl_ErrorCode != 0)
  1808. {
  1809. SendSquadTextMessage(pthis, cnxnFrom, "Your request could not be completed; try again later.");
  1810. }
  1811. }
  1812. SendSquadDetails(pthis, cnxnFrom, pfmSquad->nSquadID); // update client with the truth
  1813. }
  1814. break;
  1815. case FM_C_LEADER_BOARD_QUERY:
  1816. {
  1817. CASTPFM(pfmLeaderBoardQuery, C, LEADER_BOARD_QUERY, pfm);
  1818. const int nMaxResultSize = 84 + 1;
  1819. LeaderBoardEntry vResults[nMaxResultSize];
  1820. LeaderBoardEntry topPlayer;
  1821. int nResultCount = 0;
  1822. // force the name to be at least somewhat valid
  1823. char szBasis[c_cbName];
  1824. strncpy(szBasis, pfmLeaderBoardQuery->szBasis, c_cbName);
  1825. szBasis[c_cbName - 1] = '\0';
  1826. RemoveTrailingSpaces(szBasis);
  1827. // do the query
  1828. int characterId = (pfmLeaderBoardQuery->idBasis == -2) ? -1 : pfmLeaderBoardQuery->idBasis;
  1829. nResultCount = GetResults(pfmLeaderBoardQuery->sort,
  1830. szBasis, characterId, pfmLeaderBoardQuery->civid,
  1831. topPlayer, vResults, nMaxResultSize - 1);
  1832. // if this was a client trying to pull up the initial info on the leader
  1833. // board but we did not find any info, just pull up the top players.
  1834. // REVIEW: it's inefficient (2 queries), but saves having to add this
  1835. // special case in 12 places.
  1836. if (nResultCount == 0 && pfmLeaderBoardQuery->idBasis == -2)
  1837. {
  1838. szBasis[0] = '\0';
  1839. nResultCount = GetResults(pfmLeaderBoardQuery->sort, "", -1,
  1840. pfmLeaderBoardQuery->civid, topPlayer, vResults, nMaxResultSize - 1);
  1841. }
  1842. // compose a response
  1843. if (0 == nResultCount)
  1844. {
  1845. BEGIN_PFM_CREATE(*pthis, pfmLeaderBoardQueryFail, S, LEADER_BOARD_QUERY_FAIL)
  1846. END_PFM_CREATE
  1847. strncpy(pfmLeaderBoardQueryFail->szBasis, szBasis, c_cbName);
  1848. }
  1849. else
  1850. {
  1851. assert(nResultCount < nMaxResultSize);
  1852. // if they were seaching by name while sorted by name, they have at
  1853. // least a partial match
  1854. if ((szBasis[0] != '\0')
  1855. && (pfmLeaderBoardQuery->sort == lbSortName))
  1856. {
  1857. }
  1858. // if they were searching and the player name was not in the results, forge one
  1859. // on the end of the list.
  1860. else if ((szBasis[0] != '\0')
  1861. ? !HasPlayerNamed(szBasis, vResults, nResultCount)
  1862. : !HasCharacterID(characterId, vResults, nResultCount))
  1863. {
  1864. ForgeResultEntry(vResults[nResultCount], szBasis,
  1865. characterId, vResults[nResultCount-1].nPosition + 1);
  1866. nResultCount++;
  1867. }
  1868. // send the result list
  1869. BEGIN_PFM_CREATE(*pthis, pfmLeaderBoardList, S, LEADER_BOARD_LIST)
  1870. FM_VAR_PARM(vResults, nResultCount * sizeof(LeaderBoardEntry))
  1871. END_PFM_CREATE
  1872. pfmLeaderBoardList->cEntries = nResultCount;
  1873. pfmLeaderBoardList->entryNumber1 = topPlayer;
  1874. }
  1875. pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH);
  1876. }
  1877. break;
  1878. // default:
  1879. // TODO: perhaps we should disconnect this client.
  1880. //g_pClubApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, "Client sent unknown message type. Type = %d ", pfm->fmid);
  1881. }
  1882. return S_OK;
  1883. }
  1884. HRESULT IClubClientSite::OnSysMessage(FedMessaging * pthis)
  1885. {
  1886. return S_OK;
  1887. }
  1888. void IClubClientSite::OnMessageNAK(FedMessaging * pthis, DWORD dwTime, CFMRecipient * prcp)
  1889. {
  1890. debugf("ACK!! A guaranteed message didn't make it through to recipient %s.\n", prcp->GetName());
  1891. }
  1892. HRESULT IClubClientSite::OnNewConnection(FedMessaging * pthis, CFMConnection & cnxn)
  1893. {
  1894. CFLClient * pClient = new CFLClient(&cnxn);
  1895. debugf("Player %s has connected.\n", cnxn.GetName());
  1896. g_pClubApp->GetCounters()->cLogins++;
  1897. return S_OK;
  1898. }
  1899. HRESULT IClubClientSite::OnDestroyConnection(FedMessaging * pthis, CFMConnection & cnxn)
  1900. {
  1901. debugf("Player %s has left.\n", cnxn.GetName());
  1902. g_pClubApp->GetCounters()->cLogoffs++;
  1903. delete CFLClient::FromConnection(cnxn);
  1904. return S_OK;
  1905. }
  1906. HRESULT IClubClientSite::OnSessionLost(FedMessaging * pthis)
  1907. {
  1908. g_pClubApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, "ACK!! Clients session was lost!");
  1909. return S_OK;
  1910. }
  1911. int IClubClientSite::OnMessageBox(FedMessaging * pthis, const char * strText, const char * strCaption, UINT nType)
  1912. {
  1913. debugf("IClubClientSite::OnMessageBox: ");
  1914. return g_pClubApp->OnMessageBox(strText, strCaption, nType);
  1915. }