Arolis' Register and Login System

Started by AroliS^, Feb 11, 2021, 03:03 AM

Previous topic - Next topic

AroliS^

A multi-lang account system for beginners.


Github: https://github.com/AroliSG/Account-System

Example Script:
[noae][noae][noae][noae]class pAccount {
    HeadShoots      = 0;
    Kills           = 0;
    Deaths          = 0;
    KillingSpree    = 0;
    Bank            = 0;
    Level           = 0;
    IP              = 0.0.0.0;
    UID             = null;
    UID2            = null;

    Reg             = false;
    Log             = false;

    ServerName      = "Blank Server 0.4v";
    Owner           = "LBRr.AroliS^";

    constructor(p, ...) {
        switch (vargv.len())
        {
            case 1: this.ServerName    = vargv [0]; break;
        }

        local q = ::QuerySQL(db, "SELECT * FROM [accounts] WHERE [name] = '" +p.Name+ "'");
        if (!q) {
            ::message.toPlayer (p, "Welcome to %s Server", "Bienvenido a %s Server", [ this.ServerName ]);
            ::message.toPlayer (p, "You are not registered, please proceed to register /register.", "Tu no estas registrado, porfavor procede a registrarse /registrar.");
        }
        else {
            this.Reg            = true;
            if (::GetSQLColumnData (q,3) == p.IP && ::GetSQLColumnData (q,4) == p.UniqueID && ::GetSQLColumnData (q,5) == p.UniqueID2) {
                ::message.toPlayer (p, "Welcome back to %s Server", "Bienvenido devuelta a %s Server", [ this.ServerName ]);

                    this.HeadShoots     = ::GetSQLColumnData(q, 9);
                    this.Kills          = ::GetSQLColumnData(q, 6);
                    this.Deaths         = ::GetSQLColumnData(q, 7);
                    this.KillingSpree   = ::GetSQLColumnData(q, 8);
                    this.Bank           = ::GetSQLColumnData(q, 11);
                    this.Level          = ::GetSQLColumnData(q, 13);
                    p.Cash              = ::GetSQLColumnData(q, 10);

                    this.IP             = p.IP;
                    this.UID            = p.UniqueID;
                    this.UID2           = p.UniqueID2;

                    this.Reg            = true;
                    this.Log            = true;
            }
            else {
                ::message.toPlayer (p, "Welcome back to %s Server", "Bienvenido devuelta a %s Server", [ this.ServerName ]);
                ::message.toPlayer (p, "You are not logged-in, please proceed to logg-in /login.", "Tu no haz ingresado, porfavor procede a ingresar /ingresar.");
            }
        }
    }

    SaveStats = function (p) {
        ::QuerySQL(db, @"UPDATE [accounts] SET [kills] = '" +this.Kills+ "', [deaths] = '" +this.Deaths+ "', [headshoot] = '" +this.HeadShoots+ "', [ip] = '" +p.IP+ "', [uid] = '" +p.UniqueID+ "', [uid2] = '" +p.UniqueID2+ "', "+
        "[killingspree] = '" +this.KillingSpree+ "', [money] = '" +p.Cash+ "', [bank] = '" +this.Bank+ "', [level] = '" +this.Level+ "' WHERE [name] LIKE '" + p.Name + "'" );

        print (p.Name + " quit");
    }
}
[/noae][/noae][/noae][/noae]


I felt in the need to create something useful, for those guys that are looking for a register and login system with a clean and multi-lang code from where to begin.

if you found any bugs, feel free to post it.

database: SQLite
Language: Squirrel

These functions are composes of printable string from a combination of string literals, format placeholders, escape sequences and non-string data values.

placeholders are not necessary as far as you dont use data type.

[noae][noae][noae][noae]message.toAll (msg, msg, ..., [ format placeholders ] ); will send a message to everyone
message.toPlayer (p, msg,msg, ..., [ format placeholders ]); will send a message to player
message.toAllExcept (p, msg, msg, ..., [ format holders ] ); will send a message except to the player expecified
[/noae][/noae][/noae][/noae]

  • vargv points means that more languages can be added
  • how to add them? quick example above.

by accesing to the file called message.nut
  • add a new global variable called by the language name as example turkish romanian etc.
  • go down to the function named Insert.
  • add a new [else if] and continue by yourself after this point.

[noae][noae][noae][noae]   
 // inserting data to our data
    Insert = function (player) {
        local e = null;
        if (spanish.find (IpToCountry (player.IP)) != null) e = 2;
        else e = 1; //pre-difining lang english as default if the player is not from any spanish country.

        this.pLang.rawset (player.ID, e);
    }
[/noae][/noae][/noae][/noae]

The function uses the standard C language printf format placeholders though not all of these are relevant to Squirrel's data types. Those that are are listed in the table below:

Code   Data Type   Description
  • %x   Integer   Presents a hexadecimal number with lower-case letters
  • %X   Integer   Presents a hexadecimal number with upper-case letters
  • %o   Integer   Presents an octal number
  • %u   Integer   Presents an unsigned decimal value
  • %i   Integer   Presents a signed decimal value
  • %d   Integer   Presents a signed decimal value
  • %f   Float   Presents a decimal value in floating-point format
  • %e   Float   Presents a decimal value in scientific notation
  • %g   Float   Use the shortest representation: %e or %f
  • %s   String   Presents a string
  • %c   Integer   Presents an integer value as a character
  • %%   N/A   Percentage symbol

plugins: xmlconf04rel64 announce04rel64 squirrel04rel64 sqlite04rel64 hashing04rel64

Happy coding by your good friend Arolis <3
Lemme love ya