AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   %x (https://forums.alliedmods.net/showthread.php?t=54935)

alien 05-08-2007 09:54

%x
 
Does format( ) support %x, %X specifiers?

According to this, it does.
According to my output and funcwiki, it does not.

alien 05-08-2007 10:04

Re: %x
 
And according to this, it should. Am I just running and old Amxmodx? Well ... thanks anyway.

regalis 05-08-2007 10:17

Re: %x
 
Quote:

Originally Posted by alien (Post 474624)
And according to this, it should. Am I just running and old Amxmodx? Well ... thanks anyway.


Quote:

Reported Version 1.76d
Due in Version 1.8
You will have to wait a little bit till version 1.8 is out ;)

btw.: your first link is a sourcemod link ;)
(http://wiki.amxmodx.org/Format_Class...d_Scripting%29)

alien 05-08-2007 10:48

Re: %x
 
Yes, I've noticed it's from SourceMod :) Couldn't wait ... had to code it :/ Thnx.

regalis 05-08-2007 10:53

Re: %x
 
May i ask you for what reason you need to print a number in hexadecimal radix?
Just wonder in what case this will be used.

greetz regalis

alien 05-08-2007 11:08

Re: %x
 
Sure! ... I'm sending HTTP GET / POST requests to web servers ... in case, I'm sending something like player names, these have to be URL-safe-encoded. And to do that, I need hex.

Well, this is what I have so far - I've got a bug inside, don't know where:

PHP Code:

url_safe(unsafe_string[], safe_string[])
    {
        new 
unsafe[] =
            {
                
0x240x260x2b0x2c0x2f0x3a0x3b0x3d0x3f0x40,
                
0x200x220x3c0x230x250x7b0x7c0x7d0x5c0x5e0x7e0x5b0x5d0x60
            
}

        new 
safe[][4] =
            {
                
"%24""%26""%2b""%2c""%2f""%3a""%3b""%3d""%3f""%40",
                
"%20""%22""%3c""%23""%25""%7b""%7c""%7d""%5c""%5e""%7e""%5b""%5d""%60"
            
}

        new
            
length strlen(unsafe_string),
            
max_length length 3

        
for (new 0lengthi++)
            {
                for (new 
024j++)
                    {
                        
server_print("%d = %d"unsafe_string[i], unsafe[j])

                        if (
unsafe_string[i] == unsafe[j])
                            {
                                
format(safe_stringmax_length"%s%s"safe_stringsafe[j])

                                break;
                            }
                        else 
format(safe_stringmax_length"%s%c"safe_stringunsafe_string[i])
                    }

                
server_print(safe_string)
            }
    } 


alien 05-08-2007 11:37

Re: %x
 
Seems to work fine ... but there could be bugs inside.
Just in the case someone would need it:

PHP Code:

url_safe(unsafe_string[], safe_string[])
    {
        new 
unsafe[] =
            {
                
0x240x260x2b0x2c0x2f0x3a0x3b0x3d0x3f0x40,
                
0x200x220x3c0x230x250x7b0x7c0x7d0x5c0x5e0x7e0x5b0x5d0x60
            
}

        new 
safe[][4] =
            {
                
"%24""%26""%2b""%2c""%2f""%3a""%3b""%3d""%3f""%40",
                
"%20""%22""%3c""%23""%25""%7b""%7c""%7d""%5c""%5e""%7e""%5b""%5d""%60"
            
}

        new
            
length strlen(unsafe_string),
            
max_length length 3

        
for (new 0lengthi++)
            {
                new 
bool:safe_char true

                
for (new 024j++)
                    {
                        if (
unsafe_string[i] == unsafe[j])
                            {
                                
format(safe_stringmax_length"%s%s"safe_stringsafe[j])
                                
safe_char false

                                
break;
                            }
                    }

                if (
safe_charformat(safe_stringmax_length"%s%c"safe_stringunsafe_string[i])
            }
    } 


regalis 05-08-2007 11:48

Re: %x
 
hmm, i think i have to get more into hex ;)
don't realy understand that, luckily i don't need it *puhh*

thanks for sharing this :)
greetz regalis

Zenith77 05-08-2007 11:49

Re: %x
 
This has already been done I believe:
http://forums.alliedmods.net/showthr...highlight=HTTP

alien 05-08-2007 11:52

Re: %x
 
Woa, thanks Zenith77 :) ... but that's decode, function above is encoder. But I was in need of this as well. Cheers.


All times are GMT -4. The time now is 06:43.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.