MYSQL Ban Check
#1

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 Код:
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 Код:
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;
}
Reply
#2

It would be something like:
pawn Код:
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)