my version
const
Stats_Link = 'http://old.villavu.com/stats/api/commit';
type TVar = record
Name: string;
Value: Integer;
end;
var
Stats_Values: array of TVar;
Stats_User, Stats_Pass, Stats_ID: string;
Stats_Time: Integer;
Stats_RandomCount: array [0..23] of Integer;
Stats_RandomName: array of string;
procedure SetupSRLStats(Username, Password: string; ScriptID: Integer);
begin
Stats_User:= Username;
Stats_Pass:= Password;
Stats_ID:= IntToStr(ScriptID);
Stats_Time:= GetSystemTime;
Stats_RandomName:= ['leo the gravedigger', 'freaky forester', 'maze', 'prison pete',
'evil bob...s island', 'drill demon', 'quiz', 'surprise exam',
'mollys evil twin', 'pinball', 'sandwich lady', 'bee keeper',
'pillory', 'capn arnav', 'abyssal teleport', 'certer', 'mime',
'frog', 'trade', 'mod', 'fight', 'lamp', 'bird nest', 'death'];
end;
procedure StatsIncVar(Name: string; Value: Integer);
var
i: Integer;
Exists: Boolean;
begin
for i:=0 to High(Stats_Values) do
if (Stats_Values[i].Name = Name) then
begin
Exists:= True;
break;
end;
if not Exists then
begin
SetArrayLength(Stats_Values, Length(Stats_Values)+1);
i:= High(Stats_Values);
Stats_Values[i].Name:= Name;
end;
IncEx(Stats_Values[i].Value, Value);
end;
procedure StatsCommit;
var
Client, i: Integer;
Returned: string;
NewTime, H, M, S: Integer;
begin
Client:= InitializeHTTPClient(False, False);
if (Stats_Time = 0) then
begin
Writeln('You must call StatsIncVar(Name: string; Value: Integer) before you can use the stats');
Exit;
end;
NewTime:= GetSystemTime;
Writeln(NewTime-Stats_Time);
ConvertTime(NewTime-Stats_Time, H, M, S);
if ((H<1) and (M<1)) then Exit;
Stats_Time:= (GetSystemTime-((NewTime-Stats_Time)-((H*60*60*1000)+(M*60*1000))));
for i:=0 to 23 do
if (RandSolved[i]>Stats_RandomCount[i]) then
begin
AddPostVariable(Client, Stats_RandomName[i], IntToStr(RandSolved[i]-Stats_RandomCount[i]));
Stats_RandomCount[i]:= RandSolved[i];
end;
AddPostVariable(Client, 'time', IntToStr((H*60)+M));
AddPostVariable(Client, 'user', Stats_User);
AddPostVariable(Client, 'password', Stats_Pass);
AddPostVariable(Client, 'script', Stats_ID);
for i:=0 to High(Stats_Values) do
AddPostVariable(Client, Stats_Values[i].Name, IntToStr(Stats_Values[i].Value));
Returned:= PostHTTPPageEx(Client, Stats_Link);
FreeHTTPClient(Client);
Case Returned of
'100': Writeln('SRL_Stats: Success');
'110': Writeln('SRL_Stats: Incorrect user and/or password');
'120': Writeln('SRL_Stats: Incorrect script ID');
'130': Writeln('SRL_Stats: Invalid time');
'140': Writeln('SRL_Stats: Variable does not exist');
'150': Writeln('SRL_Stats: Wrong info for variable');
'160': Writeln('SRL_Stats: Internal server error');
else
Writeln('SRL_Stats: No POST return');
end;
SetArrayLength(Stats_Values, 0);
end;
depending on which version gets used will depend on what you have to use, but the basic principle will be the same
if mine is used then you use it like so
SetupSRLStats('user', 'pass', 5); //needed, sets up the stats
StatsIncVar('yew', 10); //adds 10 to the var yew
StatsIncVar('flax', 28); //adds 28 to the var flax
StatsIncVar('breaks', 1); //adds 1 to the var breaks
StatsCommit; //sends the stats to the server
~shut