You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.7 KiB
78 lines
2.7 KiB
#include <ripext>
|
|
#include <sourcemod>
|
|
#include <tf2_stocks>
|
|
#include <tf2>
|
|
|
|
/* 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;
|
|
}
|