Merge branch 'master' of github.com:Re-Ignited-Development/new-phone-who-dis into bug/mysql-connection-strings

This commit is contained in:
erik-sn committed 2020-10-17 18:33:57 -04:00
commit 11f0302fea
4 files changed
+88 -135

No files matched your search

+66 -109
View File
@@ -90,36 +90,21 @@ async function loadAnimDict(dict: any) {
}
}
async function phoneOpenAnim() {
//Phone Open Animation
const flag = 50; //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
deletePhone(); //Deleting before creating a new phone where itll be deleted again.
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) {
//-- true refers to at get in.
const dict = "anim@cellphone@in_car@ps";
const kek = "pepein";
async function phoneOpenAnim() { //Phone Open Animation
console.log("phoneOpenAnim") //Left for testing purposes.
const flag = 50 //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
deletePhone() //Deleting before creating a new phone where itll be deleted again.
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { //-- true refers to at get in.
const dict = 'anim@cellphone@in_car@ps'
ClearPedTasks(GetPlayerPed(-1));
await loadAnimDict(dict);
TaskPlayAnim(
GetPlayerPed(-1),
dict,
"cellphone_text_in",
8.0,
-1,
-1,
flag,
0,
false,
false,
false
);
await Delay(300); //Gives time for animation starts before creating the phone
await newPhoneProp(); //Creates the phone and attaches it.
} else {
//While not in a vehicle it will use this dict.
const dict = "cellphone@";
const kek = "pepeout";
ClearPedTasks(GetPlayerPed(-1))
await loadAnimDict(dict)
TaskPlayAnim(GetPlayerPed(-1), dict, 'cellphone_text_in', 8.0, -1, -1, flag, 0, false, false, false)
await Delay(300) //Gives time for animation starts before creating the phone
await newPhoneProp() //Creates the phone and attaches it.
}
else { //While not in a vehicle it will use this dict.
const dict = 'cellphone@'
ClearPedTasks(GetPlayerPed(-1));
await loadAnimDict(dict);
@@ -141,58 +126,31 @@ async function phoneOpenAnim() {
}
}
async function phoneCloseAnim() {
//Phone Close Animation
const flag = 50; //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
const anim = "cellphone_text_out";
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) {
//true refers to at get in.
const dict = "anim@cellphone@in_car@ps";
const kek = "pepein";
async function phoneCloseAnim() { //Phone Close Animation
console.log("phoneCloseAnim") //Left for testing purposes.
const flag = 50 //https://runtime.fivem.net/doc/natives/?_0xEA47FE3719165B94
const anim = 'cellphone_text_out'
if (IsPedInAnyVehicle(GetPlayerPed(-1), true)) { //true refers to at get in.
const dict = 'anim@cellphone@in_car@ps'
StopAnimTask(GetPlayerPed(-1), dict, "cellphone_text_in", 1.0); //Stop the pull out animation
deletePhone(); //Deletes the prop early incase they get out of the vehicle.
await Delay(250); //lets it get to a certain point
loadAnimDict(dict); //loads the new animation
TaskPlayAnim(
GetPlayerPed(-1),
dict,
anim,
8.0,
-1,
-1,
flag,
1,
false,
false,
false
); //puts phone into pocket
await Delay(200); //waits until the phone is in the pocket
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0); //clears the animation
} else {
//While not in a vehicle it will use this dict.
const dict = "cellphone@";
const kek = "pepeout";
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0) //Stop the pull out animation
deletePhone() //Deletes the prop early incase they get out of the vehicle.
await Delay(250) //lets it get to a certain point
loadAnimDict(dict) //loads the new animation
TaskPlayAnim(GetPlayerPed(-1), dict, anim, 8.0, -1, -1, flag, 0, false, false, false) //puts phone into pocket
await Delay(200) //waits until the phone is in the pocket
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) //clears the animation
}
else { //While not in a vehicle it will use this dict.
const dict = 'cellphone@'
StopAnimTask(GetPlayerPed(-1), dict, "cellphone_text_in", 1.0); //Stop the pull out animation
await Delay(100); //lets it get to a certain point
loadAnimDict(dict); //loads the new animation
TaskPlayAnim(
GetPlayerPed(-1),
dict,
anim,
8.0,
-1,
-1,
flag,
1,
false,
false,
false
); //puts phone into pocket
await Delay(200); //waits until the phone is in the pocket
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0); //clears the animation
deletePhone(); //Deletes the prop.
StopAnimTask(GetPlayerPed(-1), dict, 'cellphone_text_in', 1.0) //Stop the pull out animation
await Delay(100) //lets it get to a certain point
loadAnimDict(dict) //loads the new animation
TaskPlayAnim(GetPlayerPed(-1), dict, anim, 8.0, -1, -1, flag, 0, false, false, false) //puts phone into pocket
await Delay(200) //waits until the phone is in the pocket
StopAnimTask(GetPlayerPed(-1), dict, anim, 1.0) //clears the animation
deletePhone() //Deletes the prop.
}
}
@@ -230,12 +188,12 @@ setTick(() => {
async function Phone() {
if (config.PhoneAsItem) {
console.log("CONFIG ON")
carryingPhone(async (carryingPhone: any) => {
if (carryingPhone) {
if (!isPhoneOpen) {
isPhoneOpen = true;
await phoneOpenAnim();
console.log("phone is now open"); //Left for testing purposes.
isPhoneOpen = true
await phoneOpenAnim()
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet("phone:getCredentials"); // Gets the credentials. Will eventually most likely only get the phone number and name, idk.
SetCursorLocation(0.936, 0.922); //Experimental
@@ -246,32 +204,32 @@ async function Phone() {
method: "setVisibility",
data: true,
})
);
sendPhoneConfig();
SetNuiFocus(true, true);
} else {
isPhoneOpen = false;
console.log("phone is now closed"); //Left for testing purposes.
SendNuiMessage(
//Hides phone
)
sendPhoneConfig()
SetNuiFocus(true, true)
}
else {
isPhoneOpen = false
await phoneCloseAnim()
SendNuiMessage( //Hides phone
JSON.stringify({
app: "PHONE",
method: "setVisibility",
data: false,
})
);
SetNuiFocus(false, false);
phoneCloseAnim();
)
SetNuiFocus(false, false)
}
} else {
noPhone();
}
});
} else if (!config.PhoneAsItem) {
})
}
else if (!config.PhoneAsItem) {
console.log("CONFIG OFF")
if (!isPhoneOpen) {
isPhoneOpen = true;
await phoneOpenAnim();
console.log("phone is now open"); //Left for testing purposes.
isPhoneOpen = true
await phoneOpenAnim()
emitNet(events.CONTACTS_GET_CONTACTS);
emitNet("phone:getCredentials");
SetCursorLocation(0.936, 0.922); //Experimental
@@ -282,22 +240,21 @@ async function Phone() {
method: "setVisibility",
data: true,
})
);
sendPhoneConfig();
SetNuiFocus(true, true);
} else {
isPhoneOpen = false;
console.log("phone is now closed"); //Left for testing purposes.
SendNuiMessage(
//Hides phone
)
sendPhoneConfig()
SetNuiFocus(true, true)
}
else {
isPhoneOpen = false
await phoneCloseAnim()
SendNuiMessage( //Hides phone
JSON.stringify({
app: "PHONE",
method: "setVisibility",
data: false,
})
);
SetNuiFocus(false, false);
await phoneCloseAnim();
)
SetNuiFocus(false, false)
}
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ import {
getServerHost,
getUserId,
getPassword,
} from './db_utils';
} from "./db_utils";
// we require set mysql_connection_string to be set in the config
const mysqlConnectionString = GetConvar(CONNECTION_STRING, null);
+10 -12
View File
@@ -1,22 +1,21 @@
import * as db from "./db_utils";
const t = 'test value';
const t = "test value";
describe("parseSemiColonFormat", () => {
it("Raises a error with invalid string", () => {
expect(() => db.parseSemiColonFormat("no_variables_here")).toThrowError();
});
it("Correctly parses configuration options", () => {
const test = 'server=127.0.0.1;database=es_extended;userid=user;password=pass';
const test =
"server=127.0.0.1;database=es_extended;userid=user;password=pass";
const result = db.parseSemiColonFormat(test);
expect(result.server).toEqual('127.0.0.1');
expect(result.database).toEqual('es_extended');
expect(result.userid).toEqual('user');
expect(result.password).toEqual('pass');
expect(result.server).toEqual("127.0.0.1");
expect(result.database).toEqual("es_extended");
expect(result.userid).toEqual("user");
expect(result.password).toEqual("pass");
});
});
@@ -34,7 +33,7 @@ describe("getServerHost", () => {
});
it("Correctly returns data source", () => {
expect(db.getServerHost({ 'data source': t })).toEqual(t);
expect(db.getServerHost({ "data source": t })).toEqual(t);
});
it("Correctly returns datasource", () => {
@@ -60,7 +59,7 @@ describe("getUserId", () => {
});
it("Correctly returns user id", () => {
expect(db.getUserId({ 'user id': t })).toEqual(t);
expect(db.getUserId({ "user id": t })).toEqual(t);
});
it("Correctly returns userid", () => {
@@ -68,7 +67,7 @@ describe("getUserId", () => {
});
it("Correctly returns user name", () => {
expect(db.getUserId({ 'user name': t })).toEqual(t);
expect(db.getUserId({ "user name": t })).toEqual(t);
});
it("Correctly returns username", () => {
@@ -80,7 +79,6 @@ describe("getUserId", () => {
});
});
describe("getPassword", () => {
it("returns default", () => {
expect(() => db.getPassword({})).toThrowError();
+11 -13
View File
@@ -3,11 +3,9 @@ export const DEFAULT_PORT = 3306;
export const DEFAULT_HOST = "localhost";
export const DEFAULT_USER = "root";
interface Map {
[key: string]: string;
}
}
/**
* parse the connection string from the format server=127.0.0.1;database=es_extended;userid=user;password=pass
@@ -26,13 +24,13 @@ export function parseSemiColonFormat(connectionString: string): Map {
connectionInfo[key] = value;
return connectionInfo;
}, {});
}
}
/**
/**
* allowed variable names: host | server | data source | datasource | addr | address
* @param config - database config variables parsed from mysql_connection_string
*/
export function getServerHost(config: Map): string {
export function getServerHost(config: Map): string {
return (
config.host ||
config.server ||
@@ -42,13 +40,13 @@ export function parseSemiColonFormat(connectionString: string): Map {
config.address ||
DEFAULT_HOST
);
}
}
/**
/**
* allowed variable names: user | user id | userid | user name | username | uid
* @param config - database config variables parsed from mysql_connection_string
*/
export function getUserId(config: Map): string {
export function getUserId(config: Map): string {
return (
config.user ||
config["user id"] ||
@@ -58,16 +56,16 @@ export function parseSemiColonFormat(connectionString: string): Map {
config.uid ||
DEFAULT_USER
);
}
}
/**
/**
* allowed variable names: password | pwd
* @param config - database config variables parsed from mysql_connection_string
*/
export function getPassword(config: Map): string {
export function getPassword(config: Map): string {
const password = config.password || config.pwd;
if (!password) {
throw new Error("Password is a required field");
}
return password;
}
}