Quantcast Addon Comms with AceComm 3 - WoWInterface
 
Thread Tools Display Modes
07-02-19, 10:11 PM   #1
Aeriez
A Fallenroot Satyr
Join Date: May 2007
Posts: 24
Addon Comms with AceComm 3

So I've been picking through AceComm 3.0 in conjunction with AceSerializer. I've managed to start to figure out how it's working. However, when I reload the UI, it always triggers OnCommReceived() once on reload/login with no values. IE: print(prefix, message, sender) at the start of OnCommReceived() returns nil nil nil.
It only does it once when the game is loaded in. After that it seems to work fine, sending messages on demand and never nil values. However, that initial set of nil values is where it's breaking AceSerializer. I'm able to serialize and send, but if I attempt to deserialize, it tries passing that nil value on reload/login and breaks the Lib entirely and can no longer be used. Error stating the Deserialize function expected a string but got the nil value. Any insight into what is causing that initial SendCommMessage to fire off?

Oh, and as an added note, it's only the root client that's receiving the nil values. Other clients in the group that receive the messages do not ever see it unless they themselves reload.

Lua Code:
  1. local _, core = ...;
  2. local _G = _G;
  3. local MyAddon = core.MyAddon;
  4.  
  5. MyAddon.Sync = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceComm-3.0")
  6.  
  7. local LibAceSerializer = LibStub:GetLibrary("AceSerializer-3.0")
  8. local LibCompress = LibStub:GetLibrary("LibCompress")
  9. local LibCompressAddonEncodeTable = LibCompress:GetAddonEncodeTable()
  10.  
  11. function MyAddon.Sync:OnEnable()
  12.     MyAddon.Sync:RegisterComm("MyAddonDataSync", MyAddon.Sync:OnCommReceived())
  13. end
  14.  
  15. function MyAddon.Sync:OnCommReceived(prefix, message, distribution, sender)
  16.     local success, deserialized = LibAceSerializer:Deserialize(message);
  17.     if success then
  18.         print(deserialized)
  19.     end
  20. end
  21.  
  22. function MyAddon.Sync:SendData(data)
  23.     local serialized = nil
  24.     if data then
  25.         serialized = LibAceSerializer:Serialize(data)
  26.     end
  27.    
  28.     -- send the message
  29.     MyAddon.Sync:SendCommMessage("MonDKPDataSync", serialized, "PARTY")
  30. end

EDIT: I did work around it by filtering it through if prefix ~= nil. But is that the only way to really ignore it? Or is the initial failure a deeper bug on my behalf?

Last edited by Aeriez : 07-02-19 at 10:27 PM.
  Reply With Quote
07-03-19, 12:33 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,838
I'd check if prefix is equal to the one you registered for your addon. If user has any other addons loaded that use the comms channel, it may crash yours when you start receiving their data as well. Also, you need to make sure you aren't the sender. Most channels send an echo back with the player as the sender.

PS: I don't know, but it seems like OnCommReceived() being fired with nils is a deliberate design choice. I don't use AceComm, but the underlying API used to access these messages only fires when a message is actually received. It makes sense if it was intended to allow addons to initialize their comm channels. If this is an undocumented effect, I'd be wary of it changing or being removed in the future.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-03-19 at 12:53 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Addon Comms with AceComm 3

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off