Raised This Month: $51 Target: $400
 12% 

[ANY] Meta Chat Processor


Post New Thread Reply   
 
Thread Tools Display Modes
Author
reBane
Senior Member
Join Date: May 2020
Plugin ID:
8036
Plugin Version:
23w31b
Plugin Category:
Technical/Development
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
    13 
    Plugin Description:
    Another SayText2 hook, that has is (hopefully) compatible with SCP Redux, Drixevel's CP and CiderCP
    Old 04-22-2022 , 13:55   [ANY] Meta Chat Processor
    Reply With Quote #1

    Meta Chat Processor

    Brief: Supersedes SCP Redux, Drixevels CP and Cider CP, offering compatibility layers for all three. Custom Chat-Colors as well as HexTags were tested with MCP on TF2 (you should probably report issues here first).

    Motivation: The usual, existing chat-processors did not offer the feature set I required. At the same time I didn't want to drop existing plugins / configs that used previous chat-processors, so I naturally went for the most complex thing I could have done: Switch to private forwards and implement compatibility layers. Until now my other plugin implements a pretty rudimentary implementation of SCP forwards to allow CCC to work, while I change the chat format from AllChat/TeamChat to WorldChat/RegionChat (message 'target group' changes), but I can hopefully do it in a nicer way with MCP soon. I want to note that I tested MCP with both Custom-ChatColors and HexTags, both seem to work without any issues.

    This plugin is intended to merge, replace and extend some previous chat processors.
    With the difference to other chat processors, that I want to keep compatibility for plugins that depend on these chat processors to some degree.

    Differences: Instead of a simple forward, there's 3.5 stacked forwards for pre, early, normal and late manipulation, followed by a 'color', and 'formatted' forward if the message was changed before the post forward. This should offer enough flexibility to implement compatibility for other chat processors and then some. Supporting certain chat processors requires basic name tagging capabilities. In MCP this is done through name prefixes, instead of tags. The prefix merges tag color, tag and name color. The message format in MCP is broken down more than usual, allowing for a more refined manipulation, and registration of custom prefixes, e.g. (Region)name : message. Lastly the message is post processed to remove redundant colors and subsequently save bytes in case two plugins can't agree on where to put colors. The last difference is probably that MCP uses private forwards instead of global forwards, meaning you have to register your functions like e.g. Events or SDKHooks.

    In order to implement some of these features, the available data has to be expanded. This is done with a gamedata file on one side, and translation files on the other. The gamedata file can handle team colors, while the translation file handles things like default colors, team names, ect. Note that games that use (TEAM) as prefix can be forced to use the actual team name and vice versa, thus a translation file per game is required. To keep the localized nature, custom senderflag and group names have to be registered with translation phrases, that can then be manipulated numerically.

    On PrintToChat support
    While CPrintToChat from the color includes uses SayText2 to send messages, they are marked as non-hookable so only regular PrintToChat messages could be hooked.
    In addition to that, these messages might already be sent on a per-client basis for translation or otherwise, making parsing very hard! Instead of doing the impossible, MCP instead has a native to send SayText2 messages, to basically fake say messages.

    Config & Setup
    As mentioned above, MCP implements compatibility layers for Simple Chat-Processor, Drixevel's Chat-Processor and Cider Chat-Processor. As I expect most people to not read the docs or just skim over them, all three compat layers are enabled by default. I want to emphasise here that I am only implementing API compatibility, not feature pairity! In addition you can switch the transport method from using SayText2 packets to TextMsg packets (system/plugin messages). Simple Chat-Processor also had the quirk that the Post call was only called if the message was changed. I have an optional fix for that in place, that you can enable in the config as well. The compatibility options for Custom-ChatColors and HexTags will try to read the clients chat colors back into MCP for other plugins to access. In case you still encounter weird issues with external plugins that reliably format chat messages manually or through a compatibility layer, you can turn on the `External Formatting` option and check if things improve.
    By Default MCP will also perform input sanitation that brings chat messages back in-line with vanilla behaviour. Native colors are not actually allowed by games by default, neither are empty messages. The Trim All Whitespaces option will catch unicode spaces as well, to properly block messages without content. Lastly there's the option Ban On NewLine, this option will automatically perma-ban clients sending new line characters in chat. This should get picked up by SourceBans and other ban management utilities. There is no way (that I know of) for a player to input new line characters into a chat message, and this seems to be only used by hack clients to disrupt chat flow (With the latest TF2 patch this should not longer be possible in that game anyways).
    The config can be found at addons/sourcemod/config/metachatprocessor.cfg:

    Code:
    "config"
    {
    	"Compatibility"
    	{
    		"SCP Redux"		"1"
    		"Drixevel"		"1"
    		"Cider"			"1"
    		"Custom-ChatColors"	"1"
    		"HexTags"		"1"
    		"Fix Post Calls"	"0"
    		"External Formatting"	"0"
    	}
    	// Transport defines the message channel/type. You should probably keep it at SayText.
    	// Possible values: [ PrintToChat , SayText ]
    	"Transport"		"SayText"
    	// HookMode defines how messages are cought. Command listener is experimental and might not block the original message correctly in all cases.
    	// Possible values: [ Command , UserMessage ]
    	"HookMode"		"UserMessage"
    	"Input Sanitizer"
    	{
    		"Trim All Whitespaces"		1
    		"Ban On NewLine"			1
    		"Strip Native Colorcodes"	1
    	} 
    }

    Modules
    There's currently 3 module plugins available over on GitHub:
    • MCP-SayRedirects - basic allchat and deadchat
    • Basechat - a replacer for basechat that makes admin messages hook into MCP
    • MCP-ChatTags - a simple, config-compatible CCC and CCC Toggle replacer

    Forwards & Call order
    mcpHookPre:
    Action (int& sender, ArrayList recipients, mcpSenderFlag& senderflags, mcpTargetGroup& targetgroup, mcpMessageOption& options, char[] targetgroupColor)
    Called before the usual processing for early blocking/management.

    mcpHookEarly, mcpHookDefault:
    Action (int& sender, ArrayList recipients, mcpSenderFlag& senderflags, mcpTargetGroup& targetgroup, mcpMessageOption& options, char[] targetgroupColor, char[] name, char[] message)
    These are the main forwards, please use mcpHookDefault unless there's a conflict and it would break.

    mcpHookColors:
    Action (int sender, mcpSenderFlag senderflags, mcpTargetGroup targetgroup, mcpMessageOption options, char[] nameTag, char[] displayName, char[] chatColor)
    The dedicated forward for when mcp prefix and colors are applied. the display name might have formats from earlier forwards, nameTag has the tag&color from mcp.

    mcpHookLate:
    Action (int& sender, ArrayList recipients, mcpSenderFlag& senderflags, mcpTargetGroup& targetgroup, mcpMessageOption& options, char[] targetgroupColor, char[] name, char[] message)
    Same signature as as mcpHookEarly and mcpHookDefault, but already catches the default coloring applied by MCP or other most other plugins.

    mcpHookGroupName:
    Action (int sender, int recipient, mcpSenderFlag senderflags, mcpTargetGroup targetgroup, const char[] groupphrase, char[] groupname)
    This is intended for complex target group names that eventually contains placeholders withing their target group. An example could be SourceMods DM format that would resolve to (To %N), that would require this hook to Format that username in.

    mcpHookFormatted:
    Action (int sender, int recipient, mcpSenderFlag senderflags, mcpTargetGroup targetgroup, mcpMessageOption options, char[] formatted)
    Called after the client specific format translations are applied and the message is about to be sent to a client.

    mcpHookPost:
    void (int sender, ArrayList recipients, mcpSenderFlag senderflags, mcpTargetGroup targetgroup, mcpMessageOption options, const char[] targetgroupColor, const char[] name, const char[] message)
    The message is sent and you may do some post sending cleanup.

    Other natives
    Manage Senderflags:
    With MCP_RegisterSenderFlag and MCP_UnregisterSenderFlags you can register custom sender flags. This is done by translation phrase and will return a flag bit. Since theres 32 bits in a cell, there's a global limit of 32 senderflag. These will be concatinated within asterisks in front of a chat message (default flags are *DEAD* and *SPEC*).

    Manage Targetgroup:
    Using MCP_RegisterTargetGroup and MCP_UnregisterTargetGroups you can add custom message target group names. Again, these use translation phrases but as only one target group can be used at a time, there can be almost any amount of target groups. Target groups are formatted between sender flags and username (default groups are (TEAM) or (Spectator)). Through the modular translation system you can exchange the (TEAM) prefix for named team prefixes like (Terrorists) or (Survivors) and vice versa. These groups are put into the enum in sequence, so checking for a team message can be done with this condition: (mcpTargetTeam1 <= targetgroup <= mcpTargetTeamSender).

    Name Prefixes and Chat Colors
    Yes, MetaChatProcessor has natives to set the name prefix and chat color. I added it, as Drixevel's Chat-Processor has a whole tag system and it felt kinda wrong to have that in the compat layer but nothing comparable in Meta Chat-Processor itself. The name prefix combines tag color, tag string and name color as it's usually really only one value. The chat color is more strongly enforced to be a color instead of a chat prefix. The values are not stored and reset on connect.

    Manually Sending messages:
    You can bypass the SayText2 hook by calling MCP_SendChat directly. This allows you to easily create messages outside the normal format specifications.

    Escaping colors:
    If you want to apply colors by color tags, as we are pretty much used to now, you might run into troubles when a client inputs curly braces / color codes in the input. To prevent those from parsing, you can use MCP_EscapeCurlies and MCP_UnecapeCurlies which uses MCP_PUA_ESCAPED_LCURLY (\uEC01) as temporary replacement. This character is from the private use block and should neither break anything nor render in the client. Since I can not predict how plugins will use curlies I cannot default replace them, in neither input nor color tags.

    Manipulating recipients:
    In order to help you manage the recipients list, there the MCP_FindClients* group of methods as well as MCP_RemoveListElements. You should not worry about duplicate entries in the recipients list, that is already handled by MCP after each forward is called.

    About buffers:
    The message buffers in MCP are a bit bigger then previously. This is mostly to give color tags some additional space as they might collapse to no more than 7 bytes when parsed. Please keep in mind that the maximum length for these network packages is around 256 bytes so you should not exceed MCP_MAXLENGTH_MESSAGE.

    Compatibility:
    Out of the box MCP should work with Custom-ChatColors and HexTags, replacing SCP Redux, DCP and CCP. Keep in mind that MCP only provides API compatibility. This means features like All-Talk or Dead-Talk are not included in MCP itself. The Colortags from Custom-ChatColors and HexTags are pulled into MCPs prefix system, so other plugins can read and work with them, but are NOT pushed back into Custom-ChatColors or HexTags if set through MCP.

    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo

    Last edited by reBane; 08-06-2023 at 12:24. Reason: Update to 23w31b
    reBane is offline
    reBane
    Senior Member
    Join Date: May 2020
    Old 04-29-2022 , 12:08   Re: [ANY/WIP] Meta Chat Processor
    Reply With Quote #2

    Update 22w17a
    * Added name prefix and chat color natives to the .inc that i forgot :s

    ----------

    For a DM plugin I'm writing I kind of want to change the message to display the chat partners name instead of sender name, but I'm not yet sure how this could work... especially if plugins add additional recipients for e.g. admin snooping. something like this
    Sender sees: (DM) To TargetName : Hello
    Target sees: (DM) SenderName : Hello
    Snooping could maybe look like this: (DM) SenderName to TargetName : Hello

    I know I could just not use a chat processor for that but it is a form of chat and so I'd like it to be possible.
    One idea i had for that was to allow plugins to attach one any value to a chat message for the duration of processing, that can be filled in by MCP_SendChat. That may come in handy for other situations as well, but I'm not sure if I really want to do that yet.
    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
    reBane is offline
    reBane
    Senior Member
    Join Date: May 2020
    Old 06-28-2022 , 08:34   Re: [ANY/WIP] Meta Chat Processor
    Reply With Quote #3

    Update 22w26a
    * Added custom message data. Every plugin can now attach arbitrary data to a chat message for it's lifetime to e.g. carry additional information from pre to post forwards.
    * Added a hook for translating group names. This is intended for cases like DMs, allowing additional placeholder in group name phrases.
    * Added more compatibility to CCC and HexTags, importing the colors they parsed.
    * Changed color message options handling, now stripping and parsing colors after every callback where the flags are set.
    * Added input sanitation options, bringing the baseline closer to what is allowed in vanilla messages (no empty messages, no color codes, ban illegal new-line characters) if desired.
    * Other stuff i forgor
    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
    reBane is offline
    reBane
    Senior Member
    Join Date: May 2020
    Old 09-03-2022 , 08:05   Re: [ANY] Meta Chat Processor
    Reply With Quote #4

    Update 22w34a
    * [main] Added command-listener as hook method
    * [redirects] Added sm_sayredirect_forecteamname to change the say_team prefix
    * miscellaneous bugfixes
    Might still have issues that i kinda can't test alone (couldn't really get tf2 to run in sandboxy), so please break the plugin gently
    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
    reBane is offline
    reBane
    Senior Member
    Join Date: May 2020
    Old 10-12-2022 , 12:26   Re: [ANY] Meta Chat Processor
    Reply With Quote #5

    Update 22w41a
    * Network messages are now collected for instances where the game decides to send a message per recipient instead of sending to all recipients at once. Processing was mostly moved to the following tick as a side-effect, allowing SayText2 messages to be send during processing
    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
    reBane is offline
    Dragokas
    Veteran Member
    Join Date: Nov 2017
    Location: Ukraine on fire
    Old 10-15-2022 , 15:21   Re: [ANY] Meta Chat Processor
    Reply With Quote #6

    Nice, that somebody cares about backward compatibility with previous chat processors.
    However, I see some possible downside about this.
    What if my plugin also supports > 1 chat processors, let's say it has implementation of both SCP & DCP forwards.
    Will my plugin receive double-massage, because I think MCP will transmit message to both of these forwards within the single plugin?
    __________________
    Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
    [My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
    Dragokas is offline
    reBane
    Senior Member
    Join Date: May 2020
    Old 10-17-2022 , 15:29   Re: [ANY] Meta Chat Processor
    Reply With Quote #7

    Without further adjustments such a plugin would process the message twice, yes. The plugin could check for loaded chat processors to disable other forwards or, if that's not an option and all your plugins support the same chat processor you can also disable other compat layers in the config.
    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo

    Last edited by reBane; 10-17-2022 at 15:30.
    reBane is offline
    reBane
    Senior Member
    Join Date: May 2020
    Old 03-05-2023 , 09:00   Re: [ANY] Meta Chat Processor
    Reply With Quote #8

    Update 23w08a
    * Fixed some special chars in nicknames being replaced with `?`
    * Fixed some chat message duplications
    * Fixed name codes being usable to send empty messages
    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
    reBane is offline
    reBane
    Senior Member
    Join Date: May 2020
    Old 07-23-2023 , 11:15   Re: [ANY] Meta Chat Processor
    Reply With Quote #9

    Update 23w29a
    * Improved support with color tag formatting for CCC-Toggle
    * Added "External Formatting" option to (partially) turn off MCP formatting. This is intended to handle plugins that are not explicitly supported, but change the name and chat color similar to what CCC or HexTags do, but don't have proper support built into MCP
    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
    reBane is offline
    reBane
    Senior Member
    Join Date: May 2020
    Old 08-06-2023 , 12:25   Re: [ANY] Meta Chat Processor
    Reply With Quote #10

    Update to 23w31b
    * Added my own config-compatible replacement for Custom Chat-Colors and Custom Chat-Colors Toggle because i wanted to be able to switch applicable profiles
    * Fixed a native in MCP along the way
    __________________
    Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
    reBane is offline
    Reply



    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 07:44.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode