MCPcopy Create free account
hub / github.com/assaultcube/AC / evaluate

Method evaluate

source/src/server.cpp:2580–2606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2578 bool isalive() { return servmillis - callmillis < 30*1000; }
2579
2580 void evaluate(bool forceend = false)
2581 {
2582 if(result!=VOTE_NEUTRAL) return; // block double action
2583 if(action && !action->isvalid()) end(VOTE_NO);
2584 int stats[VOTE_NUM] = {0};
2585 int adminvote = VOTE_NEUTRAL;
2586 loopv(clients)
2587 if(clients[i]->type!=ST_EMPTY /*&& clients[i]->connectmillis < callmillis*/) // new connected people will vote now
2588 {
2589 stats[clients[i]->vote]++;
2590 if(clients[i]->role==CR_ADMIN) adminvote = clients[i]->vote;
2591 };
2592
2593 bool admin = clients[owner]->role==CR_ADMIN || (!isdedicated && clients[owner]->type==ST_LOCAL);
2594 int total = stats[VOTE_NO]+stats[VOTE_YES]+stats[VOTE_NEUTRAL];
2595 const float requiredcount = 0.51f;
2596 bool min_time = servmillis - callmillis > 10*1000;
2597#define yes_condition ((min_time && stats[VOTE_YES] - stats[VOTE_NO] > 0.34f*total && totalclients > 4) || stats[VOTE_YES] > requiredcount*total)
2598#define no_condition (forceend || !valid_client(owner) || stats[VOTE_NO] >= stats[VOTE_YES]+stats[VOTE_NEUTRAL] || adminvote == VOTE_NO)
2599#define boot_condition (!boot || (boot && valid_client(num1) && clients[num1]->peer->address.host == host))
2600 if( (yes_condition || admin || adminvote == VOTE_YES) && boot_condition ) end(VOTE_YES);
2601 else if( no_condition || (min_time && !boot_condition)) end(VOTE_NO);
2602 else return;
2603#undef boot_condition
2604#undef no_condition
2605#undef yes_condition
2606 }
2607};
2608
2609static voteinfo *curvote = NULL;

Callers 4

svoteFunction · 0.80
changeclientroleFunction · 0.80
disconnect_clientFunction · 0.80
serversliceFunction · 0.80

Calls 3

endFunction · 0.85
loopvFunction · 0.70
isvalidMethod · 0.45

Tested by

no test coverage detected