Advertisement
mixster

mixster

Oct 28th, 2008
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.23 KB | None | 0 0
  1. program RSWorldParser;
  2. type
  3.   world = record
  4.     num, pla: Integer;
  5.     pre, url, fla, loc, act: string;
  6.     loo, qui, pvp, mem: Boolean;
  7.   end;
  8.  
  9.  
  10. function Explode(str, del: string): TStringArray;
  11. var
  12.   i, l: Integer;
  13. begin
  14.   i := 0;
  15.   l := -1;
  16.   repeat
  17.     Inc(l);
  18.     SetLength(Result, l + 1);
  19.     i := Pos(del, str);
  20.     if i <= 0 then
  21.       Break;
  22.     Result[l] := Copy(str, 1, i - 1);
  23.     Delete(str, 1, i + Length(del));
  24.   until false
  25.   Result[l] := Copy(str, 1, Length(str));
  26. end;
  27.  
  28. procedure RewriteWorld;
  29. var
  30.   worldList: array of world;
  31.   str, FilePath: string;
  32.   tsa, tsb: TStringArray;
  33.   w: Integer;
  34. begin
  35.   FilePath := AppPath + 'Includes\SRL\SCSS\worlds.ini';
  36.   Writeln(FilePath);
  37.   if FileExists(FilePath) then
  38.   begin
  39.     w := RewriteFile(filePath, False);
  40.     WriteFileString(w, '');
  41.     CloseFile(w);
  42.   end;
  43.   str := GetPage('http://www.runescape.com/slu.ws?order=WMPLA');
  44.   Delete(str, 1, Pos('"Sort descending"', str));
  45.   Delete(str, 1, Pos('<tr', str) + 3);
  46.   tsa := Explode(str, '<tr');
  47.   SetLength(worldList, High(tsa) + 1);
  48.   for w := 0 to High(tsa) do
  49.     with worldList[w] do
  50.     begin
  51.       tsb := Explode(tsa[w], '<td');
  52.       if High(tsb) <= 7 then
  53.       begin
  54.         Writeln('Skipping world ' + IntToStr(w + 1) + ' because explosion didn''t return enough values');
  55.         Continue;
  56.       end;
  57.       pla := StrToIntDef(Copy(tsb[2], 1, Pos(' Players', tsb[2]) - 1), 2000);
  58.       fla := Between('"', '"', tsb[3]);
  59.       loc := fla;
  60.       case Uppercase(loc) of
  61.         'US': loc := 'United States';
  62.         'UK': loc := 'UK';
  63.         'NL': loc := 'Netherlands';
  64.         'CA': Loc := 'Canada';
  65.         'AU': Loc := 'Australia';
  66.         'SE': Loc := 'Sweden';
  67.         'FI': Loc := 'Finland';
  68.       end;
  69.       url := 'http://' + Between('>', '<', tsb[3]) + '/a2,m0,j0,o0';
  70.       pre := Between('http://', '.runescape', url);
  71.       num := StrToIntDef(Copy(pre, 6, Length(pre) - 5), -1);
  72.       act := Copy(tsb[4], 1, Pos('<', tsb[4]) - 1);
  73.       if act = '-' then
  74.         act := '';
  75.       loo := Between('title="', '"', tsb[5]) = 'Y';
  76.       qui := Between('title="', '"', tsb[6]) = 'Y';
  77.       pvp := Between('title="', '"', tsb[7]) = 'Y';
  78.       mem := Between('>', '<', tsb[8]) = 'Members';
  79.     end;
  80.   WriteINI('Worlds', 'Count', IntToStr(High(worldList) + 1), FilePath);
  81.   WriteINI('Worlds', 'High', IntToStr(worldList[High(worldList)].num), FilePath);
  82.   for w := 0 to High(worldList) do
  83.     with worldList[w] do
  84.     begin
  85.       if mem then
  86.         str := 'Members'
  87.       else
  88.         str := 'Free';
  89.       WriteINI('World' + IntToStr(num), 'Prefix', pre, FilePath);
  90.       WriteINI('World' + IntToStr(num), 'URL', url, FilePath);
  91.       WriteINI('World' + IntToStr(num), 'Activity', act, FilePath);
  92.       WriteINI('World' + IntToStr(num), 'Type', str, FilePath);
  93.       WriteINI('World' + IntToStr(num), 'Flag', fla + 'Flag', FilePath);
  94.       WriteINI('World' + IntToStr(num), 'Location', loc, FilePath);
  95.       WriteINI('World' + IntToStr(num), 'Lootshare', BoolToStr(loo), FilePath);
  96.       WriteINI('World' + IntToStr(num), 'Quickchat', BoolToStr(qui), FilePath);
  97.       WriteINI('World' + IntToStr(num), 'PvP', BoolToStr(pvp), FilePath);
  98.     end;
  99. end;
  100.  
  101. begin
  102.   RewriteWorld;
  103. end.
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement