[JS] Basic login system for command levels

Started by Mex, May 12, 2018, 05:52:48 AM

Previous topic - Next topic
May 12, 2018, 05:52:48 AM Last Edit: January 01, 1970, 01:00:00 AM by Guest
var admin = {};

admin.playerNamesData = {};
admin.connectedPlayersData = {};
admin.commandLevels = {};

// players
admin.playerNamesData['username1'] = {};
admin.playerNamesData['username1'].level = 10;
admin.playerNamesData['username1'].password = 'abc';

admin.playerNamesData['secondUsername'] = {};
admin.playerNamesData['secondUsername'].level = 10;
admin.playerNamesData['secondUsername'].password = 'abc';

// commands
admin.commandLevels['commanda'] = 5;
admin.commandLevels['commandb'] = 10;
admin.commandLevels['commandc'] = 11;

// code
function checkPlayerCommandLevel(client, commandName)
{
if(admin.commandLevels[commandName])
{
if(!admin.connectedPlayersData[client.player.name].loggedIn || admin.playerNamesData[client.player.name].level < admin.commandLevels[commandName])
{
outputChatBox("You do not have high enough admin level to use this command!", COLOUR_RED, client);
return false;
}
}
return true;
}

addEventHandler("OnPlayerJoined", (event,client) => {
admin.connectedPlayersData[client.player.name] = {};
});

addEventHandler("OnPlayerQuit", (event,client,reason) => {
admin.connectedPlayersData[client.player.name] = null;
});

addCommandHandler("login", (commandName, args, client) => {
if(admin.playerNamesData[client.player.name])
{
if(args == admin.playerNamesData[client.player.name].password)
{
admin.connectedPlayersData[client.player.name].loggedIn = true;
outputChatBox("You have logged in!", COLOUR_BLUE, client);
}
else
{
outputChatBox("Incorrect password!", COLOUR_RED, client);
}
}
else
{
outputChatBox("Account does not exist!", COLOUR_RED, client);
}
});

addCommandHandler("commanda", (commandName, args, client) => {
if(!checkPlayerCommandLevel(client, commandName))
{
return;
}

outputChatBox("Command a", COLOUR_BLUE, client);
});

addCommandHandler("commandb", (commandName, args, client) => {
if(!checkPlayerCommandLevel(client, commandName))
{
return;
}

outputChatBox("Command b", COLOUR_BLUE, client);
});

addCommandHandler("commandc", (commandName, args, client) => {
if(!checkPlayerCommandLevel(client, commandName))
{
return;
}

outputChatBox("Command c", COLOUR_BLUE, client);
});

March 16, 2022, 10:47:36 AM #1 Last Edit: January 01, 1970, 01:00:00 AM by Guest
how to I add this my gta iv server