SRL Archive - SRL Archives

Connected & WaitForConnection


Rich

2009-07-05 16:14:21

Two functions which would come in handy for someone with a poor internet connection.

What they do are check if you are connected to Runescape, via the Lost Connection box in the top left of your screen.

Connected just returns true or false depending on whether you are connected or not.

WaitForConnection again returns true if you are connected. If you are not connected though, it will wait MaxWaitMS to become connected. If it does not become connected after waiting, it returns false.

Please do not hassle me about using a DTM; it is the first method which popped into my mind. Anyway, when I tested it, it only took
Successfully compiled (234 ms)
to compile.

{*******************************************************************************
function LostConnection : Boolean;
By: R1ch
Description: Checks if you are not connected to RS. Returns true if you are NOT connected.
*******************************************************************************}
function LostConnection : Boolean;
var
X, Y , Con : Integer;

begin
Con := DTMFromString('78DA63D4606060E061C00A1861B4079060439' +
'5FBFFFF3FAA9A4820C145408D1390E025A0460D48F01150234F84' +
'39224498C341841A90BF3908A81125C2EF2A408293801A7DC2E10' +
'C0098072353');
Result:= FindDTM(Con, X, Y , 0, 0, 250, 75)
FreeDTM(Con);
end;

{*******************************************************************************
function WaitForConnection(MaxWaitMS : Integer) : Boolean;
By: R1ch
Description: Checks if you are connected to RS. Returns true if you are.
If you are not, waits MaxWaitMS to become connected.
*******************************************************************************}
function WaitForConnection(MaxWaitMS : Integer) : Boolean;
var
I : Integer;
begin
I := GetSystemTime;
while (GetSystemTime - I) < MaxWaitMS do
begin
Result:= not(LostConnection);
if Result then
Exit;
Wait(Random(15));
end;
end;

Comments?

Da 0wner

2009-07-05 16:16:28

Would be more logical to have NotConnected since you are connected most of the time :D.

But:
{*******************************************************************************
function WaitForConnection(MaxWaitMS : Integer) : Boolean;
By: R1ch
Description: Checks if you are connected to RS. Returns true if you are.
If you are not, waits MaxWaitMS to become connected.
*******************************************************************************}
function WaitForConnection(MaxWaitMS : Integer) : Boolean;
var
I : Integer;
begin
i := GetSystemTime;
while GetSystemTime - i < MaxWaitMS do
begin
result := Connected;
if result then
exit;
Wait(Random(16));
end;
end;
:D

Rich

2009-07-05 16:19:18

I'll keep Connected, but I've also added NotConnected.

EDIT: Shortened WaitForConnection.

Da 0wner

2009-07-05 16:19:55

Check my edit.

unction NotConnected : Boolean;
var
X, Y , Con : Integer;

begin
Con := DTMFromString('78DA63D4606060E061C00A1861B4079060439' +
'5FBFFFF3FAA9A4820C145408D1390E025A0460D48F01150234F84' +
'39224498C341841A90BF3908A81125C2EF2A408293801A7DC2E10' +
'C0098072353');
Result:= FindDTM(Con, X, Y , 0, 0, 250, 75)
FreeDTM(Con);
end;
->

function NotConnected : boolean;
begin
result := not Connected;
end;

Rich

2009-07-05 16:21:30

Meh, I don't see why I didn't do that to be honest.

Thanks,
Richard.

Gu3st...

2009-07-05 21:33:02

Why have both Connected and NotConnected? if you're not connected then Connected would result false…

Rich

2009-07-05 21:52:59

From: Zyt3x
Why have both Connected and NotConnected? if you're not connected then Connected would result false…


That to me is like saying why have TypeSend as well as TypeSendEx. I get what you're saying, but in my opinion, it just makes things easier.

Naike

2009-07-05 22:04:34

From: R1ch
That to me is like saying why have TypeSend as well as TypeSendEx. I get what you're saying, but in my opinion, it just makes things easier.


There's actually a logic behind TypeSendEx/TypeSend.

Rich

2009-07-05 22:11:47

Not trying to start an argument here, but instead of using TypeSend('bla'); you could use TypeSendEx('bla', True');. All TypeSend is is
procedure TypeSend(Text : string);
begin
TypeSendEx(Text, True);
end
It's the same concept with these.

It's up to the Devs whether they get in or not anyway, so if they feel it doesn't need to be there, they don't add it.

Gu3st...

2009-07-05 22:43:57

From: R1ch
That to me is like saying why have TypeSend as well as TypeSendEx. I get what you're saying, but in my opinion, it just makes things easier.

So therefore in your opinion we should have one LoggedIn and one NotLoggedIn?

Da 0wner

2009-07-06 00:18:28

I think we should just have one…

Rich

2009-07-06 00:19:06

@ Zytex: What does it matter anyway? All I'm trying to do is help, and I get flamed for it. It's just stupid. It's up to the Devs, not you.

@ Kyle: Which one?

Da 0wner

2009-07-06 00:44:59

NotConnected ;).

Rich

2009-07-06 00:51:18

Fine. I give in. I've removed Connected, and renamed NotConnected to LostConnection.