1
0

bcrypt.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* The MIT License (MIT)
  2. * Copyright (c) 2014 Lassi R.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8. * of the Software, and to permit persons to whom the Software is furnished to do
  9. * so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. #if defined bcrypt_included
  23. #endinput
  24. #endif
  25. #define bcrypt_included
  26. #if !defined HTTP_GET
  27. #include <a_http>
  28. #endif
  29. #define BCRYPT_HASH_LENGTH 61
  30. #define BCRYPT_PLUGIN_VERSION "2.2.3"
  31. enum BCRYPT_DEBUG_LEVEL {
  32. BCRYPT_LOG_FATAL,
  33. BCRYPT_LOG_ERROR,
  34. BCRYPT_LOG_WARNING,
  35. BCRYPT_LOG_INFO,
  36. BCRYPT_LOG_DEBUG,
  37. BCRYPT_LOG_TRACE
  38. }
  39. native bcrypt_hash(key[], cost = 12, callback_name[], callback_format[] = "", {Float, _}:...);
  40. native bcrypt_check(password[], hash[], callback_name[], callback_format[] = "", {Float, _}:...);
  41. native bcrypt_get_hash(dest[]);
  42. native bool:bcrypt_is_equal();
  43. native bool:bcrypt_needs_rehash(hash[], cost);
  44. native bcrypt_find_cost(time_target = 250);
  45. native bcrypt_set_thread_limit(value);
  46. native bcrypt_debug(BCRYPT_DEBUG_LEVEL:level = BCRYPT_LOG_ERROR);
  47. // Version check
  48. forward OnBcryptVersionCheck(index, response_code, data[]);
  49. #if defined FILTERSCRIPT
  50. public OnFilterScriptInit()
  51. {
  52. HTTP(0, HTTP_GET, "api.ls-rcr.com/bcrypt/?version_check&version=" #BCRYPT_PLUGIN_VERSION, "", "OnBcryptVersionCheck");
  53. return CallLocalFunction("BCRYPT_OnFilterScriptInit", "");
  54. }
  55. forward BCRYPT_OnFilterScriptInit();
  56. #if defined _ALS_OnFilterScriptInit
  57. #undef OnFilterScriptInit
  58. #else
  59. #define _ALS_OnFilterScriptInit
  60. #endif
  61. #define OnFilterScriptInit BCRYPT_OnFilterScriptInit
  62. #else
  63. public OnGameModeInit()
  64. {
  65. HTTP(0, HTTP_GET, "api.ls-rcr.com/bcrypt/?version_check&version=" #BCRYPT_PLUGIN_VERSION, "", "OnBcryptVersionCheck");
  66. return CallLocalFunction("BCRYPT_OnGameModeInit", "");
  67. }
  68. forward BCRYPT_OnGameModeInit();
  69. #if defined _ALS_OnGameModeInit
  70. #undef OnGameModeInit
  71. #else
  72. #define _ALS_OnGameModeInit
  73. #endif
  74. #define OnGameModeInit BCRYPT_OnGameModeInit
  75. #endif
  76. public OnBcryptVersionCheck(index, response_code, data[])
  77. {
  78. if(response_code == 200)
  79. {
  80. if(!strcmp("OK", data, false, 2))
  81. {
  82. print("plugin.bcrypt: The plugin is up-to-date.");
  83. }
  84. else if(!strcmp("UPDATE_AVAILABLE_MAJOR", data, false, 22))
  85. {
  86. print(" ");
  87. printf(" * plugin.bcrypt: A MAJOR UPDATE IS AVAILABLE:");
  88. printf(" * plugin.bcrypt: Current version: %s", BCRYPT_PLUGIN_VERSION);
  89. printf(" * plugin.bcrypt: Latest version: %s", data[23]);
  90. printf(" * plugin.bcrypt: Download: http://api.ls-rcr.com/bcrypt/?upgrade");
  91. printf(" * plugin.bcrypt: Upgrading is highly recommended.");
  92. print(" ");
  93. }
  94. else if(!strcmp("UPDATE_AVAILABLE_MINOR", data, false, 22))
  95. {
  96. print(" ");
  97. printf("plugin.bcrypt: A minor update is available:");
  98. printf("plugin.bcrypt: Current version: %s", BCRYPT_PLUGIN_VERSION);
  99. printf("plugin.bcrypt: Latest version: %s", data[23]);
  100. printf("plugin.bcrypt: Download: http://api.ls-rcr.com/bcrypt/?upgrade");
  101. printf("plugin.bcrypt: Upgrading is recommended.");
  102. print(" ");
  103. }
  104. else if(!strcmp("UPDATE_AVAILABLE_REVISION", data, false, 25))
  105. {
  106. print(" ");
  107. printf("plugin.bcrypt: A new revision is available:");
  108. printf("plugin.bcrypt: Current version: %s", BCRYPT_PLUGIN_VERSION);
  109. printf("plugin.bcrypt: Latest version: %s", data[26]);
  110. printf("plugin.bcrypt: Download: http://api.ls-rcr.com/bcrypt/?upgrade");
  111. printf("plugin.bcrypt: Upgrading is recommended.");
  112. print(" ");
  113. }
  114. }
  115. else
  116. {
  117. print("plugin.bcrypt: Version check failed.");
  118. }
  119. return 1;
  120. }