SQlite Register ERROR Rep+
#1

Hey,

Could anyone fix my script? It won't let the player register for some reason as it doesn't apply to the server.db. I can pay via OneBip or just Rep+. Thanks in advance .
Reply
#2

Show script.
Reply
#3

pawn Код:
/* ================================ Includes ================================ */

#include <a_samp>
#include <anticheat>
#include <a_zones>
#include <a_sampdb>
#include <sscanf2>
#include <zcmd>
#include <includefile>

/* ================================ Defines ================================ */
/** SQ_Lite Setup **/
#define DatabaseFile                "Server.db"
/** Colors **/
#define COL_GREEN                   "{6EF83C}"
#define COL_RED                     "{F81414}"
#define COL_BLUE                    "{00C0FF}"
#define COL_GREY                    "{BABABA}"

#define COLOR_BLUE                  0x003DF5FF
#define COLOR_RED                   0xFF0000FF
#define COLOR_WHITE                 0xFFFFFFFF
#define COLOR_BLACK                 0x00000000
#define COLOR_GREEN                 0x66FF00FF
#define COLOR_YELLOW                0xFFEE00FF
#define COLOR_DARKBLUE              0x0900BDFF
#define COLOR_ORANGE                0xFFC400FF
#define COLOR_PURPLE                0x990094FF
#define COLOR_PINK                  0xFF0095FF
#define COLOR_GREY                  0xC4C4C4FF
/** Dialogs **/
#define Dialog_Login                (0)
#define Dialog_Register             (1)
#define Dialog_Ban                  (2)
#define Dialog_Adm_1                (3)
#define Dialog_Adm_2                (4)
#define Dialog_Adm_3                (5)
#define Dialog_Adm_4                (6)
#define Dialog_Adm_5                (7)
#define Dialog_Adm_6                (8) // RCON
#define Dialog_SYS_Message          "{FFFFFF}Register System"
/** Server **/
#define MAX_REASON_NAME             60
#define Server_Hostname             "Los Santos Cops And Robbers (0.3c)"
#define Server_Gamemode             "Cops And Robbers"
#define Server_Mapname              "Los Santos"
#define Server_Weburl               "incorporatedgaming.co.uk"
#define Server_Rcon_Pass            "2536"
/* ================================ Global Varibles ================================ */
enum E_PLAYER_DATA
{
    pDonator,
    pAdminLevel,
    pJailed,
    pJailedTime,
    pFrozen,
    pScore,
    pMoney,
    pKills,
    pDeaths,
    pWantedLevel,
    Float:pHealth,
    Float:pArmour
}

enum E_BAN_DATA
{
    pBanned,
    pIPAddress,
    pBanDate,
    pBanTime,
    pBannedBy[25],
    pBannedReason[60],
}

new PlayerInfo[MAX_PLAYERS][E_PLAYER_DATA];
new BanInfo[MAX_PLAYERS][E_BAN_DATA];
new DB: Database;

#pragma unused BanInfo
   

/* ================================ Stock Functions ================================ */
stock DB_Escape(text[])
{
    new
        ret[80 * 2],
        ch,
        i,
        j;
    while ((ch = text[i++]) && j < sizeof (ret))
    {
        if (ch == '\'')
        {
            if (j < sizeof (ret) - 2)
            {
                ret[j++] = '\'';
                ret[j++] = '\'';
            }
        }
        else if (j < sizeof (ret))
        {
            ret[j++] = ch;
        }
        else
        {
            j++;
        }
    }
    ret[sizeof (ret) - 1] = '\0';
    return ret;
}

stock ReturnPlayerName(playerid)
{
    new PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,PlayerName,MAX_PLAYER_NAME);
    return PlayerName;
}

stock ReturnPlayerIP(playerid)
{
    new IP[20];
    GetPlayerIp(playerid,IP,sizeof(IP));
    return IP;
}

stock ServerKick(playerid, reason[])
{
    new string[60 + MAX_REASON_NAME];
    format(string,sizeof(string),"** SERVER KICK: %s Has Been Kicked From The Server - %s",ReturnPlayerName(playerid),reason);
    SendClientMessageToAll(COLOR_PINK, string);
//  KickLog(string);
    Kick(playerid);
    return 1;
}

stock SaveUser(playerid)
{
    new Query[128], PlayerName[MAX_PLAYER_NAME], IP[20], Password[24], Float:Health, Float:Armour;
    GetPlayerHealth(playerid, Health);
    GetPlayerArmour(playerid, Armour);
    GetPVarString(playerid, "PasswordUpdate", Password, sizeof(Password));
    GetPVarString(playerid, "IP", IP, sizeof(IP));
    GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
    format(Query,sizeof(Query), "UPDATE `PlayerInfo` SET Username = '%s', Password = '%s', Donator = '%d', AdminLevel = '%d', Jailed = '%d', JailedTime = '%d', Frozen = '%d', IPAddress = '%d', Score = '%d', Money = '%d', Kills = '%d', Deaths = '%d', WantedLevel = '%d', Health = '%f', Armour = '%f' WHERE `Username` = '%s' COLLATE NOCASE",
    PlayerName,
    Password,
    PlayerInfo[playerid][pDonator],
    PlayerInfo[playerid][pAdminLevel],
    PlayerInfo[playerid][pJailed],
    PlayerInfo[playerid][pJailedTime],
    PlayerInfo[playerid][pFrozen],
    IP,
    GetPlayerScore(playerid),
    Safe_GetPlayerMoney(playerid),
    PlayerInfo[playerid][pKills],
    PlayerInfo[playerid][pDeaths],
    GetPlayerWantedLevel(playerid),
    Health,
    Armour,
    DB_Escape(PlayerName));
    return 1;
}

   
   
/* ================================ Forwards ================================ */

forward KickLog(log[]);

/* ================================ Script ================================ */

main()
{
    print("Server Loaded");
}

public OnGameModeInit()
{
    Database = db_open(DatabaseFile);
    db_query(Database, "CREATE TABLE IF NOT EXISTS `PlayerInfo`(`Username`, `Password`, `Donator`, `AdminLevel`, `Jailed`, `JailedTimer`, `Frozen`, `IPAddress`, `Score`, `Money`, `Kills`, `Deaths`, `WantedLevel`, `Health`, `Armour`)");
    db_query(Database, "CREATE TABLE IF NOT EXISTS `BanInfo`(`Banned`, `IPAddress`, `BanDate`, `BanTime`, `BannedBy`, `BannedReason`)");
    db_query(Database, "CREATE TABLE IF NOT EXISTS `IPBanInfo`(`IPAddress`)");
   
    SendRconCommand("hostname "Server_Hostname);
    SendRconCommand("gamemodetext "Server_Gamemode);
    SendRconCommand("weburl "Server_Weburl);
    SendRconCommand("rcon_password "Server_Rcon_Pass);
    SendRconCommand("mapname "Server_Mapname);
    return 1;
}

public OnPlayerConnect(playerid)
{
    new Query[120], DBResult: Result, Dialog_Message[256];
    SetPVarString(playerid,"IP",ReturnPlayerIP(playerid));
    SetPVarInt(playerid,"IncorrectLogin",5); // Login Errors Before Kick
    Safe_ResetPlayerMoney(playerid);
    format(Query,sizeof(Query),"SELECT `Username` FROM `PlayerInfo` WHERE `Username` = '%s'", DB_Escape(ReturnPlayerName(playerid)));
    Result = db_query(Database, Query);
    if(db_num_rows(Result))
    {
        format(Dialog_Message,sizeof(Dialog_Message),"{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're registered.\n\nPlease login by inputting your password.",ReturnPlayerName(playerid), playerid);
        ShowPlayerDialog(playerid, Dialog_Login, DIALOG_STYLE_INPUT,Dialog_SYS_Message, Dialog_Message, "Login", "Leave");
    }
    else
    {
        format(Dialog_Message,sizeof(Dialog_Message),"{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're "COL_RED"not{FFFFFF} registered.\n\nPlease register by inputting a password below",ReturnPlayerName(playerid),playerid);
        ShowPlayerDialog(playerid, Dialog_Register, DIALOG_STYLE_INPUT, Dialog_SYS_Message, Dialog_Message, "Register", "Leave");
    }
    db_free_result(Result);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    SaveUser(playerid);
    if(GetPVarInt(playerid, "TimeoutBan") == 1)
    {
        new string[24 + 20];
        GetPVarString(playerid, "IP", string, sizeof(string));
        format(string,sizeof(string),"unbanip %s",string);
        SendRconCommand(string);
        SendRconCommand("reloadbans");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new PlayerName[MAX_PLAYER_NAME], IP[20], Query[256];
    new DBResult: Result;
    new Dialog_Message[256];
    new string[128];
    GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
    GetPlayerIp(playerid, IP, 20);
    if(dialogid == Dialog_Login)
    {
        if(response)
        {
            format(Query,sizeof(Query),"SELECT * FROM `PlayerInfo` WHERE `Username`='%s' AND `Password`='%s'",DB_Escape(PlayerName), DB_Escape(inputtext));
            Result = db_query(Database, Query);
            if(db_num_rows(Result))
            {
                new Field[20];
                db_get_field_assoc(Result, "Donator", Field, 30);
                PlayerInfo[playerid][pDonator] = strval(Field);
               
                db_get_field_assoc(Result, "AdminLevel", Field, 30);
                PlayerInfo[playerid][pAdminLevel] = strval(Field);
               
                db_get_field_assoc(Result, "Jailed", Field, 30);
                PlayerInfo[playerid][pJailed] = strval(Field);
               
                db_get_field_assoc(Result, "JailedTime", Field, 30);
                PlayerInfo[playerid][pJailedTime] = strval(Field);
               
                db_get_field_assoc(Result, "Frozen", Field, 1);
                PlayerInfo[playerid][pFrozen] = strval(Field);
               
                db_get_field_assoc(Result, "Score", Field, 30);
                SetPlayerScore(playerid, strval(Field));
               
                db_get_field_assoc(Result, "Money", Field, 30);
                Safe_GivePlayerMoney(playerid, strval(Field));
               
                db_get_field_assoc(Result, "Kills", Field, 30);
                PlayerInfo[playerid][pKills] = strval(Field);

                db_get_field_assoc(Result, "Deaths", Field, 30);
                PlayerInfo[playerid][pDeaths] = strval(Field);
               
                db_get_field_assoc(Result, "WantedLevel", Field, 30);
                SetPlayerWantedLevel(playerid, strval(Field));
               
                db_get_field_assoc(Result, "Health", Field, 30);
                SetPlayerHealth(playerid, strval(Field));
               
                db_get_field_assoc(Result, "Armour", Field, 30);
                SetPlayerArmour(playerid, strval(Field));
               
                SendClientMessage(playerid, -1, ""COL_GREY"[SERVER]:{FFFFFF}You have successfully logged in!");
            }
            else
            {
                SetPVarInt(playerid,"IncorrectLogin",-GetPVarInt(playerid,"IncorrectLogin"));
                format(Dialog_Message,sizeof(Dialog_Message),"{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're registered.\n\nPlease login by inputting your password.",ReturnPlayerName(playerid), playerid);
                ShowPlayerDialog(playerid, Dialog_Login, DIALOG_STYLE_INPUT,Dialog_SYS_Message, Dialog_Message, "Login", "Leave");
                format(string,sizeof(string),""COL_RED"[ERROR]:{FFFFFF}You have entered an incorrect password. You have %d attempts remaining",GetPVarInt(playerid,"IncorrectLogin"));
            }
            db_free_result(Result);
        }
        else return ServerKick(playerid, "Incorrect Login");
    }
    if(dialogid == Dialog_Register)
    {
        if(response)
        {
            if(strlen(inputtext) > 24 || strlen(inputtext) < 3)
            {
                format(Dialog_Message,sizeof(Dialog_Message),"{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're "COL_RED"not{FFFFFF} registered.\n\nPlease register by inputting a password below",ReturnPlayerName(playerid),playerid);
                ShowPlayerDialog(playerid, Dialog_Register, DIALOG_STYLE_INPUT, Dialog_SYS_Message, Dialog_Message, "Register", "Leave");
                SendClientMessage(playerid,-1,""COL_RED"[ERROR]:{FFFFFF} Your password must contain atleast 3 characters and not exceed 24!");
            }
            else
            {
                format(Query,sizeof(Query),"INSERT INTO `PlayerInfo`(`Username`, `Password`, `Donator`, `AdminLevel`, `Jailed`, `JailedTime`, `Frozen`, `IPAddress`, `Score`, `Money`, `Kills`, `Deaths`, `WantedLevel`, `Health`, `Armour`) VALUES('%s', '%s', '0', '0', '0', '0', '0', '%s', '0', '5000', '0', '0', '0', '100', '0')",DB_Escape(PlayerName),DB_Escape(inputtext),DB_Escape(IP));
                db_query(Database, Query);
                SetPlayerScore(playerid, 0);
                Safe_GivePlayerMoney(playerid, 5000);
                SendClientMessage(playerid, -1, "You have "COL_GREEN"successfully{FFFFFF} registered! You have been automatically logged in!");
            }
        }
        else return ServerKick(playerid, "Incorrect Login");
    }
    return 1;
}
SA:MP version: 0.3c
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)