y_version.inc 9.7 KB

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