y_version.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*----------------------------------------------------------------------------*\
  2. =====================
  3. YSI - Version Check
  4. =====================
  5. Description:
  6. Checks online to see if there is a newer version of YSI available.
  7. Legal:
  8. Version: MPL 1.1
  9. The contents of this file are subject to the Mozilla Public License Version
  10. 1.1 (the "License"); you may not use this file except in compliance with
  11. the License. You may obtain a copy of the License at
  12. http://www.mozilla.org/MPL/
  13. Software distributed under the License is distributed on an "AS IS" basis,
  14. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  15. for the specific language governing rights and limitations under the
  16. License.
  17. The Original Code is the YSI version check include.
  18. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  19. Portions created by the Initial Developer are Copyright (C) 2011
  20. the Initial Developer. All Rights Reserved.
  21. Contributors:
  22. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  23. Thanks:
  24. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  25. ZeeX - Very productive conversations.
  26. koolk - IsPlayerinAreaEx code.
  27. TheAlpha - Danish translation.
  28. breadfish - German translation.
  29. Fireburn - Dutch translation.
  30. yom - French translation.
  31. 50p - Polish translation.
  32. Zamaroht - Spanish translation.
  33. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  34. for me to strive to better.
  35. Pixels^ - Running XScripters where the idea was born.
  36. Matite - Pestering me to release it and using it.
  37. Very special thanks to:
  38. Thiadmer - PAWN, whose limits continue to amaze me!
  39. Kye/Kalcor - SA:MP.
  40. SA:MP Team past, present and future - SA:MP.
  41. Version:
  42. 0.2
  43. Changelog:
  44. 26/10/10:
  45. Added changelog capabilities.
  46. 22/10/10:
  47. First version.
  48. Functions:
  49. Public:
  50. -
  51. Core:
  52. -
  53. Stock:
  54. -
  55. Static:
  56. -
  57. Inline:
  58. -
  59. API:
  60. -
  61. Hooks:
  62. OnGameModeInit
  63. Callbacks:
  64. -
  65. Definitions:
  66. -
  67. Enums:
  68. -
  69. Macros:
  70. -
  71. Tags:
  72. -
  73. Variables:
  74. Global:
  75. -
  76. Static:
  77. -
  78. Commands:
  79. -
  80. Compile options:
  81. -
  82. Operators:
  83. -
  84. Natives:
  85. -
  86. \*----------------------------------------------------------------------------*/
  87. #include <a_samp>
  88. #tryinclude <a_http>
  89. #include "y_natives"
  90. #if MAX_PLAYER_NAME != (24)
  91. #error Unknown MAX_PLAYER_NAME size.
  92. #else
  93. // Strip the brackets off.
  94. #undef MAX_PLAYER_NAME
  95. #define MAX_PLAYER_NAME 24
  96. #endif
  97. #include "..\y_scriptinit"
  98. #define YSI_VERSION_RESPO 2
  99. #define YSI_VERSION_MAJOR 1
  100. #define YSI_VERSION_MINOR 04
  101. #define YSI_VERSION_BUILD 0000
  102. #define YSI_VERSION #YSI_VERSION_MAJOR "." #YSI_VERSION_MINOR "." #YSI_VERSION_BUILD
  103. #if defined _YSI_NO_VERSION_CHECK
  104. public OnScriptInit()
  105. {
  106. #if defined YSI_LOCK_MODE
  107. new
  108. x = 10;
  109. YSI_gLockData[YSI_gLockData[2]++] += (YSI_gLockData[3] = floatround(floatpower(x, 2))) - 2;
  110. YSI_gLockData[YSI_gLockData[2]++] = (YSI_gLockData[3] | 0x09) & ~0x04;
  111. YSI_gLockData[2] *= (6 * x) - 5;
  112. #endif
  113. CallLocalFunction("YVers_OnScriptInit", "");
  114. return 1;
  115. }
  116. #undef OnScriptInit
  117. #define OnScriptInit YVers_OnScriptInit
  118. forward OnScriptInit();
  119. #else
  120. /*------------------------------------------------------------------------*\
  121. Hook:
  122. OnScriptInit
  123. Notes:
  124. Constructor. Checks to see if there is a new version available. This
  125. code can not use ANY of the rest of YSI as it needs to be included by
  126. everything first.
  127. \*------------------------------------------------------------------------*/
  128. #if !defined _inc_a_http
  129. public OnScriptInit()
  130. {
  131. #if defined YSI_LOCK_MODE
  132. new
  133. x = 10;
  134. YSI_gLockData[0] = 'a' + 1;
  135. YSI_gLockData[YSI_gLockData[0] - 0x60] = x * 11;
  136. YSI_gLockData[x / 3] = x * 10;
  137. YSI_gLockData[1] = (YSI_gLockData[2] - YSI_gLockData[3]) / 2 + YSI_gLockData[3];
  138. #endif
  139. print(" ");
  140. print(" ======================================= ");
  141. print(" | | ");
  142. print(" | YSI version " YSI_VERSION " | ");
  143. print(" | By Alex \"Y_Less\" Cole | ");
  144. print(" | | ");
  145. print(" | Unable to check the latest YSI | ");
  146. print(" | version, please watch the forums. | ");
  147. print(" | | ");
  148. print(" ======================================= ");
  149. print(" ");
  150. CallLocalFunction("YVers_OnScriptInit", "");
  151. return 1;
  152. }
  153. #undef OnScriptInit
  154. #define OnScriptInit YVers_OnScriptInit
  155. forward OnScriptInit();
  156. #endinput
  157. #endif
  158. forward YVers_Callback(index, code, data[]);
  159. public OnScriptInit()
  160. {
  161. #if defined YSI_LOCK_MODE
  162. YSI_gLockData[0] += 1;
  163. for (new i = 0; i != 2; ++i)
  164. {
  165. YSI_gLockData[0] = YSI_gLockData[0] * 9 + 2;
  166. }
  167. YSI_gLockData[0] -= 1;
  168. YSI_gLockData[3] = YSI_gLockData[0];
  169. YSI_gLockData[0] -= 1;
  170. YSI_gLockData[2] = YSI_gLockData[0] + 11;
  171. YSI_gLockData[0] -= 1;
  172. YSI_gLockData[1] = YSI_gLockData[0] + 7;
  173. #endif
  174. print(" ");
  175. print(" ======================================= ");
  176. print(" | | ");
  177. print(" | YSI version " YSI_VERSION " | ");
  178. print(" | By Alex \"Y_Less\" Cole | ");
  179. //print(" | | ");
  180. //print(" | Checking the latest YSI version.. | ");
  181. print(" | | ");
  182. print(" ======================================= ");
  183. print(" ");
  184. // Call my server to check the current public YSI version. v is the
  185. // current version and c is the version of data response which this code
  186. // can parse. Note that the response data SHOULD be backward compatible
  187. // , but may not always be - hence the accept parameter. This will
  188. // never send any data except the current version for targeted replies
  189. // (e.g. to ignore minor updates which aren't critical). It MAY in the
  190. // future send what libraries are in use so that it only tells you to
  191. // upgrade if the libraries you are using have changed, but that will
  192. // take more work and I'm not going to do that for now (I'm not entirely
  193. // sure exactly how to do it (though I have an idea - note to self:
  194. // chain callbacks from repeated inclusions of this file in the same way
  195. // as ALS then call them BEFORE sending the HTTP)). Note that due to
  196. // the way the internet works the server will know the IP of the server
  197. // which sent the request, but the ENTIRE current contents of the remote
  198. // page are (note: I won't update this comment every time the version
  199. // updates, but that's the gist of it):
  200. //
  201. // 1
  202. // 1.01.0000
  203. //
  204. // This remote script has now been updated to include changelog
  205. // information and keeps a record of what IPs are connecting.
  206. HTTP(0, HTTP_GET, "ysi-version.y-less.com/index.php?c=" #YSI_VERSION_RESPO "&v=" YSI_VERSION, "", "YVers_Callback");
  207. CallLocalFunction("YVers_OnScriptInit", "");
  208. return 1;
  209. }
  210. #undef OnScriptInit
  211. #define OnScriptInit YVers_OnScriptInit
  212. forward OnScriptInit();
  213. /*------------------------------------------------------------------------*\
  214. Function:
  215. YVers_Callback
  216. Params:
  217. index - Not used.
  218. code - Response code from the server.
  219. data[] - HTTP data sent from the server.
  220. Return:
  221. -
  222. Notes:
  223. This is called when my server responds to the HTTP request sent above
  224. (or when it doesn't). This prints information on the current and any
  225. future versions of YSI. Note that it only does a strcmp to determine if
  226. the version is newer - people can't have versions newer than the latest,
  227. onlyolder or equal (unless they play with the version numbers, but then
  228. that's their own fault).
  229. \*------------------------------------------------------------------------*/
  230. public YVers_Callback(index, code, data[])
  231. {
  232. if (code == 200)
  233. {
  234. // Got the remote page.
  235. // The first line is the version data version. This should be
  236. // forward compatible, so new data is always added to the end of the
  237. // file. Skip the first line - contains the response version.
  238. new
  239. pos = strfind(data, "\n") + 1;
  240. if (strcmp(data[pos], YSI_VERSION, false, 9))
  241. {
  242. //data[pos + 9] = '\0';
  243. print(" ");
  244. print(" ========================================== ");
  245. print(" | | ");
  246. printf(" | A new version (v%.9s) of YSI is | ", data[pos]);
  247. print(" | available from: | ");
  248. print(" | | ");
  249. print(" | www.y-less.com/YSI/YSI_1.0.zip | ");
  250. //printf("data[0]: %c", data[0]);
  251. if (data[0] == '2')
  252. {
  253. print(" | | ");
  254. print(" | Changelog: | ");
  255. // Print the changelog.
  256. new
  257. last = pos + 13;
  258. for ( ; ; )
  259. {
  260. pos = strfind(data[last], "\n", false);
  261. //printf("%d %d %s", last, pos, data[last]);
  262. if (pos == -1)
  263. {
  264. // To break out in the middle of a loop.
  265. break;
  266. }
  267. pos += last;
  268. data[pos - 1] = '\0';
  269. printf(" | %38s | ", data[last]);
  270. last = pos + 1;
  271. }
  272. }
  273. print(" | | ");
  274. print(" ========================================== ");
  275. print(" ");
  276. }
  277. //else
  278. //{
  279. //print(" ====================================== ");
  280. //print(" | | ");
  281. //print(" | Congratulations! You are running | ");
  282. //print(" | the latest version of YSI! | ");
  283. //print(" | | ");
  284. //print(" ====================================== ");
  285. //}
  286. }
  287. //else
  288. //{
  289. // Didn't get the remote page.
  290. //print(" ======================================== ");
  291. //print(" | | ");
  292. //print(" | Could not connect to update server | ");
  293. //print(" | at this time, (your code will | ");
  294. //printf(" | still work (response was %03d)). | ", code);
  295. //print(" | | ");
  296. //print(" ======================================== ");
  297. //}
  298. }
  299. #endif