@@ -574,25 +574,21 @@ begin
574574end;
575575
576576(*
577- ## Login.SwitchToProfileWorld
577+ ## Login.SwitchWorld
578578```pascal
579- function TRSLogin.SwitchToProfileWorld (worlds : TIntegerArray): Boolean ;
579+ procedure TRSLogin.SwitchWorld (worlds: TIntegerArray);
580580```
581581Ensures we are on a world declared in the profile, retrying transient failures
582- before giving up. Returns `True` when the current world matches one from the
583- profile list.
582+ before giving up.
584583*)
585- function TRSLogin.SwitchToProfileWorld (worlds : TIntegerArray): Boolean ;
584+ procedure TRSLogin.SwitchWorld (worlds: TIntegerArray);
586585var
587586 attempt, time: Integer;
588587begin
589- if (worlds.Length = 0) or worlds.Contains(LoginWorldSwitcher.GetCurrent()) then
590- Exit(True) ;
591-
592588 for attempt := 0 to 4 do
593589 begin
594590 if LoginWorldSwitcher.Switch(worlds.Random()) then
595- Exit(True) ;
591+ Exit;
596592
597593 if attempt < 4 then
598594 Sleep(Random(10000, 20000) * (1 + attempt));
@@ -618,6 +614,7 @@ WriteLn Login.DoLogin(profile);
618614function TRSLogin.DoLogin(profile: TProfile = Default(TProfile)): Boolean;
619615var
620616 timeout: UInt64;
617+ switched: Boolean;
621618begin
622619 if profile = Default(TProfile) then
623620 profile := Profiles.Get();
@@ -632,9 +629,15 @@ begin
632629 Exit;
633630 end;
634631
635- if not Self.SwitchToProfileWorld(profile.Worlds) then Exit;
632+ if not switched and (profile.Worlds <> []) and
633+ not profile.Worlds.Contains(LoginWorldSwitcher.GetCurrent()) then
634+ begin
635+ Self.SwitchWorld(profile.Worlds);
636+ switched := True;
637+ end;
636638
637- if not Self.HandleMessage(Self.GetMessage(), profile.Username, profile.Password) then Exit;
639+ if not Self.HandleMessage(Self.GetMessage(), profile.Username, profile.Password) then
640+ Exit;
638641 Sleep(600, 1200);
639642 end;
640643
0 commit comments