- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
-  * 
-  * Family Sharing Management - http://labs.projectyami.com/famshare 
-  *  Plugin 
-  * 
-  * Copyright (C) 2014  Ryan "YamiKaitou" LeBlanc 
-  * 
-  * 
-  * Requires HTTP2 Include files, https://forums.alliedmods.net/showthread.php?t=223898 
-  * 
-  * 
-  *  This program is free software; you can redistribute it and/or modify it 
-  *  under the terms of the GNU General Public License as published by the 
-  *  Free Software Foundation; either version 3 of the License, or (at 
-  *  your option) any later version. 
-  * 
-  *  This program is distributed in the hope that it will be useful, but 
-  *  WITHOUT ANY WARRANTY; without even the implied warranty of 
-  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
-  *  General Public License for more details. 
-  * 
-  *  You should have received a copy of the GNU General Public License 
-  *  along with this program; if not, write to the Free Software Foundation, 
-  *  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
-  * 
-  *  In addition, as a special exception, the author gives permission to 
-  *  link the code of this program with the Half-Life Game Engine ("HL 
-  *  Engine") and Modified Game Libraries ("MODs") developed by Valve, 
-  *  L.L.C ("Valve"). You must obey the GNU General Public License in all 
-  *  respects for all of the code used other than the HL Engine and MODs 
-  *  from Valve. If you modify this file, you may extend this exception 
-  *  to your version of the file, but you are not obligated to do so. If 
-  *  you do not wish to do so, delete this exception statement from your 
-  *  version. 
-  * 
-  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 
-   
- #pragma semicolon 1 
-   
- #define PLUGINNAME "Családi Megosztás Menedzsment" 
- #define PLUGINAUTHOR "YamiKaitou" 
- new const PLUGINVERSION[] = "3.1"; 
-   
- #include <amxmodx> 
- #include <http2> 
-   
- new szAppID[7]; 
- new szLogFile[129]; 
- new hCvarApiKey; 
- new hCvarKick; 
- new hCvarLog; 
- new Trie:hDownloads; 
- new trash; 
- #if AMXX_VERSION_NUM < 183 
- new iMaxPlayers; 
- #endif 
-   
- public plugin_init() 
- { 
- 	register_plugin(PLUGINNAME, PLUGINVERSION, PLUGINAUTHOR); 
- 	set_pcvar_string(register_cvar("family_sharing", PLUGINVERSION, FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY), PLUGINVERSION); 
-   
- 	hCvarApiKey = register_cvar("sv_apikey", "YourAPIKey", FCVAR_PROTECTED|FCVAR_SPONLY); 
- 	hCvarKick = register_cvar("share_kick", "0"); 
- 	hCvarLog = register_cvar("share_log", "1"); // 1 - Log Shared game, 2 - Log anyway 
-   
- 	read_file("steam_appid.txt", 0, szAppID, charsmax(szAppID), trash); 
-   
- 	get_localinfo("amxx_logs", szLogFile, charsmax(szLogFile)); 
- 	add(szLogFile, charsmax(szLogFile), "/family_sharing.log"); 
-   
- 	hDownloads = TrieCreate(); 
-   
- #if AMXX_VERSION_NUM < 183 
- 	iMaxPlayers = get_maxplayers(); 
- #endif 
- } 
-   
- public client_authorized(id) 
- { 
- 	if(is_user_bot(id) || !is_user_steam(id)) 
- 		return; 
-   
- 	new szURL[251]; 
- 	new szApiKey[35]; 
- 	new szAuthID[38]; 
- 	new szFriendID[18]; 
- 	new szFile[23]; 
-   
- 	get_user_authid(id, szAuthID, charsmax(szAuthID)); 
- 	getSteam64(szAuthID, szFriendID); 
- 	formatex(szFile, charsmax(szFile), "%s.vdf", szFriendID); 
- 	TrieSetCell(hDownloads, szFile, get_user_userid(id)); 
- 	get_pcvar_string(hCvarApiKey, szApiKey, charsmax(szApiKey)); 
- 	formatex(szURL, charsmax(szURL), "http://api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?&format=vdf&steamid=%s&appid_playing=%s&key=%s", szFriendID, szAppID, szApiKey); 
- 	HTTP2_Download(szURL, szFile, "DownloadComplete"); 
- } 
-   
- public DownloadComplete(iDownload, iError) 
- { 
- 	new szFile[23]; 
- 	new iUserID; 
- 	new szLine[101]; 
- 	new szKey[21]; 
- 	new szValue[21]; 
-   
- 	HTTP2_getFilename(iDownload, szFile, charsmax(szFile)); 
- 	TrieGetCell(hDownloads, szFile, iUserID); 
-   
- 	if (iError == 0) 
- 	{ 
- 		read_file(szFile, 2, szLine, charsmax(szLine), trash); 
- 		parse(szLine, szKey, charsmax(szKey), szValue, charsmax(szValue)); 
-   
- 		if (!equal(szValue, "0")) 
- 		{ 
- 			if (get_pcvar_num(hCvarLog) > 0) 
- 			{ 
- 				new id = findUser(iUserID); 
- 				new szAuthID[40]; 
- 				new szSharedID[40]; 
- 				new szName[32]; 
-   
- 				get_user_name(id, szName, charsmax(szName)); 
- 				get_user_authid(id, szAuthID, charsmax(szAuthID)); 
- 				getSteam2(szValue, szSharedID, charsmax(szSharedID)); 
-   
- 				log_to_file(szLogFile, "%s<%s> játékos %s által megosztott játékot használ.", szName, szAuthID, szSharedID); 
- 			} 
-   
- 			if (get_pcvar_num(hCvarKick)) 
- 			{ 
- 				server_cmd("kick #%d ^"A Családi Megosztással nem játszhatsz ezen a szerveren^"", iUserID); 
- 			} 
- 		} 
- 		else 
- 		{ 
- 			if(get_pcvar_num(hCvarLog) == 2) 
- 			{ 
- 				new id = findUser(iUserID); 
- 				new szAuthID[40]; 
- 				new szName[32]; 
-   
- 				get_user_name(id, szName, charsmax(szName)); 
- 				get_user_authid(id, szAuthID, charsmax(szAuthID)); 
-   
- 				log_to_file(szLogFile, "%s<%s> játékos nem használ megosztott játékot.", szName, szAuthID); 
- 			} 
- 		} 
- 	} 
- 	else 
- 	{ 
- 		log_amx("Hiba: %d - %s", iError, szFile); 
- 	} 
-   
- 	delete_file(szFile); 
- } 
-   
- stock findUser(iUserID) 
- { 
- #if AMXX_VERSION_NUM < 183 
- 	for (new k = 0; k < iMaxPlayers; k++) 
- #else 
- 	for (new k = 0; k < MaxClients; k++) 
- #endif 
- 	{ 
- 		if (get_user_userid(k) == iUserID) 
- 		{ 
- 			return k; 
- 		} 
- 	} 
-   
- 	return 0; 
- } 
-   
- new const szBase[] = "76561197960265728"; 
-   
- stock getSteam2(const szSteam64[], szSteam2[], iLen) 
- { 
- 	new iBorrow = 0; 
- 	new szSteam[18]; 
- 	new szAccount[18]; 
- 	new iY = 0; 
- 	new iZ = 0; 
- 	new iTemp = 0; 
-   
- 	arrayset(szAccount, '0', charsmax(szAccount)); 
- 	copy(szSteam, charsmax(szSteam), szSteam64); 
-   
-   
- 	if (intval(szSteam[16]) % 2 == 1) 
- 	{ 
- 		iY = 1; 
- 		szSteam[16] = strval(intval(szSteam[16]) - 1); 
- 	} 
-   
- 	for (new k = 16; k >= 0; k--) 
- 	{ 
- 		if (iBorrow > 0) 
- 		{ 
- 			iTemp = intval(szSteam[k]) - 1; 
-   
- 			if (iTemp >= intval(szBase[k])) 
- 			{ 
- 				iBorrow = 0; 
- 				szAccount[k] = strval(iTemp - intval(szBase[k])); 
- 			} 
- 			else 
- 			{ 
- 				iBorrow = 1; 
- 				szAccount[k] = strval((iTemp + 10) - intval(szBase[k])); 
- 			} 
- 		} 
- 		else 
- 		{ 
- 			if (intval(szSteam[k]) >= intval(szBase[k])) 
- 			{ 
- 				iBorrow = 0; 
- 				szAccount[k] = strval(intval(szSteam[k]) - intval(szBase[k])); 
- 			} 
- 			else 
- 			{ 
- 				iBorrow = 1; 
- 				szAccount[k] = strval((intval(szSteam[k]) + 10) - intval(szBase[k])); 
- 			} 
- 		} 
- 	} 
-   
- 	iZ = str_to_num(szAccount); 
- 	iZ /= 2; 
-   
- 	formatex(szSteam2, iLen, "STEAM_0:%d:%d", iY, iZ); 
- } 
-   
- stock getSteam64(const szSteam2[], szSteam64[18]) 
- { 
- 	new iCarry = 0; 
- 	new szAccount[18]; 
- 	new iTemp = 0; 
-   
- 	copy(szSteam64, charsmax(szSteam64), szBase); 
- 	formatex(szAccount, charsmax(szAccount), "%s", szSteam2[10]); 
- 	formatex(szAccount, charsmax(szAccount), "%017d", str_to_num(szAccount)); 
-   
- 	szSteam64[16] = strval(intval(szSteam64[16]) + intval(szSteam2[8])); 
-   
- 	for (new j = 0; j < 2; j++) 
- 	{ 
- 		for (new k = 16; k >= 0; k--) 
- 		{ 
- 			if (iCarry > 0) 
- 			{ 
- 				iTemp = intval(szSteam64[k-iCarry+1]) + 1; 
-   
- 				if (iTemp > 9) 
- 				{ 
- 					iTemp -= 10; 
- 					szSteam64[k-iCarry+1] = strval(iTemp); 
- 					iCarry += 1; 
- 				} 
- 				else 
- 				{ 
- 					szSteam64[k-iCarry+1] = strval(iTemp); 
- 					iCarry = 0; 
- 				} 
-   
- 				k++; 
- 			} 
- 			else 
- 			{ 
- 				iTemp = intval(szSteam64[k]) + intval(szAccount[k]); 
-   
- 				if (iTemp > 9) 
- 				{ 
- 					iCarry = 1; 
- 					iTemp -= 10; 
- 				} 
-   
- 				szSteam64[k] = strval(iTemp); 
- 			} 
- 		} 
- 	} 
- } 
-   
- stock is_user_steam(id) 
- { 
- 	static dp_pointer; 
- 	if(dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider"))) 
- 	{ 
- 		server_cmd("dp_clientinfo %d", id); 
- 		server_exec(); 
- 		return (get_pcvar_num(dp_pointer) == 2) ? true : false; 
- 	} 
- 	return false; 
- } 
-   
- strval(const iNum) 
- { 
- 	switch (iNum) 
- 	{ 
- 		case 0:		return '0'; 
- 		case 1:		return '1'; 
- 		case 2:		return '2'; 
- 		case 3:		return '3'; 
- 		case 4:		return '4'; 
- 		case 5:		return '5'; 
- 		case 6:		return '6'; 
- 		case 7:		return '7'; 
- 		case 8:		return '8'; 
- 		case 9:		return '9'; 
- 	} 
-   
- 	return '0'; 
- } 
-   
- intval(cNum) 
- { 
- 	switch (cNum) 
- 	{ 
- 		case '0':		return 0; 
- 		case '1':		return 1; 
- 		case '2':		return 2; 
- 		case '3':		return 3; 
- 		case '4':		return 4; 
- 		case '5':		return 5; 
- 		case '6':		return 6; 
- 		case '7':		return 7; 
- 		case '8':		return 8; 
- 		case '9':		return 9; 
- 	} 
-   
- 	return 0; 
- }