NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
File Author: Force
VCMP Base Script (VBS)
*/

class CPlayer
{
constructor( account_name )
{
// This will store some basic information about this player so that we can access it at a later date.
local query = ::QuerySQL( database, "SELECT account_id, account_password, account_ip, account_level, registration_date, last_active, vehicles FROM registration WHERE account_name='" + account_name + "'" );

// If there was some data returned from the query, store it.
if ( ::GetSQLColumnData( query, 0 ) )
{
account_id = ::GetSQLColumnData( query, 0 );
account_password = ::GetSQLColumnData( query, 1 );
account_ip = ::GetSQLColumnData( query, 2 );
account_level = ::GetSQLColumnData( query, 3 );
registration_date = ::GetSQLColumnData( query, 4 );
last_active = ::GetSQLColumnData( query, 5 );
vehicles = ::GetSQLColumnData( query, 6 );
}

// And make sure we free the query, we don't want leaky servers now do we.
::FreeSQLQuery( query );
}

function register_player( pPlayer )
{
::PrivMessage( "[VBS] Congratulations! Your account was registered!", pPlayer );

local account_name = pPlayer.Name.tolower();

// Format the query to go into the database
local query = format( "INSERT INTO registration (account_name, name, account_password, account_ip, account_level, registration_date, last_active, vehicles) VALUES('%s', '%s', '%s', '%s', %i, %i, %i, 0)", account_name, pPlayer.Name,
account_password, account_ip, account_level, registration_date, last_active );

// execute the query
::QuerySQL( database, query );

// Now we need to get the players account ID
local query = ::QuerySQL( database, "SELECT account_id FROM registration WHERE account_name='" + account_name + "'" );
account_id = ::GetSQLColumnData( query, 0 );

::FreeSQLQuery( query );
}

function save_player_data()
{
local query = format( "UPDATE registration SET account_ip='%s', last_active=%i, vehicles=%i WHERE account_id=%i", account_ip, time(), vehicles, account_id );

// execute that query dammit willis!
::QuerySQL( database, query );
}

account_id = 0;
account_password = null;
account_level = 0;
account_ip = null;
registration_date = 0;
last_active = 0;
logged_in = false;
vehicles = 0;
}

registrations <- array( GetMaxPlayers() ); // Create the array big enough to hold MAX_PLAYERS info

function registration_initialize()
{
// All we are going to do here is connect to our database
database <- ConnectSQL( "Scripts/VBS/Data/vbs.sqlite" );

if ( database ) print( "[VBS] Successfully connected to the VBS database." );
else print( "[VBS] Unable to connect to the VBS database." );
}

function registration_add_player( pPlayer )
{
local id = pPlayer.ID, szNameLower = pPlayer.Name.tolower();

// Create a new instance of CPlayer so that we can easily reference this players account data as and when we need
registrations[id] = CPlayer( szNameLower );

// Check if the player already has an account on the server
registration_login_check( pPlayer );
}

function registration_del_player( playerid )
{
local pData = registrations[playerid];

// Make sure we save the data for this player if they are logged in
if ( pData.logged_in ) pData.save_player_data();

// Remove any reference of them from our arrays
registrations[playerid] = null;
}

function registration_login_check( pPlayer )
{
local pData = registrations[pPlayer.ID];

if ( pData.account_id )
{
// This person already has an account on this server, good to know!
if ( pData.account_ip != pPlayer.IP )
{
// The players IP has changed since he last joined, get them to login again.
MessagePlayer( "[VBS] Welcome back, " + pPlayer + "! Please login before you spawn.", pPlayer );
Announce( "~y~Login before spawning", pPlayer, 0 );
}
else
{
// This is the same IP that they used the last time they joined, automatically log them in!
MessagePlayer( "[VBS] Welcome back, " + pPlayer + "! You were auto logged-in to your account.", pPlayer );
pData.logged_in = true;
}
}
else
{
// They don't have one, attempt to get the player to register on our shiney new server! :D
PrivMessage( "[VBS] Welcome " + pPlayer + " - you can register your account with /c register <password>", pPlayer );
}
}

function registration_register_player( pPlayer, szPassword )
{
// Congratulations, if you are reading this comment then you are actually trying to figure out what this shit does
// and it's probably a lot more efficient and complex than the crap that you wrote before this!

// Grab the class instance for this player
local pData = registrations[pPlayer.ID];

// If you change this, fuck you, just fuck you. I don't want plain text password databases running around VC-MP noobs.
// I am putting this comment here so that you can't blame me if your password gets hacked because you changed this encryption function call.
pData.account_password = SHA1(szPassword);

pData.account_level = 1; // Set them as a registered player
pData.account_ip = pPlayer.IP; // Store their IP
pData.registration_date = time(); // This isn't really useful but fuck it, I'm storing when they registered, if you have a problem, tough shit!
pData.last_active = time(); // Once again, no real purpose, I'm just doing it!
pData.logged_in = true; // Oh yeh, might wanna tell the script that they are actually logged in :o

// Now we can store all this information to the database, yay o/
pData.register_player( pPlayer );
}

function registration_auto_kick( pPlayer, iReason )
{
// Convert the enum reason into readable text
switch( iReason )
{
case FAILED_TO_LOGIN:
Message( "[VBS] Auto-Kick: " + pPlayer + ", this player has failed to login." );
}

// Remove the player from memory
registrations[pPlayer.ID] = null;

// Kick them from the server.
KickPlayer( pPlayer );
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.