diff --git a/client.lua b/client.lua index f636c3c..e34b4d6 100644 --- a/client.lua +++ b/client.lua @@ -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 @@ -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) diff --git a/server.lua b/server.lua index 0ab72c6..45a45c2 100644 --- a/server.lua +++ b/server.lua @@ -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 @@ -190,7 +220,6 @@ 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) @@ -198,9 +227,7 @@ end) RegisterServerEvent('gcPhone:deleteMessage') AddEventHandler('gcPhone:deleteMessage', function(msgId) - print('---deleteMessage' .. msgId) deleteMessage(msgId) - -- gcPhone:deleteMessage id end) RegisterServerEvent('gcPhone:deleteMessageNumber') @@ -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) diff --git a/src_htmlPhone/src/components/UrgenceOnly.vue b/src_htmlPhone/src/components/UrgenceOnly.vue index 8ab6156..88181a0 100644 --- a/src_htmlPhone/src/components/UrgenceOnly.vue +++ b/src_htmlPhone/src/components/UrgenceOnly.vue @@ -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' }], diff --git a/src_htmlPhone/src/components/messages/Messages.vue b/src_htmlPhone/src/components/messages/Messages.vue index 67f88cc..37f194b 100644 --- a/src_htmlPhone/src/components/messages/Messages.vue +++ b/src_htmlPhone/src/components/messages/Messages.vue @@ -202,6 +202,7 @@ export default { .sms{ overflow: auto; zoom: 1; + } .sms_me{ @@ -247,6 +248,7 @@ export default { } .sms_message{ word-wrap: break-word; + max-width: 80%; } #sms_write{ height: 26px; diff --git a/src_htmlPhone/src/main.js b/src_htmlPhone/src/main.js index ab3e397..5ee9746 100644 --- a/src_htmlPhone/src/main.js +++ b/src_htmlPhone/src/main.js @@ -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) }