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
'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] = 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;
+ 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_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;
+ rcon_redirect_proquakeprotocol = false;
}
void Con_Rcon_Redirect_End(void)
return va("%srcon", restricted ? "restricted " : "");
}
-void RCon_Execute(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress, const char *addressstring2, const char *userlevel, const char *s, const char *endpos)
+void RCon_Execute(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress, const char *addressstring2, const char *userlevel, const char *s, const char *endpos, qboolean proquakeprotocol)
{
if(userlevel)
{
Con_Printf("\n");
if (!host_client || !host_client->netconnection || LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
- Con_Rcon_Redirect_Init(mysocket, peeraddress);
+ Con_Rcon_Redirect_Init(mysocket, peeraddress, proquakeprotocol);
while(s != endpos)
{
size_t l = strlen(s);
++s;
userlevel = RCon_Authenticate(peeraddress, password, s, endpos, hmac_mdfour_time_matching, timeval, endpos - timeval - 1); // not including the appended \0 into the HMAC
- RCon_Execute(mysocket, peeraddress, addressstring2, userlevel, s, endpos);
+ RCon_Execute(mysocket, peeraddress, addressstring2, userlevel, s, endpos, false);
return true;
}
if (length >= 42 && !memcmp(string, "srcon HMAC-MD4 CHALLENGE ", 25))
++s;
userlevel = RCon_Authenticate(peeraddress, password, s, endpos, hmac_mdfour_challenge_matching, challenge, endpos - challenge - 1); // not including the appended \0 into the HMAC
- RCon_Execute(mysocket, peeraddress, addressstring2, userlevel, s, endpos);
+ RCon_Execute(mysocket, peeraddress, addressstring2, userlevel, s, endpos, false);
return true;
}
if (length >= 5 && !memcmp(string, "rcon ", 5))
if (!ISWHITESPACE(password[0]))
{
const char *userlevel = RCon_Authenticate(peeraddress, password, s, endpos, plaintext_matching, NULL, 0);
- RCon_Execute(mysocket, peeraddress, addressstring2, userlevel, s, endpos);
+ RCon_Execute(mysocket, peeraddress, addressstring2, userlevel, s, endpos, false);
}
return true;
}
SZ_Clear(&net_message);
}
break;
+ case CCREQ_RCON:
+ if (developer_extra.integer)
+ Con_DPrintf("Datagram_ParseConnectionless: received CCREQ_RCON from %s.\n", addressstring2);
+ if (sv.active && !rcon_secure.integer)
+ {
+ char password[2048];
+ char cmd[2048];
+ char *s;
+ char *endpos;
+ const char *userlevel;
+ strlcpy(password, MSG_ReadString(), sizeof(password));
+ strlcpy(cmd, MSG_ReadString(), sizeof(cmd));
+ s = cmd;
+ endpos = cmd + strlen(cmd) + 1; // one behind the NUL, so adding strlen+1 will eventually reach it
+ userlevel = RCon_Authenticate(peeraddress, password, s, endpos, plaintext_matching, NULL, 0);
+ RCon_Execute(mysocket, peeraddress, addressstring2, userlevel, s, endpos, true);
+ return true;
+ }
+ break;
default:
break;
}