Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- TWorld = record
- Number, PlayerNo: Integer;
- Members: Boolean;
- Prefix, Location, Activity, Language: String;
- LootShare, QuickChat, PVP: Boolean;
- end;
- TWorldArray = Array of TWorld;
- function srl_Explode(str, del: string): TStringArray;
- {$IFNDEF SCAR320_UP}
- var
- i, l, dL: Integer;
- begin
- i := 0;
- l := -1;
- SetLength(Result, 0);
- if (str = '') then
- Exit;
- dL := Length(del) - 1;
- repeat
- Inc(l);
- SetLength(Result, l + 1);
- i := Pos(del, str);
- if (i <= 0) then
- Break;
- Result[l] := Copy(str, 1, i - 1);
- Delete(str, 1, i + dL);
- until false;
- Result[l] := Copy(str, 1, Length(str));
- {$ELSE}
- begin
- Result := Explode(del, str);
- {$ENDIF}
- end;
- const
- SRL_LG_ENGLISH = 0;
- SRL_LG_GERMAN = 1;
- SRL_LG_FRENCH = 2;
- SRL_LG_PORTUGUESE = 3;
- SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH;
- {*******************************************************************************
- procedure UpdateWorlds;
- by: mixster
- Description: Parses the worlds page into Worlds.INI
- *******************************************************************************}
- function UpdateWorlds: Boolean;
- var
- worldList: TWorldArray;
- str, Path: string;
- tsa, tsb: TStringArray;
- W, I, H, Time: Integer;
- begin
- try
- Result := True;
- Path := AppPath + 'Worlds.INI';
- Writeln('NOTE: Attempting to update the Worlds.INI, please allow the script to access this file.');
- Time := GetTimeRunning;
- W := RewriteFile(Path, False);
- CloseFile(W);
- if (SRL_WORLDPARSE_LANG = SRL_LG_ENGLISH) then
- str := ''
- else
- str := 'l=' + IntToStr(SRL_WORLDPARSE_LANG) + '/';
- str := GetPage('http://www.runescape.com/' + str + 'slu.ws?order=WMPLA');
- Delete(str, 1, Pos('<a href="?order=MWPLA">', str));
- Delete(str, 1, Pos('<tr', str) + 3);
- tsa := srl_Explode(str, '<tr');
- H := High(tsa);
- SetLength(worldList, H + 1);
- for I := 0 to H do
- with worldList[I] do
- begin
- tsb := srl_Explode(tsa[I], '<td');
- if High(tsb) < 5 then
- begin
- Writeln('Skipping world "' + IntToStr(I + 1) + '" because explosion didn''t return enough values');
- Continue;
- end;
- PlayerNo := StrToIntDef(Between('>', '<', tsb[2]), 2000);
- if (Between('"', '"', tsb[3]) = 'a') or (Between('"', '"', tsb[3]) = 'a d') then
- begin
- Location := 'Activity';
- Activity := Between('>', '<', tsb[3]);
- end
- else
- begin
- Location := Between('>', '<', tsb[3]);
- Activity := '';
- end;
- Prefix := Between('http://', '.runescape', tsb[1]);
- if Prefix = '' then
- Prefix := Replace(Lowercase(Between('>' + #10, #10 + #10, tsb[1])), ' ', '', [rfReplaceAll]);
- Number := StrToIntDef(Replace(Prefix, 'world', '', [rfReplaceAll]), -1);
- if Number = -1 then
- begin
- Writeln('Invalid world number produced: ' + Prefix);
- Writeln('Assuming has suffix, trying again');
- str := Replace(Prefix, 'world', '', [rfReplaceAll]);
- Number := StrToIntDef(Copy(str, 1, Length(str) - 1), -1);
- if Number = -1 then
- Writeln('Failed to gather a world number')
- else
- Writeln('Succeeded, got ' + IntToStr(Number));
- end;
- LootShare := Between('"', '"', tsb[4]) = 'd';
- QuickChat := Activity = 'Quick Chat';
- PvP := Activity = 'PvP World';
- Members := Between('"', '"', tsb[5]) = 'm';
- end;
- //Writeln('Writing to the INI File. T: ' + IntToStr(GetTimeRunning - W));
- except
- Result := False;
- //SRL_Warn('UpdateWorlds', ExceptionToString(ExceptionType, ExceptionParam), Warn_AllVersions);
- end;
- if not Result then Exit;
- WriteINI('Worlds', 'Count', IntToStr(High(worldList) + 1), Path);
- WriteINI('Worlds', 'High', IntToStr(worldList[High(worldList)].Number) + #13#10, Path);
- H := High(worldList);
- for I := 0 to H do
- with worldList[I] do
- begin
- Str := 'World' + IntToStr(Number);
- DeleteINI(Str, '', Path);
- WriteINI(Str, 'Prefix', Prefix, Path);
- WriteINI(Str, 'Activity', Activity, Path);
- //WriteINI(Str, 'Type', BoolToStr(Members), Path);
- if (Members) then
- WriteINI(Str, 'Type', 'Members', Path)
- else
- WriteINI(Str, 'Type', 'Free', Path);
- //WriteINI(Str, 'Flag', fla + 'Flag', Path);
- WriteINI(Str, 'Location', Location, Path);
- WriteINI(Str, 'LootShare', BoolToStr(LootShare), Path);
- WriteINI(Str, 'QuickChat', BoolToStr(QuickChat), Path);
- WriteINI(Str, 'PvP', BoolToStr(PvP) + #13#10, Path);
- end;
- Writeln('Parsed Worlds Page into Worlds.INI. Took ' + IntToStr(GetTimeRunning - Time) + ' ms.');
- end;
- begin
- UpdateWorlds;
- end.
Add Comment
Please, Sign In to add comment