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.

235 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //
  9. //
  10. #include "stdafx.h"
  11. #include <stdio.h>
  12. #include <process.h>
  13. #include <string.h>
  14. #include <windows.h>
  15. #include <sys/stat.h>
  16. #include "interface.h"
  17. #include "imysqlwrapper.h"
  18. #include "tier1/utlvector.h"
  19. #include "tier1/utlbuffer.h"
  20. #include "tier1/utlsymbol.h"
  21. #include "tier1/utlstring.h"
  22. #include "tier1/utldict.h"
  23. #include "tier2/tier2.h"
  24. #include "filesystem.h"
  25. #include "cbase.h"
  26. #include "gamestats.h"
  27. #include "cs_gamestats.h"
  28. #include "base_gamestats_parse.h"
  29. extern CUtlDict< int, unsigned short > g_mapOrder;
  30. const char *pValidStatLevels[] =
  31. {
  32. "cs_assault",
  33. "cs_compound",
  34. "cs_havana",
  35. "cs_italy",
  36. "cs_militia",
  37. "cs_office",
  38. "de_aztec",
  39. "de_cbble",
  40. "de_chateau",
  41. "de_dust2",
  42. "de_dust",
  43. "de_inferno",
  44. "de_nuke",
  45. "de_piranesi",
  46. "de_port",
  47. "de_prodigy",
  48. "de_tides",
  49. "de_train",
  50. };
  51. static const char * s_WeaponAliasInfo[] =
  52. {
  53. "none", // WEAPON_NONE
  54. "p228", // WEAPON_P228
  55. "glock", // WEAPON_GLOCK // old glock
  56. "scout", // WEAPON_SCOUT
  57. "hegren", // WEAPON_HEGRENADE
  58. "xm1014", // WEAPON_XM1014 // auto shotgun
  59. "c4", // WEAPON_C4
  60. "mac10", // WEAPON_MAC10 // T only
  61. "aug", // WEAPON_AUG
  62. "sgren", // WEAPON_SMOKEGRENADE
  63. "elite", // WEAPON_ELITE
  64. "fiveseven",// WEAPON_FIVESEVEN
  65. "ump45", // WEAPON_UMP45
  66. "sg550", // WEAPON_SG550 // auto-sniper
  67. "galil", // WEAPON_GALIL
  68. "famas", // WEAPON_FAMAS // CT cheap m4a1
  69. "usp", // WEAPON_USP
  70. "awp", // WEAPON_AWP
  71. "mp5navy", // WEAPON_MP5N
  72. "m249", // WEAPON_M249 // big machinegun
  73. "m3", // WEAPON_M3 // cheap shotgun
  74. "m4a1", // WEAPON_M4A1
  75. "tmp", // WEAPON_TMP
  76. "g3sg1", // WEAPON_G3SG1 // T auto-sniper
  77. "flash", // WEAPON_FLASHBANG
  78. "deagle", // WEAPON_DEAGLE
  79. "sg552", // WEAPON_SG552 // T aug equivalent
  80. "ak47", // WEAPON_AK47
  81. "knife", // WEAPON_KNIFE
  82. "p90", // WEAPON_P90
  83. "shield", // WEAPON_SHIELDGUN
  84. "kevlar",
  85. "assaultsuit",
  86. "nightvision",
  87. NULL, // WEAPON_NONE
  88. };
  89. void DescribeData( cs_gamestats_t &stats )
  90. {
  91. Msg( " Blob version: %d\n", stats.header.iVersion );
  92. Msg( " Server Uptime: %d\n", stats.iMinutesPlayed );
  93. for ( int i = 0; i < CS_NUM_LEVELS; i++ )
  94. {
  95. Msg( "%s - Terrorists Wins: %d | Counter-Terrorists Wins: %d\n", pValidStatLevels[i], stats.iTerroristVictories[i], stats.iCounterTVictories[i] );
  96. }
  97. for ( int i = 0; i < WEAPON_MAX; i++ )
  98. {
  99. Msg( "%s was purchased %d time(s)\n", s_WeaponAliasInfo[i], stats.iBlackMarketPurchases[i] );
  100. }
  101. char q[ 512 ];
  102. Q_snprintf( q, sizeof( q ), "Auto-Buy = %d\n", stats.iAutoBuyPurchases );
  103. Msg( q );
  104. Q_snprintf( q, sizeof( q ), "Re-Buy = %d\n", stats.iReBuyPurchases );
  105. Msg( q );
  106. Q_snprintf( q, sizeof( q ), "Auto-Buy: M4A1 = %d\n", stats.iAutoBuyM4A1Purchases );
  107. Msg( q );
  108. Q_snprintf( q, sizeof( q ), "Auto-Buy: AK47 = %d\n", stats.iAutoBuyAK47Purchases );
  109. Msg( q );
  110. Q_snprintf( q, sizeof( q ), "Auto-Buy: Famas = %d\n", stats.iAutoBuyFamasPurchases );
  111. Msg( q );
  112. Q_snprintf( q, sizeof( q ), "Auto-Buy: Galil = %d\n", stats.iAutoBuyGalilPurchases );
  113. Msg( q );
  114. Q_snprintf( q, sizeof( q ), "Auto-Buy: Suit = %d\n", stats.iAutoBuyVestHelmPurchases );
  115. Msg( q );
  116. Q_snprintf( q, sizeof( q ), "Auto-Buy: Kev = %d\n", stats.iAutoBuyVestPurchases );
  117. Msg( q );
  118. }
  119. int CS_ParseCustomGameStatsData( ParseContext_t *ctx )
  120. {
  121. if ( g_pFullFileSystem == NULL )
  122. return CUSTOMDATA_FAILED;
  123. FileHandle_t FileHandle = g_pFullFileSystem->Open( ctx->file, "rb" );
  124. if ( !FileHandle )
  125. {
  126. return CUSTOMDATA_FAILED;
  127. }
  128. if ( ctx->mysql == NULL && ctx->describeonly == false )
  129. return CUSTOMDATA_FAILED;
  130. char q[ 512 ];
  131. cs_gamestats_t stats;
  132. g_pFullFileSystem->Read( &stats, sizeof( cs_gamestats_t ), FileHandle );
  133. if ( Q_stricmp( stats.header.szGameName, "cstrike" ) )
  134. return CUSTOMDATA_FAILED;
  135. if ( stats.header.iVersion != CS_STATS_BLOB_VERSION )
  136. {
  137. Msg( "Error: Incorrect Blob Version! Got: %d - Expected: %d\n", stats.header.iVersion, CS_STATS_BLOB_VERSION );
  138. return CUSTOMDATA_FAILED;
  139. }
  140. if ( ctx->describeonly == true )
  141. {
  142. DescribeData( stats );
  143. return CUSTOMDATA_SUCCESS;
  144. }
  145. //Do maps first
  146. for ( int i = 0; i < CS_NUM_LEVELS; i++ )
  147. {
  148. Q_snprintf( q, sizeof( q ), "update maps set TerroristWins=TerroristWins+%d, CTWins=CTWins+%d where MapName = \"%s\";", stats.iTerroristVictories[i], stats.iCounterTVictories[i], pValidStatLevels[i] );
  149. int retcode = ctx->mysql->Execute( q );
  150. if ( retcode != 0 )
  151. {
  152. printf( "Query:\n %s\n failed\n", q );
  153. return CUSTOMDATA_FAILED;
  154. }
  155. }
  156. //Now do all weapons
  157. for ( int i = 0; i < WEAPON_MAX; i++ )
  158. {
  159. int iWeaponID = i;
  160. //HACKHACK: Fix up incorrect data for the smoke grenades.
  161. if ( i == 0 && stats.iBlackMarketPurchases[i] != 0 )
  162. {
  163. iWeaponID = 9;
  164. }
  165. Q_snprintf( q, sizeof( q ), "update weapons set Count=Count+%d where WeaponID = %d;", stats.iBlackMarketPurchases[i], iWeaponID );
  166. int retcode = ctx->mysql->Execute( q );
  167. if ( retcode != 0 )
  168. {
  169. printf( "Query:\n %s\n failed\n", q );
  170. return CUSTOMDATA_FAILED;
  171. }
  172. }
  173. Q_snprintf( q, sizeof( q ), "update autobuy set Count=Count+%d where Purchase = \"Auto-Buy\";", stats.iAutoBuyPurchases );
  174. ctx->mysql->Execute( q );
  175. Q_snprintf( q, sizeof( q ), "update autobuy set Count=Count+%d where Purchase = \"Re-Buy\";", stats.iReBuyPurchases );
  176. ctx->mysql->Execute( q );
  177. Q_snprintf( q, sizeof( q ), "update autobuy set Count=Count+%d where Purchase = \"Auto-Buy: M4A1\";", stats.iAutoBuyM4A1Purchases );
  178. ctx->mysql->Execute( q );
  179. Q_snprintf( q, sizeof( q ), "update autobuy set Count=Count+%d where Purchase = \"Auto-Buy: AK47\";", stats.iAutoBuyAK47Purchases );
  180. ctx->mysql->Execute( q );
  181. Q_snprintf( q, sizeof( q ), "update autobuy set Count=Count+%d where Purchase = \"Auto-Buy: Famas\";", stats.iAutoBuyFamasPurchases );
  182. ctx->mysql->Execute( q );
  183. Q_snprintf( q, sizeof( q ), "update autobuy set Count=Count+%d where Purchase = \"Auto-Buy: Galil\";", stats.iAutoBuyGalilPurchases );
  184. ctx->mysql->Execute( q );
  185. Q_snprintf( q, sizeof( q ), "update autobuy set Count=Count+%d where Purchase = \"Auto-Buy: Suit\";", stats.iAutoBuyVestHelmPurchases );
  186. ctx->mysql->Execute( q );
  187. Q_snprintf( q, sizeof( q ), "update autobuy set Count=Count+%d where Purchase = \"Auto-Buy: Kev\";", stats.iAutoBuyVestPurchases );
  188. ctx->mysql->Execute( q );
  189. return CUSTOMDATA_SUCCESS;
  190. }