WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Addon Comms with AceComm 3 (https://www.wowinterface.com/forums/showthread.php?t=57252)

Aeriez 07-02-19 10:11 PM

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?

SDPhantom 07-03-19 12:33 PM

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.


All times are GMT -6. The time now is 10:58 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI