Need some help here i've been struggling
when i use register command , it does register the account , the account also gets saved on the database with player's nick, but if player rejoin server , it will ask him to register again, and if it does then it'll just create another account on database with same nick, but problem still there , every time player joins the server it will ask him to re register again and again
if ( cmd == "register" )
{
if ( db_account[ player.ID ].Registed == true ) ePrivMessage( "[Error] - You're Already Registered!", player );
else if ( !text ) ePrivMessage( "[Syntax] - /" + cmd + " <Password>", player );
else
{
Register( player, text );
}
}
function Register( player, password )
{
local pass = ::SHA256(password);
QuerySQL( db, "INSERT INTO Account ( Name, IP, Level, Pass, Kills, Deaths, Cash, Bank, Joins, nogoto, DateRegistered, WonLMS, RandSpawn ) VALUES ( '" + player.Name.tolower() + "', '" + player.IP + "', 1, '" + pass + "', 0, 0, 0, 0, 0, 'off', '" + GetFullTime() + "', 0, 'on' )" );
db_account[ player.ID ].Logged = true;
db_account[ player.ID ].Reg = true;
ClientMessage( " Congratz , your account is been successfully registered", player,250,107,222 );
ClientMessage( " Remember your pass: [#FFFFFF][" + password + "]", player,250,107,222 );
ClientMessage( " you have recived 1000 cash", player,250,107,222 );
IncCash( player, 1000 );
}
function IncCash( player, amount )
{
local cash = db_account[ player.ID ].Cash;
local add = cash + amount;
db_account[ player.ID ].Cash = add;
player.Cash = add;
}
This problem happens because the server is not detecting if the name is registered add AccInfo (player) to onPlayerJoin( player )
example
function onPlayerJoin( player )
{
if(db_account[player.ID]!=null)db_account[player.ID]=null;
db_account[player.ID]=PlayerStats();
AccInfo( player )
}
And add these functions
function onPlayerJoin( player )
{
//if(db_account[player.ID]!=null)db_account[player.ID]=null;
//db_account[player.ID]=PlayerStats();
AccInfo( player )
}
function AccInfo( p )
{
local player = FindPlayer( p );
if ( player )
{
// db_account[ player.ID ] = PlayerStats(); ---
if ( GetLevel(player) >= 1 )
{
if ( player.IP != GetIP( player ) )
{
MessagePlayer("[#ffffff]Connect to your account",player);
MessagePlayer("[#ffffff] Use: /login [ Password ]",player);
db_account[ player.ID ].Logged = false;
db_account[ player.ID ].Reg = true;
else if ( player.IP == GetIP( player ) )
{
local q = QuerySQL( db, "SELECT * FROM Account WHERE Name LIKE '" + player.Name + "'" );
db_account[ player.ID ].Level = GetSQLColumnData( q, 2 );
db_account[ player.ID ].Kills = GetSQLColumnData( q, 4 );
db_account[ player.ID ].Deaths = GetSQLColumnData( q, 5 );
db_account[ player.ID ].Cash = GetSQLColumnData( q, 6 );
db_account[ player.ID ].Bank = GetSQLColumnData( q, 7 );
db_account[ player.ID ].Logged = true;
db_account[ player.ID ].Reg = true;
MessagePlayer("[#ffffff]You have automatically connected",player);
MessagePlayer("[#ffffff]Name : [ " + player.Name + " ] Level : " + db_account[ player.ID ].Level + " ]",player);
}
}
else
{
MessagePlayer("[#ffffff]Register to access the commands",player);
MessagePlayer("[#ffffff]/Register [ Password ].",player);
}
}
}
}
function GetLevel( player )
{
local result = GetSQLColumnData( QuerySQL( db, "SELECT Level FROM Account WHERE Name='" + player.Name + "'" ), 0 ), lvl;
if ( result == null ) lvl = GetSQLColumnData( QuerySQL( db, "SELECT Level FROM Account WHERE Name LIKE '" + player.Name + "'" ), 0 );
else lvl = result;
if ( lvl ) return lvl;
else return 0;
}
function GetIP( player )
{
local result = GetSQLColumnData( QuerySQL( db, "SELECT IP FROM Account WHERE Name='" + player.Name + "'" ), 0 ), ip;
if ( result == null ) ip = GetSQLColumnData( QuerySQL( db, "SELECT IP FROM Account WHERE Name LIKE '" + player.Name + "'" ), 0 );
else ip = result;
if ( ip ) return ip;
else return 0;
}
i have that also , see, it registered a few accounts with no problems , around 7, and those work fine , but then all of a sudden it started acting up
this is my on player join
function onPlayerJoin( player )
{
::AddAlias( player );
local country = geoip_country_name_by_addr(player.IP),msg;
if ( CheckPBan( player ) == 1 )
{
if ( BanNick[player.ID] != null )
{
local q = QuerySQL( db, "SELECT * FROM PBan WHERE Name='" + BanNick[player.ID] + "'" );
if (q) Message( "*** "+player.Name+" ] fue expulzado por:[ " + GetSQLColumnData( q, 2 ) + " ].");
else Message( "*** "+player.Name+" fue expulzado por que su coneccion fue baneada del servidor.");
MessagePlayer( msg.W + " your connection was banned from server", player );
MessagePlayer( msg.W + " you must do a ban appel at, www.test.com", player );
MessagePlayer( msg.W + " your current ip: " + player.IP + " your nick: " + player.Name + "- good bye.", player );
MessagePlayer( msg.I + " www.test.com", player );
FreeSQLQuery( q );
}
else Message( "*** "+player.Name+" was kicked , player is banned.");
KickPlayer( player );
}
if ( NickBanned[player.ID] != null )
{
if ( CheckBanState( player, "true", NickBanned[player.ID] ) == 1 )
{
if ( BanNick[player.ID] != null )
{
local q = QuerySQL( db, "SELECT * FROM PBan WHERE Name='" + BanNick[player.ID] + "'" );
if (q) Message( "*** "+player.Name+" banned due to:[ " + GetSQLColumnData( q, 2 ) + " ].");
FreeSQLQuery( q );
}
else
{
Message( "*** "+player.Name+" player is currently banned.");
}
KickPlayer( player );
}
}
::AccInfo( player );
LoadSpawnwep(player);
EchoMessage( "\x000313 -> "+ player.Name+" Established connection from " + country + ". [" + geoip_country_code_by_addr(player.IP) + "].");
}
and right here is my accinfo function
function AccInfo( player )
{
db_account[ player.ID ] = Info();
local id = player.ID;
local ip = player.IP;
if ( GetLevel( player ) >= 1 )
{
if ( ip != GetIP( player ) )
{
ClientMessage( " Welcome Back " + player.Name + " ", player,250,107,222 );
ClientMessage( " you have to login before you spawn", player,250,107,222 );
ClientMessage( " use command /login <pass>", player,250,107,222 );
db_account[ player.ID ].Registed = true;
db_account[ player.ID ].Logged = false;
}
else if ( ip == GetIP( player ) )
{
local q = QuerySQL( db, "SELECT * FROM Account WHERE Name='" + player.Name.tolower() + "'" );
if ( GetSQLColumnData( q, 0 ) != null )
{
db_account[ player.ID ].Level = GetSQLColumnData( q, 2 );
db_account[ player.ID ].Kills = GetSQLColumnData( q, 4 );
db_account[ player.ID ].Deaths = GetSQLColumnData( q, 5 );
db_account[ player.ID ].Cash = GetSQLColumnData( q, 6 );
db_account[ player.ID ].Bank = GetSQLColumnData( q, 7 );
db_account[ player.ID ].Joins = GetSQLColumnData( q, 8 );
}
GetSQLNextRow( q );
if ( db_account[ player.ID ].Level > 2 ) ::MessagePlayer( msg.W + " Your Account Was Succesfully identified as Admin - Level:[ " + db_account[ player.ID ].Level + " ]", player );
ClientMessage( " Welcome Back " + player.Name + " ", player,250,107,222 );
ClientMessage( " Your account was successfully identified!!", player, 250,107,222 );
ClientMessage( " Current Stats " + db_account[ player.ID ].Kills + " Kills, " + db_account[ player.ID].Bank + " Bank", player,250,107,222 );
db_account[ player.ID ].Registed = true;
db_account[ player.ID ].Logged = true;
db_account[ player.ID ].Joins++;
}
}
else
{
ClientMessage( ">> Welcome " + player.Name + "!", player,250,107,222 );
ClientMessage( " Please register your account on our system", player,250,107,222 );
ClientMessage( " Use /register <pass>", player,250,107,222 );
}
}
here's a pic from database , where u can see how many times i've registered that dummy account , and still was asking me to re register it
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2Fv74vbha.jpg&hash=7ca94c0213ceed3fe48f364ba3a6a528d64c0e78)
and problem here is that for this bugged accounts , on database it saves with level 0 , instead of level 1.
Wut?
QuerySQL( db, "INSERT INTO Account ( Name, IP, Level, Pass, Kills, Deaths, Cash, Bank, Joins, nogoto, DateRegistered, WonLMS, RandSpawn ) VALUES ( '" + player.Name.tolower() + "', '" + player.IP + "', 1, '" + pass + "', 0, 0, 0, 0, 0, 'off', '" + GetFullTime() + "', 0, 'on' )" );
use this for change level:
QuerySQL( db, "INSERT INTO Account ( Name, IP, Level, Pass, Kills, Deaths, Cash, Bank, Joins, nogoto, DateRegistered, WonLMS, RandSpawn ) VALUES ( '" + player.Name.tolower() + "', '" + player.IP + "', '1', '" + pass + "', '0', '0', '0', '0', '0', 'off', '" + GetFullTime() + "', '0', 'on' )" );
, 1, to , '1',
And look at this
if( cmd == "register" ){
if( !text ){
MessagePlayer( "Syntax Error!", player );
MessagePlayer( "Correct syntax: /register <password>", player );
}
else if( pstats[ player.ID ].Level != 0 )MessagePlayer( " This account is already Registered", player );
else if( pstats[ player.ID ].Logged == true ){
MessagePlayer( "You are already logged in.", player );
}
else{
pstats[ player.ID ].Register( player, text, sqliteDB );
}
}
even though i added the '1' instead of 1 ,
QuerySQL( db, "INSERT INTO Account ( Name, IP, Level, Pass, Kills, Deaths, Cash, Bank, Joins, nogoto, DateRegistered, WonLMS, RandSpawn ) VALUES ( '" + player.Name.tolower() + "', '" + player.IP + "', '1', '" + pass + "', '0', '0', '0', '0', '0', 'off', '" + GetFullTime() + "', '0', 'on' )" );
database still saving account with level 0
Inside register function, you are setting this:
db_account[ player.ID ].Reg = true;
While in command, you are checking this:
db_account[ player.ID ].Registed == true
Is that the way it was meant to be ?
yeah i noticed that mistake , and fixed it , but the situation is this one , and it seems thats the only problem.
accounts are getting saved in database with level 0 , instead of 1, and because of that , its always askin to re register the account , because when it gets saved , it wont add level 1, now if i update the level on database from 0 to 1 , everything goes fine
but it wont set account's level to 1 since the begining, so thats the problem
example use in your function register
Stats[player.ID].Level = 1;
Quote from: kennedyarz on May 19, 2017, 10:01 PMexample use in your function register
Stats[player.ID].Level = 1;
Please add #braindonor.
Quote from: sseebbyy on May 19, 2017, 10:03 PMQuote from: kennedyarz on May 19, 2017, 10:01 PMexample use in your function register
Stats[player.ID].Level = 1;
Please add #braindonor.
I'm just not understanding the boy
Quote from: kennedyarz on May 19, 2017, 10:13 PMI'm just not understanding the boy
Database won't set registered players' level to 0
no sseebbyy , that's the whole problem ,
QuerySQL( db, "INSERT INTO Account ( Name, IP, Level, Pass, Kills, Deaths, Cash, Bank, Joins, nogoto, DateRegistered, WonLMS, RandSpawn ) VALUES ( '" + player.Name.tolower() + "', '" + player.IP + "', '1', '" + pass + "', '0', '0', '0', '0', '0', 'off', '" + GetFullTime() + "', '0', 'on' )" );
when player registers the account , it suppose to add the value 1 as level on database
but it doesn't . instead of setting player's level to 1 on database it sets the level to value 0
and because of that reason script keeps asking to re register the account .
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FqRE8k9X.jpg&hash=635cd47c2c11cc4ddbcf5b17fd75aca9e41eccb7)
Well, just a quick thought, while reading this topic:
Did you set the 'Name' column as UNIQUE, while creating the table (there should not be multiple instances of the same nickname, isn't it)?