BroadcastPlugin/OnPluginBroadcast problem with v4.62

Posted by Seriley on Tue 28 Sep 2010 03:25 PM — 14 posts, 55,904 views.

#0
When I upgraded to 4.62 from 4.61, I lost my health bar miniwindow. I've isolated the problem to the health bar plugin not receiving the broadcast from the plugin that processes the character data.

Using Debug ("summary") I can see that the health bar plugin does receive broadcasts from other plugins.

I removed MUSHClient v4.62 and reinstalled v4.61 and the health bar plugin works fine. The miniwindow is there.

Please let me know what additional information I can provide.
Netherlands #1
I will look into the issue, although I haven't found the guilty commit yet. Nick would probably be able to find it faster.

Can you show your code? I just ran a test case on the official binary as well as one I built myself, and it worked on both.

The plugin I used to test is below. I tested the command using the Immediate function (Ctrl+I) and calling BroadcastPlugin() from there. That should work, but if it doesn't for you, I am quite intruiged.

Template:saveplugin=TestReceiveBroadcast
To save and install the TestReceiveBroadcast plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as TestReceiveBroadcast.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file TestReceiveBroadcast.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on dinsdag, september 28, 2010, 7:54  -->
<!-- MuClient version 4.62 -->

<!-- Plugin "TestReceiveBroadcast" generated by Plugin Wizard -->

<muclient>
<plugin
   name="TestReceiveBroadcast"
   author="Worstje"
   id="e4e99e5c87166aa107944dce"
   language="Lua"
   purpose="Tests the OnPluginBroadcast callback."
   date_written="2010-09-28 19:52:20"
   requires="4.12"
   version="1.0"
   >

</plugin>

<script>
<![CDATA[
function OnPluginBroadcast (msg, id, name, text)
  Note ("msg = " .. msg)
  Note ("id = " .. id)
  Note ("name = " .. name)

  Note ("text = " .. text)
end

]]>
</script>

</muclient>
Amended on Tue 28 Sep 2010 06:06 PM by Worstje
#2
Thanks, Worstje.

I used your plugin in both versions.

Its output reveals the problem:

Version 4.61

msg = 1
id = 8202bdf6e4d339ae6cae06e5
name = Achaea_Vitals
text =
msg = 1
id = 4a33087c6b66ca6c4611afed
name = Achaea_GMCP_Logger
text = H:1669/1669 M:1708/2002 E:7245/7245 W:8910/8910 NL:37/100

===========================================

Version 4.62

msg = 1
id = MISSING!
name = MISSING!
text =
msg = 1
id = 4a33087c6b66ca6c4611afed
name = Achaea_GMCP_Logger
text = H:1669/1669 M:1708/2002 E:7245/7245 W:8910/8910 NL:37/100

The Achaea_Vitals plugin is patterned after one of Nick's where the data is not sent in the text itself, but stored in variables (require "var") and retrieved using the GetPluginVariableList when the Broadcast is received.

Sending

function build_stats (s)
   local tempstats = {}

   for item in string.gmatch(s, "%d+") do
      tempstats [#tempstats + 1] = item
   end

   -- Load into plugin table for others to use
   var.hp = tempstats [1]
   var.max_hp = tempstats [2]
   var.mana = tempstats [3]
   var.max_mana = tempstats [4]
   var.endu = tempstats [5]
   var.max_endu = tempstats [6]
   var.wp = tempstats [7]
   var.max_wp = tempstats [8]
   var.tnl = tempstats [9]
   var.max_tnl = tempstats [10]

   BroadcastPlugin (1, "")
end -- build_status


Receiving


function OnPluginBroadcast (msg, id, name, text)
  if msg == 1 and id == "8202bdf6e4d339ae6cae06e5" then
  
     -- get all variables
     stats = GetPluginVariableList("8202bdf6e4d339ae6cae06e5")

     draw_bar ()
   
  end -- stats changed
end


I also tested the sending plugin with Broadcast(1, "test") and the text shows up nicely with your reporting program...just no id and/or name info.
Australia Forum Administrator #3
Ah yes, well plugins had major work. Should be easy enough to find.
Australia Forum Administrator #4
Worstje, have you any suggestions here? In your suggested changes to the CTextView, in all the confusion I didn't test writing (again) and now when I use the internal notepad to save a notepad window (like the plugin above) and read it back in, I only get a single character.

Should I put back the code here?

http://github.com/nickgammon/mushclient/commit/5e97cdfde237

Or do you have another suggestion?

Netherlands #5
Yeah you should put that back. (Sorry about the delay, was confirming the bug and such on my build.)
Amended on Tue 28 Sep 2010 09:54 PM by Worstje
Australia Forum Administrator #6
Seriley said:

Thanks, Worstje.

I used your plugin in both versions.



I can't reproduce the problem with a simple plugin that broadcasts. Is it possible the plugin that does the broadcast is also doing it in response to a broadcast? For example, the GMCP stuff broadcasts a GMCP message, your plugin decodes that message, and then re-broadcasts the decoded message?
Netherlands #7
I was wondering that too.
Australia Forum Administrator #8
I think there is a bug in rebroadcasting - the current plugin is set to NULL on BroadcastPlugin - in itself this isn't a major issue, except that the receiving plugin no longer knows its plugin ID, and a rebroadcast will then fail with these symptoms.


Also - the released 4.62 doesn't work with "find" in the notepad. So unfortunately the changes we ended up with are basically the buggy ones I had a while back, just with a different test around them. Saving is wrong, and finding is wrong.
Australia Forum Administrator #9
I also note that this causes a loop:


function OnPluginBroadcast (msg, id, name, text)
  Note ("msg = " .. msg)
  Note ("id = " .. id)
  Note ("name = " .. name)

  Note ("text = " .. text)
  BroadcastPlugin (1, "")  --> loop here
  
end



I have changed version 4.63 to not allow BroadcastPlugin to broadcast to itself.
#10
Yes. You guys are both right. Achaea_Vitals plugin is a middleman.

Achaea_GMCP_Logger -> Achaea_Vitals -> Achaea_Healthbar

This was an interim solution while I was playing with the other information that IRE provides.

Thank you both for your response
Netherlands #11
Nick Gammon said:

Also - the released 4.62 doesn't work with "find" in the notepad. So unfortunately the changes we ended up with are basically the buggy ones I had a while back, just with a different test around them. Saving is wrong, and finding is wrong.


For your viewing 'pleasure', I have put all VS2010 CEditView code regarding find and replace on pastebin. I'd go through the details and such myself, but I haven't got a clue where it goes wrong for you, and I'd have a hard time debugging an issue I don't have as well. Copy/paste as you see fit, or if you spot a more surgical solution to your problems, do that.

http://pastebin.com/s0k6HfcD
Amended on Tue 28 Sep 2010 10:29 PM by Worstje
Australia Forum Administrator #12
Seriley said:

Yes. You guys are both right. Achaea_Vitals plugin is a middleman.


For what it's worth, the new CallPlugin syntax (for Lua) introduced in version 4.55 lets you pass multiple arguments of any type, and get multiple return codes. Thus it could be a viable, faster and easier alternative to doing BroadcastPlugin.
#13
Thanks, Nick. I will look into that