Update basebans and SQL admins plugins for transitional syntax (#484)

This commit is contained in:
ErikMinekus 2016-04-27 15:34:22 +02:00 committed by Nicholas Hastings
parent 730a9a4a40
commit fb2117137e
6 changed files with 148 additions and 141 deletions

View File

@ -36,6 +36,8 @@
#include <sourcemod> #include <sourcemod>
#pragma newdecls required
public Plugin myinfo = public Plugin myinfo =
{ {
name = "SQL Admins (Prefetch)", name = "SQL Admins (Prefetch)",

View File

@ -36,6 +36,8 @@
#include <sourcemod> #include <sourcemod>
#pragma newdecls required
public Plugin myinfo = public Plugin myinfo =
{ {
name = "SQL Admins (Threaded)", name = "SQL Admins (Threaded)",

View File

@ -37,7 +37,9 @@
#undef REQUIRE_PLUGIN #undef REQUIRE_PLUGIN
#include <adminmenu> #include <adminmenu>
public Plugin:myinfo = #pragma newdecls required
public Plugin myinfo =
{ {
name = "Basic Ban Commands", name = "Basic Ban Commands",
author = "AlliedModders LLC", author = "AlliedModders LLC",
@ -48,17 +50,17 @@ public Plugin:myinfo =
TopMenu hTopMenu; TopMenu hTopMenu;
new g_BanTarget[MAXPLAYERS+1]; int g_BanTarget[MAXPLAYERS+1];
new g_BanTargetUserId[MAXPLAYERS+1]; int g_BanTargetUserId[MAXPLAYERS+1];
new g_BanTime[MAXPLAYERS+1]; int g_BanTime[MAXPLAYERS+1];
new g_IsWaitingForChatReason[MAXPLAYERS+1]; bool g_IsWaitingForChatReason[MAXPLAYERS+1];
KeyValues g_hKvBanReasons; KeyValues g_hKvBanReasons;
new String:g_BanReasonsPath[PLATFORM_MAX_PATH]; char g_BanReasonsPath[PLATFORM_MAX_PATH];
#include "basebans/ban.sp" #include "basebans/ban.sp"
public OnPluginStart() public void OnPluginStart()
{ {
BuildPath(Path_SM, g_BanReasonsPath, sizeof(g_BanReasonsPath), "configs/banreasons.txt"); BuildPath(Path_SM, g_BanReasonsPath, sizeof(g_BanReasonsPath), "configs/banreasons.txt");
@ -84,18 +86,18 @@ public OnPluginStart()
} }
} }
public OnMapStart() public void OnMapStart()
{ {
//(Re-)Load BanReasons //(Re-)Load BanReasons
LoadBanReasons(); LoadBanReasons();
} }
public OnClientDisconnect(client) public void OnClientDisconnect(int client)
{ {
g_IsWaitingForChatReason[client] = false; g_IsWaitingForChatReason[client] = false;
} }
LoadBanReasons() void LoadBanReasons()
{ {
delete g_hKvBanReasons; delete g_hKvBanReasons;
@ -124,7 +126,7 @@ LoadBanReasons()
} }
} }
public OnAdminMenuReady(Handle aTopMenu) public void OnAdminMenuReady(Handle aTopMenu)
{ {
TopMenu topmenu = TopMenu.FromHandle(aTopMenu); TopMenu topmenu = TopMenu.FromHandle(aTopMenu);
@ -138,7 +140,7 @@ public OnAdminMenuReady(Handle aTopMenu)
hTopMenu = topmenu; hTopMenu = topmenu;
/* Find the "Player Commands" category */ /* Find the "Player Commands" category */
new TopMenuObject:player_commands = hTopMenu.FindCategory(ADMINMENU_PLAYERCOMMANDS); TopMenuObject player_commands = hTopMenu.FindCategory(ADMINMENU_PLAYERCOMMANDS);
if (player_commands != INVALID_TOPMENUOBJECT) if (player_commands != INVALID_TOPMENUOBJECT)
{ {
@ -146,7 +148,7 @@ public OnAdminMenuReady(Handle aTopMenu)
} }
} }
public Action:Command_BanIp(client, args) public Action Command_BanIp(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@ -154,9 +156,9 @@ public Action:Command_BanIp(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
decl len, next_len; int len, next_len;
decl String:Arguments[256]; char Arguments[256];
decl String:arg[50], String:time[20]; char arg[50], time[20];
GetCmdArgString(Arguments, sizeof(Arguments)); GetCmdArgString(Arguments, sizeof(Arguments));
len = BreakString(Arguments, arg, sizeof(arg)); len = BreakString(Arguments, arg, sizeof(arg));
@ -177,9 +179,10 @@ public Action:Command_BanIp(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
decl String:target_name[MAX_TARGET_LENGTH]; char target_name[MAX_TARGET_LENGTH];
decl target_list[1], bool:tn_is_ml; int target_list[1];
new found_client = -1; bool tn_is_ml;
int found_client = -1;
if (ProcessTargetString( if (ProcessTargetString(
arg, arg,
@ -194,7 +197,7 @@ public Action:Command_BanIp(client, args)
found_client = target_list[0]; found_client = target_list[0];
} }
new bool:has_rcon; bool has_rcon;
if (client == 0 || (client == 1 && !IsDedicatedServer())) if (client == 0 || (client == 1 && !IsDedicatedServer()))
{ {
@ -202,11 +205,11 @@ public Action:Command_BanIp(client, args)
} }
else else
{ {
new AdminId:id = GetUserAdmin(client); AdminId id = GetUserAdmin(client);
has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON); has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
} }
new hit_client = -1; int hit_client = -1;
if (found_client != -1 if (found_client != -1
&& !IsFakeClient(found_client) && !IsFakeClient(found_client)
&& (has_rcon || CanUserTarget(client, found_client))) && (has_rcon || CanUserTarget(client, found_client)))
@ -221,7 +224,7 @@ public Action:Command_BanIp(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
new minutes = StringToInt(time); int minutes = StringToInt(time);
LogAction(client, LogAction(client,
hit_client, hit_client,
@ -248,7 +251,7 @@ public Action:Command_BanIp(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_AddBan(client, args) public Action Command_AddBan(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@ -256,13 +259,13 @@ public Action:Command_AddBan(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
decl String:arg_string[256]; char arg_string[256];
new String:time[50]; char time[50];
new String:authid[50]; char authid[50];
GetCmdArgString(arg_string, sizeof(arg_string)); GetCmdArgString(arg_string, sizeof(arg_string));
new len, total_len; int len, total_len;
/* Get time */ /* Get time */
if ((len = BreakString(arg_string, time, sizeof(time))) == -1) if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
@ -284,7 +287,7 @@ public Action:Command_AddBan(client, args)
} }
/* Verify steamid */ /* Verify steamid */
new bool:idValid = false; bool idValid = false;
if (!strncmp(authid, "STEAM_", 6) && authid[7] == ':') if (!strncmp(authid, "STEAM_", 6) && authid[7] == ':')
idValid = true; idValid = true;
else if (!strncmp(authid, "[U:", 3)) else if (!strncmp(authid, "[U:", 3))
@ -296,7 +299,7 @@ public Action:Command_AddBan(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
new minutes = StringToInt(time); int minutes = StringToInt(time);
LogAction(client, LogAction(client,
-1, -1,
@ -317,7 +320,7 @@ public Action:Command_AddBan(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_Unban(client, args) public Action Command_Unban(int client, int args)
{ {
if (args < 1) if (args < 1)
{ {
@ -325,12 +328,12 @@ public Action:Command_Unban(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
decl String:arg[50]; char arg[50];
GetCmdArgString(arg, sizeof(arg)); GetCmdArgString(arg, sizeof(arg));
ReplaceString(arg, sizeof(arg), "\"", ""); ReplaceString(arg, sizeof(arg), "\"", "");
new ban_flags; int ban_flags;
if (IsCharNumeric(arg[0])) if (IsCharNumeric(arg[0]))
{ {
ban_flags |= BANFLAG_IP; ban_flags |= BANFLAG_IP;
@ -348,7 +351,7 @@ public Action:Command_Unban(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_AbortBan(client, args) public Action Command_AbortBan(int client, int args)
{ {
if(!CheckCommandAccess(client, "sm_ban", ADMFLAG_BAN)) if(!CheckCommandAccess(client, "sm_ban", ADMFLAG_BAN))
{ {
@ -368,7 +371,7 @@ public Action:Command_AbortBan(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[]) public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
{ {
if(g_IsWaitingForChatReason[client]) if(g_IsWaitingForChatReason[client])
{ {

View File

@ -31,9 +31,9 @@
* Version: $Id$ * Version: $Id$
*/ */
PrepareBan(client, target, time, const String:reason[]) void PrepareBan(int client, int target, int time, const char[] reason)
{ {
new originalTarget = GetClientOfUserId(g_BanTargetUserId[client]); int originalTarget = GetClientOfUserId(g_BanTargetUserId[client]);
if (originalTarget != target) if (originalTarget != target)
{ {
@ -49,7 +49,7 @@ PrepareBan(client, target, time, const String:reason[])
return; return;
} }
new String:name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
GetClientName(target, name, sizeof(name)); GetClientName(target, name, sizeof(name));
if (!time) if (!time)
@ -81,11 +81,11 @@ PrepareBan(client, target, time, const String:reason[])
} }
} }
DisplayBanTargetMenu(client) void DisplayBanTargetMenu(int client)
{ {
Menu menu = CreateMenu(MenuHandler_BanPlayerList); Menu menu = new Menu(MenuHandler_BanPlayerList);
decl String:title[100]; char title[100];
Format(title, sizeof(title), "%T:", "Ban player", client); Format(title, sizeof(title), "%T:", "Ban player", client);
menu.SetTitle(title); menu.SetTitle(title);
menu.ExitBackButton = true; menu.ExitBackButton = true;
@ -95,11 +95,11 @@ DisplayBanTargetMenu(client)
menu.Display(client, MENU_TIME_FOREVER); menu.Display(client, MENU_TIME_FOREVER);
} }
DisplayBanTimeMenu(client) void DisplayBanTimeMenu(int client)
{ {
Menu menu = CreateMenu(MenuHandler_BanTimeList); Menu menu = new Menu(MenuHandler_BanTimeList);
decl String:title[100]; char title[100];
Format(title, sizeof(title), "%T: %N", "Ban player", client, g_BanTarget[client]); Format(title, sizeof(title), "%T: %N", "Ban player", client, g_BanTarget[client]);
menu.SetTitle(title); menu.SetTitle(title);
menu.ExitBackButton = true; menu.ExitBackButton = true;
@ -115,11 +115,11 @@ DisplayBanTimeMenu(client)
menu.Display(client, MENU_TIME_FOREVER); menu.Display(client, MENU_TIME_FOREVER);
} }
DisplayBanReasonMenu(client) void DisplayBanReasonMenu(int client)
{ {
Menu menu = CreateMenu(MenuHandler_BanReasonList); Menu menu = new Menu(MenuHandler_BanReasonList);
decl String:title[100]; char title[100];
Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]); Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]);
menu.SetTitle(title); menu.SetTitle(title);
menu.ExitBackButton = true; menu.ExitBackButton = true;
@ -128,8 +128,8 @@ DisplayBanReasonMenu(client)
menu.AddItem("", "Custom reason (type in chat)"); menu.AddItem("", "Custom reason (type in chat)");
//Loading configurable entries from the kv-file //Loading configurable entries from the kv-file
decl String:reasonName[100]; char reasonName[100];
decl String:reasonFull[255]; char reasonFull[255];
//Iterate through the kv-file //Iterate through the kv-file
g_hKvBanReasons.GotoFirstSubKey(false); g_hKvBanReasons.GotoFirstSubKey(false);
@ -149,12 +149,12 @@ DisplayBanReasonMenu(client)
menu.Display(client, MENU_TIME_FOREVER); menu.Display(client, MENU_TIME_FOREVER);
} }
public AdminMenu_Ban(Handle:topmenu, public void AdminMenu_Ban(Handle topmenu,
TopMenuAction:action, TopMenuAction action,
TopMenuObject:object_id, TopMenuObject object_id,
param, int param,
String:buffer[], char[] buffer,
maxlength) int maxlength)
{ {
//Reset chat reason first //Reset chat reason first
g_IsWaitingForChatReason[param] = false; g_IsWaitingForChatReason[param] = false;
@ -169,7 +169,7 @@ public AdminMenu_Ban(Handle:topmenu,
} }
} }
public MenuHandler_BanReasonList(Menu menu, MenuAction action, int param1, int param2) public int MenuHandler_BanReasonList(Menu menu, MenuAction action, int param1, int param2)
{ {
if (action == MenuAction_End) if (action == MenuAction_End)
{ {
@ -192,7 +192,7 @@ public MenuHandler_BanReasonList(Menu menu, MenuAction action, int param1, int p
} }
else else
{ {
decl String:info[64]; char info[64];
menu.GetItem(param2, info, sizeof(info)); menu.GetItem(param2, info, sizeof(info));
@ -201,7 +201,7 @@ public MenuHandler_BanReasonList(Menu menu, MenuAction action, int param1, int p
} }
} }
public MenuHandler_BanPlayerList(Menu menu, MenuAction action, int param1, int param2) public int MenuHandler_BanPlayerList(Menu menu, MenuAction action, int param1, int param2)
{ {
if (action == MenuAction_End) if (action == MenuAction_End)
{ {
@ -216,8 +216,8 @@ public MenuHandler_BanPlayerList(Menu menu, MenuAction action, int param1, int p
} }
else if (action == MenuAction_Select) else if (action == MenuAction_Select)
{ {
decl String:info[32], String:name[32]; char info[32], name[32];
new userid, target; int userid, target;
menu.GetItem(param2, info, sizeof(info), _, name, sizeof(name)); menu.GetItem(param2, info, sizeof(info), _, name, sizeof(name));
userid = StringToInt(info); userid = StringToInt(info);
@ -239,7 +239,7 @@ public MenuHandler_BanPlayerList(Menu menu, MenuAction action, int param1, int p
} }
} }
public MenuHandler_BanTimeList(Menu menu, MenuAction action, int param1, int param2) public int MenuHandler_BanTimeList(Menu menu, MenuAction action, int param1, int param2)
{ {
if (action == MenuAction_End) if (action == MenuAction_End)
{ {
@ -254,7 +254,7 @@ public MenuHandler_BanTimeList(Menu menu, MenuAction action, int param1, int par
} }
else if (action == MenuAction_Select) else if (action == MenuAction_Select)
{ {
decl String:info[32]; char info[32];
menu.GetItem(param2, info, sizeof(info)); menu.GetItem(param2, info, sizeof(info));
g_BanTime[param1] = StringToInt(info); g_BanTime[param1] = StringToInt(info);
@ -264,7 +264,7 @@ public MenuHandler_BanTimeList(Menu menu, MenuAction action, int param1, int par
} }
public Action:Command_Ban(client, args) public Action Command_Ban(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@ -272,20 +272,20 @@ public Action:Command_Ban(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
decl len, next_len; int len, next_len;
decl String:Arguments[256]; char Arguments[256];
GetCmdArgString(Arguments, sizeof(Arguments)); GetCmdArgString(Arguments, sizeof(Arguments));
decl String:arg[65]; char arg[65];
len = BreakString(Arguments, arg, sizeof(arg)); len = BreakString(Arguments, arg, sizeof(arg));
new target = FindTarget(client, arg, true); int target = FindTarget(client, arg, true);
if (target == -1) if (target == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
decl String:s_time[12]; char s_time[12];
if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1) if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
{ {
len += next_len; len += next_len;
@ -296,7 +296,7 @@ public Action:Command_Ban(client, args)
Arguments[0] = '\0'; Arguments[0] = '\0';
} }
new time = StringToInt(s_time); int time = StringToInt(s_time);
g_BanTargetUserId[client] = GetClientUserId(target); g_BanTargetUserId[client] = GetClientUserId(target);

View File

@ -54,13 +54,13 @@
* @return Plugin_Handled to block the actual server banning. * @return Plugin_Handled to block the actual server banning.
* Kicking will still occur. * Kicking will still occur.
*/ */
forward Action:OnBanClient(client, forward Action OnBanClient(int client,
time, int time,
flags, int flags,
const String:reason[], const char[] reason,
const String:kick_message[], const char[] kick_message,
const String:command[], const char[] command,
any:source); any source);
/** /**
* Called for calls to BanIdentity() with a non-empty command. * Called for calls to BanIdentity() with a non-empty command.
@ -73,12 +73,12 @@ forward Action:OnBanClient(client,
* @param source Source value passed via BanIdentity(). * @param source Source value passed via BanIdentity().
* @return Plugin_Handled to block the actual server banning. * @return Plugin_Handled to block the actual server banning.
*/ */
forward Action:OnBanIdentity(const String:identity[], forward Action OnBanIdentity(const char[] identity,
time, int time,
flags, int flags,
const String:reason[], const char[] reason,
const String:command[], const char[] command,
any:source); any source);
/** /**
* Called for calls to RemoveBan() with a non-empty command. * Called for calls to RemoveBan() with a non-empty command.
@ -89,10 +89,10 @@ forward Action:OnBanIdentity(const String:identity[],
* @param source Source value passed via BanIdentity(). * @param source Source value passed via BanIdentity().
* @return Plugin_Handled to block the actual server banning. * @return Plugin_Handled to block the actual server banning.
*/ */
forward Action:OnRemoveBan(const String:identity[], forward Action OnRemoveBan(const char[] identity,
flags, int flags,
const String:command[], const char[] command,
any:source); any source);
/** /**
* Bans a client. * Bans a client.
@ -111,13 +111,13 @@ forward Action:OnRemoveBan(const String:identity[],
* @return True on success, false on failure. * @return True on success, false on failure.
* @error Invalid client index or client not in game. * @error Invalid client index or client not in game.
*/ */
native bool:BanClient(client, native bool BanClient(int client,
time, int time,
flags, int flags,
const String:reason[], const char[] reason,
const String:kick_message[]="", const char[] kick_message="",
const String:command[]="", const char[] command="",
any:source=0); any source=0);
/** /**
* Bans an identity (either an IP address or auth string). * Bans an identity (either an IP address or auth string).
@ -132,12 +132,12 @@ native bool:BanClient(client,
* index of any sort (not actually checked by Core). * index of any sort (not actually checked by Core).
* @return True on success, false on failure. * @return True on success, false on failure.
*/ */
native bool:BanIdentity(const String:identity[], native bool BanIdentity(const char[] identity,
time, int time,
flags, int flags,
const String:reason[], const char[] reason,
const String:command[]="", const char[] command="",
any:source=0); any source=0);
/** /**
* Removes a ban that was written to the server (either in memory or on disk). * Removes a ban that was written to the server (either in memory or on disk).
@ -150,8 +150,7 @@ native bool:BanIdentity(const String:identity[],
* index of any sort (not actually checked by Core). * index of any sort (not actually checked by Core).
* @return True on success, false on failure. * @return True on success, false on failure.
*/ */
native bool:RemoveBan(const String:identity[], native bool RemoveBan(const char[] identity,
flags, int flags,
const String:command[]="", const char[] command="",
any:source=0); any source=0);

View File

@ -36,12 +36,14 @@
#include <sourcemod> #include <sourcemod>
#pragma newdecls required
#define CURRENT_SCHEMA_VERSION 1409 #define CURRENT_SCHEMA_VERSION 1409
#define SCHEMA_UPGRADE_1 1409 #define SCHEMA_UPGRADE_1 1409
new current_version[4] = {1, 0, 0, CURRENT_SCHEMA_VERSION}; int current_version[4] = {1, 0, 0, CURRENT_SCHEMA_VERSION};
public Plugin:myinfo = public Plugin myinfo =
{ {
name = "SQL Admin Manager", name = "SQL Admin Manager",
author = "AlliedModders LLC", author = "AlliedModders LLC",
@ -50,7 +52,7 @@ public Plugin:myinfo =
url = "http://www.sourcemod.net/" url = "http://www.sourcemod.net/"
}; };
public OnPluginStart() public void OnPluginStart()
{ {
LoadTranslations("common.phrases"); LoadTranslations("common.phrases");
LoadTranslations("sqladmins.phrases"); LoadTranslations("sqladmins.phrases");
@ -84,9 +86,9 @@ Database Connect()
return db; return db;
} }
CreateMySQL(client, Handle:db) void CreateMySQL(int client, Database db)
{ {
new String:queries[7][] = char queries[7][] =
{ {
"CREATE TABLE sm_admins (id int(10) unsigned NOT NULL auto_increment, authtype enum('steam','name','ip') NOT NULL, identity varchar(65) NOT NULL, password varchar(65), flags varchar(30) NOT NULL, name varchar(65) NOT NULL, immunity int(10) unsigned NOT NULL, PRIMARY KEY (id))", "CREATE TABLE sm_admins (id int(10) unsigned NOT NULL auto_increment, authtype enum('steam','name','ip') NOT NULL, identity varchar(65) NOT NULL, password varchar(65), flags varchar(30) NOT NULL, name varchar(65) NOT NULL, immunity int(10) unsigned NOT NULL, PRIMARY KEY (id))",
"CREATE TABLE sm_groups (id int(10) unsigned NOT NULL auto_increment, flags varchar(30) NOT NULL, name varchar(120) NOT NULL, immunity_level int(1) unsigned NOT NULL, PRIMARY KEY (id))", "CREATE TABLE sm_groups (id int(10) unsigned NOT NULL auto_increment, flags varchar(30) NOT NULL, name varchar(120) NOT NULL, immunity_level int(1) unsigned NOT NULL, PRIMARY KEY (id))",
@ -97,7 +99,7 @@ CreateMySQL(client, Handle:db)
"CREATE TABLE IF NOT EXISTS sm_config (cfg_key varchar(32) NOT NULL, cfg_value varchar(255) NOT NULL, PRIMARY KEY (cfg_key))" "CREATE TABLE IF NOT EXISTS sm_config (cfg_key varchar(32) NOT NULL, cfg_value varchar(255) NOT NULL, PRIMARY KEY (cfg_key))"
}; };
for (new i = 0; i < 7; i++) for (int i = 0; i < 7; i++)
{ {
if (!DoQuery(client, db, queries[i])) if (!DoQuery(client, db, queries[i]))
{ {
@ -105,7 +107,7 @@ CreateMySQL(client, Handle:db)
} }
} }
decl String:query[256]; char query[256];
Format(query, Format(query,
sizeof(query), sizeof(query),
"INSERT INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.%d') ON DUPLICATE KEY UPDATE cfg_value = '1.0.0.%d'", "INSERT INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.%d') ON DUPLICATE KEY UPDATE cfg_value = '1.0.0.%d'",
@ -120,9 +122,9 @@ CreateMySQL(client, Handle:db)
ReplyToCommand(client, "[SM] Admin tables have been created."); ReplyToCommand(client, "[SM] Admin tables have been created.");
} }
CreateSQLite(client, Handle:db) void CreateSQLite(int client, Database db)
{ {
new String:queries[7][] = char queries[7][] =
{ {
"CREATE TABLE sm_admins (id INTEGER PRIMARY KEY AUTOINCREMENT, authtype varchar(16) NOT NULL CHECK(authtype IN ('steam', 'ip', 'name')), identity varchar(65) NOT NULL, password varchar(65), flags varchar(30) NOT NULL, name varchar(65) NOT NULL, immunity INTEGER NOT NULL)", "CREATE TABLE sm_admins (id INTEGER PRIMARY KEY AUTOINCREMENT, authtype varchar(16) NOT NULL CHECK(authtype IN ('steam', 'ip', 'name')), identity varchar(65) NOT NULL, password varchar(65), flags varchar(30) NOT NULL, name varchar(65) NOT NULL, immunity INTEGER NOT NULL)",
"CREATE TABLE sm_groups (id INTEGER PRIMARY KEY AUTOINCREMENT, flags varchar(30) NOT NULL, name varchar(120) NOT NULL, immunity_level INTEGER NOT NULL)", "CREATE TABLE sm_groups (id INTEGER PRIMARY KEY AUTOINCREMENT, flags varchar(30) NOT NULL, name varchar(120) NOT NULL, immunity_level INTEGER NOT NULL)",
@ -133,7 +135,7 @@ CreateSQLite(client, Handle:db)
"CREATE TABLE IF NOT EXISTS sm_config (cfg_key varchar(32) NOT NULL, cfg_value varchar(255) NOT NULL, PRIMARY KEY (cfg_key))" "CREATE TABLE IF NOT EXISTS sm_config (cfg_key varchar(32) NOT NULL, cfg_value varchar(255) NOT NULL, PRIMARY KEY (cfg_key))"
}; };
for (new i = 0; i < 7; i++) for (int i = 0; i < 7; i++)
{ {
if (!DoQuery(client, db, queries[i])) if (!DoQuery(client, db, queries[i]))
{ {
@ -141,7 +143,7 @@ CreateSQLite(client, Handle:db)
} }
} }
decl String:query[256]; char query[256];
Format(query, Format(query,
sizeof(query), sizeof(query),
"REPLACE INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.%d')", "REPLACE INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.%d')",
@ -155,7 +157,7 @@ CreateSQLite(client, Handle:db)
ReplyToCommand(client, "[SM] Admin tables have been created."); ReplyToCommand(client, "[SM] Admin tables have been created.");
} }
public Action:Command_CreateTables(args) public Action Command_CreateTables(int args)
{ {
int client = 0; int client = 0;
Database db = Connect(); Database db = Connect();
@ -182,7 +184,7 @@ public Action:Command_CreateTables(args)
return Plugin_Handled; return Plugin_Handled;
} }
bool:GetUpdateVersion(client, Handle:db, versions[4]) bool GetUpdateVersion(int client, Database db, int versions[4])
{ {
char query[256]; char query[256];
DBResultSet rs; DBResultSet rs;
@ -201,7 +203,7 @@ bool:GetUpdateVersion(client, Handle:db, versions[4])
char version_numbers[4][12]; char version_numbers[4][12];
if (ExplodeString(version_string, ".", version_numbers, 4, 12) == 4) if (ExplodeString(version_string, ".", version_numbers, 4, 12) == 4)
{ {
for (new i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
versions[i] = StringToInt(version_numbers[i]); versions[i] = StringToInt(version_numbers[i]);
} }
@ -226,7 +228,7 @@ bool:GetUpdateVersion(client, Handle:db, versions[4])
return true; return true;
} }
UpdateSQLite(client, Database db) void UpdateSQLite(int client, Database db)
{ {
char query[512]; char query[512];
DBResultSet rs; DBResultSet rs;
@ -242,7 +244,7 @@ UpdateSQLite(client, Database db)
delete rs; delete rs;
new versions[4]; int versions[4];
if (found) if (found)
{ {
if (!GetUpdateVersion(client, db, versions)) if (!GetUpdateVersion(client, db, versions))
@ -268,7 +270,7 @@ UpdateSQLite(client, Database db)
"CREATE TABLE IF NOT EXISTS sm_config (cfg_key varchar(32) NOT NULL, cfg_value varchar(255) NOT NULL, PRIMARY KEY (cfg_key))" "CREATE TABLE IF NOT EXISTS sm_config (cfg_key varchar(32) NOT NULL, cfg_value varchar(255) NOT NULL, PRIMARY KEY (cfg_key))"
}; };
for (new i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
if (!DoQuery(client, db, queries[i])) if (!DoQuery(client, db, queries[i]))
{ {
@ -292,7 +294,7 @@ UpdateSQLite(client, Database db)
ReplyToCommand(client, "[SM] Your tables are now up to date."); ReplyToCommand(client, "[SM] Your tables are now up to date.");
} }
UpdateMySQL(client, Database db) void UpdateMySQL(int client, Database db)
{ {
char query[512]; char query[512];
DBResultSet rs; DBResultSet rs;
@ -316,7 +318,7 @@ UpdateMySQL(client, Database db)
} }
delete rs; delete rs;
new versions[4]; int versions[4];
if (found && !GetUpdateVersion(client, db, versions)) if (found && !GetUpdateVersion(client, db, versions))
{ {
@ -338,7 +340,7 @@ UpdateMySQL(client, Database db)
"ALTER TABLE sm_groups DROP immunity" "ALTER TABLE sm_groups DROP immunity"
}; };
for (new i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
if (!DoQuery(client, db, queries[i])) if (!DoQuery(client, db, queries[i]))
{ {
@ -361,9 +363,9 @@ UpdateMySQL(client, Database db)
ReplyToCommand(client, "[SM] Your tables are now up to date."); ReplyToCommand(client, "[SM] Your tables are now up to date.");
} }
public Action:Command_UpdateTables(args) public Action Command_UpdateTables(int args)
{ {
new client = 0; int client = 0;
Database db = Connect(); Database db = Connect();
if (db == null) if (db == null)
{ {
@ -388,7 +390,7 @@ public Action:Command_UpdateTables(args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_SetAdminGroups(client, args) public Action Command_SetAdminGroups(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@ -481,7 +483,7 @@ public Action:Command_SetAdminGroups(client, args)
char name[80]; char name[80];
int inherit_order = 0; int inherit_order = 0;
for (new i=3; i<=args; i++) for (int i=3; i<=args; i++)
{ {
GetCmdArg(i, name, sizeof(name)); GetCmdArg(i, name, sizeof(name));
@ -490,7 +492,7 @@ public Action:Command_SetAdminGroups(client, args)
{ {
ReplyToCommand(client, "[SM] %t", "SQL Group X not found", name); ReplyToCommand(client, "[SM] %t", "SQL Group X not found", name);
} else { } else {
new gid = SQL_FetchInt(hFindQuery, 0); int gid = SQL_FetchInt(hFindQuery, 0);
hAddQuery.BindInt(0, gid); hAddQuery.BindInt(0, gid);
hAddQuery.BindInt(1, ++inherit_order); hAddQuery.BindInt(1, ++inherit_order);
@ -516,7 +518,7 @@ public Action:Command_SetAdminGroups(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_DelGroup(client, args) public Action Command_DelGroup(int client, int args)
{ {
if (args < 1) if (args < 1)
{ {
@ -600,7 +602,7 @@ public Action:Command_DelGroup(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_AddGroup(client, args) public Action Command_AddGroup(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@ -608,10 +610,10 @@ public Action:Command_AddGroup(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
new immunity; int immunity;
if (args >= 3) if (args >= 3)
{ {
new String:arg3[32]; char arg3[32];
GetCmdArg(3, arg3, sizeof(arg3)); GetCmdArg(3, arg3, sizeof(arg3));
if (!StringToIntEx(arg3, immunity)) if (!StringToIntEx(arg3, immunity))
{ {
@ -673,7 +675,7 @@ public Action:Command_AddGroup(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_DelAdmin(client, args) public Action Command_DelAdmin(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@ -751,7 +753,7 @@ public Action:Command_DelAdmin(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_AddAdmin(client, args) public Action Command_AddAdmin(int client, int args)
{ {
if (args < 4) if (args < 4)
{ {
@ -854,11 +856,11 @@ public Action:Command_AddAdmin(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
stock bool:DoQuery(client, Handle:db, const String:query[]) stock bool DoQuery(int client, Database db, const char[] query)
{ {
if (!SQL_FastQuery(db, query)) if (!SQL_FastQuery(db, query))
{ {
decl String:error[255]; char error[255];
SQL_GetError(db, error, sizeof(error)); SQL_GetError(db, error, sizeof(error));
LogError("Query failed: %s", error); LogError("Query failed: %s", error);
LogError("Query dump: %s", query); LogError("Query dump: %s", query);
@ -869,9 +871,9 @@ stock bool:DoQuery(client, Handle:db, const String:query[])
return true; return true;
} }
stock Action:DoError(client, Handle:db, const String:query[], const String:msg[]) stock Action DoError(int client, Database db, const char[] query, const char[] msg)
{ {
decl String:error[255]; char error[255];
SQL_GetError(db, error, sizeof(error)); SQL_GetError(db, error, sizeof(error));
LogError("%s: %s", msg, error); LogError("%s: %s", msg, error);
LogError("Query dump: %s", query); LogError("Query dump: %s", query);
@ -880,7 +882,7 @@ stock Action:DoError(client, Handle:db, const String:query[], const String:msg[]
return Plugin_Handled; return Plugin_Handled;
} }
stock Action:DoStmtError(client, Handle:db, const String:query[], const String:error[], const String:msg[]) stock Action DoStmtError(int client, Database db, const char[] query, const char[] error, const char[] msg)
{ {
LogError("%s: %s", msg, error); LogError("%s: %s", msg, error);
LogError("Query dump: %s", query); LogError("Query dump: %s", query);
@ -888,4 +890,3 @@ stock Action:DoStmtError(client, Handle:db, const String:query[], const String:e
ReplyToCommand(client, "[SM] %t", "Failed to query database"); ReplyToCommand(client, "[SM] %t", "Failed to query database");
return Plugin_Handled; return Plugin_Handled;
} }