wow-rp-addons / LibMSP

The “Mary Sue Protocol” (“MSP” for short) is a simple challenge/response protocol for RP UI add-ons within WoW to communicate with each other and publish text information to other clients (such as RP character names and descriptions).
Creative Commons Zero v1.0 Universal
2 stars 1 forks source link

Add support XRP's total chunks XC field #1

Closed Ellypse closed 7 years ago

Ellypse commented 7 years ago

XRP's author, Bor, is using a special field in his implementation of the LibMSP to indicate the total number of incoming chunks of data, in the XC field. This information is sent at the very beggning of the first message (MSP\001) and can be used by the add-on receiving the data to display a visual feedback to the user of the data being received (like a loading bar).

This feature could be back-ported to the LibMSP to have it as default behavior in the msp:Send() function.

Here's an excerpt of XRP's functions related to sending and receiving that information

--[[
    (C) 2014-2017 Bor Blasthammer <bor@blasthammer.net>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
]]

local function Send(name, dataTable, channel, isRequest)
  local data = table.concat(dataTable, "\001")

  --- Stuff…

  -- Guess six added characters from metadata.
  data = ("XC=%d\001%s"):format(((#data + 6) / 255) + 1, data)
  libbw:SendAddonMessage("MSP\001", data:sub(1, 255), "WHISPER", name, "BULK", queue, AddFilter, name)
end

local handlers = {
  ["MSP\001"] = function(name, message, channel)
    local totalChunks = tonumber(message:match("^XC=(%d+)\001"))
    if totalChunks then
      if totalChunks < 512 then
        cache[name].totalChunks = totalChunks
      end
      message = message:gsub("^XC=%d+\001", "")
    end

    --- Stuff…
  end
}