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