Advertisement
RyDeR_

Hash.inc

Feb 19th, 2012
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.70 KB | None | 0 0
  1. /*
  2.     SA-MP Hash Include
  3.     Copyright © 2012 RyDeR`
  4. */
  5.  
  6. #if defined _Included_Hash
  7.     #endinput
  8. #else
  9.     #define _Included_Hash
  10. #endif
  11.  
  12. #include <a_http>
  13.  
  14. #if !defined MAX_HTTP_SIZE
  15.     #define MAX_HTTP_SIZE (1024)
  16. #endif
  17.  
  18. #if !defined HASH_SERVER
  19.     #define HASH_SERVER "ryder.com.nu/hash.php"
  20. #endif
  21.  
  22. enum e_Algorithms {
  23.     MD2,            MD4,            MD5,
  24.     SHA1,           SHA224,         SHA256,         SHA384,         SHA512,
  25.     RIPEMD128,      RIPEMD160,      RIPEMD256,      RIPEMD320,
  26.     WHIRLPOOL,
  27.     TIGER128_3,     TIGER160_3,     TIGER192_3,
  28.     TIGER128_4,     TIGER160_4,     TIGER192_4,
  29.     SNEFRU,         SNEFRU256,
  30.     GOST,
  31.     ADLER32,
  32.     CRC32,          CRC32B,
  33.     SALSA10,        SALSA20,
  34.     HAVAL128_3,     HAVAL160_3,     HAVAL192_3,     HAVAL224_3,     HAVAL256_3,
  35.     HAVAL128_4,     HAVAL160_4,     HAVAL192_4,     HAVAL224_4,     HAVAL256_4,
  36.     HAVAL128_5,     HAVAL160_5,     HAVAL192_5,     HAVAL224_5,     HAVAL256_5
  37. };
  38.  
  39. static stock const
  40.     g_aszAlgorithms[e_Algorithms][9 char] = {
  41.         !"md2",             !"md4",             !"md5",
  42.         !"sha1",            !"sha224",          !"sha256",          !"sha384",          !"sha512",
  43.         !"ripemd128",       !"ripemd160",       !"ripemd256",       !"ripemd320",
  44.         !"whirlpool",
  45.         !"tiger128,3",      !"tiger160,3",      !"tiger192,3",
  46.         !"tiger128,4",      !"tiger160,4",      !"tiger192,4",
  47.         !"snefru",          !"snefru256",
  48.         !"gost",
  49.         !"adler32",
  50.         !"crc32",           !"crc32b",
  51.         !"salsa10",         !"salsa20",
  52.         !"haval128,3",      !"haval160,3",      !"haval192,3",      !"haval224,3",      !"haval256,3",
  53.         !"haval128,4",      !"haval160,4",      !"haval192,4",      !"haval224,4",      !"haval256,4",
  54.         !"haval128,5",      !"haval160,5",      !"haval192,5",      !"haval224,5",      !"haval256,5"
  55.     }
  56. ;
  57.  
  58. stock Hash(const e_Algorithms: iAlgorithm, const iIdx, szText[]) {
  59.     static
  60.         szAlgo[10],
  61.         szHTTP[MAX_HTTP_SIZE]
  62.     ;
  63.     strunpack(szAlgo, g_aszAlgorithms[iAlgorithm]);
  64.     strcat((szHTTP[0] = EOS, szHTTP), szText);
  65.    
  66.     EncodeURL(szHTTP);
  67.     format(szHTTP, sizeof(szHTTP), "algo=%s&data=%s", szAlgo, szHTTP);
  68.  
  69.     return HTTP(iIdx, HTTP_POST, HASH_SERVER, szHTTP, "OnHashResponse");
  70. }
  71.  
  72. static stock EncodeURL(szURL[], iSize = sizeof(szURL)) {
  73.     for(new i = 0, iLen = strlen(szURL); szURL[i] != EOS; ++i) {
  74.         switch(szURL[i]) {
  75.             case '0' .. '9', 'A' .. 'Z', 'a' .. 'z', '-', '_', '.', '!', '~', '*', '\'', '(', ')': {
  76.                 continue;
  77.             }
  78.             case ' ': {
  79.                 szURL[i] = '+';
  80.                 continue;
  81.             }
  82.         }
  83.         if((i + 3) >= iSize) {
  84.             szURL[i] = EOS;
  85.             break;
  86.         }
  87.         if((iLen + 3) >= iSize) {
  88.             szURL[iSize - 3] = EOS;
  89.         }
  90.         static
  91.             s_szHex[3]
  92.         ;
  93.         format(s_szHex, sizeof(s_szHex), "%02x", szURL[i]);
  94.                
  95.         szURL[i++] = '%';
  96.         strins(szURL, s_szHex, i++, iSize);
  97.     }
  98. }
  99.  
  100. static OnHashResponse(const iIdx, const iResponse, szHash[]); public OnHashResponse(const iIdx, const iResponse, szHash[]) {
  101.     return CallRemoteFunction("OnHashUpdate", "is", iIdx, szHash);
  102. }
  103.  
  104. forward OnHashUpdate(const iIdx, szHash[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement