utils.inputbox in a trigger duplicates received text

Posted by Fiendish on Sun 03 Jan 2021 02:54 AM — 4 posts, 17,218 views.

USA Global Moderator #0
If a trigger spawns an inputbox, the output gets wonky if new messages (including GMCP) arrive while the inputbox is open.


Here's a minimal test case:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="TEST"
   author="Fiendish"
   id="52766ef28a7a682387d59687"
   language="Lua"
   purpose="Test"
   date_written="2020-12-30 00:00:00"
   version="1.00"
   >

</plugin>
<aliases>
<alias
   script="test"
   match="test"
   enabled="y"
   sequence="100"
   ignore_case="y"
>
</alias>
</aliases>

<triggers>
<trigger
   enabled="n"
   match="*"
   sequence="100"
   send_to="12"
   name="test"
>
<send>
EnableTrigger("test", false)
local input = utils.inputbox("Hi", "Hello", "Value")
</send>
</trigger>
</triggers>

<script>
<![CDATA[
   function test()
      EnableTrigger("test", true)
      Send("echo FIRST MESSAGE")
      Send("echo SECOND MESSAGE")
   end
]]>
</script>
</muclient>


I connect to Aardwolf with an empty world that has only this plugin loaded in it and then type "test" to activate the alias. I see:

Quote:

echo FIRST MESSAGE
echo SECOND MESSAGE
FIRST MESSAGEFIRST MESSAGE

SECOND MESSAGE



If I remove EnableTrigger("test", false) from the trigger script, the situation gets much worse with spawning many input boxes, and then this might happen while I'm frantically trying to close them:

Quote:

echo FIRST MESSAGE
echo SECOND MESSAGE
FIRST MESSAGEFIRST MESSAGE
FIRST MESSAGE
FIRST MESSAGE
FIRST MESSAGE

SECOND MESSAGE

{-=Masaki=-} Hassaikai Yakuza: dont really care mate

WARFARE: Genocide has been declared by Ivar for levels 1 to 18!
WARFARE: The preparation grounds shall close in approx 2 minutes!
WARFARE: Type 'combat' to join the war. No death penalties!

SECOND MESSAGE

{-=Masaki=-} Hassaikai Yakuza: dont really care mate

SECOND MESSAGE

{-=Masaki=-} Hassaikai Yakuza: dont really care mate

SECOND MESSAGE
Amended on Sun 03 Jan 2021 03:01 AM by Fiendish
Australia Forum Administrator #1

I can reproduce it, but I’m not sure why.

If I remove EnableTrigger(“test”, false) from the trigger script, the situation gets much worse with spawning many input boxes,

Well you expect that, right? It is matching “*” multiple times and thus putting up multiple input boxes. Not a recommended thing to do.

As for the first problem, it seems to be something to do with MCCP, because if you turn that off the problem goes away.

I suspect what is happening is that the first echo “FIRST MESSAGE” causes the trigger to fire, and because the inputbox does not return (until you dismiss the dialog box) then the input from the MUD is not properly cleaned up. Or to put it another way, it probably isn’t re-entrant.

If you turn on packet debug it seems to think that a second FIRST MESSAGE has been sent from the server, which clearly did not in fact happen, so there is bogus input in the input buffer, probably caused by the lack of cleanup as mentioned earlier.

As a workaround I suggest not putting up input boxes when triggers fire, there is too much possibility of this sort of problem.

USA Global Moderator #2
Quote:
Well you expect that, right?

I'm not sure. I kind of expected that the plugin won't keep processing new lines until the input box is done, but obviously that isn't infinitely sustainable.

But the more related issue is that the repeated output also duplicates more and more with the repeated input boxes.
Australia Forum Administrator #3
You might reasonably expect that a modal dialog box like utils.inputbox would stop processing until you dismissed it, however MFC implements modal dialogs in a somewhat strange way. That is, the main event loop is still active. Thus you have the possibility that non-re-entrant code will fail under certain circumstances.