marpis
09-30-2009, 05:59 PM
Self-explanatory
thanks zeph for the link to serverlist :) or should i thank mixster? ^^
E: New version that updates itself if memberworld numbers change.
Thanks to mixster, zeph and narcle! :)
function LeastCrowdedServer(Members, PVP: Boolean):Integer;
var
I, N, Hi: Integer;
GoodWorlds, PlayerCounts: TIntegerArray;
Content, S: string;
begin
Content := GetPage('http://www.runescape.com/slu.ws?order=WMPLA'); // Get serverlist as a string
LoadWorldArrays; // Load SRL Serverlist that has info of servers (is it p2p or pvp etc)
Hi := High(WorldArray);
for I := 0 to Hi do //if the world[i] is p2p server and we are looking for f2p continue. same with pvp.
if (WorldArray[I].Members and (not Members)) or (WorldArray[I].PVP and (not PVP)) then
Continue
else
begin
SetLength(GoodWorlds, Length(GoodWorlds) + 1); // we found a server which met our criters, add to "GoodWorlds" array
SetLength(PlayerCounts, Length(PlayerCounts) + 1);
GoodWorlds[High(GoodWorlds)] := WorldArray[I].Number; // here we check the worlds number from the SRL WorldArray
end;
Hi := High(GoodWorlds);
for I := 0 to Hi do
begin
N := Pos('World '+IntToStr(GoodWorlds[I]), Content); // Look for text "World 14" for example, in the serverlist website
if (N = 0) then
begin // if not found, we set the playeramount incredibly high for that server so it doesn't get picked as the least crowded
PlayerCounts[I] := 1 shl 20; // = 1048576
Continue;
end;
S := Copy(Content, N + 11, 24); // copy the part from the rs serverlist site where is the playercount
PlayerCounts[I] := StrToIntDef(GetNumbers(S), 1 shl 20); // read playercount as an integer
if PlayerCounts[I] <= 0 then // if something went wrong, set playercount very high so it doesn't get picked as the least crowded
PlayerCounts[I] := 1 shl 20;
//WriteLn('Server '+IntToStr(GoodWorlds[I])+' has '+IntToStr(PlayerCounts[I])+' players.');
end;
InIntArrayEx(PlayerCounts, N, AMin(PlayerCounts)); // now we check in which index is the smallest number in PlayerCounts array
Result := GoodWorlds[N]; // and choose the world
end;
thanks zeph for the link to serverlist :) or should i thank mixster? ^^
E: New version that updates itself if memberworld numbers change.
Thanks to mixster, zeph and narcle! :)
function LeastCrowdedServer(Members, PVP: Boolean):Integer;
var
I, N, Hi: Integer;
GoodWorlds, PlayerCounts: TIntegerArray;
Content, S: string;
begin
Content := GetPage('http://www.runescape.com/slu.ws?order=WMPLA'); // Get serverlist as a string
LoadWorldArrays; // Load SRL Serverlist that has info of servers (is it p2p or pvp etc)
Hi := High(WorldArray);
for I := 0 to Hi do //if the world[i] is p2p server and we are looking for f2p continue. same with pvp.
if (WorldArray[I].Members and (not Members)) or (WorldArray[I].PVP and (not PVP)) then
Continue
else
begin
SetLength(GoodWorlds, Length(GoodWorlds) + 1); // we found a server which met our criters, add to "GoodWorlds" array
SetLength(PlayerCounts, Length(PlayerCounts) + 1);
GoodWorlds[High(GoodWorlds)] := WorldArray[I].Number; // here we check the worlds number from the SRL WorldArray
end;
Hi := High(GoodWorlds);
for I := 0 to Hi do
begin
N := Pos('World '+IntToStr(GoodWorlds[I]), Content); // Look for text "World 14" for example, in the serverlist website
if (N = 0) then
begin // if not found, we set the playeramount incredibly high for that server so it doesn't get picked as the least crowded
PlayerCounts[I] := 1 shl 20; // = 1048576
Continue;
end;
S := Copy(Content, N + 11, 24); // copy the part from the rs serverlist site where is the playercount
PlayerCounts[I] := StrToIntDef(GetNumbers(S), 1 shl 20); // read playercount as an integer
if PlayerCounts[I] <= 0 then // if something went wrong, set playercount very high so it doesn't get picked as the least crowded
PlayerCounts[I] := 1 shl 20;
//WriteLn('Server '+IntToStr(GoodWorlds[I])+' has '+IntToStr(PlayerCounts[I])+' players.');
end;
InIntArrayEx(PlayerCounts, N, AMin(PlayerCounts)); // now we check in which index is the smallest number in PlayerCounts array
Result := GoodWorlds[N]; // and choose the world
end;