Skip to content

Commit

Permalink
Perf & remove police urgence
Browse files Browse the repository at this point in the history
  • Loading branch information
Gannon001 committed Jul 1, 2017
1 parent dbd07cb commit 52b57ab
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 35 deletions.
29 changes: 20 additions & 9 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ AddEventHandler("gcPhone:allMessage", function(_messages)
end)

RegisterNetEvent("gcPhone:receiveMessage")
AddEventHandler("gcPhone:receiveMessage", function(number, message)
SetNotificationTextEntry("STRING")
AddTextComponentString('Nouveau message')
DrawNotification(false, false)
PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
Citizen.Wait(300)
PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
Citizen.Wait(300)
PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
AddEventHandler("gcPhone:receiveMessage", function(message)
table.insert(messages, message)
SendNUIMessage({event = 'updateMessages', messages = messages})
if message.owner == 0 then
SetNotificationTextEntry("STRING")
AddTextComponentString('~o~Nouveau message')
DrawNotification(false, false)
PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
Citizen.Wait(300)
PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
Citizen.Wait(300)
PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
end
end)
--====================================================================================
-- Function client | Contacts
Expand All @@ -101,6 +105,13 @@ end
function deleteMessage(msgId)
Citizen.Trace('deleteMessage' .. msgId)
TriggerServerEvent('gcPhone:deleteMessage', msgId)
for k, v in ipairs(messages) do
if v.id == msgId then
table.remove(messages, k)
SendNUIMessage({event = 'updateMessages', messages = messages})
return
end
end
end

function deleteMessageContact(num)
Expand Down
161 changes: 141 additions & 20 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,61 @@ function getMessages(identifier)
end

function _internalAddMessage(transmitter, receiver, message, owner)
print('ADD MESSAGE: ' .. transmitter .. receiver .. message .. owner)
MySQL.Sync.execute("INSERT INTO phone_messages (`transmitter`, `receiver`,`message`, `isRead`,`owner`) VALUES(@transmitter, @receiver, @message, @isRead, @owner)", {
-- print('ADD MESSAGE: ' .. transmitter .. receiver .. message .. owner)
-- MySQL.Sync.execute("INSERT INTO phone_messages (`transmitter`, `receiver`,`message`, `isRead`,`owner`) VALUES(@transmitter, @receiver, @message, @isRead, @owner)", {
-- ['@transmitter'] = transmitter,
-- ['@receiver'] = receiver,
-- ['@message'] = message,
-- ['@isRead'] = owner,
-- ['@owner'] = owner
-- })
Parameters = {
['@transmitter'] = transmitter,
['@receiver'] = receiver,
['@message'] = message,
['@isRead'] = owner,
['@owner'] = owner
})
}
local Query = "INSERT INTO phone_messages (`transmitter`, `receiver`,`message`, `isRead`,`owner`) VALUES(@transmitter, @receiver, @message, @isRead, @owner)"
local Query2 = 'SELECT * from phone_messages WHERE `id` = (SELECT LAST_INSERT_ID())'
local Connection = MySQL:createConnection()
local Command = Connection.CreateCommand()
Command.CommandText = Query
if type(Parameters) == "table" then
for Param in pairs(Parameters) do
Command.Parameters.AddWithValue(Param, Parameters[Param])
end
end
pcall(Command.ExecuteNonQuery)

--phase2
Command = Connection.CreateCommand()
Command.CommandText = Query2
local status, result = pcall(Command.ExecuteReader)
return MySQL.Async.wrapQuery(
function (Result)
return Result
end,
Connection,
Command.CommandText
)(MyConvertResultToTable(result), nil)[1]
end

function addMessage(source, identifier, phone_number, message)
local otherIdentifier = getIdentifierByPhoneNumber(phone_number)
local myPhone = getNumberPhone(identifier)
if otherIdentifier ~= nil then
_internalAddMessage(myPhone, phone_number, message, 0)
local tomess = _internalAddMessage(myPhone, phone_number, message, 0)
getSourceFromIdentifier(otherIdentifier, function (osou)
if osou ~= nil then
TriggerClientEvent("gcPhone:allMessage", osou, getMessages(otherIdentifier))
TriggerClientEvent("gcPhone:receiveMessage", osou, myPhone, message)
-- TriggerClientEvent("gcPhone:allMessage", osou, getMessages(otherIdentifier))
TriggerClientEvent("gcPhone:receiveMessage", osou, tomess)
end
end)
end
_internalAddMessage(phone_number, myPhone, message, 1)
TriggerClientEvent("gcPhone:allMessage", source, getMessages(identifier))
-- TriggerClientEvent("gcPhone:receiveMessage", source, myPhone, message)
local memess = _internalAddMessage(phone_number, myPhone, message, 1)
-- TriggerClientEvent("gcPhone:allMessage", source, getMessages(identifier))
TriggerClientEvent("gcPhone:receiveMessage", source, memess)

end

Expand Down Expand Up @@ -190,17 +220,14 @@ end

RegisterServerEvent('gcPhone:sendMessage')
AddEventHandler('gcPhone:sendMessage', function(phoneNumber, message)
print('---sendMessage ' .. phoneNumber .. ' -> ' .. message)
local identifier = GetPlayerIdentifiers(source)[1]
print(identifier)
addMessage(source, identifier, phoneNumber, message)
end)

RegisterServerEvent('gcPhone:deleteMessage')
AddEventHandler('gcPhone:deleteMessage', function(msgId)
print('---deleteMessage' .. msgId)
deleteMessage(msgId)
-- gcPhone:deleteMessage id
end)

RegisterServerEvent('gcPhone:deleteMessageNumber')
Expand Down Expand Up @@ -283,14 +310,108 @@ print(' /_| /_|')
print('')
print('')

local query = "INSERT INTO phone_messages (`transmitter`, `receiver`,`message`, `isRead`,`owner`) VALUES(@transmitter, @receiver, @message, @isRead, @owner)"
local params = {
['@transmitter'] = '00',
['@receiver'] = '00',
['@message'] = '00',
['@isRead'] = 1,
['@owner'] = 1
}
-- local Transaction = MySQL.Sync.beginTransaction()
-- MySQL.Sync.execute("INSERT INTO phone_messages (`transmitter`, `receiver`,`message`, `isRead`,`owner`) VALUES(@transmitter, @receiver, @message, @isRead, @owner)", {
-- ['@transmitter'] = 'Inconnu',
-- ['@receiver'] = '06',
-- ['@message'] = 'Je sais qui tu est',
-- ['@isRead'] = 0,
-- ['@owner'] = 0
-- }, Transaction)

-- MySQL.Sync.fetchScalar('SELECT LAST_INSERT_ID()', nil, Transaction)
-- local result = MySQL.Sync.commitTransaction(Transaction)
-- print('result: ' .. json.encode(result))



-- function wrapQueryNoClose(next, Connection, Message, Transformer)
-- Transformer = Transformer or function (Result) return Result end
-- local Stopwatch = clr.System.Diagnostics.Stopwatch()
-- Stopwatch.Start()

-- return function (Result, Error)
-- if Error ~= nil then
-- Logger:Error(Error.ToString())

-- -- if Connection then
-- -- Connection.Close()
-- -- Connection.Dispose()
-- -- end

-- return nil
-- end

-- local ConnectionId = -1;

-- Result = Transformer(Result)

-- -- if Connection then
-- -- ConnectionId = Connection.ServerThread
-- -- Connection.Close()
-- -- Connection.Dispose()
-- -- end

-- Stopwatch.Stop()

-- next(Result)

-- return Result
-- end
-- end

-- function MySQLInsertMessage(Parameters)
-- local Query = "INSERT INTO phone_messages (`transmitter`, `receiver`,`message`, `isRead`,`owner`) VALUES(@transmitter, @receiver, @message, @isRead, @owner)"
-- local Query2 = 'SELECT * from phone_messages WHERE `id` = (SELECT LAST_INSERT_ID())'
-- local Connection = MySQL:createConnection()
-- local Command = Connection.CreateCommand()
-- Command.CommandText = Query
-- if type(Parameters) == "table" then
-- for Param in pairs(Parameters) do
-- Command.Parameters.AddWithValue(Param, Parameters[Param])
-- end
-- end
-- pcall(Command.ExecuteNonQuery)

-- --phase2
-- Command = Connection.CreateCommand()
-- Command.CommandText = Query2
-- local status, result = pcall(Command.ExecuteReader)
-- return MySQL.Async.wrapQuery(
-- function (Result)
-- return Result
-- end,
-- Connection,
-- Command.CommandText
-- )(MyConvertResultToTable(result), nil)
-- end


-- local result = MySQLInsertMessage({
-- ['@transmitter'] = 'Inconnu',
-- ['@receiver'] = '06',
-- ['@message'] = 'Je sais qui tu est',
-- ['@isRead'] = 0,
-- ['@owner'] = 0
-- })
-- print('result: ' .. json.encode(result))
-- local mess = MySQL.Sync.fetchAll('SELECT * from phone_messages WHERE `id` = (SELECT LAST_INSERT_ID())', {})
-- print('result: ' .. json.encode(mess))
-- for _, v in pairs(data) do
-- for key, vv in pairs(v) do
-- print(key .. ' -> ' .. vv)
-- end
-- print('----')
-- end

-- local query = "INSERT INTO phone_messages (`transmitter`, `receiver`,`message`, `isRead`,`owner`) VALUES(@transmitter, @receiver, @message, @isRead, @owner)"
-- local params = {
-- ['@transmitter'] = '00',
-- ['@receiver'] = '00',
-- ['@message'] = '00',
-- ['@isRead'] = 1,
-- ['@owner'] = 1
-- }
-- local insert = MySQL.Sync.execute(, )
-- print('TTTTTTTTTTTTTTTT')
-- print(insert)
Expand Down
8 changes: 4 additions & 4 deletions src_htmlPhone/src/components/UrgenceOnly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export default {
eventName: 'ambulancier:callAmbulancier',
type: 'Coma'
}, {
title: 'Police',
eventName: 'police:callPolice',
type: 'Homme à terre'
}, {
// title: 'Police',
// eventName: 'police:callPolice',
// type: 'Homme à terre'
// }, {
title: 'Hopital',
eventName: 'ambulancier:selfRespawn'
}],
Expand Down
2 changes: 2 additions & 0 deletions src_htmlPhone/src/components/messages/Messages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export default {
.sms{
overflow: auto;
zoom: 1;
}
.sms_me{
Expand Down Expand Up @@ -247,6 +248,7 @@ export default {
}
.sms_message{
word-wrap: break-word;
max-width: 80%;
}
#sms_write{
height: 26px;
Expand Down
4 changes: 2 additions & 2 deletions src_htmlPhone/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ new Vue({
number: '09',
id: 15
})
this.messages.push({id: 6, transmitter: '09', time: new Date().getTime(), message: 'GPS: -1036.7025146484, -2735.7883300781', isRead: 0, owner: 0})
this.messages.push({id: 6, transmitter: '09', time: new Date().getTime(), message: 'GPS: 5555555555555555, 22222222', isRead: 0, owner: Math.random() > 0.5 ? 1 : 0})
// this.urgenceOnly = !this.urgenceOnly
})
}
// in Game
window.addEventListener('message', (event) => {
console.log(JSON.stringify(event.data))
// console.log(JSON.stringify(event.data))
if (event.data.keyUp !== undefined) {
this.$bus.$emit('keyUp' + event.data.keyUp)
}
Expand Down

0 comments on commit 52b57ab

Please sign in to comment.