RPTools.net

Discussion and Support

Skip to content

It is currently Tue Apr 25, 2017 3:26 pm 




Forum rules


PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)



Reply to topic  [ 4 posts ] 

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Dragon
 
Joined: Mon May 17, 2010 2:29 pm
Posts: 273
 Post subject: What encode() is actually?
PostPosted: Fri Feb 03, 2017 1:07 pm 
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:

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



and another like this:

Code:

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).

_________________
--
AD&D Framework


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7677
Location: Bay Area
 Post subject: Re: What encode() is actually?
PostPosted: Fri Feb 03, 2017 2:00 pm 
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:
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.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Dragon
 
Joined: Mon May 17, 2010 2:29 pm
Posts: 273
 Post subject: Re: What encode() is actually?
PostPosted: Fri Feb 03, 2017 4:53 pm 
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:
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:
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!

_________________
--
AD&D Framework


Top
 Profile  
 
User avatar  Offline
Great Wyrm
 
Joined: Mon May 10, 2010 11:59 am
Posts: 1558
Location: Chicagoland
 Post subject: Re: What encode() is actually?
PostPosted: Sun Feb 05, 2017 2:58 am 
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

_________________
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
More information here: MapTool Nerps! Fork | TokenTool Nerps! Fork
Custom TokenTool (version 1.0b33): TokenTool.exe


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 4 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 2 guests





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman