Page 1 of 1

What encode() is actually?

Posted: Fri Feb 03, 2017 1:07 pm
by celestian
So, I'm trying to write a little tool to convert character sheets/monsters from Maptools to a tool I wrote (external) and then import. Basically a character editor for the players they can do offline... however I'm running into an issue trying to figure out something.

I use "encode()" in a maptools macro on a few things that are written to the contents.xml file. The raw text looks like this.

Code: Select all


TSR+2140+-+Monstrous+Manual+%28Second+Edition%29%3A+2e

and another like this:

Code: Select all


weaponID%3D1+%26semi%3B+weaponSource%3Dnone+%26semi%3B+name%3Dattack+%231+%26semi%3B+speed%3D5+%26semi%3B+toHit%3D0+%26semi%3B+toDamage%3D0+%26semi%3B+damageSmall%3D2d4+%26semi%3B+damageMedium%3D2d4+%26semi%3B+damageLarge%3D2d4+%26semi%3B+weaponProf%3Dnone+%26semi%3B+strHit%3D0+%26semi%3B+strDamage%3D0+%26semi%3B+dexHit%3D0+%26semi%3B+racialBonus%3D0+%26semi%3B+otherBonus%3D0+%26semi%3B

I've tried a few perl modules to "decode" that. XML/HTML::Entities but neither seem to return it to a normal "string" of clean text. Any theories on how I can get around this? I really need this to be something I can do on the export/import side (not inside maptools).

Re: What encode() is actually?

Posted: Fri Feb 03, 2017 2:00 pm
by aliasmask
Encode will change non alphanumeric characters in to %[hex value in ascii] except for the space which is a + symbol and the semi-colon is %26semi%3B or ;.

Below is the original, encoded and decoded versions.

Code: Select all

This tab	is in the way;
This+tab%09is+in+the+way%26semi%3B
This tab	is in the way;
I recall that this is a change from earlier MT versions where %20 was used for space and something else was used for the ; which had an intentional duplication when encoding, or maybe that was with form submissions which also does encoding to pass data in a URL compatible format.

Re: What encode() is actually?

Posted: Fri Feb 03, 2017 4:53 pm
by celestian
aliasmask wrote:Encode will change non alphanumeric characters in to %[hex value in ascii] except for the space which is a + symbol and the semi-colon is %26semi%3B or ;.

Below is the original, encoded and decoded versions.

Code: Select all

This tab	is in the way;
This+tab%09is+in+the+way%26semi%3B
This tab	is in the way;
I recall that this is a change from earlier MT versions where %20 was used for space and something else was used for the ; which had an intentional duplication when encoding, or maybe that was with form submissions which also does encoding to pass data in a URL compatible format.
Ah, ok so here is what I ended up with.

Code: Select all

Source :weaponID%3D1+%26semi%3B+weaponSource%3Dnone+%26semi%3B+name%3Dattack+%231+%26semi%3B+speed%3D5+%26semi%3B+toHit%3D0+%26semi%3B+toDamage%3D0+%26semi%3B+damageSmall%3D2d4+%26semi%3B+damageMedium%3D2d4+%26semi%3B+damageLarge%3D2d4+%26semi%3B+weaponProf%3Dnone+%26semi%3B+strHit%3D0+%26semi%3B+strDamage%3D0+%26semi%3B+dexHit%3D0+%26semi%3B+racialBonus%3D0+%26semi%3B+otherBonus%3D0+%26semi%3B

-Source w/+ replacement for spaces: weaponID%3D1 %26semi%3B weaponSource%3Dnone %26semi%3B name%3Dattack %231 %26semi%3B speed%3D5 %26semi%3B toHit%3D0 %26semi%3B toDamage%3D0 %26semi%3B damageSmall%3D2d4 %26semi%3B damageMedium%3D2d4 %26semi%3B damageLarge%3D2d4 %26semi%3B weaponProf%3Dnone %26semi%3B strHit%3D0 %26semi%3B strDamage%3D0 %26semi%3B dexHit%3D0 %26semi%3B racialBonus%3D0 %26semi%3B otherBonus%3D0 %26semi%3B

--Source uri unescape: weaponID=1 ; weaponSource=none ; name=attack #1 ; speed=5 ; toHit=0 ; toDamage=0 ; damageSmall=2d4 ; damageMedium=2d4 ; damageLarge=2d4 ; weaponProf=none ; strHit=0 ; strDamage=0 ; dexHit=0 ; racialBonus=0 ; otherBonus=0 ;

--Source XML decode: weaponID=1 ; weaponSource=none ; name=attack #1 ; speed=5 ; toHit=0 ; toDamage=0 ; damageSmall=2d4 ; damageMedium=2d4 ; damageLarge=2d4 ; weaponProf=none ; strHit=0 ; strDamage=0 ; dexHit=0 ; racialBonus=0 ; otherBonus=0 ;

I did a string replace of + with space, then uri unescape, then a xml decode and it gets the text back in the right format.

Thanks!

Re: What encode() is actually?

Posted: Sun Feb 05, 2017 2:58 am
by JamzTheMan
FYI: IF you want to live on the bleeding edge, my fork does have a sendURL(url, key, value) macro in it (as well as a requestURL(url)). It does a POST with the key/value pair, useful to package up json data and send it.

I only suggest it, as it seems you are developing something a little advance and may not care about staying with the normal builds. :D