This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
nosoipcontrol.pas
68 lines (55 loc) · 1.23 KB
/
nosoipcontrol.pas
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
unit NosoIPControl;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, nosotime;
type
IPControl = record
IP : String;
Count : integer;
end;
Function AddIPControl(ThisIP:String):integer;
Procedure ClearIPControls();
var
ArrCont : Array of IPControl;
CS_ArrCont : TRTLCriticalSection;
LastIPsClear : int64 = 0;
IMPLEMENTATION
Function AddIPControl(ThisIP:String):integer;
var
counter : integer;
Added : boolean = false;
Begin
EnterCriticalSection(CS_ArrCont);
For counter := 0 to length(ArrCont)-1 do
begin
if ArrCont[Counter].IP = ThisIP then
begin
Inc(ArrCont[Counter].count);
Result := ArrCont[Counter].count;
Added := true;
Break
end;
end;
if not added then
begin
Setlength(ArrCont,length(ArrCont)+1);
ArrCont[length(ArrCont)-1].IP := thisIP;
ArrCont[length(ArrCont)-1].count := 1;
Result := 1;
end;
LeaveCriticalSection(CS_ArrCont);
End;
Procedure ClearIPControls();
Begin
EnterCriticalSection(CS_ArrCont);
Setlength(ArrCont,0);
LeaveCriticalSection(CS_ArrCont);
LAstIPsClear := UTCTime;
End;
INITIALIZATION
SetLength(ArrCont,0);
InitCriticalSection(CS_ArrCont);
FINALIZATION
DoneCriticalSection(CS_ArrCont);
END.