dracoblue.net

urlencode in Pawn

When creating new REST-ful API for GTAT (based upon my pwncurl and a lua backend) I had to implement the method urlencode in pawn.

So I took a look at the specification in RFC 1738 to get information about what characters need to be encoded.

RFC 1738: Only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

Since I really want to be sure that all is encoded properly and %xx encoding is

<!--more-->allowed, too - even if not neceassary - my urlencode function encodes every character except A-Z,a-z,0-9,'-','_' and '.'.

/**
 *  Url encodes a specific string
 *  @param string string
 */
stock urlencode(string[]) {
    new ret[MAX_STRING];
    ret[0] = 0;
    new i = 0;
    new p = 0;
    new s = 0;
    while (string[i] != 0) {
        if  (
                (string[i] >= 'A' && string[i] &lt;='Z')
                || (string[i] >= 'a' && string[i] &lt;='z')
                || (string[i] >= '0' && string[i] &lt;='9')
                || (string[i] == '-')
                || (string[i] == '_')
                || (string[i] == '.')
            ) {
                ret[p] = string[i];
            } else {
                //
                ret[p] = '%';
                p++;
                s = (string[i] % 16); //
                ret[p+1] = (s>9) ? (55+s) : (48+s); // 64 - 9 = 55
                s = floatround((string[i] - s)/16);
                ret[p] = (s>9) ? (55+s) : (48+s); // 64 - 9 = 55
                p++;
            }
        p++;
        i++;
    }
    return ret;
}

This function will also be part of next release of dutils.

In dutils, pawn, pwncurl by DracoBlue @ 20 Jun 2009 | 252 Words

Morph css background-position in Internet Explorer

If you try to set the CSS-property

background-position in Internet Explorer (I tested with 7) and even use that with Mootools' morph/tween-functions, it will not work.

You can workaround that issue, if you set also background-position-x and background-position-y (actually ignored by my Firefox 3.0).

This is the code, I use at koala to move the background upwards.

$('body').morph({
    'background-position':'0 -140px',
    'background-position-y':'-140px',
});

In css, internet explorer, javascript, mootools by DracoBlue @ 16 Jun 2009 | 75 Words

Renaming a file in Pawn

If you are using pawn (for instance in san andreas multiplayer) and want to rename a file, you'll not find a method like frename.

You can either use my

dutils (pawn only solution) or a plugin (like Yless' YSF) to add frename to your functions.

If you want to make a plain pawn solution, and don't want to use dutils, here is how I made it.

There are two steps.

First you'll need fcopy (copies the file):

ohnd=fopen(oldname,io_read);
nhnd=fopen(newname,io_write);
new buf2[1];
new i;
for (i=flength(ohnd);i>0;i--) {
    fputchar(nhnd, fgetchar(ohnd, buf2[0],false),false);
}
fclose(ohnd);
fclose(nhnd);

And then you'll need to remove the old file.

fremove(oldname);

Remember, that on linux those methods will not work (since fputchar is bugged on linux). You need to use the pawnonly frenametextfile and fcopytextfile from

dutils for that.

In pawn by DracoBlue @ 13 Jun 2009 | 145 Words

Toggle Map-Icon Visibility for a Player

If you want to hide a specific player on the map, you can set the alpha value to 0x00. If you want to make him visible again, you just have to set it to 0xFF.

Since this is not always simple, to store the current color of the player in a invisible and a visible way, you can use bitwise or to do that task for you.

This is my togglePlayerMapIconVisibility function, which keeps the color of the player and toggles the player to visible or invisible on the map.

stock togglePlayerMapIconVisibility(playerid,bool:visible){
    SetPlayerColor(playerid, (GetPlayerColor(playerid) | 0xFF) - (visible ? 0x00 : 0xFF));
}

In pawn by DracoBlue @ 03 Jun 2009 | 108 Words

Could not complete the operation due to error 80020101

This happend to me when I tried to load ajax-content in internet explorer (worked fine in Firefox, etc), which had a script-tag without a valid comments tag.

So just for the record, here is the solution, which helped me.

Before (Broken):

<script type="text/javascript">
<!--
  alert('text');
// -->
</script>

Fixed (Working)

<script type="text/javascript">
// <!--
  alert('text');
// -->
</script>

In internet explorer, javascript by DracoBlue @ 14 May 2009 | 92 Words

Page 24 - Page 25 - Page 26

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About