Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

674 lines
18 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. // blackmarket.cpp : Defines the entry point for the console application.
  3. //
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. #include <process.h>
  7. #include <string.h>
  8. #include <windows.h>
  9. #include <sys/stat.h>
  10. #include "interface.h"
  11. #include "imysqlwrapper.h"
  12. #include "mathlib.h"
  13. #include "filesystem.h"
  14. #include "filesystem_helpers.h"
  15. #include "tier2/tier2.h"
  16. #include "utlbuffer.h"
  17. #include <ATLComTime.h>
  18. const char *pDBName = "blackmarket_history";
  19. const char *pHostName = "gamestats";
  20. const char *pUserName = "root";
  21. const char *pPassword = "r77GH34p";
  22. CSysModule *sql = NULL;
  23. CreateInterfaceFn factory = NULL;
  24. IMySQL *mysql = NULL;
  25. enum CSWeaponID
  26. {
  27. WEAPON_NONE = 0,
  28. WEAPON_P228,
  29. WEAPON_GLOCK,
  30. WEAPON_SCOUT,
  31. WEAPON_HEGRENADE,
  32. WEAPON_XM1014,
  33. WEAPON_C4,
  34. WEAPON_MAC10,
  35. WEAPON_AUG,
  36. WEAPON_SMOKEGRENADE,
  37. WEAPON_ELITE,
  38. WEAPON_FIVESEVEN,
  39. WEAPON_UMP45,
  40. WEAPON_SG550,
  41. WEAPON_GALIL,
  42. WEAPON_FAMAS,
  43. WEAPON_USP,
  44. WEAPON_AWP,
  45. WEAPON_MP5NAVY,
  46. WEAPON_M249,
  47. WEAPON_M3,
  48. WEAPON_M4A1,
  49. WEAPON_TMP,
  50. WEAPON_G3SG1,
  51. WEAPON_FLASHBANG,
  52. WEAPON_DEAGLE,
  53. WEAPON_SG552,
  54. WEAPON_AK47,
  55. WEAPON_KNIFE,
  56. WEAPON_P90,
  57. WEAPON_SHIELDGUN, // BOTPORT: Is this still needed?
  58. WEAPON_KEVLAR,
  59. WEAPON_ASSAULTSUIT,
  60. WEAPON_NVG,
  61. WEAPON_MAX, // number of weapons weapon index
  62. };
  63. #define PRICE_BLOB_VERSION 1
  64. #define PRICE_BLOB_NAME "weeklyprices.dat"
  65. struct weeklyprice_t
  66. {
  67. short iVersion;
  68. short iPreviousPrice[WEAPON_MAX];
  69. short iCurrentPrice[WEAPON_MAX];
  70. };
  71. int g_iCurrentWeaponPurchases[WEAPON_MAX];
  72. int g_iNewWeaponPrices[WEAPON_MAX];
  73. int g_iPriceDelta[WEAPON_MAX];
  74. int g_iPurchaseDelta[WEAPON_MAX];
  75. int g_iCounter = 0;
  76. int g_iResetCounter = 0;
  77. bool g_bWeeklyUpdate = false;
  78. #define PRICE_SCALE 0.01f
  79. struct weapons_t
  80. {
  81. int iWeaponType;
  82. int iDefaultPrice;
  83. int iID;
  84. int iPurchaseCount;
  85. int iCurrentPrice;
  86. };
  87. #define WEAPON_NOTHING 0
  88. #define WEAPON_PISTOL 1
  89. #define WEAPON_EVERYTHING 2
  90. static weapons_t g_Weapons[] =
  91. {
  92. { WEAPON_NOTHING, 0, WEAPON_NONE, 0, 0, },
  93. { WEAPON_PISTOL, 600, WEAPON_P228, 0, 0, },
  94. { WEAPON_PISTOL, 400, WEAPON_GLOCK, 0, 0, },
  95. { WEAPON_EVERYTHING, 2750, WEAPON_SCOUT, 0, 0, },
  96. { WEAPON_EVERYTHING, 300, WEAPON_HEGRENADE, 0, 0, },
  97. { WEAPON_EVERYTHING, 3000, WEAPON_XM1014, 0, 0, },
  98. { WEAPON_NOTHING, 0, WEAPON_C4, 0, 0, },
  99. { WEAPON_EVERYTHING, 1400, WEAPON_MAC10, 0, 0, },
  100. { WEAPON_EVERYTHING, 3500, WEAPON_AUG, 0, 0, },
  101. { WEAPON_EVERYTHING, 300, WEAPON_SMOKEGRENADE, 0, 0, },
  102. { WEAPON_PISTOL, 800, WEAPON_ELITE, 0, 0, },
  103. { WEAPON_PISTOL, 750, WEAPON_FIVESEVEN, 0, 0, },
  104. { WEAPON_EVERYTHING, 1700, WEAPON_UMP45, 0, 0, },
  105. { WEAPON_EVERYTHING, 4200, WEAPON_SG550, 0, 0, },
  106. { WEAPON_EVERYTHING, 2000, WEAPON_GALIL, 0, 0, },
  107. { WEAPON_EVERYTHING, 2250, WEAPON_FAMAS, 0, 0, },
  108. { WEAPON_PISTOL, 500, WEAPON_USP, 0, 0, },
  109. { WEAPON_EVERYTHING, 4750, WEAPON_AWP, 0, 0, },
  110. { WEAPON_EVERYTHING, 1500, WEAPON_MP5NAVY, 0, 0, },
  111. { WEAPON_EVERYTHING, 5750, WEAPON_M249, 0, 0, },
  112. { WEAPON_EVERYTHING, 1700, WEAPON_M3, 0, 0, },
  113. { WEAPON_EVERYTHING, 3100, WEAPON_M4A1, 0, 0, },
  114. { WEAPON_EVERYTHING, 1250, WEAPON_TMP, 0, 0, },
  115. { WEAPON_EVERYTHING, 5000, WEAPON_G3SG1, 0, 0, },
  116. { WEAPON_EVERYTHING, 200, WEAPON_FLASHBANG, 0, 0, },
  117. { WEAPON_PISTOL, 650, WEAPON_DEAGLE, 0, 0, },
  118. { WEAPON_EVERYTHING, 3500, WEAPON_SG552, 0, 0, },
  119. { WEAPON_EVERYTHING, 2500, WEAPON_AK47, 0, 0, },
  120. { WEAPON_NOTHING, 0, WEAPON_KNIFE, 0, 0, },
  121. { WEAPON_EVERYTHING, 2350, WEAPON_P90, 0, 0, },
  122. { WEAPON_NOTHING, 0, WEAPON_SHIELDGUN, 0, 0, },
  123. { WEAPON_EVERYTHING, 650, WEAPON_KEVLAR, 0, 0, },
  124. { WEAPON_EVERYTHING, 1000, WEAPON_ASSAULTSUIT, 0, 0, },
  125. { WEAPON_EVERYTHING, 1250, WEAPON_NVG, 0, 0, },
  126. };
  127. const char * s_WeaponAliasInfo[] =
  128. {
  129. "none", // WEAPON_NONE
  130. "p228", // WEAPON_P228
  131. "glock", // WEAPON_GLOCK // old glock
  132. "scout", // WEAPON_SCOUT
  133. "hegren", // WEAPON_HEGRENADE
  134. "xm1014", // WEAPON_XM1014 // auto shotgun
  135. "c4", // WEAPON_C4
  136. "mac10", // WEAPON_MAC10 // T only
  137. "aug", // WEAPON_AUG
  138. "sgren", // WEAPON_SMOKEGRENADE
  139. "elite", // WEAPON_ELITE
  140. "fiveseven",// WEAPON_FIVESEVEN
  141. "ump45", // WEAPON_UMP45
  142. "sg550", // WEAPON_SG550 // auto-sniper
  143. "galil", // WEAPON_GALIL
  144. "famas", // WEAPON_FAMAS // CT cheap m4a1
  145. "usp", // WEAPON_USP
  146. "awp", // WEAPON_AWP
  147. "mp5navy", // WEAPON_MP5N
  148. "m249", // WEAPON_M249 // big machinegun
  149. "m3", // WEAPON_M3 // cheap shotgun
  150. "m4a1", // WEAPON_M4A1
  151. "tmp", // WEAPON_TMP
  152. "g3sg1", // WEAPON_G3SG1 // T auto-sniper
  153. "flash", // WEAPON_FLASHBANG
  154. "deagle", // WEAPON_DEAGLE
  155. "sg552", // WEAPON_SG552 // T aug equivalent
  156. "ak47", // WEAPON_AK47
  157. "knife", // WEAPON_KNIFE
  158. "p90", // WEAPON_P90
  159. "shield", // WEAPON_SHIELDGUN
  160. "kevlar",
  161. "kev+helm",
  162. "ngvision",
  163. NULL, // WEAPON_NONE
  164. };
  165. enum sorttype
  166. {
  167. SORT_PURCHASE = 0,
  168. SORT_NEWPRICE,
  169. SORT_PRICEDELTA,
  170. SORT_PERCENTCHANGE,
  171. };
  172. void SortWeaponRanks( int iWeaponType, weapons_t *pWeaponsArray, int iSortType );
  173. bool GetCurrentPurchaseCount( void )
  174. {
  175. if ( mysql->InitMySQL( "gamestats_cstrike", pHostName, pUserName, pPassword ) )
  176. {
  177. Msg( "Successfully connected to database %s on host %s, user %s\n", "gamestats_cstrike", pHostName, pUserName );
  178. //Get purchase counts.
  179. mysql->Execute( "select * from weapons;" );
  180. bool bFoundNext = mysql->SeekToFirstRow();
  181. int iIndex = WEAPON_P228;
  182. while( bFoundNext && iIndex < WEAPON_MAX )
  183. {
  184. bFoundNext = mysql->NextRow();
  185. g_iCurrentWeaponPurchases[iIndex] = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "Count" ) );
  186. g_Weapons[iIndex].iPurchaseCount = g_iCurrentWeaponPurchases[iIndex];
  187. iIndex++;
  188. }
  189. mysql->Execute( "select * from snapshot_counter;" );
  190. mysql->SeekToFirstRow();
  191. mysql->NextRow();
  192. //Get snapshot counter.
  193. g_iCounter = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "counter" ) );
  194. mysql->Execute( "select * from reset_counter;" );
  195. mysql->SeekToFirstRow();
  196. mysql->NextRow();
  197. //Get reset snapshot counter.
  198. g_iResetCounter = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "counter" ) );
  199. //Get current price and purchase count
  200. mysql->Execute( "select * from weapon_info;" );
  201. bFoundNext = mysql->SeekToFirstRow();
  202. iIndex = WEAPON_P228;
  203. while( bFoundNext && iIndex < WEAPON_MAX )
  204. {
  205. bFoundNext = mysql->NextRow();
  206. int iWeaponID = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "WeaponID" ) );
  207. g_Weapons[iWeaponID].iCurrentPrice = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "current_price" ) );
  208. if ( g_bWeeklyUpdate == true )
  209. {
  210. int iPreviousPurchases = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "purchases_thisweek" ) );
  211. g_Weapons[iWeaponID].iPurchaseCount = g_iPurchaseDelta[iWeaponID] = iPreviousPurchases;
  212. }
  213. else
  214. {
  215. int iPreviousPurchases = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "purchases" ) );
  216. int iPurchasesThisWeek = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "purchases_thisweek" ) );
  217. g_iPurchaseDelta[iWeaponID] = g_iCurrentWeaponPurchases[iWeaponID] - iPreviousPurchases;
  218. g_Weapons[iWeaponID].iPurchaseCount = g_iPurchaseDelta[iWeaponID] + iPurchasesThisWeek;
  219. }
  220. iIndex++;
  221. }
  222. if ( g_bWeeklyUpdate == true )
  223. {
  224. iIndex = WEAPON_P228;
  225. while( iIndex < WEAPON_MAX )
  226. {
  227. char szQueryString[512];
  228. Q_snprintf( szQueryString, 512, "select * from purchases_pricing where snapshot=\"%d_%d\"", g_iCounter, iIndex );
  229. //Get current price and purchase count
  230. mysql->Execute( szQueryString );
  231. mysql->SeekToFirstRow();
  232. mysql->NextRow();
  233. g_iPurchaseDelta[iIndex] = mysql->GetColumnValue_Int( mysql->GetColumnIndex( "purchases" ) );
  234. iIndex++;
  235. }
  236. }
  237. return true;
  238. }
  239. Msg( "mysql->InitMySQL( %s, %s, %s, [password]) failed\n", "gamestats_cstrike", pHostName, pUserName );
  240. return false;
  241. }
  242. int GetWeaponTypeCount( int iType )
  243. {
  244. int iCount = 0;
  245. for ( int j = 0; j < WEAPON_MAX; j++ )
  246. {
  247. if ( g_Weapons[j].iWeaponType == iType )
  248. {
  249. iCount++;
  250. }
  251. }
  252. return iCount;
  253. }
  254. weapons_t g_PistolRanks[6];
  255. weapons_t g_RifleAndEquipmentRanks[24];
  256. void PrintNewPrices( void )
  257. {
  258. int iTotalPistols = 0;
  259. int iTotalRiflesEquipment = 0;
  260. int iTotalCurrentPistols = 0;
  261. int iTotalCurrentRiflesEquipment = 0;
  262. for ( int j = 0; j < WEAPON_MAX; j++ )
  263. {
  264. //Msg( "%s - Default Price: %d - New Price: %d\n", s_WeaponAliasInfo[j], g_Weapons[j].iDefaultPrice, g_iNewWeaponPrices[j] );
  265. if ( g_Weapons[j].iWeaponType == WEAPON_PISTOL )
  266. {
  267. iTotalPistols += g_Weapons[j].iCurrentPrice;
  268. iTotalCurrentPistols += g_iNewWeaponPrices[j];
  269. }
  270. else if ( g_Weapons[j].iWeaponType == WEAPON_EVERYTHING )
  271. {
  272. iTotalRiflesEquipment += g_Weapons[j].iCurrentPrice;
  273. iTotalCurrentRiflesEquipment += g_iNewWeaponPrices[j];
  274. }
  275. }
  276. int iCount = GetWeaponTypeCount( WEAPON_PISTOL );
  277. SortWeaponRanks( WEAPON_PISTOL, g_PistolRanks, SORT_PERCENTCHANGE );
  278. Msg( "\n" );
  279. Msg( "Pistol Rankings:\n\n");
  280. for ( int i = 0; i < iCount; i++ )
  281. {
  282. Msg( "#%d: %s \t\t| Purchases: %d \t| Current Price: %d \t| New Price: %d \t| Price Change: %d\n", i+1, s_WeaponAliasInfo[g_PistolRanks[i].iID], g_Weapons[g_PistolRanks[i].iID].iPurchaseCount, g_PistolRanks[i].iCurrentPrice, g_iNewWeaponPrices[g_PistolRanks[i].iID], g_iPriceDelta[g_PistolRanks[i].iID] );
  283. }
  284. iCount = GetWeaponTypeCount( WEAPON_EVERYTHING );
  285. SortWeaponRanks( WEAPON_EVERYTHING, g_RifleAndEquipmentRanks, SORT_PERCENTCHANGE );
  286. Msg( "\n\n" );
  287. Msg( "Other Weapons and Equipment Rankings:\n\n");
  288. for ( int i = 0; i < iCount; i++ )
  289. {
  290. Msg( "#%d: %s \t\t| Purchases: %d \t| Current Price: %d \t| New Price: %d \t| Price Change: %d\n", i+1, s_WeaponAliasInfo[g_RifleAndEquipmentRanks[i].iID], g_Weapons[g_RifleAndEquipmentRanks[i].iID].iPurchaseCount, g_RifleAndEquipmentRanks[i].iCurrentPrice, g_iNewWeaponPrices[g_RifleAndEquipmentRanks[i].iID], g_iPriceDelta[g_RifleAndEquipmentRanks[i].iID] );
  291. }
  292. Msg( "\n" );
  293. Msg( "Total Pistol Baseline: %d\n", iTotalPistols );
  294. Msg( "Current Pistol Total: %d\n", iTotalCurrentPistols );
  295. Msg( "Total Rifles/Equipment Baseline: %d\n", iTotalRiflesEquipment );
  296. Msg( "Current Rifles/Equipment Total: %d\n", iTotalCurrentRiflesEquipment );
  297. Msg( "\n" );
  298. }
  299. float g_flTotalWeaponPurchasesPistols = 0;
  300. float g_flTotalWeaponPurchasesRifleEquipment = 0;
  301. float g_flTotalDollarsPistols = 1;
  302. float g_flTotalDollarsRifleEquipment = 1;
  303. void SortWeaponRanks( int iWeaponType, weapons_t *pWeaponsArray, int iSortType )
  304. {
  305. int iCount = GetWeaponTypeCount( iWeaponType );
  306. int iTotalPurchases = g_flTotalWeaponPurchasesPistols;
  307. if ( iWeaponType == WEAPON_EVERYTHING )
  308. {
  309. iTotalPurchases = g_flTotalWeaponPurchasesRifleEquipment;
  310. }
  311. bool bSorted = 1;
  312. while ( bSorted )
  313. {
  314. bSorted = false;
  315. for ( int i = 1; i < iCount; i++ )
  316. {
  317. float flSize1 = 0; // (pWeaponsArray[i].iPurchaseCount * PRICE_SCALE) * (pWeaponsArray[i].iCurrentPrice * PRICE_SCALE);
  318. float flSize2 = 0; //(pWeaponsArray[i-1].iPurchaseCount * PRICE_SCALE) * (pWeaponsArray[i-1].iCurrentPrice * PRICE_SCALE);
  319. if ( iSortType == SORT_PURCHASE )
  320. {
  321. flSize1 = pWeaponsArray[i].iPurchaseCount;
  322. flSize2 = pWeaponsArray[i-1].iPurchaseCount;
  323. }
  324. else if ( iSortType == SORT_NEWPRICE )
  325. {
  326. flSize1 = g_iNewWeaponPrices[pWeaponsArray[i].iID];
  327. flSize2 = g_iNewWeaponPrices[pWeaponsArray[i-1].iID];
  328. }
  329. else if ( iSortType == SORT_PRICEDELTA )
  330. {
  331. flSize1 = g_iPriceDelta[pWeaponsArray[i].iID];
  332. flSize2 = g_iPriceDelta[pWeaponsArray[i-1].iID];
  333. }
  334. else if ( iSortType == SORT_PERCENTCHANGE )
  335. {
  336. flSize1 = (pWeaponsArray[i].iCurrentPrice / g_iNewWeaponPrices[pWeaponsArray[i].iID]) - 1;
  337. flSize2 = (pWeaponsArray[i-1].iCurrentPrice / g_iNewWeaponPrices[pWeaponsArray[i-1].iID]) - 1;
  338. }
  339. if ( flSize1 > flSize2 )
  340. {
  341. weapons_t temp = pWeaponsArray[i];
  342. pWeaponsArray[i] = pWeaponsArray[i-1];
  343. pWeaponsArray[i-1] = temp;
  344. bSorted = true;
  345. }
  346. }
  347. }
  348. }
  349. void CalculateNewPrices( weapons_t *pWeaponsArray, int iWeaponType )
  350. {
  351. int iTotalDollars = g_flTotalDollarsPistols;
  352. int iTotalPurchases = g_flTotalWeaponPurchasesPistols;
  353. int iTotalUp = 0;
  354. int iTotalDown = 0;
  355. if ( iWeaponType == WEAPON_EVERYTHING )
  356. {
  357. iTotalDollars = g_flTotalDollarsRifleEquipment;
  358. iTotalPurchases = g_flTotalWeaponPurchasesRifleEquipment;
  359. }
  360. SortWeaponRanks( iWeaponType, pWeaponsArray, SORT_PURCHASE );
  361. int iCount = GetWeaponTypeCount( iWeaponType );
  362. float flPercentage = 0.0f;
  363. int iSign = 1;
  364. for ( int i = 0; i < iCount; i++ )
  365. {
  366. float flDollarAmount = ((float)pWeaponsArray[i].iCurrentPrice * PRICE_SCALE) * ((float)pWeaponsArray[i].iPurchaseCount * PRICE_SCALE);
  367. float flTest = flDollarAmount / (float)iTotalDollars;
  368. float flTest2 = (float)pWeaponsArray[i].iPurchaseCount / (float)iTotalPurchases;
  369. if ( iSign == 1 )
  370. {
  371. float flMod = (float)pWeaponsArray[i].iDefaultPrice / (float)pWeaponsArray[i].iCurrentPrice;
  372. g_iNewWeaponPrices[pWeaponsArray[i].iID] = ceil( pWeaponsArray[i].iCurrentPrice + ( ( pWeaponsArray[i].iCurrentPrice * flTest2 ) * flMod ) );
  373. iTotalUp += iTotalDollars * flTest;
  374. }
  375. else
  376. {
  377. float flMod = (float)pWeaponsArray[i].iCurrentPrice / (float)pWeaponsArray[i].iDefaultPrice;
  378. g_iNewWeaponPrices[pWeaponsArray[i].iID] = pWeaponsArray[i].iCurrentPrice - (( 1.0f / flTest2 ) * flMod );
  379. iTotalDown += iTotalDollars * flTest;
  380. }
  381. if ( g_iNewWeaponPrices[pWeaponsArray[i].iID] <= 0 )
  382. {
  383. g_iNewWeaponPrices[pWeaponsArray[i].iID] = 1;
  384. }
  385. g_iPriceDelta[pWeaponsArray[i].iID] = g_iNewWeaponPrices[pWeaponsArray[i].iID] - pWeaponsArray[i].iCurrentPrice;
  386. flPercentage = flPercentage + flTest;
  387. if ( flPercentage >= 0.5f )
  388. {
  389. iSign = -1;
  390. }
  391. }
  392. }
  393. void ProcessBlackMarket( void )
  394. {
  395. int iPistol = 0;
  396. int iRifles = 0;
  397. for ( int i = 1; i < WEAPON_MAX; i++ )
  398. {
  399. if ( g_Weapons[i].iWeaponType == WEAPON_PISTOL )
  400. {
  401. g_flTotalDollarsPistols += ( (float)g_Weapons[i].iCurrentPrice * PRICE_SCALE) * ( (float)g_Weapons[i].iPurchaseCount * PRICE_SCALE);
  402. g_flTotalWeaponPurchasesPistols += g_Weapons[i].iPurchaseCount;
  403. g_PistolRanks[iPistol] = g_Weapons[i];
  404. g_PistolRanks[iPistol].iPurchaseCount = g_Weapons[i].iPurchaseCount; //g_iCurrentWeaponPurchases[i];
  405. iPistol++;
  406. }
  407. else if ( g_Weapons[i].iWeaponType == WEAPON_EVERYTHING )
  408. {
  409. g_flTotalDollarsRifleEquipment += ( (float)g_Weapons[i].iCurrentPrice * PRICE_SCALE ) * ( (float)g_Weapons[i].iPurchaseCount * PRICE_SCALE );
  410. g_flTotalWeaponPurchasesRifleEquipment += g_Weapons[i].iPurchaseCount;
  411. g_RifleAndEquipmentRanks[iRifles] = g_Weapons[i];
  412. g_RifleAndEquipmentRanks[iRifles].iPurchaseCount = g_Weapons[i].iPurchaseCount; //g_iCurrentWeaponPurchases[i];
  413. iRifles++;
  414. }
  415. }
  416. memset( g_iPriceDelta, 0, sizeof( g_iPriceDelta ) );
  417. CalculateNewPrices( g_PistolRanks, WEAPON_PISTOL );
  418. CalculateNewPrices( g_RifleAndEquipmentRanks, WEAPON_EVERYTHING );
  419. }
  420. //=================================
  421. // Add the current snapshot to the db
  422. //=================================
  423. void AddSnapshotToDatabase( void )
  424. {
  425. char szSnapshot[1024];
  426. //Only update the prices and close.
  427. if ( g_bWeeklyUpdate == true )
  428. {
  429. weeklyprice_t prices;
  430. CUtlBuffer buf;
  431. prices.iVersion = PRICE_BLOB_VERSION;
  432. for ( int i = 1; i < WEAPON_MAX; i ++ )
  433. {
  434. Q_snprintf( szSnapshot, sizeof( szSnapshot ), "update weapon_info set current_price=%d, purchases_thisweek=0 where WeaponID=%d", g_iNewWeaponPrices[i], i );
  435. int retcode = mysql->Execute( szSnapshot );
  436. if ( retcode != 0 )
  437. {
  438. Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode );
  439. }
  440. prices.iPreviousPrice[i] = g_Weapons[i].iCurrentPrice;
  441. prices.iCurrentPrice[i] = g_iNewWeaponPrices[i];
  442. }
  443. buf.Put( &prices, sizeof( weeklyprice_t ) );
  444. if ( g_pFullFileSystem )
  445. {
  446. g_pFullFileSystem->WriteFile( PRICE_BLOB_NAME, NULL, buf );
  447. }
  448. Q_snprintf( szSnapshot, sizeof( szSnapshot ), "update reset_counter set counter=counter+1" );
  449. int retcode = mysql->Execute( szSnapshot );
  450. if ( retcode != 0 )
  451. {
  452. Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode );
  453. }
  454. return;
  455. }
  456. g_iCounter++;
  457. for ( int i = 1; i < WEAPON_MAX; i ++ )
  458. {
  459. Q_snprintf( szSnapshot, sizeof( szSnapshot ), "Insert into purchases_pricing ( snapshot, dt2, weapon_id, purchases, current_price, projected_price, reset_counter ) values ( \"%d_%d\", NOW(), %d, %d, %d, %d, %d );",
  460. g_iCounter, i,
  461. i,
  462. g_iPurchaseDelta[i],
  463. g_Weapons[i].iCurrentPrice,
  464. g_iNewWeaponPrices[i],
  465. g_iResetCounter );
  466. int retcode = mysql->Execute( szSnapshot );
  467. if ( retcode != 0 )
  468. {
  469. Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode );
  470. }
  471. }
  472. Q_snprintf( szSnapshot, sizeof( szSnapshot ), "update snapshot_counter set counter=%d", g_iCounter );
  473. int retcode = mysql->Execute( szSnapshot );
  474. if ( retcode != 0 )
  475. {
  476. Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode );
  477. }
  478. for ( int i = 1; i < WEAPON_MAX; i ++ )
  479. {
  480. Q_snprintf( szSnapshot, sizeof( szSnapshot ), "update weapon_info set purchases=%d, purchases_thisweek=purchases_thisweek+%d where WeaponID=%d", g_iCurrentWeaponPurchases[i], g_iPurchaseDelta[i], i );
  481. int retcode = mysql->Execute( szSnapshot );
  482. if ( retcode != 0 )
  483. {
  484. Msg( "Query:\n %s\n failed - Retcode: %d\n", szSnapshot, retcode );
  485. }
  486. }
  487. Msg( "Added new snapshot to database\n", szSnapshot, retcode );
  488. }
  489. int main(int argc, char* argv[])
  490. {
  491. bool bSnapShot = false;
  492. InitDefaultFileSystem();
  493. if ( argc > 1 )
  494. {
  495. for ( int i = 0; i < argc; i++ )
  496. {
  497. if ( Q_stricmp( "-snapshot", argv[i] ) == 0 )
  498. {
  499. bSnapShot = true;
  500. }
  501. if( Q_stricmp( "-weeklyupdate", argv[i] ) == 0 )
  502. {
  503. g_bWeeklyUpdate = true;
  504. }
  505. }
  506. }
  507. // Now connect to steamweb and update the engineaccess table
  508. sql = Sys_LoadModule( "mysql_wrapper" );
  509. if ( sql )
  510. {
  511. factory = Sys_GetFactory( sql );
  512. if ( factory )
  513. {
  514. mysql = ( IMySQL * )factory( MYSQL_WRAPPER_VERSION_NAME, NULL );
  515. if ( mysql == NULL )
  516. {
  517. Msg( "Unable to get MYSQL_WRAPPER_VERSION_NAME(%s) from mysql_wrapper\n", MYSQL_WRAPPER_VERSION_NAME );
  518. exit( -1 );
  519. }
  520. }
  521. else
  522. {
  523. Msg( "Sys_GetFactory on mysql_wrapper failed\n" );
  524. exit( -1 );
  525. }
  526. }
  527. else
  528. {
  529. Msg( "Sys_LoadModule( mysql_wrapper ) failed\n" );
  530. exit( -1 );
  531. }
  532. if ( GetCurrentPurchaseCount() == false )
  533. exit( -1 );
  534. ProcessBlackMarket();
  535. if ( bSnapShot == true )
  536. {
  537. AddSnapshotToDatabase();
  538. }
  539. PrintNewPrices();
  540. if ( mysql )
  541. {
  542. mysql->Release();
  543. }
  544. return 0;
  545. }