367 * @param color_code the colour of the command. Red in case of errors, etc. |
367 * @param color_code the colour of the command. Red in case of errors, etc. |
368 * @param string the message entered or output on the console (notice, error, etc.) |
368 * @param string the message entered or output on the console (notice, error, etc.) |
369 */ |
369 */ |
370 void IConsolePrint(uint16 color_code, const char *string) |
370 void IConsolePrint(uint16 color_code, const char *string) |
371 { |
371 { |
|
372 char *str; |
372 #ifdef ENABLE_NETWORK |
373 #ifdef ENABLE_NETWORK |
373 if (_redirect_console_to_client != 0) { |
374 if (_redirect_console_to_client != 0) { |
374 /* Redirect the string to the client */ |
375 /* Redirect the string to the client */ |
375 SEND_COMMAND(PACKET_SERVER_RCON)(NetworkFindClientStateFromIndex(_redirect_console_to_client), color_code, string); |
376 SEND_COMMAND(PACKET_SERVER_RCON)(NetworkFindClientStateFromIndex(_redirect_console_to_client), color_code, string); |
376 return; |
377 return; |
377 } |
378 } |
378 #endif |
379 #endif |
379 |
380 |
|
381 /* Create a copy of the string, strip if of colours and invalid |
|
382 * characters and (when applicable) assign it to the console buffer */ |
|
383 str = strdup(string); |
|
384 str_strip_colours(str); |
|
385 str_validate(str); |
|
386 |
380 if (_network_dedicated) { |
387 if (_network_dedicated) { |
381 printf("%s\n", string); |
388 printf("%s\n", str); |
382 IConsoleWriteToLogFile(string); |
389 IConsoleWriteToLogFile(str); |
|
390 free(str); // free duplicated string since it's not used anymore |
383 return; |
391 return; |
384 } |
392 } |
385 |
393 |
386 /* move up all the strings in the buffer one place and do the same for colour |
394 /* move up all the strings in the buffer one place and do the same for colour |
387 * to accomodate for the new command/message */ |
395 * to accomodate for the new command/message */ |
388 free(_iconsole_buffer[0]); |
396 free(_iconsole_buffer[0]); |
389 memmove(&_iconsole_buffer[0], &_iconsole_buffer[1], sizeof(_iconsole_buffer[0]) * ICON_BUFFER); |
397 memmove(&_iconsole_buffer[0], &_iconsole_buffer[1], sizeof(_iconsole_buffer[0]) * ICON_BUFFER); |
390 _iconsole_buffer[ICON_BUFFER] = strdup(string); |
398 _iconsole_buffer[ICON_BUFFER] = str; |
391 |
|
392 str_strip_colours(_iconsole_buffer[ICON_BUFFER]); |
|
393 str_validate(_iconsole_buffer[ICON_BUFFER]); |
|
394 |
399 |
395 memmove(&_iconsole_cbuffer[0], &_iconsole_cbuffer[1], sizeof(_iconsole_cbuffer[0]) * ICON_BUFFER); |
400 memmove(&_iconsole_cbuffer[0], &_iconsole_cbuffer[1], sizeof(_iconsole_cbuffer[0]) * ICON_BUFFER); |
396 _iconsole_cbuffer[ICON_BUFFER] = color_code; |
401 _iconsole_cbuffer[ICON_BUFFER] = color_code; |
397 |
402 |
398 IConsoleWriteToLogFile(string); |
403 IConsoleWriteToLogFile(_iconsole_buffer[ICON_BUFFER]); |
399 |
404 |
400 SetWindowDirty(FindWindowById(WC_CONSOLE, 0)); |
405 SetWindowDirty(FindWindowById(WC_CONSOLE, 0)); |
401 } |
406 } |
402 |
407 |
403 /** |
408 /** |