diff options
-rw-r--r-- | NetConsole/netconsole.cpp | 22 | ||||
-rw-r--r-- | NorthstarDedicatedTest/rcon_shared.cpp | 48 | ||||
-rw-r--r-- | NorthstarDedicatedTest/sv_rcon.cpp | 7 |
3 files changed, 27 insertions, 50 deletions
diff --git a/NetConsole/netconsole.cpp b/NetConsole/netconsole.cpp index cfdd31e1..3a59c5be 100644 --- a/NetConsole/netconsole.cpp +++ b/NetConsole/netconsole.cpp @@ -95,23 +95,29 @@ void CNetCon::UserInput(void) size_t nPos = svInput.find(" "); if (!svInput.empty() && nPos > 0 && 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. + else // Single arg command query. { - std::string svSerialized = this->Serialize(svInput, "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); + std::string svSerialized = this->Serialize(svInput.c_str(), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); this->Send(svSerialized); } } diff --git a/NorthstarDedicatedTest/rcon_shared.cpp b/NorthstarDedicatedTest/rcon_shared.cpp index bfac496c..86892ea8 100644 --- a/NorthstarDedicatedTest/rcon_shared.cpp +++ b/NorthstarDedicatedTest/rcon_shared.cpp @@ -30,72 +30,44 @@ void _RCON_CmdQuery_f(const CCommand& args) return; } - switch (args.ArgC()) + if (args.ArgC() < 2) { - case 0: - case 1: - { - if (g_pRConClient->IsInitialized() && !g_pRConClient->IsConnected() && strlen(CVar_rcon_address->GetString()) > 0) + if (g_pRConClient->IsInitialized() && !g_pRConClient->IsConnected() && strlen(CVar_rcon_password->GetString()) > 0) { g_pRConClient->Connect(); } - break; } - case 2: + else { if (!g_pRConClient->IsInitialized()) { spdlog::warn("Failed to issue command to RCON server: uninitialized\n"); - break; + return; } else if (g_pRConClient->IsConnected()) { if (strcmp(args.Arg(1), "PASS") == 0) // Auth with RCON server using rcon_password ConVar value. { std::string svCmdQuery = - g_pRConClient->Serialize(args[1], CVar_rcon_password->GetString(), cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); + g_pRConClient->Serialize(CVar_rcon_password->GetString(), "", cl_rcon::request_t::SERVERDATA_REQUEST_AUTH); g_pRConClient->Send(svCmdQuery); - break; + return; } else if (strcmp(args.Arg(1), "disconnect") == 0) // Disconnect from RCON server. { g_pRConClient->Disconnect(); - break; + return; } - std::string svCmdQuery = g_pRConClient->Serialize(args.Arg(1), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); + std::string svCmdQuery = g_pRConClient->Serialize(args.ArgS(), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); g_pRConClient->Send(svCmdQuery); - break; + return; } else { spdlog::warn("Failed to issue command to RCON server: unconnected\n"); - break; + return; } - break; - } - case 3: - { - if (g_pRConClient->IsConnected()) - { - if (strcmp(args[1], "PASS") == 0) // Auth with RCON server. - { - std::string svCmdQuery = g_pRConClient->Serialize(args.Arg(1), args.Arg(2), cl_rcon::request_t::SERVERDATA_REQUEST_AUTH); - g_pRConClient->Send(svCmdQuery); - break; - } - - std::string svCmdQuery = g_pRConClient->Serialize(args.Arg(1), args.Arg(2), cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE); - g_pRConClient->Send(svCmdQuery); - break; - } - else - { - spdlog::warn("Failed to issue command to RCON server: unconnected\n"); - break; - } - break; - } } } diff --git a/NorthstarDedicatedTest/sv_rcon.cpp b/NorthstarDedicatedTest/sv_rcon.cpp index 271361be..ec2abfca 100644 --- a/NorthstarDedicatedTest/sv_rcon.cpp +++ b/NorthstarDedicatedTest/sv_rcon.cpp @@ -240,9 +240,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(); @@ -388,8 +388,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(); } } |