I'm working on a script for Linux that monitors chat messages. The only issue is that, if a player types square brackets into chat, they are passed through un-escaped which is problematic for reliable processing:
[CHANNELROUTER] RECEIVED MESSAGE ON Server(0): [CHAT][sender=Nightwalker][receiverType=CHANNEL][receiver=all][message=chat ]]]test]
Here are two solutions:
1. Escape or remove square brackets sent by players in chat
2. Have an option in server.cfg to use a tab instead of square brackets to separate fields (and also ensure tabs are stripped from entity names and chat messages).
Option #2 is a better option as it eliminates the need to use regex for processing, and instead allows separating fields based on a single character--which is way faster. Right now, my solution is to reject messages that contain extra [] characters, rather than creating complex logic to intelligently decipher messages.
This would require minimal server changes, and make automated processing faster and less prone to spoofing.
================================
My next suggestion is a little more complex:
Instead of sending chat messages to the console, have an option in server.cfg to load an external script to intercept chat messages (and possibly player-created entity names) before they are broadcast/committed to the server. The script would read messages from stdin, and output them to stdiout. This can be done by using popen to start a process with a bi-directional pipe.
After a message is received, the script can do whatever it chooses: Pass the message back unchanged to the server, filter the message, reject the message, send an alternative message, or optionally send server commands to warn/kick/ban a player--or perform any other server action that could be done from the console.
It would also be nice to see a /chatpm <playername> console command to be added, as well as the ability to create new chat channels from the console as well, /chatchannelnew <channel name>
[CHANNELROUTER] RECEIVED MESSAGE ON Server(0): [CHAT][sender=Nightwalker][receiverType=CHANNEL][receiver=all][message=chat ]]]test]
Here are two solutions:
1. Escape or remove square brackets sent by players in chat
2. Have an option in server.cfg to use a tab instead of square brackets to separate fields (and also ensure tabs are stripped from entity names and chat messages).
Option #2 is a better option as it eliminates the need to use regex for processing, and instead allows separating fields based on a single character--which is way faster. Right now, my solution is to reject messages that contain extra [] characters, rather than creating complex logic to intelligently decipher messages.
This would require minimal server changes, and make automated processing faster and less prone to spoofing.
================================
My next suggestion is a little more complex:
Instead of sending chat messages to the console, have an option in server.cfg to load an external script to intercept chat messages (and possibly player-created entity names) before they are broadcast/committed to the server. The script would read messages from stdin, and output them to stdiout. This can be done by using popen to start a process with a bi-directional pipe.
After a message is received, the script can do whatever it chooses: Pass the message back unchanged to the server, filter the message, reject the message, send an alternative message, or optionally send server commands to warn/kick/ban a player--or perform any other server action that could be done from the console.
It would also be nice to see a /chatpm <playername> console command to be added, as well as the ability to create new chat channels from the console as well, /chatchannelnew <channel name>