Read by Council Server chat message change for better filtering/processing (Warning:coder geek content)

    Joined
    Mar 31, 2015
    Messages
    281
    Reaction score
    95
    • Purchased!
    • Legacy Citizen 5
    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>
     
    Joined
    Mar 31, 2015
    Messages
    281
    Reaction score
    95
    • Purchased!
    • Legacy Citizen 5
    You should always, always, always sanitize user-supplied input. That means implementing point 1 (escape special characters) .

    I found some links that might help:
    In a bash script, how do I sanitize user input?
    How to sanitize user input in Bash
    Erm. I think you failed to understand the problem here. The escaping problem isn't on my end, it's on the end which receives the input to begin with. My script has no easy way to determine if the first ']" is sees is an field marker, or something the player typed in. It doesn't matter WHAT language I program this in, even C/C++ (I'm actually using python for this-- it would be insane to shell interpreter for processing user input).

    From my end as a programmer, removing the [] characters completely and and only having to deal with a single character that separates fields makes processing much faster and eliminates the overhead of loading a regex library. So, option #2 is far better from a programmer's prospective. Also, there are Unix utilities which already expect to see a tab as a field separator, so it makes a lot of sense there (then there are tab-delimited files, and so on). Although, in my code, I'll use \a because the alarm bell character isn't something people type in from the keyboard ever.
     
    Joined
    Jul 21, 2013
    Messages
    2,932
    Reaction score
    460
    • Hardware Store
    Erm. I think you failed to understand the problem here. The escaping problem isn't on my end, it's on the end which receives the input to begin with. My script has no easy way to determine if the first ']" is sees is an field marker, or something the player typed in. It doesn't matter WHAT language I program this in, even C/C++ (I'm actually using python for this-- it would be insane to shell interpreter for processing user input).

    From my end as a programmer, removing the [] characters completely and and only having to deal with a single character that separates fields makes processing much faster and eliminates the overhead of loading a regex library. So, option #2 is far better from a programmer's prospective. Also, there are Unix utilities which already expect to see a tab as a field separator, so it makes a lot of sense there (then there are tab-delimited files, and so on). Although, in my code, I'll use \a because the alarm bell character isn't something people type in from the keyboard ever.
    what if you were to simply iterate over it char by char? The order of the fields should remain the same, so you can safely assume the actual message will be the last entry, and thus you can work around the problem of it also containing key chars.
     
    • Like
    Reactions: ToasterBorst
    Joined
    Mar 31, 2015
    Messages
    281
    Reaction score
    95
    • Purchased!
    • Legacy Citizen 5
    what if you were to simply iterate over it char by char? The order of the fields should remain the same, so you can safely assume the actual message will be the last entry, and thus you can work around the problem of it also containing key chars.
    I thought about that, but if a faction, player, or channel name contains a bracket character, then it'll break.