SA-MP Forums Archive
A little issue - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: A little issue (/showthread.php?tid=648818)



A little issue - Hypex - 29.01.2018

Hi so I've made this function for banning players
Код:
stock pBan(bUser, bUserBanner, bReason[], system = 0)
{
	if(system == 0)
	{
		if(IsBanned[bUser] == 0)
		{
		    IsBanned[bUser] = 1;
            new handle = SQL::Open(SQL::INSERT, SQL_BAN_TABLE);
            SQL::ToggleAutoIncrement(handle, true);
            SQL::WriteString(handle, "bUser", bNames[bUser]);
            SQL::WriteString(handle, "bUserBanner", GetAdminName(bUserBanner));
            SQL::WriteString(handle, "bReason", bReason);
            SQL::WriteString(handle, "bUserIP", bIP[bUser]);
			SQL::Close(handle);
			
			IsBanned[bUser] = 1;
			new strkick[180];
			format(strkick, sizeof(strkick), ""COLOR_RED" System has banned %s for: %s", pName(bUser), bReason);
			SendClientMessageToAll(-1, strkick);
            SendClientMessage(bUser, -1, ""COLOR_WHITE" If you feel this is a mistake please, visit "Website" ban appeal section!");
			KickEx(bUser);
		}
	}
	else
	{
		if(IsBanned[bUser] == 0)
		{
		    IsBanned[bUser] = 1;
            new handle = SQL::Open(SQL::INSERT, SQL_BAN_TABLE);
            SQL::ToggleAutoIncrement(handle, true);
            SQL::WriteString(handle, "bUser", bNames[bUser]);
            SQL::WriteString(handle, "bUserBanner", GetAdminName(bUserBanner));
            SQL::WriteString(handle, "bReason", bReason);
            SQL::WriteString(handle, "bUserIp", bIP[bUser]);
			SQL::Close(handle);

			new strkick[180];
			format(strkick, sizeof(strkick), ""COLOR_WHITE" %s %s has banned you for: %s", GetAdminName(bUserBanner), pName(bUserBanner), bReason);
			SendClientMessage(bUser, -1, strkick);
			SendClientMessage(bUser, -1, ""COLOR_ORANGE" If you feel this is a mistake please, visit "Website" ban appeal section!");
			KickEx(bUser);
		}
	}
	return 1;
}
but it doesn't save the information of the banned user it just kicks them I didn't want to do it the long way so on my ban command I would just do pBan(bUser, playerid, bReason, 0);.I thought someone here might know how to help me.
I don't see anything wrong with the code though as it compiles with no errors.
After I've banned myself I've checked the table in phpmyadmin and it came up empty also did testing with friends and same result.

Any support is appreciated.
Note: I am using easy-mysql to do this.


Re: A little issue - ThePhenix - 29.01.2018

I don't see anything wrong in your code specifically. Have you tried enabling mysql debugging?


Re: A little issue - Hypex - 29.01.2018

I didnt even bother checking the logs
[plugins/mysql] error #1265 while executing query "INSERT INTO `Bans` (`bUser`,`bUserBanner`,`bReason`,`bUserIP`) VALUES ('Hybris','Owner','test','127.0.0.1' );": Data truncated for column 'bUserIP' at row 1 although I don't understand how the data is truncated...


Re: A little issue - ThePhenix - 29.01.2018

Can you show your ban table's structure?


Re: A little issue - Hypex - 29.01.2018

Yeah here you go
Код:
	if(!SQL::ExistsTable(SQL_BAN_TABLE))
	{
	    new handle = SQL::Open(SQL::CREATE, SQL_BAN_TABLE);
	    SQL::AddTableColumn(handle, "bUID", SQL_TYPE_INT, 11, true);
	    SQL::AddTableColumn(handle, "bUser", SQL_TYPE_VCHAR, 24);
	    SQL::AddTableColumn(handle, "bUserBanner", SQL_TYPE_VCHAR, 24);
	    SQL::AddTableColumn(handle, "bReason", SQL_TYPE_VCHAR, 90);
	    SQL::AddTableColumn(handle, "bUserIP", SQL_TYPE_VCHAR, 16);
	    SQL::Close(handle);
	    
	    print("[Unix]: Successfully created ban table!");
	}
	else if(SQL::ExistsTable(SQL_BAN_TABLE))
	{
	    printf("[Unix]: Total %d bans loaded from the ban table!", SQL::CountRows(SQL_BAN_TABLE));
	}
Also first time I put the sql type integer for buserip ive changed it to vchar but still no change.


Re: A little issue - Mugala - 29.01.2018

try to put 'INSERT' code manually in base with SQL. (like this)

If it placed sucesfully, than problem must be in bIP[bUser], where does it takes ip?
if not, then you must ensure that your SQL is correctly configured.


Re: A little issue - Hypex - 30.01.2018

I've managed to fix it with help from ThePhenix and by setting the collation to utf8_general_ci.