-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStats.scar
251 lines (227 loc) · 9.27 KB
/
Stats.scar
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
{==============================================================================\
| MSI Group Scripting Include |
| Stats.scar |
|==============================================================================|
| All Banking related routines. |
| |
| * procedure Stats_CheckOutput(); * by nielsie95 |
| * procedure Stats_GetScriptInfo(); * by nielsie95 |
| * procedure Stats_SendReport(); * by nielsie95 |
| * procedure Stats_SendAccountInfo(); * by nielsie95 |
| * procedure Stats_ManageAccounts(); * by nielsie95 |
| * procedure MSI_SendStats; * by Coh3n |
| |
\_____________________________________________________________________________}
{******************************************************************************}
{ procedure Stats_CheckOutput(s: string); }
{ By: nielsie95 }
{ Date: 10 June 2010 }
{ Description: }
{******************************************************************************}
procedure Stats_CheckOutput(s: string);
var
i: Integer;
sa: TStringArray;
begin
sa := Explode(#10, s);
for i := 0 to High(sa) do
if (Trim(sa[i]) <> '') then
if StartsWith('ERROR(1)', sa[i]) then
begin
WriteLn('STATS: "' + sa[i] + '"');
Stats_UserID := '';
Stats_Password := '';
end
else if StartsWith('ERROR(2)', sa[i]) then
begin
WriteLn('STATS: "' + sa[i] + '"');
Stats_ScriptID := '';
end
else
WriteLn('STATS: "' + sa[i] + '"');
end;
{******************************************************************************}
{ procedure Stats_GetScriptInfo( ... ); }
{ By: nielsie95 }
{ Date: 10 June 2010 }
{ Description: }
{******************************************************************************}
function Stats_GetScriptInfo(out Version, News, Link: string;
out OutDated: Boolean; out LastUpdate_HoursAgo: Integer): Boolean;
var
Client: Integer;
s: string;
sa: TStringArray;
begin
Result := False;
if (Stats_ScriptID = '') then
Exit;
Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'getinfo');
AddPostVariable (Client, 'sID', Stats_ScriptID);
s := PostHTTPPageEx(Client, STATS_LINK);
sa := Explode(#10'GLUE'#10, s);
if (Length(sa) = 5) then
begin
Result := True;
Version := sa[0];
News := sa[1];
Link := sa[2];
OutDated := sa[3] = '1';
LastUpdate_HoursAgo := StrToIntDef(sa[4], -1);
end
else
Stats_CheckOutput(s);
FreeHTTPClient(Client );
end;
{******************************************************************************}
{ procedure Stats_SendReport; }
{ By: nielsie95 }
{ Date: 10 June 2010 }
{ Description: }
{******************************************************************************}
var
Stats_GlobalVars: array[1..24] of Integer;
procedure Stats_SendReport;
var
i, Client, Time: Integer;
s: string;
begin
if (Stats_UserID = '') and (Stats_Password = '') and (Stats_ScriptID = '') then
Exit;
Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'submit');
Time := (GetTimeRunning - Stats_LastTime) div 1000 div 60;
if (Time < 5) then
Time := 0
else
Stats_LastTime := GetTimeRunning;
AddPostVariable(Client, 'sTime', IntToStr(Time));
if (Stats_UserID <> '') and (Stats_Password <> '') then
begin
AddPostVariable(Client, 'uID', Stats_UserID);
AddPostVariable(Client, 'uPass', Stats_Password);
end
else
begin
AddPostVariable(Client, 'uID', '-1');
AddPostVariable(Client, 'uPass', '');
end;
if (Stats_ScriptID <> '') then
begin
AddPostVariable (Client, 'sID', Stats_ScriptID);
for i := Low(Stats_CustomVars) to High(Stats_CustomVars) do
begin
AddPostVariable(Client, 'rndCustom' + IntToStr(i),
IntToStr(Stats_CustomVars[i]));
Stats_CustomVars[i] := 0;
end;
end
else
begin
AddPostVariable (Client, 'sID', '-1');
end;
for i := Low(Stats_GlobalVars) to High(Stats_GlobalVars) do
begin
case i of
1: s := IntToStr(SRL_Logs - Stats_GlobalVars[i]);
2: s := IntToStr(Banks - Stats_GlobalVars[i]);
3: s := IntToStr(RandSolved[rand_Death] - Stats_GlobalVars[i]);
else if ((i - 3) < Length(RandSolved) - 1) then
s := IntToStr(RandSolved[i - 3] - Stats_GlobalVars[i]);
end;
AddPostVariable(Client, 'rndGlobal' + IntToStr(i), s);
Stats_GlobalVars[i] := Stats_GlobalVars[i] + StrToInt(s);
end;
s := PostHTTPPageEx(Client, STATS_LINK);
Stats_CheckOutput(s);
FreeHTTPClient(Client);
if (SRL_Procs[srl_OnSendStats] <> nil) then
SRL_Procs[srl_OnSendStats]();
end;
{******************************************************************************}
{ procedure Stats_SendAccountInfo; }
{ By: nielsie95 }
{ Date: 10 June 2010 }
{ Description: }
{******************************************************************************}
procedure Stats_SendAccountInfo;
var
i, Client: Integer;
Accounts: TStringArray;
begin
if (Stats_UserID = '') and (Stats_Password = '') then
Exit;
Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'setaccounts');
AddPostVariable(Client, 'uID', Stats_UserID);
AddPostVariable(Client, 'uPass', Stats_Password);
if (Stats_ScriptID <> '') then
AddPostVariable (Client, 'sID', Stats_ScriptID)
else
AddPostVariable (Client, 'sID', '-1');
SetLength(Accounts, HowManyPlayers);
for i := 0 to HowManyPlayers - 1 do
Accounts[i] := Implode('.|€stat€|.', [Players[i].Name, Players[i].Loc,
IntToStr(Integer(Players[i].Active))]);
AddPostVariable(Client, 'accInfo', Implode(#10'ACC'#10, Accounts));
Stats_CheckOutput(PostHTTPPageEx(Client, STATS_LINK));
FreeHTTPClient(Client);
end;
{******************************************************************************}
{ procedure Stats_ManageAccounts; }
{ By: nielsie95 }
{ Date: 10 June 2010 }
{ Description: }
{******************************************************************************}
procedure Stats_ManageAccounts;
var
i, ii, Client: Integer;
s: string;
Accounts, Stats: TStringArray;
begin
if (Stats_UserID = '') and (Stats_Password = '') then
Exit;
Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'getaccounts');
AddPostVariable(Client, 'uPass', Stats_Password);
AddPostVariable(Client, 'uID', Stats_UserID);
s := PostHTTPPageEx(Client, STATS_LINK);
Accounts := Explode(#10'ACC'#10, s);
for i := 0 to High(Accounts) do
begin
Stats := Explode('.|€stat€|.', Accounts[i]);
if (Length(Stats) = 3) then
begin
for ii := 0 to HowManyPlayers - 1 do
if (LowerCase(Players[ii].Name) = LowerCase(Stats[0])) then
begin
Players[ii].Loc := Stats[1];
Players[ii].Active := Stats[2] = '1';
Break;
end;
end
else
begin
Stats_CheckOutput(s);
Break;
end;
end;
FreeHTTPClient(Client);
stats_SendAccountInfo;
end;
{******************************************************************************}
{ procedure MSI_SendStats; }
{ By: Coh3n }
{ Date: 10 June 2010 }
{ Description: }
{******************************************************************************}
procedure MSI_SendStats;
begin
Stats_SendReport;
Stats_ManageAccounts;
end;