r5sdk/r5dev/rtech/liveapi/liveapi.h
Kawe Mazidjatari e91b8cfcec RTech: implement custom events and slight adjustments/improvements
Implemented CustomEvent in code, which supports:
- bool|int|float|string|vector|array|table
- nested arrays and tables, up to a depth of 64

Also improved foundation code for LiveAPI:
- added ability to log liveapi events to a file on the disk (rotates between each match or round, depending on how the abstracted functions are called in scripts)
- when the system is enabled through cvars, code will be invoked on the fly
- when the system is disabled through cvars, the system will be shutdown properly on the fly (properly handling socket closing, log file finishing, etc)
- if the socket system is enabled/disabled on the fly using cvars, related code will be called to initiate or shutdown the connections.

The generated proto.cpp/h file has been moved to the protoc project as it was causing some compiler warnings that we suppress on the thirdparty (vendored) code.
2024-04-05 18:39:36 +02:00

59 lines
1.2 KiB
C++

#ifndef RTECH_LIVEAPI_H
#define RTECH_LIVEAPI_H
#include "tier2/websocket.h"
#include "thirdparty/protobuf/message.h"
#define LIVE_API_MAX_FRAME_BUFFER_SIZE 0x8000
extern ConVar liveapi_enabled;
extern ConVar liveapi_session_name;
struct ProtoWebSocketRefT;
typedef void (*LiveAPISendCallback_t)(ProtoWebSocketRefT* webSocket);
class LiveAPI
{
public:
LiveAPI();
~LiveAPI();
void Init();
void Shutdown();
void ToggleInit();
void CreateParams(CWebSocket::ConnParams_s& params);
void UpdateParams();
void InitWebSocket();
void ShutdownWebSocket();
void ToggleInitWebSocket();
void RebootWebSocket();
void CreateLogger();
void DestroyLogger();
void RunFrame();
void LogEvent(const google::protobuf::Message* const toTransmit, const google::protobuf::Message* toPrint);
bool IsEnabled() const;
bool IsValidToRun() const;
inline bool WebSocketInitialized() const { return webSocketSystem.IsInitialized(); }
inline bool FileLoggerInitialized() const { return matchLogger != nullptr; }
private:
CWebSocket webSocketSystem;
std::shared_ptr<spdlog::logger> matchLogger;
int matchLogCount;
bool initialLog;
bool initialized;
};
LiveAPI* LiveAPISystem();
#endif // RTECH_LIVEAPI_H