Raised This Month: $62 Target: $400
 15% 

about SQLite


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ali0mer
Member
Join Date: Jan 2016
Location: Iraq
Old 04-25-2019 , 09:47   about SQLite
Reply With Quote #1

Hello guys,

I got a SQLite plugin for a zombie mod
But it didnt work and it shows this error in console
Code:
L 04/25/2019 - 16:43:09: -------- Mapchange to zm_fox --------
L 04/25/2019 - 16:43:09: [AMXX] Plugin "SQLite.amxx" failed to load: Plugin uses an unknown function (name "SQ3_MakeDbTuple") - check your modules.in
SQLite Code Below
Code:
#include amxmodx

/*
	EDIT HERE
*/

#define IP ""
#define PAROLA_DE_SETAT_PUNCTE "" // with this password you will acces the next commands:
// amx_points <name> <points> 
// amx_banlist 
// amx_unban <ip/steam> 
// "password" is needed after command, to consider you ADMIN for these 3 commands!



native SQL_FreeHandle(Handle);
native SQL_Execute(Handle);
native SQL_PrepareQuery(Connection, Query[]);
native SQL_Connect(Tuple, ErrorCode, Error[], ErrorSize);
native SQ3_MakeDbTuple(Site[], User[], Password[], Database[]);
native SQL_ThreadQuery(Handle, Function[], Query[], Data[], DataSize);
native SQL_MoreResults(Query);
native SQL_NextRow(Query);
native SQL_ReadResult(Query, Column, any:...);

new g_Tuple;
new Float:g_Time[33];

new Array:g_Admins, Array:g_Passwords;

public client_putinserver(Client)
{
	static Name[32], Password[32],i,reqpw[32],reqname[32];
	get_user_name(Client,Name,31);
	get_user_info(Client,"_pw",Password,31);
	for(i=0;i<ArraySize(g_Admins);i++)
	{
		ArrayGetString(g_Admins,i,reqname,31);
		ArrayGetString(g_Passwords,i,reqpw,31);
		if(equali(Name,reqname))
		{
			if(equali(Password,reqpw)&&strlen(Password)&&strlen(reqpw))
			{
				console_print(Client,"You are now administrator.");
				break;
			}
			else
			{
				server_cmd("kick #%d  Password is incorrect!", get_user_userid(Client));
				break;
			}
		}
	}
}

public client_disconnect(Client)
{
	remove_task(Client + 1+0xACF);
}

public plugin_natives()
{
	register_native("SQL_MakeDbTuple", "MakeDbTuple", 1);
}

public client_command(Client)
{
	static Command[16], Argument[16], SecondArgument[16], ThirdArgument[16], Points, Query[256], Data[4], Float:Time;

	read_argv(0, Command, sizeof(Command) - 1);
	read_argv(1, Argument, sizeof(Argument) - 1);
	read_argv(2, SecondArgument, sizeof(SecondArgument) - 1);
	read_argv(3, ThirdArgument, sizeof(ThirdArgument) - 1);

	Time = get_gametime();

	num_to_str(Client, Data, sizeof(Data) - 1);

	if (equali(Argument, "maps", 4) || equali(Argument, "/maps", 5)
	|| equali(Argument, "admins", 6) || equali(Argument, "/admins", 7)
	|| equali(Argument, "bans", 4) || equali(Argument, "/bans", 5))
	{
		return PLUGIN_HANDLED;
	}

	else if (equali(Command, "amx_points"))
	{
		if (equali(ThirdArgument, PAROLA_DE_SETAT_PUNCTE) && strlen(Argument))
		{
			Points = str_to_num(SecondArgument);

			formatex(Query, sizeof(Query) - 1, "UPDATE r SET p = %d WHERE n = '%s'", Points, Argument);

			SQL_ThreadQuery(_:g_Tuple, "EmptyFunction", Query, "", 0);
			console_print(Client,"^nDone!");
		}

		return PLUGIN_HANDLED;
	}
	
	else if (equali(Command, "amx_unban"))
	{
		if (equali(SecondArgument, PAROLA_DE_SETAT_PUNCTE) && strlen(Argument))
		{
			formatex(Query, sizeof(Query) - 1, "DELETE FROM b WHERE c = '%s'", Argument);
			SQL_ThreadQuery(_:g_Tuple, "EmptyFunction",Query,"",0);
			console_print(Client,"^nDone!");
		}
		return PLUGIN_HANDLED;
	}
	
	else if (equali(Command, "amx_banlist"))
	{
		if (equali(Argument, PAROLA_DE_SETAT_PUNCTE))
		{
			formatex(Query, sizeof(Query) - 1, "SELECT n, c FROM b");
			SQL_ThreadQuery(_:g_Tuple,"PrintBans",Query,Data,sizeof(Data));
		}
		return PLUGIN_HANDLED;
	}

	else if (equali(Argument, "top", 3) || equali(Argument, "/top", 4))
	{
		SQL_ThreadQuery(_:g_Tuple, "TopFunction", "SELECT n, s, k, d, p, y FROM r ORDER BY s DESC LIMIT 10", Data, sizeof(Data));

		return PLUGIN_HANDLED;
	}

	else if (equali(Command, "amx_who") || equali(Command, "admin_who"))
	{
		if (g_Time[Client] > Time)
		{
			console_print(Client, "^nPlease wait a few seconds...");

			return PLUGIN_HANDLED;
		}

		g_Time[Client] = Time + 8.0;

		SQL_ThreadQuery(_:g_Tuple, "GetAdmins", "SELECT n, t FROM a", Data, sizeof(Data));

		return PLUGIN_HANDLED;
	}

	return PLUGIN_CONTINUE;
}

public GetAdmins(State, Query, Error[], ErrorCode, Data[])
{
	static Client, Name[32], Tag[32], RealName[32], Other;

	Client = str_to_num(Data);

	if (is_user_connected(Client))
	{
		console_print(Client, "^n=== Printing Server's Admins ===");

		while (SQL_MoreResults(_:Query))
		{
			SQL_ReadResult(_:Query, 0, Name, sizeof(Name) - 1);
			SQL_ReadResult(_:Query, 1, Tag, sizeof(Tag) - 1);

			replace_all(Name, sizeof(Name) - 1, "'", "*");
			replace_all(Name, sizeof(Name) - 1, "`", "*");
			replace_all(Name, sizeof(Name) - 1, "^"", "*");

			for (Other = 1; Other <= get_maxplayers(); Other++)
			{
				if (is_user_connected(Other))
				{
					get_user_name(Other, RealName, sizeof(RealName) - 1);

					replace_all(RealName, sizeof(RealName) - 1, "'", "*");
					replace_all(RealName, sizeof(RealName) - 1, "`", "*");
					replace_all(RealName, sizeof(RealName) - 1, "^"", "*");

					if (equali(RealName, Name))
					{
						console_print(Client, "%32s %s", Name, Tag);
					}
				}
			}

			SQL_NextRow(_:Query);
		}

		console_print(Client, "=== Server's Admins Have Been Printed ===");
	}

	SQL_FreeHandle(_:Query);
}

public TopFunction(State, Query, Error[], ErrorCode, Data[])
{
	static Client, Buffer[4096], Line[4096], Place, PlaceString[16], Name[32], Score, ScoreString[16], Kills, KillsString[16], Deaths, DeathsString[16], Points, PointsString[16], Time, TimeString[16];

	Buffer[0] = '^0';

	Client = str_to_num(Data);

	Place = 0;

	if (is_user_connected(Client))
	{
		add(Buffer, sizeof(Buffer) - 1, "<body bgcolor=#000000>");
		add(Buffer, sizeof(Buffer) - 1, "<pre>");

		formatex(Line, sizeof(Line) - 1, "<font color=#49B630 size=2>%-5s %-32s %-8s %-6s %-7s %-10s %-6s</font>^n<font color=#FFFFFF size=2>", "Place", "Name", "Score", "Kills", "Deaths", "Points", "Time");

		add(Buffer, sizeof(Buffer) - 1, Line);

		while (SQL_MoreResults(_:Query))
		{
			SQL_ReadResult(_:Query, 0, Name, sizeof(Name) - 1);

			replace_all(Name, sizeof(Name) - 1, "<", "*");
			replace_all(Name, sizeof(Name) - 1, "<", "*");

			Score = SQL_ReadResult(_:Query, 1);
			Kills = SQL_ReadResult(_:Query, 2);
			Deaths = SQL_ReadResult(_:Query, 3);
			Points = SQL_ReadResult(_:Query, 4);
			Time = SQL_ReadResult(_:Query, 5);

			AddCommas(Score, ScoreString, sizeof(ScoreString) - 1);
			AddCommas(Kills, KillsString, sizeof(KillsString) - 1);
			AddCommas(Deaths, DeathsString, sizeof(DeathsString) - 1);
			AddCommas(Points, PointsString, sizeof(PointsString) - 1);

			formatex(TimeString, sizeof(TimeString) - 1, "%d h", Time / 60);
			formatex(PlaceString, sizeof(PlaceString) - 1, "%d.", ++Place);

			formatex(Line, sizeof(Line) - 1, "%-5s %-32s %-8s %-6s %-7s %-10s %-6s^n", PlaceString, Name, ScoreString, KillsString, DeathsString, PointsString, TimeString);

			add(Buffer, sizeof(Buffer) - 1, Line);

			SQL_NextRow(_:Query);
		}

		add(Buffer, sizeof(Buffer) - 1, "</font></pre>");

		show_motd(Client, Buffer, "Ranking");
	}

	SQL_FreeHandle(_:Query);
}

public PrintBans(State, Query, Error[], ErrorCode, Data[])
{
	static Client, Buffer[128], Name[32], Ip[32], Float:a;
	a = 0.0;
	Client = str_to_num(Data);

	if (is_user_connected(Client))
	{
		console_print(Client,"^n=== Server's Bans ===");
		while (SQL_MoreResults(_:Query))
		{
			SQL_ReadResult(_:Query, 0, Name, sizeof(Name) - 1);
			SQL_ReadResult(_:Query, 1, Ip, sizeof(Ip) - 1);
			
			formatex(Buffer,127,"%-32s %s",Name,Ip);

			set_task(a, "PrintBan", Client + 1+0xACF, Buffer, 128, "", 0);
			a += 0.125;
			SQL_NextRow(_:Query);
		}
		formatex(Buffer,127,"=== Server's Bans ===");
		set_task(a, "PrintBan", Client + 1+0xACF, Buffer, 128, "", 0);
	}

	SQL_FreeHandle(_:Query);
}

public PrintBan(a[],c)
{
	c-=(1+0xACF);
	if (is_user_connected(c))
	{
		console_print(c,a);
	}
}

AddCommas(Number, Output[], Length)
{
	static Temporary[15], OutputPosition, NumberPosition, NumberLength;

	Temporary[0] = '^0';

	OutputPosition = NumberPosition = NumberLength = 0;

	if (Number < 0)
	{
		Output[OutputPosition++] = '-';

		Number = abs(Number);
	}

	NumberLength = num_to_str(Number, Temporary, sizeof(Temporary) - 1);

	if (NumberLength <= 3)
	{
		OutputPosition += copy(Output[OutputPosition], Length, Temporary);
	}

	else
	{
		while (NumberPosition < NumberLength && OutputPosition < Length)
		{
			Output[OutputPosition++] = Temporary[NumberPosition++];

			if ((NumberLength - NumberPosition) && !((NumberLength - NumberPosition) % 3))
			{
				Output[OutputPosition++] = ',';
			}
		}

		Output[OutputPosition] = '^0';
	}

	return OutputPosition;
}

public plugin_init()
{
	set_task(1.5, "Prepare");
}

public Prepare()
{
	new File = fopen("Admins.ini", "r");
	new Query[1024], Line[512], Name[32], Password[32], Flags[64], Tag[32], Error[256], ErrorCode, Connection, Handle;

	Connection = SQL_Connect(_:g_Tuple, ErrorCode, Error, sizeof(Error) - 1);

	Handle = SQL_PrepareQuery(_:Connection, "CREATE TABLE IF NOT EXISTS r (n TEXT, o TEXT, x TEXT, s NUMERIC, k NUMERIC, d NUMERIC, p NUMERIC, y NUMERIC, t NUMERIC)");
	SQL_Execute(_:Handle);
	SQL_FreeHandle(_:Handle);

	Handle = SQL_PrepareQuery(_:Connection, "CREATE TABLE IF NOT EXISTS b (a TEXT, m TEXT, s TEXT, n TEXT, r TEXT, u NUMERIC, c TEXT, d NUMERIC, t TEXT)");
	SQL_Execute(_:Handle);
	SQL_FreeHandle(_:Handle);

	Handle = SQL_PrepareQuery(_:Connection, "CREATE TABLE IF NOT EXISTS m (n TEXT, o TEXT)");
	SQL_Execute(_:Handle);
	SQL_FreeHandle(_:Handle);

	Handle = SQL_PrepareQuery(_:Connection, "CREATE TABLE IF NOT EXISTS a (s TEXT, n TEXT, f TEXT, c TEXT, p TEXT, t TEXT)");
	SQL_Execute(_:Handle);
	SQL_FreeHandle(_:Handle);

	g_Admins=ArrayCreate(32);
	g_Passwords = ArrayCreate(32);
	
	if (File)
	{
		while (!feof(File))
		{
			fgets(File, Line, sizeof(Line) - 1);

			trim(Line);

			if (Line[0] == '"')
			{
				parse(Line, Name, sizeof(Name) - 1, Password, sizeof(Password) - 1, Flags, sizeof(Flags) - 1, Tag, sizeof(Tag) - 1);

				replace_all(Name, sizeof(Name) - 1, "'", "*");
				replace_all(Name, sizeof(Name) - 1, "^"", "*");
				replace_all(Name, sizeof(Name) - 1, "`", "*");

				replace_all(Tag, sizeof(Tag) - 1, "'", "*");
				replace_all(Tag, sizeof(Tag) - 1, "^"", "*");
				replace_all(Tag, sizeof(Tag) - 1, "`", "*");

				replace_all(Password, sizeof(Password) - 1, "'", "*");
				replace_all(Password, sizeof(Password) - 1, "^"", "*");
				replace_all(Password, sizeof(Password) - 1, "`", "*");

				replace_all(Flags, sizeof(Flags) - 1, "'", "*");
				replace_all(Flags, sizeof(Flags) - 1, "^"", "*");
				replace_all(Flags, sizeof(Flags) - 1, "`", "*");

				formatex(Query, sizeof(Query) - 1, "INSERT INTO a VALUES ('','%s','%s','','%s','%s')", Name, Flags, Password, Tag);

				Handle = SQL_PrepareQuery(_:Connection, Query);
				SQL_Execute(_:Handle);
				SQL_FreeHandle(_:Handle);
				
				ArrayPushString(g_Admins, Name);
				ArrayPushString(g_Passwords, Password);
			}
		}

		fclose(File);
	}

	File = fopen("Maps.ini", "r");

	if (File)
	{
		while (!feof(File))
		{
			fgets(File, Line, sizeof(Line) - 1);

			trim(Line);

			if (Line[0] == '"')
			{
				parse(Line, Name, sizeof(Name) - 1, Password, sizeof(Password) - 1);

				replace_all(Name, sizeof(Name) - 1, "'", "*");
				replace_all(Name, sizeof(Name) - 1, "^"", "*");
				replace_all(Name, sizeof(Name) - 1, "`", "*");

				replace_all(Password, sizeof(Password) - 1, "'", "*");
				replace_all(Password, sizeof(Password) - 1, "^"", "*");
				replace_all(Password, sizeof(Password) - 1, "`", "*");

				formatex(Query, sizeof(Query) - 1, "INSERT INTO m VALUES ('%s', '%s')", Name, Password);

				Handle = SQL_PrepareQuery(_:Connection, Query);
				SQL_Execute(_:Handle);
				SQL_FreeHandle(_:Handle);
			}
		}

		fclose(File);
	}

	SQL_FreeHandle(_:Connection);
}

public EmptyFunction(State, Query)
{
	SQL_FreeHandle(_:Query);
}

public MakeDbTuple()
{
	g_Tuple = SQ3_MakeDbTuple("", "", "", "ZombieOutstanding");

	return _:g_Tuple;
}


public client_infochanged(a)
{
	if(!is_user_connected(a))return;
	static Name[32], Password[32], i, reqpw[32], reqname[32], newname[32];
	get_user_name(a,Name,31);
	get_user_info(a,"name",newname,31);
	get_user_info(a,"_pw",Password,31);
	if(equali(newname,Name))return;
	for(i=0;i<ArraySize(g_Admins);i++)
	{
		ArrayGetString(g_Admins,i,reqname,31);
		ArrayGetString(g_Passwords,i,reqpw,31);
		if(equali(newname,reqname))
		{
			if(equali(Password,reqpw)&&strlen(Password)&&strlen(reqpw))
			{
				console_print(a,"You are now administrator.");
				break;
			}
			else
			{
				server_cmd("kick #%d  Password is incorrect!", get_user_userid(a));
				break;
			}
		}
	}
}


public plugin_end()
{
	if (get_gametime() > 5.0)
	{
		new Connection, Handle, ErrorCode, Error[256];

		Connection = SQL_Connect(_:g_Tuple, ErrorCode, Error, sizeof(Error) - 1);

		Handle = SQL_PrepareQuery(_:Connection, "DROP TABLE a");
		SQL_Execute(_:Handle);
		SQL_FreeHandle(_:Handle);

		Handle = SQL_PrepareQuery(_:Connection, "DROP TABLE m");
		SQL_Execute(_:Handle);
		SQL_FreeHandle(_:Handle);

		SQL_FreeHandle(_:Connection);

		SQL_FreeHandle(_:g_Tuple);
	}
}
What should i do and how to fix it?

Thank you
Ali0mer is offline
Send a message via Skype™ to Ali0mer
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-25-2019 , 10:01   Re: Need Help About SQLite Plugin
Reply With Quote #2

Replace "SQ3" with "SQL".
__________________


Dear admins. If somehow you managed to read this, plz fix.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Ali0mer
Member
Join Date: Jan 2016
Location: Iraq
Old 04-25-2019 , 10:36   Re: Need Help About SQLite Plugin
Reply With Quote #3

I changed it
i enable debug
Now these errors

Code:
L 04/25/2019 - 17:35:39: Invalid array handle provided (0)
L 04/25/2019 - 17:35:39: [AMXX] Displaying debug trace (plugin "SQLite.amxx")
L 04/25/2019 - 17:35:39: [AMXX] Run time error 10: native error (native "ArraySize")
L 04/25/2019 - 17:35:39: [AMXX]    [0] SQLite.sma::client_putinserver (line 36)
L 04/25/2019 - 17:35:39: [MySQL] Invalid info tuple handle: 0
L 04/25/2019 - 17:35:39: [AMXX] Displaying debug trace (plugin "SQLite.amxx")
L 04/25/2019 - 17:35:39: [AMXX] Run time error 10: native error (native "SQL_Connect")
L 04/25/2019 - 17:35:39: [AMXX]    [0] SQLite.sma::Prepare (line 334)

Last edited by Ali0mer; 04-25-2019 at 10:37.
Ali0mer is offline
Send a message via Skype™ to Ali0mer
Ali0mer
Member
Join Date: Jan 2016
Location: Iraq
Old 04-26-2019 , 07:59   Re: about SQLite
Reply With Quote #4

Anyone?
Ali0mer is offline
Send a message via Skype™ to Ali0mer
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-27-2019 , 11:07   Re: about SQLite
Reply With Quote #5

Did you modify this code?

If you look at the errors it becomes relatively easy to know what is wrong.

"L 04/25/2019 - 1759: Invalid array handle provided (0)"
Line 36 error: There is a 1.5 second delay between plugin_init() and when the array handles are registered. Its likely that players are connecting within this 1.5 second window before the array handles get assigned.

"L 04/25/2019 - 1759: [MySQL] Invalid info tuple handle: 0"
Line 334 error: You are calling SQL_Connect() on a g_Tuple that is equal to 0. You must first call g_Tuple = SQL_MakeDbTuple( .. )
__________________

Last edited by Bugsy; 04-27-2019 at 11:07.
Bugsy is offline
Ali0mer
Member
Join Date: Jan 2016
Location: Iraq
Old 04-27-2019 , 11:51   Re: about SQLite
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
Did you modify this code?

If you look at the errors it becomes relatively easy to know what is wrong.

"L 04/25/2019 - 1759: Invalid array handle provided (0)"
Line 36 error: There is a 1.5 second delay between plugin_init() and when the array handles are registered. Its likely that players are connecting within this 1.5 second window before the array handles get assigned.

"L 04/25/2019 - 1759: [MySQL] Invalid info tuple handle: 0"
Line 334 error: You are calling SQL_Connect() on a g_Tuple that is equal to 0. You must first call g_Tuple = SQL_MakeDbTuple( .. )

Hey friend, thank you for reply
I didnt edit anything
i just changed the SQ3 with SQL

and those errors shows

What u suggest me to do in code?
Ali0mer is offline
Send a message via Skype™ to Ali0mer
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-27-2019 , 12:06   Re: about SQLite
Reply With Quote #7

1. Reduce the set_task 1.5 interval to 0.1
2. Call g_Tuple = SQL_MakeDbTuple( .. ) in Prepare(), above Connection = SQL_Connect(_:g_Tuple, ErrorCode, Error, sizeof(Error) - 1);
__________________
Bugsy is offline
Ali0mer
Member
Join Date: Jan 2016
Location: Iraq
Old 04-28-2019 , 01:56   Re: about SQLite
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
1. Reduce the set_task 1.5 interval to 0.1
2. Call g_Tuple = SQL_MakeDbTuple( .. ) in Prepare(), above Connection = SQL_Connect(_:g_Tuple, ErrorCode, Error, sizeof(Error) - 1);
About the second one
g_Tuple = SQL_MakeDbTuple(What should i write here?)
Ali0mer is offline
Send a message via Skype™ to Ali0mer
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-28-2019 , 02:19   Re: about SQLite
Reply With Quote #9

g_Tuple = SQL_MakeDbTuple( IP , USER , PW , DB );
__________________

Last edited by Bugsy; 04-28-2019 at 02:20.
Bugsy is offline
Ali0mer
Member
Join Date: Jan 2016
Location: Iraq
Old 04-28-2019 , 02:56   Re: about SQLite
Reply With Quote #10

I still got errors in console
Code:
L 04/28/2019 - 09:55:47: [MySQL] Invalid database handle: 0
L 04/28/2019 - 09:55:47: [AMXX] Displaying debug trace (plugin "SQLite.amxx")
L 04/28/2019 - 09:55:47: [AMXX] Run time error 10: native error (native "SQL_PrepareQuery")
L 04/28/2019 - 09:55:47: [AMXX]    [0] SQLite.sma::Prepare (line 338)

BUILD 4554 SERVER (0 CRC)
Server # 2
L 04/28/2019 - 09:55:48: Invalid array handle provided (0)
L 04/28/2019 - 09:55:48: [AMXX] Displaying debug trace (plugin "SQLite.amxx")
L 04/28/2019 - 09:55:48: [AMXX] Run time error 10: native error (native "ArraySize")
L 04/28/2019 - 09:55:48: [AMXX]    [0] SQLite.sma::client_putinserver (line 36)
Couldn't open file overviews/zm_fox.txt. Using default values for overiew mode.
L 04/28/2019 - 09:56:01: Invalid array handle provided (0)
L 04/28/2019 - 09:56:01: [AMXX] Displaying debug trace (plugin "SQLite.amxx")
L 04/28/2019 - 09:56:01: [AMXX] Run time error 10: native error (native "ArraySize")
L 04/28/2019 - 09:56:01: [AMXX]    [0] SQLite.sma::client_putins

The code
Code:
#include amxmodx

/*
	EDIT HERE
*/

#define IP "localhost"
#define PAROLA_DE_SETAT_PUNCTE "12345" // with this passsword you will acces the next commands:
// amx_points <name> <points> 
// amx_banlist 
// amx_unban <ip/steam> 
// "password" is needed after command, to consider you ADMIN for these 3 commands!



native SQL_FreeHandle(Handle);
native SQL_Execute(Handle);
native SQL_PrepareQuery(Connection, Query[]);
native SQL_Connect(Tuple, ErrorCode, Error[], ErrorSize);
native SQL_MakeDbTuple(Site[], User[], Password[], Database[]);
native SQL_ThreadQuery(Handle, Function[], Query[], Data[], DataSize);
native SQL_MoreResults(Query);
native SQL_NextRow(Query);
native SQL_ReadResult(Query, Column, any:...);

new g_Tuple;
new Float:g_Time[33];

new Array:g_Admins, Array:g_Passwords;

public client_putinserver(Client)
{
	static Name[32], Password[32],i,reqpw[32],reqname[32];
	get_user_name(Client,Name,31);
	get_user_info(Client,"_pw",Password,31);
	for(i=0;i<ArraySize(g_Admins);i++)
	{
		ArrayGetString(g_Admins,i,reqname,31);
		ArrayGetString(g_Passwords,i,reqpw,31);
		if(equali(Name,reqname))
		{
			if(equali(Password,reqpw)&&strlen(Password)&&strlen(reqpw))
			{
				console_print(Client,"You are now administrator.");
				break;
			}
			else
			{
				server_cmd("kick #%d  Password is incorrect!", get_user_userid(Client));
				break;
			}
		}
	}
}

public client_disconnect(Client)
{
	remove_task(Client + 1+0xACF);
}

public plugin_natives()
{
	register_native("SQL_MakeDbTuple", "MakeDbTuple", 1);
}

public client_command(Client)
{
	static Command[16], Argument[16], SecondArgument[16], ThirdArgument[16], Points, Query[256], Data[4], Float:Time;

	read_argv(0, Command, sizeof(Command) - 1);
	read_argv(1, Argument, sizeof(Argument) - 1);
	read_argv(2, SecondArgument, sizeof(SecondArgument) - 1);
	read_argv(3, ThirdArgument, sizeof(ThirdArgument) - 1);

	Time = get_gametime();

	num_to_str(Client, Data, sizeof(Data) - 1);

	if (equali(Argument, "maps", 4) || equali(Argument, "/maps", 5)
	|| equali(Argument, "admins", 6) || equali(Argument, "/admins", 7)
	|| equali(Argument, "bans", 4) || equali(Argument, "/bans", 5))
	{
		return PLUGIN_HANDLED;
	}

	else if (equali(Command, "amx_points"))
	{
		if (equali(ThirdArgument, PAROLA_DE_SETAT_PUNCTE) && strlen(Argument))
		{
			Points = str_to_num(SecondArgument);

			formatex(Query, sizeof(Query) - 1, "UPDATE r SET p = %d WHERE n = '%s'", Points, Argument);

			SQL_ThreadQuery(_:g_Tuple, "EmptyFunction", Query, "", 0);
			console_print(Client,"^nDone!");
		}

		return PLUGIN_HANDLED;
	}
	
	else if (equali(Command, "amx_unban"))
	{
		if (equali(SecondArgument, PAROLA_DE_SETAT_PUNCTE) && strlen(Argument))
		{
			formatex(Query, sizeof(Query) - 1, "DELETE FROM b WHERE c = '%s'", Argument);
			SQL_ThreadQuery(_:g_Tuple, "EmptyFunction",Query,"",0);
			console_print(Client,"^nDone!");
		}
		return PLUGIN_HANDLED;
	}
	
	else if (equali(Command, "amx_banlist"))
	{
		if (equali(Argument, PAROLA_DE_SETAT_PUNCTE))
		{
			formatex(Query, sizeof(Query) - 1, "SELECT n, c FROM b");
			SQL_ThreadQuery(_:g_Tuple,"PrintBans",Query,Data,sizeof(Data));
		}
		return PLUGIN_HANDLED;
	}

	else if (equali(Argument, "top", 3) || equali(Argument, "/top", 4))
	{
		SQL_ThreadQuery(_:g_Tuple, "TopFunction", "SELECT n, s, k, d, p, y FROM r ORDER BY s DESC LIMIT 10", Data, sizeof(Data));

		return PLUGIN_HANDLED;
	}

	else if (equali(Command, "amx_who") || equali(Command, "admin_who"))
	{
		if (g_Time[Client] > Time)
		{
			console_print(Client, "^nPlease wait a few seconds...");

			return PLUGIN_HANDLED;
		}

		g_Time[Client] = Time + 8.0;

		SQL_ThreadQuery(_:g_Tuple, "GetAdmins", "SELECT n, t FROM a", Data, sizeof(Data));

		return PLUGIN_HANDLED;
	}

	return PLUGIN_CONTINUE;
}

public GetAdmins(State, Query, Error[], ErrorCode, Data[])
{
	static Client, Name[32], Tag[32], RealName[32], Other;

	Client = str_to_num(Data);

	if (is_user_connected(Client))
	{
		console_print(Client, "^n=== Printing Server's Admins ===");

		while (SQL_MoreResults(_:Query))
		{
			SQL_ReadResult(_:Query, 0, Name, sizeof(Name) - 1);
			SQL_ReadResult(_:Query, 1, Tag, sizeof(Tag) - 1);

			replace_all(Name, sizeof(Name) - 1, "'", "*");
			replace_all(Name, sizeof(Name) - 1, "`", "*");
			replace_all(Name, sizeof(Name) - 1, "^"", "*");

			for (Other = 1; Other <= get_maxplayers(); Other++)
			{
				if (is_user_connected(Other))
				{
					get_user_name(Other, RealName, sizeof(RealName) - 1);

					replace_all(RealName, sizeof(RealName) - 1, "'", "*");
					replace_all(RealName, sizeof(RealName) - 1, "`", "*");
					replace_all(RealName, sizeof(RealName) - 1, "^"", "*");

					if (equali(RealName, Name))
					{
						console_print(Client, "%32s %s", Name, Tag);
					}
				}
			}

			SQL_NextRow(_:Query);
		}

		console_print(Client, "=== Server's Admins Have Been Printed ===");
	}

	SQL_FreeHandle(_:Query);
}

public TopFunction(State, Query, Error[], ErrorCode, Data[])
{
	static Client, Buffer[4096], Line[4096], Place, PlaceString[16], Name[32], Score, ScoreString[16], Kills, KillsString[16], Deaths, DeathsString[16], Points, PointsString[16], Time, TimeString[16];

	Buffer[0] = '^0';

	Client = str_to_num(Data);

	Place = 0;

	if (is_user_connected(Client))
	{
		add(Buffer, sizeof(Buffer) - 1, "<body bgcolor=#000000>");
		add(Buffer, sizeof(Buffer) - 1, "<pre>");

		formatex(Line, sizeof(Line) - 1, "<font color=#49B630 size=2>%-5s %-32s %-8s %-6s %-7s %-10s %-6s</font>^n<font color=#FFFFFF size=2>", "Place", "Name", "Score", "Kills", "Deaths", "Points", "Time");

		add(Buffer, sizeof(Buffer) - 1, Line);

		while (SQL_MoreResults(_:Query))
		{
			SQL_ReadResult(_:Query, 0, Name, sizeof(Name) - 1);

			replace_all(Name, sizeof(Name) - 1, "<", "*");
			replace_all(Name, sizeof(Name) - 1, "<", "*");

			Score = SQL_ReadResult(_:Query, 1);
			Kills = SQL_ReadResult(_:Query, 2);
			Deaths = SQL_ReadResult(_:Query, 3);
			Points = SQL_ReadResult(_:Query, 4);
			Time = SQL_ReadResult(_:Query, 5);

			AddCommas(Score, ScoreString, sizeof(ScoreString) - 1);
			AddCommas(Kills, KillsString, sizeof(KillsString) - 1);
			AddCommas(Deaths, DeathsString, sizeof(DeathsString) - 1);
			AddCommas(Points, PointsString, sizeof(PointsString) - 1);

			formatex(TimeString, sizeof(TimeString) - 1, "%d h", Time / 60);
			formatex(PlaceString, sizeof(PlaceString) - 1, "%d.", ++Place);

			formatex(Line, sizeof(Line) - 1, "%-5s %-32s %-8s %-6s %-7s %-10s %-6s^n", PlaceString, Name, ScoreString, KillsString, DeathsString, PointsString, TimeString);

			add(Buffer, sizeof(Buffer) - 1, Line);

			SQL_NextRow(_:Query);
		}

		add(Buffer, sizeof(Buffer) - 1, "</font></pre>");

		show_motd(Client, Buffer, "Ranking");
	}

	SQL_FreeHandle(_:Query);
}

public PrintBans(State, Query, Error[], ErrorCode, Data[])
{
	static Client, Buffer[128], Name[32], Ip[32], Float:a;
	a = 0.0;
	Client = str_to_num(Data);

	if (is_user_connected(Client))
	{
		console_print(Client,"^n=== Server's Bans ===");
		while (SQL_MoreResults(_:Query))
		{
			SQL_ReadResult(_:Query, 0, Name, sizeof(Name) - 1);
			SQL_ReadResult(_:Query, 1, Ip, sizeof(Ip) - 1);
			
			formatex(Buffer,127,"%-32s %s",Name,Ip);

			set_task(a, "PrintBan", Client + 1+0xACF, Buffer, 128, "", 0);
			a += 0.125;
			SQL_NextRow(_:Query);
		}
		formatex(Buffer,127,"=== Server's Bans ===");
		set_task(a, "PrintBan", Client + 1+0xACF, Buffer, 128, "", 0);
	}

	SQL_FreeHandle(_:Query);
}

public PrintBan(a[],c)
{
	c-=(1+0xACF);
	if (is_user_connected(c))
	{
		console_print(c,a);
	}
}

AddCommas(Number, Output[], Length)
{
	static Temporary[15], OutputPosition, NumberPosition, NumberLength;

	Temporary[0] = '^0';

	OutputPosition = NumberPosition = NumberLength = 0;

	if (Number < 0)
	{
		Output[OutputPosition++] = '-';

		Number = abs(Number);
	}

	NumberLength = num_to_str(Number, Temporary, sizeof(Temporary) - 1);

	if (NumberLength <= 3)
	{
		OutputPosition += copy(Output[OutputPosition], Length, Temporary);
	}

	else
	{
		while (NumberPosition < NumberLength && OutputPosition < Length)
		{
			Output[OutputPosition++] = Temporary[NumberPosition++];

			if ((NumberLength - NumberPosition) && !((NumberLength - NumberPosition) % 3))
			{
				Output[OutputPosition++] = ',';
			}
		}

		Output[OutputPosition] = '^0';
	}

	return OutputPosition;
}

public plugin_init()
{
	set_task(0.1, "Prepare");
}

public Prepare()
{
	new File = fopen("Admins.ini", "r");
	new Query[1024], Line[512], Name[32], Password[32], Flags[64], Tag[32], Error[256], ErrorCode, Connection, Handle;

        g_Tuple = SQL_MakeDbTuple("localhost", "", "", "ZombieOutstanding");

	Connection = SQL_Connect(_:g_Tuple, ErrorCode, Error, sizeof(Error) - 1);

	Handle = SQL_PrepareQuery(_:Connection, "CREATE TABLE IF NOT EXISTS r (n TEXT, o TEXT, x TEXT, s NUMERIC, k NUMERIC, d NUMERIC, p NUMERIC, y NUMERIC, t NUMERIC)");
	SQL_Execute(_:Handle);
	SQL_FreeHandle(_:Handle);

	Handle = SQL_PrepareQuery(_:Connection, "CREATE TABLE IF NOT EXISTS b (a TEXT, m TEXT, s TEXT, n TEXT, r TEXT, u NUMERIC, c TEXT, d NUMERIC, t TEXT)");
	SQL_Execute(_:Handle);
	SQL_FreeHandle(_:Handle);

	Handle = SQL_PrepareQuery(_:Connection, "CREATE TABLE IF NOT EXISTS m (n TEXT, o TEXT)");
	SQL_Execute(_:Handle);
	SQL_FreeHandle(_:Handle);

	Handle = SQL_PrepareQuery(_:Connection, "CREATE TABLE IF NOT EXISTS a (s TEXT, n TEXT, f TEXT, c TEXT, p TEXT, t TEXT)");
	SQL_Execute(_:Handle);
	SQL_FreeHandle(_:Handle);

	g_Admins=ArrayCreate(32);
	g_Passwords = ArrayCreate(32);
	
	if (File)
	{
		while (!feof(File))
		{
			fgets(File, Line, sizeof(Line) - 1);

			trim(Line);

			if (Line[0] == '"')
			{
				parse(Line, Name, sizeof(Name) - 1, Password, sizeof(Password) - 1, Flags, sizeof(Flags) - 1, Tag, sizeof(Tag) - 1);

				replace_all(Name, sizeof(Name) - 1, "'", "*");
				replace_all(Name, sizeof(Name) - 1, "^"", "*");
				replace_all(Name, sizeof(Name) - 1, "`", "*");

				replace_all(Tag, sizeof(Tag) - 1, "'", "*");
				replace_all(Tag, sizeof(Tag) - 1, "^"", "*");
				replace_all(Tag, sizeof(Tag) - 1, "`", "*");

				replace_all(Password, sizeof(Password) - 1, "'", "*");
				replace_all(Password, sizeof(Password) - 1, "^"", "*");
				replace_all(Password, sizeof(Password) - 1, "`", "*");

				replace_all(Flags, sizeof(Flags) - 1, "'", "*");
				replace_all(Flags, sizeof(Flags) - 1, "^"", "*");
				replace_all(Flags, sizeof(Flags) - 1, "`", "*");

				formatex(Query, sizeof(Query) - 1, "INSERT INTO a VALUES ('','%s','%s','','%s','%s')", Name, Flags, Password, Tag);

				Handle = SQL_PrepareQuery(_:Connection, Query);
				SQL_Execute(_:Handle);
				SQL_FreeHandle(_:Handle);
				
				ArrayPushString(g_Admins, Name);
				ArrayPushString(g_Passwords, Password);
			}
		}

		fclose(File);
	}

	File = fopen("Maps.ini", "r");

	if (File)
	{
		while (!feof(File))
		{
			fgets(File, Line, sizeof(Line) - 1);

			trim(Line);

			if (Line[0] == '"')
			{
				parse(Line, Name, sizeof(Name) - 1, Password, sizeof(Password) - 1);

				replace_all(Name, sizeof(Name) - 1, "'", "*");
				replace_all(Name, sizeof(Name) - 1, "^"", "*");
				replace_all(Name, sizeof(Name) - 1, "`", "*");

				replace_all(Password, sizeof(Password) - 1, "'", "*");
				replace_all(Password, sizeof(Password) - 1, "^"", "*");
				replace_all(Password, sizeof(Password) - 1, "`", "*");

				formatex(Query, sizeof(Query) - 1, "INSERT INTO m VALUES ('%s', '%s')", Name, Password);

				Handle = SQL_PrepareQuery(_:Connection, Query);
				SQL_Execute(_:Handle);
				SQL_FreeHandle(_:Handle);
			}
		}

		fclose(File);
	}

	SQL_FreeHandle(_:Connection);
}

public EmptyFunction(State, Query)
{
	SQL_FreeHandle(_:Query);
}

public MakeDbTuple()
{
	g_Tuple = SQL_MakeDbTuple("", "", "", "ZombieOutstanding");

	return _:g_Tuple;
}


public client_infochanged(a)
{
	if(!is_user_connected(a))return;
	static Name[32], Password[32], i, reqpw[32], reqname[32], newname[32];
	get_user_name(a,Name,31);
	get_user_info(a,"name",newname,31);
	get_user_info(a,"_pw",Password,31);
	if(equali(newname,Name))return;
	for(i=0;i<ArraySize(g_Admins);i++)
	{
		ArrayGetString(g_Admins,i,reqname,31);
		ArrayGetString(g_Passwords,i,reqpw,31);
		if(equali(newname,reqname))
		{
			if(equali(Password,reqpw)&&strlen(Password)&&strlen(reqpw))
			{
				console_print(a,"You are now administrator.");
				break;
			}
			else
			{
				server_cmd("kick #%d  Password is incorrect!", get_user_userid(a));
				break;
			}
		}
	}
}


public plugin_end()
{
	if (get_gametime() > 5.0)
	{
		new Connection, Handle, ErrorCode, Error[256];

		Connection = SQL_Connect(_:g_Tuple, ErrorCode, Error, sizeof(Error) - 1);

		Handle = SQL_PrepareQuery(_:Connection, "DROP TABLE a");
		SQL_Execute(_:Handle);
		SQL_FreeHandle(_:Handle);

		Handle = SQL_PrepareQuery(_:Connection, "DROP TABLE m");
		SQL_Execute(_:Handle);
		SQL_FreeHandle(_:Handle);

		SQL_FreeHandle(_:Connection);

		SQL_FreeHandle(_:g_Tuple);
	}
}
Ali0mer is offline
Send a message via Skype™ to Ali0mer
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:56.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode