#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <WPMGPrintChatColor>

#define PLUGIN 	"UserManager"
#define VERSION 	"1.0"
#define AUTHOR 	"CrAsH"

/*==========================================
	Плагины, которые требуется отключить
===========================================*/
new g_PluginsOff[][] =
{
        "admin.amxx", 
        "admin_sql.amxx", 
        "menufront.amxx"
}

/*==========================================
	Информация об структуре AmxModMenu
===========================================*/
enum _:EItems
{
	EItemName[64] = 1,
	EItemCommand[64],
	EItemFlag[64]
}

new g_EItemsNum
new g_EItems[99][EItems]

/*==========================================
		Информация о правах игрока
===========================================*/
enum _:EPlayer
{
	EPlayerDate[64] = 1,
	EPlayerNewPassword[64], 

	EPlayerDay, 
	EPlayerSysTime,
	EPlayerEditMe

}; 

new g_EPlayer[33][EPlayer]

/*==========================================
				Всякая хрень
===========================================*/
new g_LoadUsers[81]
new g_LoadItems[81]

new g_Cvar[5]

/*==========================================
				Инициализация
===========================================*/
public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)

	//Доступные настройки(Квары)
	g_Cvar[1] = register_cvar("um_pw_prefix", "_pw")					//В каком префиксе хранится пароль( дефолт )
	g_Cvar[2] = register_cvar("um_utc", "+04")						//Часовой пояс( Москва/Россия )
	g_Cvar[3] = register_cvar("um_menu_showend", "1")				//Отображать ли в меню, когда кончается срок?
	g_Cvar[4] = register_cvar("um_logs", "1")						//Вести логи авторизации?

	//Доступные команды
	register_clcmd("amxmodmenu", "AmxModMenu")
	register_clcmd("amxmenu", "AmxModMenu")
	register_clcmd("amx_menu", "AmxModMenu")

	register_clcmd("amx_reloadadmins", "ReloadAdmins")

	register_clcmd("newpassword", "NewPassword")

	//Ланг файл
	register_dictionary("UserManager.txt")
}

/*==========================================
		Загрузка и обработка конфигов
===========================================*/
public plugin_cfg()
{
	new szError[128]
	new iLine

	new g_LoadDir[81]
	get_configsdir(g_LoadDir, charsmax( g_LoadDir ))

	server_cmd("exec %s/amxx.cfg", g_LoadDir)
	server_cmd("exec %s/sql.cfg", g_LoadDir)

	formatex(g_LoadDir, charsmax( g_LoadDir ), "%s/UserManager", g_LoadDir)

	formatex(g_LoadUsers, charsmax( g_LoadUsers), "%s/users.ini", g_LoadDir)
	formatex(g_LoadItems, charsmax( g_LoadItems), "%s/amxmodmenu.ini", g_LoadDir)

	if(!dir_exists( g_LoadDir ))
	{
		formatex(szError, charsmax( szError ), "%L", LANG_PLAYER, "UM_CONFIG_NODIR", g_LoadDir)
		set_fail_state( szError )
	}

	if(!file_exists( g_LoadUsers ))
	{
		formatex(szError, charsmax( szError ), "%L", LANG_PLAYER, "UM_CONFIG_NOFILE", g_LoadUsers)
		set_fail_state( szError )
	}

	if(!file_exists( g_LoadItems ))
	{
		formatex(szError, charsmax( szError ), "%L", LANG_PLAYER, "UM_CONFIG_NOFILE", g_LoadItems)
		set_fail_state( szError )
	}

	for(new i; i < sizeof g_PluginsOff; i++ )
	{
		if(find_plugin_byfile( g_PluginsOff[i] ) != INVALID_PLUGIN_ID) 
		{
			formatex(szError, charsmax( szError ), "%L", 0, "UM_ACTIVE_PLUGINOFF", g_PluginsOff[i])
			set_fail_state( szError )
		}
	}

	new iFile = fopen(g_LoadItems, "rt")
	while(!feof( iFile ))
	{
		new szText[256]
		fgets(iFile, szText, charsmax( szText ))

		trim( szText )

		++iLine
		if(!strlen( szText ) || szText[0] == ';' || (szText[0] == '/' && szText[1] == '/' ) || iLine == 1)
			continue

		new szTextP[4][64]
		parse(szText, 
			szTextP[1], 64, 
			szTextP[2], 64, 
			szTextP[3], 64
		)

		++g_EItemsNum

		g_EItems[g_EItemsNum][EItemName] = szTextP[1]
		g_EItems[g_EItemsNum][EItemCommand] = szTextP[2]
		g_EItems[g_EItemsNum][EItemFlag] = szTextP[3]
	}
	fclose( iFile )
}

/*==========================================
Вход игрока:	Запуск проверки игрока на права
===========================================*/
public client_connect(id)
{
	if(is_user_bot(id) || is_user_hltv(id))
		return PLUGIN_CONTINUE

	set_task(1.0, "CheckPlayer", id)
	return PLUGIN_CONTINUE
}

/*==========================================
Выход игрока игрока:	Сброс данных, прав
===========================================*/
public client_disconnect(id)
{
	g_EPlayer[id][EPlayerDate] = ""
	g_EPlayer[id][EPlayerDay] = 0
	g_EPlayer[id][EPlayerSysTime] = 0
	g_EPlayer[id][EPlayerEditMe] = 0

	remove_user_flags(id)
}

/*==========================================
Изменения ника:	Выполнение перезагрузки
===========================================*/
public client_infochanged(id)
{
	if(!is_user_connected(id))
		return PLUGIN_CONTINUE

	new szNameNew[64], szNameOld[64]

	get_user_info(id, "name", szNameNew, charsmax( szNameNew ))
	get_user_name(id, szNameOld, charsmax( szNameOld ))

	if(!equal(szNameOld, szNameNew))
	{
		client_disconnect(id)
		set_task(1.0, "CheckPlayer", id)
	}
	return PLUGIN_CONTINUE
}

/*==========================================
Чекер времени, сброс прав если пришло время(отклик любой команды)
===========================================*/
public client_command(id)
{
	if(!is_user_connected(id))
		return PLUGIN_CONTINUE

	if(g_EPlayer[id][EPlayerSysTime] == -1)
		return PLUGIN_CONTINUE

	CheckEnd(id)
	return PLUGIN_CONTINUE
}

/*==========================================
			Провека на права
===========================================*/
public CheckPlayer(id)
{
	new szName[64], szIP[32], szSteam[32], szPassword[64], szPrefix[32]
	new iLine

	get_pcvar_string(g_Cvar[1], szPrefix, charsmax( szPrefix ))
	get_user_name(id, szName, charsmax( szName ))
	get_user_ip(id, szIP, charsmax( szIP ), 1)
	get_user_authid(id, szSteam, charsmax( szSteam ))
	get_user_info(id, szPrefix, szPassword, charsmax( szPassword ))

	new iFile = fopen(g_LoadUsers, "rt")
	while(!feof( iFile ))
	{
		new szText[256]
		fgets(iFile, szText, charsmax( szText ))

		trim( szText )

		++iLine
		if(!strlen( szText ) || szText[0] == ';' || (szText[0] == '/' && szText[1] == '/' ) || iLine == 1)
			continue

		new szParse[6][64]
		parse(szText, 
			szParse[1], 63, 
			szParse[2], 63, 
			szParse[3], 63, 
			szParse[4], 63, 
			szParse[5], 63
		)

		if(equal(szName, szParse[1]) || equal(szIP, szParse[1]) || equal(szSteam, szParse[1]))
		{
			if(strlen( szParse[2] ))
			{
				if(!equal(szPassword, szParse[2]))
				{
					server_cmd("kick #%d ^"%L^" ", get_user_userid(id), LANG_PLAYER, "UM_FAIL_PASSWORD")
					break
				}
			}

			if(strlen( szParse[4] ))
			{
				new iRealTime = GetRealTime()
				new iPeriodTime = ConvertPeriod( szParse[4] )

				if(iPeriodTime > iRealTime)
				{
					g_EPlayer[id][EPlayerDate] = szParse[4]
					replace_all(g_EPlayer[id][EPlayerDate], 63, " ", "/")

					g_EPlayer[id][EPlayerDay] = (iPeriodTime - iRealTime) / 86400
					g_EPlayer[id][EPlayerSysTime] = iPeriodTime
					g_EPlayer[id][EPlayerEditMe] = str_to_num( szParse[5] )

					set_user_flags(id, read_flags( szParse[3] ))
				}else{
					new szBlock[256] 
					formatex(szBlock, charsmax( szBlock ), ";%s", szText)

					write_file(g_LoadUsers, szBlock, (iLine - 1))
				}
			}else{
				g_EPlayer[id][EPlayerDate] = "unlimited"
				g_EPlayer[id][EPlayerDay] = -1
				g_EPlayer[id][EPlayerSysTime] = -1
				g_EPlayer[id][EPlayerEditMe] = str_to_num( szParse[5] )

				set_user_flags(id, read_flags( szParse[3] ))
			}
			break
		}
	}
	fclose( iFile )
}

/*==========================================
		Меню: AmxModMenu( Главное )
===========================================*/
public AmxModMenu(id)
{
	if(!(get_user_flags(id) & ADMIN_MENU))
	{
		client_print(id, print_console, "%L", LANG_PLAYER, "UM_AMXMODMENU_NOACCESS")
		return PLUGIN_HANDLED
	}

	new szText[512]

	formatex(szText, charsmax( szText ), "%L^n%s", LANG_PLAYER, "UM_AMXMODMENU_TITLE", GetEndPeriod(id))
	new iMenu = menu_create(szText, "AmxModMenu_handler")

	if(g_EPlayer[id][EPlayerEditMe])
	{
		formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_AMXMODMENU_EDIT")
		menu_additem(iMenu, szText, "1", 0)
	}else{
		formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_AMXMODMENU_EDIT")
		menu_additem(iMenu, szText, "1", ADMIN_ADMIN)
	}

	for(new i = 1; i <= g_EItemsNum; i++)
	{
		new iStr[10]
		num_to_str(i + 1, iStr, charsmax(iStr ))

		if(GetMenuFlag(id, g_EItems[i][EItemFlag]))
		{
			menu_additem(iMenu, g_EItems[i][EItemName], iStr, 0)
		}else{
			menu_additem(iMenu, g_EItems[i][EItemName], iStr, ADMIN_ADMIN)
		}
	}

	menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL)

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_MENUS_NEXT")
	menu_setprop(iMenu, MPROP_NEXTNAME, szText)

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_MENUS_BACK")
	menu_setprop(iMenu, MPROP_BACKNAME,szText)

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_MENUS_EXIT")
	menu_setprop(iMenu, MPROP_EXITNAME, szText)

	menu_display(id, iMenu, 0)

	CheckEnd(id)

	return PLUGIN_HANDLED
}

public AmxModMenu_handler(id, iMenu, iItem)
{
	if(iItem == MENU_EXIT)
	{
		menu_destroy( iMenu )
		return PLUGIN_HANDLED
	}

	new szData[6], szName[64], iAccess,iCallback
	menu_item_getinfo(iMenu, iItem, iAccess, szData, charsmax( szData ), szName, charsmax( szName ), iCallback)

	new iKey = str_to_num( szData )

	if(iKey == 1)
	{
		PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_EDITPASSWORD_INFO")
		client_cmd(id, "messagemode newpassword")
	}else{
		client_cmd(id, "%s", g_EItems[iKey - 1][EItemCommand])
	}

	menu_destroy( iMenu )
	return PLUGIN_HANDLED
}

/*==========================================
		Обработчик смены пароля
===========================================*/
public NewPassword(id)
{
	if(!g_EPlayer[id][EPlayerEditMe])
	{
		client_print(id, print_console, "%L", LANG_PLAYER, "UM_AMXMODMENU_NOACCESS")
		return PLUGIN_HANDLED
	}

	new szPassword[64]

	read_args(szPassword, charsmax( szPassword ))
	remove_quotes( szPassword )

	trim( szPassword )

	if(!strlen( szPassword ))
	{
		client_cmd(id, "messagemode newpassword")

		PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_EDITPASSWORD_NOLEN")
		PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_EDITPASSWORD_INFONEW")

		return PLUGIN_HANDLED
	}

	g_EPlayer[id][EPlayerNewPassword] = szPassword
	ConfirmationEdit(id, szPassword)

	return PLUGIN_HANDLED
}

/*==========================================
Меню:	Подтверждение смены пароля
===========================================*/
public ConfirmationEdit(id, szPassword[])
{
	new szText[512]

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_CONFIRMATIONEDIT_TITLE", szPassword)
	new iMenu = menu_create(szText, "ConfirmationEdit_handler")

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_CONFIRMATIONEDIT_ITEM_1")
	menu_additem(iMenu, szText, "1", 0)

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_CONFIRMATIONEDIT_ITEM_2")
	menu_additem(iMenu, szText, "2", 0)

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_CONFIRMATIONEDIT_ITEM_3")
	menu_additem(iMenu, szText, "3", 0)

	menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL)

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_MENUS_NEXT")
	menu_setprop(iMenu, MPROP_NEXTNAME, szText)

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_MENUS_BACK")
	menu_setprop(iMenu, MPROP_BACKNAME,szText)

	formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_MENUS_EXIT")
	menu_setprop(iMenu, MPROP_EXITNAME, szText)

	menu_display(id, iMenu, 0)
	return PLUGIN_HANDLED
}

public ConfirmationEdit_handler(id, iMenu, iItem)
{
	if(iItem == MENU_EXIT)
	{
		menu_destroy( iMenu )
		return PLUGIN_HANDLED
	}

	new szData[6], szName[64], iAccess,iCallback
	menu_item_getinfo(iMenu, iItem, iAccess, szData, charsmax( szData ), szName, charsmax( szName ), iCallback)

	new iKey = str_to_num( szData )

	switch( iKey )
	{
		case 1:
		{
			EditUser(id, 1, "", g_EPlayer[id][EPlayerNewPassword], "", "", g_EPlayer[id][EPlayerEditMe])
			PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_EDITPASSWORD_GOOD", g_EPlayer[id][EPlayerNewPassword])

			new szPrefix[32]
			get_pcvar_string(g_Cvar[1], szPrefix, charsmax( szPrefix ))

			client_cmd(id , "setinfo %s ^"%s^"", szPrefix, g_EPlayer[id][EPlayerNewPassword])

			set_task(0.1, "CheckChange", id)
		}

		case 2:
		{
			PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_EDITPASSWORD_INFO")
			client_cmd(id, "messagemode newpassword")
		}
	}
	menu_destroy( iMenu )
	return PLUGIN_HANDLED
}

/*==========================================
		Перезагрузка админов
===========================================*/
public ReloadAdmins(id)
{
	if(!(get_user_flags(id) & ADMIN_BAN))
	{
		client_print(id, print_console, "%L", LANG_PLAYER, "UM_AMXMODMENU_NOACCESS")
		return PLUGIN_HANDLED
	}

	new iPlayers[32]
	new iPlayer, iNum

	get_players(iPlayers, iNum)

	for(new i; i < iNum; i++)
	{
		iPlayer = iPlayers[i]

		if(!is_user_connected(iPlayer))
			continue

		client_disconnect(iPlayer)
		set_task(1.0, "CheckPlayer", iPlayer)
	}

	client_print(id, print_console, "Reload OK")
	return PLUGIN_HANDLED
	
}

/*==========================================
		Проверка смены пароля(setinfo)
===========================================*/
public CheckChange(id)
{
	new szPassword[64], szPrefix[32]

	get_pcvar_string(g_Cvar[1], szPrefix, charsmax( szPrefix ))
	get_user_info(id, szPrefix, szPassword, charsmax( szPassword ))

	if(!equal(szPassword, g_EPlayer[id][EPlayerNewPassword]))
	{
		PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_EDITPASSWORD_GOOD_INFO_1")
		PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_EDITPASSWORD_GOOD_INFO_2", g_EPlayer[id][EPlayerNewPassword])
	}
}

/*==========================================
		Редактирование юзера
===========================================*/
stock EditUser(id, iEnable, szData[] = "", szPassword[] = "", szFlags[] = "", szPeriod[] = "", iEditMe = 0)
{
	new szName[64], szIP[32], szSteam[32]
	new iLine

	get_user_name(id, szName, charsmax( szName ))
	get_user_ip(id, szIP, charsmax( szIP ), 1)
	get_user_authid(id, szSteam, charsmax( szSteam ))

	new iFile = fopen(g_LoadUsers, "rt")
	while(!feof( iFile ))
	{
		new szText[256]
		fgets(iFile, szText, charsmax( szText ))

		trim( szText )

		++iLine
		if(!strlen( szText ) || szText[0] == ';' || (szText[0] == '/' && szText[1] == '/' ) || iLine == 1)
			continue

		server_print("%s", szText)

		new szParse[6][64]
		parse(szText, 
			szParse[1], 63, 
			szParse[2], 63, 
			szParse[3], 63, 
			szParse[4], 63, 
			szParse[5], 63
		)

		if(equal(szName, szParse[1]) || equal(szIP, szParse[1]) || equal(szSteam, szParse[1]))
		{
			if(!iEnable)
			{
				new szBlock[256] 
				formatex(szBlock, charsmax( szBlock ), ";%s", szText)

				write_file(g_LoadUsers, szBlock, (iLine - 1))
				client_disconnect(id)

				break
			}

			formatex(szText, charsmax( szText ), "^"%s^" ^"%s^" ^"%s^" ^"%s^" ^"%d^"", 
				strlen( szData ) ? szData : szParse[1], 
				strlen( szPassword ) ? szPassword : szParse[2],
				strlen( szFlags ) ? szFlags : szParse[3], 
				strlen( szPeriod ) ? szPeriod : szParse[4],
				iEditMe ? 1 : 0
			)
	
			write_file(g_LoadUsers, szText, (iLine - 1))
			set_task(1.0, "CheckPlayer", id)

			break
		}
	}
	fclose( iFile )
}

/*==========================================
	Корректировка systime с часовым поясом
===========================================*/
stock GetRealTime()
{
	new iSysTime

	new szUTC[32]
	get_pcvar_string(g_Cvar[2], szUTC, charsmax( szUTC ))

	if(containi(szUTC, "+") != -1)
	{
		replace_all(szUTC, charsmax( szUTC ), "+", "")
		iSysTime = get_systime() + (3600 * str_to_num( szUTC ))
	}else
	if(containi(szUTC, "-") != -1)
	{
		replace_all(szUTC, charsmax( szUTC ), "-", "")
		iSysTime = get_systime() - (3600 * str_to_num( szUTC ))
	}else{
		iSysTime = get_systime() + 14400
	}
	return iSysTime
}

/*==========================================
		Конвертирование даты в systime
===========================================*/
stock ConvertPeriod( szPeriod[64] )
{
	new iDay, iMouth, iYear
	replace_all(szPeriod, charsmax( szPeriod ), "/", " ")

	new szParse[9][32]
	parse(szPeriod, 
		szParse[1], 31, 
		szParse[2], 31, 
		szParse[3], 31
	)

	iDay = str_to_num( szParse[1] )
	iMouth = str_to_num( szParse[2] )
	iYear = str_to_num( szParse[3] )

	new iSecond[4]
	if(iYear)
	{
		new iVar[5]

		iVar[1] = iYear / 4
		iVar[2] = iYear - iVar[1]
		iVar[3] = iVar[1] - 492
		iVar[4] = iVar[2] - 1478
    
		iVar[3] *= 31622400
		iVar[4] *= 31536000
    
		iSecond[1] = iVar[3] + iVar[4]
	}

	if(iMouth)
	{
		for(new i = (iMouth - 1); i >= 1; i--)
		{
			iMouth -= 1

			switch( iMouth )
			{
				case 1, 3, 5, 7, 8, 10:
				{
					iSecond[2] += 2678400
				}
		
				case 2 :
				{
					if(iYear % 4 == 0)
					{
						iSecond[2] += 2505600
					}else{
						iSecond[2] += 2419200
					}
				}
		
				case 4, 6, 9, 11:
				{
					iSecond[2] += 2592000
				}
			}
		}
	}

	if(iDay)
	{
		iSecond[3] =  (iDay * 86400) - 1
	}
	return iSecond[1] + iSecond[2] + iSecond[3]
}

/*==========================================
		Проверка доступности пункта
===========================================*/
stock GetMenuFlag(id, szFlag[])
{
	if(!strlen( szFlag ))
		return true

	new szFlags[32]
	get_flags(get_user_flags(id), szFlags, charsmax( szFlags ))

	if(containi(szFlags, szFlag) != -1)
		return true

	return false
}

/*==========================================
			Получение окончаний
===========================================*/
stock GetEndPeriod(id)
{
	new szText[512]

	if(get_pcvar_num( g_Cvar[3] ) != 1)
		return szText

	if(equal(g_EPlayer[id][EPlayerDate], "unlimited"))
	{
		formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_PERIOD_UNLIMITED")
	}else
	if(g_EPlayer[id][EPlayerDay] >= 1)
	{
		formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_PERIOD_DAY", EndWord(1, g_EPlayer[id][EPlayerDay]), g_EPlayer[id][EPlayerDate])
	}else{
		new szTime[32]
		new iEnd, iHour, iMin

		iEnd = g_EPlayer[id][EPlayerSysTime] - GetRealTime()
		iHour = iEnd / 3600
		iMin = (iEnd - (iHour * 3600)) / 60

		++iMin

		if(iHour >= 1)
		{
			formatex(szTime, charsmax( szTime ), "%s %s", EndWord(2, iHour), EndWord(3, iMin))
		}else
		if(iMin >= 1)
		{
			formatex(szTime, charsmax( szTime ), "%s", EndWord(3, iMin))
		}
		formatex(szText, charsmax( szText ), "%L", LANG_PLAYER, "UM_PERIOD_LESS", szTime)
	}
	return szText
}

/*==========================================
		Получение окончаний( текст )
===========================================*/
stock EndWord(iType, iNum) 
{
	new szText[128]
	new iLen

	static const szWords[][][] = 
	{
		{"", "", ""},
		{"ENDWORLD_DAY1", "ENDWORLD_DAY2", "ENDWORLD_DAY3"},
		{"ENDWORLD_HOUR1", "ENDWORLD_HOUR2", "ENDWORLD_HOUR3"},
		{"ENDWORLD_MIN1", "ENDWORLD_MIN2", "ENDWORLD_MIN3"}
	}

	iLen += formatex(szText, charsmax( szText ) - iLen, "%d", iNum)

	switch( iNum ) 
	{
		case 1, 21, 31, 41, 51:
		{
			iLen += formatex(szText[iLen], charsmax( szText ) - iLen, " %L", LANG_PLAYER, szWords[iType][0] )
		}

		case 2..4, 22..24, 32..34, 42..44, 52..54:
		{
			iLen += formatex(szText[iLen], charsmax( szText ) - iLen, " %L", LANG_PLAYER, szWords[iType][1] )
		}

		default:
		{
			iLen += formatex(szText[iLen], charsmax( szText ) - iLen, " %L", LANG_PLAYER, szWords[iType][2] )
		}
	}
	return szText
}

/*==========================================
			Проверка конца прав
===========================================*/
stock CheckEnd(id)
{
	if(!is_user_admin(id))
		return PLUGIN_CONTINUE

	if(g_EPlayer[id][EPlayerSysTime] == -1)
		return PLUGIN_CONTINUE

	new iEnd = g_EPlayer[id][EPlayerSysTime] - GetRealTime()
	if(iEnd <= 0)
	{
		g_EPlayer[id][EPlayerDate] = ""
		g_EPlayer[id][EPlayerDay] = 0
		g_EPlayer[id][EPlayerSysTime] = 0
		g_EPlayer[id][EPlayerEditMe] = 0

		remove_user_flags(id)
		show_menu(id, 0, "^n", 1)

		EditUser(id, 0)

		PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_ENDPERIOD_1")
		PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_ENDPERIOD_2")
		PrintChatColor(id, PRINT_COLOR_RED, "%L", LANG_PLAYER, "UM_ENDPERIOD_3")
	}
	return PLUGIN_CONTINUE
}