13#include <engine/igameeventsystem.h>
14#include <google/protobuf/descriptor.h>
15#include <google/protobuf/message.h>
16#include <networksystem/inetworkmessages.h>
17#include <networksystem/netmessage.h>
54 Log::Warn(
"Vote: {} has no field '{}'; the panel may render incomplete.",
104Schema::CVoteController Vote::Controller()
111 if (_running || !
request.Passed)
125 if (
ballot.Tally.Eligible == 0)
142 running.Timeout = _scheduler.
Delay(
running.Request.DurationMs, [
this] { Finish(VoteEndReason::TimeUp); });
153 Ballot&
ballot = *_running;
164 else if (
option ==
"option2")
175 PublishCounts(
ballot.Tally);
180void Vote::DropVoter(
int slot)
188 _running->Waiting[
slot] =
false;
189 --_running->Tally.Eligible;
190 PublishCounts(_running->Tally);
194void Vote::CloseIfAllVoted()
196 if (_running->Tally.Cast() < _running->Tally.Eligible)
216 Ballot
ballot = std::move(*_running);
229 if (
ballot.Request.Finished)
244 event->SetInt(
"vote_option",
option);
250void Vote::PublishCounts(
const VoteTally&
tally)
259 event->SetInt(
"vote_option1",
tally.Yes);
260 event->SetInt(
"vote_option2",
tally.No);
261 event->SetInt(
"vote_option3", 0);
262 event->SetInt(
"vote_option4", 0);
263 event->SetInt(
"vote_option5", 0);
264 event->SetInt(
"potentialVotes",
tally.Eligible);
268void Vote::SendStart(
const Ballot&
ballot)
270 MultiRecipientFilter
filter = Recipients();
287void Vote::SendOutcome(
const VoteRequest&
request,
bool passed)
290 auto&
cached =
passed ? _votePassInternal : _voteFailedInternal;
291 MultiRecipientFilter
filter = Recipients();
Access CS user-message fields through protobuf reflection.
A player's identity behind a slot: name, money, team, scoreboard row. It survives death and respawn; ...
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
Entity Find(std::string_view className)
CEntityInstance * Raw() const noexcept
Creates, fires and listens to game events.
bool FireEvent(IGameEvent *event, bool broadcast=true)
IGameEvent * CreateEvent(std::string_view name)
Routes a user message or filtered sound to a chosen set of player slots. Starts empty; callers add ea...
void AddRecipient(int slot)
The roster: every connected player, and the signals for the connection lifecycle.
std::span< Player *const > All() const
One connected player, owned by PlayerManager for the length of the connection.
One-shot delays and repeating timers, run on the game thread.
Subscription NextTick(std::function< void()> callback)
Subscription Delay(int64_t delayMs, std::function< void()> callback)
Vote(Interfaces &interfaces, EntitySystem &entities, PlayerManager &players, GameEvents &events, Scheduler &scheduler)
bool TryCastBallot(int slot, std::string_view option)
bool Start(VoteRequest request)
void End(VoteEndReason reason)
void Warn(std::format_string< Args... > fmt, Args &&... args)
static constexpr int NoOption
google::protobuf::Message ProtoMessage
static void SetBool(ProtoMessage *message, std::string_view name, bool value)
static constexpr std::string_view ControllerClass
static constexpr std::string_view VoteFailedMessage
static constexpr int YesNoIssueIndex
static std::string ReadFile(const std::filesystem::path &path)
static constexpr std::string_view VotePassMessage
constexpr bool IsValidSlot(int slot)
@ Cancelled
an admin (or a peer feature) called it off
@ AllVoted
every eligible player cast a ballot
static constexpr std::string_view VoteStartMessage
static ProtoMessage * AsProto(CNetMessage *message)
static const ProtoFieldDescriptor * VoteField(ProtoMessage *message, std::string_view name)
static void SetString(ProtoMessage *message, std::string_view name, const std::string &value)
static void SetInt(ProtoMessage *message, std::string_view name, int32_t value)
google::protobuf::FieldDescriptor ProtoFieldDescriptor
const ProtoFieldDescriptor * ProtoField(const ProtoMessage &message, std::string_view name)
bool PostUserMessage(Interfaces &interfaces, INetworkMessageInternal *&cached, std::string_view partialName, IRecipientFilter &filter, const std::function< bool(CNetMessage *)> &fill)
static constexpr int NoIssue
static constexpr int AllTeams
static constexpr int YesOption
Centralized holder for all HL2SDK interface pointers.
static constexpr std::string_view EventName
static constexpr std::string_view EventName