#include <sourcemod>
#include <morecolors>

#define CounterTerrorist 3

public Plugin:myinfo =
{
	name = "Regeln",
	author = "MaTTe/Bara",
	description = "Regeln",
	version = "1.0",
	url = "sourcemod.net / www.bara.in"
};

new bool:gClientSpawned[33];
new bool:gClientAgreed[33];

public OnPluginStart()
{
	HookEvent("player_spawn", HookClientSpawn, EventHookMode_Post);
}

public OnClientDisconnect(client)
{
	gClientSpawned[client] = false;
	gClientAgreed[client] = false;
}

public onClientPutInServer(client)
{
	gClientSpawned[client] = false;
}

public HookClientSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	new iUserId = GetEventInt(event, "userid");
	new client = GetClientOfUserId(iUserId);

	if(gClientSpawned[client] == false && gClientAgreed[client] == false)
	{
		Menu_Build(client);
		gClientSpawned[client] = true;
	}
}

public Menu_Build(client)
{
	new String:szTermsFile[256];
	BuildPath(Path_SM, szTermsFile, sizeof(szTermsFile), "configs/terms.txt");
	new Handle:hFile = OpenFile(szTermsFile, "rt");

	if(hFile == INVALID_HANDLE)
	{
		return;
	}

	new String:szReadData[128];

	new Handle:hMenu = CreatePanel();

	while(!IsEndOfFile(hFile) && ReadFileLine(hFile, szReadData, sizeof(szReadData)))
	{
		DrawPanelText(hMenu, szReadData);
	}

	SetPanelTitle(hMenu, "Regeln");

	DrawPanelItem(hMenu, "Nicht Akzeptieren");
	DrawPanelItem(hMenu, "Akzeptieren");

	SendPanelToClient(hMenu, client, Menu_Handler, 60);

	CloseHandle(hMenu);

	CloseHandle(hFile);
}

public Menu_Handler(Handle:hMenu, MenuAction:action, param1, param2)
{
	if(action == MenuAction_Select)
	{
		if(param2 == 2)
		{
			CPrintToChat(param1, "{blue}Sie haben die Regeln akzeptiert!");
			gClientAgreed[param1] = true;
		}
		else if(param2 == 1)
		{
			KickClient(param1, "Sie haben die Regeln nicht akzeptiert");
		}
	}
}