From b61c5e79f301f8920fd5c3a39ec2d15034ea8af8 Mon Sep 17 00:00:00 2001 From: slashkeyvalue Date: Mon, 29 Mar 2021 20:37:31 -0300 Subject: [PATCH 1/6] Handle server-sent messages routing in the same as a client-sent ones --- resources/[gameplay]/chat/sv_chat.lua | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/resources/[gameplay]/chat/sv_chat.lua b/resources/[gameplay]/chat/sv_chat.lua index aa16c3445..0257cf422 100644 --- a/resources/[gameplay]/chat/sv_chat.lua +++ b/resources/[gameplay]/chat/sv_chat.lua @@ -10,15 +10,8 @@ RegisterServerEvent('__cfx_internal:commandFallback') -- this is a built-in event, but somehow needs to be registered RegisterNetEvent('playerJoining') -exports('addMessage', function(target, message) - if not message then - message = target - target = -1 - end - - if not target or not message then return end - - TriggerClientEvent('chat:addMessage', target, message) +exports('addMessage', function(target, author, message, mode) + routeMessage(target, author, message, mode, true, true) end) local hooks = {} @@ -108,8 +101,8 @@ local function unregisterHooks(resource) end end -local function routeMessage(source, author, message, mode, fromConsole) - if source >= 1 then +local function routeMessage(source, author, message, mode, fromConsole, fromServer) + if not fromServer and source >= 1 then author = GetPlayerName(source) end @@ -170,14 +163,14 @@ local function routeMessage(source, author, message, mode, fromConsole) for _, hook in pairs(hooks) do if hook.fn then - hook.fn(source, outMessage, hookRef) + hook.fn(source, outMessage, hookRef, fromServer) end end if modes[mode] then local m = modes[mode] - m.cb(source, outMessage, hookRef) + m.cb(source, outMessage, hookRef, fromServer) end if messageCanceled then From b9a69ec9ab357349737c7c677abb18f6b0e45832 Mon Sep 17 00:00:00 2001 From: slashkeyvalue Date: Mon, 29 Mar 2021 20:40:47 -0300 Subject: [PATCH 2/6] tweak: undo `addMessage` override, thats stupid --- resources/[gameplay]/chat/sv_chat.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/resources/[gameplay]/chat/sv_chat.lua b/resources/[gameplay]/chat/sv_chat.lua index 0257cf422..eed5cd8ed 100644 --- a/resources/[gameplay]/chat/sv_chat.lua +++ b/resources/[gameplay]/chat/sv_chat.lua @@ -10,7 +10,19 @@ RegisterServerEvent('__cfx_internal:commandFallback') -- this is a built-in event, but somehow needs to be registered RegisterNetEvent('playerJoining') -exports('addMessage', function(target, author, message, mode) + +exports('addMessage', function(target, message) + if not message then + message = target + target = -1 + end + + if not target or not message then return end + + TriggerClientEvent('chat:addMessage', target, message) +end) + +exports('sendMessage', function(target, author, message, mode) routeMessage(target, author, message, mode, true, true) end) From 195eb4dd253730b36ff544fcc30ab81034611c33 Mon Sep 17 00:00:00 2001 From: slashkeyvalue Date: Mon, 29 Mar 2021 20:47:32 -0300 Subject: [PATCH 3/6] tweak: only do ace checking if source is valid. --- resources/[gameplay]/chat/sv_chat.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/[gameplay]/chat/sv_chat.lua b/resources/[gameplay]/chat/sv_chat.lua index eed5cd8ed..092029d95 100644 --- a/resources/[gameplay]/chat/sv_chat.lua +++ b/resources/[gameplay]/chat/sv_chat.lua @@ -132,7 +132,7 @@ local function routeMessage(source, author, message, mode, fromConsole, fromServ if mode and modes[mode] then local modeData = modes[mode] - if modeData.seObject and not IsPlayerAceAllowed(source, modeData.seObject) then + if modeData.seObject and (source >= 1 and not IsPlayerAceAllowed(source, modeData.seObject)) then return end end From 4f82c133254789ad0e1d542d08bd1813a415c8f9 Mon Sep 17 00:00:00 2001 From: slashkeyvalue Date: Mon, 29 Mar 2021 20:50:51 -0300 Subject: [PATCH 4/6] tweak: do not trigger `chatMessage` when its routed from server --- resources/[gameplay]/chat/sv_chat.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/[gameplay]/chat/sv_chat.lua b/resources/[gameplay]/chat/sv_chat.lua index 092029d95..75a1ec1d4 100644 --- a/resources/[gameplay]/chat/sv_chat.lua +++ b/resources/[gameplay]/chat/sv_chat.lua @@ -189,7 +189,9 @@ local function routeMessage(source, author, message, mode, fromConsole, fromServ return end - TriggerEvent('chatMessage', source, #outMessage.args > 1 and outMessage.args[1] or '', outMessage.args[#outMessage.args]) + if not fromServer then + TriggerEvent('chatMessage', source, #outMessage.args > 1 and outMessage.args[1] or '', outMessage.args[#outMessage.args]) + end if not WasEventCanceled() then if type(routingTarget) ~= 'table' then From 47874c08af97918c7f3229fac3f53f0eb729d5ff Mon Sep 17 00:00:00 2001 From: slashkeyvalue Date: Mon, 29 Mar 2021 20:54:03 -0300 Subject: [PATCH 5/6] fix: remove weird spacing --- resources/[gameplay]/chat/sv_chat.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/[gameplay]/chat/sv_chat.lua b/resources/[gameplay]/chat/sv_chat.lua index 75a1ec1d4..1835f7884 100644 --- a/resources/[gameplay]/chat/sv_chat.lua +++ b/resources/[gameplay]/chat/sv_chat.lua @@ -10,7 +10,6 @@ RegisterServerEvent('__cfx_internal:commandFallback') -- this is a built-in event, but somehow needs to be registered RegisterNetEvent('playerJoining') - exports('addMessage', function(target, message) if not message then message = target From f7250fe39e9ee2d0a872984b7bb23ff88a54555b Mon Sep 17 00:00:00 2001 From: slashkeyvalue Date: Mon, 29 Mar 2021 21:41:31 -0300 Subject: [PATCH 6/6] fix: awkward... actually set a routing target when fromServer --- resources/[gameplay]/chat/sv_chat.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/[gameplay]/chat/sv_chat.lua b/resources/[gameplay]/chat/sv_chat.lua index 1835f7884..60b108173 100644 --- a/resources/[gameplay]/chat/sv_chat.lua +++ b/resources/[gameplay]/chat/sv_chat.lua @@ -137,7 +137,8 @@ local function routeMessage(source, author, message, mode, fromConsole, fromServ end local messageCanceled = false - local routingTarget = -1 + + local routingTarget = fromServer and source or -1 local hookRef = { updateMessage = function(t) @@ -188,9 +189,7 @@ local function routeMessage(source, author, message, mode, fromConsole, fromServ return end - if not fromServer then - TriggerEvent('chatMessage', source, #outMessage.args > 1 and outMessage.args[1] or '', outMessage.args[#outMessage.args]) - end + TriggerEvent('chatMessage', fromServer and 0 or source, #outMessage.args > 1 and outMessage.args[1] or '', outMessage.args[#outMessage.args]) if not WasEventCanceled() then if type(routingTarget) ~= 'table' then