aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>2022-05-31 20:03:03 +0200
committerKawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>2022-05-31 20:03:03 +0200
commitd913256072999865140a5a82c969e5c55d8ca6b2 (patch)
treeda98fe79e8dc40291864a534f9ea0a1e9f7c182a
parent5c62807d6a3a2e9129df74693322220a61e21e66 (diff)
downloadNorthstarLauncher-d913256072999865140a5a82c969e5c55d8ca6b2.tar.gz
NorthstarLauncher-d913256072999865140a5a82c969e5c55d8ca6b2.zip
Light RCON cleanup
Use const qualifiers for CNetAdr2 methods. Removed redundant code in CNetAdr2. Add proper destructor for CRConServer, CRConClient and CNetCon.
-rw-r--r--NetConsole/netconsole.cpp9
-rw-r--r--NetConsole/netconsole.h2
-rw-r--r--NorthstarDedicatedTest/NetAdr2.cpp31
-rw-r--r--NorthstarDedicatedTest/NetAdr2.h6
-rw-r--r--NorthstarDedicatedTest/cl_rcon.cpp9
-rw-r--r--NorthstarDedicatedTest/cl_rcon.h2
-rw-r--r--NorthstarDedicatedTest/sv_rcon.cpp15
-rw-r--r--NorthstarDedicatedTest/sv_rcon.h4
8 files changed, 42 insertions, 36 deletions
diff --git a/NetConsole/netconsole.cpp b/NetConsole/netconsole.cpp
index 3a59c5be..4df47647 100644
--- a/NetConsole/netconsole.cpp
+++ b/NetConsole/netconsole.cpp
@@ -13,6 +13,15 @@
#include "netconsole.h"
//-----------------------------------------------------------------------------
+// Purpose: destructor
+//-----------------------------------------------------------------------------
+CNetCon::~CNetCon()
+{
+ delete m_pNetAdr2;
+ delete m_pSocket;
+}
+
+//-----------------------------------------------------------------------------
// Purpose: WSA and NETCON systems init
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
diff --git a/NetConsole/netconsole.h b/NetConsole/netconsole.h
index 3c35c3e1..dbd6eb2c 100644
--- a/NetConsole/netconsole.h
+++ b/NetConsole/netconsole.h
@@ -12,6 +12,8 @@ constexpr const char* NETCON_VERSION = "2.0.0.1";
class CNetCon
{
public:
+ ~CNetCon();
+
bool Init(void);
bool Shutdown(void);
diff --git a/NorthstarDedicatedTest/NetAdr2.cpp b/NorthstarDedicatedTest/NetAdr2.cpp
index 1a44390b..e493700f 100644
--- a/NorthstarDedicatedTest/NetAdr2.cpp
+++ b/NorthstarDedicatedTest/NetAdr2.cpp
@@ -11,7 +11,7 @@
// Purpose: constructor (use this when string contains <[IP]:PORT>).
// Input : svInAdr -
//-----------------------------------------------------------------------------
-CNetAdr2::CNetAdr2(std::string svInAdr)
+CNetAdr2::CNetAdr2(const std::string& svInAdr)
{
SetIPAndPort(svInAdr);
}
@@ -21,34 +21,9 @@ CNetAdr2::CNetAdr2(std::string svInAdr)
// Input : svInAdr -
// svInPort -
//-----------------------------------------------------------------------------
-CNetAdr2::CNetAdr2(std::string svInAdr, std::string svInPort)
+CNetAdr2::CNetAdr2(const std::string& svInAdr, const std::string& svInPort)
{
- SetType(netadrtype_t::NA_IP);
-
- if (strcmp(svInAdr.c_str(), "loopback") == 0 || strcmp(svInAdr.c_str(), "::1") == 0)
- {
- SetType(netadrtype_t::NA_LOOPBACK);
- }
- else if (strcmp(svInAdr.c_str(), "localhost") == 0)
- {
- svInAdr = "127.0.0.1";
- }
-
- if (strstr(svInAdr.c_str(), "["))
- {
- svInAdr = GetBase(svInAdr);
- }
-
SetIPAndPort(svInAdr, svInPort);
-
- if (m_version == netadrversion_t::NA_V4)
- {
- reinterpret_cast<sockaddr_in*>(&m_sadr)->sin_port = htons(stoi(GetPort()));
- }
- else if (m_version == netadrversion_t::NA_V6)
- {
- reinterpret_cast<sockaddr_in6*>(&m_sadr)->sin6_port = htons(stoi(GetPort()));
- }
}
//-----------------------------------------------------------------------------
@@ -242,7 +217,7 @@ std::string CNetAdr2::GetBase(void) const
// Purpose: removes brackets and port from IP address.
// Input : svInAdr -
//-----------------------------------------------------------------------------
-std::string CNetAdr2::GetBase(std::string svInAdr) const
+std::string CNetAdr2::GetBase(const std::string& svInAdr) const
{
static std::regex rx("[^\\[]*.(.*)(\\]).*");
std::smatch smRegexMatches;
diff --git a/NorthstarDedicatedTest/NetAdr2.h b/NorthstarDedicatedTest/NetAdr2.h
index a574a836..b37e6b48 100644
--- a/NorthstarDedicatedTest/NetAdr2.h
+++ b/NorthstarDedicatedTest/NetAdr2.h
@@ -45,8 +45,8 @@ class CNetAdr2
{
public:
CNetAdr2(void) {};
- CNetAdr2(std::string svInAdr);
- CNetAdr2(std::string svInAdr, std::string svInPort);
+ CNetAdr2(const std::string& svInAdr);
+ CNetAdr2(const std::string& svInAdr, const std::string& svInPort);
~CNetAdr2(void);
void SetIP(const std::string& svInAdr);
@@ -65,7 +65,7 @@ class CNetAdr2
netadrtype_t GetType(void) const;
netadrversion_t GetVersion(void) const;
std::string GetBase(void) const;
- std::string GetBase(std::string svInAdr) const;
+ std::string GetBase(const std::string& svInAdr) const;
std::vector<std::string> GetParts(void) const;
int GetSize(void) const;
int GetFamily(void) const;
diff --git a/NorthstarDedicatedTest/cl_rcon.cpp b/NorthstarDedicatedTest/cl_rcon.cpp
index 93cf0ae1..839f40bd 100644
--- a/NorthstarDedicatedTest/cl_rcon.cpp
+++ b/NorthstarDedicatedTest/cl_rcon.cpp
@@ -15,6 +15,15 @@
#include "igameserverdata.h"
//-----------------------------------------------------------------------------
+// Purpose: destructor
+//-----------------------------------------------------------------------------
+CRConClient::~CRConClient()
+{
+ delete m_pNetAdr2;
+ delete m_pSocket;
+}
+
+//-----------------------------------------------------------------------------
// Purpose: NETCON systems init
//-----------------------------------------------------------------------------
void CRConClient::Init(void)
diff --git a/NorthstarDedicatedTest/cl_rcon.h b/NorthstarDedicatedTest/cl_rcon.h
index ddfd0ed5..1b9e2dec 100644
--- a/NorthstarDedicatedTest/cl_rcon.h
+++ b/NorthstarDedicatedTest/cl_rcon.h
@@ -8,7 +8,7 @@ class CRConClient
{
public:
CRConClient(void) {};
- ~CRConClient(void) {};
+ ~CRConClient(void);
void Init(void);
void Shutdown(void);
diff --git a/NorthstarDedicatedTest/sv_rcon.cpp b/NorthstarDedicatedTest/sv_rcon.cpp
index 1dcfff32..527e5f5e 100644
--- a/NorthstarDedicatedTest/sv_rcon.cpp
+++ b/NorthstarDedicatedTest/sv_rcon.cpp
@@ -19,6 +19,15 @@
#include "igameserverdata.h"
//-----------------------------------------------------------------------------
+// Purpose: destructor
+//-----------------------------------------------------------------------------
+CRConServer::~CRConServer()
+{
+ delete m_pNetAdr2;
+ delete m_pSocket;
+}
+
+//-----------------------------------------------------------------------------
// Purpose: NETCON systems init
//-----------------------------------------------------------------------------
void CRConServer::Init(void)
@@ -35,8 +44,8 @@ void CRConServer::Init(void)
static ConVar* hostport = g_pCVar->FindVar("hostport");
- m_pAdr2 = new CNetAdr2(CVar_rcon_address->GetString(), hostport->GetString());
- m_pSocket->CreateListenSocket(*m_pAdr2, false);
+ m_pNetAdr2->SetIPAndPort(CVar_rcon_address->GetString(), hostport->GetString());
+ m_pSocket->CreateListenSocket(*m_pNetAdr2, false);
m_svPasswordHash = sha256(CVar_rcon_password->GetString());
spdlog::info("Remote server access initialized");
@@ -84,7 +93,7 @@ void CRConServer::Think(void)
{
if (!m_pSocket->IsListening())
{
- m_pSocket->CreateListenSocket(*m_pAdr2, false);
+ m_pSocket->CreateListenSocket(*m_pNetAdr2, false);
}
}
}
diff --git a/NorthstarDedicatedTest/sv_rcon.h b/NorthstarDedicatedTest/sv_rcon.h
index 23ca2118..ec762d25 100644
--- a/NorthstarDedicatedTest/sv_rcon.h
+++ b/NorthstarDedicatedTest/sv_rcon.h
@@ -13,6 +13,8 @@ constexpr char s_pszAuthMessage[] = "RCON authentication succesfull.\n\r";
class CRConServer
{
public:
+ ~CRConServer();
+
void Init(void);
void Shutdown(void);
@@ -40,7 +42,7 @@ class CRConServer
private:
bool m_bInitialized = false;
int m_nConnIndex = 0;
- CNetAdr2* m_pAdr2 = new CNetAdr2();
+ CNetAdr2* m_pNetAdr2 = new CNetAdr2();
CSocketCreator* m_pSocket = new CSocketCreator();
std::vector<std::string> m_vBannedAddress;
std::string m_svPasswordHash;