Engine: improve type usage consistency

RCON was using buffer types and size types inconsistently, which required having to do many casts. Normalized type usage to reduce the number of casts required.
This commit is contained in:
Kawe Mazidjatari 2025-02-09 19:04:48 +01:00
parent f2e332efa0
commit dea3888973
11 changed files with 83 additions and 87 deletions

View File

@ -31,10 +31,10 @@ enum class ServerDataResponseType_e : int
struct ConnectedNetConsoleData_s
{
SocketHandle_t m_hSocket;
int m_nPayloadLen; // Num bytes for this message.
int m_nPayloadRead; // Num read bytes from input buffer.
int m_nFailedAttempts; // Num failed authentication attempts.
int m_nIgnoredMessage; // Count how many times client ignored the no-auth message.
u32 m_nPayloadLen; // Num bytes for this message.
u32 m_nPayloadRead; // Num read bytes from input buffer.
u32 m_nFailedAttempts; // Num failed authentication attempts.
u32 m_nIgnoredMessage; // Count how many times client ignored the no-auth message.
bool m_bValidated; // Revalidates netconsole if false.
bool m_bAuthorized; // Set to true after successful netconsole auth.
bool m_bInputOnly; // If set, don't send spew to this netconsole.
@ -51,6 +51,8 @@ struct ConnectedNetConsoleData_s
m_bValidated = false;
m_bAuthorized = false;
m_bInputOnly = true;
m_FrameHeader.magic = 0;
m_FrameHeader.length = 0;
}
};

View File

@ -105,7 +105,7 @@ void CRConClient::Disconnect(const char* szReason)
// Input : *pMsgBug -
// nMsgLen -
//-----------------------------------------------------------------------------
bool CRConClient::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
bool CRConClient::ProcessMessage(const byte* const pMsgBuf, const u32 nMsgLen)
{
netcon::response response;
@ -165,10 +165,10 @@ void CRConClient::RequestConsoleLog(const bool bWantLog)
const char* const szEnable = bWantLog ? "1" : "0";
const SocketHandle_t hSocket = GetSocket();
vector<char> vecMsg;
vector<byte> vecMsg;
const bool ret = Serialize(vecMsg, "", 0, szEnable, 1, netcon::request_e::SERVERDATA_REQUEST_SEND_CONSOLE_LOG);
if (ret && !Send(hSocket, vecMsg.data(), int(vecMsg.size())))
if (ret && !Send(hSocket, vecMsg.data(), (u32)vecMsg.size()))
{
Error(eDLL_T::CLIENT, NO_ERROR, "Failed to send RCON message: (%s)\n", "SOCKET_ERROR");
}
@ -183,7 +183,7 @@ void CRConClient::RequestConsoleLog(const bool bWantLog)
// request_t -
// Output : serialized results as string
//-----------------------------------------------------------------------------
bool CRConClient::Serialize(vector<char>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
bool CRConClient::Serialize(vector<byte>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
const char* szReqVal, const size_t nReqValLen, const netcon::request_e requestType) const
{
return NetconClient_Serialize(this, vecBuf, szReqBuf, nReqMsgLen, szReqVal, nReqValLen, requestType,
@ -323,7 +323,7 @@ static void RCON_CmdQuery_f(const CCommand& args)
}
else if (RCONClient()->IsConnected())
{
vector<char> vecMsg;
vector<byte> vecMsg;
bool bSuccess = false;
const SocketHandle_t hSocket = RCONClient()->GetSocket();
@ -344,7 +344,7 @@ static void RCON_CmdQuery_f(const CCommand& args)
if (bSuccess)
{
RCONClient()->Send(hSocket, vecMsg.data(), int(vecMsg.size()));
RCONClient()->Send(hSocket, vecMsg.data(), (u32)vecMsg.size());
}
return;
@ -364,7 +364,7 @@ static void RCON_CmdQuery_f(const CCommand& args)
bSuccess = RCONClient()->Serialize(vecMsg, request, requestLen, value, valueLen, netcon::request_e::SERVERDATA_REQUEST_EXECCOMMAND);
if (bSuccess)
{
RCONClient()->Send(hSocket, vecMsg.data(), int(vecMsg.size()));
RCONClient()->Send(hSocket, vecMsg.data(), (u32)vecMsg.size());
}
return;
}

View File

@ -15,9 +15,9 @@ public:
void RunFrame(void);
virtual void Disconnect(const char* szReason = nullptr) override;
virtual bool ProcessMessage(const char* pMsgBuf, const int nMsgLen) override;
virtual bool ProcessMessage(const byte* pMsgBuf, const u32 nMsgLen) override;
bool Serialize(vector<char>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
bool Serialize(vector<byte>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
const char* szReqVal, const size_t nReqValLen, const netcon::request_e requestType) const;
void RequestConsoleLog(const bool bWantLog);

View File

@ -270,7 +270,7 @@ void CRConServer::RunFrame(void)
// nMsgLen -
// Output: true on success, false otherwise
//-----------------------------------------------------------------------------
bool CRConServer::SendToAll(const char* pMsgBuf, const int nMsgLen) const
bool CRConServer::SendToAll(const byte* pMsgBuf, const u32 nMsgLen) const
{
const int nCount = m_Socket.GetAcceptedSocketCount();
bool bSuccess = true;
@ -281,7 +281,7 @@ bool CRConServer::SendToAll(const char* pMsgBuf, const int nMsgLen) const
if (data.m_bAuthorized && !data.m_bInputOnly)
{
const int ret = ::send(data.m_hSocket, pMsgBuf, nMsgLen, MSG_NOSIGNAL);
const int ret = ::send(data.m_hSocket, (const char*)pMsgBuf, (i32)nMsgLen, MSG_NOSIGNAL);
if (ret == SOCKET_ERROR)
{
@ -310,7 +310,7 @@ bool CRConServer::SendToAll(const char* pMsgBuf, const int nMsgLen) const
bool CRConServer::SendEncoded(const char* pResponseMsg, const size_t nResponseMsgLen, const char* pResponseVal, const size_t nResponseValLen,
const netcon::response_e responseType, const int nMessageId, const int nMessageType) const
{
vector<char> vecMsg;
vector<byte> vecMsg;
if (!Serialize(vecMsg, pResponseMsg, nResponseMsgLen, pResponseVal, nResponseValLen,
responseType, nMessageId, nMessageType))
{
@ -341,7 +341,7 @@ bool CRConServer::SendEncoded(const SocketHandle_t hSocket,
const char* pResponseMsg, const size_t nResponseMsgLen, const char* pResponseVal, const size_t nResponseValLen,
const netcon::response_e responseType, const int nMessageId, const int nMessageType) const
{
vector<char> vecMsg;
vector<byte> vecMsg;
if (!Serialize(vecMsg, pResponseMsg, nResponseMsgLen, pResponseVal, nResponseValLen,
responseType, nMessageId, nMessageType))
{
@ -368,7 +368,7 @@ bool CRConServer::SendEncoded(const SocketHandle_t hSocket,
// nMessageType -
// Output : serialized results as string
//-----------------------------------------------------------------------------
bool CRConServer::Serialize(vector<char>& vecBuf,
bool CRConServer::Serialize(vector<byte>& vecBuf,
const char* pResponseMsg, const size_t nResponseMsgLen, const char* pResponseVal, const size_t nResponseValLen,
const netcon::response_e responseType, const int nMessageId, const int nMessageType) const
{
@ -445,7 +445,7 @@ bool CRConServer::Comparator(const string& svPassword) const
// nMsgLen -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool CRConServer::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
bool CRConServer::ProcessMessage(const byte* pMsgBuf, const u32 nMsgLen)
{
netcon::request request;

View File

@ -35,14 +35,14 @@ public:
const int nMessageId = static_cast<int>(eDLL_T::NETCON),
const int nMessageType = static_cast<int>(LogType_t::LOG_NET)) const;
bool SendToAll(const char* pMsgBuf, const int nMsgLen) const;
bool Serialize(vector<char>& vecBuf, const char* pResponseMsg, const size_t nResponseMsgLen, const char* pResponseVal, const size_t nResponseValLen,
bool SendToAll(const byte* pMsgBuf, const u32 nMsgLen) const;
bool Serialize(vector<byte>& vecBuf, const char* pResponseMsg, const size_t nResponseMsgLen, const char* pResponseVal, const size_t nResponseValLen,
const netcon::response_e responseType, const int nMessageId = static_cast<int>(eDLL_T::NETCON), const int nMessageType = static_cast<int>(LogType_t::LOG_NET)) const;
void Authenticate(const netcon::request& request, ConnectedNetConsoleData_s& data);
bool Comparator(const string& svPassword) const;
virtual bool ProcessMessage(const char* pMsgBuf, const int nMsgLen) override;
virtual bool ProcessMessage(const byte* pMsgBuf, const u32 nMsgLen) override;
void Execute(const netcon::request& request) const;
bool CheckForBan(ConnectedNetConsoleData_s& data);

View File

@ -144,14 +144,14 @@ bool CNetConBase::Connect(const char* pHostName, const int nPort)
// nMaxLen -
// Output: true on success, false otherwise
//-----------------------------------------------------------------------------
bool CNetConBase::ProcessBuffer(ConnectedNetConsoleData_s& data, const char* pRecvBuf, int nRecvLen, const int nMaxLen)
bool CNetConBase::ProcessBuffer(ConnectedNetConsoleData_s& data, const byte* pRecvBuf, u32 nRecvLen, const int nMaxLen)
{
while (nRecvLen > 0)
{
// Read payload if it's already in progress.
if (data.m_nPayloadLen)
{
const int bytesToCopy = Min(nRecvLen, data.m_nPayloadLen - data.m_nPayloadRead);
const u32 bytesToCopy = Min(nRecvLen, data.m_nPayloadLen - data.m_nPayloadRead);
memcpy(&data.m_RecvBuffer[data.m_nPayloadRead], pRecvBuf, bytesToCopy);
data.m_nPayloadRead += bytesToCopy;
@ -161,7 +161,7 @@ bool CNetConBase::ProcessBuffer(ConnectedNetConsoleData_s& data, const char* pRe
if (data.m_nPayloadRead == data.m_nPayloadLen)
{
if (!ProcessMessage(reinterpret_cast<const char*>(data.m_RecvBuffer.data()), data.m_nPayloadLen))
if (!ProcessMessage(data.m_RecvBuffer.data(), data.m_nPayloadLen))
return false;
// Reset state.
@ -171,7 +171,7 @@ bool CNetConBase::ProcessBuffer(ConnectedNetConsoleData_s& data, const char* pRe
}
else if (data.m_nPayloadRead < sizeof(NetConFrameHeader_s)) // Read the header if we haven't fully recv'd it.
{
const int bytesToCopy = Min(nRecvLen, int(sizeof(NetConFrameHeader_s)) - data.m_nPayloadRead);
const u32 bytesToCopy = Min(nRecvLen, int(sizeof(NetConFrameHeader_s)) - data.m_nPayloadRead);
memcpy(reinterpret_cast<char*>(&data.m_FrameHeader) + data.m_nPayloadRead, pRecvBuf, bytesToCopy);
data.m_nPayloadRead += bytesToCopy;
@ -236,13 +236,12 @@ bool CNetConBase::ProcessBuffer(ConnectedNetConsoleData_s& data, const char* pRe
// nDataLen -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool CNetConBase::Encrypt(CryptoContext_s& ctx, const char* pInBuf,
char* pOutBuf, const size_t nDataLen) const
bool CNetConBase::Encrypt(CryptoContext_s& ctx, const byte* pInBuf, byte* pOutBuf, const u32 nDataLen) const
{
if (Crypto_GenerateIV(ctx, reinterpret_cast<const unsigned char*>(pInBuf), nDataLen))
return Crypto_CTREncrypt(ctx, reinterpret_cast<const unsigned char*>(pInBuf),
reinterpret_cast<unsigned char*>(pOutBuf), m_NetKey, nDataLen);
if (Crypto_GenerateIV(ctx, pInBuf, nDataLen))
return Crypto_CTREncrypt(ctx, pInBuf, pOutBuf, m_NetKey, nDataLen);
Assert(0);
return false; // failure
}
@ -254,11 +253,9 @@ bool CNetConBase::Encrypt(CryptoContext_s& ctx, const char* pInBuf,
// nDataLen -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool CNetConBase::Decrypt(CryptoContext_s& ctx, const char* pInBuf,
char* pOutBuf, const size_t nDataLen) const
bool CNetConBase::Decrypt(CryptoContext_s& ctx, const byte* pInBuf, byte* pOutBuf, const u32 nDataLen) const
{
return Crypto_CTRDecrypt(ctx, reinterpret_cast<const unsigned char*>(pInBuf),
reinterpret_cast<unsigned char*>(pOutBuf), m_NetKey, nDataLen);
return Crypto_CTRDecrypt(ctx, pInBuf, pOutBuf, m_NetKey, nDataLen);
}
//-----------------------------------------------------------------------------
@ -268,10 +265,9 @@ bool CNetConBase::Decrypt(CryptoContext_s& ctx, const char* pInBuf,
// nMsgLen -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool CNetConBase::Encode(google::protobuf::MessageLite* pMsg,
char* pMsgBuf, const size_t nMsgLen) const
bool CNetConBase::Encode(google::protobuf::MessageLite* pMsg, byte* pMsgBuf, const u32 nMsgLen) const
{
return pMsg->SerializeToArray(pMsgBuf, int(nMsgLen));
return pMsg->SerializeToArray(pMsgBuf, (i32)nMsgLen);
}
//-----------------------------------------------------------------------------
@ -281,10 +277,9 @@ bool CNetConBase::Encode(google::protobuf::MessageLite* pMsg,
// nMsgLen -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool CNetConBase::Decode(google::protobuf::MessageLite* pMsg,
const char* pMsgBuf, const size_t nMsgLen) const
bool CNetConBase::Decode(google::protobuf::MessageLite* pMsg, const byte* pMsgBuf, const u32 nMsgLen) const
{
return pMsg->ParseFromArray(pMsgBuf, int(nMsgLen));
return pMsg->ParseFromArray(pMsgBuf, (i32)nMsgLen);
}
//-----------------------------------------------------------------------------
@ -294,10 +289,9 @@ bool CNetConBase::Decode(google::protobuf::MessageLite* pMsg,
// nMsgLen -
// Output: true on success, false otherwise
//-----------------------------------------------------------------------------
bool CNetConBase::Send(const SocketHandle_t hSocket, const char* pMsgBuf,
const int nMsgLen) const
bool CNetConBase::Send(const SocketHandle_t hSocket, const byte* pMsgBuf, const u32 nMsgLen) const
{
const int ret = ::send(hSocket, pMsgBuf, nMsgLen, MSG_NOSIGNAL);
const int ret = ::send(hSocket, (char*)pMsgBuf, (i32)nMsgLen, MSG_NOSIGNAL);
return (ret != SOCKET_ERROR);
}
@ -354,7 +348,7 @@ void CNetConBase::Recv(ConnectedNetConsoleData_s& data, const int nMaxLen)
nReadLen -= static_cast<u_long>(nRecvLen); // Process what we've got.
if (!ProcessBuffer(data, szRecvBuf, nRecvLen, nMaxLen))
if (!ProcessBuffer(data, reinterpret_cast<byte*>(&szRecvBuf), static_cast<u32>(nRecvLen), nMaxLen))
break;
}

View File

@ -21,16 +21,16 @@ public:
virtual bool Connect(const char* pHostName, const int nHostPort = SOCKET_ERROR);
virtual void Disconnect(const char* szReason = nullptr) { NOTE_UNUSED(szReason); };
virtual bool ProcessBuffer(ConnectedNetConsoleData_s& data, const char* pRecvBuf, int nRecvLen, const int nMaxLen = SOCKET_ERROR);
virtual bool ProcessMessage(const char* /*pMsgBuf*/, int /*nMsgLen*/) { return true; };
virtual bool ProcessBuffer(ConnectedNetConsoleData_s& data, const byte* pRecvBuf, u32 nRecvLen, const int nMaxLen = SOCKET_ERROR);
virtual bool ProcessMessage(const byte* /*pMsgBuf*/, const u32 /*nMsgLen*/) { return true; };
virtual bool Encrypt(CryptoContext_s& ctx, const char* pInBuf, char* pOutBuf, const size_t nDataLen) const;
virtual bool Decrypt(CryptoContext_s& ctx, const char* pInBuf, char* pOutBuf, const size_t nDataLen) const;
virtual bool Encrypt(CryptoContext_s& ctx, const byte* pInBuf, byte* pOutBuf, const u32 nDataLen) const;
virtual bool Decrypt(CryptoContext_s& ctx, const byte* pInBuf, byte* pOutBuf, const u32 nDataLen) const;
virtual bool Encode(google::protobuf::MessageLite* pMsg, char* pMsgBuf, const size_t nMsgLen) const;
virtual bool Decode(google::protobuf::MessageLite* pMsg, const char* pMsgBuf, const size_t nMsgLen) const;
virtual bool Encode(google::protobuf::MessageLite* pMsg, byte* pMsgBuf, const u32 nMsgLen) const;
virtual bool Decode(google::protobuf::MessageLite* pMsg, const byte* pMsgBuf, const u32 nMsgLen) const;
virtual bool Send(const SocketHandle_t hSocket, const char* pMsgBuf, const int nMsgLen) const;
virtual bool Send(const SocketHandle_t hSocket, const byte* pMsgBuf, const u32 nMsgLen) const;
virtual void Recv(ConnectedNetConsoleData_s& data, const int nMaxLen = SOCKET_ERROR);
CSocketCreator* GetSocketCreator(void) { return &m_Socket; }

View File

@ -23,7 +23,7 @@
// bDebug -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool NetconServer_Serialize(const CNetConBase* pBase, vector<char>& vecBuf,
bool NetconServer_Serialize(const CNetConBase* pBase, vector<byte>& vecBuf,
const char* pResponseMsg, const size_t nResponseMsgLen, const char* pResponseVal, const size_t nResponseValLen,
const netcon::response_e responseType, const int nMessageId, const int nMessageType, const bool bEncrypt, const bool bDebug)
{
@ -35,7 +35,7 @@ bool NetconServer_Serialize(const CNetConBase* pBase, vector<char>& vecBuf,
response.set_responsemsg(pResponseMsg, nResponseMsgLen);
response.set_responseval(pResponseVal, nResponseValLen);
if (!NetconShared_PackEnvelope(pBase, vecBuf, response.ByteSizeLong(), &response, bEncrypt, bDebug))
if (!NetconShared_PackEnvelope(pBase, vecBuf, (u32)response.ByteSizeLong(), &response, bEncrypt, bDebug))
{
return false;
}
@ -56,7 +56,7 @@ bool NetconServer_Serialize(const CNetConBase* pBase, vector<char>& vecBuf,
// bDebug -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool NetconClient_Serialize(const CNetConBase* pBase, vector<char>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
bool NetconClient_Serialize(const CNetConBase* pBase, vector<byte>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
const char* szReqVal, const size_t nReqValLen, const netcon::request_e requestType, const bool bEncrypt, const bool bDebug)
{
netcon::request request;
@ -66,7 +66,7 @@ bool NetconClient_Serialize(const CNetConBase* pBase, vector<char>& vecBuf, cons
request.set_requestmsg(szReqBuf, nReqMsgLen);
request.set_requestval(szReqVal, nReqValLen);
if (!NetconShared_PackEnvelope(pBase, vecBuf, request.ByteSizeLong(), &request, bEncrypt, bDebug))
if (!NetconShared_PackEnvelope(pBase, vecBuf, (u32)request.ByteSizeLong(), &request, bEncrypt, bDebug))
{
return false;
}
@ -129,11 +129,11 @@ bool NetconClient_Connect(CNetConBase* pBase, const char* pHostAdr, const int nH
// bDebug -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool NetconShared_PackEnvelope(const CNetConBase* pBase, vector<char>& outMsgBuf, const size_t nMsgLen,
google::protobuf::MessageLite* inMsg, const bool bEncrypt, const bool bDebug)
bool NetconShared_PackEnvelope(const CNetConBase* pBase, vector<byte>& outMsgBuf, const u32 nMsgLen,
google::protobuf::MessageLite* const inMsg, const bool bEncrypt, const bool bDebug)
{
char* encodeBuf = new char[nMsgLen];
std::unique_ptr<char[]> encodedContainer(encodeBuf);
byte* const encodeBuf = new byte[nMsgLen];
std::unique_ptr<byte[]> encodedContainer(encodeBuf);
if (!pBase->Encode(inMsg, encodeBuf, nMsgLen))
{
@ -148,12 +148,12 @@ bool NetconShared_PackEnvelope(const CNetConBase* pBase, vector<char>& outMsgBuf
netcon::envelope envelope;
envelope.set_encrypted(bEncrypt);
const char* dataBuf = encodeBuf;
std::unique_ptr<char[]> container;
const byte* dataBuf = encodeBuf;
std::unique_ptr<byte[]> container;
if (bEncrypt)
{
char* encryptBuf = new char[nMsgLen];
byte* encryptBuf = new byte[nMsgLen];
container.reset(encryptBuf);
CryptoContext_s ctx;
@ -172,10 +172,10 @@ bool NetconShared_PackEnvelope(const CNetConBase* pBase, vector<char>& outMsgBuf
}
envelope.set_data(dataBuf, nMsgLen);
const size_t envelopeSize = envelope.ByteSizeLong();
const u32 envelopeSize = (u32)envelope.ByteSizeLong();
outMsgBuf.resize(sizeof(NetConFrameHeader_s) + envelopeSize);
char* const scratch = outMsgBuf.data();
byte* const scratch = outMsgBuf.data();
if (!pBase->Encode(&envelope, &scratch[sizeof(NetConFrameHeader_s)], envelopeSize))
{
@ -206,8 +206,8 @@ bool NetconShared_PackEnvelope(const CNetConBase* pBase, vector<char>& outMsgBuf
// bDebug -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool NetconShared_UnpackEnvelope(const CNetConBase* pBase, const char* pMsgBuf, const size_t nMsgLen,
google::protobuf::MessageLite* outMsg, const bool bDebug)
bool NetconShared_UnpackEnvelope(const CNetConBase* pBase, const byte* pMsgBuf, const u32 nMsgLen,
google::protobuf::MessageLite* const outMsg, const bool bDebug)
{
netcon::envelope envelope;
@ -221,33 +221,33 @@ bool NetconShared_UnpackEnvelope(const CNetConBase* pBase, const char* pMsgBuf,
return false;
}
const size_t msgLen = envelope.data().size();
const u32 msgLen = (u32)envelope.data().size();
if (msgLen > RCON_FRAME_MAX_SIZE)
{
Error(eDLL_T::ENGINE, NO_ERROR, "Data in RCON message envelope is too large (%zu > %zu)\n",
Error(eDLL_T::ENGINE, NO_ERROR, "Data in RCON message envelope is too large (%u > %u)\n",
msgLen, RCON_FRAME_MAX_SIZE);
return false;
}
const char* netMsg = envelope.data().c_str();
const char* dataBuf = netMsg;
const byte* netMsg = reinterpret_cast<const byte*>(envelope.data().c_str());
const byte* dataBuf = netMsg;
std::unique_ptr<char[]> container;
std::unique_ptr<byte[]> container;
if (envelope.encrypted())
{
char* decryptBuf = new char[msgLen];
byte* decryptBuf = new byte[msgLen];
container.reset(decryptBuf);
const size_t ivLen = envelope.nonce().size();
const u32 ivLen = (u32)envelope.nonce().size();
if (ivLen != sizeof(CryptoIV_t))
{
if (bDebug)
{
Error(eDLL_T::ENGINE, NO_ERROR, "Nonce in RCON message envelope is invalid (%zu != %zu)\n",
Error(eDLL_T::ENGINE, NO_ERROR, "Nonce in RCON message envelope is invalid (%u != %u)\n",
ivLen, sizeof(CryptoIV_t));
}

View File

@ -16,16 +16,16 @@ extern void RCON_InitClientAndTrySyncKeys();
#endif // !DEDICATED
#endif // _TOOLS
bool NetconServer_Serialize(const CNetConBase* pBase, vector<char>& vecBuf,
bool NetconServer_Serialize(const CNetConBase* pBase, vector<byte>& vecBuf,
const char* pResponseMsg, const size_t nResponseMsgLen, const char* pResponseVal, const size_t nResponseValLen,
const netcon::response_e responseType, const int nMessageId, const int nMessageType, const bool bEncrypt, const bool bDebug);
bool NetconClient_Serialize(const CNetConBase* pBase, vector<char>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
bool NetconClient_Serialize(const CNetConBase* pBase, vector<byte>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
const char* szReqVal, const size_t nReqValLen, const netcon::request_e requestType, const bool bEncrypt, const bool bDebug);
bool NetconClient_Connect(CNetConBase* pBase, const char* pHostAdr, const int nHostPort);
bool NetconShared_PackEnvelope(const CNetConBase* pBase, vector<char>& outMsgBuf, const size_t nMsgLen, google::protobuf::MessageLite* inMsg, const bool bEncrypt, const bool bDebug);
bool NetconShared_UnpackEnvelope(const CNetConBase* pBase, const char* pMsgBuf, const size_t nMsgLen, google::protobuf::MessageLite* outMsg, const bool bDebug);
bool NetconShared_PackEnvelope(const CNetConBase* pBase, vector<byte>& outMsgBuf, const u32 nMsgLen, google::protobuf::MessageLite* const inMsg, const bool bEncrypt, const bool bDebug);
bool NetconShared_UnpackEnvelope(const CNetConBase* pBase, const byte* pMsgBuf, const u32 nMsgLen, google::protobuf::MessageLite* const outMsg, const bool bDebug);
ConnectedNetConsoleData_s* NetconShared_GetConnData(CNetConBase* pBase, const int iSocket);
SocketHandle_t NetconShared_GetSocketHandle(CNetConBase* pBase, const int iSocket);

View File

@ -233,7 +233,7 @@ void CNetCon::RunInput(const string& lineInput)
return;
}
vector<char> vecMsg;
vector<byte> vecMsg;
const SocketHandle_t hSocket = GetSocket();
bool bSend = false;
@ -422,7 +422,7 @@ void CNetCon::Disconnect(const char* szReason)
// nMsgLen -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool CNetCon::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
bool CNetCon::ProcessMessage(const byte* pMsgBuf, const u32 nMsgLen)
{
netcon::response response;
@ -441,10 +441,10 @@ bool CNetCon::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
const long i = strtol(response.responseval().c_str(), NULL, NULL);
if (!i) // Means we are marked 'input only' on the rcon server.
{
vector<char> vecMsg;
bool ret = Serialize(vecMsg, "", 0, "1", 1, netcon::request_e::SERVERDATA_REQUEST_SEND_CONSOLE_LOG);
vector<byte> vecMsg;
const bool ret = Serialize(vecMsg, "", 0, "1", 1, netcon::request_e::SERVERDATA_REQUEST_SEND_CONSOLE_LOG);
if (ret && !Send(GetSocket(), vecMsg.data(), int(vecMsg.size())))
if (ret && !Send(GetSocket(), vecMsg.data(), (u32)vecMsg.size()))
{
Error(eDLL_T::CLIENT, NO_ERROR, "Failed to send RCON message: (%s)\n", "SOCKET_ERROR");
}
@ -480,7 +480,7 @@ bool CNetCon::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
// requestType -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
bool CNetCon::Serialize(vector<char>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
bool CNetCon::Serialize(vector<byte>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
const char* szReqVal, const size_t nReqValLen, const netcon::request_e requestType) const
{
return NetconClient_Serialize(this, vecBuf, szReqBuf, nReqMsgLen, szReqVal, nReqValLen, requestType, m_bEncryptFrames, true);

View File

@ -35,10 +35,10 @@ public:
virtual bool Connect(const char* pHostName, const int nHostPort = SOCKET_ERROR) override;
virtual void Disconnect(const char* szReason = nullptr) override;
virtual bool ProcessMessage(const char* pMsgBuf, const int nMsgLen) override;
virtual bool ProcessMessage(const byte* pMsgBuf, const u32 nMsgLen) override;
void TrySetKey(const char* const pKey);
bool Serialize(vector<char>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
bool Serialize(vector<byte>& vecBuf, const char* szReqBuf, const size_t nReqMsgLen,
const char* szReqVal, const size_t nReqValLen, const netcon::request_e requestType) const;
SocketHandle_t GetSocket(void);