qboolean con_initialized;
// used for server replies to rcon command
-qboolean rcon_redirect = false;
+lhnetsocket_t *rcon_redirect_sock = NULL;
+lhnetaddress_t *rcon_redirect_dest = NULL;
int rcon_redirect_bufferpos = 0;
char rcon_redirect_buffer[1400];
'x', 'y', 'z', '{', '|', '}', '~', '<'
};
+void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest)
+{
+ rcon_redirect_sock = sock;
+ rcon_redirect_dest = dest;
+ memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print
+ rcon_redirect_bufferpos = 5;
+}
+
+void Con_Rcon_Redirect_Flush()
+{
+ rcon_redirect_buffer[rcon_redirect_bufferpos] = 0;
+ NetConn_WriteString(rcon_redirect_sock, rcon_redirect_buffer, rcon_redirect_dest);
+ memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print
+ rcon_redirect_bufferpos = 5;
+}
+
+void Con_Rcon_Redirect_End()
+{
+ Con_Rcon_Redirect_Flush();
+ rcon_redirect_dest = NULL;
+ rcon_redirect_sock = NULL;
+}
+
+void Con_Rcon_Redirect_Abort()
+{
+ rcon_redirect_dest = NULL;
+ rcon_redirect_sock = NULL;
+}
+
/*
================
Con_Rcon_AddChar
// if this print is in response to an rcon command, add the character
// to the rcon redirect buffer
- if (rcon_redirect && rcon_redirect_bufferpos < (int)sizeof(rcon_redirect_buffer) - 1)
+ if (rcon_redirect_dest)
+ {
rcon_redirect_buffer[rcon_redirect_bufferpos++] = c;
+ if(rcon_redirect_bufferpos >= (int)sizeof(rcon_redirect_buffer) - 1)
+ Con_Rcon_Redirect_Flush();
+ }
else if(*log_dest_udp.string) // don't duplicate rcon command responses here, these are sent another way
{
if(log_dest_buffer_pos == 0)
extern int con_backscroll;
extern qboolean con_initialized;
-extern qboolean rcon_redirect;
-extern int rcon_redirect_bufferpos;
-extern char rcon_redirect_buffer[1400];
+void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest);
+void Con_Rcon_Redirect_End();
+void Con_Rcon_Redirect_Abort();
void Con_CheckResize (void);
void Con_Init (void);
s_ptr += l + 1;
}
Con_Printf("\n");
- rcon_redirect = true;
- rcon_redirect_bufferpos = 0;
+
+ if (!host_client || !host_client->netconnection || LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
+ Con_Rcon_Redirect_Init(mysocket, peeraddress);
while(s != endpos)
{
size_t l = strlen(s);
}
s += l + 1;
}
- rcon_redirect_buffer[rcon_redirect_bufferpos] = 0;
- rcon_redirect = false;
- // print resulting text to client
- // if client is playing, send a reliable reply instead of
- // a command packet
- if (host_client)
- {
- // if the netconnection is loop, then this is the
- // local player on a listen mode server, and it would
- // result in duplicate printing to the console
- // (not that the local player should be using rcon
- // when they have the console)
- if (host_client->netconnection && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
- SV_ClientPrintf("%s", rcon_redirect_buffer);
- }
- else
- {
- // qw print command
- dpsnprintf(response, sizeof(response), "\377\377\377\377n%s", rcon_redirect_buffer);
- NetConn_WriteString(mysocket, response, peeraddress);
- }
+ Con_Rcon_Redirect_End();
}
else
{