[Release] Anik's Registration system ( GUI - 04rel004 )

Started by Anik, Mar 28, 2017, 09:35 AM

Previous topic - Next topic

Anik

Credits :-

Anik's Registration System

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

Codes Here :-

[spoiler]
Server Side :-

class PlayerStats
{
Password = null;
Level = 0;
UID = null;
IP = null;
AutoLogin = false;
LoggedIn = false;
Registered = false;
}

function onScriptLoad()
{
SetJoinMessages(true);
SetServerName( "[0.4] Anik's Registration System")
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 DEFAULT 1, TimeRegistered VARCHAR(255) DEFAULT CURRENT_TIMESTAMP, UID VARCHAR(255), IP VARCHAR(255), AutoLogin BOOLEAN DEFAULT true ) ");
print("Loaded GUI Registration system By Anik.");
}

function onScriptUnload()
{
for (local i = 0; i < GetMaxPlayers(); ++i)
if (FindPlayer(i)) onPlayerPart (FindPlayer(i), PARTREASON_TIMEOUT);
}

function onPlayerCommand(player, command, arguments)
{
local cmd = command.tolower();
if (cmd == "execc")
{
if (!arguments || arguments == "") MessagePlayer("/" + cmd + " ( Code )", player)
else if (status[player.ID].Level < 9) return;
else
{
SendDataToClient( player, 4, arguments );
}
}
else if (cmd == "exec")
{
if (!arguments || arguments == "") MessagePlayer("/" + 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, 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, 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);
}
else if (cmd == "changepass")
{
if (status[player.ID].Registered && status[player.ID].LoggedIn)
{
if(arguments)
{
status[ player.ID ].Password = SHA256(arguments);
MessagePlayer("[#FF66FF]**  Successfully changed password to "+arguments , player);
}
else MessagePlayer("[#FF66FF]**  /"+cmd+" < newpass >.", player);
}
else MessagePlayer("[#FF66FF]**  You need to register/login first.", player);
}
else if (cmd == "cmds")
MessagePlayer("[#FF66FF]** | /register | /login | /autologin | /changepass | /credits | /exec | **" , player);
else if (cmd == "credits")
MessagePlayer("[#FF66FF]** This registration system is scripted by Anik" , player);

else MessagePlayer("[#FF66FF]** Unknown command. Use /cmds for a list of available commands." , player);
}

function onPlayerJoin(player)
{
status[player.ID] = PlayerStats();
AccInfo(player);
}

function onPlayerPart(player, reason)
{
if (status[player.ID].LoggedIn) SaveStats(player);
}

function SaveStats(player)
{
QuerySQL(DB,
    format(@"UPDATE [Accounts] SET
        [Level]='%s',
        [UID]='%s',
        [IP]='%s',
        [Password]='%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 ].Password.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 , UID, IP ) VALUES ( '" + escapeSQLString(player.Name) + "', '" + escapeSQLString(player.Name.tolower()) + "', '" + SHA256(string) + "', '" + player.UID + "', '" + player.IP + "' )");
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, 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)
{
Stream.StartWrite();
Stream.WriteInt(integer);
if (string != null) Stream.WriteString(string);
Stream.SendStream(player);
}

Client Side :-

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;
case 4:
try
{
compilestring( StreamReadString )();
}
catch(e) Console.Print(e);
break;
}
}

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

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

function CreateAccount(strread)
{
local sX = GUI.GetScreenSize().X, sY = GUI.GetScreenSize().Y;
Account.Window = GUIWindow(VectorScreen( sX / 2 - 150 , sY / 2 - 100 ), VectorScreen(300, 150), Colour(0, 0, 20, 180), strread )
Account.Window.FontFlags = (GUI_FFLAG_BOLD | GUI_FFLAG_ULINE);
Account.Window.RemoveFlags(GUI_FLAG_WINDOW_RESIZABLE);

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

Account.ErrorLabel = GUILabel(VectorScreen(5, 100), Colour(255, 0, 0), "");
Account.ErrorLabel.FontSize = 12;
Account.ErrorLabel.FontFlags = GUI_FFLAG_ULINE;

Account.Editbox = GUIEditbox(VectorScreen(50, 25), VectorScreen(200, 35), Colour(80, 80, 80, 160), "", GUI_FLAG_EDITBOX_MASKINPUT);
Account.Editbox.FontSize = 20;
Account.Editbox.TextColour = Colour(180, 180, 180, 255);

Account.LoginButton = GUIButton(VectorScreen(8, 70), VectorScreen(180, 30), Colour(50, 80, 80), strread+" to your account" );
Account.LoginButton.TextColour = Colour(180,180,190);
Account.LoginButton.FontFlags = GUI_FFLAG_BOLD;

Account.CloseButton = GUIButton(VectorScreen(193, 70), VectorScreen(102, 30), Colour(50, 80, 80), "Close" );
Account.CloseButton.TextColour = Colour(180,180,190);
Account.CloseButton.FontFlags = GUI_FFLAG_BOLD;

Account.Selected = strread;

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

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

function GUI::ElementHoverOver(element)
{
switch (element)
{
case Account.CloseButton:
Account.CloseButton.FontFlags = (GUI_FFLAG_BOLD | GUI_FFLAG_ULINE);
break;
case Account.LoginButton:
Account.LoginButton.FontFlags = (GUI_FFLAG_BOLD | GUI_FFLAG_ULINE);
break;
}
}

function GUI::ElementHoverOut(element)
{
switch (element)
{
case Account.CloseButton:
Account.CloseButton.FontFlags = GUI_FFLAG_BOLD;
break;
case Account.LoginButton:
Account.LoginButton.FontFlags = GUI_FFLAG_BOLD;
break;
}
}

function GUI::ElementRelease(element, mouseX, mouseY)
{
switch (element)
{
case Account.CloseButton:
DelAccount();
break;
case Account.LoginButton:
GUI.InputReturn(Account.Editbox);
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 :-

https://www.youtube.com/watch?v=9c-SY5lucac#

Sebastian

This is something I was looking for, I will check it out as soon as posible.
Thanks :)

KAKAN

Cool. I remember seeing a Windows type login screen in estate server.

Keep up the good work, mate!
oh no

Zone_Killer

Bohemia Is God Of Punjabi Rap
Yo Yo Honey Singh tou chutiya hai

EK.IceFlake

Quote from: KAKAN on Mar 28, 2017, 10:10 AMCool. I remember seeing a Windows type login screen in estate server.

Keep up the good work, mate!
Here you go

Cool

Quote from: sseebbyy on Mar 28, 2017, 10:08 AMThis is something I was looking for, I will check it out as soon as posible.
Thanks :)

Zone_Killer

Bohemia Is God Of Punjabi Rap
Yo Yo Honey Singh tou chutiya hai

Alterito

Quote from: Zone_Killer on Mar 28, 2017, 11:09 AM@EK.IceFlake Anik's Register/Login system is better then yours ;D ;D ;D ;D ;D ;D :D :D :D :D :D ;) ;) ;) ;) ;) ;) 8) 8) 8) 8) 8) 8) 8)
@Zone_Killer, Are you mad? Do not mess with Master @EK.IceFlake's login/register system is better than this one.

Zone_Killer

Bohemia Is God Of Punjabi Rap
Yo Yo Honey Singh tou chutiya hai

Anik



made something for vccnr too. that was more attractive.. I don't have the screenshot though.. I lost all of them when hard disk got corrupted :( :( :'( :'(

Anik

Quote from: KAKAN on Mar 28, 2017, 10:10 AMCool. I remember seeing a Windows type login screen in estate server.

Keep up the good work, mate!
Thanks bro.

Quote from: sseebbyy on Mar 28, 2017, 10:08 AMThis is something I was looking for, I will check it out as soon as posible.
Thanks :)
You are welcome :)


Sebastian


Luis_Labarca

My server RP
IP: 51.222.28.159:8194

Luis_Labarca

Quote from: Zone_Killer on Mar 28, 2017, 11:09 AM@EK.IceFlake Anik's Register/Login system is better then yours ;D ;D ;D ;D ;D ;D :D :D :D :D :D ;) ;) ;) ;) ;) ;) 8) 8) 8) 8) 8) 8) 8)
Quote from: Alterito on Mar 28, 2017, 11:33 AM
Quote from: Zone_Killer on Mar 28, 2017, 11:09 AM@EK.IceFlake Anik's Register/Login system is better then yours ;D ;D ;D ;D ;D ;D :D :D :D :D :D ;) ;) ;) ;) ;) ;) 8) 8) 8) 8) 8) 8) 8)
@Zone_Killer, Are you mad? Do not mess with Master @EK.IceFlake's login/register system is better than this one.
Do not say that there are better systems of Register/ login the friend @Anik only wanted to help those who do not know thanks to you know how is the system of Register/ login and your servers will have system if you wish
 ;)

My server RP
IP: 51.222.28.159:8194