AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Text formating? (https://forums.alliedmods.net/showthread.php?t=23023)

Charr 01-08-2006 20:43

Text formating?
 
I was looking through amxmodx.inc and saw this:
Code:

/* Prints message to server console.
* You may use text formating (f.e. server_print("%-32s %.2f!","hello",7.345)) */

???

Brad 01-08-2006 20:44

This link should help.
http://www.cplusplus.com/ref/cstdio/printf.html

Charr 01-08-2006 20:47

Thanks for the fast help :) !

Brad 01-08-2006 20:50

No problem, I had some time while I'm waiting for Mein to come over.

Twilight Suzuka 01-08-2006 21:52

Har har.

Charr 01-09-2006 10:06

Also, what else can you format?

Brad 01-09-2006 10:49

What do you mean, "what else"? What else are you referring to?

Charr 01-09-2006 10:51

What else can you use text formating?

Brad 01-09-2006 11:26

Anywhere you can use %s, %i, and the like. format(), client_print(), etc.

PM 01-09-2006 12:16

Which makes it DANGEROUS to pass strings which were supplied from outside to such a function directly.

Imagine this example:

Code:
// Assume this is in a client command handler new text[32]; read_argv(1, text, 31); client_print(id, print_chat, text);   //!!!!

It may look right, but when the client types:
command "hello %s", you will get a native error and he won't get any message. It's not as damaging in small as it is in C/C++, where your program usually crashes on such occassions (like valve's source bug where you would crash all clients if your name contained %s and you made your name appear in the hud, eg. by commiting suicide).

It's better to do this:
Code:
client_print(id, print_chat, "%s", text);


All times are GMT -4. The time now is 16:13.

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