-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathUServer.Types.pas
More file actions
1264 lines (1073 loc) · 29.7 KB
/
UServer.Types.pas
File metadata and controls
1264 lines (1073 loc) · 29.7 KB
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
unit UServer.Types;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, HGM.Controls.VirtualTable, UnturnedIDB, System.IniFiles,
Vcl.ExtCtrls, System.Generics.Collections, HGM.Controls.PanelCollapsed,
Vcl.Buttons;
type
TAround = (caGroup, caArea, caWorld);
TChatFrom = (cfConsole, cfSite, cfAdmin, cfInfo, cfPlayer);
TConState = (csNone, csConnected, csDisconnected, csConnecting);
TGetPlayersIDFunc = procedure(var Items: TStringList) of object;
TListInt = TList<Integer>;
TListString = TList<string>;
TLoadouts = TListString;
TLogHandler = procedure(Text: string) of object;
TPBPos = (pbpNone, pbpWork, pbpError, pbpOK);
TPVMode = (modePVP, modePVE);
TSendCommandHandler = procedure(Command: string) of object;
TSteamID = string;
TThWork = (twNone, twWork, twExcept, twExit);
TTimeWords = (twYears, twMonths, twDays, twHours, twMinutes, twSeconds);
TServerStartCommands = record
private
FLoadouts: TLoadouts;
public
MaxPlayers: Integer;
Port: Integer;
Name: string; //50
Map: string;
Mode: string;
PVMode: TPVMode;
Cheats: Boolean;
Gold: Boolean;
Timeout: Integer;
Perspective: string;
Log: string;
Owner: string;
Votify: string;
Welcome: string;
BindIP: string;
Cycle: Integer;
procedure AddLoadout(Value: string);
procedure SetDefault;
property Loadouts: TLoadouts read FLoadouts write FLoadouts;
procedure Create;
end;
TGameMessage = record
ID: Integer;
Text: string;
Color: TColor;
end;
TGameMessages = class(TTableData<TGameMessage>)
private
FCurrentMessage: Integer;
public
function GetNext: TGameMessage;
function SetNext(Value: Integer): TGameMessage;
procedure Randomize;
property CurrentMessage: Integer read FCurrentMessage;
constructor Create(AOwner: TTableEx); override;
end;
TMark = record
ID: Integer;
ValueStr: string;
ValueInt: Integer;
Date: TDateTime;
end;
TMarks = TTableData<TMark>;
TPlayer = record
SteamID: TSteamID;
GameName: string;
SteamName: string;
Ping: string;
function Create(pSID, pGName, pSName: string): TPlayer;
end;
TDonat = record
ID: Integer;
Group: string;
DateBegin: TDateTime;
DateEnd: TDateTime;
Days: Integer;
Active: Boolean;
Unlimit: Boolean;
Comment: string;
Player: TPlayer;
end;
TDonats = TTableData<TDonat>;
TServerAction = record
Date: TDateTime;
SteamID: TSteamID;
Data: string;
function Create(pDate: TDateTime; pData: string; pSteamID: string = ''): TServerAction;
end;
TServerActions = class(TTableData<TServerAction>)
function Add(Data: string; SteamID: string): Integer; overload;
end;
THearthBeat = record
BeatValue: Byte;
procedure Beat;
end;
TChatRecord = record
From: TChatFrom;
Date: TDateTime;
Text: string;
Player: TPlayer;
Around: TAround;
PM: Boolean;
function Message: string;
end;
TChatList = class(TTableData<TChatRecord>)
procedure DeleteLast;
end;
TUEItems = class(TDisplayDataItems)
function GetItemDesc(ID: Integer): string;
end;
TUEVehicles = class(TDisplayDataVehicles)
function GetItemDesc(ID: Integer): string;
end;
TMapPlace = record
Name: string;
Desc: string;
function Create(aName, aDesc: string): TMapPlace;
end;
TMapPlaces = TTableData<TMapPlace>;
PProcessData = ^TProcessData;
TProcessData = record
UseMemory: Cardinal; //Èñï. ÎÇÓ
CntThreads: Word; //Ïîòîêîâ
OKTime: Int64;
OUTime: Int64;
CPUUse: Double; //Èñïîëüçîâàíèå ÖÏ
end;
TLogRecord = record
Date: TDateTime;
Value: string;
function Create(pValue: string; pDate: TDateTime): TLogRecord; overload;
function Create(pValue: string): TLogRecord; overload;
function ToString: string;
end;
TLog = class(TTableData<TLogRecord>)
private
FSize: Integer;
public
function Add(Value: TLogRecord): Integer; override;
constructor Create(Table: TTableEx; Size: Integer);
end;
TKitItem = record
DBID: Integer;
ID: string;
Pic: TBitmap;
Count: Integer;
class function Create(pDBID: Integer; pID: string; pCount: Integer): TKitItem; static;
end;
TKit = class(TList<TKitItem>)
private
FDBID: Integer;
FKitName: string;
public
property KitName: string read FKitName write FKitName;
property DBID: Integer read FDBID write FDBID;
constructor Create(pID: Integer; pKitName: string);
end;
TKits = class(TTableData<TKit>)
end;
TDashboardItem = record
Col: Word;
Order: Integer;
Control: TPanelCollapsed;
end;
TDashboardItems = TList<TDashboardItem>;
TDashboard = class
private
FItems: TDashboardItems;
FCols: Word;
FIntervalTop: Word;
FIntervalLeft: Word;
FColor: TColor;
FFont: TColor;
FFontCap: TColor;
FColorBorder: TColor;
procedure FUpdate;
procedure SetCols(const Value: Word);
procedure SetColor(const Value: TColor);
procedure SetFontContent(const Value: TColor);
procedure SetFontCaption(const Value: TColor);
procedure SetColorBorder(const Value: TColor);
public
class function CreateItem(Col: Word; Order: Integer; Ctrl: TPanelCollapsed): TDashboardItem;
procedure Update;
function Reg(Item: TDashboardItem): Integer;
function Unreg(Item: TDashboardItem): Boolean;
constructor Create(APlace: TControl);
property Cols: Word read FCols write SetCols;
property IntervalTop: Word read FIntervalTop write FIntervalTop;
property IntervalLeft: Word read FIntervalLeft write FIntervalLeft;
property Color: TColor read FColor write SetColor;
property ColorBorder: TColor read FColorBorder write SetColorBorder;
property FontContent: TColor read FFont write SetFontContent;
property FontCaption: TColor read FFontCap write SetFontCaption;
end;
TSettings = class
private
FIniFile: TIniFile;
public
function GetBool(const Section, Ident: string; Default: Boolean): Boolean; overload;
function GetBool(const Element: array of string; Default: Boolean): Boolean; overload;
function GetInt(const Section, Ident: string; Default: Integer): Integer; overload;
function GetInt(const Element: array of string; Default: Integer): Integer; overload;
function GetStr(const Section, Ident: string; Default: string): string; overload;
function GetStr(const Element: array of string; Default: string): string; overload;
function GetDate(const Section, Ident: string; Default: TDateTime): TDateTime; overload;
function GetDate(const Element: array of string; Default: TDateTime): TDateTime; overload;
procedure SetBool(const Section, Ident: string; Value: Boolean); overload;
procedure SetBool(const Element: array of string; Value: Boolean); overload;
procedure SetInt(const Section, Ident: string; Value: Integer); overload;
procedure SetInt(const Element: array of string; Value: Integer); overload;
procedure SetStr(const Section, Ident: string; Value: string); overload;
procedure SetStr(const Element: array of string; Value: string); overload;
procedure SetDate(const Section, Ident: string; Value: TDateTime); overload;
procedure SetDate(const Element: array of string; Value: TDateTime); overload;
constructor Create(FileName: TFileName);
destructor Destroy;
end;
TPlayerInfoRecord = record
private
function GetFrom: string;
public
SteamID: string;
SteamName: string;
CharName: string;
IP: string;
LastLoginGlobal: TDateTime;
TotalPlayTime: Cardinal;
LastServerID: Integer;
FromCountry: string;
FromCity: string;
RegDate: TDateTime;
Balance: Extended;
KillSZombie: Integer;
KillMZombie: Integer;
KillAnimal: Integer;
KillPlayer: Integer;
function Score: Integer;
property From: string read GetFrom;
function RegDateString: string;
function GetPlayerData: TPlayer;
end;
TPlayerInfo = TTableData<TPlayerInfoRecord>;
TConsoleAnswer = record
Question: string;
Answer: string;
function Create(Q, A: string): TConsoleAnswer;
end;
TConsoleAnswers = TList<TConsoleAnswer>;
TPlayers = class(TTableData<TPlayer>)
function Delete(SteamID: string): Boolean; overload;
end;
TPlayerRev = record
Player: TPlayer;
Connected: Boolean;
DateTime: TDateTime;
function Create(pPlayer: TPlayer; pCon: Boolean; pDate: TDateTime): TPlayerRev;
end;
TPlayersRev = TTableData<TPlayerRev>;
TExecutedCommand = record
CommandText: string;
Date: TDateTime;
end;
TExecutedCommands = class(TList<TExecutedCommand>)
FCurIndex: Integer;
public
procedure New(Command: string);
procedure ResetCur;
function GetPrev(var Cmd: string): Boolean;
function GetNext(var Cmd: string): Boolean;
constructor Create;
end;
TAdminPlayer = record
public
PlayerSteamName: string;
PlayerGameName: string; //Hemul
PlayerSteamID: string; //76561198357353975
//
JudgeSteamID: string; //Ñóäüÿ 76561198182216738
JudgeGameName: string; //Ñóäüÿ
JudgeSteamName: string; //Ñóäüÿ
end;
TAdmins = TTableData<TAdminPlayer>;
TBannedPlayer = record
public
PlayerSteamName: string;
PlayerGameName: string; //Hemul
PlayerSteamID: string; //76561198357353975
//
JudgeSteamID: string; //Ñóäüÿ 76561198182216738
JudgeGameName: string; //Ñóäüÿ 76561198182216738
JudgeSteamName: string; //Ñóäüÿ 76561198182216738
Reason: string; //ïðè÷èíà
Duration: Int64; //31536000 ñåêóíä+
Remaining: Int64; //29330614 îñòàëîñü
end;
TBans = TTableData<TBannedPlayer>;
TStatData = record
ID: Integer;
Date: TDateTime;
Value: Extended;
function Create(pID: Integer; pDate: TDateTime; pValue: Extended): TStatData;
end;
TStatistics = TList<TStatData>;
TCurrentStatistics = record
private
FAVGTMP: Integer;
FMaxPlayersDate: TDate;
FMaxPlayers: Cardinal;
FAllPlayers: Cardinal;
FNewPlayers: Cardinal;
FEndPlayers: Cardinal;
FAllPlayersToday: Cardinal;
FAllPlayersMonth: Cardinal;
FAllPlayersYest: Cardinal;
FNewPlayersYest: Cardinal;
FEndPlayersYest: Cardinal;
FActivePlayers: Cardinal;
FNoPlayers: Cardinal;
FAvgPlayTime: Cardinal;
procedure SetMaxPlayers(const Value: Cardinal);
function GetMaxPlayers: Cardinal;
public
procedure BeginUpdate;
procedure UpdateStat(PI: TPlayerInfoRecord);
procedure EndUpdate;
property MaxPlayers: Cardinal read GetMaxPlayers write SetMaxPlayers;
property AllPlayers: Cardinal read FAllPlayers write FAllPlayers;
property NewPlayers: Cardinal read FNewPlayers write FNewPlayers;
property EndPlayers: Cardinal read FEndPlayers write FEndPlayers;
property AllPlayersToday: Cardinal read FAllPlayersToday write FAllPlayersToday;
property AllPlayersMonth: Cardinal read FAllPlayersMonth write FAllPlayersMonth;
property AllPlayersYest: Cardinal read FAllPlayersYest write FAllPlayersYest;
property NewPlayersYest: Cardinal read FNewPlayersYest write FNewPlayersYest;
property EndPlayersYest: Cardinal read FEndPlayersYest write FEndPlayersYest;
property ActivePlayers: Cardinal read FActivePlayers write FActivePlayers;
property NoPlayers: Cardinal read FNoPlayers write FNoPlayers;
property AvgPlayTime: Cardinal read FAvgPlayTime write FAvgPlayTime;
end;
TUpdatedDataPlayerFrom = record
City, Country: string;
SteamID: TSteamID;
end;
TUpdatedDataPlayerFromList = TList<TUpdatedDataPlayerFrom>;
function IsYestarday(const AValue: TDateTime): Boolean;
function DaysAndTimeToStr(D: Cardinal; H, M, S: Word): string;
function GetWord(TW: TTimeWords; Value: Integer): string;
function GetWithWord(TW: TTimeWords; Value: Integer): string;
function TranslateGoogle(Text, myLang, toLang: string): string;
function IFELSESTR(Value: Boolean; ResTrue, ResFalse: string): string;
function Ask(Text: string): Boolean;
function Warning(Text: string): Boolean;
procedure SecToDateTime(Value: Cardinal; var D: Cardinal; var H, M, S: Word);
procedure SecToTime(Value: Cardinal; var H, M, S: Word);
const
TimeWords: array[TTimeWords, 1..3] of string =
(('ãîä', 'ãîäà', 'ëåò'),
('ìåñÿö', 'ìåñÿöà', 'ìåñÿöåâ'),
('äåíü', 'äíÿ', 'äíåé'),
('÷àñ', '÷àñà', '÷àñîâ'),
('ìèíóòà', 'ìèíóòû', 'ìèíóò'),
('ñåêóíäà', 'ñåêóíäû', 'ñåêóíä'));
EndPlayersTime = 60 * 60;
ActivePlayersTime = 30 * 60 * 60;
implementation
uses
Math, System.DateUtils, MMSystem, IdHTTP, StrUtils, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, UServer.CommonFunc;
function Warning(Text: string): Boolean;
begin
MessageBox(Application.Handle, PWideChar(Text), 'Âíèìàíèå', MB_ICONWARNING or MB_OK);
Result := True;
end;
function Ask(Text: string): Boolean;
begin
Result := MessageBox(Application.Handle, PWideChar(Text), 'Âîïðîñ', MB_ICONQUESTION or MB_YESNO) = ID_YES;
end;
function IsYestarday(const AValue: TDateTime): Boolean;
begin
Result := IsSameDay(AValue, Date - 1);
end;
function IFELSESTR(Value: Boolean; ResTrue, ResFalse: string): string;
begin
if Value then
Result := ResTrue
else
Result := ResFalse;
end;
function TranslateGoogle(Text, myLang, toLang: string): string;
var
HTTP: TidHTTP;
PostData: TStringList;
Response: TStringStream;
begin
Result := '';
HTTP := TIdHTTP.Create(nil);
Text := StringReplace(Text, '...', '', [rfReplaceAll]);
Text := StringReplace(Text, #13#10, ' ', [rfReplaceAll]);
PostData := TStringList.Create;
PostData.Add('sl=' + myLang);
PostData.Add('tl=' + toLang);
PostData.Add('js=n');
PostData.add('prev=_t');
PostData.Add('hl=' + myLang);
PostData.Add('ie=UTF-8');
PostData.add('eotf=1');
PostData.Add('text=' + Text);
PostData.Add('client=x');
Response := TStringStream.Create('');
try
HTTP.Post('http://translate.google.ru/translate_a/t', PostData, Response);
Result := UTF8ToWideString(Response.DataString);
if Result.Length > 0 then
Delete(Result, 1, 1);
if Result.Length > 0 then
Delete(Result, Result.Length, 1);
finally
PostData.Free;
HTTP.Free;
Response.Free;
end;
end;
function GetWithWord(TW: TTimeWords; Value: Integer): string;
begin
Result := IntToStr(Value) + ' ' + GetWord(TW, Value);
end;
function GetWord(TW: TTimeWords; Value: Integer): string;
var
C: Char;
W: Byte;
begin
Result := '';
C := IntToStr(Value)[Length(IntToStr(Value))];
case C of
'1':
W := 1;
'2', '3', '4':
W := 2;
'5', '6', '7', '8', '9', '0':
W := 3;
end;
Result := TimeWords[TW, W];
end;
function DaysAndTimeToStr(D: Cardinal; H, M, S: Word): string;
begin
Result := '';
if D <> 0 then
Result := Result + ' ' + IntToStr(D) + ' ' + GetWord(twDays, D);
if H <> 0 then
Result := Result + ' ' + IntToStr(H) + ' ' + GetWord(twHours, H);
if M <> 0 then
Result := Result + ' ' + IntToStr(M) + ' ' + GetWord(twMinutes, M);
if S <> 0 then
Result := Result + ' ' + IntToStr(S) + ' ' + GetWord(twSeconds, S);
Result := Trim(Result);
end;
procedure SecToTime(Value: Cardinal; var H, M, S: Word);
begin
H := Value div SecsPerHour;
Value := Value - H * SecsPerHour;
M := Value div SecsPerMin;
Value := Value - M * SecsPerMin;
S := Value;
end;
procedure SecToDateTime(Value: Cardinal; var D: Cardinal; var H, M, S: Word);
begin
D := Value div SecsPerDay;
Value := Value - D * SecsPerDay;
H := Value div SecsPerHour;
Value := Value - H * SecsPerHour;
M := Value div SecsPerMin;
Value := Value - M * SecsPerMin;
S := Value;
end;
{ THearthBeat }
procedure THearthBeat.Beat;
begin
if BeatValue = 1 then
BeatValue := 2
else
BeatValue := 1;
end;
{ TChatRecord }
function TChatRecord.Message: string;
begin
Result := TimeToStr(Self.Date) + ' ' + Player.GameName + ': ' + Text;
end;
{ TChatList }
procedure TChatList.DeleteLast;
begin
if Count > 0 then
Delete(Count - 1);
end;
{ TMapPlace }
function TMapPlace.Create(aName, aDesc: string): TMapPlace;
begin
Name := aName;
Desc := aDesc;
Result := Self;
end;
{ TServerAction }
function TServerAction.Create(pDate: TDateTime; pData, pSteamID: string): TServerAction;
begin
Date := pDate;
Data := pData;
SteamID := pSteamID;
Result := Self;
end;
{ TLogRecord }
function TLogRecord.Create(pValue: string; pDate: TDateTime): TLogRecord;
begin
Value := pValue;
Date := pDate;
Result := Self;
end;
function TLogRecord.Create(pValue: string): TLogRecord;
begin
Value := pValue;
Date := Now;
Result := Self;
end;
function TLogRecord.ToString: string;
begin
Result := DateTimeToStr(Date) + ': ' + Value;
end;
{ TLog }
function TLog.Add(Value: TLogRecord): Integer;
begin
Insert(0, Value);
UpdateTable;
Result := 0;
while Count > FSize do
Delete(Self.Count - 1);
end;
constructor TLog.Create(Table: TTableEx; Size: Integer);
begin
inherited Create(Table);
FSize := Size;
end;
{ TServerActions }
function TServerActions.Add(Data, SteamID: string): Integer;
var
SA: TServerAction;
begin
Result := Add(SA.Create(Now, Data, SteamID));
end;
{ TKit }
constructor TKit.Create(pID: Integer; pKitName: string);
begin
inherited Create;
FKitName := pKitName;
FDBID := pID;
end;
{ TKitItem }
class function TKitItem.Create(pDBID: Integer; pID: string; pCount: Integer): TKitItem;
begin
Result.DBID := pDBID;
Result.ID := pID;
Result.Count := pCount;
Result.Pic := TBitmap.Create;
end;
{ TPlayer }
function TPlayer.Create(pSID, pGName, pSName: string): TPlayer;
begin
SteamID := pSID;
GameName := pGName;
SteamName := pSName;
Result := Self;
end;
{ TUEItems }
function TUEItems.GetItemDesc(ID: Integer): string;
var
i: Integer;
begin
Result := '';
for i := 0 to Count - 1 do
if Items[i].ID = ID then
Exit(Items[i].Desc);
end;
{ TUEVehicles }
function TUEVehicles.GetItemDesc(ID: Integer): string;
var
i: Integer;
begin
Result := '';
for i := 0 to Count - 1 do
if Items[i].ID = ID then
Exit(Items[i].Desc);
end;
{ TDashboard }
constructor TDashboard.Create(APlace: TControl);
begin
FItems := TDashboardItems.Create;
FIntervalTop := 6;
FIntervalLeft := 6;
end;
class function TDashboard.CreateItem(Col: Word; Order: Integer; Ctrl: TPanelCollapsed): TDashboardItem;
begin
Result.Col := Col;
Result.Order := Order;
Result.Control := Ctrl;
end;
function TDashboard.Reg(Item: TDashboardItem): Integer;
begin
Result := FItems.Add(Item);
end;
function TDashboard.Unreg(Item: TDashboardItem): Boolean;
var
i: Integer;
begin
Result := False;
for i := 0 to FItems.Count - 1 do
begin
if FItems[i].Control.Name = Item.Control.Name then
begin
FItems.Delete(i);
Exit(True);
end;
end;
end;
procedure TDashboard.FUpdate;
var
c, i: Integer;
Sorted: TDashboardItems;
LastRight, LRCalc, LastBottom: Integer;
procedure Sort;
var
i, j: Integer;
Item: TDashboardItem;
begin
if Sorted.Count <= 0 then
Exit; //0-4
for i := 1 to (Sorted.Count - 1) do //0-3
for j := 0 to (Sorted.Count - 1) - i do //0-
begin
if Sorted[j].Order > Sorted[j + 1].Order then
begin
Item := Sorted[j];
Sorted[j] := Sorted[j + 1];
Sorted[j + 1] := Item;
end;
end;
end;
begin
Sorted := TDashboardItems.Create;
LastRight := 0;
for c := 0 to FCols - 1 do
begin
LRCalc := LastRight;
LastBottom := 0;
Sorted.Clear;
for i := 0 to FItems.Count - 1 do
if FItems[i].Col = c then
Sorted.Add(FItems[i]);
Sort;
for i := 0 to Sorted.Count - 1 do
begin
Sorted[i].Control.Top := LastBottom + IntervalTop;
LastBottom := Sorted[i].Control.Top + Sorted[i].Control.Height;
Sorted[i].Control.Left := LastRight + IntervalLeft;
if LRCalc < (Sorted[i].Control.Left + Sorted[i].Control.Width) then
LRCalc := Sorted[i].Control.Left + Sorted[i].Control.Width;
end;
LastRight := LRCalc;
end;
Sorted.Free;
end;
procedure TDashboard.SetColor(const Value: TColor);
var
i, j: Integer;
begin
FColor := Value;
for i := 0 to FItems.Count - 1 do
begin
FItems[i].Control.Color := FColor;
FItems[i].Control.CaptionColor := FColor;
for j := 0 to FItems[i].Control.ControlCount - 1 do
begin
if (FItems[i].Control.Controls[j] is TShape) then
begin
(FItems[i].Control.Controls[j] as TShape).Brush.Color := ColorLighter(Value, 20);
(FItems[i].Control.Controls[j] as TShape).Pen.Color := ColorLighter(Value, 20);
end;
end;
end;
end;
procedure TDashboard.SetColorBorder(const Value: TColor);
var
i: Integer;
begin
FColorBorder := Value;
for i := 0 to FItems.Count - 1 do
FItems[i].Control.SimpleBorderColor := FColorBorder;
end;
procedure TDashboard.SetFontCaption(const Value: TColor);
var
i: Integer;
begin
FFontCap := Value;
for i := 0 to FItems.Count - 1 do
FItems[i].Control.FontCaption.Color := Value;
end;
procedure TDashboard.SetFontContent(const Value: TColor);
var
i, j: Integer;
begin
FFont := Value;
for i := 0 to FItems.Count - 1 do
begin
FItems[i].Control.Font.Color := FFont;
for j := 0 to FItems[i].Control.ControlCount - 1 do
begin
if (FItems[i].Control.Controls[j] is TLabel) then
begin
(FItems[i].Control.Controls[j] as TLabel).Font.Color := Value;
end;
if (FItems[i].Control.Controls[j] is TEdit) then
begin
(FItems[i].Control.Controls[j] as TEdit).Font.Color := Value;
end;
if (FItems[i].Control.Controls[j] is TSpeedButton) then
begin
(FItems[i].Control.Controls[j] as TSpeedButton).Font.Color := Value;
end;
end;
end;
end;
procedure TDashboard.SetCols(const Value: Word);
begin
FCols := Max(1, Value);
end;
procedure TDashboard.Update;
begin
FUpdate;
end;
{ TSettings }
constructor TSettings.Create(FileName: TFileName);
begin
FIniFile := TIniFile.Create(FileName);
end;
destructor TSettings.Destroy;
begin
if Assigned(FIniFile) then
FIniFile.Free;
end;
function TSettings.GetBool(const Section, Ident: string; Default: Boolean): Boolean;
begin
Result := FIniFile.ReadBool(Section, Ident, Default);
end;
function TSettings.GetBool(const Element: array of string; Default: Boolean): Boolean;
begin
if Length(Element) < 2 then
Exit(Default);
Result := GetBool(Element[0], Element[1], Default);
end;
function TSettings.GetDate(const Element: array of string; Default: TDateTime): TDateTime;
begin
if Length(Element) < 2 then
Exit(Default);
Result := GetDate(Element[0], Element[1], Default);
end;
function TSettings.GetDate(const Section, Ident: string; Default: TDateTime): TDateTime;
begin
Result := FIniFile.ReadDateTime(Section, Ident, Default);
end;
function TSettings.GetInt(const Element: array of string; Default: Integer): Integer;
begin
if Length(Element) < 2 then
Exit(Default);
Result := GetInt(Element[0], Element[1], Default);
end;
function TSettings.GetInt(const Section, Ident: string; Default: Integer): Integer;
begin
Result := FIniFile.ReadInteger(Section, Ident, Default);
end;
function TSettings.GetStr(const Section, Ident: string; Default: string): string;
begin
Result := FIniFile.ReadString(Section, Ident, Default);
end;
function TSettings.GetStr(const Element: array of string; Default: string): string;
begin
if Length(Element) < 2 then
Exit(Default);
Result := GetStr(Element[0], Element[1], Default);
end;
procedure TSettings.SetBool(const Section, Ident: string; Value: Boolean);
begin
FIniFile.WriteBool(Section, Ident, Value);
end;
procedure TSettings.SetBool(const Element: array of string; Value: Boolean);
begin
if Length(Element) < 2 then
Exit;
SetBool(Element[0], Element[1], Value);
end;
procedure TSettings.SetDate(const Element: array of string; Value: TDateTime);
begin
if Length(Element) < 2 then
Exit;
SetDate(Element[0], Element[1], Value);
end;
procedure TSettings.SetDate(const Section, Ident: string; Value: TDateTime);
begin
FIniFile.WriteDateTime(Section, Ident, Value);
end;
procedure TSettings.SetInt(const Element: array of string; Value: Integer);
begin
if Length(Element) < 2 then
Exit;
SetInt(Element[0], Element[1], Value);
end;
procedure TSettings.SetInt(const Section, Ident: string; Value: Integer);
begin
FIniFile.WriteInteger(Section, Ident, Value);
end;
procedure TSettings.SetStr(const Element: array of string; Value: string);
begin
if Length(Element) < 2 then
Exit;
SetStr(Element[0], Element[1], Value);
end;
procedure TSettings.SetStr(const Section, Ident: string; Value: string);
begin
FIniFile.WriteString(Section, Ident, Value);
end;
{ TServerStartCommands }
procedure TServerStartCommands.AddLoadout(Value: string);
begin
FLoadouts.Add(Value);
end;
procedure TServerStartCommands.Create;
begin
FLoadouts := TListString.Create;
end;