Page 3 of 6 FirstFirst 1 2 3 4 5 ... LastLast
Results 21 to 30 of 53

Thread: Mafia automatically using custom combat macro

  1. #21
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    12,180

    Default

    So every RelayAgent has an associated RelayAutoCombatThread.

    This is used to automate the whole fight when the browser requests /fight.php?action=custom
    This is used to automate the whole fight when the browser requests /fight.php?hotkey=11
    This is used to execute a single combat action when the browser requests /fight.php?hotkey=XX where XX is not 11

    "Automating the whole fight" means calling FightRequest.INSTANCE.run() in a RelayAutoCombatThread.
    "Executing a single combat action" means calling FightRequest.INSTANCE.runOnce( this.desiredAction ) in a RelayAutoCombatThread.

    Neither of those request is synchronized, so you could have multiple RelayAutoCombatThreads in there stepping on each other.
    I don't see evidence of that in your log.

    When we call FightRequest.run(), that is, by definition, automating the fight. Extracted from that method:

    Code:
    		FightRequest.isAutomatingFight = true;
    
    		do
    		{
    			this.runOnce( null );
    		}
    		while ( this.responseCode == 200 && FightRequest.currentRound != 0 && !KoLmafia.refusesContinue() );
    
    		if ( this.responseCode == 302 )
    		{
    			FightRequest.clearInstanceData();
    		}
    
    		FightRequest.isAutomatingFight = false;
    I'd synchronize those methods and put the set/clear of the static class variable in try/finally, just to protect from real double clicks coming from the browser.

    I'm still trying to figure out how FightRequest.run() got called for your second fight BEFORE you later pressed the "script" button.
    Last edited by Veracity; 09-15-2019 at 08:58 PM.

  2. #22
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    12,180

    Default

    Actually, looking more closely, there is a single RelayAutoCombatThread. Huh.

  3. #23
    Developer
    Join Date
    Aug 2009
    Posts
    2,974

    Default

    Another thing I pondered was whether it's possible to exit that block in comment #21, e.g. by GenericRequest throwing an exception. I don't think that's consistent with the log, though.

  4. #24
    Developer
    Join Date
    Aug 2009
    Posts
    2,974

    Default

    I don't know enough about how Mafia relay browser works, but is it possible that the HTTP response for the completion of fight.php gets served to the browser before FightRequest.run() completes?

  5. #25
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    12,180

    Default

    I did several changes which I cannot confirm will fix this, since I still cannot come up with a scenario that caused this.

    - I made a new RelayAutoCombatThread for each RelayAgent, rather than sharing one without synchronization.
    - I attempted to synchronize of FIghtRequest.INSTANCE whenever it is used.
    - I moved the setting/clearing of FightRequest.isAutomating fights into a try/finally block

    Since I do not understand what caused your "glitch", I cannot guarantee that this solves it, but, please try it out.

    I did go into the Relay Browser, repeatedly, and click on the "script" button up to 5 times, and I always got back exactly the resonse I expected - the result of the first click - even though up to 5 threads wre responding to the click, as dispatched by requests from the browser.

    Revision 19544.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  6. #26
    Senior Member
    Join Date
    Aug 2015
    Posts
    268

    Default

    I did several changes which I cannot confirm will fix this, since I still cannot come up with a scenario that caused this.

    - I made a new RelayAutoCombatThread for each RelayAgent, rather than sharing one without synchronization.
    - I attempted to synchronize of FIghtRequest.INSTANCE whenever it is used.
    - I moved the setting/clearing of FightRequest.isAutomating fights into a try/finally block

    Since I do not understand what caused your "glitch", I cannot guarantee that this solves it, but, please try it out.

    I did go into the Relay Browser, repeatedly, and click on the "script" button up to 5 times, and I always got back exactly the resonse I expected - the result of the first click - even though up to 5 threads wre responding to the click, as dispatched by requests from the browser.

    Revision 19544.
    Originally Posted by Veracity View Post
    Would this also fix multiple clicks of the "Begin" button in the Adventure tab causing it to run multiple adventures simultaneously?

  7. #27
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    12,180

    Default

    No. This only affects the Relay Browser.

  8. #28

    Default

    Glitch doesn't seem to trigger (though maybe I am overestimating how easy it is to trigger it).

    Worth noting that the fight result screen seemed to take a little bit longer to appear. Not sure if it is a result of the changes, but it could be that instead of the glitch being fixed, the conditions to get it were made harder to obtain. (For all I know, maybe 2 of the 3 changes fixed the glitch, while the 3rd just made the fight result appear slower/later, who knows)

  9. #29
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    12,180

    Default

    I am noticing that my script which runs the LOV is getting "A choice follows this fight immediately." when trying to take the choice following the second fight.
    Looking at the code, I cannot see how that is possible, given the ASH functions I am calling.
    But, this is new and repeatable, so I guess I need to turn on DEBUG logging and see what's up.

  10. #30
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    12,180

    Default

    Worth noting that the fight result screen seemed to take a little bit longer to appear.
    Originally Posted by fredg1 View Post
    Give me some metrics about exactly "how much" "a little bit longer" is, and I'll pay attention.

    Hard to imagine that synchronizing on something which is not actually in contention would cause a noticible effect. Which is to say, I want something more concrete than "it seems to take longer".

    FWIW, I also added DEBUG logging when various thread activation things happened.
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •