mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
* Fix multiple issues related to threading, such as not locking the mutex when using thread-unsafe members or methods. * Netconsole now logs its output to a file on the disk. * Properly handle close events, to allow netconsole to shutdown properly, so stuff like log buffers could flush properly. Input is now ran in a separate thread so main thread could check if we need to shutdown, and do so if needed. This was needed as previously input was ran in the main thread and the issue is that its blocking until an input is given.
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
//===========================================================================//
|
|
//
|
|
// Purpose:
|
|
//
|
|
//===========================================================================//
|
|
#pragma once
|
|
#include "tier1/cmd.h"
|
|
#include "protoc/cl_rcon.pb.h"
|
|
#include "protoc/sv_rcon.pb.h"
|
|
#include "engine/shared/base_rcon.h"
|
|
|
|
constexpr const char* NETCON_VERSION = "2.0.0.1";
|
|
|
|
class CNetCon : public CNetConBase
|
|
{
|
|
public:
|
|
CNetCon(void);
|
|
~CNetCon(void);
|
|
|
|
bool Init(const bool bAnsiColor, const char* pHostName = nullptr, const int nPort = SOCKET_ERROR);
|
|
bool Shutdown(void);
|
|
void TermSetup(const bool bAnsiColor);
|
|
|
|
void RunInput(const string& lineInput);
|
|
bool RunFrame(void);
|
|
|
|
bool GetQuitting(void) const;
|
|
void SetQuitting(const bool bQuit);
|
|
|
|
bool GetPrompting(void) const;
|
|
void SetPrompting(const bool bPrompt);
|
|
|
|
inline float GetTickInterval() const { return m_flTickInterval; }
|
|
static BOOL WINAPI CloseHandler(DWORD eventCode);
|
|
|
|
virtual void Disconnect(const char* szReason = nullptr);
|
|
virtual bool ProcessMessage(const char* pMsgBuf, const int nMsgLen) override;
|
|
|
|
bool Serialize(vector<char>& vecBuf, const char* szReqBuf,
|
|
const char* szReqVal, const cl_rcon::request_t requestType) const;
|
|
|
|
SocketHandle_t GetSocket(void);
|
|
bool IsInitialized(void) const;
|
|
bool IsConnected(void);
|
|
|
|
private:
|
|
bool m_bInitialized;
|
|
bool m_bQuitting;
|
|
bool m_bPromptConnect;
|
|
float m_flTickInterval;
|
|
|
|
characterset_t m_CharacterSet;
|
|
mutable std::mutex m_Mutex;
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// singleton
|
|
//-----------------------------------------------------------------------------
|
|
extern CNetCon* NetConsole();
|