diff --git a/ext/sourcepawn-client/Facti13BackendIntegration.sp b/ext/sourcepawn-client/Facti13BackendIntegration.sp index 36e2f9d..37d9dea 100644 --- a/ext/sourcepawn-client/Facti13BackendIntegration.sp +++ b/ext/sourcepawn-client/Facti13BackendIntegration.sp @@ -1,7 +1,4 @@ -#include -#include -#include -#include +#include "core/globals.sp" #define PLUGIN_VERSION "1.0" @@ -13,71 +10,23 @@ public Plugin myinfo = { url = "https://tf2.pblr-nyk.pro" } -/* CONVAR */ -Handle g_server_id_convar = INVALID_HANDLE; -Handle g_api_secret_key_convar = INVALID_HANDLE; -Handle g_api_gateway_convar = INVALID_HANDLE; - -char g_server_id[32]; -char g_secretkey[64]; -char g_gateway[128]; - -char g_cookie[128]; -char g_url[128]; - Handle g_timer = INVALID_HANDLE; int g_lastupdate = 0; bool g_warned = true; -bool g_setuped = false; bool g_updating = false; -stock SetupConVar() { - g_server_id_convar = CreateConVar("sm_fbi_server_id", "srv8", "fbi server id", FCVAR_PROTECTED); - g_api_secret_key_convar = CreateConVar("sm_fbi_secretkey", "123456789", "fbi secret key", FCVAR_PROTECTED); - g_api_gateway_convar = CreateConVar("sm_fbi_gateway", "http://192.168.3.50:8080/api/server/%s", "fbi gateway", FCVAR_PROTECTED); - // - HookConVarChange(g_server_id_convar, OnServerIdChanged); - HookConVarChange(g_api_secret_key_convar, OnSecretKeyChanged); - HookConVarChange(g_api_gateway_convar, OnGatewayChanged); - // - GetConVarString(g_server_id_convar, g_server_id, sizeof(g_server_id)); - GetConVarString(g_api_secret_key_convar, g_secretkey, sizeof(g_secretkey)); - GetConVarString(g_api_gateway_convar, g_gateway, sizeof(g_gateway)); - // - UpdateUrlData(); -} -stock UnSetupConvar() { - UnhookConVarChange(g_server_id_convar, OnServerIdChanged); - UnhookConVarChange(g_api_secret_key_convar, OnSecretKeyChanged); - UnhookConVarChange(g_api_gateway_convar, OnGatewayChanged); -} - -public OnServerIdChanged(Handle:cvar, const String:oldVal[], const String:newVal[]) { - strcopy(g_server_id, sizeof(g_server_id), newVal); - LogMessage("[FBI] Server id now: %s", g_server_id); - UpdateUrlData(); -} -public OnSecretKeyChanged(Handle:cvar, const String:oldVal[], const String:newVal[]) { - strcopy(g_secretkey, sizeof(g_secretkey), newVal); - LogMessage("[FBI] Secret key now lenght: %d", strlen(g_secretkey)); - UpdateUrlData(); -} -public OnGatewayChanged(Handle:cvar, const String:oldVal[], const String:newVal[]) { - strcopy(g_gateway, sizeof(g_gateway), newVal); - LogMessage("[FBI] Gateway now: %s", g_gateway); - UpdateUrlData(); +public OnPluginStart() { + SetupGlobalConVar(); + RegAdminCmd("fbi_test", TestUpdate, ADMFLAG_ROOT); + g_timer = CreateTimer(15, timerCall, 0, TIMER_REPEAT); } -stock UpdateUrlData(){ - g_setuped = false; - if (strlen(g_server_id)>0 && strlen(g_secretkey)>0){ - Format(g_url, sizeof(g_url), g_gateway, g_server_id); - Format(g_cookie, sizeof(g_cookie), "secretkey=%s", g_secretkey); - g_setuped = true; - LogMessage("[FBI] Successful set URL and SecretKey"); - } else - LogError("[FBI] Failed URL and SecretKey"); +public OnPluginEnd() { + UnSetupGlobalConvar(); + if (g_timer != INVALID_HANDLE) { + KillTimer(g_timer); + } } stock HTTPRequest createRequest() { @@ -187,34 +136,11 @@ static void Request_Callback(HTTPResponse response, any value){ } } -stock IsValidClient(int client){ - if(client > 4096){ - client = EntRefToEntIndex(client); - } - if(client < 1 || client > MaxClients) return false; - if(!IsClientInGame(client)) return false; - if(IsFakeClient(client)) return false; - return true; -} - -public OnPluginStart() { - SetupConVar(); - RegAdminCmd("fbi_test", TestUpdate, ADMFLAG_ROOT); - g_timer = CreateTimer(15, timerCall, 0, TIMER_REPEAT); -} - public Action timerCall(Handle:t, any:d) { UpdateStatus(); return Plugin_Continue; } -public OnPluginEnd() { - UnSetupConvar(); - if (g_timer != INVALID_HANDLE) { - KillTimer(g_timer); - } -} - public Action TestUpdate(int client, int args){ UpdateStatus(); ReplyToCommand(client, "OK! Last update: %d", g_lastupdate) diff --git a/ext/sourcepawn-client/Facti13Reports.sp b/ext/sourcepawn-client/Facti13Reports.sp new file mode 100644 index 0000000..e832cbe --- /dev/null +++ b/ext/sourcepawn-client/Facti13Reports.sp @@ -0,0 +1,386 @@ +#include "core/globals.sp" + +#define PLUGIN_VERSION "1.0" + +public Plugin myinfo = { + name = "Facti13 Reports", + author = "gsd", + description = "basic reports to backend", + version = PLUGIN_VERSION, + url = "https://tf2.pblr-nyk.pro" +} + +#define REASON_TEXT_SIZE 256 +#define CONFIG_REASON_LINE REASON_TEXT_SIZE + 32 + +// Client Vars +int g_clients_cooldown[MAXPLAYERS+1]; +int g_clients_reported_uid[MAXPLAYERS+1]; +bool g_clients_reasons_wait[MAXPLAYERS+1]; +char g_clients_reason[MAXPLAYERS+1][REASON_TEXT_SIZE]; + +// Plugin Vars +int g_client_cooldown; + +// Choices +#define REASONS_SLOTS 32 +char g_reasons[REASONS_SLOTS][64]; +int g_reasons_bitflag[REASONS_SLOTS]; +char g_reasons_solution[REASONS_SLOTS][REASON_TEXT_SIZE]; + +public OnPluginStart() { + SetupGlobalConVar(); + SetupThis(); +} + +public OnPluginEnd() { + UnSetupGlobalConvar(); +} + +public SetupThis(){ + RegConsoleCmd("sm_report2", COMMAND_ClientReport); + ///////////////////////////////////////////////////////////////// + RegConsoleCmd("say", SayHook); + RegConsoleCmd("say_team", SayHook); + ///////////////////////////////////////////////////////////////// + for(int i; i++ < MaxClients - 1;){ + OnClientPutInServer(i); + } + ///////////////////////////////////////////////////////////////// +} + +public void OnClientPutInServer(int cid){ + g_clients_cooldown[cid] = -1; + g_clients_reasons_wait[cid] = false; + g_clients_reported_uid[cid] = -1; +} + +stock HTTPRequest createRequest() { + HTTPRequest client = INVALID_HANDLE; + char url[256]; + Format(url, sizeof(url), "%s/report", g_url); + + if (strlen(g_url)>0) { + client = new HTTPRequest(g_url); + client.SetHeader("Cookie", g_cookie); + client.Timeout = 3; + } else { + LogMessage("[FBI] Client not builded"); + } + return client; +} + +//legacy +static void SendReport(const char[] reason, int uid){ + int cid_author = GetClientOfUserId(uid); + int cid_reported = GetClientOfUserId(g_clients_reported_uid[cid_author]); + + char author_steam64[64]; + char reported_steam64[64]; + GetClientAuthId(cid_author, AuthId_SteamID64, author_steam64, 64); + GetClientAuthId(cid_reported, AuthId_SteamID64, reported_steam64, 64); + + JSONObject payload = new JSONObject(); + payload.SetString("author_steam64", author_steam64); + payload.SetString("reported_steam64", reported_steam64); + payload.SetString("reason", reason); + + createRequest().Post(payload, Report_Callback, uid); + + //////////////////////////////////////////////////////////////// + g_clients_cooldown[cid_author] = GetTime(); + g_clients_reported_uid[cid_author] = -1; + g_clients_reasons_wait[cid_author] = false; + //////////////////////////////////////////////////////////////// +} + + +public Action COMMAND_ClientReport(int cid, int args){ + if(cid == 0){ + return Plugin_Handled; + } + /////////////////////////////////////////////////////////////////////////////// + int client_cooldown = GetTime() - g_clients_cooldown[cid]; + if(client_cooldown < g_client_cooldown){ + PrintToChat(cid, "Подожди еще %i секунды прежде чем отправлять следующий репорт.", g_client_cooldown - client_cooldown); + return Plugin_Handled; + } + /////////////////////////////////////////////////////////////////////////////// + ShowDisclaimer(cid); + return Plugin_Handled; +} + +public int ShowDisclaimer(int cid){ + Handle Disclaimer = CreateMenu(PreDisplayPlayers); + SetMenuTitle(Disclaimer, "Ты согласен с тем что твой репорт на игрока оправдан и несет в себе ценную информацию, иначе тебе могут дать по жопе?"); + AddMenuItem(Disclaimer, "","Согласен?", ITEMDRAW_RAWLINE); + AddMenuItem(Disclaimer, "", "ДА"); + AddMenuItem(Disclaimer, "", "НЕТ"); + DisplayMenu(Disclaimer, cid, MENU_TIME_FOREVER); + return 0; +} + +public int ShowReasonSolution(int cid, int reason_id, const char[] reason){ + strcopy(g_clients_reason[cid], sizeof(g_clients_reason[]), reason); + Handle Solution = CreateMenu(PreDisplayPlayers); + SetMenuTitle(Solution, "Смотри друг на твою проблему есть решение, без учатия модераторов: \n%s\nТы всеравно хочешь отправить репорт?", g_reasons_solution[reason_id]); + int count = 4; + int choice = GetRandomInt(0, count); + for(int i = 0; i <= count; i++){ + if(i == choice) AddMenuItem(Solution, "","ДА"); + else AddMenuItem(Solution, "","НЕТ"); + } + SetMenuExitBackButton(Solution, false); + SetMenuExitButton(Solution, false); + DisplayMenu(Solution, cid, MENU_TIME_FOREVER); +} + +public int PreDisplayPlayers(Handle Disclaimer, MenuAction eAction, int cid, int select){ + switch(eAction){ + case MenuAction_End:CloseHandle(Disclaimer); + case MenuAction_Select:{ + char cmd[32]; + GetMenuItem(Disclaimer, select, cmd, sizeof(cmd)); + ////////////////////////////////////////////////// + if (StrContains(cmd, "") != -1){ + return DisplayPlayers(cid); + } + if (StrContains(cmd, "") != -1){ + //SDKHooks_TakeDamage(cid, cid, cid, 99999999.0); + FakeClientCommand(cid, "explode"); + return 0; + } + if (StrContains(cmd, "") != -1){ + ReportProcessing(cid, g_clients_reason[cid]); + return 0; + } + if (StrContains(cmd, "") != -1){ + g_clients_cooldown[cid] = -1; + return 0; + } + return 0; + } + } + return 0; +} + +public int DisplayReasons(int cid){ + if(strlen(g_reasons[0]) > 0){ + bool HavePermitionReason = false; + Handle ReasonsMenu = CreateMenu(SelectReasonsHandle); + SetMenuExitBackButton(ReasonsMenu, true); + SetMenuExitButton(ReasonsMenu, true); + SetMenuTitle(ReasonsMenu, "Выбери причину:"); + char menu_item[REASON_TEXT_SIZE]; + for (int i = 0; i < 32; i++){ + menu_item[0] = '\0'; + if(strlen(g_reasons[i]) > 0){ + Format(menu_item, sizeof(menu_item), "%i|%s", i, g_reasons[i]); + + if(g_reasons_bitflag[i] != 0){ + if(HavePermitionReason){ + continue; + } + + if(CheckCommandAccess(GetClientOfUserId(g_clients_reported_uid[cid]), "", g_reasons_bitflag[i])){ + AddMenuItem(ReasonsMenu, menu_item, g_reasons[i]); + HavePermitionReason = true; + continue; + } + } else { + AddMenuItem(ReasonsMenu, menu_item, g_reasons[i]); + } + /*if(StrContains(g_reasons[i], "|") != -1){ + if(HavePermitionReason){ + continue; + } + + if(g_reasons_bitflag != 0){ + if(CheckCommandAccess(cid, "", )) + } + //char container[3][256]; + //ExplodeString(g_reasons[i],"|",container, 2, 64); + //int flag = (1<", "Меню"); + AddMenuItem(ReasonsMenu, "", "Своя причина"); + DisplayMenu(ReasonsMenu, cid, MENU_TIME_FOREVER); + return 0; + } else { + SetWaitChatMessage(cid); + return 0; + } + return 0; +} + +public int SelectReasonsHandle(Handle ReasonMenu, MenuAction eAction, int cid, int select){ + switch(eAction){ + case MenuAction_End:CloseHandle(ReasonMenu); + case MenuAction_Select:{ + char reason_and_id[64], reason[64]; + GetMenuItem(ReasonMenu, select, reason_and_id, sizeof(reason_and_id)); + + if(StrContains(reason_and_id, "|") != -1){ + char reason_array[2][64]; + int reason_id = 0; + + ExplodeString(reason_and_id, "|", reason_array, 2, 64); + strcopy(reason, sizeof(reason), reason_array[1]); + reason_id = StringToInt(reason_array[0]); + + if(strlen(g_reasons_solution[reason_id]) > 0){ + ShowReasonSolution(cid, reason_id, reason); + return 0; + } + } else { + strcopy(reason, 64, reason_and_id); + if (StrContains(reason, "") != -1){ + SetWaitChatMessage(cid); + return 0; + } + if (StrContains(reason, "") != -1){ + FakeClientCommand(cid, "sm_menu"); + return 0; + } + } + ReportProcessing(cid, reason); + return 0; + } + } + return 0; +} + +public int DisplayPlayers(int cid){ + Handle ReportMenu = CreateMenu(SelectPlayerHandle); + for (int i; i++ <= MaxClients - 1;) { + //i == cid || + if(!IsClientInGame(i) || IsFakeClient(i)){ + continue; + } + + if(i == cid){ + if(!(GetUserFlagBits(cid) & ADMFLAG_ROOT)){ + continue; + } + } + + char menu_uid[16]; + char menu_name[32]; + + IntToString(GetClientUserId(i), menu_uid, sizeof(menu_uid)); + GetClientName(i, menu_name, sizeof(menu_name)); + + AddMenuItem(ReportMenu, menu_uid, menu_name); + } + /////////////////////////////////////////////////////////////////////////////// + if (GetMenuItemCount(ReportMenu) > 0){ + SetMenuExitBackButton(ReportMenu, false); + SetMenuExitButton(ReportMenu, true); + SetMenuTitle(ReportMenu, "Зарепортить игрока:"); + DisplayMenu(ReportMenu, cid, MENU_TIME_FOREVER); + return 1; + } + + CloseHandle(ReportMenu); + PrintToChat(cid, "Увы! Подходящих игроков не найдено."); + return 0; +} + +// Menu functions +public int SelectPlayerHandle(Handle ReportMenu, MenuAction eAction, int cid, int select){ + switch(eAction){ + case MenuAction_End:CloseHandle(ReportMenu); + case MenuAction_Select:{ + char menu_uid[16]; + GetMenuItem(ReportMenu, select, menu_uid, sizeof(menu_uid)); + + int reported_cid = GetClientOfUserId(StringToInt(menu_uid)); + if(!reported_cid){ + PrintToChat(cid, "Увы! Данный игрок недоступен."); + return; + } + + g_clients_reported_uid[cid] = GetClientUserId(reported_cid); + + DisplayReasons(cid); + } + } +} + +//Say hook +static void SetWaitChatMessage(int cid){ + g_clients_reasons_wait[cid] = true; + PrintToChat(cid, "Напиши в чат, причину жалобы. Если ты не уверен, напиши в чат: !отмена") +} + +public Action SayHook(cid, args){ + if(!cid || !g_clients_reasons_wait[cid]) { + return Plugin_Continue; + } + + if(!(GetClientOfUserId(g_clients_reported_uid[cid]))){ + PrintToChat(cid, "Увы! К написанию жалобы, данный игрок стал недоступен.") + OnClientPutInServer(cid); + return Plugin_Handled; + } + + char Reason[512]; + + if(args == 1){ + GetCmdArg(1, Reason, sizeof(Reason)); + } else { + GetCmdArgString(Reason, sizeof(Reason)); + } + + if (!strcmp(Reason, "!отмена")) { + PrintToChat(cid, "Твоя жалоба была откланена!"); + OnClientPutInServer(cid); + return Plugin_Handled; + } + + if (!strcmp(Reason, "!menu") || !strcmp(Reason, "!MENU") || !strcmp(Reason, "menu") || !strcmp(Reason, "MENU") || !strcmp(Reason, "!меню") || !strcmp(Reason, "!МЕНЮ") || !strcmp(Reason, "меню") || !strcmp(Reason, "МЕНЮ")) { + KickClient(cid, "МЕНЮ БЛЯТЬ ПОШЕЛ НАХУЙ"); + return Plugin_Handled; + } + + if (!strcmp(Reason, "!report")) { + PrintToChat(cid, "Твоя жалоба была откланена, по причине долбаеб."); + OnClientPutInServer(cid); + return Plugin_Handled; + } + + ReportProcessing(cid, Reason); + + return Plugin_Handled; +} + +stock ReportProcessing(int cid, const char[] Reason){ + if (cid == GetClientOfUserId(g_clients_reported_uid[cid])){ + g_clients_reported_uid[cid] = 0; + }else{ + PrintToChat(GetClientOfUserId(g_clients_reported_uid[cid]), "\n\n[REPORT.SYSTEM] На вас составили репорт, ожидайте пока вам дадут пизды!\n\n"); + } + SendReport(Reason, GetClientUserId(cid)); +} + +static void Report_Callback(HTTPResponse response, any value){ + int cid_author = GetClientOfUserId(value); + + if (response.Status > 200 && response.Status < 210){ + PrintToChat(cid_author, "Репорт отправлен!"); + return; + } else { + OnClientPutInServer(cid_author); + PrintToChat(cid_author, "РЕПОРТ НЕ БЫЛ ДОСТАВЛЕН, ПОВТОРИ ПОПЫТКУ ПОЗЖЕ"); + PrintToServer("Failed response! Code: %i", response.Status); + return; + } +} \ No newline at end of file diff --git a/ext/sourcepawn-client/core/globals.sp b/ext/sourcepawn-client/core/globals.sp new file mode 100644 index 0000000..ee00cf6 --- /dev/null +++ b/ext/sourcepawn-client/core/globals.sp @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +/* CONVAR */ +Handle g_server_id_convar = INVALID_HANDLE; +Handle g_api_secret_key_convar = INVALID_HANDLE; +Handle g_api_gateway_convar = INVALID_HANDLE; + +char g_server_id[32]; +char g_secretkey[64]; +char g_gateway[128]; + +char g_cookie[128]; +char g_url[128]; + +bool g_setuped = false; + +stock SetupGlobalConVar() { + g_server_id_convar = CreateConVar("sm_fbi_server_id", "srv8", "fbi server id", FCVAR_PROTECTED); + g_api_secret_key_convar = CreateConVar("sm_fbi_secretkey", "123456789", "fbi secret key", FCVAR_PROTECTED); + g_api_gateway_convar = CreateConVar("sm_fbi_gateway", "http://192.168.3.50:8080/api/server/%s", "fbi gateway", FCVAR_PROTECTED); + // + HookConVarChange(g_server_id_convar, OnServerIdChanged); + HookConVarChange(g_api_secret_key_convar, OnSecretKeyChanged); + HookConVarChange(g_api_gateway_convar, OnGatewayChanged); + // + GetConVarString(g_server_id_convar, g_server_id, sizeof(g_server_id)); + GetConVarString(g_api_secret_key_convar, g_secretkey, sizeof(g_secretkey)); + GetConVarString(g_api_gateway_convar, g_gateway, sizeof(g_gateway)); + // + UpdateUrlData(); +} + +stock UnSetupGlobalConvar() { + UnhookConVarChange(g_server_id_convar, OnServerIdChanged); + UnhookConVarChange(g_api_secret_key_convar, OnSecretKeyChanged); + UnhookConVarChange(g_api_gateway_convar, OnGatewayChanged); +} + +public OnServerIdChanged(Handle:cvar, const String:oldVal[], const String:newVal[]) { + strcopy(g_server_id, sizeof(g_server_id), newVal); + LogMessage("[FBI] Server id now: %s", g_server_id); + UpdateUrlData(); +} +public OnSecretKeyChanged(Handle:cvar, const String:oldVal[], const String:newVal[]) { + strcopy(g_secretkey, sizeof(g_secretkey), newVal); + LogMessage("[FBI] Secret key now lenght: %d", strlen(g_secretkey)); + UpdateUrlData(); +} +public OnGatewayChanged(Handle:cvar, const String:oldVal[], const String:newVal[]) { + strcopy(g_gateway, sizeof(g_gateway), newVal); + LogMessage("[FBI] Gateway now: %s", g_gateway); + UpdateUrlData(); +} + +stock UpdateUrlData(){ + g_setuped = false; + if (strlen(g_server_id)>0 && strlen(g_secretkey)>0){ + Format(g_url, sizeof(g_url), g_gateway, g_server_id); + Format(g_cookie, sizeof(g_cookie), "secretkey=%s", g_secretkey); + g_setuped = true; + LogMessage("[FBI] Successful set URL and SecretKey"); + } else + LogError("[FBI] Failed URL and SecretKey"); +} + + +stock IsValidClient(int client){ + if(client > 4096){ + client = EntRefToEntIndex(client); + } + if(client < 1 || client > MaxClients) return false; + if(!IsClientInGame(client)) return false; + if(IsFakeClient(client)) return false; + return true; +} \ No newline at end of file diff --git a/src/main/java/app/controllers/server/ServerUpdaterController.java b/src/main/java/app/controllers/server/ServerUpdaterController.java index 93f8779..1807b02 100644 --- a/src/main/java/app/controllers/server/ServerUpdaterController.java +++ b/src/main/java/app/controllers/server/ServerUpdaterController.java @@ -65,7 +65,7 @@ public class ServerUpdaterController { @Data public class ReportBody { private String author_steam64; - private String reported_steam64; + private String reported_steam64 = null; private String reason; } }