#ifdef ENABLE_CROWD_CONTROL #ifndef _CROWDCONTROL_C #define _CROWDCONTROL_C #endif #include "stdint.h" #ifdef __cplusplus #include #include #include #include #include #include #include #include #include class CrowdControl { private: typedef struct CCPacket { uint32_t packetId; std::string effectType; uint32_t effectValue; std::string effectCategory; long timeRemaining; } CCPacket; enum EffectResult { /// The effect executed successfully. Success = 0x00, /// The effect failed to trigger, but is still available for use. Viewer(s) will be refunded. You probably don't want this. Failure = 0x01, /// Same as but the effect is no longer available for use for the remainder of the game. You probably don't want this. Unavailable = 0x02, /// The effect cannot be triggered right now, try again in a few seconds. This is the "normal" failure response. Retry = 0x03, /// INTERNAL USE ONLY. The effect has been queued for execution after the current one ends. Queue = 0x04, /// INTERNAL USE ONLY. The effect triggered successfully and is now active until it ends. Running = 0x05, /// The timed effect has been paused and is now waiting. Paused = 0x06, /// The timed effect has been resumed and is counting down again. Resumed = 0x07, /// The timed effect has finished. Finished = 0x08, /// The processor isn't ready to start or has shut down. NotReady = 0xFF }; enum ResponseType { EffectRequest = 0x00, Login = 0xF0, LoginSuccess = 0xF1, Disconnect = 0xFE, KeepAlive = 0xFF }; struct Response { int id; EffectResult status; long timeRemaining; ResponseType type = ResponseType::EffectRequest; }; std::thread ccThreadReceive; TCPsocket tcpsock; IPaddress ip; bool connected; char received[512]; std::vector receivedCommands; std::mutex receivedCommandsMutex; void RunCrowdControl(CCPacket* packet); void ReceiveFromCrowdControl(); EffectResult ExecuteEffect(std::string effectId, uint32_t value, bool dryRun); bool SpawnEnemy(std::string effectId); void RemoveEffect(std::string effectId); public: static CrowdControl* Instance; void InitCrowdControl(); }; #endif #endif