Skip to content

Commit 6f9d7a0

Browse files
committed
fix(sleep): randomness is more contained now
- small fix in WaspClient that would cause crashing without using the launcher
1 parent 3334233 commit 6f9d7a0

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

examples/script_template.simba

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@ type
1616

1717
function TTemplate.GetReportValues(): TStringArray;
1818
var
19-
actionsStr: String;
19+
actionsStr, sleepInfo: String;
2020
begin
2121
actionsStr := ToStr(Self.Actions);
2222
if Self.MaxActions <> 0 then
2323
actionsStr += '/' + ToStr(Self.MaxActions);
2424

25+
if Antiban.Sleeps = [] then
26+
sleepInfo := '00:00:00'
27+
else
28+
sleepInfo := Antiban.TimeUntilSleep(Antiban.Sleeps.First, TIME_SHORT);
29+
2530
Result := [
2631
GetTimeStamp(TIME_SHORT),
2732
Logger.TimeRunning.ElapsedFmt(TIME_SHORT),
2833
Antiban.TimeRunning.ElapsedFmt(TIME_SHORT),
34+
sleepInfo,
2935
actionsStr
3036
];
3137
end;
@@ -35,7 +41,10 @@ begin
3541
Logger.Setup('Template');
3642
ProgressReport.Setup(
3743
'Template',
38-
['Script runtime', 'Botting runtime', 'Antiban runtime', 'Actions'],
44+
[
45+
'Script runtime:', 'Botting runtime:', 'Antiban runtime:', 'Next sleep:',
46+
'Actions:'
47+
],
3948
@Self.GetReportValues
4049
);
4150

@@ -81,6 +90,7 @@ begin
8190
state := Self.GetState();
8291
Logger.Info(ToStr(state));
8392
ProgressReport.Print();
93+
WaspClient.SubmitStats();
8494

8595
case state of
8696
ETemplateState.LOGIN: Login.DoLogin();

osrs/antiban/antiban.simba

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ begin
8080
if res < 0 then res += 1;
8181

8282
Result := GetTimeRunning() + UInt64(Trunc(res * ONE_DAY));
83-
Result += Trunc(Abs(GaussRand(0, randomness * 10 * ONE_DAY)));
84-
Result := Max(0, Result);
83+
Result += Trunc(Abs(GaussRand(0, randomness * ONE_DAY / 2)));
8584
end;
8685

8786

@@ -119,7 +118,7 @@ begin
119118
Self.Sleeps[idx].Length := length;
120119
Self.Sleeps[idx].StdVar := randomness;
121120
Self.Sleeps[idx].LogoutChance := logoutChance;
122-
Self.Sleeps[idx].Next := Self.TimeRunningAtClock(Self.Sleeps[idx].Time, Self.Sleeps[idx].StdVar);
121+
Self.Sleeps[idx].Next := Self.TimeRunningAtClock(time, randomness);
123122
end;
124123

125124

@@ -198,6 +197,8 @@ in a "bare" time format (00:00:00).
198197

199198
`randomness` is self explanatory, gives variance to the time our script will
200199
sleep at and it's length too.
200+
One thing to keep in mind is that randomness only affects time past `time`.
201+
In other words, you will never sleep before `time`.
201202

202203
`logoutChance` is the probability of logging out for the sleep break or to
203204
simply afk and logout from inactivity.
@@ -514,25 +515,25 @@ end;
514515
(*
515516
## Antiban.TimeUntilBreak
516517
```pascal
517-
function TAntiban.TimeUntilBreak(task: TBreakTask): String;
518+
function TAntiban.TimeUntilBreak(constref task: TBreakTask; fmt: String = TIME_FORMAL): String;
518519
```
519520
Check how much time is left until the specified break `task` should be taken.
520521
*)
521-
function TAntiban.TimeUntilBreak(task: TBreakTask): String;
522+
function TAntiban.TimeUntilBreak(constref task: TBreakTask; fmt: String = TIME_FORMAL): String;
522523
begin
523-
Result := FormatMilliseconds(Max(0, Round(task.Next - GetTimeRunning())), True);
524+
Result := FormatMilliseconds(Max(0, Round(task.Next - GetTimeRunning())), fmt);
524525
end;
525526

526527
(*
527528
## Antiban.TimeUntilSleep
528529
```pascal
529-
function TAntiban.TimeUntilSleep(task: TSleepTask): String;
530+
function TAntiban.TimeUntilSleep(constref task: TSleepTask; fmt: String = TIME_FORMAL): String;
530531
```
531532
Check how much time is left until the specified sleep break `task` should be taken.
532533
*)
533-
function TAntiban.TimeUntilSleep(task: TSleepTask): String;
534+
function TAntiban.TimeUntilSleep(constref task: TSleepTask; fmt: String = TIME_FORMAL): String;
534535
begin
535-
Result := FormatMilliseconds(Max(0, Round(task.Next - GetTimeRunning())), True);
536+
Result := FormatMilliseconds(Max(0, Round(task.Next - GetTimeRunning())), fmt);
536537
end;
537538

538539
(*

utils/waspclient.simba

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ end;
202202

203203
procedure TWaspClient.ResetPayload();
204204
begin
205-
if not Self.Lock.TryEnter() or not Self.IsSetup then
206-
Exit;
205+
if not Self.IsSetup then Exit;
206+
if not Self.Lock.TryEnter() then Exit;
207207

208208
Self.Payload.Item['experience'].AsInt := 0;
209209
Self.Payload.Item['gold'].AsInt := 0;
@@ -215,8 +215,8 @@ procedure TWaspClient.UpdatePayload(xp, gp: Integer);
215215
var
216216
item: TJSONItem;
217217
begin
218-
if not Self.Lock.TryEnter() or not Self.IsSetup then
219-
Exit;
218+
if not Self.IsSetup then Exit;
219+
if not Self.Lock.TryEnter() then Exit;
220220

221221
item := Self.Payload.Item['experience'];
222222
item.AsInt := item.AsInt + xp;
@@ -232,8 +232,9 @@ var
232232
status: Integer;
233233
logLevel: ELogLevel;
234234
begin
235-
if not Self.Lock.TryEnter() then
236-
Exit;
235+
if not Self.IsSetup then Exit;
236+
if not Self.Lock.TryEnter() then Exit;
237+
237238
Self.Client.RequestHeader['Accept-Profile'] := 'stats';
238239

239240
with Self.Payload.Item['runtime'] do

0 commit comments

Comments
 (0)