forked from dordnung/Ingame-Map-Download
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapdownload.sp
3578 lines (2861 loc) · 118 KB
/
mapdownload.sp
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
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Sourcemod
#include <sourcemod>
// Colors
#include <colors>
// System2
#include <system2>
// Auto append config
#include <autoexecconfig>
// Downloads Table
#include <sdktools>
// Escaping
#include <stringescape>
// Cookie for config
#undef REQUIRE_PLUGIN
#undef REQUIRE_EXTENSIONS
#include <clientprefs>
// Maybe include the updater if exists
#include <updater>
// Using semicolons ands new api
#pragma semicolon 1
#pragma newdecls required
// Table Version
#define TABLE_VERSION "2"
// URLs
#define UPDATE_URL_PLUGIN "http://dordnung.de/sourcemod/mapdl/update.txt"
#define UPDATE_URL_DB "http://dordnung.de/sourcemod/mapdl/gamebanana.sq3"
// Client menu store defines
#define SEARCH 0
#define SEARCHREAL 1
#define CAT_ID 2
#define MAPNAME 3
#define MAPFILE 4
#define MAPID 5
#define MAPSIZE 6
#define DATE 7
#define MDATE 8
#define DOWNLOADS 9
#define RATING 10
#define VOTES 11
#define VIEWS 12
#define GAME 13
#define CUSTOM 14
#define TITLE 15
#define CURRENT_MENU 16
#define NUMBER_ELEMENTS 17
// List of dl modes
enum Modus
{
MODUS_DOWNLOAD,
MODUS_UPLOAD,
MODUS_COMPRESS,
MODUS_FINISH
}
// List of download information
// Use old syntax here, otherwise enums like this won't work anymore ):
enum struct DownloadInfo
{
int DL_CLIENT; // Client of current download
int DL_FINISH; // Finished files
float DL_CURRENT; // Current Bytes
float DL_TOTAL; // Total bytes
Modus DL_MODE; // Current dl Modes
char DL_ID[32]; // Map ID
char DL_NAME[128]; // Map Name
char DL_FILE[128]; // Download Link
char DL_SAVE[PLATFORM_MAX_PATH + 1]; // Path to save to
Handle DL_FILES; // Array to store files
Handle DL_FTPFILES; // Array to store ftp files
}
// Global download list
//int g_Downloads[20][DownloadInfo];
DownloadInfo g_Downloads[20];
// Global strings
char g_sVersion[] = "2.4.0";
char g_sModes[][] = {"Downloading", "Uploading", "Compressing"};
char g_sGameSearch[64];
char g_sClientConfig[MAXPLAYERS + 1][256];
char g_sPluginPath[PLATFORM_MAX_PATH + 1];
char g_sCommand[32];
char g_sCommandCustom[32];
char g_sCommandDownload[32];
char g_sFTPCommand[32];
char g_sTag[32];
char g_sTagChat[64];
char g_sFlag[32];
char g_sFTPHost[128];
char g_sFTPUser[64];
char g_sFTPPW[128];
char g_sFTPPath[PLATFORM_MAX_PATH + 1];
char g_sGame[12];
char g_sSearch[MAXPLAYERS + 1][NUMBER_ELEMENTS][128];
char g_sLogin[MAXPLAYERS + 1][2][64];
char g_sWhitelistMaps[1024];
char g_sBlacklistMaps[1024];
char g_sWhitelistCategories[1024];
char g_sBlacklistCategories[1024];
char g_sLogPath[PLATFORM_MAX_PATH + 1];
// Global bools
bool g_bShow;
bool g_bMapCycle;
bool g_bNotice;
bool g_bFTP;
bool g_bFTPLogin;
bool g_bFirst;
bool g_bUpdate;
bool g_bUpdateDB;
bool g_bDBLoaded;
bool g_bSearch;
bool g_bDownloadList;
bool g_bUseCustom;
bool g_bClientprefsAvailable;
bool g_bForce32Bit;
// Global ints
int g_iFTPPort;
int g_iTotalDownloads;
int g_iCurrentDownload;
int g_iShowColor[4];
int g_iLast[MAXPLAYERS + 1][2];
int g_iCurrentNotice;
int g_iDatabaseRetries;
int g_iDatabaseTries;
// Global handles
ConVar g_hSearch;
ConVar g_hCommand;
ConVar g_hCommandCustom;
ConVar g_hCommandDownload;
ConVar g_hUpdate;
ConVar g_hUpdateDB;
ConVar g_hTag;
ConVar g_hFlag;
ConVar g_hShow;
ConVar g_hShowColor;
ConVar g_hMapCycle;
ConVar g_hNotice;
ConVar g_hFTP;
ConVar g_hFTPHost;
ConVar g_hFTPUser;
ConVar g_hFTPPW;
ConVar g_hFTPPort;
ConVar g_hFTPPath;
Database g_hDatabase;
Handle g_hHudSync;
ConVar g_hDownloadList;
ConVar g_hFTPLogin;
ConVar g_hFTPCommand;
ConVar g_hDatabaseRetries;
Handle g_hConfigCookie;
// Database querys
// Check if database is valid
char g_sDatabaseCheck[] = "SELECT \
`mapdl_categories_v2`.`id`, `mapdl_categories_v2`.`name`, `mapdl_categories_v2`.`game`, \
`mapdl_maps_v2`.`id`, `mapdl_maps_v2`.`categories_id`, `mapdl_maps_v2`.`date`, `mapdl_maps_v2`.`mdate`, \
`mapdl_maps_v2`.`downloads`, `mapdl_maps_v2`.`name`, `mapdl_maps_v2`.`rating`, `mapdl_maps_v2`.`votes`, \
`mapdl_maps_v2`.`views`, `mapdl_maps_v2`.`download`, `mapdl_maps_v2`.`size`, `mapdl_info_v2`.`table_version` \
FROM `mapdl_categories_v2`, `mapdl_maps_v2`, `mapdl_info_v2` LIMIT 1";
// Check if database is current version
char g_sDatabaseCheckVersion[] = "SELECT `table_version` FROM `mapdl_info_v2`";
// Get all categories
char g_sAllCategories[] = "SELECT \
`mapdl_categories_v2`.`id`, `mapdl_categories_v2`.`name`, COUNT(`mapdl_maps_v2`.`name`) FROM `mapdl_categories_v2`, `mapdl_maps_v2` \
WHERE `mapdl_categories_v2`.`game` IN %s AND `mapdl_categories_v2`.`id`=`mapdl_maps_v2`.`categories_id` %s%s%s%s GROUP BY `mapdl_categories_v2`.`name`";
// Search for a category by name
char g_sSearchCategories[] = "SELECT \
`mapdl_categories_v2`.`id`, `mapdl_categories_v2`.`name`, COUNT(`mapdl_maps_v2`.`name`) FROM `mapdl_categories_v2`, `mapdl_maps_v2` \
WHERE `mapdl_categories_v2`.`game` IN %s AND `mapdl_categories_v2`.`id`=`mapdl_maps_v2`.`categories_id` AND `mapdl_maps_v2`.`name` \
LIKE '%s' ESCAPE '?' %s%s%s%s GROUP BY `mapdl_categories_v2`.`name`";
// Get all maps
char g_sAllMaps[] = "SELECT `mapdl_maps_v2`.`id`, `mapdl_maps_v2`.`date`, `mapdl_maps_v2`.`mdate`, `mapdl_maps_v2`.`downloads`, `mapdl_maps_v2`.`rating`, `mapdl_maps_v2`.`votes`, \
`mapdl_maps_v2`.`views`, `mapdl_maps_v2`.`name`, `mapdl_maps_v2`.`download`, `mapdl_maps_v2`.`size`, `mapdl_categories_v2`.`game` FROM `mapdl_maps_v2`, `mapdl_categories_v2` \
WHERE `mapdl_maps_v2`.`categories_id`=%i AND `mapdl_maps_v2`.`categories_id` = `mapdl_categories_v2`.`id` %s%s %s";
// Search for a map by name
char g_sSearchMapsByName[] = "SELECT `mapdl_maps_v2`.`id`, `mapdl_maps_v2`.`date`, `mapdl_maps_v2`.`mdate`, `mapdl_maps_v2`.`downloads`, `mapdl_maps_v2`.`rating`, `mapdl_maps_v2`.`votes`, \
`mapdl_maps_v2`.`views`, `mapdl_maps_v2`.`name`, `mapdl_maps_v2`.`download`, `mapdl_maps_v2`.`size`, `mapdl_categories_v2`.`game` FROM `mapdl_maps_v2`, `mapdl_categories_v2` \
WHERE `mapdl_maps_v2`.`name` LIKE '%s' ESCAPE '?' AND `mapdl_maps_v2`.`categories_id`=%i AND `mapdl_maps_v2`.`categories_id` = `mapdl_categories_v2`.`id` %s%s %s";
// Search for a map by date
char g_sSearchMapsByDate[] = "SELECT `mapdl_maps_v2`.`id`, `mapdl_maps_v2`.`date`, `mapdl_maps_v2`.`mdate`, `mapdl_maps_v2`.`downloads`, `mapdl_maps_v2`.`rating`, `mapdl_maps_v2`.`votes`, \
`mapdl_maps_v2`.`views`, `mapdl_maps_v2`.`name`, `mapdl_maps_v2`.`download`, `mapdl_maps_v2`.`size`, `mapdl_categories_v2`.`game` FROM `mapdl_maps_v2`, `mapdl_categories_v2` \
WHERE `mapdl_categories_v2`.`game` IN %s AND `mapdl_maps_v2`.`categories_id` = `mapdl_categories_v2`.`id` %s%s%s%s GROUP BY `mapdl_maps_v2`.`name` ORDER BY `mapdl_maps_v2`.`date` DESC, cast(`mapdl_maps_v2`.`rating` as float) DESC LIMIT 100";
// Search for a map by last modification date
char g_sSearchMapsByMDate[] = "SELECT `mapdl_maps_v2`.`id`, `mapdl_maps_v2`.`date`, `mapdl_maps_v2`.`mdate`, `mapdl_maps_v2`.`downloads`, `mapdl_maps_v2`.`rating`, `mapdl_maps_v2`.`votes`, \
`mapdl_maps_v2`.`views`, `mapdl_maps_v2`.`name`, `mapdl_maps_v2`.`download`, `mapdl_maps_v2`.`size`, `mapdl_categories_v2`.`game` FROM `mapdl_maps_v2`, `mapdl_categories_v2` \
WHERE `mapdl_categories_v2`.`game` IN %s AND `mapdl_maps_v2`.`date` != `mapdl_maps_v2`.`mdate` AND `mapdl_maps_v2`.`categories_id` = `mapdl_categories_v2`.`id` %s%s%s%s GROUP BY `mapdl_maps_v2`.`name` ORDER BY `mapdl_maps_v2`.`mdate`DESC, cast(`mapdl_maps_v2`.`rating` as float) DESC LIMIT 100";
// Search for a map by downloads
char g_sSearchMapsByDownloads[] = "SELECT `mapdl_maps_v2`.`id`, `mapdl_maps_v2`.`date`, `mapdl_maps_v2`.`mdate`, `mapdl_maps_v2`.`downloads`, `mapdl_maps_v2`.`rating`, `mapdl_maps_v2`.`votes`, \
`mapdl_maps_v2`.`views`, `mapdl_maps_v2`.`name`, `mapdl_maps_v2`.`download`, `mapdl_maps_v2`.`size`, `mapdl_categories_v2`.`game` FROM `mapdl_maps_v2`, `mapdl_categories_v2` \
WHERE `mapdl_categories_v2`.`game` IN %s AND `mapdl_maps_v2`.`categories_id` = `mapdl_categories_v2`.`id` %s%s%s%s GROUP BY `mapdl_maps_v2`.`name` ORDER BY `mapdl_maps_v2`.`downloads` DESC, cast(`mapdl_maps_v2`.`rating` as float) DESC LIMIT 100";
// Search for a map by views
char g_sSearchMapsByViews[] = "SELECT `mapdl_maps_v2`.`id`, `mapdl_maps_v2`.`date`, `mapdl_maps_v2`.`mdate`, `mapdl_maps_v2`.`downloads`, `mapdl_maps_v2`.`rating`, `mapdl_maps_v2`.`votes`, \
`mapdl_maps_v2`.`views`, `mapdl_maps_v2`.`name`, `mapdl_maps_v2`.`download`, `mapdl_maps_v2`.`size`, `mapdl_categories_v2`.`game` FROM `mapdl_maps_v2`, `mapdl_categories_v2` \
WHERE `mapdl_categories_v2`.`game` IN %s AND `mapdl_maps_v2`.`categories_id` = `mapdl_categories_v2`.`id` %s%s%s%s GROUP BY `mapdl_maps_v2`.`name` ORDER BY `mapdl_maps_v2`.`views` DESC, cast(`mapdl_maps_v2`.`rating` as float) DESC LIMIT 100";
// Search for a map by rating
char g_sSearchMapsByRating[] = "SELECT `mapdl_maps_v2`.`id`, `mapdl_maps_v2`.`date`, `mapdl_maps_v2`.`mdate`, `mapdl_maps_v2`.`downloads`, `mapdl_maps_v2`.`rating`, `mapdl_maps_v2`.`votes`, \
`mapdl_maps_v2`.`views`, `mapdl_maps_v2`.`name`, `mapdl_maps_v2`.`download`, `mapdl_maps_v2`.`size`, `mapdl_categories_v2`.`game` FROM `mapdl_maps_v2`, `mapdl_categories_v2` \
WHERE `mapdl_categories_v2`.`game` IN %s AND `mapdl_maps_v2`.`categories_id` = `mapdl_categories_v2`.`id` %s%s%s%s GROUP BY `mapdl_maps_v2`.`name` ORDER BY cast(`mapdl_maps_v2`.`rating` as float) DESC, `mapdl_maps_v2`.`votes` DESC LIMIT 100";
// Customs
// Create Customs
char g_sCreateCustom[] = "CREATE TABLE IF NOT EXISTS `mapdl_custom` \
(`id` integer PRIMARY KEY, `name` varchar(255) NOT NULL, `url` varchar(255) NOT NULL, UNIQUE (name, url))";
// Create Customs maps
char g_sCreateCustomMaps[] = "CREATE TABLE IF NOT EXISTS `mapdl_custom_maps` \
(`custom_id` tinyint NOT NULL, `file` varchar(128) NOT NULL, UNIQUE (custom_id, file))";
// Insert name and urls
char g_InsertCustom[] = "INSERT INTO `mapdl_custom` \
(`id`, `name`, `url`) VALUES (NULL, '%s', '%s')";
// Insert Maps
char g_InsertCustomMaps[] = "INSERT INTO `mapdl_custom_maps` (`custom_id`, `file`) \
SELECT `mapdl_custom`.`id`, '%s' FROM `mapdl_custom` WHERE `mapdl_custom`.`name` = '%s'";
// Get custom urls
char g_sAllCustom[] = "SELECT `mapdl_custom`.`id`, `mapdl_custom`.`name`, COUNT(`mapdl_custom_maps`.`file`) FROM `mapdl_custom_maps`, `mapdl_custom` \
WHERE `mapdl_custom`.`id` = `mapdl_custom_maps`.`custom_id` %s%s GROUP BY `mapdl_custom`.`name`";
// Get custom urls search
char g_sSearchCustom[] = "SELECT `mapdl_custom`.`id`, `mapdl_custom`.`name`, COUNT(`mapdl_custom_maps`.`file`) FROM `mapdl_custom_maps`, `mapdl_custom` \
WHERE `mapdl_custom_maps`.`file` LIKE '%s' ESCAPE '?' AND `mapdl_custom`.`id` = `mapdl_custom_maps`.`custom_id` %s%s GROUP BY `mapdl_custom`.`name`";
// Get custom maps
char g_sAllCustomMaps[] = "SELECT `mapdl_custom_maps`.`file`, `mapdl_custom`.`url` FROM `mapdl_custom_maps`, `mapdl_custom` \
WHERE `mapdl_custom_maps`.`custom_id`=%i AND `mapdl_custom`.`id` = `mapdl_custom_maps`.`custom_id` %s%s GROUP BY `mapdl_custom_maps`.`file`";
// Get custom maps search
char g_sSearchCustomMaps[] = "SELECT `mapdl_custom_maps`.`file`, `mapdl_custom`.`url` FROM `mapdl_custom_maps`, `mapdl_custom` \
WHERE `mapdl_custom_maps`.`file` LIKE '%s' ESCAPE '?' AND `mapdl_custom_maps`.`custom_id`=%i AND `mapdl_custom`.`id` = `mapdl_custom_maps`.`custom_id` %s%s GROUP BY `mapdl_custom_maps`.`file`";
// Global info
public Plugin myinfo =
{
name = "Ingame Map Download",
author = "dordnung",
version = g_sVersion,
description = "Allows admins to download maps ingame"
};
/*
**************
MAIN METHODS
**************
*/
// Plugin started
public void OnPluginStart()
{
// Load Translation
LoadTranslations("core.phrases");
LoadTranslations("mapdownload.phrases");
// First is true!
g_bFirst = true;
g_bDBLoaded = false;
g_bUseCustom = false;
g_bClientprefsAvailable = false;
g_bForce32Bit = false;
g_iCurrentNotice = 0;
g_iDatabaseTries = 0;
g_iShowColor = {255, 255, 255, 255};
// Init. AutoExecConfig
AutoExecConfig_SetFile("plugin.mapdownload");
// Public Cvar
AutoExecConfig_CreateConVar("mapdownload_version", g_sVersion, "Ingame Map Download Version", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY | FCVAR_DONTRECORD);
// Set Cvars
g_hCommand = AutoExecConfig_CreateConVar("mapdownload_command", "sm_mapdl", "Command to open Map Download menu. Append prefix 'sm_' for chat use!");
g_hCommandCustom = AutoExecConfig_CreateConVar("mapdownload_command_custom", "sm_mapdl_custom", "Command to open custom Map Download menu. Append prefix 'sm_' for chat use!");
g_hCommandDownload = AutoExecConfig_CreateConVar("mapdownload_command_download", "sm_mapdl_url", "Command to download a map directly from an url. Append prefix 'sm_' for chat use!");
g_hTag = AutoExecConfig_CreateConVar("mapdownload_tag", "Map Download", "Chat prefix of Map Download");
g_hFlag = AutoExecConfig_CreateConVar("mapdownload_flag", "bg", "Flagstring to access menu (see configs/admin_levels.cfg)");
g_hShow = AutoExecConfig_CreateConVar("mapdownload_show", "0", "1 = All players see map downloading status, 0 = Only admins");
g_hShowColor = AutoExecConfig_CreateConVar("mapdownload_show_color", "255,255,255,255", "RGBA Color of the HUD Text if available", FCVAR_PROTECTED);
g_hDatabaseRetries = AutoExecConfig_CreateConVar("mapdownload_retries", "1", "Numbers of retries to load database");
g_hSearch = AutoExecConfig_CreateConVar("mapdownload_search", "1", "1 = Search searchmask within a string, 0 = Search excact mask");
g_hMapCycle = AutoExecConfig_CreateConVar("mapdownload_mapcycle", "1", "1 = Write downloaded map in mapcycle.txt, 0 = Off");
g_hNotice = AutoExecConfig_CreateConVar("mapdownload_notice", "1", "1 = Notice admins on server that Map Download runs, 0 = Off");
g_hDownloadList = AutoExecConfig_CreateConVar("mapdownload_downloadlist", "1", "1 = Add custom files of a map into an intern downloadlist, all items whill be loaded when a player will connect the first time, 0 = Off");
g_hUpdate = AutoExecConfig_CreateConVar("mapdownload_update_plugin", "1", "1 = Auto update plugin with God Tony's autoupdater, 0 = Off");
g_hUpdateDB = AutoExecConfig_CreateConVar("mapdownload_update_database", "1", "1 = Auto download gamebanana database on plugin start, 0 = Off");
g_hFTP = AutoExecConfig_CreateConVar("mapdownload_ftp", "0", "1 = Use Fast Download upload, 0 = Off");
g_hFTPLogin = AutoExecConfig_CreateConVar("mapdownload_ftp_login", "0", "1 = Player have to insert username and password of ftp server in his console (Security), 0 = Off");
g_hFTPCommand = AutoExecConfig_CreateConVar("mapdownload_ftp_command", "mapdl_login", "Command to set username and passwort if 'mapdownload_ftp_ingame = 1'");
g_hFTPHost = AutoExecConfig_CreateConVar("mapdownload_ftp_host", "192.168.0.1", "Host of your FastDL server", FCVAR_PROTECTED);
g_hFTPPort = AutoExecConfig_CreateConVar("mapdownload_ftp_port", "21", "Port of your FastDL server", FCVAR_PROTECTED);
g_hFTPUser = AutoExecConfig_CreateConVar("mapdownload_ftp_user", "username", "Username to login", FCVAR_PROTECTED);
g_hFTPPW = AutoExecConfig_CreateConVar("mapdownload_ftp_pass", "password", "Password for username to login", FCVAR_PROTECTED);
g_hFTPPath = AutoExecConfig_CreateConVar("mapdownload_ftp_path", "path/on/fastdl", "Path to your FastDL gamedir folder, including folders maps, sound, and so on", FCVAR_PROTECTED);
// Exec Config
AutoExecConfig(true, "plugin.mapdownload");
// clean Config
AutoExecConfig_CleanFile();
}
// Config is executed
public void OnConfigsExecuted()
{
char showColor[32];
char showColorExploded[4][12];
// Read all convars
// Ints
g_iFTPPort = g_hFTPPort.IntValue;
// Bools
g_bNotice = g_hNotice.BoolValue;
g_bShow = g_hShow.BoolValue;
g_bMapCycle = g_hMapCycle.BoolValue;
g_bFTP = g_hFTP.BoolValue;
g_bFTPLogin = (g_hFTPLogin.BoolValue && g_bFTP);
g_bUpdate = g_hUpdate.BoolValue;
g_bUpdateDB = g_hUpdateDB.BoolValue;
g_bSearch = g_hSearch.BoolValue;
g_bDownloadList = g_hDownloadList.BoolValue;
g_iDatabaseRetries = g_hDatabaseRetries.BoolValue;
// Strings
g_hShowColor.GetString(showColor, sizeof(showColor));
g_hCommand.GetString(g_sCommand, sizeof(g_sCommand));
g_hCommandCustom.GetString(g_sCommandCustom, sizeof(g_sCommandCustom));
g_hCommandDownload.GetString(g_sCommandDownload, sizeof(g_sCommandDownload));
g_hFTPCommand.GetString(g_sFTPCommand, sizeof(g_sFTPCommand));
g_hTag.GetString(g_sTag, sizeof(g_sTag));
g_hFlag .GetString(g_sFlag, sizeof(g_sFlag));
g_hFTPHost.GetString(g_sFTPHost, sizeof(g_sFTPHost));
g_hFTPUser.GetString(g_sFTPUser, sizeof(g_sFTPUser));
g_hFTPPW.GetString(g_sFTPPW, sizeof(g_sFTPPW));
g_hFTPPath.GetString(g_sFTPPath, sizeof(g_sFTPPath));
// Hud Sync
g_hHudSync = CreateHudSynchronizer();
// Explode Colors
int found = ExplodeString(showColor, ",", showColorExploded, sizeof(showColorExploded), sizeof(showColorExploded[]));
if (found == 4)
{
int r = StringToInt(showColorExploded[0]);
int g = StringToInt(showColorExploded[1]);
int b = StringToInt(showColorExploded[2]);
int a = StringToInt(showColorExploded[3]);
if (r < 0 || r > 255)
{
LogError("Red Color have to be between 0 and 255 in '%s'!", showColor);
}
else
{
g_iShowColor[0] = r;
}
if (g < 0 || g > 255)
{
LogError("Green Color have to be between 0 and 255 in '%s'!", showColor);
}
else
{
g_iShowColor[1] = g;
}
if (b < 0 || b > 255)
{
LogError("Blue Color have to be between 0 and 255 in '%s'!", showColor);
}
else
{
g_iShowColor[2] = b;
}
if (a < 0 || a > 255)
{
LogError("Alpha have to be between 0 and 255 in '%s'!", showColor);
}
else
{
g_iShowColor[3] = a;
}
}
else
{
LogError("RGBA Colors '%s' have an invalid format!", showColor);
}
// Add Auto Updater if exit and wanted
if (LibraryExists("updater") && g_bUpdate)
{
Updater_AddPlugin(UPDATE_URL_PLUGIN);
}
// Check for clientprefs
if (LibraryExists("clientprefs"))
{
g_bClientprefsAvailable = true;
g_hConfigCookie = RegClientCookie("mapdl_config", "MapDownload Config Cookie", CookieAccess_Private);
}
// Disable Hud Hint sound
ConVar cvar = FindConVar("sv_hudhint_sound");
if (cvar != null)
{
cvar.SetInt(0);
}
// First start?
if (g_bFirst)
{
// Reset
g_iCurrentDownload = -1;
g_iTotalDownloads = 0;
// Now register command to open menu
RegAdminCmd(g_sCommand, OpenMenu, ReadFlagString(g_sFlag));
RegAdminCmd(g_sCommandCustom, OpenMenuCustom, ReadFlagString(g_sFlag));
RegAdminCmd(g_sCommandDownload, DownloadMapDirect, ReadFlagString(g_sFlag));
RegConsoleCmd(g_sFTPCommand, OnSetLoginData);
// Prepare folders and connect to database
PreparePlugin();
// Start notice timer, every 6 minutes
if (g_bNotice)
{
CreateTimer(360.0, NoticeTimer, _, TIMER_REPEAT);
}
// Started
g_bFirst = false;
}
// Change color for csgo
if (StrEqual(g_sGame, "csgo", false))
{
CReplaceColor(Color_Green, Color_Lightred);
CReplaceColor(Color_Lightgreen, Color_Lime);
}
// No Lightgreen?
if (!CColorAllowed(Color_Lightgreen))
{
CReplaceColor(Color_Lightgreen, Color_Olive);
}
// Load the downloadlist
ParseDownloadList();
}
// All plugins are loaded now
public void OnAllPluginsLoaded()
{
// Is system2 extension here?
if (!LibraryExists("system2"))
{
// No -> stop plugin!
SetFailState("Attention: Extension system2 couldn't be found. Please install it to run Map Download!");
}
char binDir[PLATFORM_MAX_PATH];
char binDir32Bit[PLATFORM_MAX_PATH];
if (!System2_Check7ZIP(binDir, sizeof(binDir))) {
if (!System2_Check7ZIP(binDir32Bit, sizeof(binDir32Bit), true)) {
if (StrEqual(binDir, binDir32Bit)) {
SetFailState("Attention: 7-ZIP was not found or is not executable at '%s'", binDir);
} else {
SetFailState("Attention: 7-ZIP was not found or is not executable at '%s' or '%s'", binDir, binDir32Bit);
}
} else {
g_bForce32Bit = true;
Log("Attention: 64-Bit version of 7-ZIP was not found or is not executable at '%s', falling back to 32-Bit version!", binDir);
}
}
}
// Logging Stuff
void Log(char[] fmt, any ...)
{
char format[1024];
char file[PLATFORM_MAX_PATH + 1];
char currentDate[32];
VFormat(format, sizeof(format), fmt, 2);
FormatTime(currentDate, sizeof(currentDate), "%d-%m-%y");
Format(file, sizeof(file), "%s/mapdownload_(%s).log", g_sLogPath, currentDate);
LogToFile(file, "[ MAPDL ] %s", format);
}
// Client cookies are cached
public void OnClientCookiesCached(int client)
{
int config = GetClientConfigCookie(client);
switch(config)
{
case 0:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY LOWER(`mapdl_maps_v2`.`name`) ASC");
}
case 1:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY LOWER(`mapdl_maps_v2`.`name`) DESC");
}
case 2:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY `mapdl_maps_v2`.`date` DESC, cast(`mapdl_maps_v2`.`rating` as float) DESC");
}
case 3:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY `mapdl_maps_v2`.`date` ASC, cast(`mapdl_maps_v2`.`rating` as float) ASC");
}
case 4:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "AND `mapdl_maps_v2`.`date` != `mapdl_maps_v2`.`mdate` ORDER BY `mapdl_maps_v2`.`mdate` DESC, cast(`mapdl_maps_v2`.`rating` as float) DESC");
}
case 5:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "AND `mapdl_maps_v2`.`date` != `mapdl_maps_v2`.`mdate` ORDER BY `mapdl_maps_v2`.`mdate` ASC, cast(`mapdl_maps_v2`.`rating` as float) ASC");
}
case 6:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY `mapdl_maps_v2`.`downloads` DESC, cast(`mapdl_maps_v2`.`rating` as float) DESC");
}
case 7:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY `mapdl_maps_v2`.`downloads` ASC, cast(`mapdl_maps_v2`.`rating` as float) ASC");
}
case 8:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY `mapdl_maps_v2`.`views` DESC, cast(`mapdl_maps_v2`.`rating` as float) DESC");
}
case 9:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY `mapdl_maps_v2`.`views` ASC, cast(`mapdl_maps_v2`.`rating` as float) ASC");
}
case 10:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY cast(`mapdl_maps_v2`.`rating` as float) DESC, `mapdl_maps_v2`.`votes` DESC");
}
case 11:
{
strcopy(g_sClientConfig[client], sizeof(g_sClientConfig[]), "ORDER BY cast(`mapdl_maps_v2`.`rating` as float) ASC, `mapdl_maps_v2`.`votes` ASC");
}
}
}
// Set Title at search
void SetTitleWithCookie(int client)
{
int config = GetClientConfigCookie(client);
switch(config)
{
case 0:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "0");
}
case 1:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "0");
}
case 2:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "1");
}
case 3:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "1");
}
case 4:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "2");
}
case 5:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "2");
}
case 6:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "3");
}
case 7:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "3");
}
case 8:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "4");
}
case 9:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "4");
}
case 10:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "5");
}
case 11:
{
strcopy(g_sSearch[client][TITLE], sizeof(g_sSearch[][]), "5");
}
}
}
// Gets the Client cookie
int GetClientConfigCookie(int client)
{
// Only with clientprefs
if (g_bClientprefsAvailable && IsClientValid(client) && AreClientCookiesCached(client))
{
char buffer[8];
GetClientCookie(client, g_hConfigCookie, buffer, sizeof(buffer));
return StringToInt(buffer);
}
return -1;
}
// Prepare folders and connect to database
void PreparePlugin()
{
// Build plugin paths
BuildPath(Path_SM, g_sPluginPath, sizeof(g_sPluginPath), "data/mapdownload");
BuildPath(Path_SM, g_sLogPath, sizeof(g_sLogPath), "data/mapdownload/logs");
// Check if paths exist
// If not, create them!
if (!DirExists(g_sPluginPath))
{
CreateDirectory(g_sPluginPath, 511);
}
if (!DirExists(g_sLogPath))
{
CreateDirectory(g_sLogPath, 511);
}
// Temp dir
Format(g_sPluginPath, sizeof(g_sPluginPath), "%s/temp", g_sPluginPath);
// First delete old temp path
DeletePath(g_sPluginPath);
// Create new one
CreateDirectory(g_sPluginPath, 511);
// Format tags
Format(g_sTagChat, sizeof(g_sTagChat), "{lightgreen}[{green} %s {lightgreen}]", g_sTag);
Format(g_sTag, sizeof(g_sTag), "[ %s ]", g_sTag);
// Get the game
GetGameFolderName(g_sGame, sizeof(g_sGame));
// We need the gamename of gamebanana
if (StrEqual(g_sGame, "tf", false))
{
Format(g_sGame, sizeof(g_sGame), "tf2");
}
else if (StrEqual(g_sGame, "cstrike", false))
{
Format(g_sGame, sizeof(g_sGame), "css");
}
else if (StrEqual(g_sGame, "hl2mp", false))
{
Format(g_sGame, sizeof(g_sGame), "hl2dm");
}
else if (StrEqual(g_sGame, "dod", false))
{
Format(g_sGame, sizeof(g_sGame), "dods");
}
else if (!StrEqual(g_sGame, "csgo", false))
{
// Log error and stop plugin
LogError("%s isn't supported for Map Download!", g_sGame);
SetFailState("%s isn't supported for Map Download!", g_sGame);
}
// Format Search
Format(g_sGameSearch, sizeof(g_sGameSearch), "('%s')", g_sGame);
// If no DB update -> Load Database
if (!g_bUpdateDB)
{
// Save methods :)
PrepareDB(true, "", null, null, METHOD_GET);
}
else
{
char path[PLATFORM_MAX_PATH + 1];
// Path to sql file
BuildPath(Path_SM, path, sizeof(path), "data/sqlite/gamebanana.sq3");
// Download current database
System2HTTPRequest downloadRequest = new System2HTTPRequest(PrepareDB, UPDATE_URL_DB);
downloadRequest.SetOutputFile(path);
downloadRequest.GET();
delete downloadRequest;
}
}
// Prepare folders and connect to database
void ParseDownloadList()
{
// Parse Downloadlist
if (g_bDownloadList)
{
char dllistFile[PLATFORM_MAX_PATH + 1];
char readbuffer[64];
// Path to downloadlist
BuildPath(Path_SM, dllistFile, sizeof(dllistFile), "data/mapdownload/downloadlist.txt");
// Open file
File file = OpenFile(dllistFile, "rb");
// We could open file
if (file != null)
{
// Loop through file content
while (!file.EndOfFile() && file.ReadLine(readbuffer, sizeof(readbuffer)))
{
// Replace line ends
ReplaceString(readbuffer, sizeof(readbuffer), "\n", "");
ReplaceString(readbuffer, sizeof(readbuffer), "\t", "");
ReplaceString(readbuffer, sizeof(readbuffer), "\r", "");
// No comments or spaces at start
if (readbuffer[0] == '/' || readbuffer[0] == ' ')
{
continue;
}
// Add to download table
AddFileToDownloadsTable(readbuffer);
}
// Close File
file.Close();
}
}
}
// Create DB Connection
public void PrepareDB(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method)
{
if (g_bUpdateDB)
{
char detailError[256];
// Response 200 expected
if (success && response != null && response.StatusCode != 200)
{
success = false;
Format(detailError, sizeof(detailError), "Expected HTTP status code 200, but got %d", response.StatusCode);
}
else
{
strcopy(detailError, sizeof(detailError), error);
}
if (!success)
{
// We couldn't update the db
if (g_iDatabaseRetries > g_iDatabaseTries)
{
// We couldn't update the db
LogError("Attention: Couldn't update database. Error: '%s'. Trying again...", detailError);
g_iDatabaseTries++;
// Retry the download
request.GET();
return;
}
else
{
LogError("Attention: Couldn't update database after %d retries. Error: '%s'. Try to restart your server", g_iDatabaseTries, detailError);
}
}
else
{
// Notice update
Log("Updated gamebanana Database succesfully!");
}
}
char sqlError[256];
// Connect to database
KeyValues dbValue = new KeyValues("Databases");
dbValue.SetString("driver", "sqlite");
dbValue.SetString("host", "localhost");
dbValue.SetString("database", "gamebanana");
dbValue.SetString("user", "root");
// Connect
g_hDatabase = SQL_ConnectCustom(dbValue, sqlError, sizeof(sqlError), true);
// Close Keyvalues
delete dbValue;
// Check valid connection
if (g_hDatabase == null)
{
// Log error and stop plugin
LogError("Map Download couldn't connect to the Database! Error: %s", sqlError);
SetFailState("Map Download couldn't connect to the Database! Error: %s", sqlError);
}
else
{
// Create Transaction
Transaction txn = new Transaction();
txn.AddQuery(g_sDatabaseCheck, 1);
txn.AddQuery(g_sDatabaseCheckVersion, 2);
txn.AddQuery(g_sCreateCustom, 3);
txn.AddQuery(g_sCreateCustomMaps, 4);
g_hDatabase.Execute(txn, OnDBStartedUp, OnDBStartUpFailed);
}
}
// Everything is started up
public void OnDBStartedUp(Database db, any data, int numQueries, DBResultSet[] results, any[] queryData)
{
for (int i=0; i < numQueries; i++)
{
if (queryData[i] == 1)
{
// Check valid database
if (!results[i].FetchRow())
{
LogError("Map Download database seems to be empty!");
}
}
if (queryData[i] == 2)
{
char version[16];
// Check valid database version
if (!results[i].FetchRow())
{
LogError("Your Map Download database seems to be outdated!");
}
results[i].FetchString(0, version, sizeof(version));
if (!StrEqual(version, TABLE_VERSION, false))
{
LogError("Your Map Download database seems to be outdated: Found '%s', expected '%s'!", version, TABLE_VERSION);
}
}
}
// Now we can load white,black and customlist
ParseLists();
// Database loaded
g_bDBLoaded = true;
}
// start up failed
public void OnDBStartUpFailed(Database db, any data, int numQueries, const char[] error, int failIndex, any[] queryData)
{
LogError("Map Download couldn't prepare the Database. Error: '%s'", error);
if (g_iDatabaseRetries > g_iDatabaseTries)
{
g_iDatabaseTries++;
// Retrie
PrepareDB(true, "", null, null, METHOD_GET);
}
}
// Parse the white,black and customlist
void ParseLists()
{
char listPath[PLATFORM_MAX_PATH + 1];
KeyValues listKeyValue = new KeyValues("MapDownloadLists");
// Path
BuildPath(Path_SM, listPath, sizeof(listPath), "configs/mapdownload_lists.cfg");
// List file exists?
if (!FileExists(listPath))
{
// no...
return;
}