Bug 3140 - console_print or print_console on client console max characters 128 not checked
console_print or print_console on client console max characters 128 not checked
Status: RESOLVED FIXED
Product: AMX Mod X
Classification: Unclassified
Component: Core
trunk
PC All
: P4 minor
Assigned To: amxmodx-bugs@alliedmods.net
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-02-02 01:33 PST by vittu
Modified: 2014-02-08 23:53 PST (History)
4 users (show)

See Also:


Attachments
Proposed patch (3.91 KB, patch)
2013-08-13 23:10 PDT, DynamicBits
hv.contact: review+
hv.contact: feedback+
alliedmods.net: feedback? (vittu_shmod)
Details | Diff | Splinter Review

Description vittu 2008-02-02 01:33:24 PST
Using console_print or client_print with the print_console option for __client console only__ (not the server's) with a string longer than 128 characters will not print the entire string and will cause the next call, if nothing between, to start on same line of previous call at the 128 character.

I'm not really sure what is causing this because how would it be able to print on same line with the second call if the max is 128?

I also don't know if this is really a bug, since you might say it's up to scripter to check. Yet I found no info telling me there was a max, and printing on same line with previous message cut is not what i think a console print should be intended to do.

Again this only effects client console not the server's.
Comment 1 DynamicBits 2011-11-12 17:16:37 PST
I've actually spent some time dealing with this issue while attempting to add in plugin-level support for longer strings to better support multi-byte characters.

From what I can tell, the client does truncate strings at 128 bytes, no matter what. The client also relies on the server to add newline characters. It could be argued that this is a bug in the hlds client itself.

Adding in newline characters server-side (in AMXX) is one method that could eliminate the behavior you describe, but it *will* break plugins, especially for languages like Russian that use multi-byte characters. I know for a fact that code like the following exists to allow for longer lines:

new gmsgTextMsg = get_user_msgid("TextMsg");
message_begin(MSG_ONE, gmsgTextMsg, {0, 0, 0}, id);
write_byte(print_console);
write_string(message);
message_end();

Unless we want to break a lot of existing code to fix behavior that really isn't caused by AMXX, I think the best solution would be to update the documentation to reflect the 128 byte limit imposed by the client.

--
Andy
Comment 2 Vincent Herbet [:Arkshine] 2013-07-29 00:25:43 PDT
Well, If the client expects \n inserted by the server, it's technically AMXX fault to not ensure \n is properly set but it would require to know the buffer size. As for CS, it seems to be 128. Is it the same for all the others games ?

Also could you explain more about "it will break plugins" ? Because I'm not sure to understand.

I've tried fastly under CS sending TextMsg and I can't get longer lines. It will always stop to 128 characters (or less if using multi-byte characters), even if using sub-string.

Documenting is ok, though this should be done for all supported games.
If limit is 128 everywhere, that's something which should be fixed in AMXX code.
We could send extra messages, like if message length < 2 * 128, we send 1 extra message but not sure if it makes sense and what would be happen if cut in the middle of multi-byte character.
Comment 3 DynamicBits 2013-08-11 15:00:56 PDT
After revisiting this issue, I am in favor of AMXX adding in the newline characters for calls to console_print and client_print for client consoles.

Plugins using the "TextMsg" code will *not* be affected (as I previously stated) since they are not directly calling console_print/client_print.

I'm not aware of any specific examples, but even if making this change means a couple of plugins need to be updated, I think the benefit to the players is greater. With multiple messages being printed without newlines, the console gets pretty difficult to read.

After this change, if a plugin needs to write a longer line, they can use the "TextMsg" code and manually add a newline to the final message. I have done it before and would be happy to help anyone who wants to do the same.

Whether or not this change is made, the documentation should still be updated.

If no one else is against this change, I'll create a patch for it in the next couple weeks.


--
Andy
Comment 4 Vincent Herbet [:Arkshine] 2013-08-13 15:41:02 PDT
As said, I've tried to send TextMsg to get longer lines (I'm not talking about _print) and you can't go above 128. The limit, in CS at least, is 128. String is cut at 128. I've checked with IDA. So I'm not sure how you can go over that.

Anyway, this limit is client-specific, and I don't know if 128 applies for all supported games. If so, we should just cut the string and appending \n if need.
But I guess 128 is a fair limit for the console.
Comment 5 DynamicBits 2013-08-13 17:41:10 PDT
Unfortunately, TextMsg isn't the limiting factor and I don't think there is any way to get around it with a single message. (See the v3.25Beta release of Deagles' Map Manager if you want to see how I did it with multiple messages.)

The limit is actually 127 bytes for all mods that I tested. Not including the \n, only 126 single-byte characters can be printed to the console at once.

Regarding it being a fair limit, I'd have to agree. I've actually removed that section of code from Deagles' Map Manager because I realized it wasn't necessary. I guess the time I spent on it wasn't really wasted because now I can submit this patch with confidence.

Anyways, I'm testing the patch right now with each of the 10 different mods I have servers set up for. The patch limits the length of longer strings and makes sure every message has a \n. It also takes into account double-byte characters so that one is not split at the end of the string.


--
Andy
Comment 6 DynamicBits 2013-08-13 23:10:45 PDT
Created attachment 3529 [details] [review]
Proposed patch

The attached patch:
- Truncates long strings to a max of 127 bytes including the newline
- Does not split trailing double-byte characters
- Was tested with the following mods:
  - Counter-Strike (Windows and Linux client)
  - Counter-Strike: Condition Zero (Windows and Linux client)
  - Day of Defeat (Windows and Linux client)
  - Deathmatch Classic (Windows and Linux client)
  - Half-Life (Windows and Linux client)
  - Half-Life: Opposing Force (Windows and Linux client)
  - Natural Selection (Windows client only)
  - Ricochet (Windows and Linux client)
  - Sven Co-op (Windows client only)
  - Team Fortress Classic (Windows and Linux client)
- Executes less client_print code if the specified player is not connected
- Is formatted in Allman indent style to match most of the existing code
- Is commented to better explain the code
- Has trailing whitespace removed


--
Andy
Comment 7 Vincent Herbet [:Arkshine] 2013-08-14 05:39:19 PDT
Comment on attachment 3529 [details] [review]
Proposed patch

Review of attachment 3529 [details] [review]:
-----------------------------------------------------------------

Thanks for the patch.

It looks good.
Comment 8 AM Bugzilla Bot 2013-08-24 14:49:48 PDT
Pushed changeset: http://hg.alliedmods.net/amxmodx-central/rev/cc2af0f816a4
Changelog:
	Fix missing new line on client console message which is not truncated server-side if its length exceeds buffer size (bug 3140, r=arkshine)
Comment 9 AM Bugzilla Bot 2014-02-08 23:53:26 PST
Commit pushed to master at https://github.com/alliedmodders/amxmodx

https://github.com/alliedmodders/amxmodx/commit/7f0c8205669415ce3d5808f4917f4a1f49908cfa
Fix missing new line on client console message which is not truncated server-side if its length exceeds buffer size (bug 3140, r=arkshine)


Former-commit-id: 6373b0238ddda08ce1d7f9c137650120522d08ef

Note You need to log in before you can comment on or make changes to this bug.