]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - console.c
crypto: avoid generating control-like packets
[xonotic/darkplaces.git] / console.c
index 3ce37373d3067e5c1e017266b6176344529a8897..ae73809b9d8decedd2274775a520f37f270a88bb 100644 (file)
--- a/console.c
+++ b/console.c
@@ -93,6 +93,7 @@ lhnetsocket_t *rcon_redirect_sock = NULL;
 lhnetaddress_t *rcon_redirect_dest = NULL;
 int rcon_redirect_bufferpos = 0;
 char rcon_redirect_buffer[1400];
+qboolean rcon_redirect_proquakeprotocol = false;
 
 // generic functions for console buffers
 
@@ -125,8 +126,10 @@ ConBuffer_Shutdown
 void ConBuffer_Shutdown(conbuffer_t *buf)
 {
        buf->active = false;
-       Mem_Free(buf->text);
-       Mem_Free(buf->lines);
+       if (buf->text)
+               Mem_Free(buf->text);
+       if (buf->lines)
+               Mem_Free(buf->lines);
        buf->text = NULL;
        buf->lines = NULL;
 }
@@ -885,20 +888,38 @@ static char qfont_table[256] = {
        'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<'
 };
 
-void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest)
+void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest, qboolean proquakeprotocol)
 {
        rcon_redirect_sock = sock;
        rcon_redirect_dest = dest;
-       memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print
+       rcon_redirect_proquakeprotocol = proquakeprotocol;
+       if (rcon_redirect_proquakeprotocol)
+       {
+               // reserve space for the packet header
+               rcon_redirect_buffer[0] = 0;
+               rcon_redirect_buffer[1] = 0;
+               rcon_redirect_buffer[2] = 0;
+               rcon_redirect_buffer[3] = 0;
+               // this is a reply to a CCREQ_RCON
+               rcon_redirect_buffer[4] = (char)CCREP_RCON;
+       }
+       else
+               memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print
        rcon_redirect_bufferpos = 5;
 }
 
 void Con_Rcon_Redirect_Flush(void)
 {
        rcon_redirect_buffer[rcon_redirect_bufferpos] = 0;
-       NetConn_WriteString(rcon_redirect_sock, rcon_redirect_buffer, rcon_redirect_dest);
+       if (rcon_redirect_proquakeprotocol)
+       {
+               // update the length in the packet header
+               StoreBigLong((unsigned char *)rcon_redirect_buffer, NETFLAG_CTL | (rcon_redirect_bufferpos & NETFLAG_LENGTH_MASK));
+       }
+       NetConn_Write(rcon_redirect_sock, rcon_redirect_buffer, rcon_redirect_bufferpos, rcon_redirect_dest);
        memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print
        rcon_redirect_bufferpos = 5;
+       rcon_redirect_proquakeprotocol = false;
 }
 
 void Con_Rcon_Redirect_End(void)
@@ -1029,8 +1050,6 @@ void Con_MaskPrint(int additionalmask, const char *msg)
        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)
                {
@@ -1049,7 +1068,7 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                                {
                                        if (con_chatsound.value)
                                        {
-                                               if(gamemode == GAME_NEXUIZ)
+                                               if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                                                {
                                                        if(msg[1] == '\r' && cl.foundtalk2wav)
                                                                S_LocalSound ("sound/misc/talk2.wav");
@@ -1075,6 +1094,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;
@@ -1089,16 +1110,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
@@ -1276,6 +1310,7 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                        }
                        // empty the line buffer
                        index = 0;
+                       mask = 0;
                }
        }
 }
@@ -2791,7 +2826,7 @@ void Con_CompleteCommandLine (void)
                                                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)
                                                {