Jump to content


Photo

Command Handler Synchronization


    4 replies to this topic

    #1 Mojo

    Mojo

      Newbie

    • Members
    • Pip
    • 6 posts

      Posted 30 September 2015 - 10:58 PM

      I was wondering if there is some documentation on how the command handler works.  I've been working on an addon that registers on incoming text events and can possibly generate additional text events.  Recursion is something I need to handle properly.  Some messing around has led me to conclude that the command handler is a queue and the windower.chat.input function will add an event to the queue.  Is this right?  Also, what assumptions can I make regarding synchronized access to the queue?  Is it safe to assume that while an addon function is executing, it has sole access to the queue (i.e. no race conditions with incoming packets that could also cause events?)  Any help would be greatly appreciated.



      #2 Arcon

      Arcon

        Advanced Member

      • Windower Staff
      • 1189 posts
      • LocationMunich, Germany

      Posted 01 October 2015 - 05:50 AM

      There is a FFXI command handler and a Windower command handler and they're entirely separate. Addon commands have their own event, it's "addon command". This is a skeleton you can use for it:

       

      _addon.command = 'foo'
      -- Or
      _addon.commands = {'foo', 'f'}
       
      windower.register_event('addon command', function(command, ...)
          command = command and command:lower() or 'help'
          local args = {...}
       
          if command == 'this' then
              -- Do this
          elseif command == 'that' then
              -- Do that
          elseif command == 'help' then
              -- Print help text
          end
      end)

       

      The command handler is called before incoming text. If an addon registers a command with the "_addon.command = 'foo'" or "_addon.commands = {'foo', 'f'}" statements then typing "//foo one two three" will call the function registered with "windower.register_event". There will be no issues with multiple addons either, because it will abort after the first addon it finds that has the command registered. But that shouldn't happen in the first place, should make sure to have different commands for each addon.

       

      As for the "incoming text" event, it's fired consecutively for each addon (in the order they were loaded) and only once all addons (and plugins) are processed it gets passed back to the game. But you shouldn't be using that for commands.



      #3 Mojo

      Mojo

        Newbie

      • Members
      • Pip
      • 6 posts

        Posted 05 October 2015 - 05:06 PM

        Hey,

         

        Thanks for the replay and sorry for the delayed response.  I believe I misled you with my incorrect nomenclature.  I am not trying to send a plugin commands.  The 'commands' I'm interested in are incoming text events (i.e. windower.register_event('incoming_text', function)).  The addon I'm writing registers a callback with text events and may generate additional text events when the callback executes.  The question I'm trying to answer is whether the client will be able to insert an arbitrary text event in the middle of a series of addon generated text events, or if the event queue (or whatever mechanism handles/generates these) is protected from such behavior.  I hope this makes sense.



        #4 Iryoku

        Iryoku

          Advanced Member

        • Windower Staff
        • 488 posts

          Posted 05 October 2015 - 10:12 PM

          There's no such guarantee, windower.add_to_chat() is atomic, but a sequence of such calls is not; I'm not sure why you would expect any different. We do guarantee that you will receive incoming text events in the order the client sees them though.



          #5 Arcon

          Arcon

            Advanced Member

          • Windower Staff
          • 1189 posts
          • LocationMunich, Germany

          Posted 05 October 2015 - 11:29 PM

          Technically you are able to split lines in a single add_to_chat call by using the 0x07 character, which FFXI interprets as a new line. This should also work with addons like Timestamp. However, the max message size is 2048 bytes, including a lot of control characters (such like color codes, new lines, braces, color resets, etc.), so you will not be able to exceed that in a single call.






          1 user(s) are reading this topic

          0 members, 1 guests, 0 anonymous users