HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.  *
  3.  * Family Sharing Management - http://labs.projectyami.com/famshare
  4.  * Plugin
  5.  *
  6.  * Copyright (C) 2014 Ryan "YamiKaitou" LeBlanc
  7.  *
  8.  *
  9.  * Requires HTTP2 Include files, https://forums.alliedmods.net/showthread.php?t=223898
  10.  *
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify it
  13.  * under the terms of the GNU General Public License as published by the
  14.  * Free Software Foundation; either version 3 of the License, or (at
  15.  * your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful, but
  18.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20.  * General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; if not, write to the Free Software Foundation,
  24.  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25.  *
  26.  * In addition, as a special exception, the author gives permission to
  27.  * link the code of this program with the Half-Life Game Engine ("HL
  28.  * Engine") and Modified Game Libraries ("MODs") developed by Valve,
  29.  * L.L.C ("Valve"). You must obey the GNU General Public License in all
  30.  * respects for all of the code used other than the HL Engine and MODs
  31.  * from Valve. If you modify this file, you may extend this exception
  32.  * to your version of the file, but you are not obligated to do so. If
  33.  * you do not wish to do so, delete this exception statement from your
  34.  * version.
  35.  *
  36.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  37.  
  38. #pragma semicolon 1
  39.  
  40. #define PLUGINNAME "Családi Megosztás Menedzsment"
  41. #define PLUGINAUTHOR "YamiKaitou"
  42. new const PLUGINVERSION[] = "3.1";
  43.  
  44. #include <amxmodx>
  45. #include <http2>
  46.  
  47. new szAppID[7];
  48. new szLogFile[129];
  49. new hCvarApiKey;
  50. new hCvarKick;
  51. new hCvarLog;
  52. new Trie:hDownloads;
  53. new trash;
  54. #if AMXX_VERSION_NUM < 183
  55. new iMaxPlayers;
  56. #endif
  57.  
  58. public plugin_init()
  59. {
  60. register_plugin(PLUGINNAME, PLUGINVERSION, PLUGINAUTHOR);
  61. set_pcvar_string(register_cvar("family_sharing", PLUGINVERSION, FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY), PLUGINVERSION);
  62.  
  63. hCvarApiKey = register_cvar("sv_apikey", "YourAPIKey", FCVAR_PROTECTED|FCVAR_SPONLY);
  64. hCvarKick = register_cvar("share_kick", "0");
  65. hCvarLog = register_cvar("share_log", "1"); // 1 - Log Shared game, 2 - Log anyway
  66.  
  67. read_file("steam_appid.txt", 0, szAppID, charsmax(szAppID), trash);
  68.  
  69. get_localinfo("amxx_logs", szLogFile, charsmax(szLogFile));
  70. add(szLogFile, charsmax(szLogFile), "/family_sharing.log");
  71.  
  72. hDownloads = TrieCreate();
  73.  
  74. #if AMXX_VERSION_NUM < 183
  75. iMaxPlayers = get_maxplayers();
  76. #endif
  77. }
  78.  
  79. public client_authorized(id)
  80. {
  81. if(is_user_bot(id) || !is_user_steam(id))
  82. return;
  83.  
  84. new szURL[251];
  85. new szApiKey[35];
  86. new szAuthID[38];
  87. new szFriendID[18];
  88. new szFile[23];
  89.  
  90. get_user_authid(id, szAuthID, charsmax(szAuthID));
  91. getSteam64(szAuthID, szFriendID);
  92. formatex(szFile, charsmax(szFile), "%s.vdf", szFriendID);
  93. TrieSetCell(hDownloads, szFile, get_user_userid(id));
  94. get_pcvar_string(hCvarApiKey, szApiKey, charsmax(szApiKey));
  95. formatex(szURL, charsmax(szURL), "http://api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?&format=vdf&steamid=%s&appid_playing=%s&key=%s", szFriendID, szAppID, szApiKey);
  96. HTTP2_Download(szURL, szFile, "DownloadComplete");
  97. }
  98.  
  99. public DownloadComplete(iDownload, iError)
  100. {
  101. new szFile[23];
  102. new iUserID;
  103. new szLine[101];
  104. new szKey[21];
  105. new szValue[21];
  106.  
  107. HTTP2_getFilename(iDownload, szFile, charsmax(szFile));
  108. TrieGetCell(hDownloads, szFile, iUserID);
  109.  
  110. if (iError == 0)
  111. {
  112. read_file(szFile, 2, szLine, charsmax(szLine), trash);
  113. parse(szLine, szKey, charsmax(szKey), szValue, charsmax(szValue));
  114.  
  115. if (!equal(szValue, "0"))
  116. {
  117. if (get_pcvar_num(hCvarLog) > 0)
  118. {
  119. new id = findUser(iUserID);
  120. new szAuthID[40];
  121. new szSharedID[40];
  122. new szName[32];
  123.  
  124. get_user_name(id, szName, charsmax(szName));
  125. get_user_authid(id, szAuthID, charsmax(szAuthID));
  126. getSteam2(szValue, szSharedID, charsmax(szSharedID));
  127.  
  128. log_to_file(szLogFile, "%s<%s> játékos %s által megosztott játékot használ.", szName, szAuthID, szSharedID);
  129. }
  130.  
  131. if (get_pcvar_num(hCvarKick))
  132. {
  133. server_cmd("kick #%d ^"A Családi Megosztással nem játszhatsz ezen a szerveren^"", iUserID);
  134. }
  135. }
  136. else
  137. {
  138. if(get_pcvar_num(hCvarLog) == 2)
  139. {
  140. new id = findUser(iUserID);
  141. new szAuthID[40];
  142. new szName[32];
  143.  
  144. get_user_name(id, szName, charsmax(szName));
  145. get_user_authid(id, szAuthID, charsmax(szAuthID));
  146.  
  147. log_to_file(szLogFile, "%s<%s> játékos nem használ megosztott játékot.", szName, szAuthID);
  148. }
  149. }
  150. }
  151. else
  152. {
  153. log_amx("Hiba: %d - %s", iError, szFile);
  154. }
  155.  
  156. delete_file(szFile);
  157. }
  158.  
  159. stock findUser(iUserID)
  160. {
  161. #if AMXX_VERSION_NUM < 183
  162. for (new k = 0; k < iMaxPlayers; k++)
  163. #else
  164. for (new k = 0; k < MaxClients; k++)
  165. #endif
  166. {
  167. if (get_user_userid(k) == iUserID)
  168. {
  169. return k;
  170. }
  171. }
  172.  
  173. return 0;
  174. }
  175.  
  176. new const szBase[] = "76561197960265728";
  177.  
  178. stock getSteam2(const szSteam64[], szSteam2[], iLen)
  179. {
  180. new iBorrow = 0;
  181. new szSteam[18];
  182. new szAccount[18];
  183. new iY = 0;
  184. new iZ = 0;
  185. new iTemp = 0;
  186.  
  187. arrayset(szAccount, '0', charsmax(szAccount));
  188. copy(szSteam, charsmax(szSteam), szSteam64);
  189.  
  190.  
  191. if (intval(szSteam[16]) % 2 == 1)
  192. {
  193. iY = 1;
  194. szSteam[16] = strval(intval(szSteam[16]) - 1);
  195. }
  196.  
  197. for (new k = 16; k >= 0; k--)
  198. {
  199. if (iBorrow > 0)
  200. {
  201. iTemp = intval(szSteam[k]) - 1;
  202.  
  203. if (iTemp >= intval(szBase[k]))
  204. {
  205. iBorrow = 0;
  206. szAccount[k] = strval(iTemp - intval(szBase[k]));
  207. }
  208. else
  209. {
  210. iBorrow = 1;
  211. szAccount[k] = strval((iTemp + 10) - intval(szBase[k]));
  212. }
  213. }
  214. else
  215. {
  216. if (intval(szSteam[k]) >= intval(szBase[k]))
  217. {
  218. iBorrow = 0;
  219. szAccount[k] = strval(intval(szSteam[k]) - intval(szBase[k]));
  220. }
  221. else
  222. {
  223. iBorrow = 1;
  224. szAccount[k] = strval((intval(szSteam[k]) + 10) - intval(szBase[k]));
  225. }
  226. }
  227. }
  228.  
  229. iZ = str_to_num(szAccount);
  230. iZ /= 2;
  231.  
  232. formatex(szSteam2, iLen, "STEAM_0:%d:%d", iY, iZ);
  233. }
  234.  
  235. stock getSteam64(const szSteam2[], szSteam64[18])
  236. {
  237. new iCarry = 0;
  238. new szAccount[18];
  239. new iTemp = 0;
  240.  
  241. copy(szSteam64, charsmax(szSteam64), szBase);
  242. formatex(szAccount, charsmax(szAccount), "%s", szSteam2[10]);
  243. formatex(szAccount, charsmax(szAccount), "%017d", str_to_num(szAccount));
  244.  
  245. szSteam64[16] = strval(intval(szSteam64[16]) + intval(szSteam2[8]));
  246.  
  247. for (new j = 0; j < 2; j++)
  248. {
  249. for (new k = 16; k >= 0; k--)
  250. {
  251. if (iCarry > 0)
  252. {
  253. iTemp = intval(szSteam64[k-iCarry+1]) + 1;
  254.  
  255. if (iTemp > 9)
  256. {
  257. iTemp -= 10;
  258. szSteam64[k-iCarry+1] = strval(iTemp);
  259. iCarry += 1;
  260. }
  261. else
  262. {
  263. szSteam64[k-iCarry+1] = strval(iTemp);
  264. iCarry = 0;
  265. }
  266.  
  267. k++;
  268. }
  269. else
  270. {
  271. iTemp = intval(szSteam64[k]) + intval(szAccount[k]);
  272.  
  273. if (iTemp > 9)
  274. {
  275. iCarry = 1;
  276. iTemp -= 10;
  277. }
  278.  
  279. szSteam64[k] = strval(iTemp);
  280. }
  281. }
  282. }
  283. }
  284.  
  285. stock is_user_steam(id)
  286. {
  287. static dp_pointer;
  288. if(dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
  289. {
  290. server_cmd("dp_clientinfo %d", id);
  291. server_exec();
  292. return (get_pcvar_num(dp_pointer) == 2) ? true : false;
  293. }
  294. return false;
  295. }
  296.  
  297. strval(const iNum)
  298. {
  299. switch (iNum)
  300. {
  301. case 0: return '0';
  302. case 1: return '1';
  303. case 2: return '2';
  304. case 3: return '3';
  305. case 4: return '4';
  306. case 5: return '5';
  307. case 6: return '6';
  308. case 7: return '7';
  309. case 8: return '8';
  310. case 9: return '9';
  311. }
  312.  
  313. return '0';
  314. }
  315.  
  316. intval(cNum)
  317. {
  318. switch (cNum)
  319. {
  320. case '0': return 0;
  321. case '1': return 1;
  322. case '2': return 2;
  323. case '3': return 3;
  324. case '4': return 4;
  325. case '5': return 5;
  326. case '6': return 6;
  327. case '7': return 7;
  328. case '8': return 8;
  329. case '9': return 9;
  330. }
  331.  
  332. return 0;
  333. }