diff options
author | Amos <48657826+Mauler125@users.noreply.github.com> | 2022-03-04 02:20:28 +0100 |
---|---|---|
committer | Amos <48657826+Mauler125@users.noreply.github.com> | 2022-03-04 02:20:28 +0100 |
commit | 60d1b4805f1e199d01229cc7f60dcc22ef9387b8 (patch) | |
tree | abaea391be987f89ad045dee6b09883627be985d /NetConsole | |
parent | 4b8bdb0077f95d344df27d5c22e42637958384c5 (diff) | |
download | NorthstarLauncher-60d1b4805f1e199d01229cc7f60dcc22ef9387b8.tar.gz NorthstarLauncher-60d1b4805f1e199d01229cc7f60dcc22ef9387b8.zip |
Fix formatting
Diffstat (limited to 'NetConsole')
-rw-r--r-- | NetConsole/netconsole.cpp | 98 | ||||
-rw-r--r-- | NetConsole/netconsole.h | 14 |
2 files changed, 51 insertions, 61 deletions
diff --git a/NetConsole/netconsole.cpp b/NetConsole/netconsole.cpp index 210de097..cfdd31e1 100644 --- a/NetConsole/netconsole.cpp +++ b/NetConsole/netconsole.cpp @@ -1,10 +1,9 @@ //=====================================================================================// -// +// // Purpose: Lightweight netconsole client. -// +// //=====================================================================================// - #include "pch.h" #include "NetAdr2.h" #include "socketcreator.h" @@ -94,10 +93,7 @@ void CNetCon::UserInput(void) return; } size_t nPos = svInput.find(" "); - if (!svInput.empty() - && nPos > 0 - && nPos < svInput.size() - && nPos != svInput.size()) + 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(" ")); @@ -122,10 +118,7 @@ void CNetCon::UserInput(void) else // Setup connection from input. { size_t nPos = svInput.find(" "); - if (!svInput.empty() - && nPos > 0 - && nPos < svInput.size() - && nPos != svInput.size()) + if (!svInput.empty() && nPos > 0 && nPos < svInput.size() && nPos != svInput.size()) { std::string svInPort = svInput.substr(nPos + 1); std::string svInAdr = svInput.erase(svInput.find(" ")); @@ -172,15 +165,12 @@ void CNetCon::RunFrame(void) // Purpose: checks if application should be terminated // Output : true for termination, false otherwise //----------------------------------------------------------------------------- -bool CNetCon::ShouldQuit(void) const -{ - return this->m_bQuitApplication; -} +bool CNetCon::ShouldQuit(void) const { return this->m_bQuitApplication; } //----------------------------------------------------------------------------- // Purpose: connect to specified address and port -// Input : *svInAdr - -// *svInPort - +// Input : *svInAdr - +// *svInPort - // Output : true if connection succeeds, false otherwise //----------------------------------------------------------------------------- bool CNetCon::Connect(const std::string& svInAdr, const std::string& svInPort) @@ -208,13 +198,13 @@ bool CNetCon::Connect(const std::string& svInAdr, const std::string& svInPort) void CNetCon::Disconnect(void) { ::closesocket(m_pSocket->GetAcceptedSocketHandle(0)); - m_abPromptConnect = true; + m_abPromptConnect = true; m_abConnEstablished = false; } //----------------------------------------------------------------------------- // Purpose: send message -// Input : *svMessage - +// Input : *svMessage - //----------------------------------------------------------------------------- void CNetCon::Send(const std::string& svMessage) const { @@ -232,7 +222,7 @@ void CNetCon::Recv(void) { static char szRecvBuf[MAX_NETCONSOLE_INPUT_LEN]{}; - {////////////////////////////////////////////// + { ////////////////////////////////////////////// int nPendingLen = ::recv(m_pSocket->GetAcceptedSocketData(0)->m_hSocket, szRecvBuf, sizeof(szRecvBuf), MSG_PEEK); if (nPendingLen == SOCKET_ERROR && m_pSocket->IsSocketBlocking()) { @@ -244,7 +234,7 @@ void CNetCon::Recv(void) spdlog::info("Server closed connection"); return; } - }////////////////////////////////////////////// + } ////////////////////////////////////////////// u_long nReadLen; // Find out how much we have to read. ::ioctlsocket(m_pSocket->GetAcceptedSocketData(0)->m_hSocket, FIONREAD, &nReadLen); @@ -272,8 +262,8 @@ void CNetCon::Recv(void) //----------------------------------------------------------------------------- // Purpose: handles input response buffer -// Input : *pszIn - -// nRecvLen - +// Input : *pszIn - +// nRecvLen - //----------------------------------------------------------------------------- void CNetCon::ProcessBuffer(const char* pszIn, int nRecvLen) const { @@ -311,32 +301,32 @@ void CNetCon::ProcessBuffer(const char* pszIn, int nRecvLen) const //----------------------------------------------------------------------------- // Purpose: processes received message -// Input : *sv_response - +// Input : *sv_response - //----------------------------------------------------------------------------- void CNetCon::ProcessMessage(const sv_rcon::response& sv_response) const { switch (sv_response.responsetype()) { - case sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH: - case sv_rcon::response_t::SERVERDATA_RESPONSE_CONSOLE_LOG: - { - std::string svOut = sv_response.responsebuf(); - svOut.erase(std::remove(svOut.begin(), svOut.end(), '\n'), svOut.end()); - spdlog::info(svOut.c_str()); - break; - } - default: - { - break; - } + case sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH: + case sv_rcon::response_t::SERVERDATA_RESPONSE_CONSOLE_LOG: + { + std::string svOut = sv_response.responsebuf(); + svOut.erase(std::remove(svOut.begin(), svOut.end(), '\n'), svOut.end()); + spdlog::info(svOut.c_str()); + break; + } + default: + { + break; + } } } //----------------------------------------------------------------------------- // Purpose: serializes input -// Input : *svReqBuf - -// *svReqVal - -// request_t - +// Input : *svReqBuf - +// *svReqVal - +// request_t - // Output : serialized results as string //----------------------------------------------------------------------------- std::string CNetCon::Serialize(const std::string& svReqBuf, const std::string& svReqVal, cl_rcon::request_t request_t) const @@ -348,25 +338,25 @@ std::string CNetCon::Serialize(const std::string& svReqBuf, const std::string& s switch (request_t) { - case cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE: - case cl_rcon::request_t::SERVERDATA_REQUEST_AUTH: - { - cl_request.set_requestbuf(svReqBuf); - cl_request.set_requestval(svReqVal); - break; - } - case cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND: - { - cl_request.set_requestbuf(svReqBuf); - break; - } + case cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE: + case cl_rcon::request_t::SERVERDATA_REQUEST_AUTH: + { + cl_request.set_requestbuf(svReqBuf); + cl_request.set_requestval(svReqVal); + break; + } + case cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND: + { + cl_request.set_requestbuf(svReqBuf); + break; + } } return cl_request.SerializeAsString().append("\r"); } //----------------------------------------------------------------------------- // Purpose: de-serializes input -// Input : *svBuf - +// Input : *svBuf - // Output : de-serialized object //----------------------------------------------------------------------------- sv_rcon::response CNetCon::Deserialize(const std::string& svBuf) const @@ -379,8 +369,8 @@ sv_rcon::response CNetCon::Deserialize(const std::string& svBuf) const //----------------------------------------------------------------------------- // Purpose: entrypoint -// Input : argc - -// *argv - +// Input : argc - +// *argv - //----------------------------------------------------------------------------- int main(int argc, char* argv[]) { diff --git a/NetConsole/netconsole.h b/NetConsole/netconsole.h index a777a27e..3c35c3e1 100644 --- a/NetConsole/netconsole.h +++ b/NetConsole/netconsole.h @@ -1,6 +1,6 @@ //===========================================================================// // -// Purpose: +// Purpose: // //===========================================================================// #pragma once @@ -11,7 +11,7 @@ constexpr const char* NETCON_VERSION = "2.0.0.1"; class CNetCon { -public: + public: bool Init(void); bool Shutdown(void); @@ -33,12 +33,12 @@ public: std::string Serialize(const std::string& svReqBuf, const std::string& svReqVal, cl_rcon::request_t request_t) const; sv_rcon::response Deserialize(const std::string& svBuf) const; -private: + private: CNetAdr2* m_pNetAdr2 = new CNetAdr2("localhost", "37015"); CSocketCreator* m_pSocket = new CSocketCreator(); - bool m_bInitialized = false; - bool m_bQuitApplication = false; - std::atomic<bool> m_abPromptConnect{ true }; - std::atomic<bool> m_abConnEstablished{ false }; + bool m_bInitialized = false; + bool m_bQuitApplication = false; + std::atomic<bool> m_abPromptConnect{true}; + std::atomic<bool> m_abConnEstablished{false}; };
\ No newline at end of file |