y_version.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. </remarks>
  87. \**--------------------------------------------------------------------------**/
  88. #include <a_samp>
  89. #tryinclude <a_http>
  90. #include "y_natives"
  91. #if MAX_PLAYER_NAME != (24)
  92. #error Unknown MAX_PLAYER_NAME size.
  93. #else
  94. // Strip the brackets off.
  95. #undef MAX_PLAYER_NAME
  96. #define MAX_PLAYER_NAME 24
  97. #endif
  98. #include "..\y_scriptinit"
  99. #define YSI_VERSION_RESPO 2
  100. #define YSI_VERSION_MAJOR 3
  101. #define YSI_VERSION_MINOR 09
  102. #define YSI_VERSION_BUILD 0684
  103. #define YSI_VERSION #YSI_VERSION_MAJOR "." #YSI_VERSION_MINOR "." #YSI_VERSION_BUILD
  104. #if defined _YSI_NO_VERSION_CHECK
  105. public OnScriptInit()
  106. {
  107. #if defined YSI_LOCK_MODE
  108. new
  109. x = 10;
  110. YSI_gLockData[YSI_gLockData[2]++] += (YSI_gLockData[3] = floatround(floatpower(x, 2))) - 2;
  111. YSI_gLockData[YSI_gLockData[2]++] = (YSI_gLockData[3] | 0x09) & ~0x04;
  112. YSI_gLockData[2] *= (6 * x) - 5;
  113. #endif
  114. #if defined YVers_OnScriptInit
  115. YVers_OnScriptInit();
  116. #endif
  117. return 1;
  118. }
  119. #undef OnScriptInit
  120. #define OnScriptInit YVers_OnScriptInit
  121. #if defined YVers_OnScriptInit
  122. forward YVers_OnScriptInit();
  123. #endif
  124. #else
  125. /**----------------------------------------------------------------------**\
  126. Hook:
  127. OnScriptInit
  128. </returns>
  129. <remarks>
  130. Constructor. Checks to see if there is a new version available. This
  131. code can not use ANY of the rest of YSI as it needs to be included by
  132. everything first.
  133. </remarks>
  134. \**----------------------------------------------------------------------**/
  135. #if !defined _inc_a_http
  136. public OnScriptInit()
  137. {
  138. #if defined YSI_LOCK_MODE
  139. new
  140. x = 10;
  141. YSI_gLockData[0] = 'a' + 1;
  142. YSI_gLockData[YSI_gLockData[0] - 0x60] = x * 11;
  143. YSI_gLockData[x / 3] = x * 10;
  144. YSI_gLockData[1] = (YSI_gLockData[2] - YSI_gLockData[3]) / 2 + YSI_gLockData[3];
  145. #endif
  146. print(" ");
  147. print(" ");
  148. print(" ");
  149. print(" ======================================= ");
  150. print(" | | ");
  151. print(" | YSI version " YSI_VERSION " | ");
  152. print(" | By Alex \"Y_Less\" Cole | ");
  153. print(" | | ");
  154. print(" | Unable to check the latest YSI | ");
  155. print(" | version, please watch the forums. | ");
  156. print(" | | ");
  157. print(" ======================================= ");
  158. print(" ");
  159. #if defined YVers_OnScriptInit
  160. YVers_OnScriptInit();
  161. #endif
  162. return 1;
  163. }
  164. #undef OnScriptInit
  165. #define OnScriptInit YVers_OnScriptInit
  166. #if defined YVers_OnScriptInit
  167. forward YVers_OnScriptInit();
  168. #endif
  169. #endinput
  170. #endif
  171. forward YVers_Callback(index, code, data[]);
  172. public OnScriptInit()
  173. {
  174. #if defined YSI_LOCK_MODE
  175. YSI_gLockData[0] += 1;
  176. for (new i = 0; i != 2; ++i)
  177. {
  178. YSI_gLockData[0] = YSI_gLockData[0] * 9 + 2;
  179. }
  180. YSI_gLockData[0] -= 1;
  181. YSI_gLockData[3] = YSI_gLockData[0];
  182. YSI_gLockData[0] -= 1;
  183. YSI_gLockData[2] = YSI_gLockData[0] + 11;
  184. YSI_gLockData[0] -= 1;
  185. YSI_gLockData[1] = YSI_gLockData[0] + 7;
  186. #endif
  187. print(" ");
  188. print(" ");
  189. print(" ");
  190. print(" ======================================= ");
  191. print(" | | ");
  192. print(" | YSI version " YSI_VERSION " | ");
  193. print(" | By Alex \"Y_Less\" Cole | ");
  194. //print(" | | ");
  195. //print(" | Checking the latest YSI version.. | ");
  196. print(" | | ");
  197. print(" ======================================= ");
  198. print(" ");
  199. // Call my server to check the current public YSI version. v is the
  200. // current version and c is the version of data response which this code
  201. // can parse. Note that the response data SHOULD be backward compatible
  202. // , but may not always be - hence the accept parameter. This will
  203. // never send any data except the current version for targeted replies
  204. // (e.g. to ignore minor updates which aren't critical). It MAY in the
  205. // future send what libraries are in use so that it only tells you to
  206. // upgrade if the libraries you are using have changed, but that will
  207. // take more work and I'm not going to do that for now (I'm not entirely
  208. // sure exactly how to do it (though I have an idea - note to self:
  209. // chain callbacks from repeated inclusions of this file in the same way
  210. // as ALS then call them BEFORE sending the HTTP)). Note that due to
  211. // the way the internet works the server will know the IP of the server
  212. // which sent the request, but the ENTIRE current contents of the remote
  213. // page are (note: I won't update this comment every time the version
  214. // updates, but that's the gist of it):
  215. //
  216. // 1
  217. // 1.01.0000
  218. //
  219. // This remote script has now been updated to include changelog
  220. // information and keeps a record of what IPs are connecting.
  221. HTTP(0, HTTP_GET, "version.ysi.tl/index.php?c=" #YSI_VERSION_RESPO "&v=" YSI_VERSION, "", "YVers_Callback");
  222. #if defined YVers_OnScriptInit
  223. YVers_OnScriptInit();
  224. #endif
  225. return 1;
  226. }
  227. #undef OnScriptInit
  228. #define OnScriptInit YVers_OnScriptInit
  229. #if defined YVers_OnScriptInit
  230. forward YVers_OnScriptInit();
  231. #endif
  232. /**----------------------------------------------------------------------**\
  233. <summary>YVers_Callback</summary>
  234. <param name=" index">Not used.</param>
  235. <param name=" code">Response code from the server.</param>
  236. <param name=" data[]">HTTP data sent from the server.</param>
  237. <returns>
  238. -
  239. </returns>
  240. <remarks>
  241. This is called when my server responds to the HTTP request sent above
  242. (or when it doesn't). This prints information on the current and any
  243. future versions of YSI. Note that it only does a strcmp to determine if
  244. the version is newer - people can't have versions newer than the latest,
  245. onlyolder or equal (unless they play with the version numbers, but then
  246. that's their own fault).
  247. </remarks>
  248. \**----------------------------------------------------------------------**/
  249. public YVers_Callback(index, code, data[])
  250. {
  251. if (code == 200)
  252. {
  253. // Got the remote page.
  254. // The first line is the version data version. This should be
  255. // forward compatible, so new data is always added to the end of the
  256. // file. Skip the first line - contains the response version.
  257. new
  258. pos = strfind(data, "\n") + 1;
  259. if (strcmp(data[pos], YSI_VERSION, false, 9))
  260. {
  261. //data[pos + 9] = '\0';
  262. print(" ");
  263. print(" ========================================== ");
  264. print(" | | ");
  265. printf(" | A new version (v%.9s) of YSI is | ", data[pos]);
  266. print(" | available from: | ");
  267. print(" | | ");
  268. print(" | www.y-less.com/YSI/YSI_1.0.zip | ");
  269. //printf("data[0]: %c", data[0]);
  270. if (data[0] == '2')
  271. {
  272. print(" | | ");
  273. print(" | Changelog: | ");
  274. // Print the changelog.
  275. new
  276. last = pos + 13;
  277. for ( ; ; )
  278. {
  279. pos = strfind(data[last], "\n", false);
  280. //printf("%d %d %s", last, pos, data[last]);
  281. if (pos == -1)
  282. {
  283. // To break out in the middle of a loop.
  284. break;
  285. }
  286. pos += last;
  287. data[pos - 1] = '\0';
  288. printf(" | %38s | ", data[last]);
  289. last = pos + 1;
  290. }
  291. }
  292. print(" | | ");
  293. print(" ========================================== ");
  294. print(" ");
  295. }
  296. //else
  297. //{
  298. //print(" ====================================== ");
  299. //print(" | | ");
  300. //print(" | Congratulations! You are running | ");
  301. //print(" | the latest version of YSI! | ");
  302. //print(" | | ");
  303. //print(" ====================================== ");
  304. //}
  305. }
  306. //else
  307. //{
  308. // Didn't get the remote page.
  309. //print(" ======================================== ");
  310. //print(" | | ");
  311. //print(" | Could not connect to update server | ");
  312. //print(" | at this time, (your code will | ");
  313. //printf(" | still work (response was %03d)). | ", code);
  314. //print(" | | ");
  315. //print(" ======================================== ");
  316. //}
  317. }
  318. #endif