From 9f21efed2deed478b99cec1507d6d1cdeb8c319d Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Fri, 31 May 2019 23:09:40 +0200 Subject: [PATCH] Minor cleanup and added missing sql index --- client/main.lua | 47 +++++---------- esx_phone.sql | 17 +++--- html/ui.html | 13 ++-- html/ui_br.html | 13 ++-- html/ui_de.html | 13 ++-- html/ui_en.html | 13 ++-- html/ui_pl.html | 153 +++++++++++++++++++++++++----------------------- server/main.lua | 94 ++++++++++++++--------------- 8 files changed, 180 insertions(+), 183 deletions(-) diff --git a/client/main.lua b/client/main.lua index 0249ab82..dd69b91f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,40 +1,21 @@ -local Keys = { - ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, - ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, - ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18, - ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182, - ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81, - ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, - ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178, - ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173, - ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118 -} - -local GUI = {} -local PhoneData = { phoneNumber = 0, contacts = {} } -local CurrentAction = nil -local CurrentActionMsg = '' -local CurrentActionData = {} -local CurrentDispatchRequestId = -1 -local PhoneNumberSources = {} - -ESX = nil -GUI.PhoneIsShowed = false -GUI.MessagesIsShowed = false -GUI.AddContactIsShowed = false +local GUI, PhoneData, CurrentActionData, PhoneNumberSources, CurrentDispatchRequestId = {}, {phoneNumber = 0, contacts = {}}, {}, {}, -1 +local CurrentAction, CurrentActionMsg +GUI.PhoneIsShowed = false +GUI.MessagesIsShowed = false +GUI.AddContactIsShowed = false +ESX = nil Citizen.CreateThread(function() while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Citizen.Wait(0) end - + ESX.UI.Menu.RegisterType('phone', OpenPhone, ClosePhone) end) function OpenPhone() local playerPed = PlayerPedId() - TriggerServerEvent('esx_phone:reload', PhoneData.phoneNumber) SendNUIMessage({ @@ -188,7 +169,7 @@ AddEventHandler('esx_phone:onMessage', function(phoneNumber, message, position, anonyme = anon, job = job } - + ESX.SetTimeout(15000, function() CurrentAction = nil end) @@ -222,7 +203,7 @@ RegisterNUICallback('send', function(data) local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) - if tonumber(phoneNumber) ~= nil then + if tonumber(phoneNumber) then phoneNumber = tonumber(phoneNumber) end @@ -231,7 +212,7 @@ RegisterNUICallback('send', function(data) y = coords.y, z = coords.z }) - + SendNUIMessage({ showMessageEditor = false }) @@ -269,7 +250,7 @@ Citizen.CreateThread(function() else -- open phone -- todo: is player busy (handcuffed, etc) - if IsControlJustReleased(0, Keys['F1']) and IsInputDisabled(0) then + if IsControlJustReleased(0, 288) and IsInputDisabled(0) then if not ESX.UI.Menu.IsOpen('phone', GetCurrentResourceName(), 'main') then ESX.UI.Menu.CloseAll() ESX.UI.Menu.Open('phone', GetCurrentResourceName(), 'main') @@ -292,10 +273,10 @@ Citizen.CreateThread(function() while true do Citizen.Wait(0) - if CurrentAction ~= nil then + if CurrentAction then ESX.ShowHelpNotification(CurrentActionMsg) - if IsControlJustReleased(0, Keys['E']) and IsInputDisabled(0) then + if IsControlJustReleased(0, 38) and IsInputDisabled(0) then if CurrentAction == 'dispatch' then TriggerServerEvent('esx_phone:stopDispatch', CurrentDispatchRequestId) SetNewWaypoint(CurrentActionData.position.x, CurrentActionData.position.y) @@ -307,4 +288,4 @@ Citizen.CreateThread(function() Citizen.Wait(500) end end -end) +end) \ No newline at end of file diff --git a/esx_phone.sql b/esx_phone.sql index 76da439f..220d5ad1 100644 --- a/esx_phone.sql +++ b/esx_phone.sql @@ -1,12 +1,15 @@ USE `essentialmode`; CREATE TABLE `user_contacts` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `identifier` varchar(255) NOT NULL, - `name` varchar(255) NOT NULL, - `number` int(11) NOT NULL, - - PRIMARY KEY (`id`) + `id` INT(11) NOT NULL AUTO_INCREMENT, + `identifier` VARCHAR(22) NOT NULL, + `name` VARCHAR(100) NOT NULL, + `number` INT(11) NOT NULL, + + PRIMARY KEY (`id`), + INDEX `index_user_contacts_identifier_name_number` (`identifier`, `name`, `number`) ); -ALTER TABLE `users`ADD COLUMN `phone_number` INT NULL; \ No newline at end of file +ALTER TABLE `users` + ADD COLUMN `phone_number` INT(11) NULL, + ADD UNIQUE INDEX `index_users_phone_number` (`phone_number`); \ No newline at end of file diff --git a/html/ui.html b/html/ui.html index e9023e74..d958ac00 100644 --- a/html/ui.html +++ b/html/ui.html @@ -25,9 +25,10 @@
- -
Répertoire
+
+ Répertoire + +
@@ -51,7 +52,8 @@
-
+
@@ -64,7 +66,8 @@
-
Ajouter un contact
+
Ajouter + un contact
diff --git a/html/ui_br.html b/html/ui_br.html index af05a98d..b0e2c9e3 100644 --- a/html/ui_br.html +++ b/html/ui_br.html @@ -25,9 +25,10 @@
- -
Agenda
+
+ Agenda + +
@@ -51,7 +52,8 @@
-
+
@@ -64,7 +66,8 @@
-
Adicionar contato
+
Adicionar contato
diff --git a/html/ui_de.html b/html/ui_de.html index 87faddcd..e8171754 100644 --- a/html/ui_de.html +++ b/html/ui_de.html @@ -25,9 +25,10 @@
- -
Kontakte
+
+ Kontakte + +
@@ -51,7 +52,8 @@
-
+
@@ -64,7 +66,8 @@
-
Kontakt hinzufügen
+
Kontakt + hinzufügen
diff --git a/html/ui_en.html b/html/ui_en.html index 469fb76a..18375822 100644 --- a/html/ui_en.html +++ b/html/ui_en.html @@ -25,9 +25,10 @@
- -
Contacts
+
+ Contacts + +
@@ -51,7 +52,8 @@
-
+
@@ -64,7 +66,8 @@
-
Add a contact
+
Add a + contact
diff --git a/html/ui_pl.html b/html/ui_pl.html index 0d731437..92448574 100644 --- a/html/ui_pl.html +++ b/html/ui_pl.html @@ -1,82 +1,91 @@ - - - - - - -
+ + + + + -
+ -
- - #123456 -
+
- - -
- -
Kontakty
-
-
-
-

Brak kontaktów

-
-
-
-
- -
-
Wiadomości
-
-
-
-

Brak wiadomości

-
-
-
-
- -
-
-
-
- - - - - -
-
-
- -
-
Dodaj kontakt
-
-
- - - - -
-
-
+
+
+ + #123456
+ + + +
+
+ Kontakty + +
+
+
+
+

Brak kontaktów

+
+
+
+
+ +
+
Wiadomości + +
+
+
+
+

Brak wiadomości

+
+
+
+
+ +
+
+
+
+ + + + + +
+
+
+ +
+
Dodaj + kontakt
+
+
+ + + + +
+
+
+
+
- - - - + + + + - - + + + \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index f8c624cb..ee6b4e37 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,6 +1,15 @@ -ESX = nil -local DisptachRequestId = 0 -local PhoneNumbers = {} +ESX = nil +local DisptachRequestId, PhoneNumbers = 0, {} + +TriggerEvent('esx:getSharedObject', function(obj) + ESX = obj + + local xPlayers = ESX.GetPlayers() + + for i=1, #xPlayers, 1 do + LoadPlayer(xPlayers[i]) + end +end) function LoadPlayer(source) local xPlayer = ESX.GetPlayerFromId(source) @@ -21,8 +30,7 @@ function LoadPlayer(source) if phoneNumber == nil then phoneNumber = GenerateUniquePhoneNumber() - MySQL.Async.execute('UPDATE users SET phone_number = @phone_number WHERE identifier = @identifier', - { + MySQL.Async.execute('UPDATE users SET phone_number = @phone_number WHERE identifier = @identifier', { ['@identifier'] = xPlayer.identifier, ['@phone_number'] = phoneNumber }) @@ -42,7 +50,7 @@ function LoadPlayer(source) xPlayer.set('phoneNumber', phoneNumber) local contacts = {} - if PhoneNumbers[xPlayer.job.name] ~= nil then + if PhoneNumbers[xPlayer.job.name] then TriggerEvent('esx_phone:addSource', xPlayer.job.name, source) end @@ -62,16 +70,6 @@ function LoadPlayer(source) end) end -TriggerEvent('esx:getSharedObject', function(obj) - ESX = obj - - local xPlayers = ESX.GetPlayers() - - for i=1, #xPlayers, 1 do - LoadPlayer(xPlayers[i]) - end -end) - function GenerateUniquePhoneNumber() local foundNumber, phoneNumber = false, nil @@ -109,8 +107,8 @@ AddEventHandler('esx_phone:getDistpatchRequestId', function(cb) cb(GetDistpatchRequestId()) end) -AddEventHandler('esx:playerLoaded', function(source) - LoadPlayer(source) +AddEventHandler('esx:playerLoaded', function(playerId) + LoadPlayer(playerId) end) AddEventHandler('esx:playerDropped', function(source) @@ -120,39 +118,36 @@ AddEventHandler('esx:playerDropped', function(source) TriggerClientEvent('esx_phone:setPhoneNumberSource', -1, phoneNumber, -1) PhoneNumbers[phoneNumber] = nil - if PhoneNumbers[xPlayer.job.name] ~= nil then + if PhoneNumbers[xPlayer.job.name] then TriggerEvent('esx_phone:removeSource', xPlayer.job.name, source) end end) AddEventHandler('esx:setJob', function(source, job, lastJob) - if PhoneNumbers[lastJob.name] ~= nil then + if PhoneNumbers[lastJob.name] then TriggerEvent('esx_phone:removeSource', lastJob.name, source) end - if PhoneNumbers[job.name] ~= nil then + if PhoneNumbers[job.name] then TriggerEvent('esx_phone:addSource', job.name, source) end end) RegisterServerEvent('esx_phone:reload') AddEventHandler('esx_phone:reload', function(phoneNumber) - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) + local playerId = source + local xPlayer = ESX.GetPlayerFromId(playerId) local contacts = xPlayer.get('contacts') - TriggerClientEvent('esx_phone:loaded', _source, phoneNumber, contacts) + TriggerClientEvent('esx_phone:loaded', playerId, phoneNumber, contacts) end) RegisterServerEvent('esx_phone:send') AddEventHandler('esx_phone:send', function(phoneNumber, message, anon, position) - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - + local xPlayer = ESX.GetPlayerFromId(source) print(('esx_phone: MESSAGE => %s@%s: %s'):format(xPlayer.name, phoneNumber, message)) - if PhoneNumbers[phoneNumber] ~= nil then - + if PhoneNumbers[phoneNumber] then for k,v in pairs(PhoneNumbers[phoneNumber].sources) do local numType = PhoneNumbers[phoneNumber].type local numHasDispatch = PhoneNumbers[phoneNumber].hasDispatch @@ -171,7 +166,6 @@ AddEventHandler('esx_phone:send', function(phoneNumber, message, anon, position) TriggerClientEvent('esx_phone:onMessage', numSource, xPlayer.get('phoneNumber'), message, numPosition, (numHide and true or anon), numType, false) end end - end end) @@ -203,29 +197,29 @@ end) RegisterServerEvent('esx_phone:addPlayerContact') AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) + local playerId = source + local xPlayer = ESX.GetPlayerFromId(playerId) phoneNumber = tonumber(phoneNumber) local playerOnline = false if phoneNumber == nil then - print(('esx_phone: %s attempted SQL injecting!'):format(xPlayer.identifier)) + print(('esx_phone: %s parsed invalid player contact number!'):format(xPlayer.identifier)) return end MySQL.Async.fetchAll('SELECT phone_number, identifier FROM users WHERE phone_number = @number', { ['@number'] = phoneNumber }, function(result) - if result[1] ~= nil then + if result[1] then if phoneNumber == xPlayer.get('phoneNumber') then - TriggerClientEvent('esx:showNotification', _source, _U('cannot_add_self')) + TriggerClientEvent('esx:showNotification', playerId, _U('cannot_add_self')) else local contacts = xPlayer.get('contacts') -- already added player? for i=1, #contacts, 1 do if contacts[i].number == phoneNumber then - TriggerClientEvent('esx:showNotification', _source, _U('number_in_contacts')) + TriggerClientEvent('esx:showNotification', playerId, _U('number_in_contacts')) return end end @@ -239,34 +233,33 @@ AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) -- is the player currently online? local xTarget = ESX.GetPlayerFromIdentifier(result[1].identifier) - playerOnline = (xTarget ~= nil) + playerOnline = xTarget ~= nil - MySQL.Async.execute('INSERT INTO user_contacts (identifier, name, number) VALUES (@identifier, @name, @number)', - { + MySQL.Async.execute('INSERT INTO user_contacts (identifier, name, number) VALUES (@identifier, @name, @number)', { ['@identifier'] = xPlayer.identifier, ['@name'] = contactName, ['@number'] = phoneNumber }, function(rowsChanged) - TriggerClientEvent('esx:showNotification', _source, _U('contact_added')) - TriggerClientEvent('esx_phone:addContact', _source, contactName, phoneNumber, playerOnline) + TriggerClientEvent('esx:showNotification', playerId, _U('contact_added')) + TriggerClientEvent('esx_phone:addContact', playerId, contactName, phoneNumber, playerOnline) end) end else - TriggerClientEvent('esx:showNotification', _source, _U('number_not_assigned')) + TriggerClientEvent('esx:showNotification', playerId, _U('number_not_assigned')) end end) end) RegisterServerEvent('esx_phone:removePlayerContact') AddEventHandler('esx_phone:removePlayerContact', function(phoneNumber, contactName) - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) + local playerId = source + local xPlayer = ESX.GetPlayerFromId(playerId) local foundNumber = false MySQL.Async.fetchAll('SELECT phone_number FROM users WHERE phone_number = @number', { ['@number'] = phoneNumber }, function(result) - if result[1] ~= nil then + if result[1] then foundNumber = true end @@ -281,17 +274,16 @@ AddEventHandler('esx_phone:removePlayerContact', function(phoneNumber, contactNa xPlayer.set('contacts', contacts) - MySQL.Async.execute('DELETE FROM user_contacts WHERE identifier=@identifier AND name=@name AND number=@number', - { + MySQL.Async.execute('DELETE FROM user_contacts WHERE identifier = @identifier AND name = @name AND number = @number', { ['@identifier'] = xPlayer.identifier, ['@name'] = contactName, ['@number'] = phoneNumber }, function(rowsChanged) - TriggerClientEvent('esx:showNotification', _source, _U('contact_removed')) - TriggerClientEvent('esx_phone:removeContact', _source, contactName, phoneNumber) + TriggerClientEvent('esx:showNotification', playerId, _U('contact_removed')) + TriggerClientEvent('esx_phone:removeContact', playerId, contactName, phoneNumber) end) else - TriggerClientEvent('esx:showNotification', _source, _U('number_not_assigned')) + TriggerClientEvent('esx:showNotification', playerId, _U('number_not_assigned')) end end) end) @@ -299,4 +291,4 @@ end) RegisterServerEvent('esx_phone:stopDispatch') AddEventHandler('esx_phone:stopDispatch', function(dispatchRequestId) TriggerClientEvent('esx_phone:stopDispatch', -1, dispatchRequestId, GetPlayerName(source)) -end) +end) \ No newline at end of file