-
-
Notifications
You must be signed in to change notification settings - Fork 169
Improved chat + Fix #460 (Chat messages sent twice) #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
e2d6a80
Update playercolors.lua
Nico8340 ec9465e
Revert "Update playercolors.lua"
Nico8340 6f573a5
Add check for freeroam's state
Nico8340 add32d5
Revert "Add check for freeroam's state"
Nico8340 c2db63f
Ignore playercolors if freeroam is running
Nico8340 6a079e8
Revert "Ignore playercolors if freeroam is running"
Nico8340 e7f0756
Remove onPlayerChat handler from playercolors
Nico8340 56732e7
Remove onPlayerChat handler from assault
Nico8340 6e6251c
Remove onPlayerChat handler from ctv
Nico8340 3b15015
Remove onPlayerChat handler from tdma
Nico8340 431f699
Remove onPlayerChat handler from freeroam
Nico8340 1772c02
Remove uncomplete implementation from admin2
Nico8340 ef04d24
Add logic and support for admin
Nico8340 6fccd20
Add logic and support for admin2
Nico8340 9611228
Resolve conflicts with meta.xml
Nico8340 a1c637c
Merge branch 'master' into master
Nico8340 acc54f2
Fix lint #343
Nico8340 45ffa9d
Using get instead of unique xml
Nico8340 a8a43e3
Remove unintended check
Nico8340 92fd10e
Use named function for onPlayerChat
Nico8340 9356468
Remove unintended files and exports
Nico8340 8385863
Add option to enable / disable chat handler
Nico8340 8354207
Merge branch 'master' into master
Nico8340 672ef45
Fix chat history if 'isChatEnabled' is not true
Nico8340 9ce919d
Merge branch 'master' into master
Nico8340 4d24235
Remove unused config
Nico8340 f051b8a
Merge branch 'master' of https://github.com/Nico8340/mtasa-resources
Nico8340 7df0605
Fix chat history if 'isChatEnabled' is not true (admin2)
Nico8340 38c7d4a
Revert 'Remove unused config'
Nico8340 e77d4a0
Fix chat history logic
Nico8340 51cdd42
Fix chat history logic (new solution)
Nico8340 74c33da
Add message filter
Nico8340 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<chat> | ||
<chatconfig name="antiSpamEnabled" value="true" /> <!-- Is Anti-Spam protection enabled? (true or false) (default: true) --> | ||
<chatconfig name="antiSpamTimeout" value="3" /> <!-- In case of spam, how long do you want to mute the player? (sec) (default: 3) (disable: 0) --> | ||
<chatconfig name="antiSpamDelay" value="1" /> <!-- How much time should elapse between two messages to not be considered spam? (ms) (default: 1) --> | ||
<chatconfig name="antiSpamRepeat" value="true" /> <!-- Do you want to mute the player even if he repeats himself several times in a row? (true or false) (default: true) --> | ||
|
||
<chatconfig name="isPlayercolorsEnabled" value="true" /> <!-- Do you want to use the playercolors resource for coloring the player's name in the chat? (true or false) (default: true) --> | ||
<chatconfig name="isCustomcolorsEnabled" value="false" /> <!-- Do you want to enable custom hex color codes in the chat? (true or false) (default: false) --> | ||
</chat> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
--[[********************************** | ||
* | ||
* Multi Theft Auto - Admin Panel | ||
* | ||
* admin_chat.lua | ||
* | ||
* Original File by Nico834 | ||
* | ||
**************************************]] | ||
|
||
local chatConfig = {} | ||
local chatMessages = {} | ||
local chatTimeouts = {} | ||
|
||
addEventHandler("onResourceStart", resourceRoot, | ||
function() | ||
local configFile = getResourceConfig("conf/chat.xml") | ||
local configData = xmlNodeGetChildren(configFile) | ||
|
||
for k, v in pairs(configData) do | ||
local configName = xmlNodeGetAttribute(v, "name") | ||
local configValue = xmlNodeGetAttribute(v, "value") | ||
|
||
chatConfig[configName] = autoType(configValue) or false | ||
end | ||
|
||
for k, v in pairs(getElementsByType("player")) do | ||
chatMessages[v] = {} | ||
end | ||
end | ||
) | ||
|
||
addEventHandler("onPlayerJoin", root, | ||
function() | ||
chatMessages[source] = {} | ||
end | ||
) | ||
|
||
addEventHandler("onPlayerQuit", root, | ||
function() | ||
chatMessages[source] = nil | ||
chatTimeouts[source] = nil | ||
end | ||
) | ||
|
||
addEventHandler("onPlayerChat", root, | ||
Nico8340 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function(messageContent, messageType) | ||
if messageType ~= 0 then | ||
return | ||
end | ||
|
||
cancelEvent() | ||
|
||
if utf8.len(messageContent) < 1 then | ||
Nico8340 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
outputChatBox("You can't send an empty message.", source, 255, 0, 0) | ||
return | ||
end | ||
|
||
if chatConfig.antiSpamEnabled then | ||
if chatConfig.antiSpamTimeout > 0 then | ||
if chatTimeouts[source] then | ||
if chatTimeouts[source] - getRealTime().timestamp <= 0 then | ||
chatTimeouts[source] = nil | ||
else | ||
outputChatBox("You need to wait " .. math.ceil(chatTimeouts[source] - getRealTime().timestamp) .. " seconds before sending an another message.", source, 255, 0, 0) | ||
return | ||
end | ||
end | ||
end | ||
|
||
local lastMessage = getMessageLast(source) | ||
|
||
if chatConfig.antiSpamRepeat then | ||
if lastMessage and type(lastMessage) == "table" then | ||
local lastMessageContent = lastMessage[1] | ||
|
||
if lastMessageContent then | ||
local contentStart, contentStartIndex = string.find(lastMessageContent, "#ffffff") | ||
local contentTrim = string.sub(lastMessageContent, contentStartIndex + 1) | ||
|
||
if contentTrim == messageContent then | ||
outputChatBox("Stop repeating yourself!", source, 255, 0, 0) | ||
return | ||
end | ||
end | ||
end | ||
end | ||
|
||
if lastMessage and type(lastMessage) == "table" then | ||
local lastMessageTime = lastMessage[2] | ||
|
||
if lastMessageTime then | ||
if math.abs(getRealTime().timestamp - lastMessageTime) < chatConfig.antiSpamDelay then | ||
if chatConfig.antiSpamTimeout > 0 then | ||
outputChatBox("Your message has been marked as spam. You need to wait " .. chatConfig.antiSpamTimeout .. " seconds before sending an another message.", source, 255, 0, 0) | ||
chatTimeouts[source] = getRealTime().timestamp + chatConfig.antiSpamTimeout | ||
else | ||
outputChatBox("Your message has been marked as spam.", source, 255, 0, 0) | ||
end | ||
|
||
return | ||
end | ||
end | ||
end | ||
end | ||
|
||
local playerName = getPlayerName(source) | ||
local playerNameColor = {197, 232, 242} | ||
|
||
if not chatConfig.isCustomcolorsEnabled then | ||
messageContent = messageContent:gsub("#%x%x%x%x%x%x", "") | ||
end | ||
|
||
if chatConfig.isPlayercolorsEnabled then | ||
playerNameColor = {getPlayerNametagColor(source)} | ||
playerNameColor = string.format("#%02X%02X%02X", playerNameColor[1], playerNameColor[2], playerNameColor[3]) | ||
else | ||
playerNameColor = string.format("#%02X%02X%02X", playerNameColor[1], playerNameColor[2], playerNameColor[3]) | ||
end | ||
|
||
messageContent = string.format("%s%s: #ffffff%s", playerNameColor, playerName, messageContent) | ||
messageContent = messageContent:gsub("%s+", " ") | ||
|
||
table.insert(chatMessages[source], {messageContent, getRealTime().timestamp}) | ||
outputChatBox(messageContent, root, 255, 255, 255, true) | ||
outputServerLog(messageContent:gsub("#%x%x%x%x%x%x", "")) | ||
end | ||
) | ||
|
||
function autoType(inputString) | ||
if tonumber(inputString) then | ||
return tonumber(inputString) | ||
elseif inputString == "true" then | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
function getMessageLog(playerElement) | ||
if playerElement and isElement(playerElement) then | ||
if chatMessages[playerElement] then | ||
return chatMessages[playerElement] | ||
else | ||
return false | ||
end | ||
end | ||
end | ||
|
||
function getMessageLast(playerElement) | ||
if playerElement and isElement(playerElement) then | ||
if chatMessages[playerElement] then | ||
return chatMessages[playerElement][#chatMessages[playerElement]] | ||
else | ||
return false | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<chat> | ||
<chatconfig name="antiSpamEnabled" value="true" /> <!-- Is Anti-Spam protection enabled? (true or false) (default: true) --> | ||
<chatconfig name="antiSpamTimeout" value="3" /> <!-- In case of spam, how long do you want to mute the player? (sec) (default: 3) (disable: 0) --> | ||
<chatconfig name="antiSpamDelay" value="1" /> <!-- How much time should elapse between two messages to not be considered spam? (ms) (default: 1) --> | ||
<chatconfig name="antiSpamRepeat" value="true" /> <!-- Do you want to mute the player even if he repeats himself several times in a row? (true or false) (default: true) --> | ||
|
||
<chatconfig name="isPlayercolorsEnabled" value="true" /> <!-- Do you want to use the playercolors resource for coloring the player's name in the chat? (true or false) (default: true) --> | ||
<chatconfig name="isCustomcolorsEnabled" value="false" /> <!-- Do you want to enable custom hex color codes in the chat? (true or false) (default: false) --> | ||
</chat> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.