Initial commit

This commit is contained in:
VortrexFTW
2020-09-04 15:56:19 -05:00
commit c536fcd6ef
245 changed files with 14997 additions and 0 deletions

722
scripts/server/account.js Normal file
View File

@@ -0,0 +1,722 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: account.js
// DESC: Provides account functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initAccountScript() {
console.log("[Asshat.Account]: Initializing account script ...");
addAccountCommandHandlers();
console.log("[Asshat.Account]: Account script initialized!");
}
// ---------------------------------------------------------------------------
function addAccountCommandHandlers() {
console.log("[Asshat.Account]: Adding account command handlers ...");
let accountCommands = serverCommands.account;
for(let i in accountCommands) {
addCommandHandler(accountCommands[i].command, accountCommands[i].handlerFunction);
}
console.log("[Asshat.Account]: Account command handlers added!");
}
// ---------------------------------------------------------------------------
function loginCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!isClientRegistered(client)) {
messageClientError(client, "Your name is not registered! Use /register to make an account.");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
if(isAccountPasswordCorrect(serverData.clients[client.index].accountData, hashAccountPassword(client.name, params))) {
messageClientError(client, "Incorrect username or password!");
return false;
}
loginSuccess(client);
messageClientSuccess(client, "You have been logged in! Press left CTRL to spawn.");
return true;
}
// ---------------------------------------------------------------------------
function registerCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(isClientRegistered(client)) {
messageClientError(client, "Your name is already registered!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
if(!doesPasswordMeetRequirements(params)) {
return false
}
let accountData = createAccount(client.name, params);
if(!accountData) {
messageClientError(client, "Something went wrong, and your account could not be created!");
messageClientAlert(client, "Asshat Gaming staff have been notified of the problem and will fix it shortly.");
return false;
}
serverData.clients[client.index].accountData = accountData;
messageClientSuccess(client, "Your account has been created!");
messageClientAlert(client, "To play on the server, you will need to make a character.");
}
// ---------------------------------------------------------------------------
function changePasswordCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let splitParams = params.split(" ");
let oldPassword = splitParams[0];
let newPassword = splitParams[1];
if(isAccountPasswordCorrect(serverData.clients[client.index].accountData, hashAccountPassword(client.name, oldPassword))) {
messageClientError(client, "The old password is invalid!");
return false;
}
if(!doesPasswordMeetRequirements(newPassword)) {
messageClientError(client, "The new password must meet the requirements!");
messageClientInfo(client, "Passwords must have at least one capital letter, one lowercase letter, and one number!");
return false;
}
serverData.clients[client.index].accountData.password = hashAccountPassword(serverData.clients[client.index].accountData.name, params);
messageClientSuccess(client, "Your password has been changed!");
}
// ---------------------------------------------------------------------------
function switchCharacterCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
let subAccountId = serverData.clients[client.index].currentSubAccount;
serverData.clients[client.index].subAccounts[subAccountId].spawnPosition = client.player.position;
serverData.clients[client.index].subAccounts[subAccountId].spawnHeading = client.player.heading;
let tempSubAccount = serverData.clients[client.index].subAccounts[subAccountId];
saveSubAccountToDatabase(tempSubAccount);
client.despawnPlayer();
triggerNetworkEvent("ag.connectCamera", client, serverConfig.connectCameraPosition[server.game], serverConfig.connectCameraLookAt[server.game]);
triggerNetworkEvent("ag.showCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin);
}
// ---------------------------------------------------------------------------
function isClientLoggedIn(client) {
let loggedIn = serverData.clients[client.index].loggedIn;
return loggedIn;
}
// ---------------------------------------------------------------------------
function isClientRegistered(client) {
if(serverData.clients[client.index].accountData != false) {
if(serverData.clients[client.index].accountData.databaseId != 0) {
return true;
}
}
return false;
}
// ---------------------------------------------------------------------------
function doesPasswordMeetRequirements(password) {
// Will be added soon
return true;
}
// ---------------------------------------------------------------------------
function isAccountPasswordCorrect(accountData, password) {
if(accountData.password == password) {
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function loadAccountFromName(accountName) {
let dbConnection = connectToDatabase();
if(dbConnection) {
accountName = dbConnection.escapeString(accountName);
let dbQueryString = `SELECT * FROM acct_main WHERE acct_name = '${accountName}' LIMIT 1;`;
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
if(dbQuery.numRows > 0) {
let dbAssoc = dbQuery.fetchAssoc();
let tempAccountData = new serverClasses.accountData(dbAssoc);
dbQuery.free();
return tempAccountData;
}
}
disconnectFromDatabase(dbConnection);
}
return false;
}
// ---------------------------------------------------------------------------
function loadAccountFromId(accountId) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQueryString = `SELECT * FROM acct_main WHERE acct_id = ${accountId} LIMIT 1;`;
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
let dbAssoc = dbQuery.fetchAssoc();
dbQuery.free();
return new serverClasses.accountData(dbAssoc);
}
disconnectFromDatabase(dbConnection);
}
return false;
}
// ---------------------------------------------------------------------------
function loadSubAccountFromName(firstName, lastName) {
let dbConnection = connectToDatabase();
if(dbConnection) {
firstName = dbConnection.escapeString(firstName);
lastName = dbConnection.escapeString(lastName);
let dbQueryString = `SELECT * FROM sacct_main WHERE sacct_name_first = '${firstName}' AND sacct_name_last = '${lastName}' LIMIT 1;`;
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
let dbAssoc = dbQuery.fetchAssoc();
dbQuery.free();
return new serverClasses.subAccountData(dbAssoc);
}
disconnectFromDatabase(dbConnection);
}
return false;
}
// ---------------------------------------------------------------------------
function loadSubAccountFromId(subAccountId) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQueryString = `SELECT * FROM sacct_main WHERE sacct_id = ${subAccountId} LIMIT 1;`;
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
let dbAssoc = dbQuery.fetchAssoc();
dbQuery.free();
return new serverClasses.subAccountData(dbAssoc);
}
disconnectFromDatabase(dbConnection);
}
return false;
}
// ---------------------------------------------------------------------------
function loadSubAccountsFromAccount(accountId) {
let tempSubAccounts = [];
let dbAssoc = false;
if(accountId > 0) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQueryString = `SELECT * FROM sacct_main WHERE sacct_acct = ${accountId};`;
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
while(dbAssoc = dbQuery.fetchAssoc()) {
let tempSubAccount = new serverClasses.subAccountData(dbAssoc);
tempSubAccounts.push(tempSubAccount);
}
dbQuery.free();
}
disconnectFromDatabase(dbConnection);
}
}
return tempSubAccounts;
}
// ---------------------------------------------------------------------------
function getAccountHashingFunction() {
switch(serverConfig.accountPasswordHash.toLowerCase()) {
case "md5":
return module.hashing.md5;
case "sha1":
return module.hashing.sha1;
case "sha224":
return module.hashing.sha224;
case "sha256":
return module.hashing.sha256;
case "sha384":
return module.hashing.sha384;
case "sha512":
return module.hashing.sha512;
case "ripemd128":
return module.hashing.ripemd128;
case "ripemd160":
return module.hashing.ripemd160;
case "ripemd256":
return module.hashing.ripemd256;
case "ripemd320":
return module.hashing.ripemd320;
case "whirlpool":
return module.hashing.whirlpool;
}
}
// ---------------------------------------------------------------------------
function isNameRegistered(name) {
let accountData = loadAccountFromName(name);
if(accountData.databaseId > 0) {
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function hashAccountPassword(name, password) {
let hashFunction = getAccountHashingFunction();
let saltedInfo = saltAccountInfo(name, password);
return hashFunction(saltedInfo);
}
// ---------------------------------------------------------------------------
function saltAccountInfo(name, password) {
// Will be added later
return name + "." + password;
}
// ---------------------------------------------------------------------------
function loginSuccess(client) {
serverData.clients[client.index].loggedIn = true;
triggerNetworkEvent("ag.loginSuccess", client);
}
// ---------------------------------------------------------------------------
function saveAccountToDatabase(accountData) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let safePassword = dbConnection.escapeString(accountData.password);
let safeStaffTitle = dbConnection.escapeString(accountData.staffTitle);
let safeEmailAddress = dbConnection.escapeString(accountData.emailAddress);
//let safeIRCAccount = dbConnection.escapeString(accountData.ircAccount);
let dbQueryString = `UPDATE acct_main SET acct_pass='${safePassword}', acct_settings=${accountData.settings}, acct_staff_flags=${accountData.flags.admin}, acct_staff_title='${safeStaffTitle}', acct_mod_flags=${String(accountData.flags.moderation)}, acct_discord=${String(accountData.discordAccount)}, acct_email='${safeEmailAddress}' WHERE acct_id=${accountData.databaseId}`;
console.log(dbQueryString);
let dbQuery = dbConnection.query(dbQueryString);
//dbQuery.free();
disconnectFromDatabase(dbConnection);
}
}
// ---------------------------------------------------------------------------
function saveSubAccountToDatabase(subAccountData) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQueryString = `UPDATE sacct_main SET sacct_pos_x=${subAccountData.spawnPosition.x}, sacct_pos_y=${subAccountData.spawnPosition.y}, sacct_pos_z=${subAccountData.spawnPosition.z}, sacct_angle=${subAccountData.spawnHeading}, sacct_skin=${subAccountData.skin}, sacct_cash=${subAccountData.cash} WHERE sacct_id=${subAccountData.databaseId}`;
let dbQuery = dbConnection.query(dbQueryString);
//dbQuery.free();
disconnectFromDatabase(dbConnection);
}
}
// ---------------------------------------------------------------------------
function createAccount(name, password, email = "") {
let dbConnection = connectToDatabase();
if(dbConnection) {
let hashedPassword = hashAccountPassword(name, password);
let safeName = dbConnection.escapeString(name);
let safeEmail = dbConnection.escapeString(email);
let dbQuery = dbConnection.query(`INSERT INTO acct_main (acct_name, acct_pass, acct_email) VALUES ('${safeName}', '${hashedPassword}', '${safeEmail}')`);
if(dbConnection.insertId > 0) {
return loadAccountFromId(dbConnection.insertId);
}
}
return false;
}
// ---------------------------------------------------------------------------
function createSubAccount(accountId, firstName, lastName, skinId, dateOfBirth, placeOfOrigin) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let safeFirstName = dbConnection.escapeString(firstName);
let safeLastName = dbConnection.escapeString(lastName);
let safePlaceOfOrigin = dbConnection.escapeString(placeOfOrigin);
let dbQuery = dbConnection.query(`INSERT INTO sacct_main (sacct_acct, sacct_name_first, sacct_name_last, sacct_skin, sacct_origin, sacct_when_born, sacct_pos_x, sacct_pos_y, sacct_pos_z, sacct_cash) VALUES (${accountId}, '${safeFirstName}', '${safeLastName}', ${skinId}, '${safePlaceOfOrigin}', '${dateOfBirth}', ${serverConfig.newCharacter.spawnPosition.x}, ${serverConfig.newCharacter.spawnPosition.y}, ${serverConfig.newCharacter.spawnPosition.z}, ${serverConfig.newCharacter.money})`);
if(dbConnection.insertId > 0) {
return loadSubAccountFromId(dbConnection.insertId);
}
disconnectFromDatabase(dbConnection);
}
return false;
}
// ---------------------------------------------------------------------------
addNetworkHandler("ag.checkLogin", function(client, password) {
let loginAttemptsRemaining = client.getData("ag.loginAttemptsRemaining")-1;
if(isClientLoggedIn(client)) {
//messageClientError(client, "You are already logged in!");
triggerNetworkEvent("ag.loginSuccess", client);
return false;
}
if(!isClientRegistered(client)) {
//messageClientError(client, "Your name is not registered! Use /register to make an account.");
triggerNetworkEvent("ag.showRegistration", client);
return false;
}
if(areParamsEmpty(password)) {
//messageClientError(client, "You must enter a password!");
triggerNetworkEvent("ag.loginFailed", client, "Invalid password! " + String(loginAttemptsRemaining) + " tries remaining.");
return false;
}
if(!isAccountPasswordCorrect(serverData.clients[client.index].accountData, hashAccountPassword(client.name, password))) {
//messageClientError(client, "Invalid password!");
triggerNetworkEvent("ag.loginFailed", client, "Invalid password! " + String(loginAttemptsRemaining) + " tries remaining.");
return false;
}
loginSuccess(client);
if(serverData.clients[client.index].subAccounts.length == 0) {
triggerNetworkEvent("ag.showPrompt", client, "You have no characters. Would you like to make one?", "No characters");
client.setData("ag.prompt", AG_PROMPT_CREATEFIRSTCHAR, false);
} else {
serverData.clients[client.index].currentSubAccount = 0;
let tempSubAccount = serverData.clients[client.index].subAccounts[0];
triggerNetworkEvent("ag.showCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin);
}
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.checkRegistration", function(client, password, confirmPassword, emailAddress) {
console.log("[Asshat.Account]: Checking registration for " + String(client.name));
if(isClientRegistered(client)) {
//messageClientError(client, "Your name is already registered!");
triggerNetworkEvent("ag.showLogin", client);
return false;
}
if(isClientLoggedIn(client)) {
//messageClientError(client, "You are already logged in!");
triggerNetworkEvent("ag.loginSuccess", client);
return false;
}
if(areParamsEmpty(password)) {
triggerNetworkEvent("ag.registrationFailed", client, "Password cannot be blank!");
return false;
}
if(areParamsEmpty(confirmPassword)) {
triggerNetworkEvent("ag.registrationFailed", client, "Password confirm cannot be blank!");
return false;
}
if(areParamsEmpty(emailAddress)) {
triggerNetworkEvent("ag.registrationFailed", client, "Email address cannot be blank!");
return false;
}
if(password != confirmPassword) {
triggerNetworkEvent("ag.registrationFailed", client, "The passwords must match!");
return false;
}
if(!doesPasswordMeetRequirements(password)) {
// Work on this later. Function should return true by default anyway for now.
triggerNetworkEvent("ag.registrationFailed", client, "Password doesn't meet requirements!");
return false
}
if(!isValidEmailAddress(emailAddress)) {
// Work on this later. Function should return true by default anyway for now.
triggerNetworkEvent("ag.registrationFailed", client, "You must put a valid email!");
return false
}
let accountData = createAccount(client.name, password, emailAddress);
if(!accountData) {
triggerNetworkEvent("ag.registrationFailed", client, "Something went wrong. Your account could not be created!");
messageClientAlert(client, "Asshat Gaming staff have been notified of the problem and will fix it shortly.");
return false;
}
serverData.clients[client.index].accountData = accountData;
messageClientSuccess(client, "Your account has been created!");
messageClientAlert(client, "To play on the server, you will need to make a character.");
triggerNetworkEvent("ag.registrationSuccess", client);
triggerNetworkEvent("ag.showPrompt", client, "You have no characters. Would you like to make one?", "No Characters");
client.setData("ag.prompt", AG_PROMPT_CREATEFIRSTCHAR, false);
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.checkNewCharacter", function(client, firstName, lastName, dateOfBirth, placeOfOrigin, skinId) {
if(areParamsEmpty(firstName)) {
triggerNetworkEvent("ag.newCharacterFailed", client, "First name cannot be blank!");
return false;
}
if(areParamsEmpty(lastName)) {
triggerNetworkEvent("ag.newCharacterFailed", client, "Last name cannot be blank!");
return false;
}
if(areParamsEmpty(dateOfBirth)) {
triggerNetworkEvent("ag.newCharacterFailed", client, "Date of birth cannot be blank!");
return false;
}
if(areParamsEmpty(placeOfOrigin)) {
triggerNetworkEvent("ag.newCharacterFailed", client, "Place of origin cannot be blank!");
return false;
}
if(areParamsEmpty(skinId)) {
triggerNetworkEvent("ag.newCharacterFailed", client, "Invalid skin!");
return false;
}
let subAccountData = createSubAccount(serverData.clients[client.index].accountData.databaseId, firstName, lastName, skinId, dateOfBirth, placeOfOrigin);
if(!subAccountData) {
triggerNetworkEvent("ag.newCharacterFailed", client, "Something went wrong. Your character could not be created!");
messageClientAlert(client, "Asshat Gaming staff have been notified of the problem and will fix it shortly.");
return false;
}
serverData.clients[client.index].accountData.subAccounts = loadSubAccountsFromAccount(serverData.clients[client.index].accountData.databaseId);
triggerNetworkEvent("ag.newCharacterSuccess", client);
serverData.clients[client.index].currentSubAccount = 0;
let tempSubAccount = serverData.clients[client.index].subAccounts[0];
triggerNetworkEvent("ag.showCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin);
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.previousCharacter", function(client) {
if(serverData.clients[client.index].subAccounts.length > 1) {
if(serverData.clients[client.index].currentSubAccount <= 0) {
serverData.clients[client.index].currentSubAccount = serverData.clients[client.index].subAccounts.length-1;
} else {
serverData.clients[client.index].currentSubAccount--;
}
let subAccountId = serverData.clients[client.index].currentSubAccount;
let tempSubAccount = serverData.clients[client.index].subAccounts[subAccountId];
triggerNetworkEvent("ag.switchCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin);
}
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.nextCharacter", function(client) {
if(serverData.clients[client.index].subAccounts.length > 1) {
if(serverData.clients[client.index].currentSubAccount >= serverData.clients[client.index].subAccounts.length-1) {
serverData.clients[client.index].currentSubAccount = 0;
} else {
serverData.clients[client.index].currentSubAccount++;
}
let subAccountId = serverData.clients[client.index].currentSubAccount;
let tempSubAccount = serverData.clients[client.index].subAccounts[subAccountId];
triggerNetworkEvent("ag.switchCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin);
}
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.selectCharacter", function(client) {
triggerNetworkEvent("ag.characterSelectSuccess", client);
let subAccountId = serverData.clients[client.index].currentSubAccount;
let tempSubAccount = serverData.clients[client.index].subAccounts[subAccountId];
spawnPlayer(client, tempSubAccount.spawnPosition, tempSubAccount.spawnHeading, tempSubAccount.skin);
});
// ---------------------------------------------------------------------------
function isValidEmailAddress(emailAddress) {
return true;
}
// ---------------------------------------------------------------------------
function saveAllClientsToDatabase() {
console.log("[Asshat.Account]: Saving all clients to database ...");
getClients().forEach(function(client) {
saveClientToDatabase(client);
});
console.log("[Asshat.Account]: All clients saved to database successfully!");
}
// ---------------------------------------------------------------------------
function saveClientToDatabase(client) {
console.log("[Asshat.Account]: Saving client " + String(client.name) + " to database ...");
saveAccountToDatabase(getClientData(client).accountData);
console.log("acct done");
let subAccountData = getClientCurrentSubAccount(client);
console.log("sacct got");
subAccountData.spawnPosition = client.player.position;
console.log("sacct pos");
subAccountData.spawnHeading = client.player.heading;
console.log("sacct start");
saveSubAccountToDatabase(subAccountData);
console.log("sacct done");
console.log("[Asshat.Account]: Saved client " + String(client.name) + " to database successfully!");
return true;
}
// ---------------------------------------------------------------------------
function initClient(client) {
triggerNetworkEvent("ag.connectCamera", client, serverConfig.connectCameraPosition[server.game], serverConfig.connectCameraLookAt[server.game]);
let tempAccountData = loadAccountFromName(client.name);
let tempSubAccounts = loadSubAccountsFromAccount(tempAccountData.databaseId);
serverData.clients[client.index] = new serverClasses.clientData(client, tempAccountData, tempSubAccounts);
if(tempAccountData != false) {
triggerNetworkEvent("ag.showLogin", client);
//messageClient("Welcome back to Asshat Gaming RP, " + String(client.name) + "! Please /login to continue.", client, serverConfig.colour.byName["white"]);
} else {
triggerNetworkEvent("ag.showRegistration", client);
//messageClient("Welcome to Asshat Gaming RP, " + String(client.name) + "! Please /register to continue.", client, serverConfig.colour.byName["white"]);
}
}

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: ammunation.js
// DESC: Provides ammunation functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================

256
scripts/server/ban.js Normal file
View File

@@ -0,0 +1,256 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: bans.js
// DESC: Provides ban functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
const banType = {
none: 0,
account: 1,
subAccount: 3,
ipAddress: 4,
uid: 5,
};
// ---------------------------------------------------------------------------
function initBanScript() {
console.log("[Asshat.Ban]: Initializing ban script ...");
addBanCommandHandlers();
console.log("[Asshat.Ban]: Ban script initialized!");
}
// ---------------------------------------------------------------------------
function addBanCommandHandlers() {
console.log("[Asshat.Ban]: Adding ban command handlers ...");
let banCommands = serverData.commands.ban;
for(let i in banCommands) {
addCommandHandler(banCommands[i].command, banCommands[i].handlerFunction);
}
console.log("[Asshat.Ban]: Bans command handlers added! ...");
}
// ---------------------------------------------------------------------------
function accountBanCommand(command, params, client, fromDiscord) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
// Prevent banning admins with really high permissions
if(doesClientHaveStaffPermission(targetClient, "ManageServer") || doesClientHaveStaffPermission(targetClient, "Developer")) {
messageClientError(client, "You cannot ban this person!");
return false;
}
message("[#996600][ADMIN]: [#FFFFFF]" + getClientData(targetClient).accountData.name + " has been banned from the server (account ban).");
banAccount(getClientData(targetClient).accountData.databaseId, getClientData(client).accountData.databaseId, "");
targetClient.disconnect();
}
// ---------------------------------------------------------------------------
function subAccountBanCommand(command, params, client, fromDiscord) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
// Prevent banning admins with really high permissions
if(doesClientHaveStaffPermission(targetClient, "ManageServer") || doesClientHaveStaffPermission(targetClient, "Developer")) {
messageClientError(client, "You cannot ban this person!");
return false;
}
message("[#996600][ADMIN]: [#FFFFFF]" + getClientData(targetClient).currentSubAccountData.name + " has been banned from the server (character ban).");
banSubAccount(getClientData(targetClient).currentSubAccountData.databaseId, getClientData(client).accountData.databaseId, "");
}
// ---------------------------------------------------------------------------
function ipBanCommand(command, params, client, fromDiscord) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
message("[#996600][ADMIN]: [#FFFFFF]" + targetClient.name + " has been banned from the server (IP ban).");
banIPAddress(targetClient.ip, getClientData(client).accountData.databaseId, "");
}
// ---------------------------------------------------------------------------
function banAccount(accountId, adminAccountId, reason) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let safeReason = dbConnection.escapeString(reason);
let dbQuery = dbConnection.query("INSERT INTO `ban_main` (`ban_type`, `ban_detail`, `ban_who_banned`, `ban_reason`) VALUES (" + banType.account + ", " + accountId + ", " + adminAccountId + ", '" + safeReason + "');");
dbQuery.free();
dbConnection.close();
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function banSubAccount(subAccountId, adminAccountId, reason) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let safeReason = dbConnection.escapeString(reason);
let dbQuery = dbConnection.query("INSERT INTO `ban_main` (`ban_type`, `ban_detail`, `ban_who_banned`, `ban_reason`) VALUES (" + banType.subAccount + ", " + subAccountId + ", " + adminAccountId + ", '" + safeReason + "');");
dbQuery.free();
dbConnection.close();
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function banIPAddress(ipAddress, adminAccountId, reason) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let safeReason = dbConnection.escapeString(reason);
let dbQuery = dbConnection.query("INSERT INTO `ban_main` (`ban_type`, `ban_detail`, `ban_who_banned`, `ban_reason`) VALUES (" + banType.ipAddress + ", " + INET_ATON(ipAddress) + ", " + adminAccountId + ", '" + safeReason + "');");
dbQuery.free();
dbConnection.close();
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function unbanAccount(accountId, adminAccountId) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = dbConnection.query("UPDATE `ban_main` SET `ban_who_removed` = " + adminAccountId + ", `ban_removed` = 1 WHERE `ban_type` = " + banType.account + " AND ban_detail` = " + accountId + " AND `ban_removed` = 0");
dbQuery.free();
dbConnection.close();
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function unbanSubAccount(subAccountId, adminAccountId) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = dbConnection.query("UPDATE `ban_main` SET `ban_who_removed` = " + adminAccountId + ", `ban_removed` = 1 WHERE `ban_type` = " + banType.subAccount + " AND ban_detail` = " + subAccountId + " AND `ban_removed` = 0");
dbQuery.free();
dbConnection.close();
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function unbanIPAddress(ipAddress, adminAccountId) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = dbConnection.query("UPDATE `ban_main` SET `ban_who_removed` = " + adminAccountId + ", `ban_removed` = 1 WHERE `ban_type` = " + banType.ipAddress + " AND ban_detail` = " + ipAddress + " AND `ban_removed` = 0");
dbQuery.free();
dbConnection.close();
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function isAccountBanned(accountId) {
let bans = serverData.bans;
for(let i in bans) {
if(bans[i].type == banType.account) {
if(bans[i].detail == accountId) {
return true;
}
}
}
return false;
}
// ---------------------------------------------------------------------------
function isSubAccountBanned(subAccountId) {
let bans = serverData.bans;
for(let i in bans) {
if(bans[i].type == banType.subAcount) {
if(bans[i].detail == subAccountId) {
return true;
}
}
}
return false;
}
// ---------------------------------------------------------------------------
function isIpAddressBanned(ipAddress) {
let bans = serverData.bans;
for(let i in bans) {
if(bans[i].type == banType.ipAddress) {
if(bans[i].detail == ipAddress) {
return true;
}
}
}
return false;
}
// ---------------------------------------------------------------------------

80
scripts/server/bitflag.js Normal file
View File

@@ -0,0 +1,80 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: bitflags.js
// DESC: Provides bitwise operations, functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initBitFlagScript() {
serverData.staffFlags = createBitFlagTable(serverData.staffFlagKeys);
serverData.moderationFlags = createBitFlagTable(serverData.moderationFlagKeys);
serverData.accountSettingsFlags = createBitFlagTable(serverData.accountSettingsFlagKeys);
//serverData.subAccountSettingsFlags = createBitFlagTable(serverData.subAccountSettingsFlagKeys);
serverData.clanFlags = createBitFlagTable(serverData.clanFlagKeys);
serverData.clanPermissionFlags = createBitFlagTable(serverData.clanPermissionFlagKeys);
serverData.factionFlags = createBitFlagTable(serverData.factionFlagKeys);
return true;
}
// ---------------------------------------------------------------------------
function addBitFlagCommandHandlers() {
return true;
}
// ---------------------------------------------------------------------------
function createBitFlagTable(keyNames) {
let bitVal = 0;
let bitTable = {};
let incVal = 1;
for(let i in keyNames) {
let key = keyNames[i];
bitTable[key] = bitVal;
bitVal = 1 << incVal;
incVal++;
}
return bitTable;
}
// ---------------------------------------------------------------------------
function doesClientHaveStaffPermission(client, requiredFlags) {
if(requiredFlags == getStaffFlagValue("none")) {
return true;
}
let staffFlags = 0;
if(isClientFromDiscord(client)) {
staffFlags = serverData.clients[client.index].accountData.staffFlags;
} else {
staffFlags = getDiscordUserData(client).accountData.staffFlags;
}
// -1 is automatic override (having -1 for staff flags is basically god mode admin level)
if(staffFlags == getStaffFlagValue("all")) {
return true;
}
if(staffFlags & requiredFlags) {
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function getStaffFlagValue(flagName) {
if(flagName == "all") {
return -1;
}
return serverData.staffFlags[flagName];
}
// ---------------------------------------------------------------------------

320
scripts/server/business.js Normal file
View File

@@ -0,0 +1,320 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: business.js
// DESC: Provides business functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initBusinessScript() {
console.log("[Asshat.Business]: Initializing business script ...");
serverData.businesses = loadBusinessesFromDatabase();
addBusinessCommandHandlers();
console.log("[Asshat.Business]: Business script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addBusinessCommandHandlers() {
console.log("[Asshat.Business]: Adding business commands!");
let businessCommands = serverCommands.business;
for(let i in businessCommands) {
addCommandHandler(businessCommands[i].command, businessCommands[i].handlerFunction);
}
console.log("[Asshat.Business]: Business commands added!");
return true;
}
// ---------------------------------------------------------------------------
function loadBusinessesFromDatabase() {
console.log("[Asshat.Business]: Loading businesses from database ...");
let tempBusinesses = [];
let dbConnection = connectToDatabase();
let dbQuery = null;
if(dbConnection) {
dbQuery = dbConnection.query("SELECT * FROM `biz_main` WHERE `biz_server` = " + String(serverId));
if(dbQuery) {
if(dbQuery.numRows > 0) {
while(dbFetchAssoc = dbQuery.fetchAssoc()) {
let tempBusinessData = businessData(dbFetchAssoc);
tempBusinesses.push(tempBusinessData);
console.log(`[Asshat.Business]: Business '${tempBusinessData.name}' loaded from database successfully!`);
}
}
dbQuery.free();
}
disconnectFromDatabase(dbConnection);
}
console.log("[Asshat.Business]: " + String(tempBusinesses.length) + " businesses loaded from database successfully!");
return tempBusinesses;
}
// ---------------------------------------------------------------------------
function createBusinessCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
if(isClientSpawned(client)) {
messageClientError("You must be spawned to use this command!");
return false;
}
createBusiness(params, client.player.position, getClientInterior(client), getClientVirtualWorld(client));
messageClientSuccess(client, "Business created in " + getAreaName(client.player.position) + " (" + params + ")");
}
// ---------------------------------------------------------------------------
function createBusiness(name, entrancePosition, interiorId, virtualWorld) {
let dbConnection = connectToDatabase();
let escapedName = name;
if(dbConnection) {
escapedName = dbConnection.escapeString(escapedName)
let dbQuery = dbConnection.query("INSERT INTO `biz_main` (`biz_server`, `biz_name`, `biz_entrance_x`, `biz_entrance_y`, `biz_entrance_z`, `biz_entrance_int`, `biz_entrance_vw`) VALUES (" + String(serverId) + ", '" + escapedName + "', " + String(entrancePosition.x) + ", " + String(entrancePosition.y) + ", " + String(entrancePosition.z) + ", " + String(interiorId) + ", " + String(virtualWorld) + ")");
disconnectFromDatabase(dbConnection);
let tempBusinessData = loadBusinessFromDatabaseById(dbConnection.insertID);
if(tempBusinessData != false) {
let tempBusiness = getClasses().businessData(tempBusinessData);
serverData.business.push(tempBusiness);
}
}
return true;
}
// ---------------------------------------------------------------------------
function deleteBusinessCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let businessId = Number(params);
let tempBusinessData = serverData.businesses.filter(b => b.databaseId == businessId)[0];
deleteBusiness(businessId);
messageClientSuccess(client, `Business '${tempBusinessData.name} deleted!`);
}
// ---------------------------------------------------------------------------
function setBusinessNameCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let splitParams = params.split(" ");
let newBusinessName = String(splitParams[0]);
let businessId = Number(splitParams[1]) || (isPlayerInAnyBusiness(client.player)) ? getPlayerBusiness(client.player) : getClosestBusinessEntrance(client.player.position).databaseId;
let tempBusinessData = serverData.businesses.filter(b => b.databaseId == businessId)[0];
serverData.businesses[businessId].name = newBusinessName;
messageClientSuccess(client, `Business '${tempBusinessData.name}' renamed to '${newBusinessName}'!`);
}
// ---------------------------------------------------------------------------
function setBusinessOwnerCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
if(isClientSpawned(client)) {
messageClientError("You must be spawned to use this command!");
return false;
}
let splitParams = params.split(" ");
let newBusinessOwner = getClientFromParams(splitParams[0]);
let businessId = Number(splitParams[1]) || (isPlayerInAnyBusiness(client.player)) ? getPlayerBusiness(client.player) : getClosestBusinessEntrance(client.player.position).databaseId;
if(!newBusinessOwner) {
messageClientError("Player not found!");
return false;
}
if(!getBusinessDataFromDatabaseId(businessId)) {
messageClientError("Business not found!");
return false;
}
serverData.businesses[businessId].ownerId = serverData.clients[newBusinessOwner.index].accountData.databaseId;
messageClientSuccess(client, `Business '${serverData.businesses[businessId].name}' owner set to '${newBusinessOwner.name}'!`);
}
// ---------------------------------------------------------------------------
function lockBusinessCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
if(isClientSpawned(client)) {
messageClientError("You must be spawned to use this command!");
return false;
}
let splitParams = params.split(" ");
let businessId = Number(splitParams[0]) || (isPlayerInAnyBusiness(client.player)) ? getPlayerBusiness(client.player) : getClosestBusinessEntrance(client.player.position).databaseId;
serverData.businesses[businessId].locked = !serverData.businesses[businessId].locked;
messageClientSuccess(client, "Business " + serverData.businesses[businessId].name + " " + (serverData.businesses[businessId].locked) ? "locked" : "unlocked" + "!");
}
// ---------------------------------------------------------------------------
function getBusinessDataFromDatabaseId(databaseId) {
let matchingBusinesses = serverData.businesses.filter(b => b.databaseId == businessId)
if(matchingBusinesses.length == 1) {
return matchingBusinesses[0];
}
return false;
}
// ---------------------------------------------------------------------------
function getClosestBusinessEntrance(position) {
return serverData.businesses.reduce((i, j) => ((i.entrancePosition.distance(position) <= j.entrancePosition.distance(position)) ? i : j));
}
// ---------------------------------------------------------------------------
function isPlayerInAnyBusiness(player) {
if(player.getData("ag.inBusiness")) {
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function getPlayerBusiness(player) {
if(player.getData("ag.inBusiness")) {
return player.getData("ag.inBusiness");
}
return false;
}
// ---------------------------------------------------------------------------
function saveAllBusinessesToDatabase() {
}
// ---------------------------------------------------------------------------

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: bakery.js
// DESC: Provides bakery business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: bar.js
// DESC: Provides bar/pub business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: burger.js
// DESC: Provides burger joint (McDonalds?) business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: clothing.js
// DESC: Provides clothing (skin) business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: club.js
// DESC: Provides club/nightclub business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: fuel.js
// DESC: Provides fuel/petrol business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: mechanic.js
// DESC: Provides mechanic/vehicle repair business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: pizza.js
// DESC: Provides pizza restaurant business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: restaurant.js
// DESC: Provides generic restaurant business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: vehicle.js
// DESC: Provides vehicle dealership business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: weapon.js
// DESC: Provides weapon (ammu) business functions and usage
// TYPE: Business (JavaScript)
// ===========================================================================

180
scripts/server/chat.js Normal file
View File

@@ -0,0 +1,180 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: chat.js
// DESC: Provides chat functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initChatScript() {
console.log("[Asshat.Chat]: Initializing chat script ...");
addChatCommandHandlers();
console.log("[Asshat.Chat]: Chat script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addChatCommandHandlers() {
console.log("[Asshat.Chat]: Adding chat command handlers ...");
let chatCommands = serverCommands.chat;
for(let i in chatCommands) {
addCommandHandler(chatCommands[i].command, chatCommands[i].handlerFunction);
}
console.log("[Asshat.Chat]: Chat command handlers added successfully!");
return true;
}
// ---------------------------------------------------------------------------
function meActionCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
meActionToNearbyPlayers(client, params);
return true;
}
// ---------------------------------------------------------------------------
function doActionCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
doActionToNearbyPlayers(client, params);
return true;
}
// ---------------------------------------------------------------------------
function shoutCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
shoutToNearbyPlayers(client, params);
return true;
}
// ---------------------------------------------------------------------------
function talkCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
talkToNearbyPlayers(client, params);
return true;
}
// ---------------------------------------------------------------------------
function whisperCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
whisperToNearbyPlayers(client, params);
return true;
}
// ---------------------------------------------------------------------------
function talkToNearbyPlayers(client, messageText) {
let clients = getClientsInRange(client.player.position, serverConfig.talkDistance);
for(let i in clients) {
//if(clients[i] != client) {
messageClientTalk(clients[i], client, messageText);
//}
}
}
// ---------------------------------------------------------------------------
function whisperToNearbyPlayers(client, messageText) {
let clients = getClientsInRange(client.player.position, serverConfig.talkDistance);
for(let i in clients) {
//if(clients[i] != client) {
messageClientWhisper(clients[i], client, messageText);
//}
}
}
// ---------------------------------------------------------------------------
function shoutToNearbyPlayers(client, messageText) {
let clients = getClientsInRange(client.player.position, serverConfig.shoutDistance);
for(let i in clients) {
//if(clients[i].index != client.index) {
messageClientShout(clients[i], client, messageText);
//}
}
}
// ---------------------------------------------------------------------------
function doActionToNearbyPlayers(client, messageText) {
let clients = getClientsInRange(client.player.position, serverConfig.doActionDistance);
for(let i in clients) {
//if(clients[i].index != client.index) {
messageClientDoAction(clients[i], client, messageText);
//}
}
}
// ---------------------------------------------------------------------------
function meActionToNearbyPlayers(client, messageText) {
let clients = getClientsInRange(client.player.position, serverConfig.meActionDistance);
for(let i in clients) {
//if(clients[i].index != client.index) {
messageClientMeAction(clients[i], client, messageText);
//}
}
}
// ---------------------------------------------------------------------------

597
scripts/server/clan.js Normal file
View File

@@ -0,0 +1,597 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: clan.js
// DESC: Provides clan functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initClanScript() {
console.log("[Asshat.Clan]: Initializing clans script ...");
serverData.clans = loadClansFromDatabase();
addClanCommandHandlers();
console.log("[Asshat.Clan]: Clan script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addClanCommandHandlers() {
console.log("[Asshat.Clan]: Adding clan command handlers ...");
let clanCommands = serverCommands.clan;
for(let i in clanCommands) {
addCommandHandler(clanCommands[i].command, clanCommands[i].handlerFunction);
}
console.log("[Asshat.Clan]: Clan command handlers added successfully!");
return true;
}
// ---------------------------------------------------------------------------
function loadClansFromDatabase() {
console.log("[Asshat.Clan]: Loading clans from database ...");
let tempClans = [];
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = dbConnection.query("SELECT * FROM `clan_main` WHERE `clan_server` = " + String(serverId));
if(dbQuery) {
if(dbQuery.numRows > 0) {
while(dbFetchAssoc = dbQuery.fetchAssoc()) {
let tempClanData = getClasses().clanData(dbFetchAssoc);
tempClanData.members = loadClanMembersFromDatabase(tempClanData.databaseId);
tempClanData.ranks = loadClanRanksFromDatabase(tempClanData.databaseId);
tempClans.push(tempClanData);
console.log(`[Asshat.Clan]: Clan '${tempClanData.name}' loaded from database successfully!`);
}
}
dbQuery.free();
}
disconnectFromDatabase(dbConnection);
}
console.log("[Asshat.Clan]: " + String(tempClans.length) + " clans loaded from database successfully!");
return tempClans;
}
// ----------------------------------------------------------------------------
function createClanCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
if(doesClanNameExist(params)) {
messageClientError(client, "A clan with that name already exists!");
return false;
}
// Create clan without owner. Can set owner with /clanowner afterward
createClan(params);
messageClientSuccess(client, "The '" + params + "' clan has been created!");
}
// ----------------------------------------------------------------------------
function deleteClanCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
if(isNaN(params)) {
messageClientError(client, "The clan ID must be a number!");
return false;
}
if(!doesClanIDExist(Number(params))) {
messageClientError(client, "That clan ID does not exist!");
return false;
}
messageClientSuccess(client, "The '" + getClanData(Number(params)).name + "' clan has been deleted!");
deleteClan(Number(params));
}
// ----------------------------------------------------------------------------
function setClanOwnerCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "owner")) {
messageClientError(client, "You must be the clan owner to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function setClanTagCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "clanTag")) {
messageClientError(client, "You can not change the clan tag!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function setClanNameCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "clanName")) {
messageClientError(client, "You can not change the clan name!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function setClanMemberTagCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "memberTag")) {
messageClientError(client, "You can not change a clan member's tag!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function setClanRankTagCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "rankTag")) {
messageClientError(client, "You can not change a clan ranks's tag!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function setClanMemberFlagsCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "memberFlags")) {
messageClientError(client, "You can not change a clan member's permissions!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function setClanRankFlagsCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "rankFlags")) {
messageClientError(client, "You can not change a clan ranks's permissions!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function setClanMemberTitleCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "memberFlags")) {
messageClientError(client, "You can not change a clan member's title!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function setClanRankTitleCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(!doesClientHaveClanPermission(client, "rankTitle")) {
messageClientError(client, "You can not change a clan ranks's title!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ----------------------------------------------------------------------------
function createClan(name) {
let dbConnection = connectToDatabase();
let serverId = getServerId();
let escapedName = name;
if(dbConnection) {
escapedName = dbConnection.escapeString(escapedName)
let dbQuery = dbConnection.query("INSERT INTO `clan_main` (`clan_server`, `clan_name`) VALUES (" + String(serverId) + ", '" + escapedName + "')");
disconnectFromDatabase(dbConnection);
let tempClanData = loadClanFromDatabaseById(dbConnection.insertID);
if(tempClanData != false) {
let tempClan = serverClasses.clanData(tempClanData);
serverData.clans.push(tempClan);
}
}
return true;
}
// ----------------------------------------------------------------------------
function deleteClan(clanId) {
saveClansToDatabase();
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = dbConnection.query("DELETE FROM `clan_main` WHERE `clan_id` = " + clanId);
dbQuery.free();
disconnectFromDatabase(dbConnection);
reloadAllClans();
return true;
}
return false;
}
// ----------------------------------------------------------------------------
function getClanData(clanId) {
let clans = getServerData().clans;
for(let i in clans) {
if(clans[i].databaseId == clanId) {
return clans[i];
}
}
return false;
}
// ----------------------------------------------------------------------------
function doesClanNameExist(name) {
let clans = getServerData().clans;
for(let i in clans) {
if(clans[i].name == name) {
return true;
}
}
return false;
}
// ----------------------------------------------------------------------------
function doesClanIdExist(clanId) {
let clans = getServerData().clans;
for(let i in clans) {
if(clans[i].databaseId == clanId) {
return true;
}
}
return false;
}
// ----------------------------------------------------------------------------
function reloadAllClans() {
getServerData().clans = loadClansFromDatabase();
}
// ----------------------------------------------------------------------------
function saveClansToDatabase() {
let clans = getServerData().clans;
for(let i in clans) {
saveClanToDatabase(clans[i]);
}
}
// ----------------------------------------------------------------------------
function saveClanToDatabase(clanData) {
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQueryString = "UPDATE `clan_main` SET `clan_name` = '" + dbConnection.escapeString(clanData.name) + "', `clan_owner` = " + clanData.ownerId;
let dbQuery = dbConnection.query(dbQueryString);
dbQuery.free();
disconnectFromDatabase(dbConnection);
return true;
}
return false;
}
// ----------------------------------------------------------------------------
function setClanTag(clanId, tag) {
getClanData(clanId).tag = tag;
}
// ----------------------------------------------------------------------------
function setClanOwner(clanId, ownerId) {
getClanData(clanId).ownerId = ownerId;
}
// ----------------------------------------------------------------------------
function setClanMemberTag(memberId, tag) {
// finish this later, need to query db
}
// ----------------------------------------------------------------------------
function setClanMemberFlags(memberId, flags) {
// finish this later, need to query db
}
// ----------------------------------------------------------------------------
function setClanMemberTitle(memberId, title) {
// finish this later, need to query db
}
// ----------------------------------------------------------------------------
function setClanRankTag(clanId, rankId, tag) {
getClanRankData(clanId, rankId).tag = tag;
}
// ----------------------------------------------------------------------------
function setClanRankFlags(clanId, rankId, flags) {
getClanRankData(clanId, rankId).flags = flags;
}
// ----------------------------------------------------------------------------
function setClanRankTitle(clanId, rankId, title) {
getClanRankData(clanId, rankId).title = title;
}
// ----------------------------------------------------------------------------
function saveAllClansToDatabase() {
}
// ---------------------------------------------------------------------------

209
scripts/server/class.js Normal file
View File

@@ -0,0 +1,209 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: class.js
// DESC: Provides classes
// TYPE: Server (JavaScript)
// ===========================================================================
let serverClasses = initClassTable();
// ---------------------------------------------------------------------------
function initClassScript() {
}
// ---------------------------------------------------------------------------
function initClassTable() {
let tempClasses = {
clientData: class {
constructor(client, accountData, subAccounts) {
this.accountData = accountData;
this.subAccounts = subAccounts; // Characters
this.client = client;
this.currentSubAccount = 0;
this.loggedIn = false;
}
},
accountData: class {
constructor(accountAssoc) {
if(!accountAssoc) {
return;
}
this.databaseId = accountAssoc["acct_id"];
this.name = accountAssoc["acct_name"];
this.password = accountAssoc["acct_pass"];
this.registerDate = accountAssoc["acct_when_made"];
this.flags = {
moderation: accountAssoc["acct_mod_flags"],
settings: accountAssoc["acct_settings"],
admin: accountAssoc["acct_staff_flags"],
};
this.staffTitle = accountAssoc["acct_staff_title"];
this.ircAccount = accountAssoc["acct_irc"] || "None";
this.discordAccount = accountAssoc["acct_discord"];
this.settings = accountAssoc["acct_settings"];
this.emailAddress = accountAssoc["acct_email"];
this.subAccounts = [];
this.loggedIn = false;
}
},
subAccountData: class {
constructor(subAccountAssoc) {
if(!subAccountAssoc) {
return;
}
this.databaseId = subAccountAssoc["sacct_id"];
this.server = subAccountAssoc["sacct_server"];
this.firstName = subAccountAssoc["sacct_name_first"];
this.lastName = subAccountAssoc["sacct_name_last"];
this.accountId = subAccountAssoc["sacct_acct"];
this.skin = subAccountAssoc["sacct_skin"];
this.cash = subAccountAssoc["sacct_cash"];
this.placeOfOrigin = subAccountAssoc["sacct_origin"];
this.dateOfBirth = subAccountAssoc["sacct_when_born"];
this.spawnPosition = new Vec3(subAccountAssoc["sacct_pos_x"], subAccountAssoc["sacct_pos_y"], subAccountAssoc["sacct_pos_z"]);
this.spawnHeading = Number(subAccountAssoc["sacct_angle"]);
this.isWorking = false;
this.jobUniform = this.skin;
this.lastJobVehicle = null;
this.weapons = [];
}
},
businessData: class {
constructor(businessAssoc) {
if(!businessAssoc) {
return;
}
this.databaseId = businessAssoc("biz_id");
this.name = businessAssoc("biz_name");
this.ownerType = businessAssoc("biz_owner_type");
this.ownerId = businessAssoc("biz_owner_id");
this.locked = businessAssoc("biz_locked");
this.entrancePosition = new Vec3(businessAssoc("biz_entrance_pos_x"), businessAssoc("biz_entrance_pos_y"), businessAssoc("biz_entrance_pos_z"));
this.entranceInterior = Number(businessAssoc["biz_entrance_int"]);
this.entranceDimension = Number(businessAssoc["biz_entrance_vw"]);
this.exitPosition = new Vec3(businessAssoc("biz_exit_pos_x"), businessAssoc("biz_exit_pos_y"), businessAssoc("biz_exit_pos_z"));
this.exitInterior = Number(businessAssoc["biz_exit_int"]);
this.exitDimension = Number(businessAssoc["biz_exit_vw"]);
}
},
houseData: class {
},
familyData: class {
},
factionData: class {
},
vehicleData: class {
constructor(vehicleAssoc) {
if(!vehicleAssoc) {
return;
}
// General Info
this.databaseId = vehicleAssoc["veh_id"];
this.server = vehicleAssoc["veh_server"];
this.model = vehicleAssoc["veh_model"];
this.vehicle = null;
// Ownership
this.ownerType = vehicleAssoc["veh_owner_type"];
this.ownerId = vehicleAssoc["veh_owner_id"];
this.buyPrice = vehicleAssoc["veh_buy_price"];
this.rentPrice = vehicleAssoc["veh_buy_price"];
// Position and Rotation
this.savedPosition = new Vec3(vehicleAssoc["veh_pos_x"], vehicleAssoc["veh_pos_y"], vehicleAssoc["veh_pos_z"]);
this.savedRotation = new Vec3(vehicleAssoc["veh_rot_x"], vehicleAssoc["veh_rot_y"], vehicleAssoc["veh_rot_z"]);
// Colour Info
this.colour1IsRGBA = vehicleAssoc["veh_col1_isrgba"];
this.colour2IsRGBA = vehicleAssoc["veh_col2_isrgba"];
this.colour3IsRGBA = vehicleAssoc["veh_col3_isrgba"];
this.colour4IsRGBA = vehicleAssoc["veh_col4_isrgba"];
this.colour1RGBA = toColour(vehicleAssoc["veh_col1_r"], vehicleAssoc["veh_col1_g"], vehicleAssoc["veh_col1_b"], vehicleAssoc["veh_col1_a"]);
this.colour2RGBA = toColour(vehicleAssoc["veh_col2_r"], vehicleAssoc["veh_col2_g"], vehicleAssoc["veh_col2_b"], vehicleAssoc["veh_col2_a"]);
this.colour3RGBA = toColour(vehicleAssoc["veh_col3_r"], vehicleAssoc["veh_col3_g"], vehicleAssoc["veh_col3_b"], vehicleAssoc["veh_col3_a"]);
this.colour4RGBA = toColour(vehicleAssoc["veh_col4_r"], vehicleAssoc["veh_col4_g"], vehicleAssoc["veh_col4_b"], vehicleAssoc["veh_col4_a"]);
this.colour1 = vehicleAssoc["veh_col1"];
this.colour2 = vehicleAssoc["veh_col2"];
this.colour3 = vehicleAssoc["veh_col3"];
this.colour4 = vehicleAssoc["veh_col4"];
// Vehicle Attributes
this.locked = vehicleAssoc["veh_locked"];
this.engine = vehicleAssoc["veh_engine"];
this.lights = vehicleAssoc["veh_lights"];
this.health = vehicleAssoc["veh_damage_normal"];
this.engineDamage = vehicleAssoc["veh_damage_engine"];
this.visualDamage = vehicleAssoc["veh_damage_visual"];
this.dirtLevel = vehicleAssoc["veh_dirt_level"];
this.vehicle = null;
}
},
commandData: class {
enable() {
this.enabled = true;
}
disable() {
this.enabled = false;
}
toggleEnabled() {
this.enabled = !this.enabled;
}
constructor(command, handlerFunction, syntaxString, requiredStaffFlags, requireLogin, allowOnDiscord) {
this.command = command;
this.handlerFunction = handlerFunction;
this.syntaxString = syntaxString;
this.requiredStaffFlags = requiredStaffFlags;
this.enabled = true;
this.requireLogin = requireLogin;
this.allowOnDiscord = allowOnDiscord
}
},
crimeData: class {
constructor(suspectId, crimeType, reporterId = 0) {
this.crimeType = crimeType;
this.suspectId = suspectId;
this.reporterId = reporterId;
this.whenCommitted = new Date().getTime();
this.whenReported = new Date().getTime();
this.databaseId = 0;
}
}
}
return tempClasses;
}
// ---------------------------------------------------------------------------
function getClasses() {
return serverClasses;
}
// ---------------------------------------------------------------------------
function getClass(className) {
return serverClasses[className];
}
// ---------------------------------------------------------------------------

92
scripts/server/client.js Normal file
View File

@@ -0,0 +1,92 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: client.js
// DESC: Provides client communication and cross-endpoint operations
// TYPE: Server (JavaScript)
// ===========================================================================
// ---------------------------------------------------------------------------
addNetworkHandler("ag.onPlayerEnterSphere", function(client, sphere) {
switch(sphere.getData("ag.type")) {
case AG_SPHERE_HOUSE:
client.player.setData("ag.atHouse", sphere.getData("ag.id"), false);
break;
case AG_SPHERE_BUSINESS:
client.player.setData("ag.atBusiness", sphere.getData("ag.id"), false);
break;
default:
break;
}
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.onPlayerExitSphere", function(client, sphere) {
client.player.removeData("ag.atHouse");
client.player.removeData("ag.atBusiness");
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.promptAnswerNo", function(client) {
if(!client.getData("ag.prompt")) {
return false;
}
switch(client.getData("ag.prompt")) {
case AG_PROMPT_CREATEFIRSTCHAR:
triggerNetworkEvent("ag.showError", client, "You don't have a character to play. Goodbye!", "No Characters");
setTimeout(function() { client.disconnect(); }, 5000);
break;
default:
break;
}
client.removeData("ag.prompt");
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.promptAnswerYes", function(client) {
if(!client.getData("ag.prompt")) {
return false;
}
switch(client.getData("ag.prompt")) {
case AG_PROMPT_CREATEFIRSTCHAR:
triggerNetworkEvent("ag.showNewCharacter", client);
break;
S
default:
break;
}
client.removeData("ag.prompt");
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.onPickupCollected", function(client, pickup) {
let ownerType = getPickupOwnerType(pickup);
let ownerId = getPickupOwnerType(pickup);
switch(ownerType) {
case AG_PICKUP_JOB:
let jobData = serverData.jobs[server.game][jobId];
showJobInformationToPlayer(client, jobData.jobType);
break;
default:
break;
}
});
// ---------------------------------------------------------------------------

52
scripts/server/colour.js Normal file
View File

@@ -0,0 +1,52 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: colour.js
// DESC: Provides colours, functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
// ----------------------------------------------------------------------------
function getColourByType(typeName) {
return serverConfig.colour.byType[typeName];
}
// ----------------------------------------------------------------------------
function getColourByName(colourName) {
return serverConfig.colour.byName[colourName];
}
// ---------------------------------------------------------------------------
function rgbToHex(red, green, blue) {
return "#" + componentToHex(red) + componentToHex(green) + componentToHex(blue);
}
// ---------------------------------------------------------------------------
function componentToHex(component) {
let hex = component.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
// ---------------------------------------------------------------------------
function hexToRGB(hex) {
let red = parseInt((cutHex(hex)).substring(0,2),16);
let green = parseInt((cutHex(hex)).substring(2,4),16);
let blue = parseInt((cutHex(hex)).substring(4,6),16);
return {r: red, g: green, b: blue};
}
// ---------------------------------------------------------------------------
function cutHex(hex) {
return (hex.charAt(0)=="#") ? hex.substring(1,7) : hex;
}
// ---------------------------------------------------------------------------

165
scripts/server/command.js Normal file
View File

@@ -0,0 +1,165 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: command.js
// DESC: Provides command data, functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
let serverCommands = {};
function initCommandScript() {
serverCommands = loadCommandData();
}
// ---------------------------------------------------------------------------
function loadCommandData() {
let tempCommands = {
account: [
commandData("login", loginCommand, "<password>", getStaffFlagValue("none"), false, false),
commandData("register", registerCommand, "<password>", getStaffFlagValue("none"), false, false),
commandData("changepass", changePasswordCommand, "<password>", getStaffFlagValue("none"), true, false),
//commandData("setpass", changePasswordCommand, "<password>", getStaffFlagValue("none"), true, false),
commandData("switchchar", switchCharacterCommand, "", getStaffFlagValue("none"), true, false),
],
ammunation: [],
ban: [
commandData("aban", accountBanCommand, "<player name/id> <reason>", getStaffFlagValue("manageBans"), true, true),
commandData("saban", subAccountBanCommand, "<player name/id> <reason>", getStaffFlagValue("manageBans"), true, true),
commandData("ipban", ipBanCommand, "<player name/id> <reason>", getStaffFlagValue("manageBans"), true, true),
],
bitFlag: [],
business: [
commandData("addbiz", createBusinessCommand, "<name>", getStaffFlagValue("manageBusinesses"), true, false),
commandData("delbiz", deleteBusinessCommand, "[id]", getStaffFlagValue("manageBusinesses"), true, true),
],
chat: [
commandData("me", meActionCommand, "<message>", getStaffFlagValue("none"), true, false),
commandData("do", doActionCommand, "<message>", getStaffFlagValue("none"), true, false),
commandData("s", shoutCommand, "<message>", getStaffFlagValue("none"), true, false),
commandData("shout", shoutCommand, "<message>", getStaffFlagValue("none"), true, false),
commandData("talk", talkCommand, "<message>", getStaffFlagValue("none"), true, false),
commandData("local", talkCommand, "<message>", getStaffFlagValue("none"), true, false),
commandData("l", talkCommand, "<message>", getStaffFlagValue("none"), true, false),
commandData("w", whisperCommand, "<message>", getStaffFlagValue("none"), true, false),
commandData("whisper", whisperCommand, "<message>", getStaffFlagValue("none"), true, false),
],
clan: [
commandData("addclan", createClanCommand, "<name>", getStaffFlagValue("manageClans"), true, true),
commandData("delclan", deleteClanCommand, "<clan id>", getStaffFlagValue("manageClans"), true, true),
commandData("clanowner", setClanOwnerCommand, "<clan id> <player name/id>", getStaffFlagValue("none"), true, true),
commandData("clantag", setClanTagCommand, "<tag>", getStaffFlagValue("none"), true, true),
commandData("clanranktag", setClanRankTagCommand, "<rank id> <tag>", getStaffFlagValue("none"), true, true),
commandData("clanmembertag", setClanMemberTagCommand, "<player name/id> <tag>", getStaffFlagValue("none"), true, true),
commandData("clanranktitle", setClanRankTitleCommand, "<rank id> <title>", getStaffFlagValue("none"), true, true),
commandData("clanmembertitle", setClanMemberTitleCommand, "<player name/id> <title>", getStaffFlagValue("none"), true, true),
commandData("clanrankper", setClanRankFlagsCommand, "<rank id>", getStaffFlagValue("none"), true, true),
commandData("clanmemberper", setClanMemberFlagsCommand, "<player name/id>", getStaffFlagValue("none"), true, true),
],
class: [],
client: [],
colour: [],
command: [],
config: [],
core: [],
database: [],
developer: [
commandData("scode", executeServerCodeCommand, "<code>", getStaffFlagValue("developer"), true, true),
commandData("ccode", executeClientCodeCommand, "<code>", getStaffFlagValue("developer"), true, true),
commandData("gmx", restartGameModeCommand, "", getStaffFlagValue("developer"), true, true)
],
discord: [],
faction: [],
help: [],
house: [],
item: [],
job: [
commandData("takejob", takeJobCommand, "", getStaffFlagValue("none"), true, false),
commandData("startwork", startWorkingCommand, "", getStaffFlagValue("none"), true, false),
commandData("stopwork", stopWorkingCommand, "", getStaffFlagValue("none"), true, false),
commandData("quitjob", quitJobCommand, "", getStaffFlagValue("none"), true, false),
commandData("radio", jobRadioCommand, "", getStaffFlagValue("none"), true, false),
commandData("r", jobRadioCommand, "", getStaffFlagValue("none"), true, false),
commandData("d", jobDepartmentRadioCommand, "", getStaffFlagValue("none"), true, false),
// Taxi
commandData("fare", takeJobCommand, "", getStaffFlagValue("none"), true, false),
// Police
commandData("tazer", policeTazerCommand, "", getStaffFlagValue("none"), true, false),
commandData("cuff", policeCuffCommand, "", getStaffFlagValue("none"), true, false),
commandData("detain", policeDetainCommand, "", getStaffFlagValue("none"), true, false),
commandData("drag", policeDragCommand, "", getStaffFlagValue("none"), true, false),
commandData("search", policeSearchCommand, "", getStaffFlagValue("none"), true, false),
],
locale: [],
messaging: [],
misc: [],
moderation: [
commandData("kick", kickClientCommand, "<player name/id> [reason]", getStaffFlagValue("basicModeration"), true, true),
commandData("mute", muteClientCommand, "<player name/id> [reason]", getStaffFlagValue("basicModeration"), true, true),
commandData("freeze", freezeClientCommand, "<player name/id> [reason]", getStaffFlagValue("basicModeration"), true, true),
commandData("unmute", unMuteClientCommand, "<player name/id> [reason]", getStaffFlagValue("basicModeration"), true, true),
commandData("unfreeze", unFreezeClientCommand, "<player name/id> [reason]", getStaffFlagValue("basicModeration"), true, true),
],
security: [],
startup: [],
translate: [],
utilities: [],
vehicle: [],
}
return tempCommands;
}
// ---------------------------------------------------------------------------
function getCommand(command) {
let commandGroups = getCommands()
for(let i in commandGroups) {
let commandGroup = commandGroups[i];
for(let j in commandGroup)
if(commandGroup[j].command.toLowerCase() == command.toLowerCase()) {
return commandGroup[j];
}
}
}
// ---------------------------------------------------------------------------
function getCommands() {
return serverCommands;
}
// ---------------------------------------------------------------------------
function commandData(command, handlerFunction, syntaxString = "", requiredStaffFlags = getStaffFlagValue("none"), requireLogin = true, allowOnDiscord = true) {
return new serverClasses.commandData(command, handlerFunction, syntaxString, requiredStaffFlags, requireLogin, allowOnDiscord);
}
// ---------------------------------------------------------------------------
function doesCommandRequireLogin(command) {
return getCommand(command).requireLogin;
}
// ---------------------------------------------------------------------------
function getCommandRequiredPermissions(command) {
return getCommand(command).requiredStaffFlags;
}
// ---------------------------------------------------------------------------
function isCommandAllowedOnDiscord(command) {
return getCommand(command).allowOnDiscord;
}
// ---------------------------------------------------------------------------

76
scripts/server/config.js Normal file
View File

@@ -0,0 +1,76 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: config.js
// DESC: Provides server configuration
// TYPE: Server (JavaScript)
// ===========================================================================
let serverConfig = {
colour: {
byType: {
talkMessage: toColour(200, 200, 200),
shoutMessage: toColour(255, 255, 200),
whisperMessage: toColour(130, 130, 130),
doActionMessage: toColour(153, 50, 204, 255),
meActionMessage: toColour(153, 50, 204, 255),
errorMessage: toColour(237, 67, 55, 255),
syntaxMessage: toColour(200, 200, 200, 255),
normalMessage: toColour(255, 255, 255, 255),
alertMessage: toColour(255, 255, 0, 255),
successMessage: toColour(0, 180, 0, 255),
},
byName: {
white: toColour(255, 255, 255, 255),
black: toColour(0, 0, 0, 255),
red: toColour(255, 0, 0, 255),
yellow: toColour(255, 255, 0, 255),
royalBlue: toColour(0, 0, 255, 255),
teal: toColour(0, 255, 255, 255),
orange: toColour(255, 128, 0, 255),
lightGrey: toColour(200, 200, 200, 255),
mediumGrey: toColour(150, 150, 150, 255),
darkGrey: toColour(64, 64, 64, 255),
policeBlue: toColour(70, 130, 180, 255),
medicPink: toColour(219, 112, 147, 255),
firefighterRed: toColour(205, 92, 92, 255),
busDriverGreen: toColour(50,205, 50, 255),
taxiDriverYellow: toColour(240, 230, 140, 255),
burntYellow: toColour(0, 180, 180, 255),
burntOrange: toColour(0, 120, 210, 255),
}
},
accountPasswordHash: "SHA512",
connectCameraPosition: [
false,
new Vec3(-1176.481, -17.694, 95.992),
false,
false,
false,
],
connectCameraLookAt: [
false,
new Vec3(-1175.726, -17.055, 95.847),
false,
false,
false,
],
newCharacter: {
spawnPosition: new Vec3(1038.40, -666.70, 14.97),
spawnHeading: 0.0,
money: 1000,
},
npcFarProximity: 100,
npcMediumProximity: 40,
npcCloseProximity: 12,
meActionDistance: 20,
doActionDistance: 15,
shoutDistance: 30,
talkDistance: 10,
whisperDistance: 2,
megaphoneDistance: 40,
};
// ----------------------------------------------------------------------------

30
scripts/server/const.js Normal file
View File

@@ -0,0 +1,30 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: const.js
// DESC: Provides constants
// TYPE: Server (JavaScript)
// ===========================================================================
// Sphere types
const AG_SPHERE_HOUSE = 1;
const AG_SPHERE_BUSINESS = 2;
// Prompts (used for client GUI prompt responses)
const AG_PROMPT_CREATEFIRSTCHAR = 1;
// Job Types
const AG_JOB_NONE = 0;
const AG_JOB_POLICE = 1;
const AG_JOB_MEDICAL = 2;
const AG_JOB_FIRE = 3;
const AG_JOB_BUS = 4;
const AG_JOB_TAXI = 5;
const AG_JOB_GARBAGE = 6;
const AG_JOB_WEAPON = 7;
const AG_JOB_DRUG = 8;
// Pickup Owner Types
const AG_PICKUP_JOB = 1;

736
scripts/server/core.js Normal file
View File

@@ -0,0 +1,736 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: core.js
// DESC: Provides core data structures, function, and operations
// TYPE: Server (JavaScript)
// ===========================================================================
let serverId = server.game;
// ----------------------------------------------------------------------------
let serverData = {
saveDataIntervalTimer: false,
staffFlagKeys: [
"none",
"basicModeration",
"manageHouses",
"manageVehicles",
"manageBusinesses",
"manageFactions",
"manageClans",
"manageServer",
"developer"
],
moderationFlagKeys: [
"none",
"muted",
"frozen",
"hackerBox",
"jobBanned",
"ammuBanned",
"policeBanned",
"fireBanned",
"gunBanned",
],
factionFlagKeys: [
"none",
"police",
"medical",
"fire",
"government"
],
clanFlagKeys: [
"none",
"illegal",
"legal",
"mafia",
"streetGang",
"weapons",
"drugs",
"humanTrafficking",
"vigilante",
"hitContracts"
],
clanPermissionFlagKeys: [
"none",
"inviteMember",
"removeMember",
"memberRank",
"memberFlags",
"memberTag",
"memberTitle",
"rankFlags",
"rankTag",
"rankTitle",
"clanTag",
"clanName",
"owner"
],
accountSettingsFlagKeys: [
"None",
"useWhiteList",
"useBlackList",
"twoStepAuth",
"authAttemptAlert"
],
subAccountSettingsFlagKeys: [],
staffFlags: {},
moderationFlags: {},
factionFlags: {},
clanFlags: {},
accountSettingsFlags: {},
subAccountSettingsFlags: {},
vehicles: [],
clients: new Array(128),
businesses: [],
houses: [],
families: [],
factions: [],
translation: {
translationBaseURL: "http://api.mymemory.translated.net/get?de=example@example.com&q={0}&langpair={1}|{2}",
languages: [
["Abkhazian", "AB"],
["Afar", "AA"],
["Afrikaans", "AF"],
["Albanian", "SQ"],
["Amharic", "AM"],
["Arabic", "AR"],
["Armenian", "HY"],
["Assamese", "AS"],
["Aymara", "AY"],
["Azerbaijani", "AZ"],
["Bashkir", "BA"],
["Basque", "EU"],
["Bengali, Bangla", "BN"],
["Bhutani", "DZ"],
["Bihari", "BH"],
["Bislama", "BI"],
["Breton", "BR"],
["Bulgarian", "BG"],
["Burmese", "MY"],
["Byelorussian", "BE"],
["Cambodian", "KM"],
["Catalan", "CA"],
["Chinese", "ZH"],
["Corsican", "CO"],
["Croatian", "HR"],
["Czech", "CS"],
["Danish", "DA"],
["Dutch", "NL"],
["English", "EN"],
["Esperanto", "EO"],
["Estonian", "ET"],
["Faeroese", "FO"],
["Fiji", "FJ"],
["Finnish", "FI"],
["French", "FR"],
["Frisian", "FY"],
["Gaelic (Scots Gaelic)", "GD"],
["Galician", "GL"],
["Georgian", "KA"],
["German", "DE"],
["Greek", "EL"],
["Greenlandic", "KL"],
["Guarani", "GN"],
["Gujarati", "GU"],
["Hausa", "HA"],
["Hebrew", "IW"],
["Hindi", "HI"],
["Hungarian", "HU"],
["Icelandic", "IS"],
["Indonesian", "IN"],
["Interlingua", "IA"],
["Interlingue", "IE"],
["Inupiak", "IK"],
["Irish", "GA"],
["Italian", "IT"],
["Japanese", "JA"],
["Javanese", "JW"],
["Kannada", "KN"],
["Kashmiri", "KS"],
["Kazakh", "KK"],
["Kinyarwanda", "RW"],
["Kirghiz", "KY"],
["Kirundi", "RN"],
["Korean", "KO"],
["Kurdish", "KU"],
["Laothian", "LO"],
["Latin", "LA"],
["Latvian, Lettish", "LV"],
["Lingala", "LN"],
["Lithuanian", "LT"],
["Macedonian", "MK"],
["Malagasy", "MG"],
["Malay", "MS"],
["Malayalam", "ML"],
["Maltese", "MT"],
["Maori", "MI"],
["Marathi", "MR"],
["Moldavian", "MO"],
["Mongolian", "MN"],
["Nauru", "NA"],
["Nepali", "NE"],
["Norwegian", "NO"],
["Occitan", "OC"],
["Oriya", "OR"],
["Oromo, Afan", "OM"],
["Pashto, Pushto", "PS"],
["Persian", "FA"],
["Polish", "PL"],
["Portuguese", "PT"],
["Punjabi", "PA"],
["Quechua", "QU"],
["Rhaeto-Romance", "RM"],
["Romanian", "RO"],
["Russian", "RU"],
["Samoan", "SM"],
["Sangro", "SG"],
["Sanskrit", "SA"],
["Serbian", "SR"],
["Serbo-Croatian", "SH"],
["Sesotho", "ST"],
["Setswana", "TN"],
["Shona", "SN"],
["Sindhi", "SD"],
["Singhalese", "SI"],
["Siswati", "SS"],
["Slovak", "SK"],
["Slovenian", "SL"],
["Somali", "SO"],
["Spanish", "ES"],
["Sudanese", "SU"],
["Swahili", "SW"],
["Swedish", "SV"],
["Tagalog", "TL"],
["Tajik", "TG"],
["Tamil", "TA"],
["Tatar", "TT"],
["Tegulu", "TE"],
["Thai", "TH"],
["Tibetan", "BO"],
["Tigrinya", "TI"],
["Tonga", "TO"],
["Tsonga", "TS"],
["Turkish", "TR"],
["Turkmen", "TK"],
["Twi", "TW"],
["Ukrainian", "UK"],
["Urdu", "UR"],
["Uzbek", "UZ"],
["Vietnamese", "VI"],
["Volapuk", "VO"],
["Welsh", "CY"],
["Wolof", "WO"],
["Xhosa", "XH"],
["Yiddish", "JI"],
["Yoruba", "YO"],
["Zulu", "ZU"]
],
cache: null,
},
commands: {},
policeStations: [
false,
[ // GTA 3
{
position: new Vec3(1143.875, -675.1875, 14.97),
heading: 1.5,
blip: false,
name: "Portland",
},
{
position: new Vec3(340.25, -1123.375, 25.98),
heading: 3.14,
blip: false,
name: "Staunton Island",
},
{
position: new Vec3(-1253.0, -138.1875, 58.75),
heading: 1.5,
blip: false,
name: "Shoreside Vale",
},
],
[ // GTA VC
],
[ // GTA SA
],
[ // GTA UG
],
[ // GTA IV
]
],
fireStations: [
false,
[ // GTA 3
{
position: new Vec3(1103.70, -52.45, 7.49),
heading: 1.5,
blip: false,
name: "Portland",
},
{
position: new Vec3(-78.48, -436.80, 16.17),
heading: 3.14,
blip: false,
name: "Staunton Island",
},
{
position: new Vec3(-1202.10, -14.67, 53.20),
heading: 1.5,
blip: false,
name: "Shoreside Vale",
},
],
[ // GTA VC
],
[ // GTA SA
],
[ // GTA UG
],
[ // GTA IV
]
],
hospitals: [
false,
[ // GTA 3
{
position: new Vec3(1144.25, -596.875, 14.97),
heading: 1.5,
blip: false,
name: "Portland",
},
{
position: new Vec3(183.5, -17.75, 16.21),
heading: 3.14,
blip: false,
name: "Staunton Island",
},
{
position: new Vec3(-1259.5, -44.5, 58.89),
heading: 1.5,
blip: false,
name: "Shoreside Vale",
},
],
[ // GTA VC
],
[ // GTA SA
],
[ // GTA UG
],
[ // GTA IV
]
],
payAndSprays: [
false,
[ // GTA 3
{
position: new Vec3(925.4, -360.3, 10.83),
blip: false,
name: "Portland",
},
{
position: new Vec3(381.8, -493.8, 25.95),
blip: false,
name: "Staunton Island",
},
{
position: new Vec3(-1142.4, 35.01, 58.61),
blip: false,
name: "Shoreside Vale",
},
],
[ // GTA VC
],
[ // GTA SA
],
[ // GTA UG
],
[ // GTA IV
]
],
ammunations: [
false,
[ // GTA 3
{
position: new Vec3(1068.3, -400.9, 15.24),
blip: false,
name: "Portland",
},
{
position: new Vec3(348.2, -717.9, 26.43),
blip: false,
name: "Staunton Island",
},
],
[ // GTA VC
],
[ // GTA SA
],
[ // GTA UG
],
[ // GTA IV
]
],
fuelStations: [
false,
[ // GTA 3
{
position: new Vec3(1161.9, -76.73, 7.27),
blip: false,
name: "Portland",
},
],
[ // GTA VC
],
[ // GTA SA
],
[ // GTA UG
],
[ // GTA IV
]
],
jobs: [
false,
[ // GTA 3
{
name: "Police Officer",
position: new Vec3(1143.87, -675.18, 14.97),
pickup: false,
pickupModel: 1383,
blip: false,
jobType: AG_JOB_POLICE,
jobSkin: 1,
jobColour: serverConfig.colour.byName.policeBlue,
enabled: true
},
{
name: "Paramedic",
position: new Vec3(1144.25, -596.87, 14.97),
pickup: false,
pickupModel: 1362,
blip: false,
jobType: AG_JOB_MEDICAL,
jobSkin: 5,
jobColour: serverConfig.colour.byName.medicPink,
enabled: true
},
{
name: "Firefighter",
position: new Vec3(1103.70, -52.45, 7.49),
pickup: false,
pickupModel: 1364,
blip: false,
jobType: AG_JOB_FIRE,
jobSkin: 6,
jobColour: serverConfig.colour.byName.firefighterRed,
enabled: true
},
{
name: "Trash Collector",
position: new Vec3(1121.8, 27.8, 1.99),
pickup: false,
pickupModel: 1351,
blip: false,
jobType: AG_JOB_GARBAGE,
jobSkin: 53,
jobColour: 2,
enabled: true
},
{
name: "Trash Collector",
position: new Vec3(-66.83, -932.2, 16.47),
pickup: false,
pickupModel: 1351,
blip: false,
jobType: AG_JOB_GARBAGE,
jobSkin: 53,
jobColour: 2,
enabled: true
},
{
name: "Taxi Driver",
position: new Vec3(1229.2, -740.1, 15.17),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_TAXI,
jobSkin: 8,
jobColour: 3,
enabled: true
},
{
name: "Bus Driver",
position: new Vec3(1310.20, -1016.30, 14.88),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_BUS,
jobSkin: 121,
jobColour: 3,
enabled: true
},
{
name: "Police Officer",
position: new Vec3(340.25, -1123.37, 25.98),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_POLICE,
jobSkin: 1,
jobColour: serverConfig.colour.byName.policeBlue,
enabled: true
},
{
name: "Police Officer",
position: new Vec3(-1253.0, -138.18, 58.75),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_POLICE,
jobSkin: 1,
jobColour: serverConfig.colour.byName.policeBlue,
enabled: true
},
{
name: "Paramedic",
position: new Vec3(183.5, -17.75, 16.21),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_MEDICAL,
jobSkin: 5,
jobColour: serverConfig.colour.byName.medicPink,
enabled: true
},
{
name: "Paramedic",
position: new Vec3(-1259.5, -44.5, 58.89),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_MEDICAL,
jobSkin: 5,
jobColour: serverConfig.colour.byName.medicPink,
enabled: true
} ,
{
name: "Firefighter",
position: new Vec3(-78.48, -436.80, 16.17),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_FIRE,
jobSkin: 6,
jobColour: serverConfig.colour.byName.firefighterRed,
enabled: true
},
{
name: "Firefighter",
position: new Vec3(-1202.10, -14.67, 53.20),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_FIRE,
jobSkin: 6,
jobColour: serverConfig.colour.byName.firefighterRed,
enabled: true
},
{
name: "Taxi Driver",
position: new Vec3(1229.2, -740.1, 15.17),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_TAXI,
jobSkin: 8,
jobColour: 3,
enabled: true
},
{
name: "Bus Driver",
position: new Vec3(-57.1661, -334.266, 16.9324),
pickup: false,
pickupModel: 1361,
blip: false,
jobType: AG_JOB_BUS,
jobSkin: 121,
jobColour: 3,
enabled: true
},
],
[ // GTA VC
],
[ // GTA SA
],
[ // GTA UG
],
[ // GTA IV
]
//{ name: "Postal Worker" , position: Vector ( ) , pickup: false, pickupModel: 1361, blip: false, jobType: 7 },
//{ name: "Delivery Worker" , position: Vector ( ) , pickup: false, pickupModel: 1361, blip: false, jobType: 8 },
//{ name: "Mechanic" , position: Vector ( ) , pickup: false, pickupModel: 1361, blip: false, jobType: 9 },
],
policeJobSkins: [
false,
[ // GTA III
1, 92,
],
[ // GTA VC
1,
],
[ // GTA SA
280, 281, 282, 283, 284, 285, 28, 288,
],
[ // GTA UG
],
[ // GTA IV
]
],
medicalJobSkins: [
false,
[ // GTA III
5, 72, 73
],
[ // GTA VC
5,
],
[ // GTA SA
274, 275, 276
],
[ // GTA UG
],
[ // GTA IV
]
],
fireJobSkins: [
false,
[ // GTA III
6
],
[ // GTA VC
6,
],
[ // GTA SA
277, 278, 279
],
[ // GTA UG
],
[ // GTA IV
]
],
taxiJobSkins: [
false,
[ // GTA III
8,
],
[ // GTA VC
8,
],
[ // GTA SA
7, 142
],
[ // GTA UG
],
[ // GTA IV
]
],
busJobSkins: [
false,
[ // GTA III
8,
],
[ // GTA VC
8,
],
[ // GTA SA
7, 142
],
[ // GTA UG
],
[ // GTA IV
]
],
garbageJobSkins: [
false,
[ // GTA III
53, 54,
],
[ // GTA VC
53, 54,
],
[ // GTA SA
16,
],
[ // GTA UG
],
[ // GTA IV
]
],
};
// ----------------------------------------------------------------------------
function initServerData() {
// Pre-allocate translation cache language slots
global.serverData.translation.cache = new Array(global.serverData.translation.languages.length);
let translationCacheFrom = new Array(global.serverData.translation.languages.length);
translationCacheFrom.fill([]);
global.serverData.translation.cache.fill(translationCacheFrom);
}
// ----------------------------------------------------------------------------
function getServerId() {
return serverId;
}
// ----------------------------------------------------------------------------

View File

@@ -0,0 +1,72 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: database.js
// DESC: Provides database handling, functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
// ----------------------------------------------------------------------------
let databaseConfig = {
host: "158.69.238.64",
user: "db24053",
pass: "G3At3d7BsA",
name: "db24053",
port: 3306,
usePersistentConnection: true,
}
let persistentDatabaseConnection = null;
// ----------------------------------------------------------------------------
function initDatabaseScript() {
console.log("[Asshat.Database]: Initializing database script ...");
addDatabaseCommandHandlers()
console.log("[Asshat.Database]: Database script initialized successfully!");
}
// ----------------------------------------------------------------------------
function addDatabaseCommandHandlers() {
console.log("[Asshat.Database]: Adding database command handlers ...");
let databaseCommands = serverCommands.database;
for(let i in databaseCommands) {
addCommandHandler(databaseCommands[i].command, databaseCommands[i].handlerFunction);
}
console.log("[Asshat.Database]: Database command handlers added!");
}
// ----------------------------------------------------------------------------
function connectToDatabase() {
if(persistentDatabaseConnection == null) {
console.log("[Asshat.Database] Initializing database connection ...");
persistentDatabaseConnection = module.mysql.connect(databaseConfig.host, databaseConfig.user, databaseConfig.pass, databaseConfig.name, databaseConfig.port);
if(persistentDatabaseConnection.error) {
console.warn("[Asshat.Database] Database connection error: " + String(persistentDatabaseConnection.error));
persistentDatabaseConnection = null;
return false;
}
console.log("[Asshat.Database] Database connection successful!");
return persistentDatabaseConnection;
} else {
console.log("[Asshat.Database] Using existing database connection.");
return persistentDatabaseConnection;
}
}
// ----------------------------------------------------------------------------
function disconnectFromDatabase(dbConnection) {
if(!databaseConfig.usePersistentConnection) {
dbConnection.close();
}
return true;
}
// ----------------------------------------------------------------------------

168
scripts/server/developer.js Normal file
View File

@@ -0,0 +1,168 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: developer.js
// DESC: Provides developer operation, commands, functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initDeveloperScript() {
console.log("[Asshat.Developer]: Initializing developer script ...");
addDeveloperCommandHandlers()
console.log("[Asshat.Developer]: Developer script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addDeveloperCommandHandlers() {
console.log("[Asshat.Developer]: Adding developer command handlers ...");
let developerCommands = serverCommands.database;
for(let i in developerCommands) {
addCommandHandler(developerCommands[i].command, developerCommands[i].handlerFunction);
}
console.log("[Asshat.Developer]: Developer command handlers added!");
return true;
}
// ---------------------------------------------------------------------------
function executeServerCodeCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
try {
eval(params);
} catch(error) {
messageClientError(client, "The code could not be executed!");
return false;
}
messageClientSuccess(client, "Code executed!");
messageClientNormal(client, "Code: " + params);
return true;
}
// ---------------------------------------------------------------------------
function executeClientCodeCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let splitParams = params.split();
let targetClient = getClientFromParams(splitParams[0]);
let code = splitParams.slice(1).join(" ");
if(!targetClient) {
messageClientError(client, "That player was not found!");
return false;
}
if(code.length > 0) {
messageClientError(client, "You didn't enter any code!");
return false;
}
triggerNetworkEvent("ag.runcode", targetClient, code);
messageClientSuccess(client, "Client code executed for " + String(targetClient.name) + "!");
messageClientNormal(client, "Code: " + params);
return true;
}
// ---------------------------------------------------------------------------
function restartGameModeCommand(command, params, client) {
if(client.administrator) {
consoleCommand("/refresh");
thisResource.restart();
}
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
thisResource.restart();
return true;
}
// ---------------------------------------------------------------------------
function developerAnnounceCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
developerAnnouncement(client, params);
return true;
}
// ---------------------------------------------------------------------------
function queryDatabaseCommand(command, params, client) {
//if(client == consoleClient) {
let databaseConnection = connectToDatabase();
if(databaseConnection.error) {
console.error("Database error: " + databaseConnection.error);
return false;
}
let query = databaseConnection.query(params);
if(databaseConnection.error) {
console.error("Query error: " + databaseConnection.error);
return false;
}
console.log("Query executed!");
console.log(query.fetchRow()[0]);
//}
}
addCommandHandler("query", queryDatabaseCommand);
// ---------------------------------------------------------------------------

67
scripts/server/discord.js Normal file
View File

@@ -0,0 +1,67 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: discord.js
// DESC: Provides discord bridging and connection functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
addEventHandler("OnDiscordCommand", function(command, params, discordUser) {
let commandData = getCommand(command);
if(!commandData) {
messageClientError(discordUser, "That command does not exist!");
return false;
}
if(isCommandAllowedOnDiscord(command)) {
messageClientError(discordUser, "That command can not be used on Discord!");
return false;
}
if(doesClientHavePermission(discordUser, getCommandRequiredPermissions(command))) {
messageClientError(discordUser, "You do not have permission to use that command!");
return false;
}
commandData.handlerFunction(command, params, discordUser);
});
// ---------------------------------------------------------------------------
function messageDiscordUser(discordUser, messageText) {
let socketData = JSON.stringify({
type: "chat.message.text",
payload: {
author: discordUser.name,
text: messageText,
}
});
sendDiscordSocketData(socketData);
}
// ---------------------------------------------------------------------------
function sendDiscordSocketData(socketData) {
getDiscordSocket().send(module.hash.encodeBase64(socketData) + "\r\n");
}
// ---------------------------------------------------------------------------
function isClientFromDiscord(client) {
if(client instanceof Client) {
return false;
} else {
return false;
}
}
// ---------------------------------------------------------------------------
function getDiscordUserData(discordUserId) {
return loadAccountFromDiscordUserId(discordUserId);
}
// ---------------------------------------------------------------------------

75
scripts/server/event.js Normal file
View File

@@ -0,0 +1,75 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: event.js
// DESC: Provides handlers for built in GTAC and Asshat-Gaming created events
// TYPE: Server (JavaScript)
// ===========================================================================
addEventHandler("OnPlayerJoined", function(event, client) {
triggerNetworkEvent("ag.connectCamera", client, serverConfig.connectCameraPosition[server.game], serverConfig.connectCameraLookAt[server.game]);
client.setData("ag.loginAttemptsRemaining", 3, false);
let tempAccountData = loadAccountFromName(client.name);
let tempSubAccounts = loadSubAccountsFromAccount(tempAccountData.databaseId);
serverData.clients[client.index] = new serverClasses.clientData(client, tempAccountData, tempSubAccounts);
if(tempAccountData != false) {
triggerNetworkEvent("ag.showLogin", client);
//messageClient("Welcome back to Asshat Gaming RP, " + String(client.name) + "! Please /login to continue.", client, serverConfig.colour.byName["white"]);
} else {
triggerNetworkEvent("ag.showRegistration", client);
//messageClient("Welcome to Asshat Gaming RP, " + String(client.name) + "! Please /register to continue.", client, serverConfig.colour.byName["white"]);
}
});
// ---------------------------------------------------------------------------
addEventHandler("OnPlayerQuit", function(event, client, quitReasonId) {
saveClientToDatabase(client);
serverData.clients[client.index] = null;
});
// ---------------------------------------------------------------------------
addEventHandler("OnPedSpawn", function(event, ped) {
if(ped.isType(ELEMENT_PLAYER)) {
let client = getClientFromPlayerElement(ped);
triggerNetworkEvent("ag.locations", client, serverData.policeStations[server.game], serverData.fireStations[server.game], serverData.hospitals[server.game], serverData.payAndSprays[server.game], serverData.ammunations[server.game], serverData.jobs[server.game]);
}
});
// ---------------------------------------------------------------------------
addEventHandler("OnPedWasted", function(event, wastedPed, killerPed, weaponId, pedPiece) {
let closestHospital = getClosestHospital(wastedPed.position);
let client = getClientFromPedElement(wastedPed);
spawnPlayer(client, closestHospital.position, closestHospital.heading, getClientCurrentSubAccount(client).skin);
});
// ---------------------------------------------------------------------------
bindEventHandler("OnResourceStop", thisResource, function(event, resource) {
//console.log("[Asshat.Event]: Resource stopping. Saving all data to database ...");
//saveAllClientsToDatabase();
//console.log("[Asshat.Event]: All data saved to database successfully!");
});
// ---------------------------------------------------------------------------
bindEventHandler("OnResourceStart", thisResource, function(event, resource) {
getClients().forEach(function(client) {
initClient(client);
});
createAllLocationBlips();
serverData.saveDataIntervalTimer = setInterval(saveAllServerDataToDatabase, 600000);
});
// ---------------------------------------------------------------------------

59
scripts/server/faction.js Normal file
View File

@@ -0,0 +1,59 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: faction.js
// DESC: Provides faction functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initFactionScript() {
console.log("[Asshat.Faction]: Initializing faction script ...");
addFactionCommandHandlers();
console.log("[Asshat.Faction]: Faction script initialized!");
return true;
}
// ---------------------------------------------------------------------------
function addFactionCommandHandlers() {
console.log("[Asshat.Faction]: Adding faction command handlers ...");
let factionCommands = serverCommands.faction;
for(let i in factionCommands) {
addCommandHandler(factionCommands[i].command, factionCommands[i].handlerFunction);
}
console.log("[Asshat.Faction]: Faction command handlers added!");
return true;
}
// ---------------------------------------------------------------------------
function loadFactionsFromDatabase() {
console.log("[Asshat.Faction]: Loading factions from database ...");
let tempFactions = [];
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = dbConnection.query("SELECT * FROM `fac_main` WHERE `fac_server` = " + String(serverId));
if(dbQuery) {
if(dbQuery.numRows > 0) {
while(dbFetchAssoc = dbQuery.fetchAssoc()) {
let tempFactionData = getClasses().clanData(dbFetchAssoc);
tempFactionData.members = loadFactionMembersFromDatabase(tempFactionData.databaseId);
tempFactionData.ranks = loadFactionRanksFromDatabase(tempFactionData.databaseId);
tempFactions.push(tempFactionData);
console.log(`[Asshat.Faction]: Faction '${tempFactionData.name}' loaded from database successfully!`);
}
}
dbQuery.free();
}
dbConnection.close();
}
console.log("[Asshat.Faction]: " + String(tempFactions.length) + " factions loaded from database successfully!");
return tempFactions;
}
// ---------------------------------------------------------------------------

10
scripts/server/help.js Normal file
View File

@@ -0,0 +1,10 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: help.js
// DESC: Provides update info, help commands, and documentation
// TYPE: Server (JavaScript)
// ===========================================================================

98
scripts/server/house.js Normal file
View File

@@ -0,0 +1,98 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: house.js
// DESC: Provides house commands, functions, and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initHouseScript() {
console.log("[Asshat.House]: Initializing house script ...");
serverData.houses = loadHousesFromDatabase();
addHouseCommandHandlers();
console.log("[Asshat.House]: House script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addHouseCommandHandlers() {
console.log("[Asshat.House]: Adding house commands!");
let houseCommands = serverCommands.house;
for(let i in houseCommands) {
addCommandHandler(houseCommands[i].command, houseCommands[i].handlerFunction);
}
console.log("[Asshat.House]: House commands added!");
return true;
}
// ---------------------------------------------------------------------------
function loadHousesFromDatabase() {
console.log("[Asshat.House]: Loading houses from database ...");
let tempHouses = [];
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = dbConnection.query("SELECT * FROM `house_main` WHERE `house_server` = " + String(serverId))
if(dbQuery) {
if(dbQuery.numRows > 0) {
while(dbFetchAssoc = dbQuery.fetchAssoc()) {
let tempHouseData = getClasses().houseData(dbFetchAssoc);
tempHouses.push(tempHouseData);
console.log("[Asshat.House]: Houses '" + String(tempHouseData.databaseId) + "' loaded!");
}
}
dbQuery.free();
}
disconnectFromDatabase(dbConnection);
}
console.log("[Asshat.House]: " + String(tempHouses.length) + " houses loaded from database successfully!");
return tempHouses;
}
// ---------------------------------------------------------------------------
function getHouseDataFromDatabaseId(databaseId) {
let matchingHouses = serverData.houses.filter(b => b.databaseId == databaseId)
if(matchingHouses.length == 1) {
return matchingHouses[0];
}
return false;
}
// ---------------------------------------------------------------------------
function getClosestHouseEntrance(position) {
return serverData.houses.reduce((i, j) => ((i.entrancePosition.distance(position) <= j.entrancePosition.distance(position)) ? i : j));
}
// ---------------------------------------------------------------------------
function isPlayerInAnyBusiness(player) {
if(player.getData("ag.inHouse")) {
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function getPlayerHouse(player) {
if(player.getData("ag.inHouse")) {
return player.getData("ag.inHouse");
}
return false;
}
// ---------------------------------------------------------------------------
function saveAllHousesToDatabase() {
}
// ---------------------------------------------------------------------------

42
scripts/server/item.js Normal file
View File

@@ -0,0 +1,42 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: item.js
// DESC: Provides item functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initItemScript() {
return true;
}
// ---------------------------------------------------------------------------
function addItemCommandHandlers() {
return true;
}
// ---------------------------------------------------------------------------
function loadItemsFromDatabase() {
let tempItems = [];
let dbConnection = connectToDatabase();
if(dbConnection) {
let dbQuery = dbConnection.query("SELECT * FROM `item_main` WHERE `item_server` = " + getServerGame())
if(dbQuery) {
if(dbQuery.numRows > 0) {
while(dbFetchAssoc = dbQuery.fetchAssoc()) {
let tempItemData = getClasses().itemData(dbFetchAssoc);
tempItems.push(tempItemData);
}
}
dbQuery.free();
}
disconnectFromDatabase(dbConnection);
}
}
// ---------------------------------------------------------------------------

538
scripts/server/job.js Normal file
View File

@@ -0,0 +1,538 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: job.js
// DESC: Provides job functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initJobScript() {
console.log("[Asshat.Job]: Initializing job script ...");
addJobCommandHandlers();
createAllJobPickups();
createAllJobBlips();
//addEvent("onJobPickupCollected", null, 2);
console.log("[Asshat.Job]: Job script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addJobCommandHandlers() {
console.log("[Asshat.Job]: Adding job command handlers ...");
let jobCommands = serverCommands.job;
for(let i in jobCommands) {
addCommandHandler(jobCommands[i].command, jobCommands[i].handlerFunction);
}
console.log("[Asshat.Job]: Job command handlers added successfully!");
return true;
}
// ---------------------------------------------------------------------------
function createAllJobBlips() {
for(let i in serverData.jobs[server.game]) {
serverData.jobs[server.game][i].blip = createBlip(0, serverData.jobs[server.game][i].position, 2, serverConfig.colour.byName.burntYellow);
//serverData.jobs[server.game][i].position
}
}
// ---------------------------------------------------------------------------
function createAllJobPickups() {
for(let i in serverData.jobs[server.game]) {
serverData.jobs[server.game][i].pickup = createPickup(serverData.jobs[server.game][i].pickupModel, serverData.jobs[server.game][i].position, PICKUP_COLLECTABLE1);
serverData.jobs[server.game][i].pickup.setData("ag.ownerType", AG_PICKUP_JOB, false);
serverData.jobs[server.game][i].pickup.setData("ag.ownerId", i, false);
}
}
// ---------------------------------------------------------------------------
function showJobInformationToPlayer(client, jobType) {
if(!canClientUseJobs(client)){
return false;
}
if(jobType == getClientCurrentSubAccount(client).job) {
messageClientInfo("Welcome back to your job. Use /startwork to begin.");
return false;
}
switch(jobType) {
case AG_JOB_POLICE:
if(!canClientUsePoliceJob(client)) {
return false;
}
messageClientInfo(client, "== Job Help =================================");
messageClientInfo(client, "- Police Officers are enforcers of the law.");
messageClientInfo(client, "- Use /startwork at a police station to work as a Police Officer.");
messageClientInfo(client, "- Use /laws to see a list of laws.");
messageClientInfo(client, "- Commands are: /cuff, /drag, /detain, /arrest, /search /tazer /radio");
messageClientInfo(client, "- When finished, use /stopwork to stop working.");
break;
case AG_JOB_MEDICAL:
messageClientInfo(client, "== Job Help =================================");
messageClientInfo(client, "- Paramedics help people by healing them.");
messageClientInfo(client, "- Use /startwork at the hospital to work as a Paramedic.");
messageClientInfo(client, "- People can enter your ambulance to get healed.");
messageClientInfo(client, "- The pay depends on the player's health before healing them.");
messageClientInfo(client, "- When finished, use /stopwork to stop working.");
break;
case AG_JOB_FIRE:
if(!canClientUseFireJob(client)){
return false;
}
messageClientInfo(client, "== Job Help =================================");
messageClientInfo(client, "- Firefighters put out vehicle and building fires.");
messageClientInfo(client, "- Use /startwork at the fire station to work as a Firefighter.");
messageClientInfo(client, "- Get in a firetruck and you will be told where to go.");
messageClientInfo(client, "- Use the firetruck hose to put out fires");
messageClientInfo(client, "- When finished, use /stopwork to stop working.");
break;
case AG_JOB_BUS:
messageClientInfo(client, "== Job Help =================================");
messageClientInfo(client, "- Bus Drivers transport people around the city on a route");
messageClientInfo(client, "- Use /startwork at the bus depot to work as a Bus Driver.");
messageClientInfo(client, "- Passengers can get on/off at any stop on your route");
messageClientInfo(client, "- Stay on your assigned route. You will be paid when finished.");
messageClientInfo(client, "- When finished, use /stopwork to stop working.");
break;
case AG_JOB_TAXI:
messageClientInfo(client, "== Job Help =================================");
messageClientInfo(client, "- Taxi Drivers transport people around the city");
messageClientInfo(client, "- Use /startwork at the taxi depot to work as a Taxi Driver.");
messageClientInfo(client, "- Use /fare to set a fare. Fares start when a player gets in.");
messageClientInfo(client, "- The meter will run until the player exits the vehicle.");
messageClientInfo(client, "- You will automatically receive the fare money");
messageClientInfo(client, "- When finished, use /stopwork to stop working.");
break;
case AG_JOB_GARBAGE:
messageClientInfo(client, "== Job Help =================================");
messageClientInfo(client, "- Garbage Collectors pick up the trash around the city.");
messageClientInfo(client, "- Use /startwork at the garbage depot to work as a Garbage Collector.");
messageClientInfo(client, "- Drive up to a garbage can or dumpster, and right click to grab a bag.");
messageClientInfo(client, "- Walk up to the back of your truck and right click again to throw the bag in.");
messageClientInfo(client, "- Your truck can hold 25 trashbags. Each bag is worth $25");
messageClientInfo(client, "- Drive to the garbage depot again to deliver trash");
messageClientInfo(client, "- When finished, use /stopwork to stop working.");
break;
case AG_JOB_WEAPON:
break;
case AG_JOB_DRUG:
break;
default:
break;
}
}
// ---------------------------------------------------------------------------
function takeJobCommand(command, params, client) {
if(!canClientUseJobs(client)){
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
let closestJob = getClosestJobPoint(client.player.position);
if(closestJob.position.distance(client.player.position) > 5) {
messageClientError(client, "There are no job points close enough!");
return false;
}
if(getClientCurrentSubAccount(client).job != AG_JOB_NONE) {
getClientCurrentSubAccount(client).job = closestJob.jobType;
}
messageClientSuccess(client, "You now have the " + String(closestJob.name) + " job");
return true;
}
// ---------------------------------------------------------------------------
function startWorkingCommand(command, params, client) {
if(!canClientUseJobs(client)){
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
let closestJob = getClosestJobPoint(client.player.position);
if(closestJob.position.distance(client.player.position) > 5) {
messageClientError(client, "There are no job points close enough!");
return false;
}
if(getClientCurrentSubAccount(client).job != closestJob.jobType) {
messageClientError(client, "This is not your job!");
messageClientInfo(client, "Use /quitjob if you want to quit your current job and take this one.");
return false;
}
startWorking(client);
messageClientSuccess(client, "You are now working as a " + String(closestJob.name));
return true;
}
// ---------------------------------------------------------------------------
function stopWorkingCommand(command, params, client) {
if(!canClientUseJobs(client)){
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
let closestJob = getClosestJobPoint(client.player.position);
if(closestJob.position.distance(client.player.position) > 5) {
messageClientError(client, "There are no job points close enough!");
return false;
}
//if(getClientCurrentSubAccount(client).job != closestJob.jobType) {
// messageClientError(client, "This is not your job!");
// messageClientInfo(client, "Use /quitjob if you want to quit your current job and take this one.");
// break;
//}
stopWorking(client);
messageClientSuccess(client, "You have stopped working!");
return true;
}
// ---------------------------------------------------------------------------
function startWorking(client) {
if(!canClientUseJobs(client)){
return false;
}
getClientCurrentSubAccount(client).isWorking = true;
let jobId = getClientCurrentSubAccount(client).job;
switch(serverData.jobs[server.game][jobId].jobType) {
case AG_JOB_POLICE:
messageClientInfo(client, "Use /uniform and /equip to get your equipment.");
break;
case AG_JOB_MEDICAL:
messageClientInfo(client, "Use /uniform and /equip to get your equipment.");
break;
case AG_JOB_FIRE:
messageClientInfo(client, "Use /uniform and /equip to get your equipment.");
break;
case AG_JOB_BUS:
messageClientInfo(client, "Get in a bus to get started.");
break;
case AG_JOB_TAXI:
messageClientInfo(client, "Get in a taxi to get started.");
break;
case AG_JOB_GARBAGE:
messageClientInfo(client, "Get in a trash truck to get started.");
break;
case AG_JOB_WEAPON:
break;
case AG_JOB_DRUG:
break;
default:
break;
}
}
// ---------------------------------------------------------------------------
function stopWorking(client) {
if(!canClientUseJobs(client)){
return false;
}
getClientCurrentSubAccount(client).isWorking = false;
client.player.skin = getClientCurrentSubAccount(client).skin;
let jobVehicle = getClientCurrentSubAccount(client).lastJobVehicle;
if(jobVehicle) {
let vehicleData = getVehicleData(jobVehicle);
jobVehicle.fix();
jobVehicle.position = vehicleData.spawnPosition;
jobVehicle.heading = vehicleData.spawnHeading;
}
triggerNetworkEvent("ag.clearWeapons", client);
let jobId = getClientCurrentSubAccount(client).job;
switch(serverData.jobs[server.game][jobId].jobType) {
case AG_JOB_POLICE:
messageClientInfo(client, "Your uniform, equipment, and police car have been returned to the police station");
break;
case AG_JOB_MEDICAL:
messageClientInfo(client, "Your uniform and ambulance have been returned to the hospital");
break;
case AG_JOB_FIRE:
messageClientInfo(client, "Your uniform and fire truck have been returned to the fire station");
break;
case AG_JOB_BUS:
messageClientInfo(client, "Your bus has been returned to the bus depot");
break;
case AG_JOB_TAXI:
messageClientInfo(client, "Your taxi has been returned to the taxi depot");
break;
case AG_JOB_GARBAGE:
messageClientInfo(client, "Your trash truck has been returned to the city landfill");
break;
case AG_JOB_WEAPON:
break;
case AG_JOB_DRUG:
break;
default:
break;
}
}
// ---------------------------------------------------------------------------
function jobUniformCommand(command, params, client) {
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
let uniformId = Number(params) || 0;
let jobId = getClientCurrentSubAccount(client).job;
getClientCurrentSubAccount(client).jobUniform = uniformId;
switch(serverData.jobs[server.game][jobId].jobType) {
case AG_JOB_POLICE:
client.player.modelIndex = serverData.policeJobSkins[server.game][uniformId];
triggerNetworkEvent("ag.giveWeapon", client, 2, 200, false);
triggerNetworkEvent("ag.giveWeapon", client, 1, 1, false);
break;
case AG_JOB_MEDICAL:
client.player.modelIndex = serverData.medicalJobSkins[server.game][uniformId];
messageClientInfo(client, "Your uniform and ambulance have been returned to the hospital");
break;
case AG_JOB_FIRE:
client.player.modelIndex = serverData.fireJobSkins[server.game][uniformId];
messageClientInfo(client, "Your uniform and fire truck have been returned to the fire station");
break;
case AG_JOB_BUS:
client.player.modelIndex = serverData.busJobSkins[server.game][uniformId];
messageClientInfo(client, "Your bus has been returned to the bus depot");
break;
case AG_JOB_TAXI:
client.player.modelIndex = serverData.taxiJobSkins[server.game][uniformId];
messageClientInfo(client, "Your taxi has been returned to the taxi depot");
break;
case AG_JOB_GARBAGE:
client.player.modelIndex = serverData.garbageJobSkins[server.game][uniformId];
messageClientInfo(client, "Your trash truck has been returned to the city landfill");
break;
case AG_JOB_WEAPON:
break;
case AG_JOB_DRUG:
break;
default:
break;
}
}
// ---------------------------------------------------------------------------
function quitJobCommand(command, params, client) {
if(!canClientUseJobs(client)){
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
stopWorking(client);
let tempJob = getClientCurrentSubAccount(client).job;
getClientCurrentSubAccount(client).job = AG_JOB_NONE;
messageClientSuccess(client, "You just quit the " + String(tempJob.name) + " job");
return true;
}
// ---------------------------------------------------------------------------
function jobRadioCommand(command, params, client) {
if(!canClientUseJobs(client)){
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
return true;
}
// ---------------------------------------------------------------------------
function jobDepartmentRadioCommand(command, params, client) {
if(!canClientUseJobs(client)){
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
return true;
}

97
scripts/server/job/bus.js Normal file
View File

@@ -0,0 +1,97 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: bus.js
// DESC: Provides bus driver job functions and usage
// TYPE: Job (JavaScript)
// ===========================================================================
let busRoutes = [
false,
// GTA 3
[
// PORTLAND ISLAND ROUTE 1
{
name: "Portland Red Line",
island: 1,
busColour: toColour(120, 0, 0, 255),
positions: [
new Vec3(1269, -1056.4, 14.75),
new Vec3(1088.7, -968.8, 14.91),
new Vec3(1059.1, -870.9, 14.91),
new Vec3(917.6, -815.9, 14.91),
new Vec3(851.1, -766.1, 14.91),
new Vec3(838.8, -598.7, 14.91),
new Vec3(959.3, -581.6, 14.91),
new Vec3(853.1, -485.9, 14.91),
new Vec3(838.8, -312.68, 6.8),
new Vec3(913.9, -177.4, 4.91),
new Vec3(1123.3, -67.74, 7.41),
new Vec3(1043.6, -191.63, 4.91),
new Vec3(1213.2, -281.3, 25.76),
new Vec3(1193.3, -474.3, 24.98),
new Vec3(1335.4, -499.7, 45.28),
new Vec3(1220.3, -341.4, 26.38),
new Vec3(1122.6, -475.6, 19.91),
new Vec3(1309.2, -642.4, 12.3),
new Vec3(1350.5, -845, 14.91),
new Vec3(1322.2, -1025.3, 14.76),
],
},
// STAUNTON ISLAND ROUTE 1
{
name: "Staunton Red Line",
island: 2,
busColour: toColour(120, 0, 0, 255),
positions: [
new Vec3(-1.11, -388.4, 16.11),
new Vec3(-15.75, -735.3, 26.15),
new Vec3(33.63, -1029.4, 26.11),
new Vec3(-53.92, -1233.4, 26.11),
new Vec3(126.58, -1323.7, 26.11),
new Vec3(189.39, -1285.6, 26.11),
new Vec3(266.9, -1179.1, 26.11),
new Vec3(283.93, -1370.2, 26.11),
new Vec3(144.44, -1455.5, 26.11),
new Vec3(34.5, -1511.7, 26.11),
new Vec3(325.31, -1579, 26.03),
new Vec3(302.33, -1417.7, 26.11),
new Vec3(309.76, -1290, 26.11),
new Vec3(378.5, -1235.1, 26.11),
new Vec3(404, -1376.3, 26.11),
new Vec3(189.07, -1159.3, 26.11),
new Vec3(189.44, -956.9, 26.11),
new Vec3(254.18, -722.3, 26.11),
new Vec3(383.4, -704.2, 26.11),
new Vec3(429.3, -420.6, 22.04),
new Vec3(570.9, -336.4, 19.71),
new Vec3(267.46, 91.12, 15.96),
new Vec3(99.13, -31.96, 16.11),
new Vec3(243.94, -187.01, 21.31),
new Vec3(99.17, -263.44, 16.11),
new Vec3(-26.92, -283.73, 16.11),
],
},
],
// GTA VC
[
],
// GTA SA
[
],
false,
// GTA IV
[
],
];

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: drug.js
// DESC: Provides drug runner/dealer job functions and usage
// TYPE: Job (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: fire.js
// DESC: Provides firefighter job functions and usage
// TYPE: Job (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,72 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: garbage.js
// DESC: Provides garbage collector job functions and usage
// TYPE: Job (JavaScript)
// ===========================================================================
let garbageRoutes = [
false,
// GTA 3
[
// PORTLAND ISLAND ROUTE 1
{
name: "Portland #1",
island: 1,
positions: [
new Vec3(1169.8, -45.54, 10.4),
new Vec3(928, -59.1, 8.61),
new Vec3(935.4, -262.45, 5.52),
new Vec3(935.4, -262.45, 5.52),
new Vec3(1042.5, -375.9, 15.4),
new Vec3(987, -450.5, 15.39),
new Vec3(871.3, -277.07, 5.4),
new Vec3(1119.4, -766.7, 15.4),
new Vec3(1082.3, -990.8, 15.4),
new Vec3(1166.9, -1046.8, 15.41),
new Vec3(1310.1, -980.4, 15.46),
new Vec3(1129.5, -645.3, 15.4),
new Vec3(1128.9, -446.1, 20.41),
new Vec3(1226.5, -52.41, 10.42) ,
],
},
// STAUNTON ISLAND ROUTE 1
{
name: "Staunton #1",
island: 2,
positions: [
new Vec3(49.85, -1539.9, 26.6),
new Vec3(49.71, -1458.1, 26.6),
new Vec3(170.78, -1403.8, 26.59),
new Vec3(183.48, -1485.9, 26.6),
new Vec3(320.43, -1452.4, 26.6),
new Vec3(310.13, -1311.8, 26.6),
new Vec3(134.76, -1097.7, 26.6),
new Vec3(55.63, -1058.6, 26.6),
new Vec3(-0.02, -790.9, 26.64),
],
},
],
// GTA VC
[
],
// GTA SA
[
],
false,
// GTA IV
[
],
];

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: medic.js
// DESC: Provides medic job functions and usage
// TYPE: Job (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,183 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: police.js
// DESC: Provides police officer job functions and usage
// TYPE: Job (JavaScript)
// ===========================================================================
function policeTazerCommand(command, params, client) {
if(!canClientUseJobs(client) || !!canClientUsePoliceJob(client)){
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
return true;
}
// ---------------------------------------------------------------------------
function policeCuffCommand(command, params, client) {
if(!canClientUseJobs(client) || !!canClientUsePoliceJob(client)) {
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
return true;
}
// ---------------------------------------------------------------------------
function policeArrestCommand(command, params, client) {
if(!canClientUseJobs(client) || !!canClientUsePoliceJob(client)) {
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
return true;
}
// ---------------------------------------------------------------------------
function policeSearchCommand(command, params, client) {
if(!canClientUseJobs(client) || !!canClientUsePoliceJob(client)) {
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
return true;
}
// ---------------------------------------------------------------------------
function policeDragCommand(command, params, client) {
if(!canClientUseJobs(client) || !!canClientUsePoliceJob(client)) {
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
return true;
}
// ---------------------------------------------------------------------------
function policeDetainCommand(command, params, client) {
if(!canClientUseJobs(client) || !!canClientUsePoliceJob(client)) {
return false;
}
if(doesCommandRequireLogin(command)) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You are not logged in!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
return true;
}
// ---------------------------------------------------------------------------

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: taxi.js
// DESC: Provides taxi driver job functions and usage
// TYPE: Job (JavaScript)
// ===========================================================================

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2019 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: weapon.js
// DESC: Provides weapons dealer job functions and usage
// TYPE: Job (JavaScript)
// ===========================================================================

11
scripts/server/locale.js Normal file
View File

@@ -0,0 +1,11 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: locale.js
// DESC: Provides locale structures, functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
// (V) This may be obsolete with the new translation tool!

View File

@@ -0,0 +1,93 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: messaging.js
// DESC: Provides messaging functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
// ---------------------------------------------------------------------------
function messageClientError(client, messageText) {
if(client instanceof Client) {
messageClient("🚫 " + String(messageText), client, getColourByType("errorMessage"));
} else {
messageDiscordUser("🚫 " + String(messageText), client);
}
}
// ---------------------------------------------------------------------------
function messageClientSyntax(client, messageText) {
if(client instanceof Client) {
messageClient("⌨️ [#FFFFFF] " + String(messageText), client, getColourByType("syntaxMessage"));
} else {
messageDiscordUser("⌨️ " + String(messageText), client);
}
}
// ---------------------------------------------------------------------------
function messageClientAlert(client, messageText) {
if(client instanceof Client) {
messageClient("⚠️ [#FFFFFF] " + String(messageText), client, getColourByType("alertMessage"));
} else {
messageDiscordUser("⚠️ " + String(messageText), client);
}
}
// ---------------------------------------------------------------------------
function messageClientSuccess(client, messageText) {
if(client instanceof Client) {
messageClient("👍 [#FFFFFF] " + String(messageText), client, getColourByType("successMessage"));
} else {
messageDiscordUser("👍 " + String(messageText), client);
}
}
// ---------------------------------------------------------------------------
function messageClientInfo(client, messageText) {
if(client instanceof Client) {
messageClient(" [#FFFFFF] " + String(messageText), client, getColourByType("successMessage"));
} else {
messageDiscordUser(" " + String(messageText), client);
}
}
// ---------------------------------------------------------------------------
function messageClientTalk(client, talkingClient, messageText) {
messageClient(getClientSubAccountName(client) + " says: " + String(messageText), client, getColourByType("talkMessage"));
}
// ---------------------------------------------------------------------------
function messageClientWhisper(client, talkingClient, messageText) {
messageClient(getClientSubAccountName(client) + " whispers: " + String(messageText), client, getColourByType("whisperMessage"));
}
// ---------------------------------------------------------------------------
function messageClientShout(client, talkingClient, messageText) {
messageClient(getClientSubAccountName(client) + " shouts: " + String(messageText) + "!", client, getColourByType("shoutMessage"));
}
// ---------------------------------------------------------------------------
function messageClientDoAction(client, talkingClient, messageText) {
if(client instanceof Client) {
messageClient(String(messageText) + " * (" + getClientSubAccountName(client) + ")", client, getColourByType("doActionMessage"));
}
}
// ---------------------------------------------------------------------------
function messageClientMeAction(client, talkingClient, messageText) {
messageClient(getClientSubAccountName(client) + " " + String(messageText), client, getColourByType("meActionMessage"));
}
// ---------------------------------------------------------------------------

11
scripts/server/misc.js Normal file
View File

@@ -0,0 +1,11 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: misc.js
// DESC: Provides any uncategorized functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
// FUCK

View File

@@ -0,0 +1,204 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: moderation.js
// DESC: Provides moderation commands, functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initModerationScript() {
addModerationCommandHandlers();
}
// ---------------------------------------------------------------------------
function addModerationCommandHandlers() {
let moderationCommands = serverCommands.moderation;
for(let i in moderationCommands) {
addCommandHandler(moderationCommands[i].command, moderationCommands[i].handlerFunction);
}
}
// ---------------------------------------------------------------------------
function kickClientCommand(command, params, client, fromDiscord) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let targetClient = getClientFromParams(params);
if(!targetClient) {
messageClientError(client, "That player is not connected!");
return false;
}
// Prevent kicking admins with really high permissions
if(doesClientHaveStaffPermission(targetClient, "manageServer") || doesClientHaveStaffPermission(targetClient, "developer")) {
messageClientError(client, "You cannot kick this person!");
return false;
}
message("[#996600][ADMIN]: [#FFFFFF]" + String(targetClient.name) + " has been kicked from the server.");
targetClient.disconnect();
}
// ---------------------------------------------------------------------------
function muteClientCommand(command, params, client, fromDiscord) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let targetClient = getClientFromParams(params);
if(!targetClient) {
messageClientError(client, "That player is not connected!");
return false;
}
// Prevent muting admins with really high permissions
if(doesClientHaveStaffPermission(targetClient, "manageServer") || doesClientHaveStaffPermission(targetClient, "developer")) {
messageClientError(client, "You cannot mute this person!");
return false;
}
message("[#996600][ADMIN]: [#FFFFFF]" + String(targetClient.name) + " has been muted!");
targetClient.setData("ag.muted", true, false);
}
// ---------------------------------------------------------------------------
function unMuteClientCommand(command, params, client, fromDiscord) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let targetClient = getClientFromParams(params);
if(!targetClient) {
messageClientError(client, "That player is not connected!");
return false;
}
// Prevent unmuting admins with really high permissions
if(doesClientHaveStaffPermission(targetClient, "manageServer") || doesClientHaveStaffPermission(targetClient, "developer")) {
messageClientError(client, "You cannot unmute this person!");
return false;
}
message("[#996600][ADMIN]: [#FFFFFF]" + String(targetClient.name) + " has been unmuted!");
targetClient.removeData("ag.muted");
}
// ---------------------------------------------------------------------------
function freezeClientCommand(command, params, client, fromDiscord) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let targetClient = getClientFromParams(params);
if(!targetClient) {
messageClientError(client, "That player is not connected!");
return false;
}
// Prevent freeze admins with really high permissions
if(doesClientHaveStaffPermission(targetClient, "manageServer") || doesClientHaveStaffPermission(targetClient, "developer")) {
messageClientError(client, "You cannot freeze this person!");
return false;
}
message("[#996600][ADMIN]: [#FFFFFF]" + String(targetClient.name) + " has been frozen!");
triggerNetworkEvent("ag.frozen", client, true);
}
// ---------------------------------------------------------------------------
function unFreezeClientCommand(command, params, client, fromDiscord) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
let targetClient = getClientFromParams(params);
if(!targetClient) {
messageClientError(client, "That player is not connected!");
return false;
}
// Prevent unfreezing admins with really high permissions
if(doesClientHaveStaffPermission(targetClient, "manageServer") || doesClientHaveStaffPermission(targetClient, "developer")) {
messageClientError(client, "You cannot freeze this person!");
return false;
}
message("[#996600][ADMIN]: [#FFFFFF]" + String(targetClient.name) + " has been un-frozen!");
triggerNetworkEvent("ag.frozen", client, false);
}
// ---------------------------------------------------------------------------

94
scripts/server/npc.js Normal file
View File

@@ -0,0 +1,94 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: npc.js
// DESC: Provides NPC usage and functions
// TYPE: Server (JavaScript)
// ===========================================================================
const NPC = {
Trigger: {
farProximity,
mediumProximity,
nearProximity,
enterLineOfSight,
exitLineOfSight,
pedCollision,
vehicleCollision,
shootGun,
swingMelee,
stealOccupiedVehicle,
stealUnoccupiedVehicle,
hotwireVehicleStart,
hotwireVehicleFail,
hotwireVehicleSucceed,
vehicleAlarmStart,
varAlarmStop,
sirenStart,
sirenStop,
vehicleEnter,
vehicleExit,
interiorEnter,
interiorExit,
attackedByMelee,
attackedByGun
},
Condition: {
isInLineOfSight,
isFarProximity,
isMediumProximity,
isNearProximity,
isEnemyFaction,
isAllyFaction,
isSameFaction,
isSameClan,
isLawEnforcement,
isCriminal,
hasWantedLevel,
isSelfVehicle,
isOtherVehicle,
isEmergencyVehicle,
isPoliceVehicle,
isDriver,
isInFrontSeat,
isInSeatId,
vehicleLocked,
vehicleHotwired,
isPistol,
isShotgun,
isAutomatic,
isRifle,
isAssaultRifle,
isSniper,
isRPG,
isFlameThrower,
},
Response: {
shout,
talk,
whisper,
switchWeapon,
shootWeapon,
aimWeapon,
fleeSprint,
fleeWalk,
fleeRun,
attackMelee,
attackFist,
runToward,
crouch,
phoneCall,
walkieTalkieMessage,
switchRadioStation,
toggleSiren,
fleeTo,
driveTo,
enterVehicle,
}
};
function beginNPCInteraction() {
}

View File

View File

View File

View File

View File

View File

View File

View File

View File

@@ -0,0 +1,9 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: security.js
// DESC: Provides security functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================

74
scripts/server/startup.js Normal file
View File

@@ -0,0 +1,74 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: startup.js
// DESC: Provides startup/shutdown procedures
// TYPE: Server (JavaScript)
// ===========================================================================
function initServerScripts() {
checkForAllRequiredModules();
initClassScript();
initDatabaseScript();
initCommandScript();
initBusinessScript();
initClanScript();
initHouseScript();
initChatScript();
initModerationScript();
initAccountScript();
initChatScript();
initJobScript();
}
// ---------------------------------------------------------------------------
function checkForHashingModule() {
if(module.hashing == "undefined") {
return false;
}
return true;
}
// ---------------------------------------------------------------------------
function checkForMySQLModule() {
if(module.mysql == "undefined") {
return false;
}
return true;
}
// ---------------------------------------------------------------------------
function checkForAllRequiredModules() {
console.log("[AsshatRP.Startup]: Checking for required modules ...");
if(!checkForHashingModule()) {
console.warn("[AsshatRP.Startup]: Hashing module is not loaded!");
console.warn("[AsshatRP.Startup]: This resource will now shutdown.");
thisResource.stop();
}
if(!checkForMySQLModule()) {
console.warn("[AsshatRP.Startup]: MySQL module is not loaded!");
console.warn("[AsshatRP.Startup]: This resource will now shutdown.");
thisResource.stop();
}
console.log("[AsshatRP.Startup]: All required modules loaded!");
return true;
}
// ---------------------------------------------------------------------------
initServerScripts();
// ----------------------------------------------------------------------------

View File

@@ -0,0 +1,83 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: translate.js
// DESC: Provides translation functions
// TYPE: Server (JavaScript)
// ===========================================================================
// ---------------------------------------------------------------------------
function translateMessage(messageText, fromLanguageId, toLanguageId) {
let translatedText = "";
let thisTranslationURL = formatTranslationURL(messageText, fromLanguageId, toLanguageId);
httpGet(
thisTranslationURL,
"",
function(data) {
data = String(data).substr(0, String(data).lastIndexOf("}")+1);
let translationData = JSON.parse(data);
//this.translatedText = translationData.responseData.translatedText;
addTranslationToCache(messageText, translationData.responseData.translatedText, fromLanguageId, toLanguageId);
return translationData.responseData.translatedText;
},
function(data) {
}
);
return this.translatedText;
}
// ---------------------------------------------------------------------------
function addTranslationToCache(originalText, translatedText, fromLanguageId, toLanguageId) {
serverData.translation.cache[fromLanguageId][toLanguageId].push([originalText, translatedText]);
return true;
}
// ---------------------------------------------------------------------------
function formatTranslationURL(originalText, fromLanguageId, toLanguageId) {
return serverData.translation.translationBaseURL.format(encodeURI(originalText), getLanguageShortCode(fromLanguageId), getLanguageShortCode(toLanguageId));
}
// ---------------------------------------------------------------------------
function getLanguageShortCode(languageId) {
return serverData.translation.languages[languageId][1];
}
// ---------------------------------------------------------------------------
function getLanguageFullName(languageId) {
return serverData.translation.languages[languageId][0];
}
// ---------------------------------------------------------------------------
function getLanguageIdFromFullName(languageName) {
let languages = serverData.translation.languages;
for(let i in languages) {
if(languages[i][0] == languageName) {
return i;
}
}
return false;
}
// ---------------------------------------------------------------------------
function getLanguageIdFromShortCode(languageShortCode) {
let languages = serverData.translation.languages;
for(let i in languages) {
if(languages[i][1] == languageShortCode) {
return i;
}
}
return false;
}
// ---------------------------------------------------------------------------

3216
scripts/server/utilities.js Normal file

File diff suppressed because it is too large Load Diff

129
scripts/server/vehicle.js Normal file
View File

@@ -0,0 +1,129 @@
// ===========================================================================
// Asshat Gaming RP
// http://asshatgaming.com
// © 2020 Asshat Gaming
// ---------------------------------------------------------------------------
// FILE: vehicle.js
// DESC: Provides vehicle functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
function initVehicleScript() {
console.log("[Asshat.Clan]: Initializing vehicle script ...");
serverData.vehicles = loadVehiclesFromDatabase();
spawnAllVehicles();
addVehicleCommandHandlers();
console.log("[Asshat.Clan]: Vehicle script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addVehicleCommandHandlers() {
console.log("[Asshat.Clan]: Adding vehicle command handlers ...");
let vehicleCommands = vehicleCommands.clan;
for(let i in vehicleCommands) {
addCommandHandler(vehicleCommands[i].command, vehicleCommands[i].handlerFunction);
}
console.log("[Asshat.Clan]: Vehicle command handlers added successfully!");
return true;
}
function loadVehiclesFromDatabase() {
let dbConnection = connectToDatabase();
if(dbConnection) {
accountName = dbConnection.escapeString(accountName);
let dbQueryString = format("SELECT * FROM `veh_main` WHERE `veh_game` = %d", serverGame);
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
while(dbAssoc = dbQuery.fetchAssoc()) {
let vehicleData = new vehicleData(dbAssoc);
serverData.vehicles.push(vehicleData);
}
}
disconnectFromDatabase(dbConnection);
}
return false;
}
// ---------------------------------------------------------------------------
function saveVehiclesToDatabase() {
let vehicles = serverData.vehicles;
for(let i in vehicles) {
saveVehicleToDatabase(vehicles[i]);
}
return true;
}
// ---------------------------------------------------------------------------
function saveVehicleToDatabase(vehicleData) {
let dbConnection = connectToDatabase();
if(dbConnection) {
// If vehicle hasn't been added to database, ID will be 0
if(vehicleData.databaseId == 0) {
//let dbQueryColourFields = "`veh_col1_id`, `veh_col2_id`, `veh_col3_id1, `veh_col4_id`";
//if(vehicleData.colourType == AH_VEH_COLOURTYPE_RGBA) {
// dbQueryColourFields = "`veh_col1_rgba`, `veh_col2_rgba`, `veh_col3_rgba`, `veh_col4_rgba`";
// dbQueryColourValues = vehicleData.colour1Red, `veh_col1_g`, `veh_col1_b`, `veh_col1_a`, `veh_col2_r`, `veh_col2_g`, `veh_col2_b`, `veh_col2_a`, `veh_col3_r`, `veh_col3_g`, `veh_col3_b`, `veh_col3_a`, `veh_col4_r`, `veh_col4_g`, `veh_col4_b`, `veh_col4_a`,";
//}
let dbQueryString = "INSERT INTO `veh_main` (`veh_model`, `veh_pos_x`, `veh_pos_y`, `veh_pos_z`, veh_owner_type`, `veh_owner_id`) VALUES (" + vehicleData.modelId + ", " + vehicleData.spawnPosition.x + ", " + vehicleData.spawnPosition.y + ", " + vehicleData.spawnPosition.z + ", " + vehicleData.spawnRotation.z + ", " + vehicleData.ownerType + ", " + vehicleData.ownerId + ");";
let dbQuery = dbConnection.query(dbQueryString);
getVehicleData(vehicleData.vehicle).databaseId = dbConnection.insertId;
} else {
let dbQueryString = "UPDATE `veh_main` SET `veh_model` = " + vehicleData.modelId + ", `veh_pos_x` = " + vehicleData.spawnPosition.x + ", `veh_pos_y` = " + vehicleData.spawnPosition.y + ", " + vehicleData.spawnPosition.z + ", `veh_pos_z` = " + vehicleData.spawnRotation.z + ", `veh_owner_type`" + vehicleData.ownerType + ", `veh_owner_id` = " + vehicleData.ownerId;
let dbQuery = dbConnection.query(dbQueryString);
}
disconnectFromDatabase(dbConnection);
return true;
}
return false;
}
// ---------------------------------------------------------------------------
function spawnAllVehicles() {
for(let i in serverData.vehicles) {
let vehicle = gta.createVehicle(serverData.vehicles[i].modelId, serverData.vehicles[i].spawnPosition, serverData.vehicles[i].spawnHeading);
vehicle.locked = serverData.vehicles[i].locked;
if(serverData.vehicles[i].colour1IsRGBA && serverData.vehicles[i].colour2IsRGBA) {
vehicle.setRGBColours(serverData.vehicles[i].colour1RGBA, serverData.vehicles[i].colour2RGBA);
} else {
vehicle.colour1 = serverData.vehicles[i].colour1;
vehicle.colour2 = serverData.vehicles[i].colour2;
vehicle.colour3 = serverData.vehicles[i].colour3;
vehicle.colour4 = serverData.vehicles[i].colour4;
}
vehicle.engine = serverData.vehicles[i].engine;
vehicle.lights = serverData.vehicles[i].engine;
//vehicle.health = serverData.vehicles[i].health;
addToWorld(vehicle);
serverData.vehicles[i].vehicle = vehicle;
vehicle.setData("ag.dataSlot", i, false);
}
}
// ---------------------------------------------------------------------------
function getVehicleData(vehicle) {
let dataIndex = vehicle.getData("ag.dataSlot");
return serverData.vehicles[dataIndex];
}
// ---------------------------------------------------------------------------
function saveAllVehiclesToDatabase() {
}
// ---------------------------------------------------------------------------