5.03 causing json issues

Posted by Kahenraz on Sat 08 Oct 2016 09:06 PM — 9 posts, 35,512 views.

#0
I updated from 4.94 to 5.03 today and have started getting the following JSON error spam from GMCP:

GMCP DATA ERROR: C:\data\games\Mush\lua\json\decode\state.lua:151: Value set when one already in slot

GMCP DATA ERROR: C:\data\games\Mush\lua\json\decode\util.lua:35: unexpected character @ character: 2 0:2 [l] line:
[l

GMCP DATA ERROR: C:\data\games\Mush\lua\json\decode\util.lua:35: unexpected character @ character: 2 0:2 [v] line:
[v
Amended on Sat 08 Oct 2016 09:08 PM by Kahenraz
Australia Forum Administrator #1
On what MUD? I just tested on Aardwolf (which uses GMCP heavily) without any problems.
#2
I've sent you an e-mail with a zip file containing screenshots and a plugin which outputs the incoming packets.

There is a definite disparity between 4.94 and 5.03 which may be causing these issues.
Australia Forum Administrator #3
Which MUD? You could copy/paste the text of what you see into a reply. Screenshots of text aren't usually that helpful.

The screenshots don't show that error message anywhere.
#4
Materia Magica.
Australia Forum Administrator #5

function OnPluginPacketReceived (s)
   print(s)
   
   print("------------------------------")
   
   return s
end -- function


I don't think it is wise to start introducing newlines into the output window when you receive a packet. This could have weird side-effects. That callback was really for manipulating packet data (eg. getting rid of carriage-returns) not for triggering displays on the output window.

Does this problem go away with the plugin removed?
#6
I think it was an error in how I was handling a string.gsub which sometimes inserted a newline in the middle of a json block depending on how packets were received.

I've disabled this plugin for now pending further thought on how to implement this.

It's relayed to the same issue another user had with his implementation:

https://gammon.com.au/forum/bbshowpost.php?bbsubject_id=8476

MM does not guarantee that a newline will arrive at the end of the packet with the prompt or something.

If I understand it correctly, I think the prompt arrives as {prompt}{json}{\n} where the newline is appended after the json. But sometimes the packet splits in the middle of the json which causes problems. The prompt isn't guaranteed to arrive in a complete packet.

Configure MUSHclient to convert an IAC EOR/GA to a newline doesn't work in this case so I've been looking into OnPluginPacketReceived().

I would say that this is not a bug as I had thought.
Australia Forum Administrator #7
A more sophisticated OnPluginPacketReceived would look for newlines. That is, it would take the incoming packet, break it into "lines" and assemble an outgoing packet (with changes as required). Then any left over can be held over (ie. in an "extra" variable).

Next time OnPluginPacketReceived is called you prepend the "extra" variable (which after all was not sent to the client before) and repeat the process. That way, you never split a line.

There were some changes in version 4.99 (see release notes point 1) which are more likely to be the cause of the issue.

http://www.gammon.com.au/scripts/showrelnote.php?version=4.99&productid=0
Australia Forum Administrator #8
Something like this will handle partial lines (untested though):



partial = ""  -- partial line from last time through

function OnPluginPacketReceived (s)

  -- add packet to what we already have (excluding carriage-returns)
  
  partial = partial .. s
  
  t = {}  -- table of lines to be returned
  
  -- iterate over each line
  
  partial = string.gsub (partial, "(.-)\n", 
    function (line) 
      table.insert (t, line)
      return ""
    end)

  if table.getn (t) > 0 then
    table.insert (t, "")  -- to get final linefeed
  end -- if
    
  -- return table of lines, concatenated with newlines between each one
  return table.concat (t, "\n")
  
end -- function OnPluginPacketReceived


That keeps left-over data from the previous packet in the variable "partial" (partial line). It then adds the current packet to the end. The new combined packet is then broken down at line-breaks by the string.gsub, and put into a table.

Now you could examine the table and make changes to individual lines.

Finally we return as the processed packet the table, concatenated together with newlines so it looks similar to the original. Any left-over data will be in "partial" for next time around.