Hello Guyz can some one teach me ?

Started by =RK=MarineForce, Sep 21, 2018, 10:42 AM

Previous topic - Next topic

=RK=MarineForce

how can i make register and login system? with database?


=RK=MarineForce

#2
class PlayerStats
{
login = false;
register = false;
}

function onScriptLoad()
{
db <- ConnectSQL( "DataBase.db" );
QuerySQL( db, "CREATE TABLE IF NOT EXISTS Stats ( Name VARCHAR(32), IP VARCHAR(25), Admin TEXT, Reason TEXT )" );

database<- ConnectSQL( "database.db" );
QuerySQL( database, "CREATE TABLE IF NOT EXISTS Stats ( player VARCHAR(255), password VARCHAR(255), uid VARCHAR(255) " );
Stats <- array(GetMaxPlayers(), null);
print("Register,Login System Has Been Loaded by MarineForce");
}

function onScriptUnload()
{
DisconnectSQL( db );
DisconnectSQL( database );
}

function onPlayerJoin( player )
{
Stats[player.ID] = PlayerStats();
Message(" " + player.Name + " Has Joined The server  : " + player.IP + " ");

}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "register" )
{
  if ( ( Stats[ player.ID ].register ) || ( Stats[ player.ID ].login ) ) PrivMessage( player, "Error: You are already registered." );
  else if ( !text ) PrivMessage( player, format( "Error: Use /%s <password>", cmd ) );
  else
  {
   QuerySQL( database, "INSERT INTO Stats ( player, password, uid) VALUES ( '" + player.Name.tolower() + "', '" + SHA256( text ) + "', '" + player.UniqueID + "', '0', '0', '0', '1', '0', '1', 'on' )" );
   Stats[player.ID].register = true;
   Stats[player.ID].login = true;
   PrivMessage( player, format( "You have been successfully registered! Nickname:[ %s ] Password:[ %s ]", player.Name, text ) );
   MessageAllExcept( format( "[#00FF00]>> %s has been successfully registered.", player.Name ), player );
  }
}

else if ( cmd == "login" )
{
  if ( Stats[ player.ID ].login ) PrivMessage( player, "Error: You are already logged-in." );
  else if ( !text ) PrivMessage( player, format( "Error: Use /%s <password>", cmd ) );
  else if ( SHA256( text ) != GetSQLColumnData( QuerySQL( database, "SELECT password FROM Stats WHERE player = '" + player.Name.tolower() + "'" ), 0 ) ) PrivMessage( player, "INVALID PASSWORD." );
  else
  {
   local query = QuerySQL( database, "SELECT * FROM Stats WHERE player = '" + player.Name.tolower() + "'" );
   if ( query )
   {
   Stats[player.ID].register = true;
   Stats[player.ID].login = true;
   Message(" Welcome Back To Server " + player.Name + " ");
   }
   else PrivMessage( player, "wtf" );
  }
}
}
its not save the data when i quit. Commands Made by =TRC=Kelvin. i can but i need to know about steps.

///if i learn this thing i hope i will make my own Account System :P

///Some Things From Kelvin aCCOUNT system which i don't understand its only in cmd

Can u tell me, how to use it and what is . it

//what is GetSQLColumnData ??? and tolower

 ' + player.Name.tolower()+"' ");  what it Tolower?

I know QuerySQL( database, "SELECT password FROM Stats WHERE player  = ' " +
//else if ( SHA256( text ) != GetSQLColumnData( QuerySQL( database, "SELECT password FROM account WHERE player = '" + player.Name.tolower() + "'" ), 0 ) ) PrivMessage( player, "INVALID PASSWORD." );
// QuerySQL( database, "INSERT INTO Stats ( player, password, uid)
 //  VALUES ( '" + player.Name.tolower() + "', '" + SHA256( text ) + "', '" + player.UniqueID + "', '0', '0', '0', '1', '0', '1', 'on' )" );

Mahmoud Tornado

GetSQLColumnData
Tolower
"The C library function int tolower(int c) converts a given letter to lowercase."

D4rkR420R

[noae]
Quote from: =RK=MarineForce on Sep 21, 2018, 01:53 PMclass PlayerStats
{
login = false;
register = false;
}

function onScriptLoad()
{
db <- ConnectSQL( "DataBase.db" );
QuerySQL( db, "CREATE TABLE IF NOT EXISTS Stats ( Name VARCHAR(32), IP VARCHAR(25), Admin TEXT, Reason TEXT )" );

database<- ConnectSQL( "database.db" );
QuerySQL( database, "CREATE TABLE IF NOT EXISTS Stats ( player VARCHAR(255), password VARCHAR(255), uid VARCHAR(255) " );
Stats <- array(GetMaxPlayers(), null);
print("Register,Login System Has Been Loaded by MarineForce");
}

function onScriptUnload()
{
DisconnectSQL( db );
DisconnectSQL( database );
}

function onPlayerJoin( player )
{
Stats[player.ID] = PlayerStats();
Message(" " + player.Name + " Has Joined The server  : " + player.IP + " ");

}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "register" )
{
  if ( ( Stats[ player.ID ].register ) || ( Stats[ player.ID ].login ) ) PrivMessage( player, "Error: You are already registered." );
  else if ( !text ) PrivMessage( player, format( "Error: Use /%s <password>", cmd ) );
  else
  {
   QuerySQL( database, "INSERT INTO Stats ( player, password, uid) VALUES ( '" + player.Name.tolower() + "', '" + SHA256( text ) + "', '" + player.UniqueID + "', '0', '0', '0', '1', '0', '1', 'on' )" );
   Stats[player.ID].register = true;
   Stats[player.ID].login = true;
   PrivMessage( player, format( "You have been successfully registered! Nickname:[ %s ] Password:[ %s ]", player.Name, text ) );
   MessageAllExcept( format( "[#00FF00]>> %s has been successfully registered.", player.Name ), player );
  }
}

else if ( cmd == "login" )
{
  if ( Stats[ player.ID ].login ) PrivMessage( player, "Error: You are already logged-in." );
  else if ( !text ) PrivMessage( player, format( "Error: Use /%s <password>", cmd ) );
  else if ( SHA256( text ) != GetSQLColumnData( QuerySQL( database, "SELECT password FROM Stats WHERE player = '" + player.Name.tolower() + "'" ), 0 ) ) PrivMessage( player, "INVALID PASSWORD." );
  else
  {
   local query = QuerySQL( database, "SELECT * FROM Stats WHERE player = '" + player.Name.tolower() + "'" );
   if ( query )
   {
   Stats[player.ID].register = true;
   Stats[player.ID].login = true;
   Message(" Welcome Back To Server " + player.Name + " ");
   }
   else PrivMessage( player, "wtf" );
  }
}
}
its not save the data when i quit. Commands Made by =TRC=Kelvin. i can but i need to know about steps.

///if i learn this thing i hope i will make my own Account System :P

///Some Things From Kelvin aCCOUNT system which i don't understand its only in cmd

Can u tell me, how to use it and what is . it

//what is GetSQLColumnData ??? and tolower

 ' + player.Name.tolower()+"' ");  what it Tolower?

I know QuerySQL( database, "SELECT password FROM Stats WHERE player  = ' " +
//else if ( SHA256( text ) != GetSQLColumnData( QuerySQL( database, "SELECT password FROM account WHERE player = '" + player.Name.tolower() + "'" ), 0 ) ) PrivMessage( player, "INVALID PASSWORD." );
// QuerySQL( database, "INSERT INTO Stats ( player, password, uid)
 //  VALUES ( '" + player.Name.tolower() + "', '" + SHA256( text ) + "', '" + player.UniqueID + "', '0', '0', '0', '1', '0', '1', 'on' )" );
[/noae]

Haven't you written a code where it'll update the player's statistics into the database on the onPlayerPart event?

=RK=MarineForce


Mahmoud Tornado

[noae]
Quote from: KuRuMi^ on Sep 22, 2018, 06:57 AM[noae]
Quote from: =RK=MarineForce on Sep 21, 2018, 01:53 PMclass PlayerStats
{
login = false;
register = false;
}

function onScriptLoad()
{
db <- ConnectSQL( "DataBase.db" );
QuerySQL( db, "CREATE TABLE IF NOT EXISTS Stats ( Name VARCHAR(32), IP VARCHAR(25), Admin TEXT, Reason TEXT )" );

database<- ConnectSQL( "database.db" );
QuerySQL( database, "CREATE TABLE IF NOT EXISTS Stats ( player VARCHAR(255), password VARCHAR(255), uid VARCHAR(255) " );
Stats <- array(GetMaxPlayers(), null);
print("Register,Login System Has Been Loaded by MarineForce");
}

function onScriptUnload()
{
DisconnectSQL( db );
DisconnectSQL( database );
}

function onPlayerJoin( player )
{
Stats[player.ID] = PlayerStats();
Message(" " + player.Name + " Has Joined The server  : " + player.IP + " ");

}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "register" )
{
  if ( ( Stats[ player.ID ].register ) || ( Stats[ player.ID ].login ) ) PrivMessage( player, "Error: You are already registered." );
  else if ( !text ) PrivMessage( player, format( "Error: Use /%s <password>", cmd ) );
  else
  {
   QuerySQL( database, "INSERT INTO Stats ( player, password, uid) VALUES ( '" + player.Name.tolower() + "', '" + SHA256( text ) + "', '" + player.UniqueID + "', '0', '0', '0', '1', '0', '1', 'on' )" );
   Stats[player.ID].register = true;
   Stats[player.ID].login = true;
   PrivMessage( player, format( "You have been successfully registered! Nickname:[ %s ] Password:[ %s ]", player.Name, text ) );
   MessageAllExcept( format( "[#00FF00]>> %s has been successfully registered.", player.Name ), player );
  }
}

else if ( cmd == "login" )
{
  if ( Stats[ player.ID ].login ) PrivMessage( player, "Error: You are already logged-in." );
  else if ( !text ) PrivMessage( player, format( "Error: Use /%s <password>", cmd ) );
  else if ( SHA256( text ) != GetSQLColumnData( QuerySQL( database, "SELECT password FROM Stats WHERE player = '" + player.Name.tolower() + "'" ), 0 ) ) PrivMessage( player, "INVALID PASSWORD." );
  else
  {
   local query = QuerySQL( database, "SELECT * FROM Stats WHERE player = '" + player.Name.tolower() + "'" );
   if ( query )
   {
   Stats[player.ID].register = true;
   Stats[player.ID].login = true;
   Message(" Welcome Back To Server " + player.Name + " ");
   }
   else PrivMessage( player, "wtf" );
  }
}
}
its not save the data when i quit. Commands Made by =TRC=Kelvin. i can but i need to know about steps.

///if i learn this thing i hope i will make my own Account System :P

///Some Things From Kelvin aCCOUNT system which i don't understand its only in cmd

Can u tell me, how to use it and what is . it

//what is GetSQLColumnData ??? and tolower

 ' + player.Name.tolower()+"' ");  what it Tolower?

I know QuerySQL( database, "SELECT password FROM Stats WHERE player  = ' " +
//else if ( SHA256( text ) != GetSQLColumnData( QuerySQL( database, "SELECT password FROM account WHERE player = '" + player.Name.tolower() + "'" ), 0 ) ) PrivMessage( player, "INVALID PASSWORD." );
// QuerySQL( database, "INSERT INTO Stats ( player, password, uid)
 //  VALUES ( '" + player.Name.tolower() + "', '" + SHA256( text ) + "', '" + player.UniqueID + "', '0', '0', '0', '1', '0', '1', 'on' )" );
[/noae]

Haven't you written a code where it'll update the player's statistics into the database on the onPlayerPart event?
[/noae]
I can remember that, @KuRuMi^ . ^-^

D4rkR420R

Quote from: =RK=MarineForce on Sep 22, 2018, 01:45 PMonplayerpart{PlayerStats();} ?

What is it that you want to store in the database based from the player's statistics?

Mahmoud Tornado

Make SaveStats function!.

QuerySQL( database, "UPDATE Players SET Cash='"+Stats[ player.ID ].Cash+"',Bank='"+Stats[ player.ID ].Bank+"' WHERE Name LIKE '" + player.Name + "'" );