#include <sourcemod>
new String:command_record[128];
public OnPluginStart()
{
new Handle:hCvarHostName = FindConVar("hostname"), String:sHostName[64];
HookConVarChange(hCvarHostName, OnHostNameChanged);
GetConVarString(hCvarHostName, sHostName, sizeof(sHostName));
LogMessage(sHostName);
EscapeHostNameStr(sHostName, sizeof(sHostName));
LogMessage(sHostName);
FormatEx(command_record, sizeof(command_record), "record \"SAVE/%s\"", sHostName);
LogMessage(command_record);
}
public OnConfigsExecuted()
{
new String:sHostName[64];
GetConVarString(hCvarHostName, sHostName, sizeof(sHostName));
EscapeHostNameStr(sHostName, sizeof(sHostName));
FormatEx(command_record, sizeof(command_record), "record \"SAVE/%s\"", sHostName);
}
EscapeHostNameStr(String:str[], size)
{
ReplaceString(str, size, " ","_");
ReplaceString(str, size, "/","");
ReplaceString(str, size, "\\", "");
ReplaceString(str, size, ":","");
ReplaceString(str, size, ";","");
ReplaceString(str, size, "*","");
ReplaceString(str, size, "?","");
ReplaceString(str, size, "<","");
ReplaceString(str, size, ">","");
ReplaceString(str, size, "|","");
ReplaceString(str, size, " ","");
ReplaceString(str, size, "\"",""); // попытка экранировать "
return String:str[size];
}
public OnHostNameChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
if (!StrEqual(newValue, oldValue)) FormatEx(command_record, sizeof(command_record), "record SAVE/%s", newValue);
}
public OnClientPutInServer(client)
{
LogMessage("OnClientPutInServer: %i:%i",client, GetClientUserId(client));
CreateTimer(4.0, RecordPanel, GetClientUserId(client));
}
public Action:RecordPanel(Handle:timer, any:userid)
{
new client = GetClientOfUserId(userid);
LogMessage("RecordPanel: %i:%i",client, GetClientUserId(client));
if (GetClientTeam(client) > 0)
{
WelcomePanel(client);
return Plugin_Stop;
}
else
{
CreateTimer(4.0, RecordPanel, GetClientUserId(client));
}
return Plugin_Continue;
}
WelcomePanel(client)
{
decl String:name[32], String:buffer[64];
GetClientName(client, name, sizeof(name));
new Handle:panel = CreatePanel();
SetPanelTitle(panel, "[DemoRecord] Автоматическая запись демо.\n");
Format(buffer, sizeof(buffer), "Добро пожаловать, %s!", name);
DrawPanelText(panel, buffer);
DrawPanelText(panel, "Хочешь записать свою игру?");
DrawPanelText(panel, " ");
DrawPanelItem(panel, "Да.");
DrawPanelItem(panel, "Нет.");
DrawPanelText(panel, " ");
DrawPanelItem(panel, "Как это работает?");
SendPanelToClient(panel, client, Select_Record_Panel, 0);
CloseHandle(panel);
}
public Select_Record_Panel(Handle:panel, MenuAction:action, client, index)
{
if (action == MenuAction_Select)
{
switch(index)
{
case 1: Recorder(client);
case 2: PrintToChat(client, "\x04[DemoRecord] \x01Вы отказались от записи демо!");
case 3: RulesPanel(client);
}
}
}
RulesPanel(client)
{
new Handle:panel = CreatePanel();
SetPanelTitle(panel, "[DemoRecord] Как это работает?");
DrawPanelText(panel, " ");
DrawPanelText(panel, "С Вашего соглашения автоматически запишется демо,");
DrawPanelText(panel, "которое будет сохранено в папке cssv34/cstrike/save/");
DrawPanelText(panel, "В случае бана или других спорных моментов,");
DrawPanelText(panel, "при предоставлении демо вопросы будут решаться быстрей.");
DrawPanelText(panel, " ");
DrawPanelText(panel, "С уважением, администрация!");
DrawPanelItem(panel, "Вернуться назад...");
SendPanelToClient(panel, client, Select_Rules_Panel, 0);
CloseHandle(panel);
}
public Select_Rules_Panel(Handle:panel, MenuAction:action, client, index)
{
if (action == MenuAction_Select)
{
if (index == 1)
{
WelcomePanel(client);
}
}
}
Recorder(client)
{
new Handle:KV = CreateKeyValues("DemoRecord");
KvSetString(KV, "cmd", command_record);
ShowVGUIPanel(client, "info", KV);
CloseHandle(KV);
}