1
0

y_version.inc 9.5 KB

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