News A server update was released on July 20. Server patch notes and downloads are here. Additionally, a client update was released on the same day. Client patch notes are here.
Register Command Not Working Properly

SilentX

  • Newbie
  • Posts: 6
Register Command Not Working Properly
«  »Last edited
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

Code: [Select]
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 );
}
}


Code: [Select]
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 );

}

Code: [Select]
function IncCash( player, amount )
{
      local cash = db_account[ player.ID ].Cash;
  local add = cash + amount;
  db_account[ player.ID ].Cash = add;
  player.Cash = add;
}

Luis_Labarca

  • Sr. Member
  • Hello :D
  • Posts: 275
Re: Reggister Command Not Working Properly
« Reply #1,  »

This problem happens because the server is not detecting if the name is registered add AccInfo (player) to onPlayerJoin( player )

example
Code: [Select]
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

Code: [Select]
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 invite them to .::SkyNet-Real.Life::.
IP: 149.56.143.129:8195

SilentX

  • Newbie
  • Posts: 6
Re: Reggister Command Not Working Properly
« Reply #2,  »Last edited
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
Code: [Select]
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
Code: [Select]
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


kennedyarz

  • Full Member
  • Making American Great Again
  • Posts: 237
Re: Register Command Not Working Properly
« Reply #4,  »Last edited
Wut?

Code: [Select]
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:

Code: [Select]
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

Code: [Select]
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 );
  }
 }

SilentX

  • Newbie
  • Posts: 6
Re: Register Command Not Working Properly
« Reply #5,  »
even though i added the '1' instead of 1 ,

Code: [Select]
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

sseebbyy

  • Wiki Contributor
  • Something like this: hga hga hga
  • Posts: 707
Re: Register Command Not Working Properly
« Reply #6,  »
Inside register function, you are setting this:
Code: [Select]
db_account[ player.ID ].Reg = true;

While in command, you are checking this:
Code: [Select]
db_account[ player.ID ].Registed == true


Is that the way it was meant to be ?

SilentX

  • Newbie
  • Posts: 6
Re: Register Command Not Working Properly
« Reply #7,  »
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

kennedyarz

  • Full Member
  • Making American Great Again
  • Posts: 237

sseebbyy

  • Wiki Contributor
  • Something like this: hga hga hga
  • Posts: 707

kennedyarz

  • Full Member
  • Making American Great Again
  • Posts: 237

sseebbyy

  • Wiki Contributor
  • Something like this: hga hga hga
  • Posts: 707

SilentX

  • Newbie
  • Posts: 6
Re: Register Command Not Working Properly
« Reply #12,  »
no sseebbyy , that's the whole problem ,

Code: [Select]
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 .


T800

  • Newbie
  • Posts: 8
Re: Register Command Not Working Properly
« Reply #13,  »
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)?