Add vehicles, util funcs. Fix jobs

This commit is contained in:
VortrexFTW
2020-09-05 02:30:39 -05:00
parent c536fcd6ef
commit 29e273bf60
9 changed files with 155 additions and 81 deletions

View File

@@ -290,7 +290,7 @@ app.init = function()
textFont: robotoFont,
textAlign: 0.5,
},
}, checkLogin);
}, checkLogin);
login.notRegisteredLabel = login.window.text(20, 240, 175, 20, "Don't have an account?", {
main: {
@@ -541,7 +541,7 @@ app.init = function()
textFont: robotoFont,
}
});
//register.passwordInput.masked = true;
register.passwordInput.masked = true;
register.passwordInput.placeholder = "Password";
register.confirmPasswordInput = register.window.textInput(20, 130, 260, 25, '', {
@@ -561,7 +561,7 @@ app.init = function()
textFont: robotoFont,
}
});
//register.confirmPasswordInput.masked = true;
register.confirmPasswordInput.masked = true;
register.confirmPasswordInput.placeholder = "Confirm password";
register.emailInput = register.window.textInput(20, 160, 260, 25, '', {

View File

@@ -57,7 +57,7 @@ function loginCommand(command, params, client) {
return false;
}
if(isAccountPasswordCorrect(serverData.clients[client.index].accountData, hashAccountPassword(client.name, params))) {
if(isAccountPasswordCorrect(getClientData(client).accountData, hashAccountPassword(client.name, params))) {
messageClientError(client, "Incorrect username or password!");
return false;
}
@@ -110,7 +110,7 @@ function registerCommand(command, params, client) {
return false;
}
serverData.clients[client.index].accountData = accountData;
getClientData(client).accountData = accountData;
messageClientSuccess(client, "Your account has been created!");
messageClientAlert(client, "To play on the server, you will need to make a character.");
}
@@ -146,7 +146,7 @@ function changePasswordCommand(command, params, client) {
let oldPassword = splitParams[0];
let newPassword = splitParams[1];
if(isAccountPasswordCorrect(serverData.clients[client.index].accountData, hashAccountPassword(client.name, oldPassword))) {
if(isAccountPasswordCorrect(getClientData(client).accountData, hashAccountPassword(client.name, oldPassword))) {
messageClientError(client, "The old password is invalid!");
return false;
}
@@ -157,7 +157,7 @@ function changePasswordCommand(command, params, client) {
return false;
}
serverData.clients[client.index].accountData.password = hashAccountPassword(serverData.clients[client.index].accountData.name, params);
getClientData(client).accountData.password = hashAccountPassword(getClientData(client).accountData.name, params);
messageClientSuccess(client, "Your password has been changed!");
}
@@ -183,31 +183,29 @@ function switchCharacterCommand(command, params, client) {
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;
getClientCurrentSubAccount(client).spawnPosition = client.player.position;
getClientCurrentSubAccount(client).spawnHeading = client.player.heading;
let tempSubAccount = serverData.clients[client.index].subAccounts[subAccountId];
let tempSubAccount = getClientCurrentSubAccount(client);
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;
let loggedIn = getClientData(client).loggedIn;
return loggedIn;
}
// ---------------------------------------------------------------------------
function isClientRegistered(client) {
if(serverData.clients[client.index].accountData != false) {
if(serverData.clients[client.index].accountData.databaseId != 0) {
if(getClientData(client).accountData != false) {
if(getClientData(client).accountData.databaseId != 0) {
return true;
}
}
@@ -396,14 +394,13 @@ function hashAccountPassword(name, password) {
// ---------------------------------------------------------------------------
function saltAccountInfo(name, password) {
// Will be added later
return name + "." + password;
return "asshat.gaming." + String(accountSaltHash) + "." + String(name) + "." + String(password);
}
// ---------------------------------------------------------------------------
function loginSuccess(client) {
serverData.clients[client.index].loggedIn = true;
getClientData(client).loggedIn = true;
triggerNetworkEvent("ag.loginSuccess", client);
}
@@ -501,7 +498,7 @@ addNetworkHandler("ag.checkLogin", function(client, password) {
return false;
}
if(!isAccountPasswordCorrect(serverData.clients[client.index].accountData, hashAccountPassword(client.name, password))) {
if(!isAccountPasswordCorrect(getClientData(client).accountData, hashAccountPassword(client.name, password))) {
//messageClientError(client, "Invalid password!");
triggerNetworkEvent("ag.loginFailed", client, "Invalid password! " + String(loginAttemptsRemaining) + " tries remaining.");
return false;
@@ -509,12 +506,12 @@ addNetworkHandler("ag.checkLogin", function(client, password) {
loginSuccess(client);
if(serverData.clients[client.index].subAccounts.length == 0) {
if(getClientData(client).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];
getClientData(client).currentSubAccount = 0;
let tempSubAccount = getClientData(client).subAccounts[0];
triggerNetworkEvent("ag.showCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin);
}
});
@@ -575,11 +572,14 @@ addNetworkHandler("ag.checkRegistration", function(client, password, confirmPass
return false;
}
serverData.clients[client.index].accountData = accountData;
getClientData(client).accountData = accountData;
getClientData(client).loggedIn = true;
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);
});
@@ -611,33 +611,33 @@ addNetworkHandler("ag.checkNewCharacter", function(client, firstName, lastName,
return false;
}
let subAccountData = createSubAccount(serverData.clients[client.index].accountData.databaseId, firstName, lastName, skinId, dateOfBirth, placeOfOrigin);
let subAccountData = createSubAccount(getClientData(client).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);
getClientData(client).subAccounts = loadSubAccountsFromAccount(getClientData(client).accountData.databaseId);
triggerNetworkEvent("ag.newCharacterSuccess", client);
serverData.clients[client.index].currentSubAccount = 0;
let tempSubAccount = serverData.clients[client.index].subAccounts[0];
getClientData(client).currentSubAccount = 0;
let tempSubAccount = getClientData(client).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;
if(getClientData(client).subAccounts.length > 1) {
if(getClientData(client).currentSubAccount <= 0) {
getClientData(client).currentSubAccount = getClientData(client).subAccounts.length-1;
} else {
serverData.clients[client.index].currentSubAccount--;
getClientData(client).currentSubAccount--;
}
let subAccountId = serverData.clients[client.index].currentSubAccount;
let tempSubAccount = serverData.clients[client.index].subAccounts[subAccountId];
let subAccountId = getClientData(client).currentSubAccount;
let tempSubAccount = getClientData(client).subAccounts[subAccountId];
triggerNetworkEvent("ag.switchCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin);
}
});
@@ -645,15 +645,15 @@ addNetworkHandler("ag.previousCharacter", function(client) {
// ---------------------------------------------------------------------------
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;
if(getClientData(client).subAccounts.length > 1) {
if(getClientData(client).currentSubAccount >= getClientData(client).subAccounts.length-1) {
getClientData(client).currentSubAccount = 0;
} else {
serverData.clients[client.index].currentSubAccount++;
getClientData(client).currentSubAccount++;
}
let subAccountId = serverData.clients[client.index].currentSubAccount;
let tempSubAccount = serverData.clients[client.index].subAccounts[subAccountId];
let subAccountId = getClientData(client).currentSubAccount;
let tempSubAccount = getClientData(client).subAccounts[subAccountId];
triggerNetworkEvent("ag.switchCharacterSelect", client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.placeOfOrigin, tempSubAccount.dateOfBirth, tempSubAccount.skin);
}
});
@@ -663,8 +663,8 @@ addNetworkHandler("ag.nextCharacter", function(client) {
addNetworkHandler("ag.selectCharacter", function(client) {
triggerNetworkEvent("ag.characterSelectSuccess", client);
let subAccountId = serverData.clients[client.index].currentSubAccount;
let tempSubAccount = serverData.clients[client.index].subAccounts[subAccountId];
let subAccountId = getClientData(client).currentSubAccount;
let tempSubAccount = getClientData(client).subAccounts[subAccountId];
spawnPlayer(client, tempSubAccount.spawnPosition, tempSubAccount.spawnHeading, tempSubAccount.skin);
});
@@ -719,4 +719,12 @@ function initClient(client) {
triggerNetworkEvent("ag.showRegistration", client);
//messageClient("Welcome to Asshat Gaming RP, " + String(client.name) + "! Please /register to continue.", client, serverConfig.colour.byName["white"]);
}
}
}
// ---------------------------------------------------------------------------
function getClientData(client) {
return serverData.clients[client.index];
}
// ---------------------------------------------------------------------------

View File

@@ -74,6 +74,7 @@ function initClassTable() {
this.isWorking = false;
this.jobUniform = this.skin;
this.lastJobVehicle = null;
this.job = -1;
this.weapons = [];
}
@@ -127,8 +128,8 @@ function initClassTable() {
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"]);
this.spawnPosition = new Vec3(vehicleAssoc["veh_pos_x"], vehicleAssoc["veh_pos_y"], vehicleAssoc["veh_pos_z"]);
this.spawnRotation = Number(vehicleAssoc["veh_rot_z"]);
// Colour Info
this.colour1IsRGBA = vehicleAssoc["veh_col1_isrgba"];

View File

@@ -85,6 +85,7 @@ function loadCommandData() {
commandData("startwork", startWorkingCommand, "", getStaffFlagValue("none"), true, false),
commandData("stopwork", stopWorkingCommand, "", getStaffFlagValue("none"), true, false),
commandData("quitjob", quitJobCommand, "", getStaffFlagValue("none"), true, false),
commandData("uniform", jobUniformCommand, "", getStaffFlagValue("none"), true, false),
commandData("radio", jobRadioCommand, "", getStaffFlagValue("none"), true, false),
commandData("r", jobRadioCommand, "", getStaffFlagValue("none"), true, false),

View File

@@ -173,8 +173,8 @@ function takeJobCommand(command, params, client) {
return false;
}
if(getClientCurrentSubAccount(client).job != AG_JOB_NONE) {
getClientCurrentSubAccount(client).job = closestJob.jobType;
if(getClientCurrentSubAccount(client).job == -1) {
getClientCurrentSubAccount(client).job = getJobIndex(closestJob);
}
messageClientSuccess(client, "You now have the " + String(closestJob.name) + " job");
@@ -214,7 +214,7 @@ function startWorkingCommand(command, params, client) {
return false;
}
if(getClientCurrentSubAccount(client).job != closestJob.jobType) {
if(getClientCurrentSubAccount(client).job != getJobIndex(closestJob)) {
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;
@@ -339,7 +339,6 @@ function stopWorking(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;

View File

@@ -7,3 +7,5 @@
// DESC: Provides security functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
let accountSaltHash = "FGjD49yWqMrW"

View File

@@ -24,6 +24,7 @@ function initServerScripts() {
initAccountScript();
initChatScript();
initJobScript();
initVehicleScript();
}
// ---------------------------------------------------------------------------

View File

@@ -2451,6 +2451,12 @@ function getClosestJobPoint(position) {
// ---------------------------------------------------------------------------
function getJobIndex(jobData) {
return serverData.jobs[server.game].indexOf(jobData);
}
// ---------------------------------------------------------------------------
function getVehiclesInRange(position, distance) {
return getElementsByType(ELEMENT_VEHICLE).filter(x => x.position.distance(position) <= distance);
}
@@ -3213,4 +3219,18 @@ function saveAllServerDataToDatabase() {
saveAllHousesToDatabase();
saveAllBusinessesToDatabase();
saveAllClansToDatabase();
}
}
// ---------------------------------------------------------------------------
function intToBool(intVal) {
return !!intVal;
}
// ---------------------------------------------------------------------------
function boolToInt(boolVal) {
return (boolVal) ? 1 : 0;
}
// ---------------------------------------------------------------------------

View File

@@ -10,48 +10,53 @@
function initVehicleScript() {
console.log("[Asshat.Clan]: Initializing vehicle script ...");
dd console.log("[Asshat.Vehicle]: Initializing vehicle script ...");
serverData.vehicles = loadVehiclesFromDatabase();
spawnAllVehicles();
addVehicleCommandHandlers();
console.log("[Asshat.Clan]: Vehicle script initialized successfully!");
console.log("[Asshat.Vehicle]: Vehicle script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addVehicleCommandHandlers() {
console.log("[Asshat.Clan]: Adding vehicle command handlers ...");
let vehicleCommands = vehicleCommands.clan;
console.log("[Asshat.Vehicle]: Adding vehicle command handlers ...");
let vehicleCommands = serverCommands.vehicle;
for(let i in vehicleCommands) {
addCommandHandler(vehicleCommands[i].command, vehicleCommands[i].handlerFunction);
}
console.log("[Asshat.Clan]: Vehicle command handlers added successfully!");
console.log("[Asshat.Vehicle]: 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() {
function loadVehiclesFromDatabase() {
console.log("[Asshat.Vehicle]: Loading vehicles from database ...");
let dbConnection = connectToDatabase();
let tempVehicles = [];
let dbAssoc;
if(dbConnection) {
let dbQueryString = `SELECT * FROM veh_main WHERE veh_server = ${serverId}`;
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
while(dbAssoc = dbQuery.fetchAssoc()) {
let tempVehicleData = new serverClasses.vehicleData(dbAssoc);
tempVehicles.push(tempVehicleData);
}
dbQuery.free();
}
disconnectFromDatabase(dbConnection);
}
console.log("[Asshat.Vehicle]: " + tempVehicles.length + " vehicles loaded from database successfully!");
return tempVehicles;
}
// ---------------------------------------------------------------------------
function saveAllVehiclesToDatabase() {
let vehicles = serverData.vehicles;
for(let i in vehicles) {
saveVehicleToDatabase(vehicles[i]);
@@ -72,7 +77,7 @@ function saveVehicleToDatabase(vehicleData) {
// 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 dbQueryString = "INSERT INTO `veh_main` (`veh_model`, `veh_pos_x`, `veh_pos_y`, `veh_pos_z`, veh_owner_type`, `veh_owner_id`) VALUES (" + vehicleData.model + ", " + 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 {
@@ -90,8 +95,9 @@ function saveVehicleToDatabase(vehicleData) {
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;
console.log(serverData.vehicles[i].spawnRotation);
let vehicle = gta.createVehicle(serverData.vehicles[i].model, serverData.vehicles[i].spawnPosition, serverData.vehicles[i].spawnRotation);
addToWorld(vehicle);
if(serverData.vehicles[i].colour1IsRGBA && serverData.vehicles[i].colour2IsRGBA) {
vehicle.setRGBColours(serverData.vehicles[i].colour1RGBA, serverData.vehicles[i].colour2RGBA);
@@ -102,11 +108,14 @@ function spawnAllVehicles() {
vehicle.colour4 = serverData.vehicles[i].colour4;
}
vehicle.engine = serverData.vehicles[i].engine;
vehicle.lights = serverData.vehicles[i].engine;
vehicle.engine = intToBool(serverData.vehicles[i].engine);
//vehicle.lights = intToBool(serverData.vehicles[i].lights);
//vehicle.health = serverData.vehicles[i].health;
//vehicle.position = serverData.vehicles[i].spawnPosition;
vehicle.heading = serverData.vehicles[i].spawnRotation;
addToWorld(vehicle);
vehicle.locked = intToBool(serverData.vehicles[i].locked);
serverData.vehicles[i].vehicle = vehicle;
vehicle.setData("ag.dataSlot", i, false);
@@ -122,8 +131,41 @@ function getVehicleData(vehicle) {
// ---------------------------------------------------------------------------
function saveAllVehiclesToDatabase() {
function vehicleLockCommand(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;
}
let closestVehicle = getClosestVehicle();
if((!client.player.vehicle && doesClientHaveVehicleKeys(client, closestVehicle) && closestVehicle.position.distance(client.player.position) <= 5) || client.player.vehicle) {
if(getVehicleData(closestVehicle).locked) {
closestVehicle.locked = false;
getVehicleData(closestVehicles).locked = false;
} else {
closestVehicle.locked = true;
getVehicleData(closestVehicles).locked = true;
}
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ---------------------------------------------------------------------------