mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
* Implemented robust length-prefix framing logic for non-blocking sockets (previously used character sequences to determine length, but you cannot use character sequences on protocol buffers as its binary data. This logic should fix all problems regarding some commands not getting networked properly to the server and stuff not getting printed on the client). * Increased buffer size to std::vector::max_size when netconsole is authenticated (MAX_NETCONSOLE_INPUT_LEN still remains enforced on accepted but not authenticated connections to prevent attackers from crashing the server). * Process max 1024 bytes each recv buffer iteration. * Additional optimizations and cleanup.
72 lines
2.0 KiB
C++
72 lines
2.0 KiB
C++
//===========================================================================//
|
|
//
|
|
// Purpose: Enumerations for writing out the requests.
|
|
//
|
|
//===========================================================================//
|
|
#pragma once
|
|
|
|
typedef int SocketHandle_t;
|
|
|
|
enum class ServerDataRequestType_t : int
|
|
{
|
|
SERVERDATA_REQUEST_VALUE = 0,
|
|
SERVERDATA_REQUEST_SETVALUE,
|
|
SERVERDATA_REQUEST_EXECCOMMAND,
|
|
SERVERDATA_REQUEST_AUTH,
|
|
SERVERDATA_REQUEST_SEND_CONSOLE_LOG,
|
|
SERVERDATA_REQUEST_SEND_REMOTEBUG,
|
|
};
|
|
|
|
enum class ServerDataResponseType_t : int
|
|
{
|
|
SERVERDATA_RESPONSE_VALUE = 0,
|
|
SERVERDATA_RESPONSE_UPDATE,
|
|
SERVERDATA_RESPONSE_AUTH,
|
|
SERVERDATA_RESPONSE_CONSOLE_LOG,
|
|
SERVERDATA_RESPONSE_STRING,
|
|
SERVERDATA_RESPONSE_REMOTEBUG,
|
|
};
|
|
|
|
class CConnectedNetConsoleData
|
|
{
|
|
public:
|
|
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.
|
|
bool m_bValidated; // Revalidates netconsole if false.
|
|
bool m_bAuthorized; // Set to true after successfull netconsole auth.
|
|
bool m_bInputOnly; // If set, don't send spew to this net console.
|
|
std::vector<uint8_t> m_RecvBuffer;
|
|
|
|
CConnectedNetConsoleData(SocketHandle_t hSocket = -1)
|
|
{
|
|
m_hSocket = hSocket;
|
|
m_nPayloadLen = 0;
|
|
m_nPayloadRead = 0;
|
|
m_nFailedAttempts = 0;
|
|
m_nIgnoredMessage = 0;
|
|
m_bValidated = false;
|
|
m_bAuthorized = false;
|
|
m_bInputOnly = false;
|
|
m_RecvBuffer.reserve(sizeof(int)); // Reserve enough for length-prefix.
|
|
}
|
|
};
|
|
|
|
/* PACKET FORMAT **********************************
|
|
|
|
REQUEST:
|
|
int requestID;
|
|
int ServerDataRequestType_t;
|
|
NullTerminatedString (variable or command)
|
|
NullTerminatedString (value)
|
|
|
|
RESPONSE:
|
|
int requestID;
|
|
int ServerDataResponseType_t;
|
|
NullTerminatedString (variable)
|
|
NullTerminatedString (value)
|
|
|
|
***************************************************/
|