Improve RCON system

* Buffers are now send properly from the game client and netconsole client (running scripts and executing command's/convar's now work properly).
* Removed 'PASS' string check on server and only rely on 'SERVERDATA_REQUEST_AUTH' enum for auth queries (should make heavy abuse even harder).
This commit is contained in:
Kawe Mazidjatari 2022-05-07 03:06:19 +02:00
parent 43cb013358
commit 57e6dc4280
3 changed files with 43 additions and 71 deletions

View File

@ -237,9 +237,9 @@ void CRConServer::Authenticate(const cl_rcon::request& cl_request, CConnectedNet
{
return;
}
else if (strcmp(cl_request.requestbuf().c_str(), "PASS") == 0)
else
{
if (this->Comparator(cl_request.requestval()))
if (this->Comparator(cl_request.requestbuf()))
{
pData->m_bAuthorized = true;
m_pSocket->CloseListenSocket();
@ -386,9 +386,7 @@ void CRConServer::Execute(const cl_rcon::request& cl_request) const
}
else // Execute command with "<val>".
{
std::string svExec = cl_request.requestbuf() + " \"" + cl_request.requestval() + "\"";
Cbuf_AddText(Cbuf_GetCurrentPlayer(), svExec.c_str(), cmd_source_t::kCommandSrcCode);
Cbuf_AddText(Cbuf_GetCurrentPlayer(), cl_request.requestbuf().c_str(), cmd_source_t::kCommandSrcCode);
Cbuf_Execute();
}
}

View File

@ -119,24 +119,25 @@ void CNetCon::UserInput(void)
&& nPos < svInput.size()
&& nPos != svInput.size())
{
std::string svReqVal = svInput.substr(nPos + 1);
std::string svReqBuf = svInput.erase(svInput.find(" "));
std::string svSecondArg = svInput.substr(nPos + 1);
std::string svFirstArg = svInput;
svFirstArg = svFirstArg.erase(svFirstArg.find(" "));
if (strcmp(svReqBuf.c_str(), "PASS") == 0) // Auth with RCON server.
if (strcmp(svFirstArg.c_str(), "PASS") == 0) // Auth with RCON server.
{
std::string svSerialized = this->Serialize(svReqBuf, svReqVal, cl_rcon::request_t::SERVERDATA_REQUEST_AUTH);
std::string svSerialized = this->Serialize(svSecondArg, "", cl_rcon::request_t::SERVERDATA_REQUEST_AUTH);
this->Send(svSerialized);
}
else // This is a ConVar.
else if (strcmp(svFirstArg.c_str(), "SET") == 0) // Set value query.
{
std::string svSerialized = this->Serialize(svReqBuf, svReqVal, cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE);
std::string svSerialized = this->Serialize(svFirstArg, svSecondArg, cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE);
this->Send(svSerialized);
}
else // Execute command query.
{
std::string svSerialized = this->Serialize(svInput.c_str(), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND);
this->Send(svSerialized);
}
}
else // This is a ConCommand.
{
std::string svSerialized = this->Serialize(svInput, "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND);
this->Send(svSerialized);
}
}
else // Setup connection from input.

View File

@ -646,72 +646,45 @@ _RCON_CmdQuery_f_CompletionFunc
*/
void _RCON_CmdQuery_f_CompletionFunc(const CCommand& args)
{
switch (args.ArgC())
if (args.ArgC() < 2)
{
case 0:
case 1:
if (g_pRConClient->IsInitialized()
&& !g_pRConClient->IsConnected()
&& strlen(rcon_address->GetString()) > 0)
{
if (g_pRConClient->IsInitialized()
&& !g_pRConClient->IsConnected()
&& strlen(rcon_address->GetString()) > 0)
{
g_pRConClient->Connect();
}
break;
g_pRConClient->Connect();
}
case 2:
}
else
{
if (!g_pRConClient->IsInitialized())
{
if (!g_pRConClient->IsInitialized())
{
Warning(eDLL_T::CLIENT, "Failed to issue command to RCON server: uninitialized\n");
break;
}
else if (g_pRConClient->IsConnected())
{
if (strcmp(args.Arg(1), "PASS") == 0) // Auth with RCON server using rcon_password ConVar value.
{
string svCmdQuery = g_pRConClient->Serialize(args.Arg(1), rcon_password->GetString(), cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND);
g_pRConClient->Send(svCmdQuery);
break;
}
else if (strcmp(args.Arg(1), "disconnect") == 0) // Disconnect from RCON server.
{
g_pRConClient->Disconnect();
break;
}
string svCmdQuery = g_pRConClient->Serialize(args.Arg(1), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND);
g_pRConClient->Send(svCmdQuery);
break;
}
else
{
Warning(eDLL_T::CLIENT, "Failed to issue command to RCON server: unconnected\n");
break;
}
break;
Warning(eDLL_T::CLIENT, "Failed to issue command to RCON server: uninitialized\n");
return;
}
case 3:
else if (g_pRConClient->IsConnected())
{
if (g_pRConClient->IsConnected())
if (strcmp(args.Arg(1), "PASS") == 0) // Auth with RCON server using rcon_password ConVar value.
{
if (strcmp(args.Arg(1), "PASS") == 0) // Auth with RCON server.
{
string svCmdQuery = g_pRConClient->Serialize(args.Arg(1), args.Arg(2), cl_rcon::request_t::SERVERDATA_REQUEST_AUTH);
g_pRConClient->Send(svCmdQuery);
break;
}
string svCmdQuery = g_pRConClient->Serialize(args.Arg(1), args.Arg(2), cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE);
string svCmdQuery = g_pRConClient->Serialize(rcon_password->GetString(), "", cl_rcon::request_t::SERVERDATA_REQUEST_AUTH);
g_pRConClient->Send(svCmdQuery);
break;
return;
}
else
else if (strcmp(args.Arg(1), "disconnect") == 0) // Disconnect from RCON server.
{
Warning(eDLL_T::CLIENT, "Failed to issue command to RCON server: unconnected\n");
break;
g_pRConClient->Disconnect();
return;
}
break;
string svCmdQuery = g_pRConClient->Serialize(args.ArgS(), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND);
g_pRConClient->Send(svCmdQuery);
return;
}
else
{
Warning(eDLL_T::CLIENT, "Failed to issue command to RCON server: unconnected\n");
return;
}
}
}