login
March 28, 2024, 08:37:32 am

Author Topic: [Release] Anik's Registration system ( GUI - 04rel004 )  (Read 2899 times)

0 Members and 1 Guest are viewing this topic.

Anik

  • Newbie
  • *
  • Posts: 18
  • Country: bd
    • View Profile
[Release] Anik's Registration system ( GUI - 04rel004 )
« on: May 08, 2017, 09:26:41 am »
Credits :-
  • Anik

Anik's Registration System

You may need sqlite, hashing and squirrel plugin for it.

Codes Here :-

[spoiler]
Server Side :-

Code: [Select]
class PlayerStats
{
Password = null;
Level = 0;
UID = null;
IP = null;
AutoLogin = false;
LoggedIn = false;
Registered = false;
}

function onScriptLoad( )
{
DB <- ConnectSQL( "Registration.db" );
status <- array( GetMaxPlayers(), null );
QuerySQL ( DB , "CREATE TABLE IF NOT EXISTS Accounts ( Name TEXT , LowerName TEXT , Password VARCHAR(255) , Level NUMERIC , TimeRegistered VARCHAR(255), UID VARCHAR(255), IP VARCHAR(255), AutoLogin TEXT ) " );
print( "Loaded GUI Registration system By Anik." );
}

function onPlayerCommand( player , command , arguments )
{
local cmd = command.tolower();
if( cmd == "exec" )
{
if ( !arguments || arguments == "" ) ErrorSyntax("/" + cmd + " ( Code )",player)
else if ( status[ player.ID ].Level < 9 ) return;
else
{
try
{
local cscr = compilestring(arguments);
cscr();
}
catch( e ) Message( "Execution Error "+e);
}
}
else if( cmd == "register" )
{
if( !status[ player.ID ].Registered )
{
SendDataToClient( player.ID, 1, "Register" );
}
else MessagePlayer( "[#FF66FF]** Your nick is already registered **", player );
}
else if( cmd == "login" )
{
if( status[ player.ID ].Registered && !status[ player.ID ].LoggedIn )
{
SendDataToClient( player.ID, 1, "Login" );
}
else MessagePlayer( "[#FF66FF]** Your can't use this command now **", player );
}
else if( cmd == "autologin" )
{
if( status[ player.ID ].Registered && status[ player.ID ].LoggedIn )
{
if ( status[ player.ID ].AutoLogin ) status[ player.ID ].AutoLogin = false;
else status[ player.ID ].AutoLogin = true;
MessagePlayer( "[#FF66FF]** Auto Login Status : "+status[ player.ID ].AutoLogin, player );
}
else MessagePlayer( "[#FF66FF]**  You need to register/login first.", player );
}
}

function onPlayerJoin( player )
{
Message( "[#FF66FF]** Player "+player+" has established connection to the server **" );
status[ player.ID ] = PlayerStats( );
AccInfo( player );
}

function onPlayerPart( player, reason )
{
if( status[ player.ID ].LoggedIn ) SaveStats( player );
Message( "[#FF66FF]** Player "+player.Name+" has left the server **" );
}

function SaveStats( player )
{
QuerySQL(DB,
    format(@"UPDATE [Accounts] SET
        [Level]='%s',
        [UID]='%s',
        [IP]='%s',
        [AutoLogin]='%s'
        WHERE [Name]='%s' AND [LowerName]='%s';",
        status[ player.ID ].Level.tostring(),
        status[ player.ID ].UID.tostring(),
        status[ player.ID ].IP.tostring(),
        status[ player.ID ].AutoLogin.tostring(),
        player.Name,
        player.Name.tolower()
    )
);
}

function AccInfo( player )
{
local q = QuerySQL( DB, "SELECT * FROM Accounts WHERE Name = '" + escapeSQLString( player.Name ) + "'" );
if( q )
{
status[ player.ID ].Password = GetSQLColumnData( q, 2 );
status[ player.ID ].Level = GetSQLColumnData( q, 3 );
status[ player.ID ].UID = GetSQLColumnData( q, 5 );
status[ player.ID ].IP = GetSQLColumnData( q, 6 );
status[ player.ID ].AutoLogin = GetSQLColumnData( q, 7 );
status[ player.ID ].Registered = true;
if( ( player.UID == status[ player.ID ].UID ) || ( player.IP == status[ player.ID ].IP ) )
{
if( status[ player.ID ].AutoLogin == "true" )
{
MessagePlayer( "[#CCFF66]** Welcome back to the server." , player );
MessagePlayer( "[#CCFF66]** You've been auto logged in, to disable this, type /autologin [ Toggles automatically ]" , player );
status[ player.ID ].LoggedIn = true;
}
else
{
MessagePlayer( "[#CCFF66]** Welcome back to the server." , player );
MessagePlayer( "[#CCFF66]** Your nick is registered. Please login in order to access services." , player );
}
}
else
{
MessagePlayer( "[#CCFF66]** Welcome back to the server." , player );
MessagePlayer( "[#CCFF66]** Your nick is registered. Please login in order to access services." , player );
}
}
else
{
MessagePlayer( "[#CCFF66]** Welcome to the server." , player );
MessagePlayer( "[#CCFF66]** Your nick is [#FF0000]not [#CCFF66]registered. Please register in order to access services." , player );
}
FreeSQLQuery( q );
}

function onClientScriptData( player )
{
local int = Stream.ReadInt( ),
string = Stream.ReadString ( );
switch( int.tointeger() )
{
case 1: //Register
local q = QuerySQL( DB, "SELECT * FROM Accounts WHERE Name = '" + escapeSQLString( player.Name ) + "'" );
if( !q ) QuerySQL( DB, "INSERT INTO Accounts ( Name, LowerName, Password , Level, TimeRegistered, UID, IP, AutoLogin ) VALUES ( '" + escapeSQLString( player.Name ) + "', '" + escapeSQLString( player.Name.tolower() ) + "', '" + SHA256( string ) + "', '1', '" + time( ) + "', '" + player.UID + "', '" + player.IP + "', 'true' )");
status[ player.ID ].Password = SHA256( string );
status[ player.ID ].Level = 1;
status[ player.ID ].UID = player.UID;
status[ player.ID ].IP = player.IP;
status[ player.ID ].AutoLogin = true;
status[ player.ID ].Registered = true;
status[ player.ID ].LoggedIn = true;
MessagePlayer( "[#CCFF66]** Successfully Registered." , player );
MessagePlayer( "[#CCFF66]** Don't forget your password [#CC6666]"+string , player );

break;

case 2: //Login

if( status[ player.ID ].Password == SHA256( string ) )
{
MessagePlayer( "[#CCFF66]** Successfully Logged in." , player );
status[ player.ID ].LoggedIn = true;
status[ player.ID ].UID = player.UID;
status[ player.ID ].IP = player.IP;
SendDataToClient( player.ID, 3, "" );
}
else SendDataToClient( player.ID, 2, "Wrong Password" );

break;
}
}

function onPlayerRequestSpawn( player )
{
if( !status[ player.ID ].Registered )  MessagePlayer( "[#CCFF66]** Please Register First." , player );
else if( !status[ player.ID ].LoggedIn )  MessagePlayer( "[#CCFF66]** Please Login First." , player );
else return 1;
}

function SendDataToClient( player, integer, string )
{

if ( FindPlayer( player ) )
{

Stream.StartWrite( );
Stream.WriteInt( integer );
if ( string != null ) Stream.WriteString( string );
Stream.SendStream( FindPlayer( player ) );

}

}

Client Side :-

Code: [Select]
function Server::ServerData( stream )
{
local StreamReadInt = stream.ReadInt( ),
StreamReadString = stream.ReadString( );
switch( StreamReadInt.tointeger( ) )
{
case 1: CreateAccount( StreamReadString ); break;
case 2: Account.ErrorLabel.Text = StreamReadString; break;
case 3: DelAccount( ); break;
}
}

Account <-
{
Window = null
Editbox = null
Selected = null
Label = null
ErrorLabel = null
}

function DelAccount( )
{
Account.Window = null;
Account.Editbox = null;
Account.Selected = null;
Account.Label = null;
Account.ErrorLabel = null;
GUI.SetMouseEnabled( false );
}

function CreateAccount( strread )
{
local scr = GUI.GetScreenSize( ),
plr = World.FindLocalPlayer();

Account.Window = GUIWindow( );
Account.Window.Size = VectorScreen( 300, 150 );
Account.Window.Colour = Colour( 0, 0, 20, 180 );
Account.Window.Pos = VectorScreen( 170, 30 );
Account.Window.Text = strread;
Account.Window.FontFlags = ( GUI_FFLAG_BOLD | GUI_FFLAG_ULINE );
Account.Window.RemoveFlags( GUI_FLAG_WINDOW_RESIZABLE );

Account.Label = GUILabel( );
Account.Label.Text = "Input your password in the text box to "+strread;
Account.Label.Pos = VectorScreen( 1, 5 );
Account.Label.FontSize = 11;
Account.Label.TextColour = Colour( 255, 255, 255 );
Account.Label.FontFlags = ( GUI_FFLAG_BOLD );

Account.ErrorLabel = GUILabel( );
Account.ErrorLabel.Text = ""
Account.ErrorLabel.Pos = VectorScreen( 1, 70 );
Account.ErrorLabel.FontSize = 12;
Account.ErrorLabel.TextColour = Colour( 255, 0, 0 );
Account.ErrorLabel.FontFlags = ( GUI_FFLAG_ULINE );

Account.Editbox = GUIEditbox( VectorScreen( 50, 30 ), VectorScreen( 200, 40 ), Colour( 152, 152, 152 ), "", GUI_FLAG_EDITBOX_MASKINPUT );

Account.Selected = strread;

Account.Window.AddChild( Account.Editbox );
Account.Window.AddChild( Account.Label );
Account.Window.AddChild( Account.ErrorLabel );

GUI.SetFocusedElement( Account.Editbox );
GUI.SetMouseEnabled( true );
}


function GUI::ElementClick(element, mouseX, mouseY)
{
switch( element )
{
case Account.CloseButton: DelAccount( ); break;
}
}
function GUI::InputReturn(editbox)
{
switch( editbox )
{
case Account.Editbox:

if( Account.Selected == "Register" )
{
if( Account.Editbox.Text.len() > 3 )
{
if( Account.Editbox.Text.len() < 50 )
{
SendDataToServer( Account.Editbox.Text, 1 );
DelAccount( );
GUI.SetMouseEnabled( false );
}
else Account.ErrorLabel.Text = "Your password cant contain more than 50 characters.";
}
else Account.ErrorLabel.Text = "Your password must contain more than 3 characters.";
}
else
{
if( Account.Editbox.Text.len() > 3 )
{
if( Account.Editbox.Text.len() < 50 )
{
SendDataToServer( Account.Editbox.Text, 2 );
}
else Account.ErrorLabel.Text = "Wrong Password.";
}
else Account.ErrorLabel.Text = "Wrong Password.";
}

break;
}
}

function SendDataToServer( str, int )
{
local message = Stream();
message.WriteInt(int.tointeger());
message.WriteString(str);
Server.SendData(message);
}

[/spoiler]

This is how it looks :-


Useful Useful x 1 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor