]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - console.c
Merge remote branch 'origin/master' into akari/irc
[xonotic/darkplaces.git] / console.c
index 0eaccd3efb4a43914d6eb5342a973e57a08d4c19..e89ad5314346361e2eaa7e17db503b3d30167df3 100644 (file)
--- a/console.c
+++ b/console.c
@@ -29,6 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // for u8_encodech
 #include "ft2.h"
 
+#include <pthread.h>
+
 float con_cursorspeed = 4;
 
 // lines up from bottom to display
@@ -623,8 +625,11 @@ void Con_MessageMode_f (void)
 {
        key_dest = key_message;
        chat_mode = 0; // "say"
-       chat_bufferlen = 0;
-       chat_buffer[0] = 0;
+       if(Cmd_Argc() > 1)
+       {
+               dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args());
+               chat_bufferlen = strlen(chat_buffer);
+       }
 }
 
 
@@ -637,8 +642,11 @@ void Con_MessageMode2_f (void)
 {
        key_dest = key_message;
        chat_mode = 1; // "say_team"
-       chat_bufferlen = 0;
-       chat_buffer[0] = 0;
+       if(Cmd_Argc() > 1)
+       {
+               dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args());
+               chat_bufferlen = strlen(chat_buffer);
+       }
 }
 
 /*
@@ -901,7 +909,7 @@ void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest, qboolean
                rcon_redirect_buffer[2] = 0;
                rcon_redirect_buffer[3] = 0;
                // this is a reply to a CCREQ_RCON
-               rcon_redirect_buffer[4] = CCREP_RCON;
+               rcon_redirect_buffer[4] = (char)CCREP_RCON;
        }
        else
                memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print
@@ -1041,17 +1049,22 @@ Con_MaskPrint
 extern cvar_t timestamps;
 extern cvar_t timeformat;
 extern qboolean sys_nostdout;
+
+// -- Akari: attempted to make this somewhat thread safe.... works.... sometimes
+
+pthread_mutex_t con_print_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 void Con_MaskPrint(int additionalmask, const char *msg)
 {
        static int mask = 0;
        static int index = 0;
        static char line[MAX_INPUTLINE];
 
+       pthread_mutex_lock(&con_print_mutex);
+
        for (;*msg;msg++)
        {
                Con_Rcon_AddChar(*msg);
-               if (index == 0)
-                       mask |= additionalmask;
                // if this is the beginning of a new line, print timestamp
                if (index == 0)
                {
@@ -1096,6 +1109,8 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                        for (;*timestamp;index++, timestamp++)
                                if (index < (int)sizeof(line) - 2)
                                        line[index] = *timestamp;
+                       // add the mask
+                       mask |= additionalmask;
                }
                // append the character
                line[index++] = *msg;
@@ -1110,16 +1125,29 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                        if (con_initialized && cls.state != ca_dedicated)
                        {
                                Con_PrintToHistory(line, mask);
-                               mask = 0;
                        }
                        // send to terminal or dedicated server window
                        if (!sys_nostdout)
+                       if (developer.integer || !(mask & CON_MASK_DEVELOPER))
                        {
-                               unsigned char *p;
                                if(sys_specialcharactertranslation.integer)
                                {
-                                       for (p = (unsigned char *) line;*p; p++)
-                                               *p = qfont_table[*p];
+                                       char *p;
+                                       const char *q;
+                                       p = line;
+                                       while(*p)
+                                       {
+                                               int ch = u8_getchar(p, &q);
+                                               if(ch >= 0xE000 && ch <= 0xE0FF)
+                                               {
+                                                       *p = qfont_table[ch - 0xE000];
+                                                       if(q > p+1)
+                                                               memmove(p+1, q, strlen(q)+1);
+                                                       p = p + 1;
+                                               }
+                                               else
+                                                       p = p + (q - p);
+                                       }
                                }
 
                                if(sys_colortranslation.integer == 1) // ANSI
@@ -1297,8 +1325,11 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                        }
                        // empty the line buffer
                        index = 0;
+                       mask = 0;
                }
        }
+       
+       pthread_mutex_unlock(&con_print_mutex);
 }
 
 /*
@@ -1722,11 +1753,20 @@ void Con_DrawNotify (void)
 
                // LordHavoc: speedup, and other improvements
                if (chat_mode < 0)
-                       dpsnprintf(temptext, sizeof(temptext), "]%s%s", chat_buffer, cursor);
+                       dpsnprintf(temptext, sizeof(temptext), "]%s%c", chat_buffer, cursor);
+               else if(chat_mode == 2)
+               {
+                       if(chat_buffer[0] == '#' || chat_buffer[0] == '&') //Channels are yellow, nicks are green
+                               dpsnprintf(temptext, sizeof(temptext), "(IRC)target:^3%s^7%c", chat_buffer, cursor);
+                       else
+                               dpsnprintf(temptext, sizeof(temptext), "(IRC)target:^2%s^7%c", chat_buffer, cursor);
+               }
+               else if(chat_mode == 3)
+                       dpsnprintf(temptext, sizeof(temptext), "(IRC)message:%s%c", chat_buffer, cursor);
                else if(chat_mode)
-                       dpsnprintf(temptext, sizeof(temptext), "say_team:%s%s", chat_buffer, cursor);
+                       dpsnprintf(temptext, sizeof(temptext), "say_team:%s%c", chat_buffer, cursor);
                else
-                       dpsnprintf(temptext, sizeof(temptext), "say:%s%s", chat_buffer, cursor);
+                       dpsnprintf(temptext, sizeof(temptext), "say:%s%c", chat_buffer, cursor);
 
                // FIXME word wrap
                inputsize = (numChatlines ? con_chatsize : con_notifysize).value;
@@ -2808,11 +2848,11 @@ void Con_CompleteCommandLine (void)
                                        }
                                        else
                                        {
-                                               stringlistsort(&resultbuf); // dirbuf is already sorted
+                                               stringlistsort(&resultbuf, true); // dirbuf is already sorted
                                                Con_Printf("\n%i possible filenames\n", resultbuf.numstrings + dirbuf.numstrings);
                                                for(i = 0; i < dirbuf.numstrings; ++i)
                                                {
-                                                       Con_Printf("%s/\n", dirbuf.strings[i]);
+                                                       Con_Printf("^4%s^7/\n", dirbuf.strings[i]);
                                                }
                                                for(i = 0; i < resultbuf.numstrings; ++i)
                                                {