29 May 15, 06:30PM
So, I don't know if anyone actually cares about my "blog", but if anyone is reading this... can someone explain why this is a struct instead of a class?
[SELECT ALL] Code:
struct voteinfo
{
int boot;
int owner, callmillis, result, num1, num2, type;
char text[MAXTRANS];
serveraction *action;
bool gonext;
enet_uint32 host;
voteinfo() : boot(0), owner(0), callmillis(0), result(VOTE_NEUTRAL), action(NULL), gonext(false), host(0) {}
~voteinfo() { delete action; }
void end(int result)
{
if(action && !action->isvalid()) result = VOTE_NO; // don't perform() invalid votes
sendf(-1, 1, "ri2", SV_VOTERESULT, result);
this->result = result;
if(result == VOTE_YES)
{
if(valid_client(owner)) clients[owner]->lastvotecall = 0;
if(action) action->perform();
}
loopv(clients) clients[i]->vote = VOTE_NEUTRAL;
}
bool isvalid() { return valid_client(owner) && action != NULL && action->isvalid(); }
bool isalive() { return servmillis - callmillis < 30*1000; }
void evaluate(bool forceend = false)
{
if(result!=VOTE_NEUTRAL) return; // block double action
if(action && !action->isvalid()) end(VOTE_NO);
int stats[VOTE_NUM] = {0};
int adminvote = VOTE_NEUTRAL;
loopv(clients)
if(clients[i]->type!=ST_EMPTY /*&& clients[i]->connectmillis < callmillis*/) // new connected people will vote now
{
stats[clients[i]->vote]++;
if(clients[i]->role==CR_ADMIN) adminvote = clients[i]->vote;
};
bool admin = clients[owner]->role==CR_ADMIN || (!isdedicated && clients[owner]->type==ST_LOCAL);
int total = stats[VOTE_NO]+stats[VOTE_YES]+stats[VOTE_NEUTRAL];
const float requiredcount = 0.51f;
bool min_time = servmillis - callmillis > 10*1000;
#define yes_condition ((min_time && stats[VOTE_YES] - stats[VOTE_NO] > 0.34f*total && totalclients > 4) || stats[VOTE_YES] > requiredcount*total)
#define no_condition (forceend || !valid_client(owner) || stats[VOTE_NO] >= stats[VOTE_YES]+stats[VOTE_NEUTRAL] || adminvote == VOTE_NO)
#define boot_condition (!boot || (boot && valid_client(num1) && clients[num1]->peer->address.host == host))
if( (yes_condition || admin || adminvote == VOTE_YES) && boot_condition ) end(VOTE_YES);
else if( no_condition || (min_time && !boot_condition)) end(VOTE_NO);
else return;
#undef boot_condition
#undef no_condition
#undef yes_condition
}
};