void VoteYes() { int votes; if( !get_votes( OV_ELECT ) ) return; if( self->v.elect_type != etNone ) { G_sprint(self, 2, "You cannot vote for yourself\n"); return; } if( self->v.elect ) { G_sprint(self, 2, "--- your vote is still good ---\n"); return; } // register the vote self->v.elect = 1; G_bprint(2, "%s gives %s vote\n", self->s.v.netname, g_his( self )); // calculate how many more votes are needed if ( (votes = get_votes_req( OV_ELECT, true )) ) G_bprint(2, "\x90%d\x91 more vote%s needed\n", votes, count_s( votes )); vote_check_elect (); }
void vote_check_antilag () { int veto; if ( match_in_progress || intermission_running || match_over ) return; if ( !get_votes( OV_ANTILAG ) ) return; veto = is_admins_vote( OV_ANTILAG ); if( veto || !get_votes_req( OV_ANTILAG, true ) ) { vote_clear( OV_ANTILAG ); // toggle antilag mode. trap_cvar_set_float( "sv_antilag", (float)(cvar( "sv_antilag" ) ? 0 : 2)); if ( veto ) G_bprint(2, "%s\n", redtext(va("Antilag mode %s by admin veto", OnOff(2 == cvar("sv_antilag"))))); else G_bprint(2, "%s\n", redtext(va("Antilag mode %s by majority vote", OnOff(2 == cvar("sv_antilag"))))); return; } }
// !!! do not confuse rpickup and pickup void vote_check_pickup () { gedict_t *p; int veto; if ( match_in_progress || k_captains ) return; if ( !get_votes( OV_PICKUP ) ) return; veto = is_admins_vote( OV_PICKUP ); if( veto || !get_votes_req( OV_PICKUP, true ) ) { vote_clear( OV_PICKUP ); if ( veto ) G_bprint(2, "console: admin veto for pickup\n"); else G_bprint(2, "console: a pickup game it is then\n"); for( p = world; (p = find_plr( p )); ) { stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "break\n" "color 0\n" "team \"\"\n" "skin base\n"); } return; } }
// { votecoop void vote_check_coop () { int veto; if ( ( deathmatch && match_in_progress ) || intermission_running || match_over ) return; if ( !get_votes( OV_COOP ) ) return; veto = is_admins_vote( OV_COOP ); if( veto || !get_votes_req( OV_COOP, true ) ) { vote_clear( OV_COOP ); // toggle coop mode cvar_fset( "coop", coop = !cvar("coop") ); // set appropriate deathmatch cvar_fset( "deathmatch", deathmatch = !coop ); if ( veto ) G_bprint( 2, "%s\n", redtext(va("Coop mode %s by admin veto", OnOff(cvar("coop")))) ); else G_bprint( 2, "%s\n", redtext(va("Coop mode %s by majority vote", OnOff(cvar("coop")))) ); // and reload map if ( cvar("k_bloodfest") ) changelevel( coop ? g_globalvars.mapname : cvar_string( "k_defmap" ) ); else changelevel( coop ? "start" : g_globalvars.mapname ); return; } }
void vote_check_teamoverlay () { int veto; if ( match_in_progress || intermission_running || match_over ) return; if ( !get_votes( OV_TEAMOVERLAY ) ) return; veto = is_admins_vote( OV_TEAMOVERLAY ); if( veto || !get_votes_req( OV_TEAMOVERLAY, true ) ) { vote_clear( OV_TEAMOVERLAY ); // Toggle teamoverlay. cvar_fset("k_teamoverlay", !cvar("k_teamoverlay")); if ( veto ) G_bprint(2, "%s\n", redtext(va("Teamoverlay %s by admin veto", OnOff(cvar("k_teamoverlay"))))); else G_bprint(2, "%s\n", redtext(va("Teamoverlay %s by majority vote", OnOff(cvar("k_teamoverlay"))))); return; } }
// !!! do not confuse rpickup and pickup void vote_check_rpickup () { float frnd; int i, tn, pl_cnt, pl_idx; gedict_t *p; int veto; if ( match_in_progress || k_captains ) return; if ( !get_votes( OV_RPICKUP ) ) return; // Firstly obtain the number of players we have in total on server pl_cnt = CountPlayers(); if ( pl_cnt < 4 ) return; veto = is_admins_vote( OV_RPICKUP ); if( veto || !get_votes_req( OV_RPICKUP, true ) ) { vote_clear( OV_RPICKUP ); for( p = world; (p = find_plr( p )); ) p->k_teamnumber = 0; for( tn = 1; pl_cnt > 0; pl_cnt-- ) { frnd = g_random(); // bound is macros - so u _can't_ put g_random inside bound pl_idx = bound(0, (int)( frnd * pl_cnt ), pl_cnt-1 ); // select random player between 0 and pl_cnt for( i = 0, p = world; (p = find_plr( p )); ) { if ( p->k_teamnumber ) continue; if ( i == pl_idx ) { p->k_teamnumber = tn; tn = (tn == 1 ? 2 : 1); // next random player will be in other team if( p->k_teamnumber == 1 ) stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "break\ncolor 4\nskin \"\"\nteam red\n"); else stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "break\ncolor 13\nskin \"\"\nteam blue\n"); break; } i++; } } if ( veto ) G_bprint(2, "console: admin veto for %s\n", redtext("random pickup")); else G_bprint(2, "console: %s game it is then\n", redtext("random pickup")); return; } }
// fill maps_voted[] with data, // return the index in maps_voted[] of most voted map // return -1 inf no votes at all or some failures // if admin votes for map - map will be treated as most voted int vote_get_maps () { int best_idx = -1, i; gedict_t *p; memset(maps_voted, 0, sizeof(maps_voted)); maps_voted_idx = -1; if ( !get_votes( OV_MAP ) ) return -1; // no one votes at all for( p = world; (p = find_client( p )); ) { if ( !p->v.map ) continue; // player is not voted if (!race_allow_map_vote(p)) continue; for ( i = 0; i < MAX_CLIENTS; i++ ) { if ( !maps_voted[i].map_id ) break; // empty if ( maps_voted[i].map_id == p->v.map ) break; // already count votes for this map } if ( i >= MAX_CLIENTS ) continue; // heh, all slots is full, just for sanity maps_voted[i].map_id = p->v.map; maps_voted[i].map_votes += 1; maps_voted[i].admins += (is_adm( p ) ? 1 : 0); // find the most voted map if ( best_idx < 0 || maps_voted[i].map_votes > maps_voted[best_idx].map_votes ) best_idx = i; // admin voted maps have priority if ( maps_voted[i].admins > maps_voted[best_idx].admins ) best_idx = i; } return (maps_voted_idx = best_idx); }
void vote_check_nospecs () { int veto; if ( match_in_progress || intermission_running || match_over ) return; if ( !get_votes( OV_NOSPECS ) ) return; veto = is_admins_vote( OV_NOSPECS ); if( veto || !get_votes_req( OV_NOSPECS, true ) ) { vote_clear( OV_NOSPECS ); // set no specs mode cvar_fset("_k_nospecs", !cvar("_k_nospecs")); if ( veto ) G_bprint(2, "%s\n", redtext(va("No spectators mode %s by admin veto", OnOff(cvar("_k_nospecs"))))); else G_bprint(2, "%s\n", redtext(va("No spectators mode %s by majority vote", OnOff(cvar("_k_nospecs"))))); // kick specs if ( cvar("_k_nospecs") ) { gedict_t *spec; for ( spec = world; (spec = find_spc( spec )); ) { if ( VIP( spec ) & ALLOWED_NOSPECS_VIPS ) continue; // don't kick this VIP if ( is_real_adm(spec) ) continue; // don't kick real admin stuffcmd(spec, "disconnect\n"); // FIXME: stupid way } } return; } }
void VoteNo() { int votes; // withdraw one's vote if( !get_votes( OV_ELECT ) || self->v.elect_type != etNone || !self->v.elect ) return; // unregister the vote self->v.elect = 0; G_bprint(2, "%s withdraws %s vote\n", self->s.v.netname, g_his( self )); // calculate how many more votes are needed if ( (votes = get_votes_req( OV_ELECT, true )) ) G_bprint(2, "\x90%d\x91 more vote%s needed\n", votes, count_s( votes )); vote_check_elect (); }
gams::elections::CandidateList gams::elections::ElectionCumulative::get_leaders(int num_leaders) { madara_logger_ptr_log(gams::loggers::global_logger.get(), gams::loggers::LOG_MAJOR, "gams::elections::ElectionCumulative:get_leaders" \ " getting leaders from %s\n", election_prefix_.c_str()); CandidateList leaders; if (knowledge_) { knowledge::ContextGuard guard(*knowledge_); typedef std::map <KnowledgeRecord::Integer, CandidateList> Leaderboard; CandidateVotes candidates; Leaderboard leaderboard; get_votes(candidates); // construct the leaderboard for (CandidateVotes::iterator i = candidates.begin(); i != candidates.end(); ++i) { leaderboard[i->second].push_back(i->first); } // leaderboard is in ascending order, so grab from the back for (Leaderboard::reverse_iterator i = leaderboard.rbegin(); i != leaderboard.rend() &&(int) leaders.size() < num_leaders; ++i) { // if it is a tie, we could provide more than num_leaders leaders.insert(leaders.end(), i->second.begin(), i->second.end()); } } return leaders; }
void VoteAdmin() { gedict_t *p; int till; gedict_t *electguard; // Can't allow election and code entering for the same person at the same time if( self->k_adminc ) { G_sprint(self, 2, "Finish entering the code first\n"); return; } if( is_adm( self ) ) { G_sprint(self, 2, "You are already an admin\n"); return; } if( is_elected( self, etAdmin ) ) { G_bprint(2, "%s %s!\n", self->netname, redtext("aborts election")); AbortElect(); return; } // Only one election per server because otherwise we wouldn't know how to count // "yes"s or "no"s if( get_votes( OV_ELECT ) ) { G_sprint(self, 2, "An election is already in progress\n"); return; } if( !cvar( "k_admins" ) ) { G_sprint(self, 2, "%s on this server!\n", redtext("NO admins")); return; } // Check if voteadmin is allowed if( !cvar( "k_allowvoteadmin" ) ) { G_sprint(self, 2, "Admin election is not allowed on this server\n"); return; } if( (till = Q_rint( self->v.elect_block_till - g_globalvars.time)) > 0 ) { G_sprint(self, 2, "Wait %d second%s!\n", till, count_s(till) ); return; } if( self->ct == ctSpec && match_in_progress ) return; G_bprint(2, "%s has %s rights!\n", self->netname, redtext("requested admin")); for( p = world; (p = find_client( p )); ) if ( p != self && p->ct == ctPlayer ) G_sprint(p, 2, "Type %s in console to approve\n", redtext("yes")); G_sprint(self, 2, "Type %s to abort election\n", redtext("elect")); // announce the election self->v.elect = 1; self->v.elect_type = etAdmin; electguard = spawn(); // Check the 1 minute timeout for election electguard->s.v.owner = EDICT_TO_PROG( world ); electguard->classname = "electguard"; electguard->think = ( func_t ) ElectThink; electguard->s.v.nextthink = g_globalvars.time + 60; }
static int show_nodes(nodeid_format_t nodeid_format, name_format_t name_format) { quorum_handle_t q_handle = 0; votequorum_handle_t v_handle = 0; corosync_cfg_handle_t c_handle = 0; corosync_cfg_callbacks_t c_callbacks; int i; int using_vq = 0; quorum_callbacks_t q_callbacks; votequorum_callbacks_t v_callbacks; int err; int result = EXIT_FAILURE; q_callbacks.quorum_notify_fn = quorum_notification_fn; err=quorum_initialize(&q_handle, &q_callbacks); if (err != CS_OK) { fprintf(stderr, "Cannot connect to quorum service, is it loaded?\n"); return result; } v_callbacks.votequorum_notify_fn = NULL; v_callbacks.votequorum_expectedvotes_notify_fn = NULL; using_vq = using_votequorum(); if (using_vq) { if ( (err=votequorum_initialize(&v_handle, &v_callbacks)) != CS_OK) { fprintf(stderr, "votequorum_initialize FAILED: %d, this is probably a configuration error\n", err); v_handle = 0; goto err_exit; } } err = quorum_trackstart(q_handle, CS_TRACK_CURRENT); if (err != CS_OK) { fprintf(stderr, "quorum_trackstart FAILED: %d\n", err); goto err_exit; } g_called = 0; while (g_called == 0) quorum_dispatch(q_handle, CS_DISPATCH_ONE); quorum_finalize(q_handle); q_handle = 0; err = corosync_cfg_initialize(&c_handle, &c_callbacks); if (err != CS_OK) { fprintf(stderr, "Cannot initialise CFG service\n"); c_handle = 0; goto err_exit; } if (using_vq) printf("Nodeid Votes Name\n"); else printf("Nodeid Name\n"); for (i=0; i < g_view_list_entries; i++) { if (nodeid_format == NODEID_FORMAT_DECIMAL) { printf("%4u ", g_view_list[i]); } else { printf("0x%04x ", g_view_list[i]); } if (using_vq) { printf("%3d %s\n", get_votes(v_handle, g_view_list[i]), node_name(c_handle, g_view_list[i], name_format)); } else { printf("%s\n", node_name(c_handle, g_view_list[i], name_format)); } } result = EXIT_SUCCESS; err_exit: if (q_handle != 0) { quorum_finalize (q_handle); } if (using_vq && v_handle != 0) { votequorum_finalize (v_handle); } if (c_handle != 0) { corosync_cfg_finalize (c_handle); } return result; }
int get_votes_req( int fofs, qbool diff ) { float percent = 51; int votes, vt_req, idx, el_type; votes = get_votes( fofs ); switch ( fofs ) { case OV_BREAK: percent = cvar(k_matchLess ? "k_vp_map" : "k_vp_break"); break; // in matchless mode there is no /break but /next_map so using "k_vp_map" case OV_PICKUP: percent = cvar("k_vp_pickup"); break; case OV_RPICKUP: percent = cvar("k_vp_rpickup"); break; case OV_MAP: percent = cvar("k_vp_map"); idx = vote_get_maps (); if ( idx >= 0 && !strnull( GetMapName(maps_voted[idx].map_id) ) ) votes = maps_voted[idx].map_votes; else votes = 0; break; case OV_ELECT: if ( (el_type = get_elect_type ()) == etAdmin ) { percent = cvar("k_vp_admin"); break; } else if ( el_type == etCaptain ) { percent = cvar("k_vp_captain"); break; } else { percent = 100; break; // unknown/none election break; } break; case OV_NOSPECS: percent = cvar("k_vp_nospecs"); break; case OV_COOP: percent = cvar("k_vp_coop"); break; case OV_ANTILAG: percent = cvar("k_vp_antilag"); break; } percent = bound(0.51, bound(51, percent, 100)/100, 1); // calc and bound percentage between 50% to 100% vt_req = ceil( percent * CountPlayers() ); if ( fofs == OV_ELECT ) vt_req = max(2, vt_req); // if election, at least 2 votes needed else if ( fofs == OV_BREAK && k_matchLess && match_in_progress == 1 ) vt_req = max(2, vt_req); // at least 2 votes in this case else if ( fofs == OV_BREAK ) vt_req = max(1, vt_req); // at least 1 vote in any case else if ( fofs == OV_RPICKUP ) vt_req = max(3, vt_req); // at least 3 votes in this case else if ( fofs == OV_NOSPECS ) vt_req = max(2, vt_req); // at least 2 votes in this case else if ( fofs == OV_COOP ) vt_req = max(1, vt_req); // at least 1 votes in this case else if ( fofs == OV_ANTILAG ) vt_req = max(2, vt_req); // at least 2 votes in this case if ( diff ) return max(0, vt_req - votes); return max(0, vt_req); }