reg system problem
#1

Код:

#include <a_samp>
#include <a_mysql>
#include <sscanf2>
#include <streamer>
#include <zcmd>
#include <mxdate>

#define SQL_HOST     "127.0.0.1" 
#define SQL_USER     "root"         
#define SQL_PASS     "12345" 
#define SQL_DB       "accounts" 

#define DIALOG_LOGIN        1
#define DIALOG_REGISTER     2
#define DIALOG_WRONGPAS     3
#define COLOR_GREEN 		0x33AA33AA
#define COLOR_RED 			0xAA3333AA

enum pInfo 
{
    pID,
    pName[MAX_PLAYER_NAME],
    pPassword[15],
    bool: pLogged,
    pWrongPassword,
};
new PlayerInfo[MAX_PLAYERS][pInfo];

AntiDeAMX()
{
        new a[][] =
        {
                "Unarmed (Fist)",
                "Brass K"
        };
        #pragma unused a
}

main()
{
	print("\n----------------------------------");
	print(" 12345");
	print("----------------------------------\n");
}

stock CheckMySQLConnection() 
{ 
    if(mysql_ping() == -1) mysql_reconnect();
    return 1;
} 

stock ConnectMySQL() 
{ 
    mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
    switch(mysql_ping()) 
	{ 
        case 1: print("MySQL connection: Yes"); 
        case -1: print("MySQL connection: No"); 
    }
    return 1;
}

stock DisconnectMySQL() 
{ 
    mysql_close();
    print("MySQL connection closed.");
}

stock CreateAccount(playerid, password[]) 
{
    new
        query[128],
        sqlname[MAX_PLAYER_NAME],
        sqlpassword[15];
    mysql_real_escape_string(PlayerInfo[playerid][pName], sqlname);
    mysql_real_escape_string(password, sqlpassword);
    format(query, sizeof(query), "INSERT INTO `accounts` (`name`, `password`) VALUE ('%s', '%s')", sqlname, sqlpassword);
    mysql_query(query);
    PlayerInfo[playerid][pID] = mysql_insert_id(); 
    strmid(PlayerInfo[playerid][pPassword], password, 0, 15, 255);
    PlayerInfo[playerid][pLogged] = true;
    return 1;
}

stock LoadAccount(playerid, password[]) 
{
    new
        query[128],
        sqlpass[32],
        result[5+24+64],
        dialog[128];
    mysql_real_escape_string(password, sqlpass);
    format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `password` = '%s' AND `id` = '%i'", sqlpass, PlayerInfo[playerid][pID]);
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows() == 1) 
	{ 
        mysql_fetch_row_format(result, "|");
        sscanf(result, "p<|>is[24]s[32]",
            PlayerInfo[playerid][pID],
            PlayerInfo[playerid][pName],
            PlayerInfo[playerid][pPassword],
            PlayerInfo[playerid][pLogged] = true );
        mysql_free_result();
        
    }
    else 
	{
        if(PlayerInfo[playerid][pWrongPassword] == 4) 
		{
            SendClientMessage(playerid, COLOR_RED, "Вы 3 раза ввели неверный пароль и были отключены от сервера.");
            Kick(playerid);
            return 1;
        }
        PlayerInfo[playerid][pWrongPassword] ++;
        format(dialog, sizeof(dialog),
		"Вы ввели неверный пароль.\n\
		У Вас осталось %i/3 попыток ввода.", 3 - PlayerInfo[playerid][pWrongPassword]);
        ShowPlayerDialog(playerid, DIALOG_WRONGPAS, DIALOG_STYLE_MSGBOX, "Ошибка.", dialog, "Повтор", "Отмена");
    }
    return 1;
}

stock GetAccountID(playerid) 
{
    new
        query[128];
    format(query, sizeof(query),"SELECT `ID` FROM `accounts` WHERE `name` = '%s'", PlayerInfo[playerid][pName]);
    mysql_query(query);
    mysql_store_result(); 
    if(mysql_num_rows() == 1) 
	{ 
        PlayerInfo[playerid][pID] = mysql_fetch_int();
        mysql_free_result();
        return PlayerInfo[playerid][pID]; 
    }
    return 0;
}

stock SaveAccount(playerid) 
{ 
    if(PlayerInfo[playerid][pLogged] == true) 
	{ 
      CheckMySQLConnection(); 
      new 
        query[186],
        sqlname[MAX_PLAYER_NAME],
        sqlpass[64];
      mysql_real_escape_string(PlayerInfo[playerid][pName], sqlname);
      mysql_real_escape_string(PlayerInfo[playerid][pPassword], sqlpass);
      format(query, sizeof(query), "UPDATE `accounts` SET `name` = '%s', `password` = '%s' WHERE `id` = '%i'", sqlname, sqlpass, PlayerInfo[playerid][pID]);
      mysql_query(query);
    }
    return 1;
}

stock RemovePlayerInfo(playerid)
{
    PlayerInfo[playerid][pWrongPassword] = 0;
    PlayerInfo[playerid][pID] = 0;
    PlayerInfo[playerid][pLogged] = false;
    return 1;
} 

public OnGameModeInit()
{
    AntiDeAMX();
	SetGameModeText("Role Play");
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
	return 1;
}

public OnPlayerConnect(playerid)
{

    GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);

    if(GetAccountID(playerid)) 
	{ 
        new dialog[128+MAX_PLAYER_NAME];
        format(dialog, sizeof(dialog),
		"Добро пожаловать на Сервер!\n\
		Этот аккаунт зарегистрирован.\n\n\
		Логин: %s\n\
		Введите пароль:", PlayerInfo[playerid][pName]);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Авторизация.", dialog, "Войти", "Отмена");
    }
    else 
	{ 
        new dialog[344+MAX_PLAYER_NAME];
        format(dialog, sizeof(dialog),
		"Добро пожаловать на Сервер!\n\
		Этот аккаунт не зарегистрирован.\n\n\
		Логин: %s\n\
		Введите пароль и нажмите \"Далее\".\n\n\
		Примечания:\n\
		- Длина пароля от 6 до 15 символов.\n", PlayerInfo[playerid][pName]);
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Регистрация.", dialog, "Далее", "Отмена");
    }
    RemovePlayerInfo(playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	if(PlayerInfo[playerid][pLogged] == true) SaveAccount(playerid);
    return 1;
}

public OnPlayerSpawn(playerid)
{
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	return 1;
}

public OnVehicleSpawn(vehicleid)
{
	return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
	return 1;
}

public OnPlayerText(playerid, text[])
{
	if(PlayerInfo[playerid][pLogged] == false) return 0;
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
		return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
	return 1;
}

public OnRconCommand(cmd[])
{
	return 1;
}

public OnPlayerRequestSpawn(playerid)
{
	return 1;
}

public OnObjectMoved(objectid)
{
	return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
	return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
	return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
	return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
	return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
	return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
	return 1;
}

public OnPlayerExitedMenu(playerid)
{
	return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
	return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
	return 1;
}

public OnPlayerUpdate(playerid)
{
	return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
	return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
	return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
	return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 
{
    switch(dialogid) 
	{
        case DIALOG_LOGIN: 
		{ 
            if(!response) 
			{ 
                SendClientMessage(playerid, COLOR_GREEN, "Введите /q, чтобы выйти из игры!");
                Kick(playerid);
                return 1;
            }
            if(!strlen(inputtext)) 
			{ 
                new dialog[134+MAX_PLAYER_NAME];
                format(dialog, sizeof(dialog),
				"Добро пожаловать на Сервер!\n\
				Этот аккаунт зарегистрирован.\n\n\
				Логин: %s\n\
				Введите пароль:", PlayerInfo[playerid][pName]);
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Авторизация.", dialog, "Войти", "Отмена");
                return 1;
            }
            LoadAccount(playerid, inputtext);
        }
        case DIALOG_REGISTER: 
		{ 
            if(!response)
			{ 
                SendClientMessage(playerid, COLOR_GREEN, "Введите /q, чтобы выйти из игры!");
                Kick(playerid);
                return 1;
            }
            if(!strlen(inputtext) || strlen(inputtext) < 6 || strlen(inputtext) > 15) 
			{ 
                 new dialog[380+24+10];
                format(dialog, sizeof(dialog),
				"Добро пожаловать на Сервер!\n\
				Этот аккаунт не зарегистрирован.\n\n\
				Логин: %s\n\
				Введите пароль и нажмите \"Далее\".\n\n\
				Примечания:\n\
				- Длина пароля от 6 до 15 символов.\n", PlayerInfo[playerid][pName]);
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Регистрация.", dialog, "Далее", "Отмена");
                return 1;
            }
            CreateAccount(playerid, inputtext);
            PlayerInfo[playerid][pLogged] = true;

        }
        case DIALOG_WRONGPAS: 
		{ 
            if(response)
			{
                new dialog[134+MAX_PLAYER_NAME];
                format(dialog, sizeof(dialog),
                    "Добро пожаловать на Сервер!\n\
                    Этот аккаунт зарегистрирован.\n\n\
                    Логин: %s\n\
                    Введите пароль:",
                    PlayerInfo[playerid][pName]);
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Авторизация.", dialog, "Войти", "Отмена");
                return 1;
            }
            else 
			{ 
                Kick(playerid);
                return 1;
            }
        }
    }
    return 1;
} 

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
	return 1;
}
when reg account, info not entered in database. Pls check my script. I dont know where may be error. Sry for my english
Reply
#2

up up up
Reply
#3

Any MySQL errors? Check your mysql_log or server_log. If you can't find any logs, enable mysql_log in OnGameModeInit.
Reply
#4

no logs, but 100% error in pawno code. requests are valid
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)