SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/03/2016, 11:49 AM   #1
theonethatownz
Big Clucker
 
Join Date: Jan 2013
Posts: 57
Reputation: 2
Default MYSQL Ban Check

I'm trying to create a mysql script. I have a login / account system.

When a admin bans a player, it adds the information (Name, IP, Reason etc) into a MySQL table "bans"

Under OnPlayerConnect, I currently use this:

pawn Code:
Player[playerid][Logged] = 0;
    TogglePlayerSpectating(playerid, true);
    new
        query[128],
        playername[MAX_PLAYER_NAME];
         
    GetPlayerName(playerid, playername, sizeof(playername));
    mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);

I would like to make it so when they join, it searches the bans mysql table for the playername and IP and if it matches, it'll kick the player with a message or dialog with the ban information in.

My OnAccountCheck
pawn Code:
public OnAccountCheck(playerid)
{
    new
        rows,
        fields;
    cache_get_data(rows, fields, mysql);
     
    if(rows)
    {
        cache_get_field_content(0, "Password", Player[playerid][Password], mysql, 129);
        Player[playerid][ID] = cache_get_field_content_int(0, "ID");
        ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_PASSWORD, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
    }
    return true;
}
theonethatownz is offline   Reply With Quote
Old 25/03/2016, 08:18 PM   #2
mcreed
Huge Clucker
 
Join Date: Nov 2011
Location: La Lima, Honduras.
Posts: 212
Reputation: 2
Default Respuesta: MYSQL Ban Check

It would be something like:
pawn Code:
new query[126];
    format(query,sizeof(query),"SELECT * FROM table_bans WHERE Name='%s'",playername);
    mysql_query(mysql,query);
    if(cache_num_rows() > 0)
    {
        new banstring[256];
        new bName[30],bIP[30],bAdmin[30],bReason[30];
                cache_get_field_content(0,"Name",bName);
        cache_get_field_content(0,"IP",bIP);
        cache_get_field_content(0,"Admin",bAdmin);
        cache_get_field_content(0,"Reason",bReason);
        format(banstring,sizeof(banstring),"Name: %s\nIP: %s\nAdmin: %s\nReason: %s",bName,bIP,bAdmin,bReason);
        ShowPlayerDialog(playerid,DIALOG_BAN,DIALOG_STYLE_MSGBOX,"Account Banned",banstring,"Aceptar","");
        Kick(playerid);
    }

I'm not very sure about function cache_num_rows, but try it., but try it.

sorry for my bad english.
mcreed is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Someone please check this mysql STONEGOLD Scripting Help 2 06/06/2015 06:54 AM
Mysql queriesYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for th audriuxxx Scripting Help 4 11/04/2014 07:42 PM
[HELP] mysql check V4at Scripting Help 10 25/02/2014 08:52 PM
[Help] Mysql check VMe89 Scripting Help 1 20/03/2012 06:16 PM
mysql check ajwar Scripting Help 2 08/02/2012 04:03 PM


All times are GMT. The time now is 01:56 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.