1
0
mirror of https://github.com/citizenfx/cfx-server-data.git synced 2025-02-09 06:33:29 +08:00

chat2: fix routing policy for / and say, add mode to hook data

This commit is contained in:
astatine 2020-04-27 11:30:50 +02:00 committed by blattersturm
parent abb38d4ff1
commit 1c41359493

View File

@ -106,17 +106,16 @@ local function unregisterHooks(resource)
end end
end end
AddEventHandler('_chat:messageEntered', function(author, color, message, mode) local function routeMessage(source, author, message, mode, fromConsole)
if not message or not author then if source >= 1 then
return author = GetPlayerName(source)
end end
local source = source
local outMessage = { local outMessage = {
color = { 255, 255, 255 }, color = { 255, 255, 255 },
multiline = true, multiline = true,
args = { message } args = { message },
mode = mode
} }
if author ~= "" then if author ~= "" then
@ -167,18 +166,16 @@ AddEventHandler('_chat:messageEntered', function(author, color, message, mode)
end end
} }
if message:sub(1, 1) ~= '/' then for _, hook in pairs(hooks) do
for _, hook in pairs(hooks) do if hook.fn then
if hook.fn then hook.fn(source, outMessage, hookRef)
hook.fn(source, outMessage, hookRef)
end
end end
end
if modes[mode] then if modes[mode] then
local m = modes[mode] local m = modes[mode]
m.cb(source, outMessage, hookRef) m.cb(source, outMessage, hookRef)
end
end end
if messageCanceled then if messageCanceled then
@ -188,6 +185,9 @@ AddEventHandler('_chat:messageEntered', function(author, color, message, mode)
TriggerEvent('chatMessage', source, #outMessage.args > 1 and outMessage.args[1] or '', outMessage.args[#outMessage.args]) TriggerEvent('chatMessage', source, #outMessage.args > 1 and outMessage.args[1] or '', outMessage.args[#outMessage.args])
if not WasEventCanceled() then if not WasEventCanceled() then
-- remove the mode name, we don't need this for routing
outMessage.mode = nil
if type(routingTarget) ~= 'table' then if type(routingTarget) ~= 'table' then
TriggerClientEvent('chat:addMessage', routingTarget, outMessage) TriggerClientEvent('chat:addMessage', routingTarget, outMessage)
else else
@ -197,17 +197,26 @@ AddEventHandler('_chat:messageEntered', function(author, color, message, mode)
end end
end end
print(author .. '^7' .. (modes[mode] and (' (' .. modes[mode].displayName .. ')') or '') .. ': ' .. message .. '^7') if not fromConsole then
print(author .. '^7' .. (modes[mode] and (' (' .. modes[mode].displayName .. ')') or '') .. ': ' .. message .. '^7')
end
end
AddEventHandler('_chat:messageEntered', function(author, color, message, mode)
if not message or not author then
return
end
local source = source
routeMessage(source, author, message, mode)
end) end)
AddEventHandler('__cfx_internal:commandFallback', function(command) AddEventHandler('__cfx_internal:commandFallback', function(command)
local name = GetPlayerName(source) local name = GetPlayerName(source)
TriggerEvent('chatMessage', source, name, '/' .. command) -- route the message as if it were a /command
routeMessage(source, name, '/' .. command, nil, true)
if not WasEventCanceled() then
TriggerClientEvent('chatMessage', -1, name, { 255, 255, 255 }, '/' .. command)
end
CancelEvent() CancelEvent()
end) end)
@ -230,7 +239,7 @@ AddEventHandler('playerDropped', function(reason)
end) end)
RegisterCommand('say', function(source, args, rawCommand) RegisterCommand('say', function(source, args, rawCommand)
TriggerClientEvent('chatMessage', -1, (source == 0) and 'console' or GetPlayerName(source), { 255, 255, 255 }, rawCommand:sub(5)) routeMessage(source, (source == 0) and 'console' or GetPlayerName(source), rawCommand:sub(5), nil, true)
end) end)
-- command suggestions for clients -- command suggestions for clients