diff options
author | Amos <48657826+Mauler125@users.noreply.github.com> | 2022-03-04 02:26:59 +0100 |
---|---|---|
committer | Amos <48657826+Mauler125@users.noreply.github.com> | 2022-03-04 02:26:59 +0100 |
commit | 5fb1eee4725c7aa0002411eafbc0a1a94fa073b3 (patch) | |
tree | f6e1f58d74b1ae7508f612bbf41aba1e7473fb42 /NorthstarDedicatedTest | |
parent | 60d1b4805f1e199d01229cc7f60dcc22ef9387b8 (diff) | |
download | NorthstarLauncher-5fb1eee4725c7aa0002411eafbc0a1a94fa073b3.tar.gz NorthstarLauncher-5fb1eee4725c7aa0002411eafbc0a1a94fa073b3.zip |
Fix formatting
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r-- | NorthstarDedicatedTest/cl_rcon.cpp | 43 | ||||
-rw-r--r-- | NorthstarDedicatedTest/cl_rcon.h | 5 | ||||
-rw-r--r-- | NorthstarDedicatedTest/rcon_shared.cpp | 11 | ||||
-rw-r--r-- | NorthstarDedicatedTest/sha256.h | 84 | ||||
-rw-r--r-- | NorthstarDedicatedTest/sv_rcon.cpp | 120 | ||||
-rw-r--r-- | NorthstarDedicatedTest/sv_rcon.h | 22 |
6 files changed, 134 insertions, 151 deletions
diff --git a/NorthstarDedicatedTest/cl_rcon.cpp b/NorthstarDedicatedTest/cl_rcon.cpp index 00353a18..28c36353 100644 --- a/NorthstarDedicatedTest/cl_rcon.cpp +++ b/NorthstarDedicatedTest/cl_rcon.cpp @@ -1,7 +1,7 @@ //===========================================================================// -// +// // Purpose: Implementation of the rcon client. -// +// //===========================================================================// #include "pch.h" @@ -17,10 +17,7 @@ //----------------------------------------------------------------------------- // Purpose: NETCON systems init //----------------------------------------------------------------------------- -void CRConClient::Init(void) -{ - m_bInitialized = true; -} +void CRConClient::Init(void) { m_bInitialized = true; } //----------------------------------------------------------------------------- // Purpose: NETCON systems shutdown @@ -69,8 +66,8 @@ bool CRConClient::Connect(void) //----------------------------------------------------------------------------- // Purpose: connect to specified address and port -// Input : *svInAdr - -// *svInPort - +// Input : *svInAdr - +// *svInPort - // Output : true if connection succeeds, false otherwise //----------------------------------------------------------------------------- bool CRConClient::Connect(const std::string& svInAdr, const std::string& svInPort) @@ -103,7 +100,7 @@ void CRConClient::Disconnect(void) //----------------------------------------------------------------------------- // Purpose: send message -// Input : *svMessage - +// Input : *svMessage - //----------------------------------------------------------------------------- void CRConClient::Send(const std::string& svMessage) const { @@ -121,7 +118,7 @@ void CRConClient::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()) { @@ -133,7 +130,7 @@ void CRConClient::Recv(void) spdlog::info("Server closed RCON connection"); return; } - }////////////////////////////////////////////// + } ////////////////////////////////////////////// u_long nReadLen; // Find out how much we have to read. ::ioctlsocket(m_pSocket->GetAcceptedSocketData(0)->m_hSocket, FIONREAD, &nReadLen); @@ -161,8 +158,8 @@ void CRConClient::Recv(void) //----------------------------------------------------------------------------- // Purpose: handles input response buffer -// Input : *pszIn - -// nRecvLen - +// Input : *pszIn - +// nRecvLen - //----------------------------------------------------------------------------- void CRConClient::ProcessBuffer(const char* pszIn, int nRecvLen) const { @@ -200,7 +197,7 @@ void CRConClient::ProcessBuffer(const char* pszIn, int nRecvLen) const //----------------------------------------------------------------------------- // Purpose: processes received message -// Input : *sv_response - +// Input : *sv_response - //----------------------------------------------------------------------------- void CRConClient::ProcessMessage(const sv_rcon::response& sv_response) const { @@ -230,9 +227,9 @@ void CRConClient::ProcessMessage(const sv_rcon::response& sv_response) const //----------------------------------------------------------------------------- // Purpose: serializes input -// Input : *svReqBuf - -// *svReqVal - -// request_t - +// Input : *svReqBuf - +// *svReqVal - +// request_t - // Output : serialized results as string //----------------------------------------------------------------------------- std::string CRConClient::Serialize(const std::string& svReqBuf, const std::string& svReqVal, cl_rcon::request_t request_t) const @@ -262,7 +259,7 @@ std::string CRConClient::Serialize(const std::string& svReqBuf, const std::strin //----------------------------------------------------------------------------- // Purpose: de-serializes input -// Input : *svBuf - +// Input : *svBuf - // Output : de-serialized object //----------------------------------------------------------------------------- sv_rcon::response CRConClient::Deserialize(const std::string& svBuf) const @@ -277,18 +274,12 @@ sv_rcon::response CRConClient::Deserialize(const std::string& svBuf) const // Purpose: checks if client rcon is initialized // Output : true if initialized, false otherwise //----------------------------------------------------------------------------- -bool CRConClient::IsInitialized(void) const -{ - return m_bInitialized; -} +bool CRConClient::IsInitialized(void) const { return m_bInitialized; } //----------------------------------------------------------------------------- // Purpose: checks if client rcon is connected // Output : true if connected, false otherwise //----------------------------------------------------------------------------- -bool CRConClient::IsConnected(void) const -{ - return m_bConnEstablished; -} +bool CRConClient::IsConnected(void) const { return m_bConnEstablished; } /////////////////////////////////////////////////////////////////////////////// CRConClient* g_pRConClient = new CRConClient(); diff --git a/NorthstarDedicatedTest/cl_rcon.h b/NorthstarDedicatedTest/cl_rcon.h index 956a9e22..e2b616b8 100644 --- a/NorthstarDedicatedTest/cl_rcon.h +++ b/NorthstarDedicatedTest/cl_rcon.h @@ -6,7 +6,7 @@ class CRConClient { -public: + public: CRConClient(void){}; ~CRConClient(void){}; @@ -31,12 +31,11 @@ public: bool IsInitialized(void) const; bool IsConnected(void) const; -private: + private: CNetAdr2* m_pNetAdr2 = new CNetAdr2("localhost", "37015"); CSocketCreator* m_pSocket = new CSocketCreator(); bool m_bInitialized = false; bool m_bConnEstablished = false; }; -void InitializeClientRcon(HMODULE baseAddress); extern CRConClient* g_pRConClient;
\ No newline at end of file diff --git a/NorthstarDedicatedTest/rcon_shared.cpp b/NorthstarDedicatedTest/rcon_shared.cpp index 25ad11c1..2b8797d1 100644 --- a/NorthstarDedicatedTest/rcon_shared.cpp +++ b/NorthstarDedicatedTest/rcon_shared.cpp @@ -132,17 +132,16 @@ void InitializeRconSystems(HMODULE baseAddress) CVar_sv_rcon_debug = new ConVar("sv_rcon_debug", "0", FCVAR_RELEASE, "Show rcon debug information ( !slower! ).", false, 0.f, false, 0.f, nullptr); CVar_sv_rcon_maxfailures = new ConVar( - "sv_rcon_maxfailures", "10", FCVAR_RELEASE, "Max number of times a user can fail rcon authentication before being banned.", - false, 0.f, false, 0.f, nullptr); + "sv_rcon_maxfailures", "10", FCVAR_RELEASE, "Max number of times a user can fail rcon authentication before being banned.", false, + 0.f, false, 0.f, nullptr); CVar_sv_rcon_maxignores = new ConVar( - "sv_rcon_maxignores", "15", FCVAR_RELEASE, "Max number of times a user can ignore the no-auth message before being banned.", - false, 0.f, false, 0.f, nullptr); + "sv_rcon_maxignores", "15", FCVAR_RELEASE, "Max number of times a user can ignore the no-auth message before being banned.", false, + 0.f, false, 0.f, nullptr); CVar_sv_rcon_maxsockets = new ConVar( "sv_rcon_maxsockets", "32", FCVAR_RELEASE, "Max number of accepted sockets before the server starts closing redundant sockets.", false, 0.f, false, 0.f, nullptr); CVar_sv_rcon_sendlogs = new ConVar( - "sv_rcon_sendlogs", "0", FCVAR_RELEASE, "If enabled, sends conlogs to connected netconsoles.", - false, 0.f, false, 0.f, nullptr); + "sv_rcon_sendlogs", "0", FCVAR_RELEASE, "If enabled, sends conlogs to connected netconsoles.", false, 0.f, false, 0.f, nullptr); CVar_sv_rcon_whitelist_address = new ConVar( "sv_rcon_whitelist_address", "", FCVAR_RELEASE, "This address is not considered a 'redundant' socket and will never be banned for failed authentications. Example: " diff --git a/NorthstarDedicatedTest/sha256.h b/NorthstarDedicatedTest/sha256.h index b6ef8bc1..dec51173 100644 --- a/NorthstarDedicatedTest/sha256.h +++ b/NorthstarDedicatedTest/sha256.h @@ -1,52 +1,50 @@ #ifndef SHA256_H #define SHA256_H - + class SHA256 { -protected: - typedef unsigned char uint8; - typedef unsigned int uint32; - typedef unsigned long long uint64; - - const static uint32 sha256_k[]; - static const unsigned int SHA224_256_BLOCK_SIZE = (512/8); -public: - void init(); - void update(const unsigned char *message, unsigned int len); - void final(unsigned char *digest); - static const unsigned int DIGEST_SIZE = ( 256 / 8); - -protected: - void transform(const unsigned char *message, unsigned int block_nb); - unsigned int m_tot_len; - unsigned int m_len; - unsigned char m_block[2*SHA224_256_BLOCK_SIZE]; - uint32 m_h[8]; + protected: + typedef unsigned char uint8; + typedef unsigned int uint32; + typedef unsigned long long uint64; + + const static uint32 sha256_k[]; + static const unsigned int SHA224_256_BLOCK_SIZE = (512 / 8); + + public: + void init(); + void update(const unsigned char* message, unsigned int len); + void final(unsigned char* digest); + static const unsigned int DIGEST_SIZE = (256 / 8); + + protected: + void transform(const unsigned char* message, unsigned int block_nb); + unsigned int m_tot_len; + unsigned int m_len; + unsigned char m_block[2 * SHA224_256_BLOCK_SIZE]; + uint32 m_h[8]; }; - + std::string sha256(std::string input); - -#define SHA2_SHFR(x, n) (x >> n) -#define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) -#define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) -#define SHA2_CH(x, y, z) ((x & y) ^ (~x & z)) + +#define SHA2_SHFR(x, n) (x >> n) +#define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) +#define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) +#define SHA2_CH(x, y, z) ((x & y) ^ (~x & z)) #define SHA2_MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) -#define SHA256_F1(x) (SHA2_ROTR(x, 2) ^ SHA2_ROTR(x, 13) ^ SHA2_ROTR(x, 22)) -#define SHA256_F2(x) (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25)) -#define SHA256_F3(x) (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3)) +#define SHA256_F1(x) (SHA2_ROTR(x, 2) ^ SHA2_ROTR(x, 13) ^ SHA2_ROTR(x, 22)) +#define SHA256_F2(x) (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25)) +#define SHA256_F3(x) (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3)) #define SHA256_F4(x) (SHA2_ROTR(x, 17) ^ SHA2_ROTR(x, 19) ^ SHA2_SHFR(x, 10)) -#define SHA2_UNPACK32(x, str) \ -{ \ - *((str) + 3) = (uint8) ((x) ); \ - *((str) + 2) = (uint8) ((x) >> 8); \ - *((str) + 1) = (uint8) ((x) >> 16); \ - *((str) + 0) = (uint8) ((x) >> 24); \ -} -#define SHA2_PACK32(str, x) \ -{ \ - *(x) = ((uint32) *((str) + 3) ) \ - | ((uint32) *((str) + 2) << 8) \ - | ((uint32) *((str) + 1) << 16) \ - | ((uint32) *((str) + 0) << 24); \ -} +#define SHA2_UNPACK32(x, str) \ + { \ + *((str) + 3) = (uint8)((x)); \ + *((str) + 2) = (uint8)((x) >> 8); \ + *((str) + 1) = (uint8)((x) >> 16); \ + *((str) + 0) = (uint8)((x) >> 24); \ + } +#define SHA2_PACK32(str, x) \ + { \ + *(x) = ((uint32) * ((str) + 3)) | ((uint32) * ((str) + 2) << 8) | ((uint32) * ((str) + 1) << 16) | ((uint32) * ((str) + 0) << 24); \ + } #endif diff --git a/NorthstarDedicatedTest/sv_rcon.cpp b/NorthstarDedicatedTest/sv_rcon.cpp index 7d81b887..936a7811 100644 --- a/NorthstarDedicatedTest/sv_rcon.cpp +++ b/NorthstarDedicatedTest/sv_rcon.cpp @@ -1,7 +1,7 @@ //===========================================================================// -// +// // Purpose: Implementation of the rcon server. -// +// //===========================================================================// #include "pch.h" @@ -104,7 +104,7 @@ void CRConServer::RunFrame(void) //----------------------------------------------------------------------------- // Purpose: send message -// Input : *svMessage - +// Input : *svMessage - //----------------------------------------------------------------------------- void CRConServer::Send(const std::string& svMessage) const { @@ -133,10 +133,10 @@ void CRConServer::Recv(void) for (m_nConnIndex = nCount - 1; m_nConnIndex >= 0; m_nConnIndex--) { CConnectedNetConsoleData* pData = m_pSocket->GetAcceptedSocketData(m_nConnIndex); - {////////////////////////////////////////////// + { ////////////////////////////////////////////// if (this->CheckForBan(pData)) { - std::string svNoAuth = this->Serialize(s_pszBannedMessage, "", sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH); + std::string svNoAuth = this->Serialize(s_pszBannedMessage, "", sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH); ::send(pData->m_hSocket, svNoAuth.c_str(), static_cast<int>(svNoAuth.size()), MSG_NOSIGNAL); this->CloseConnection(); continue; @@ -152,7 +152,7 @@ void CRConServer::Recv(void) this->CloseConnection(); continue; } - }////////////////////////////////////////////// + } ////////////////////////////////////////////// u_long nReadLen; // Find out how much we have to read. ::ioctlsocket(pData->m_hSocket, FIONREAD, &nReadLen); @@ -180,9 +180,9 @@ void CRConServer::Recv(void) //----------------------------------------------------------------------------- // Purpose: serializes input -// Input : *svRspBuf - -// *svRspVal - -// response_t - +// Input : *svRspBuf - +// *svRspVal - +// response_t - // Output : serialized results as string //----------------------------------------------------------------------------- std::string CRConServer::Serialize(const std::string& svRspBuf, const std::string& svRspVal, sv_rcon::response_t response_t) const @@ -194,28 +194,28 @@ std::string CRConServer::Serialize(const std::string& svRspBuf, const std::strin switch (response_t) { - case sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH: - { - sv_response.set_responsebuf(svRspBuf); - break; - } - case sv_rcon::response_t::SERVERDATA_RESPONSE_CONSOLE_LOG: - { - sv_response.set_responsebuf(svRspBuf); - sv_response.set_responseval(""); - break; - } - default: - { - break; - } + case sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH: + { + sv_response.set_responsebuf(svRspBuf); + break; + } + case sv_rcon::response_t::SERVERDATA_RESPONSE_CONSOLE_LOG: + { + sv_response.set_responsebuf(svRspBuf); + sv_response.set_responseval(""); + break; + } + default: + { + break; + } } return sv_response.SerializeAsString().append("\r"); } //----------------------------------------------------------------------------- // Purpose: de-serializes input -// Input : *svBuf - +// Input : *svBuf - // Output : de-serialized object //----------------------------------------------------------------------------- cl_rcon::request CRConServer::Deserialize(const std::string& svBuf) const @@ -228,8 +228,8 @@ cl_rcon::request CRConServer::Deserialize(const std::string& svBuf) const //----------------------------------------------------------------------------- // Purpose: authenticate new connections -// Input : *cl_request - -// *pData - +// Input : *cl_request - +// *pData - // Todo : implement logic for key exchange instead so we never network our // password in plain text over the wire. create a cvar for this so user could // also opt out and use legacy authentication instead for older RCON clients @@ -270,7 +270,7 @@ void CRConServer::Authenticate(const cl_rcon::request& cl_request, CConnectedNet //----------------------------------------------------------------------------- // Purpose: sha256 hashed password comparison -// Input : *svCompare - +// Input : *svCompare - // Output : true if matches, false otherwise //----------------------------------------------------------------------------- bool CRConServer::Comparator(std::string svPassword) const @@ -292,9 +292,9 @@ bool CRConServer::Comparator(std::string svPassword) const //----------------------------------------------------------------------------- // Purpose: handles input command buffer -// Input : *pszIn - -// nRecvLen - -// *pData - +// Input : *pszIn - +// nRecvLen - +// *pData - //----------------------------------------------------------------------------- void CRConServer::ProcessBuffer(const char* pszIn, int nRecvLen, CConnectedNetConsoleData* pData) { @@ -328,14 +328,13 @@ void CRConServer::ProcessBuffer(const char* pszIn, int nRecvLen, CConnectedNetCo //----------------------------------------------------------------------------- // Purpose: processes received message -// Input : *cl_request - +// Input : *cl_request - //----------------------------------------------------------------------------- void CRConServer::ProcessMessage(const cl_rcon::request& cl_request) { CConnectedNetConsoleData* pData = m_pSocket->GetAcceptedSocketData(m_nConnIndex); - if (!pData->m_bAuthorized - && cl_request.requesttype() != cl_rcon::request_t::SERVERDATA_REQUEST_AUTH) + if (!pData->m_bAuthorized && cl_request.requesttype() != cl_rcon::request_t::SERVERDATA_REQUEST_AUTH) { // Notify net console that authentication is required. std::string svMessage = this->Serialize(s_pszNoAuthMessage, "", sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH); @@ -346,39 +345,39 @@ void CRConServer::ProcessMessage(const cl_rcon::request& cl_request) } switch (cl_request.requesttype()) { - case cl_rcon::request_t::SERVERDATA_REQUEST_AUTH: - { - this->Authenticate(cl_request, pData); - break; - } - case cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND: - case cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE: - { - // Only execute if auth was succesfull. - if (pData->m_bAuthorized) - { - this->Execute(cl_request); - } - break; - } - case cl_rcon::request_t::SERVERDATA_REQUEST_SEND_CONSOLE_LOG: + case cl_rcon::request_t::SERVERDATA_REQUEST_AUTH: + { + this->Authenticate(cl_request, pData); + break; + } + case cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND: + case cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE: + { + // Only execute if auth was succesfull. + if (pData->m_bAuthorized) { - if (pData->m_bAuthorized) - { - CVar_sv_rcon_sendlogs->SetValue(1); - } - break; + this->Execute(cl_request); } - default: + break; + } + case cl_rcon::request_t::SERVERDATA_REQUEST_SEND_CONSOLE_LOG: + { + if (pData->m_bAuthorized) { - break; + CVar_sv_rcon_sendlogs->SetValue(1); } + break; + } + default: + { + break; + } } } //----------------------------------------------------------------------------- // Purpose: execute commands issued from net console -// Input : *cl_request - +// Input : *cl_request - //----------------------------------------------------------------------------- void CRConServer::Execute(const cl_rcon::request& cl_request) const { @@ -397,15 +396,14 @@ void CRConServer::Execute(const cl_rcon::request& cl_request) const //----------------------------------------------------------------------------- // Purpose: checks for amount of failed attempts and bans net console accordingly -// Input : *pData - +// Input : *pData - //----------------------------------------------------------------------------- bool CRConServer::CheckForBan(CConnectedNetConsoleData* pData) { CNetAdr2 netAdr2 = m_pSocket->GetAcceptedSocketAddress(m_nConnIndex); // Check if IP is in the ban vector. - if (std::find(m_vBannedAddress.begin(), m_vBannedAddress.end(), - netAdr2.GetIP(true)) != m_vBannedAddress.end()) + if (std::find(m_vBannedAddress.begin(), m_vBannedAddress.end(), netAdr2.GetIP(true)) != m_vBannedAddress.end()) { return true; } diff --git a/NorthstarDedicatedTest/sv_rcon.h b/NorthstarDedicatedTest/sv_rcon.h index 399d5f2e..23ca2118 100644 --- a/NorthstarDedicatedTest/sv_rcon.h +++ b/NorthstarDedicatedTest/sv_rcon.h @@ -5,14 +5,14 @@ #include "cl_rcon.pb.h" #include "igameserverdata.h" -constexpr char s_pszNoAuthMessage[] = "This server is password protected for console access. Must send 'PASS <password>' command.\n\r"; +constexpr char s_pszNoAuthMessage[] = "This server is password protected for console access. Must send 'PASS <password>' command.\n\r"; constexpr char s_pszWrongPwMessage[] = "Password incorrect.\n\r"; -constexpr char s_pszBannedMessage[] = "Go away.\n\r"; -constexpr char s_pszAuthMessage[] = "RCON authentication succesfull.\n\r"; +constexpr char s_pszBannedMessage[] = "Go away.\n\r"; +constexpr char s_pszAuthMessage[] = "RCON authentication succesfull.\n\r"; class CRConServer { -public: + public: void Init(void); void Shutdown(void); @@ -37,14 +37,12 @@ public: void CloseConnection(void); void CloseNonAuthConnection(void); -private: - - bool m_bInitialized = false; - int m_nConnIndex = 0; - CNetAdr2* m_pAdr2 = new CNetAdr2(); - CSocketCreator* m_pSocket = new CSocketCreator(); + private: + bool m_bInitialized = false; + int m_nConnIndex = 0; + CNetAdr2* m_pAdr2 = new CNetAdr2(); + CSocketCreator* m_pSocket = new CSocketCreator(); std::vector<std::string> m_vBannedAddress; - std::string m_svPasswordHash; + std::string m_svPasswordHash; }; -void InitializeServerRcon(HMODULE baseAddress); extern CRConServer* g_pRConServer;
\ No newline at end of file |